From 39187dacacfe24721ccb5f9411ab888dfb57da49 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 29 Feb 2016 23:44:55 +0100 Subject: [PATCH] + add voxel filter function to Reen module --- .../App/AppReverseEngineering.cpp | 53 +++++++++++++++++++ src/Mod/ReverseEngineering/App/CMakeLists.txt | 5 ++ 2 files changed, 58 insertions(+) diff --git a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp index c0011a8b4..0fc1761fb 100644 --- a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp +++ b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp @@ -44,6 +44,10 @@ #include "ApproxSurface.h" #include "BSplineFitting.h" #include "SurfaceTriangulation.h" +#if defined(HAVE_PCL_FILTERS) +#include +#include +#endif using namespace Reen; @@ -82,6 +86,11 @@ public: add_keyword_method("fitBSpline",&Module::fitBSpline, "fitBSpline(PointKernel)." ); +#endif +#if defined(HAVE_PCL_FILTERS) + add_keyword_method("filterVoxelGrid",&Module::filterVoxelGrid, + "filterVoxelGrid(dim)." + ); #endif initialize("This module is the ReverseEngineering module."); // register with Python } @@ -519,6 +528,50 @@ Mesh.show(m) throw Py::RuntimeError("Computation of B-Spline surface failed"); } #endif +#if defined(HAVE_PCL_FILTERS) + Py::Object filterVoxelGrid(const Py::Tuple& args, const Py::Dict& kwds) + { + PyObject *pts; + double voxDimX = 0; + double voxDimY = 0; + double voxDimZ = 0; + + static char* kwds_voxel[] = {"Points", "DimX", "DimY", "DimZ", NULL}; + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d|dd", kwds_voxel, + &(Points::PointsPy::Type), &pts, + &voxDimX, &voxDimY, &voxDimZ)) + throw Py::Exception(); + + if (voxDimY == 0) + voxDimY = voxDimX; + + if (voxDimZ == 0) + voxDimZ = voxDimX; + + Points::PointKernel* points = static_cast(pts)->getPointKernelPtr(); + + pcl::PointCloud::Ptr cloud (new pcl::PointCloud); + cloud->reserve(points->size()); + for (Points::PointKernel::const_iterator it = points->begin(); it != points->end(); ++it) { + cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z)); + } + + // Create the filtering object + pcl::PointCloud::Ptr cloud_downSmpl (new pcl::PointCloud); + pcl::VoxelGrid voxG; + voxG.setInputCloud (cloud); + voxG.setLeafSize (voxDimX, voxDimY, voxDimZ); + voxG.filter (*cloud_downSmpl); + + Points::PointKernel* points_sample = new Points::PointKernel(); + points_sample->reserve(cloud_downSmpl->size()); + for (pcl::PointCloud::const_iterator it = cloud_downSmpl->begin();it!=cloud_downSmpl->end();++it) { + points_sample->push_back(Base::Vector3d(it->x,it->y,it->z)); + } + + return Py::asObject(new Points::PointsPy(points_sample)); + } +#endif }; } // namespace Reen diff --git a/src/Mod/ReverseEngineering/App/CMakeLists.txt b/src/Mod/ReverseEngineering/App/CMakeLists.txt index 3a1c286c4..8f5cdc584 100644 --- a/src/Mod/ReverseEngineering/App/CMakeLists.txt +++ b/src/Mod/ReverseEngineering/App/CMakeLists.txt @@ -12,6 +12,10 @@ if (PCL_SURFACE_FOUND AND PCL_FEATURES_FOUND) endif() endif () +if (PCL_FILTERS_FOUND AND PCL_FEATURES_FOUND) + add_definitions(-DHAVE_PCL_FILTERS) +endif () + include_directories( ${CMAKE_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS} @@ -35,6 +39,7 @@ set(Reen_LIBS ${PCL_COMMON_LIBRARIES} ${PCL_KDTREE_LIBRARIES} ${PCL_FEATURES_LIBRARIES} + ${PCL_FILTERS_LIBRARIES} ${PCL_SEARCH_LIBRARIES} ${PCL_SURFACE_LIBRARIES} ${QT_QTCORE_LIBRARY}