43 #include <pcl/surface/reconstruction.h>
45 #include <pcl/kdtree/kdtree.h>
49 #include <Eigen/Geometry>
64 isVisible (
const Eigen::Vector2f &X,
const Eigen::Vector2f &S1,
const Eigen::Vector2f &S2,
65 const Eigen::Vector2f &R = Eigen::Vector2f::Zero ())
67 double a0 = S1[1] - S2[1];
68 double b0 = S2[0] - S1[0];
69 double c0 = S1[0]*S2[1] - S2[0]*S1[1];
73 if (R != Eigen::Vector2f::Zero())
77 c1 = R[0]*X[1] - X[0]*R[1];
79 double div = a0*b1 - b0*a1;
80 double x = (b0*c1 - b1*c0) / div;
81 double y = (a1*c0 - a0*c1) / div;
83 bool intersection_outside_XR;
84 if (R == Eigen::Vector2f::Zero())
87 intersection_outside_XR = (x <= 0) || (x >= X[0]);
89 intersection_outside_XR = (x >= 0) || (x <= X[0]);
91 intersection_outside_XR = (y <= 0) || (y >= X[1]);
93 intersection_outside_XR = (y >= 0) || (y <= X[1]);
95 intersection_outside_XR =
true;
100 intersection_outside_XR = (x <= R[0]) || (x >= X[0]);
101 else if (X[0] < R[0])
102 intersection_outside_XR = (x >= R[0]) || (x <= X[0]);
103 else if (X[1] > R[1])
104 intersection_outside_XR = (y <= R[1]) || (y >= X[1]);
105 else if (X[1] < R[1])
106 intersection_outside_XR = (y >= R[1]) || (y <= X[1]);
108 intersection_outside_XR =
true;
110 if (intersection_outside_XR)
113 return (x <= S2[0]) || (x >= S1[0]);
115 return (x >= S2[0]) || (x <= S1[0]);
117 return (y <= S2[1]) || (y >= S1[1]);
119 return (y >= S2[1]) || (y <= S1[1]);
130 template <
typename Po
intInT>
134 using Ptr = shared_ptr<GreedyProjectionTriangulation<PointInT> >;
135 using ConstPtr = shared_ptr<const GreedyProjectionTriangulation<PointInT> >;
250 inline std::vector<int>
256 inline std::vector<int>
306 doubleEdge () =
default;
308 Eigen::Vector2f first;
309 Eigen::Vector2f second;
317 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > coords_{};
320 std::vector<nnAngle> angles_{};
324 std::vector<int> state_{};
332 std::vector<int> part_{};
334 std::vector<int> fringe_queue_{};
337 bool is_current_free_{
false};
341 bool prev_is_ffn_{
false};
343 bool prev_is_sfn_{
false};
345 bool next_is_ffn_{
false};
347 bool next_is_sfn_{
false};
349 bool changed_1st_fn_{
false};
351 bool changed_2nd_fn_{
false};
358 bool already_connected_{
false};
361 Eigen::Vector3f proj_qp_;
367 Eigen::Vector2f uvn_ffn_;
369 Eigen::Vector2f uvn_sfn_;
371 Eigen::Vector2f uvn_next_ffn_;
373 Eigen::Vector2f uvn_next_sfn_;
376 Eigen::Vector3f tmp_;
388 performReconstruction (std::vector<pcl::Vertices> &polygons)
override;
394 reconstructPolygons (std::vector<pcl::Vertices> &polygons);
398 getClassName ()
const override {
return (
"GreedyProjectionTriangulation"); }
411 connectPoint (std::vector<pcl::Vertices> &polygons,
415 const Eigen::Vector2f &uvn_current,
416 const Eigen::Vector2f &uvn_prev,
417 const Eigen::Vector2f &uvn_next);
424 closeTriangle (std::vector<pcl::Vertices> &polygons);
429 std::vector<std::vector<std::size_t> >
445 const Eigen::Vector3f pv = p.getVector3fMap ();
446 if (p.getNormalVector3fMap ().dot (
467 polygons.push_back (triangle_);
475 addFringePoint (
int v,
int s)
479 fringe_queue_.push_back(v);
488 nnAngleSortAsc (
const nnAngle& a1,
const nnAngle& a2)
490 if (a1.visible == a2.visible)
491 return (a1.angle < a2.angle);
498 #ifdef PCL_NO_PRECOMPILE
499 #include <pcl/surface/impl/gp3.hpp>
double getMaximumAngle() const
Get the parameter for distance based weighting of neighbors.
shared_ptr< PointCloud< PointInT > > Ptr
pcl::Indices getSFN() const
Get the sfn list.
void setConsistentVertexOrdering(bool consistent_ordering)
Set the flag to order the resulting triangle vertices consistently (positive direction around normal)...
bool getConsistentVertexOrdering() const
Get the flag signaling consistently ordered triangle vertices.
double getMinimumAngle() const
Get the parameter for distance based weighting of neighbors.
void setMu(double mu)
Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point ...
typename 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...
IndicesPtr indices_
A pointer to the vector of point indices to use.
shared_ptr< const GreedyProjectionTriangulation< PointInT > > ConstPtr
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
shared_ptr< GreedyProjectionTriangulation< PointInT > > Ptr
shared_ptr< KdTree< PointT > > Ptr
double getMaximumSurfaceAngle() const
Get the maximum surface angle.
bool getNormalConsistency() const
Get the flag for consistently oriented normals.
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.
double getMu() const
Get the nearest neighbor distance multiplier.
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.
int nnn_
The maximum number of nearest neighbors accepted by searching.
typename KdTree::Ptr KdTreePtr
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
double minimum_angle_
The preferred minimum angle for the triangles.
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
bool consistent_
Set this to true if the normals of the input are consistently oriented.
int getMaximumNearestNeighbors() const
Get the maximum number of nearest neighbors to be searched for.
IndicesAllocator<> Indices
Type used for indices in PCL.
pcl::Indices getFFN() const
Get the ffn list.
MeshConstruction represents a base surface reconstruction class.
void setMaximumSurfaceAngle(double eps_angle)
Don't consider points for triangulation if their normal deviates more than this value from the query ...
double eps_angle_
Maximum surface angle.
void setSearchRadius(double radius)
Set the sphere radius that is to be used for determining the k-nearest neighbors used for triangulati...
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
GreedyProjectionTriangulation()=default
Empty constructor.
double maximum_angle_
The maximum angle for the triangles.
shared_ptr< const PointCloud< PointInT > > ConstPtr
typename PointCloudIn::Ptr PointCloudInPtr
PointCloudConstPtr input_
The input point cloud dataset.
bool consistent_ordering_
Set this to true if the output triangle vertices should be consistently oriented. ...
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.
KdTree represents the base spatial locator class for kd-tree implementations.