43 #include <pcl/surface/reconstruction.h>
44 #include <pcl/surface/boost.h>
46 #include <pcl/conversions.h>
47 #include <pcl/kdtree/kdtree.h>
48 #include <pcl/PolygonMesh.h>
66 isVisible (
const Eigen::Vector2f &X,
const Eigen::Vector2f &S1,
const Eigen::Vector2f &S2,
67 const Eigen::Vector2f &R = Eigen::Vector2f::Zero ())
69 double a0 = S1[1] - S2[1];
70 double b0 = S2[0] - S1[0];
71 double c0 = S1[0]*S2[1] - S2[0]*S1[1];
75 if (R != Eigen::Vector2f::Zero())
79 c1 = R[0]*X[1] - X[0]*R[1];
81 double div = a0*b1 - b0*a1;
82 double x = (b0*c1 - b1*c0) / div;
83 double y = (a1*c0 - a0*c1) / div;
85 bool intersection_outside_XR;
86 if (R == Eigen::Vector2f::Zero())
89 intersection_outside_XR = (x <= 0) || (x >= X[0]);
91 intersection_outside_XR = (x >= 0) || (x <= X[0]);
93 intersection_outside_XR = (y <= 0) || (y >= X[1]);
95 intersection_outside_XR = (y >= 0) || (y <= X[1]);
97 intersection_outside_XR =
true;
102 intersection_outside_XR = (x <= R[0]) || (x >= X[0]);
103 else if (X[0] < R[0])
104 intersection_outside_XR = (x >= R[0]) || (x <= X[0]);
105 else if (X[1] > R[1])
106 intersection_outside_XR = (y <= R[1]) || (y >= X[1]);
107 else if (X[1] < R[1])
108 intersection_outside_XR = (y >= R[1]) || (y <= X[1]);
110 intersection_outside_XR =
true;
112 if (intersection_outside_XR)
115 return (x <= S2[0]) || (x >= S1[0]);
117 return (x >= S2[0]) || (x <= S1[0]);
119 return (y <= S2[1]) || (y >= S1[1]);
121 return (y >= S2[1]) || (y <= S1[1]);
131 template <
typename Po
intInT>
135 using Ptr = shared_ptr<GreedyProjectionTriangulation<PointInT> >;
136 using ConstPtr = shared_ptr<const GreedyProjectionTriangulation<PointInT> >;
170 is_current_free_ (false),
172 prev_is_ffn_ (false),
173 prev_is_sfn_ (false),
174 next_is_ffn_ (false),
175 next_is_sfn_ (false),
176 changed_1st_fn_ (false),
177 changed_2nd_fn_ (false),
179 already_connected_ (false)
272 inline std::vector<int>
278 inline std::vector<int>
283 inline std::vector<int>
287 inline std::vector<int>
328 doubleEdge () : index (0) {}
330 Eigen::Vector2f first;
331 Eigen::Vector2f second;
339 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > coords_;
342 std::vector<nnAngle> angles_;
346 std::vector<int> state_;
348 std::vector<int> source_;
350 std::vector<int> ffn_;
352 std::vector<int> sfn_;
354 std::vector<int> part_;
356 std::vector<int> fringe_queue_;
359 bool is_current_free_;
371 bool changed_1st_fn_;
373 bool changed_2nd_fn_;
380 bool already_connected_;
383 Eigen::Vector3f proj_qp_;
389 Eigen::Vector2f uvn_ffn_;
391 Eigen::Vector2f uvn_sfn_;
393 Eigen::Vector2f uvn_next_ffn_;
395 Eigen::Vector2f uvn_next_sfn_;
398 Eigen::Vector3f tmp_;
410 performReconstruction (std::vector<pcl::Vertices> &polygons)
override;
416 reconstructPolygons (std::vector<pcl::Vertices> &polygons);
420 getClassName ()
const override {
return (
"GreedyProjectionTriangulation"); }
433 connectPoint (std::vector<pcl::Vertices> &polygons,
434 const int prev_index,
435 const int next_index,
436 const int next_next_index,
437 const Eigen::Vector2f &uvn_current,
438 const Eigen::Vector2f &uvn_prev,
439 const Eigen::Vector2f &uvn_next);
446 closeTriangle (std::vector<pcl::Vertices> &polygons);
451 std::vector<std::vector<std::size_t> >
461 addTriangle (
int a,
int b,
int c, std::vector<pcl::Vertices> &polygons)
467 const Eigen::Vector3f pv = p.getVector3fMap ();
468 if (p.getNormalVector3fMap ().dot (
489 polygons.push_back (triangle_);
497 addFringePoint (
int v,
int s)
501 fringe_queue_.push_back(v);
510 nnAngleSortAsc (
const nnAngle& a1,
const nnAngle& a2)
512 if (a1.visible == a2.visible)
513 return (a1.angle < a2.angle);
520 #ifdef PCL_NO_PRECOMPILE
521 #include <pcl/surface/impl/gp3.hpp>
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
void setSearchRadius(double radius)
Set the sphere radius that is to be used for determining the k-nearest neighbors used for triangulati...
double eps_angle_
Maximum surface angle.
double maximum_angle_
The maximum angle for the triangles.
double getMaximumAngle() const
Get the parameter for distance based weighting of neighbors.
int getMaximumNearestNeighbors() const
Get the maximum number of nearest neighbors to be searched for.
void setConsistentVertexOrdering(bool consistent_ordering)
Set the flag to order the resulting triangle vertices consistently (positive direction around normal)...
typename PointCloudIn::ConstPtr PointCloudInConstPtr
bool getNormalConsistency() const
Get the flag for consistently oriented normals.
bool consistent_ordering_
Set this to true if the output triangle vertices should be consistently oriented.
std::vector< int > getFFN() const
Get the ffn list.
shared_ptr< const GreedyProjectionTriangulation< PointInT > > ConstPtr
bool getConsistentVertexOrdering() const
Get the flag signaling consistently ordered triangle vertices.
int nnn_
The maximum number of nearest neighbors accepted by searching.
double getMaximumSurfaceAngle() const
Get the maximum surface angle.
std::vector< int > getSFN() const
Get the sfn list.
typename PointCloudIn::Ptr PointCloudInPtr
double mu_
The nearest neighbor distance multiplier to obtain the final search radius.
double search_radius_
The nearest neighbors search radius for each point and the maximum edge length.
typename KdTree::Ptr KdTreePtr
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
bool consistent_
Set this to true if the normals of the input are consistently oriented.
GreedyProjectionTriangulation()
Empty constructor.
std::vector< int > getPartIDs() const
Get the ID of each point after reconstruction.
double getSearchRadius() const
Get the sphere radius used for determining the k-nearest neighbors.
double getMu() const
Get the nearest neighbor distance multiplier.
double getMinimumAngle() const
Get the parameter for distance based weighting of neighbors.
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
double minimum_angle_
The preferred minimum angle for the triangles.
shared_ptr< GreedyProjectionTriangulation< PointInT > > Ptr
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
void setMu(double mu)
Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point ...
std::vector< int > getPointStates() const
Get the state of each point after reconstruction.
void setMaximumSurfaceAngle(double eps_angle)
Don't consider points for triangulation if their normal deviates more than this value from the query ...
KdTree represents the base spatial locator class for kd-tree implementations.
shared_ptr< KdTree< PointT > > Ptr
MeshConstruction represents a base surface reconstruction class.
PointCloudConstPtr input_
The input point cloud dataset.
IndicesPtr indices_
A pointer to the vector of point indices to use.
shared_ptr< PointCloud< PointInT > > Ptr
shared_ptr< const PointCloud< PointInT > > ConstPtr
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...
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.
std::vector< std::uint32_t > vertices