From 5342b67122a2f4aeeb2f77872f9723d23cd955ec Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 23 Feb 2016 19:47:54 +0100 Subject: [PATCH] + when cutting scattered points then also remove colors, grey values or normals if available --- src/Mod/Points/App/Properties.cpp | 8 ++-- src/Mod/Points/Gui/ViewProvider.cpp | 60 ++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/Mod/Points/App/Properties.cpp b/src/Mod/Points/App/Properties.cpp index 1c94f60d8..0c901023b 100644 --- a/src/Mod/Points/App/Properties.cpp +++ b/src/Mod/Points/App/Properties.cpp @@ -190,22 +190,21 @@ unsigned int PropertyGreyValueList::getMemSize (void) const void PropertyGreyValueList::removeIndices( const std::vector& uIndices ) { -#if 0 // We need a sorted array std::vector uSortedInds = uIndices; std::sort(uSortedInds.begin(), uSortedInds.end()); - const std::vector& rValueList = getValues(); + const std::vector& rValueList = getValues(); assert( uSortedInds.size() <= rValueList.size() ); if ( uSortedInds.size() > rValueList.size() ) return; - std::vector remainValue; + std::vector remainValue; remainValue.reserve(rValueList.size() - uSortedInds.size()); std::vector::iterator pos = uSortedInds.begin(); - for ( std::vector::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) { + for ( std::vector::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) { unsigned long index = it - rValueList.begin(); if (pos == uSortedInds.end()) remainValue.push_back( *it ); @@ -216,7 +215,6 @@ void PropertyGreyValueList::removeIndices( const std::vector& uIn } setValues(remainValue); -#endif } PropertyNormalList::PropertyNormalList() diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index a3d35e0fc..5d41b4a5a 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -428,6 +428,15 @@ void ViewProviderScattered::updateData(const App::Property* prop) // The number of points might have changed, so force also a resize of the Inventor internals setActiveMode(); } + else if (prop->getTypeId() == Points::PropertyNormalList::getClassTypeId()) { + setActiveMode(); + } + else if (prop->getTypeId() == Points::PropertyGreyValueList::getClassTypeId()) { + setActiveMode(); + } + else if (prop->getTypeId() == App::PropertyColorList::getClassTypeId()) { + setActiveMode(); + } } void ViewProviderScattered::cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) @@ -446,24 +455,63 @@ void ViewProviderScattered::cut(const std::vector& picked, Gui::View3DI SbViewVolume vol = pCam->getViewVolume(); // search for all points inside/outside the polygon - Points::PointKernel newKernel; - for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt) { + std::vector removeIndices; + removeIndices.reserve(points.size()); + + unsigned long index = 0; + for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt, ++index) { SbVec3f pt(jt->x,jt->y,jt->z); // project from 3d to 2d vol.projectToScreen(pt, pt); - if (!cPoly.Contains(Base::Vector2D(pt[0],pt[1]))) - newKernel.push_back(*jt); + if (cPoly.Contains(Base::Vector2D(pt[0],pt[1]))) + removeIndices.push_back(index); } - if (newKernel.size() == points.size()) + if (removeIndices.empty()) return; // nothing needs to be done //Remove the points from the cloud and open a transaction object for the undo/redo stuff Gui::Application::Instance->activeDocument()->openCommand("Cut points"); // sets the points outside the polygon to update the Inventor node - fea->Points.setValue(newKernel); + fea->Points.removeIndices(removeIndices); + + std::map Map; + pcObject->getPropertyMap(Map); + + for (std::map::iterator it = Map.begin(); it != Map.end(); ++it) { + Base::Type type = it->second->getTypeId(); + if (type == Points::PropertyNormalList::getClassTypeId()) { + static_cast(it->second)->removeIndices(removeIndices); + } + else if (type == Points::PropertyGreyValueList::getClassTypeId()) { + static_cast(it->second)->removeIndices(removeIndices); + } + else if (type == App::PropertyColorList::getClassTypeId()) { + //static_cast(it->second)->removeIndices(removeIndices); + const std::vector& colors = static_cast(it->second)->getValues(); + + if (removeIndices.size() > colors.size()) + break; + + std::vector remainValue; + remainValue.reserve(colors.size() - removeIndices.size()); + + std::vector::iterator pos = removeIndices.begin(); + for (std::vector::const_iterator jt = colors.begin(); jt != colors.end(); ++jt) { + unsigned long index = jt - colors.begin(); + if (pos == removeIndices.end()) + remainValue.push_back( *jt ); + else if (index != *pos) + remainValue.push_back( *jt ); + else + ++pos; + } + + static_cast(it->second)->setValues(remainValue); + } + } // unset the modified flag because we don't need the features' execute() to be called Gui::Application::Instance->activeDocument()->commitCommand();