+ filter out invalid points
This commit is contained in:
parent
f336b7ed67
commit
ec992ae1dc
|
@ -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>
|
||||
|
|
|
@ -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"
|
||||
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
@ -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 ());
|
||||
|
|
Loading…
Reference in New Issue
Block a user