35 #ifndef PCL_FILTERS_IMPL_PLANE_CLIPPER3D_HPP
36 #define PCL_FILTERS_IMPL_PLANE_CLIPPER3D_HPP
38 #include <pcl/filters/plane_clipper3D.h>
40 template<
typename Po
intT>
42 : plane_params_ (plane_params)
46 template<
typename Po
intT>
void
49 plane_params_ = plane_params;
52 template<
typename Po
intT>
const Eigen::Vector4f&
64 template<
typename Po
intT>
float
67 return (plane_params_[0] * point.x + plane_params_[1] * point.y + plane_params_[2] * point.z + plane_params_[3]);
70 template<
typename Po
intT>
bool
73 return ((plane_params_[0] * point.x + plane_params_[1] * point.y + plane_params_[2] * point.z ) >= -plane_params_[3]);
79 template<
typename Po
intT>
bool
82 float dist1 = getDistance (point1);
83 float dist2 = getDistance (point2);
85 if (dist1 * dist2 > 0)
88 float lambda = dist2 / (dist2 - dist1);
92 intersection.x = (point1.x - point2.x) * lambda + point2.x;
93 intersection.y = (point1.y - point2.y) * lambda + point2.y;
94 intersection.z = (point1.z - point2.z) * lambda + point2.z;
98 point2 = intersection;
100 point1 = intersection;
108 template<
typename Po
intT>
void
111 clipped_polygon.clear ();
112 clipped_polygon.reserve (polygon.size ());
115 if (polygon.size () < 3)
117 if (polygon.size () == 1)
120 if (clipPoint3D (polygon [0]))
121 clipped_polygon.push_back (polygon [0]);
123 else if (polygon.size () == 2)
125 clipped_polygon.push_back (polygon [0]);
126 clipped_polygon.push_back (polygon [1]);
127 if (!clipLineSegment3D (clipped_polygon [0], clipped_polygon [1]))
128 clipped_polygon.clear ();
133 float previous_distance = getDistance (polygon [0]);
135 if (previous_distance > 0)
136 clipped_polygon.push_back (polygon [0]);
138 typename std::vector<PointT, Eigen::aligned_allocator<PointT> >::const_iterator prev_it = polygon.begin ();
140 for (
typename std::vector<
PointT, Eigen::aligned_allocator<PointT> >::const_iterator pIt = prev_it + 1; pIt != polygon.end (); prev_it = pIt++)
143 float distance = getDistance (*pIt);
144 if (
distance * previous_distance < 0)
149 intersection.x = (prev_it->x - pIt->x) * lambda + pIt->x;
150 intersection.y = (prev_it->y - pIt->y) * lambda + pIt->y;
151 intersection.z = (prev_it->z - pIt->z) * lambda + pIt->z;
153 clipped_polygon.push_back (intersection);
156 clipped_polygon.push_back (*pIt);
165 template<
typename Po
intT>
void
168 std::vector<PointT, Eigen::aligned_allocator<PointT> > clipped;
169 clipPlanarPolygon3D (polygon, clipped);
174 template<
typename Po
intT>
void
177 if (indices.empty ())
179 clipped.reserve (cloud_in.
size ());
211 for (
unsigned pIdx = 0; pIdx < cloud_in.
size (); ++pIdx)
212 if (clipPoint3D (cloud_in[pIdx]))
213 clipped.push_back (pIdx);
217 for (
const auto& index : indices)
218 if (clipPoint3D (cloud_in[index]))
219 clipped.push_back (index);
Base class for 3D clipper objects.
Implementation of a plane clipper in 3D.
void setPlaneParameters(const Eigen::Vector4f &plane_params)
Set new plane parameters.
const Eigen::Vector4f & getPlaneParameters() const
return the current plane parameters
virtual bool clipPoint3D(const PointT &point) const
interface to clip a single point
virtual Clipper3D< PointT > * clone() const
polymorphic method to clone the underlying clipper with its parameters.
virtual bool clipLineSegment3D(PointT &from, PointT &to) const
virtual void clipPlanarPolygon3D(std::vector< PointT, Eigen::aligned_allocator< PointT > > &polygon) const
virtual void clipPointCloud3D(const pcl::PointCloud< PointT > &cloud_in, Indices &clipped, const Indices &indices=Indices()) const
interface to clip a point cloud
PCL_MAKE_ALIGNED_OPERATOR_NEW PlaneClipper3D(const Eigen::Vector4f &plane_params)
Constructor taking the homogeneous representation of the plane as a Eigen::Vector4f.
float getDistance(const PointT &point) const
PointCloud represents the base class in PCL for storing collections of 3D points.
float distance(const PointT &p1, const PointT &p2)
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing Euclidean xyz coordinates, and the RGB color.