From 5e0f2ae418b95ffe7268f5a4ecbc3a40fa8cb9cc Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 31 Dec 2015 15:50:56 +0100 Subject: [PATCH] + use custom points feature to read in ply with properties --- src/Mod/Points/App/AppPointsPy.cpp | 98 ++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 18 deletions(-) diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index cf55676cf..d79aca74b 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -45,6 +45,7 @@ #include "PointsPy.h" #include "PointsAlgos.h" #include "PointsFeature.h" +#include "Properties.h" using namespace Points; @@ -77,18 +78,48 @@ open(PyObject *self, PyObject *args) } #ifdef HAVE_PCL_IO else if (file.hasExtension("ply")) { - // create new document import + PlyReader reader; + reader.read(EncodedName); + App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); - Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()); - Points::PointKernel pkTemp; + if (reader.hasProperties()) { + Points::FeatureCustom *pcFeature = new Points::FeatureCustom(); + pcFeature->Points.setValue(reader.getPoints()); + // add gray values + if (reader.hasIntensities()) { + Points::PropertyGreyValueList* prop = static_cast + (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); + if (prop) { + prop->setValues(reader.getIntensities()); + } + } + // add colors + if (reader.hasColors()) { + App::PropertyColorList* prop = static_cast + (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); + if (prop) { + prop->setValues(reader.getColors()); + } + } + // add normals + if (reader.hasNormals()) { + Points::PropertyNormalList* prop = static_cast + (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); + if (prop) { + prop->setValues(reader.getNormals()); + } + } - // pcl test - pcl::PointCloud cloud_in; - pcl::io::loadPLYFile(EncodedName.c_str(),cloud_in); - - for (pcl::PointCloud::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) - pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z)); - pcFeature->Points.setValue( pkTemp ); + // delayed adding of the points feature + pcDoc->addObject(pcFeature, file.fileNamePure().c_str()); + pcDoc->recomputeFeature(pcFeature); + } + else { + Points::Feature *pcFeature = static_cast + (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); + pcFeature->Points.setValue(reader.getPoints()); + pcDoc->recomputeFeature(pcFeature); + } } #endif else { @@ -136,16 +167,47 @@ insert(PyObject *self, PyObject *args) pcDoc = App::GetApplication().newDocument(DocName); } - Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()); - Points::PointKernel pkTemp; + PlyReader reader; + reader.read(EncodedName); - // pcl test - pcl::PointCloud cloud_in; - pcl::io::loadPLYFile(EncodedName.c_str(),cloud_in); + if (reader.hasProperties()) { + Points::FeatureCustom *pcFeature = new Points::FeatureCustom(); + pcFeature->Points.setValue(reader.getPoints()); + // add gray values + if (reader.hasIntensities()) { + Points::PropertyGreyValueList* prop = static_cast + (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); + if (prop) { + prop->setValues(reader.getIntensities()); + } + } + // add colors + if (reader.hasColors()) { + App::PropertyColorList* prop = static_cast + (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); + if (prop) { + prop->setValues(reader.getColors()); + } + } + // add normals + if (reader.hasNormals()) { + Points::PropertyNormalList* prop = static_cast + (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); + if (prop) { + prop->setValues(reader.getNormals()); + } + } - for (pcl::PointCloud::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) - pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z)); - pcFeature->Points.setValue( pkTemp ); + // delayed adding of the points feature + pcDoc->addObject(pcFeature, file.fileNamePure().c_str()); + pcDoc->recomputeFeature(pcFeature); + } + else { + Points::Feature *pcFeature = static_cast + (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); + pcFeature->Points.setValue(reader.getPoints()); + pcDoc->recomputeFeature(pcFeature); + } } #endif else {