Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ filter out invalid points
  • Loading branch information
wwmayer committed Mar 2, 2016
1 parent f336b7e commit ec992ae
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/Mod/Points/App/PointsPy.xml
Expand Up @@ -44,6 +44,16 @@ transforming and much more.
<UserDocu>add one or more (list of) points to the object</UserDocu>
</Documentation>
</Methode>
<Methode Name="fromSegment" Const="true">
<Documentation>
<UserDocu>Get a new point object from a given segment</UserDocu>
</Documentation>
</Methode>
<Methode Name="fromValid" Const="true">
<Documentation>
<UserDocu>Get a new point object from points with valid coordinates (i.e. that are not NaN)</UserDocu>
</Documentation>
</Methode>
<Attribute Name="CountPoints" ReadOnly="true">
<Documentation>
<UserDocu>Return the number of vertices of the points object.</UserDocu>
Expand Down
49 changes: 49 additions & 0 deletions src/Mod/Points/App/PointsPyImp.cpp
Expand Up @@ -27,6 +27,7 @@
#include <Base/Builder3D.h>
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <boost/math/special_functions/fpclassify.hpp>

// inclusion of the generated files (generated out of PointsPy.xml)
#include "PointsPy.h"
Expand Down Expand Up @@ -168,6 +169,54 @@ PyObject* PointsPy::addPoints(PyObject * args)
Py_Return;
}

PyObject* PointsPy::fromSegment(PyObject * args)
{
PyObject *obj;
if (!PyArg_ParseTuple(args, "O", &obj))
return 0;

try {
const PointKernel* points = getPointKernelPtr();
Py::Sequence list(obj);
std::auto_ptr<PointKernel> pts(new PointKernel());
pts->reserve(list.size());
int numPoints = static_cast<int>(points->size());
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
int index = static_cast<int>(Py::Int(*it));
if (index >= 0 && index < numPoints)
pts->push_back(points->getPoint(index));
}

return new PointsPy(pts.release());
}
catch (const Py::Exception&) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "expect a list of int");
return 0;
}
}

PyObject* PointsPy::fromValid(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;

try {
const PointKernel* points = getPointKernelPtr();
std::auto_ptr<PointKernel> pts(new PointKernel());
pts->reserve(points->size());
for (PointKernel::const_iterator it = points->begin(); it != points->end(); ++it) {
if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z))
pts->push_back(*it);
}

return new PointsPy(pts.release());
}
catch (const Py::Exception&) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "expect a list of int");
return 0;
}
}

Py::Int PointsPy::getCountPoints(void) const
{
return Py::Int((long)getPointKernelPtr()->size());
Expand Down
1 change: 1 addition & 0 deletions src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp
Expand Up @@ -649,6 +649,7 @@ Mesh.show(m)
for (std::size_t i = 0; i < parameters.size(); i++)
tuple.setItem(i, Py::Float(parameters[i]));
dict.setItem(Py::String("Probability"), Py::Float(probability));
dict.setItem(Py::String("Parameters"), tuple);

return dict;
}
Expand Down
24 changes: 15 additions & 9 deletions src/Mod/ReverseEngineering/App/RegionGrowing.cpp
Expand Up @@ -26,6 +26,7 @@
#include "RegionGrowing.h"
#include <Mod/Points/App/Points.h>
#include <Base/Exception.h>
#include <boost/math/special_functions/fpclassify.hpp>

#if defined(HAVE_PCL_FILTERS)
#include <pcl/filters/passthrough.h>
Expand Down Expand Up @@ -55,7 +56,8 @@ void RegionGrowing::perform(int ksearch)
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
cloud->reserve(myPoints.size());
for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) {
cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z));
if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z))
cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z));
}

//normal estimation
Expand Down Expand Up @@ -102,19 +104,23 @@ void RegionGrowing::perform(const std::vector<Base::Vector3f>& myNormals)

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
cloud->reserve(myPoints.size());
for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) {
cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z));
pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
normals->reserve(myNormals.size());

std::size_t num_points = myPoints.size();
const std::vector<Base::Vector3f>& points = myPoints.getBasicPoints();
for (std::size_t index=0; index<num_points; index++) {
const Base::Vector3f& p = points[index];
const Base::Vector3f& n = myNormals[index];
if (!boost::math::isnan(p.x) && !boost::math::isnan(p.y) && !boost::math::isnan(p.z)) {
cloud->push_back(pcl::PointXYZ(p.x, p.y, p.z));
normals->push_back(pcl::Normal(n.x, n.y, n.z));
}
}

pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ> > (new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud (cloud);

pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
normals->reserve(myNormals.size());
for (std::vector<Base::Vector3f>::const_iterator it = myNormals.begin(); it != myNormals.end(); ++it) {
normals->push_back(pcl::Normal(it->x, it->y, it->z));
}

// pass through
pcl::IndicesPtr indices (new std::vector <int>);
pcl::PassThrough<pcl::PointXYZ> pass;
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/ReverseEngineering/App/SampleConsensus.cpp
Expand Up @@ -26,6 +26,7 @@
#include "SampleConsensus.h"
#include <Mod/Points/App/Points.h>
#include <Base/Exception.h>
#include <boost/math/special_functions/fpclassify.hpp>

#if defined(HAVE_PCL_SAMPLE_CONSENSUS)
#include <pcl/point_types.h>
Expand All @@ -48,7 +49,8 @@ double SampleConsensus::perform(std::vector<float>& parameters)
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
cloud->reserve(myPoints.size());
for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) {
cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z));
if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z))
cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z));
}

cloud->width = int (cloud->points.size ());
Expand Down

0 comments on commit ec992ae

Please sign in to comment.