44 #include <pcl/surface/reconstruction.h>
45 #include <pcl/surface/boost.h>
47 #include <pcl/conversions.h>
48 #include <pcl/kdtree/kdtree.h>
49 #include <pcl/kdtree/kdtree_flann.h>
50 #include <pcl/PolygonMesh.h>
68 isVisible (
const Eigen::Vector2f &X,
const Eigen::Vector2f &S1,
const Eigen::Vector2f &S2,
69 const Eigen::Vector2f &R = Eigen::Vector2f::Zero ())
71 double a0 = S1[1] - S2[1];
72 double b0 = S2[0] - S1[0];
73 double c0 = S1[0]*S2[1] - S2[0]*S1[1];
77 if (R != Eigen::Vector2f::Zero())
81 c1 = R[0]*X[1] - X[0]*R[1];
83 double div = a0*b1 - b0*a1;
84 double x = (b0*c1 - b1*c0) / div;
85 double y = (a1*c0 - a0*c1) / div;
87 bool intersection_outside_XR;
88 if (R == Eigen::Vector2f::Zero())
91 intersection_outside_XR = (x <= 0) || (x >= X[0]);
93 intersection_outside_XR = (x >= 0) || (x <= X[0]);
95 intersection_outside_XR = (y <= 0) || (y >= X[1]);
97 intersection_outside_XR = (y >= 0) || (y <= X[1]);
99 intersection_outside_XR =
true;
104 intersection_outside_XR = (x <= R[0]) || (x >= X[0]);
105 else if (X[0] < R[0])
106 intersection_outside_XR = (x >= R[0]) || (x <= X[0]);
107 else if (X[1] > R[1])
108 intersection_outside_XR = (y <= R[1]) || (y >= X[1]);
109 else if (X[1] < R[1])
110 intersection_outside_XR = (y >= R[1]) || (y <= X[1]);
112 intersection_outside_XR =
true;
114 if (intersection_outside_XR)
119 return (x <= S2[0]) || (x >= S1[0]);
120 else if (S1[0] < S2[0])
121 return (x >= S2[0]) || (x <= S1[0]);
122 else if (S1[1] > S2[1])
123 return (y <= S2[1]) || (y >= S1[1]);
124 else if (S1[1] < S2[1])
125 return (y >= S2[1]) || (y <= S1[1]);
137 template <
typename Po
intInT>
141 typedef boost::shared_ptr<GreedyProjectionTriangulation<PointInT> >
Ptr;
142 typedef boost::shared_ptr<const GreedyProjectionTriangulation<PointInT> >
ConstPtr;
184 is_current_free_ (false),
186 prev_is_ffn_ (false),
187 prev_is_sfn_ (false),
188 next_is_ffn_ (false),
189 next_is_sfn_ (false),
190 changed_1st_fn_ (false),
191 changed_2nd_fn_ (false),
193 already_connected_ (false),
294 inline std::vector<int>
300 inline std::vector<int>
305 inline std::vector<int>
309 inline std::vector<int>
350 doubleEdge () : index (0), first (), second () {}
352 Eigen::Vector2f first;
353 Eigen::Vector2f second;
361 std::vector<Eigen::Vector3f> coords_;
364 std::vector<nnAngle> angles_;
368 std::vector<int> state_;
370 std::vector<int> source_;
372 std::vector<int> ffn_;
374 std::vector<int> sfn_;
376 std::vector<int> part_;
378 std::vector<int> fringe_queue_;
381 bool is_current_free_;
393 bool changed_1st_fn_;
395 bool changed_2nd_fn_;
402 bool already_connected_;
405 Eigen::Vector3f proj_qp_;
411 Eigen::Vector2f uvn_ffn_;
413 Eigen::Vector2f uvn_sfn_;
415 Eigen::Vector2f uvn_next_ffn_;
417 Eigen::Vector2f uvn_next_sfn_;
420 Eigen::Vector3f tmp_;
432 performReconstruction (std::vector<pcl::Vertices> &polygons);
438 reconstructPolygons (std::vector<pcl::Vertices> &polygons);
442 getClassName ()
const {
return (
"GreedyProjectionTriangulation"); }
455 connectPoint (std::vector<pcl::Vertices> &polygons,
456 const int prev_index,
457 const int next_index,
458 const int next_next_index,
459 const Eigen::Vector2f &uvn_current,
460 const Eigen::Vector2f &uvn_prev,
461 const Eigen::Vector2f &uvn_next);
468 closeTriangle (std::vector<pcl::Vertices> &polygons);
473 std::vector<std::vector<size_t> >
483 addTriangle (
int a,
int b,
int c, std::vector<pcl::Vertices> &polygons)
489 const Eigen::Vector3f pv = p.getVector3fMap ();
490 if (p.getNormalVector3fMap ().dot (
511 polygons.push_back (triangle_);
519 addFringePoint (
int v,
int s)
523 fringe_queue_.push_back(v);
532 nnAngleSortAsc (
const nnAngle& a1,
const nnAngle& a2)
534 if (a1.visible == a2.visible)
535 return (a1.angle < a2.angle);
543 #ifdef PCL_NO_PRECOMPILE
544 #include <pcl/surface/impl/gp3.hpp>
547 #endif //#ifndef PCL_GP3_H_