void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) { // create the polygon from the picked points Base::Polygon2D cPoly; for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it) { cPoly.Add(Base::Vector2D((*it)[0],(*it)[1])); } // get a reference to the point feature Points::Feature* fea = static_cast<Points::Feature*>(pcObject); const Points::PointKernel& points = fea->Points.getValue(); SoCamera* pCam = Viewer.getSoRenderManager()->getCamera(); SbViewVolume vol = pCam->getViewVolume(); // search for all points inside/outside the polygon Points::PointKernel newKernel; newKernel.reserve(points.size()); bool invalidatePoints = false; double nan = std::numeric_limits<double>::quiet_NaN(); for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt) { // valid point? Base::Vector3d vec(*jt); if (!(boost::math::isnan(jt->x) || boost::math::isnan(jt->y) || boost::math::isnan(jt->z))) { 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]))) { invalidatePoints = true; vec.Set(nan, nan, nan); } } newKernel.push_back(vec); } if (invalidatePoints) { //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); // unset the modified flag because we don't need the features' execute() to be called Gui::Application::Instance->activeDocument()->commitCommand(); fea->purgeTouched(); } }
void ViewProviderPoints::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) { // create the polygon from the picked points Base::Polygon2D cPoly; for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it) { cPoly.Add(Base::Vector2D((*it)[0],(*it)[1])); } // get a reference to the point feature Points::Feature* fea = (Points::Feature*)pcObject; const Points::PointKernel& points = fea->Points.getValue(); SoCamera* pCam = Viewer.getSoRenderManager()->getCamera(); 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 ) { 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 (newKernel.size() == points.size()) 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); // unset the modified flag because we don't need the features' execute() to be called Gui::Application::Instance->activeDocument()->commitCommand(); fea->purgeTouched(); }
Py::Object open(const Py::Tuple& args) { char* Name; if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); try { Base::Console().Log("Open in Points with %s",EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension().empty()) throw Py::RuntimeError("No file extension"); 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 ); } #ifdef HAVE_PCL_IO else if (file.hasExtension("ply")) { PlyReader reader; 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 colors if (reader.hasColors()) { App::PropertyColorList* prop = static_cast<App::PropertyColorList*> (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); if (prop) { prop->setValues(reader.getColors()); } } // 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); } else { Points::Feature *pcFeature = static_cast<Points::Feature*> (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); pcFeature->Points.setValue(reader.getPoints()); pcDoc->recomputeFeature(pcFeature); } } #endif else { throw Py::RuntimeError("Unsupported file extension"); } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }