Skip to content

Commit 718a3a6

Browse files
feat: add point cloud intersection calculation to DFPointCloud
1 parent bbbee07 commit 718a3a6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,42 @@ namespace diffCheck::geometry
322322
}
323323
}
324324

325+
diffCheck::geometry::DFPointCloud DFPointCloud::Intersect(const DFPointCloud &pointCloud, double distanceThreshold)
326+
{
327+
if (this->Points.size() == 0 || pointCloud.Points.size() == 0)
328+
throw std::invalid_argument("One of the point clouds is empty.");
329+
330+
auto O3DSourcePointCloud = this->Cvt2O3DPointCloud();
331+
auto O3DTargetPointCloud = std::make_shared<DFPointCloud>(pointCloud)->Cvt2O3DPointCloud();
332+
auto O3DResultPointCloud = std::make_shared<open3d::geometry::PointCloud>();
333+
334+
open3d::geometry::KDTreeFlann threeDTree;
335+
threeDTree.SetGeometry(*O3DTargetPointCloud);
336+
std::vector<int> indices;
337+
std::vector<double> distances;
338+
for (const auto &point : O3DSourcePointCloud->points_)
339+
{
340+
threeDTree.SearchRadius(point, distanceThreshold, indices, distances);
341+
if (!indices.empty())
342+
{
343+
O3DResultPointCloud->points_.push_back(point);
344+
if (O3DSourcePointCloud->HasColors())
345+
{
346+
O3DResultPointCloud->colors_.push_back(O3DSourcePointCloud->colors_[&point - &O3DSourcePointCloud->points_[0]]);
347+
}
348+
if (O3DSourcePointCloud->HasNormals())
349+
{
350+
O3DResultPointCloud->normals_.push_back(O3DSourcePointCloud->normals_[&point - &O3DSourcePointCloud->points_[0]]);
351+
}
352+
}
353+
}
354+
diffCheck::geometry::DFPointCloud result;
355+
result.Points = O3DResultPointCloud->points_;
356+
result.Colors = O3DResultPointCloud->colors_;
357+
result.Normals = O3DResultPointCloud->normals_;
358+
return result;
359+
}
360+
325361
void DFPointCloud::ApplyTransformation(const diffCheck::transformation::DFTransformation &transformation)
326362
{
327363
auto O3DPointCloud = this->Cvt2O3DPointCloud();

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace diffCheck::geometry
152152
*/
153153
std::vector<Eigen::Vector3d> GetTightBoundingBox();
154154

155-
public: ///< Point cloud subtraction
155+
public: ///< Point cloud subtraction and intersection
156156
/**
157157
* @brief Subtract the points, colors and normals from another point cloud when they are too close to the points of another point cloud.
158158
*
@@ -161,6 +161,15 @@ namespace diffCheck::geometry
161161
*/
162162
void SubtractPoints(const DFPointCloud &pointCloud, double distanceThreshold = 0.01);
163163

164+
/**
165+
* @brief Intersect the points, colors and normals from another point cloud when they are close enough to the points of another point cloud. Is the point cloud interpretation of a boolean intersection.
166+
*
167+
* @param pointCloud the other point cloud to intersect with this one
168+
* @param distanceThreshold the distance threshold to consider a point as too close. Default is 0.01.
169+
* @return diffCheck::geometry::DFPointCloud the intersected point cloud
170+
*/
171+
diffCheck::geometry::DFPointCloud Intersect(const DFPointCloud &pointCloud, double distanceThreshold = 0.01);
172+
164173
public: ///< Transformers
165174
/**
166175
* @brief Apply a transformation to the point cloud

0 commit comments

Comments
 (0)