From 7bdecf9b38cdc83e32168277c7cb3aa72f199302 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 20 Feb 2016 22:19:47 +0100 Subject: [PATCH] + handling of organized point cloud --- src/Mod/Points/App/AppPoints.cpp | 2 ++ src/Mod/Points/App/AppPointsPy.cpp | 43 ++++++++++++++++++++++++++-- src/Mod/Points/App/PointsAlgos.cpp | 20 +++++++++++++ src/Mod/Points/App/PointsAlgos.h | 4 +++ src/Mod/Points/App/PointsFeature.cpp | 23 +++++++++++++++ src/Mod/Points/App/PointsFeature.h | 24 ++++++++++++++++ src/Mod/Points/Gui/AppPointsGui.cpp | 7 +++-- src/Mod/Points/Gui/ViewProvider.cpp | 24 ++++++++++++++++ src/Mod/Points/Gui/ViewProvider.h | 17 +++++++++++ 9 files changed, 159 insertions(+), 5 deletions(-) diff --git a/src/Mod/Points/App/AppPoints.cpp b/src/Mod/Points/App/AppPoints.cpp index fa7905546..2fddf9af9 100644 --- a/src/Mod/Points/App/AppPoints.cpp +++ b/src/Mod/Points/App/AppPoints.cpp @@ -57,7 +57,9 @@ PyMODINIT_FUNC initPoints() // add data types Points::Feature ::init(); + Points::Organized ::init(); Points::FeatureCustom ::init(); + Points::OrganizedCustom ::init(); Points::FeaturePython ::init(); Points::ViewFeature ::init(); } diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index fd0e11c40..38242adcf 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -104,8 +104,28 @@ private: reader->read(EncodedName); App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + + Points::Feature *pcFeature = 0; if (reader->hasProperties()) { - Points::FeatureCustom *pcFeature = new Points::FeatureCustom(); + // is organized in a grid structure? + if (reader->isOrganized()) { + pcFeature = new Points::OrganizedCustom(); + + App::PropertyInteger* width = static_cast + (pcFeature->getPropertyByName("Width")); + if (width) { + width->setValue(reader->getWidth()); + } + App::PropertyInteger* height = static_cast + (pcFeature->getPropertyByName("Height")); + if (height) { + height->setValue(reader->getHeight()); + } + } + else { + pcFeature = new Points::FeatureCustom(); + } + pcFeature->Points.setValue(reader->getPoints()); // add gray values if (reader->hasIntensities()) { @@ -190,8 +210,27 @@ private: pcDoc = App::GetApplication().newDocument(DocName); } + Points::Feature *pcFeature = 0; if (reader->hasProperties()) { - Points::FeatureCustom *pcFeature = new Points::FeatureCustom(); + // is organized in a grid structure? + if (reader->isOrganized()) { + pcFeature = new Points::OrganizedCustom(); + + App::PropertyInteger* width = static_cast + (pcFeature->getPropertyByName("Width")); + if (width) { + width->setValue(reader->getWidth()); + } + App::PropertyInteger* height = static_cast + (pcFeature->getPropertyByName("Height")); + if (height) { + height->setValue(reader->getHeight()); + } + } + else { + pcFeature = new Points::FeatureCustom(); + } + pcFeature->Points.setValue(reader->getPoints()); // add gray values if (reader->hasIntensities()) { diff --git a/src/Mod/Points/App/PointsAlgos.cpp b/src/Mod/Points/App/PointsAlgos.cpp index 4e534e506..5998eef1b 100644 --- a/src/Mod/Points/App/PointsAlgos.cpp +++ b/src/Mod/Points/App/PointsAlgos.cpp @@ -122,6 +122,8 @@ void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName) Reader::Reader() { + width = 0; + height = 0; } Reader::~Reader() @@ -175,6 +177,21 @@ bool Reader::hasNormals() const return (!normals.empty()); } +bool Reader::isOrganized() const +{ + return (width > 1 && height > 1); +} + +int Reader::getWidth() const +{ + return width; +} + +int Reader::getHeight() const +{ + return height; +} + // ---------------------------------------------------------------------------- AscReader::AscReader() @@ -351,6 +368,9 @@ void PcdReader::read(const std::string& filename) hasColors = true; } + width = cloud2.width; + height = cloud2.height; + if (hasNormals && hasColors) { pcl::PointCloud cloud_in; pcl::io::loadPCDFile(filename, cloud_in); diff --git a/src/Mod/Points/App/PointsAlgos.h b/src/Mod/Points/App/PointsAlgos.h index b24d9d576..dd62cc593 100644 --- a/src/Mod/Points/App/PointsAlgos.h +++ b/src/Mod/Points/App/PointsAlgos.h @@ -59,12 +59,16 @@ public: bool hasColors() const; const std::vector& getNormals() const; bool hasNormals() const; + bool isOrganized() const; + int getWidth() const; + int getHeight() const; protected: PointKernel points; std::vector intensity; std::vector colors; std::vector normals; + int width, height; }; class AscReader : public Reader diff --git a/src/Mod/Points/App/PointsFeature.cpp b/src/Mod/Points/App/PointsFeature.cpp index 9bc1c9833..eabc65df4 100644 --- a/src/Mod/Points/App/PointsFeature.cpp +++ b/src/Mod/Points/App/PointsFeature.cpp @@ -91,6 +91,20 @@ void Feature::onChanged(const App::Property* prop) // --------------------------------------------------------- +PROPERTY_SOURCE(Points::Organized, Points::Feature) + +Organized::Organized() +{ + ADD_PROPERTY_TYPE(Width,(1),"Width",App::Prop_ReadOnly,"Width"); + ADD_PROPERTY_TYPE(Height,(1),"Height",App::Prop_ReadOnly,"Height"); +} + +Organized::~Organized() +{ +} + +// --------------------------------------------------------- + namespace App { /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Points::FeatureCustom, Points::Feature) @@ -100,6 +114,15 @@ PROPERTY_SOURCE_TEMPLATE(Points::FeatureCustom, Points::Feature) template class PointsExport FeatureCustomT; } +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Points::OrganizedCustom, Points::Organized) +/// @endcond + +// explicit template instantiation +template class PointsExport FeatureCustomT; +} + // --------------------------------------------------------- namespace App { diff --git a/src/Mod/Points/App/PointsFeature.h b/src/Mod/Points/App/PointsFeature.h index 963b73e7b..be8a5cf03 100644 --- a/src/Mod/Points/App/PointsFeature.h +++ b/src/Mod/Points/App/PointsFeature.h @@ -76,7 +76,31 @@ public: PropertyPointKernel Points; /**< The point kernel property. */ }; +/** Feature for organized points. + */ +class PointsExport Organized : public Feature +{ + PROPERTY_HEADER(Points::Organized); + +public: + /// Constructor + Organized(void); + virtual ~Organized(void); + + App::PropertyInteger Width; + App::PropertyInteger Height; + + /** @name methods overide Feature */ + //@{ + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "PointsGui::ViewProviderOrganized"; + } + //@} +}; + typedef App::FeatureCustomT FeatureCustom; +typedef App::FeatureCustomT OrganizedCustom; typedef App::FeaturePythonT FeaturePython; } //namespace Points diff --git a/src/Mod/Points/Gui/AppPointsGui.cpp b/src/Mod/Points/Gui/AppPointsGui.cpp index ed79d26f0..bd6dbb0ed 100644 --- a/src/Mod/Points/Gui/AppPointsGui.cpp +++ b/src/Mod/Points/Gui/AppPointsGui.cpp @@ -87,9 +87,10 @@ PyMODINIT_FUNC initPointsGui() // instantiating the commands CreatePointsCommands(); - PointsGui::ViewProviderPoints::init(); - PointsGui::ViewProviderPython::init(); - PointsGui::Workbench ::init(); + PointsGui::ViewProviderPoints ::init(); + PointsGui::ViewProviderOrganized ::init(); + PointsGui::ViewProviderPython ::init(); + PointsGui::Workbench ::init(); Gui::ViewProviderBuilder::add( Points::PropertyPointKernel::getClassTypeId(), PointsGui::ViewProviderPoints::getClassTypeId()); diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index ca4a39226..17c55289b 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -456,6 +456,30 @@ void ViewProviderPoints::cut(const std::vector& picked, Gui::View3DInve // ------------------------------------------------- +PROPERTY_SOURCE(PointsGui::ViewProviderOrganized, PointsGui::ViewProviderPoints) + +ViewProviderOrganized::ViewProviderOrganized() +{ +} + +ViewProviderOrganized::~ViewProviderOrganized() +{ +} + +void ViewProviderOrganized::updateData(const App::Property* prop) +{ + Gui::ViewProviderGeometryObject::updateData(prop); + if (prop->getTypeId() == Points::PropertyPointKernel::getClassTypeId()) { + ViewProviderPointsBuilder builder; + builder.createPoints(prop, pcPointsCoord, pcPoints); + + // The number of points might have changed, so force also a resize of the Inventor internals + setActiveMode(); + } +} + +// ------------------------------------------------- + namespace Gui { /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(PointsGui::ViewProviderPython, PointsGui::ViewProviderPoints) diff --git a/src/Mod/Points/Gui/ViewProvider.h b/src/Mod/Points/Gui/ViewProvider.h index e4957a55a..bc2928672 100644 --- a/src/Mod/Points/Gui/ViewProvider.h +++ b/src/Mod/Points/Gui/ViewProvider.h @@ -119,6 +119,23 @@ private: static App::PropertyFloatConstraint::Constraints floatRange; }; +/** + * The ViewProviderOrganized class creates + * a node representing the organized points. + * @author Werner Mayer + */ +class PointsGuiExport ViewProviderOrganized : public ViewProviderPoints +{ + PROPERTY_HEADER(PointsGui::ViewProviderOrganized); + +public: + ViewProviderOrganized(); + virtual ~ViewProviderOrganized(); + + /// Update the point representation + virtual void updateData(const App::Property*); +}; + typedef Gui::ViewProviderPythonFeatureT ViewProviderPython; } // namespace PointsGui