+ add voxel filter function to Reen module

This commit is contained in:
wmayer 2016-02-29 23:44:55 +01:00
parent 9139ab37d3
commit 39187dacac
2 changed files with 58 additions and 0 deletions

View File

@ -44,6 +44,10 @@
#include "ApproxSurface.h"
#include "BSplineFitting.h"
#include "SurfaceTriangulation.h"
#if defined(HAVE_PCL_FILTERS)
#include <pcl/filters/voxel_grid.h>
#include <pcl/point_types.h>
#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<Points::PointsPy*>(pts)->getPointKernelPtr();
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
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<pcl::PointXYZ>::Ptr cloud_downSmpl (new pcl::PointCloud<pcl::PointXYZ>);
pcl::VoxelGrid<pcl::PointXYZ> 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<pcl::PointXYZ>::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

View File

@ -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}