Skip to content

Commit

Permalink
+ fixes #1592: Import colored PCL point clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 14, 2016
1 parent 237c74c commit 1a64c3f
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 136 deletions.
192 changes: 94 additions & 98 deletions src/Mod/Points/App/AppPointsPy.cpp
Expand Up @@ -23,6 +23,7 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <memory>
#endif

// PCL test
Expand Down Expand Up @@ -84,63 +85,62 @@ class Module : public Py::ExtensionModule<Module>
if (file.extension().empty())
throw Py::RuntimeError("No file extension");

std::auto_ptr<Reader> reader;
if (file.hasExtension("asc")) {
// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
Points::PointKernel pkTemp;
pkTemp.load(EncodedName.c_str());
pcFeature->Points.setValue( pkTemp );

reader.reset(new AscReader);
}
#ifdef HAVE_PCL_IO
else if (file.hasExtension("ply")) {
PlyReader reader;
reader.read(EncodedName);
reader.reset(new PlyReader);
}
else if (file.hasExtension("pcd")) {
reader.reset(new PcdReader);
}
#endif
else {
throw Py::RuntimeError("Unsupported file extension");
}

App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
if (prop) {
prop->setValues(reader.getIntensities());
}
}
// add colors
if (reader.hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader.getColors());
}
reader->read(EncodedName);

App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
if (prop) {
prop->setValues(reader->getIntensities());
}
// add normals
if (reader.hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
if (prop) {
prop->setValues(reader.getNormals());
}
}
// add colors
if (reader->hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader->getColors());
}

// delayed adding of the points feature
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
pcDoc->recomputeFeature(pcFeature);
}
else {
Points::Feature *pcFeature = static_cast<Points::Feature*>
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
pcFeature->Points.setValue(reader.getPoints());
pcDoc->recomputeFeature(pcFeature);
// add normals
if (reader->hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
if (prop) {
prop->setValues(reader->getNormals());
}
}

// delayed adding of the points feature
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
pcDoc->recomputeFeature(pcFeature);
}
#endif
else {
throw Py::RuntimeError("Unsupported file extension");
Points::Feature *pcFeature = static_cast<Points::Feature*>
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
pcFeature->Points.setValue(reader->getPoints());
pcDoc->recomputeFeature(pcFeature);
}
}
catch (const Base::Exception& e) {
Expand All @@ -167,70 +167,66 @@ class Module : public Py::ExtensionModule<Module>
if (file.extension().empty())
throw Py::RuntimeError("No file extension");

std::auto_ptr<Reader> reader;
if (file.hasExtension("asc")) {
// add Import feature
App::Document *pcDoc = App::GetApplication().getDocument(DocName);
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument(DocName);
}

Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
Points::PointKernel pkTemp;
pkTemp.load(EncodedName.c_str());
pcFeature->Points.setValue( pkTemp );
reader.reset(new AscReader);
}
#ifdef HAVE_PCL_IO
else if (file.hasExtension("ply")) {
App::Document *pcDoc = App::GetApplication().getDocument(DocName);
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument(DocName);
}
reader.reset(new PlyReader);
}
else if (file.hasExtension("pcd")) {
reader.reset(new PcdReader);
}
#endif
else {
throw Py::RuntimeError("Unsupported file extension");
}

PlyReader reader;
reader.read(EncodedName);
reader->read(EncodedName);

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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
if (prop) {
prop->setValues(reader.getIntensities());
}
}
// add colors
if (reader.hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader.getColors());
}
App::Document *pcDoc = App::GetApplication().getDocument(DocName);
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument(DocName);
}

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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
if (prop) {
prop->setValues(reader->getIntensities());
}
// add normals
if (reader.hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
if (prop) {
prop->setValues(reader.getNormals());
}
}
// add colors
if (reader->hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader->getColors());
}

// delayed adding of the points feature
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
pcDoc->recomputeFeature(pcFeature);
}
else {
Points::Feature *pcFeature = static_cast<Points::Feature*>
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
pcFeature->Points.setValue(reader.getPoints());
pcDoc->recomputeFeature(pcFeature);
// add normals
if (reader->hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
if (prop) {
prop->setValues(reader->getNormals());
}
}

// delayed adding of the points feature
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
pcDoc->recomputeFeature(pcFeature);
}
#endif
else {
throw Py::RuntimeError("Unsupported file extension");
Points::Feature *pcFeature = static_cast<Points::Feature*>
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
pcFeature->Points.setValue(reader->getPoints());
pcDoc->recomputeFeature(pcFeature);
}
}
catch (const Base::Exception& e) {
Expand Down

0 comments on commit 1a64c3f

Please sign in to comment.