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_
pcl::KdTree< PointInT >::Ptr KdTreePtr
void setMu(double mu)
Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point ...
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
int getMaximumNearestNeighbors() const
Get the maximum number of nearest neighbors to be searched for.
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.
std::vector< int > getPartIDs() const
Get the ID of each point after reconstruction.
PointCloudIn::Ptr PointCloudInPtr
double getMu() const
Get the nearest neighbor distance multiplier.
GreedyProjectionTriangulation()
Empty constructor.
double getMinimumAngle() const
Get the parameter for distance based weighting of neighbors.
double eps_angle_
Maximum surface angle.
std::vector< uint32_t > vertices
bool consistent_ordering_
Set this to true if the output triangle vertices should be consistently oriented. ...
double getMaximumAngle() const
Get the parameter for distance based weighting of neighbors.
double getMaximumSurfaceAngle() const
Get the maximum surface angle.
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
void setMaximumSurfaceAngle(double eps_angle)
Don't consider points for triangulation if their normal deviates more than this value from the query ...
pcl::KdTree< PointInT > KdTree
MeshConstruction represents a base surface reconstruction class.
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
boost::shared_ptr< const GreedyProjectionTriangulation< PointInT > > ConstPtr
double search_radius_
The nearest neighbors search radius for each point and the maximum edge length.
std::vector< int > getPointStates() const
Get the state of each point after reconstruction.
boost::shared_ptr< PointCloud< PointT > > Ptr
bool consistent_
Set this to true if the normals of the input are consistently oriented.
PointCloudIn::ConstPtr PointCloudInConstPtr
bool isVisible(const Eigen::Vector2f &X, const Eigen::Vector2f &S1, const Eigen::Vector2f &S2, const Eigen::Vector2f &R=Eigen::Vector2f::Zero())
Returns if a point X is visible from point R (or the origin) when taking into account the segment bet...
pcl::PointCloud< PointInT > PointCloudIn
KdTree represents the base spatial locator class for kd-tree implementations.
IndicesPtr indices_
A pointer to the vector of point indices to use.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
bool getConsistentVertexOrdering() const
Get the flag signaling consistently ordered triangle vertices.
double maximum_angle_
The maximum angle for the triangles.
boost::shared_ptr< KdTree< PointT > > Ptr
int nnn_
The maximum number of nearest neighbors accepted by searching.
void setConsistentVertexOrdering(bool consistent_ordering)
Set the flag to order the resulting triangle vertices consistently (positive direction around normal)...
double mu_
The nearest neighbor distance multiplier to obtain the final search radius.
double getSearchRadius() const
Get the sphere radius used for determining the k-nearest neighbors.
boost::shared_ptr< GreedyProjectionTriangulation< PointInT > > Ptr
double minimum_angle_
The preferred minimum angle for the triangles.
PointCloudConstPtr input_
The input point cloud dataset.
std::vector< int > getSFN() const
Get the sfn list.
void setSearchRadius(double radius)
Set the sphere radius that is to be used for determining the k-nearest neighbors used for triangulati...
std::vector< int > getFFN() const
Get the ffn list.
bool getNormalConsistency() const
Get the flag for consistently oriented normals.