+ view provider for scattered and organized point clouds
This commit is contained in:
parent
7bdecf9b38
commit
24e4e08be5
|
@ -155,12 +155,14 @@ private:
|
||||||
// delayed adding of the points feature
|
// delayed adding of the points feature
|
||||||
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
|
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
|
||||||
pcDoc->recomputeFeature(pcFeature);
|
pcDoc->recomputeFeature(pcFeature);
|
||||||
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Points::Feature *pcFeature = static_cast<Points::Feature*>
|
Points::Feature *pcFeature = static_cast<Points::Feature*>
|
||||||
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
|
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
|
||||||
pcFeature->Points.setValue(reader->getPoints());
|
pcFeature->Points.setValue(reader->getPoints());
|
||||||
pcDoc->recomputeFeature(pcFeature);
|
pcDoc->recomputeFeature(pcFeature);
|
||||||
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
|
@ -260,12 +262,14 @@ private:
|
||||||
// delayed adding of the points feature
|
// delayed adding of the points feature
|
||||||
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
|
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
|
||||||
pcDoc->recomputeFeature(pcFeature);
|
pcDoc->recomputeFeature(pcFeature);
|
||||||
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Points::Feature *pcFeature = static_cast<Points::Feature*>
|
Points::Feature *pcFeature = static_cast<Points::Feature*>
|
||||||
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
|
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
|
||||||
pcFeature->Points.setValue(reader->getPoints());
|
pcFeature->Points.setValue(reader->getPoints());
|
||||||
pcDoc->recomputeFeature(pcFeature);
|
pcDoc->recomputeFeature(pcFeature);
|
||||||
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
|
|
|
@ -54,6 +54,11 @@ Feature::~Feature()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short Feature::mustExecute() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
App::DocumentObjectExecReturn *Feature::execute(void)
|
App::DocumentObjectExecReturn *Feature::execute(void)
|
||||||
{
|
{
|
||||||
this->Points.touch();
|
this->Points.touch();
|
||||||
|
@ -95,8 +100,8 @@ PROPERTY_SOURCE(Points::Organized, Points::Feature)
|
||||||
|
|
||||||
Organized::Organized()
|
Organized::Organized()
|
||||||
{
|
{
|
||||||
ADD_PROPERTY_TYPE(Width,(1),"Width",App::Prop_ReadOnly,"Width");
|
ADD_PROPERTY_TYPE(Width,(1),"Organized points",App::Prop_ReadOnly,"Width of the frame");
|
||||||
ADD_PROPERTY_TYPE(Height,(1),"Height",App::Prop_ReadOnly,"Height");
|
ADD_PROPERTY_TYPE(Height,(1),"Organized points",App::Prop_ReadOnly,"Height of the frame");
|
||||||
}
|
}
|
||||||
|
|
||||||
Organized::~Organized()
|
Organized::~Organized()
|
||||||
|
|
|
@ -62,11 +62,12 @@ public:
|
||||||
//@{
|
//@{
|
||||||
void Restore(Base::XMLReader &reader);
|
void Restore(Base::XMLReader &reader);
|
||||||
void RestoreDocFile(Base::Reader &reader);
|
void RestoreDocFile(Base::Reader &reader);
|
||||||
|
short mustExecute() const;
|
||||||
/// recalculate the Feature
|
/// recalculate the Feature
|
||||||
virtual App::DocumentObjectExecReturn *execute(void);
|
virtual App::DocumentObjectExecReturn *execute(void);
|
||||||
/// returns the type name of the ViewProvider
|
/// returns the type name of the ViewProvider
|
||||||
virtual const char* getViewProviderName(void) const {
|
virtual const char* getViewProviderName(void) const {
|
||||||
return "PointsGui::ViewProviderPoints";
|
return "PointsGui::ViewProviderScattered";
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void onChanged(const App::Property* prop);
|
void onChanged(const App::Property* prop);
|
||||||
|
|
|
@ -88,6 +88,7 @@ PyMODINIT_FUNC initPointsGui()
|
||||||
CreatePointsCommands();
|
CreatePointsCommands();
|
||||||
|
|
||||||
PointsGui::ViewProviderPoints ::init();
|
PointsGui::ViewProviderPoints ::init();
|
||||||
|
PointsGui::ViewProviderScattered ::init();
|
||||||
PointsGui::ViewProviderOrganized ::init();
|
PointsGui::ViewProviderOrganized ::init();
|
||||||
PointsGui::ViewProviderPython ::init();
|
PointsGui::ViewProviderPython ::init();
|
||||||
PointsGui::Workbench ::init();
|
PointsGui::Workbench ::init();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
# include <Inventor/nodes/SoCoordinate3.h>
|
# include <Inventor/nodes/SoCoordinate3.h>
|
||||||
# include <Inventor/nodes/SoDrawStyle.h>
|
# include <Inventor/nodes/SoDrawStyle.h>
|
||||||
# include <Inventor/nodes/SoPointSet.h>
|
# include <Inventor/nodes/SoPointSet.h>
|
||||||
|
# include <Inventor/nodes/SoIndexedPointSet.h>
|
||||||
# include <Inventor/nodes/SoMaterial.h>
|
# include <Inventor/nodes/SoMaterial.h>
|
||||||
# include <Inventor/nodes/SoMaterialBinding.h>
|
# include <Inventor/nodes/SoMaterialBinding.h>
|
||||||
# include <Inventor/nodes/SoNormal.h>
|
# include <Inventor/nodes/SoNormal.h>
|
||||||
|
@ -35,6 +36,9 @@
|
||||||
# include <Inventor/events/SoMouseButtonEvent.h>
|
# include <Inventor/events/SoMouseButtonEvent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/math/special_functions/fpclassify.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
/// Here the FreeCAD includes sorted by Base,App,Gui,...
|
/// Here the FreeCAD includes sorted by Base,App,Gui,...
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
#include <Base/Parameter.h>
|
#include <Base/Parameter.h>
|
||||||
|
@ -60,7 +64,7 @@ using namespace PointsGui;
|
||||||
using namespace Points;
|
using namespace Points;
|
||||||
|
|
||||||
|
|
||||||
PROPERTY_SOURCE(PointsGui::ViewProviderPoints, Gui::ViewProviderGeometryObject)
|
PROPERTY_SOURCE_ABSTRACT(PointsGui::ViewProviderPoints, Gui::ViewProviderGeometryObject)
|
||||||
|
|
||||||
|
|
||||||
App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0,64.0,1.0};
|
App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0,64.0,1.0};
|
||||||
|
@ -78,8 +82,6 @@ ViewProviderPoints::ViewProviderPoints()
|
||||||
|
|
||||||
pcPointsCoord = new SoCoordinate3();
|
pcPointsCoord = new SoCoordinate3();
|
||||||
pcPointsCoord->ref();
|
pcPointsCoord->ref();
|
||||||
pcPoints = new SoPointSet();
|
|
||||||
pcPoints->ref();
|
|
||||||
pcPointsNormal = new SoNormal();
|
pcPointsNormal = new SoNormal();
|
||||||
pcPointsNormal->ref();
|
pcPointsNormal->ref();
|
||||||
pcColorMat = new SoMaterial;
|
pcColorMat = new SoMaterial;
|
||||||
|
@ -95,7 +97,6 @@ ViewProviderPoints::~ViewProviderPoints()
|
||||||
{
|
{
|
||||||
pcHighlight->unref();
|
pcHighlight->unref();
|
||||||
pcPointsCoord->unref();
|
pcPointsCoord->unref();
|
||||||
pcPoints->unref();
|
|
||||||
pcPointsNormal->unref();
|
pcPointsNormal->unref();
|
||||||
pcColorMat->unref();
|
pcColorMat->unref();
|
||||||
pcPointStyle->unref();
|
pcPointStyle->unref();
|
||||||
|
@ -190,52 +191,6 @@ void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcPrope
|
||||||
pcPointsNormal->vector.finishEditing();
|
pcPointsNormal->vector.finishEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderPoints::attach(App::DocumentObject* pcObj)
|
|
||||||
{
|
|
||||||
// call parent's attach to define display modes
|
|
||||||
ViewProviderGeometryObject::attach(pcObj);
|
|
||||||
|
|
||||||
pcHighlight->objectName = pcObj->getNameInDocument();
|
|
||||||
pcHighlight->documentName = pcObj->getDocument()->getName();
|
|
||||||
pcHighlight->subElementName = "Main";
|
|
||||||
|
|
||||||
// Hilight for selection
|
|
||||||
pcHighlight->addChild(pcPointsCoord);
|
|
||||||
pcHighlight->addChild(pcPoints);
|
|
||||||
|
|
||||||
std::vector<std::string> modes = getDisplayModes();
|
|
||||||
|
|
||||||
// points part ---------------------------------------------
|
|
||||||
SoGroup* pcPointRoot = new SoGroup();
|
|
||||||
pcPointRoot->addChild(pcPointStyle);
|
|
||||||
pcPointRoot->addChild(pcShapeMaterial);
|
|
||||||
pcPointRoot->addChild(pcHighlight);
|
|
||||||
addDisplayMaskMode(pcPointRoot, "Point");
|
|
||||||
|
|
||||||
// points shaded ---------------------------------------------
|
|
||||||
if (std::find(modes.begin(), modes.end(), std::string("Shaded")) != modes.end()) {
|
|
||||||
SoGroup* pcPointShadedRoot = new SoGroup();
|
|
||||||
pcPointShadedRoot->addChild(pcPointStyle);
|
|
||||||
pcPointShadedRoot->addChild(pcShapeMaterial);
|
|
||||||
pcPointShadedRoot->addChild(pcPointsNormal);
|
|
||||||
pcPointShadedRoot->addChild(pcHighlight);
|
|
||||||
addDisplayMaskMode(pcPointShadedRoot, "Shaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
// color shaded ------------------------------------------
|
|
||||||
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
|
|
||||||
std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
|
|
||||||
SoGroup* pcColorShadedRoot = new SoGroup();
|
|
||||||
pcColorShadedRoot->addChild(pcPointStyle);
|
|
||||||
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
|
|
||||||
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
|
|
||||||
pcColorShadedRoot->addChild(pcColorMat);
|
|
||||||
pcColorShadedRoot->addChild(pcMatBinding);
|
|
||||||
pcColorShadedRoot->addChild(pcHighlight);
|
|
||||||
addDisplayMaskMode(pcColorShadedRoot, "Color");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewProviderPoints::setDisplayMode(const char* ModeName)
|
void ViewProviderPoints::setDisplayMode(const char* ModeName)
|
||||||
{
|
{
|
||||||
int numPoints = pcPointsCoord->point.getNum();
|
int numPoints = pcPointsCoord->point.getNum();
|
||||||
|
@ -339,18 +294,6 @@ std::vector<std::string> ViewProviderPoints::getDisplayModes(void) const
|
||||||
return StrList;
|
return StrList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderPoints::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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon ViewProviderPoints::getIcon() const
|
QIcon ViewProviderPoints::getIcon() const
|
||||||
{
|
{
|
||||||
static const char * const Points_Feature_xpm[] = {
|
static const char * const Points_Feature_xpm[] = {
|
||||||
|
@ -414,7 +357,80 @@ void ViewProviderPoints::clipPointsCallback(void * ud, SoEventCallback * n)
|
||||||
view->redraw();
|
view->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderPoints::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
|
// -------------------------------------------------
|
||||||
|
|
||||||
|
PROPERTY_SOURCE(PointsGui::ViewProviderScattered, PointsGui::ViewProviderPoints)
|
||||||
|
|
||||||
|
ViewProviderScattered::ViewProviderScattered()
|
||||||
|
{
|
||||||
|
pcPoints = new SoPointSet();
|
||||||
|
pcPoints->ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewProviderScattered::~ViewProviderScattered()
|
||||||
|
{
|
||||||
|
pcPoints->unref();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewProviderScattered::attach(App::DocumentObject* pcObj)
|
||||||
|
{
|
||||||
|
// call parent's attach to define display modes
|
||||||
|
ViewProviderGeometryObject::attach(pcObj);
|
||||||
|
|
||||||
|
pcHighlight->objectName = pcObj->getNameInDocument();
|
||||||
|
pcHighlight->documentName = pcObj->getDocument()->getName();
|
||||||
|
pcHighlight->subElementName = "Main";
|
||||||
|
|
||||||
|
// Hilight for selection
|
||||||
|
pcHighlight->addChild(pcPointsCoord);
|
||||||
|
pcHighlight->addChild(pcPoints);
|
||||||
|
|
||||||
|
std::vector<std::string> modes = getDisplayModes();
|
||||||
|
|
||||||
|
// points part ---------------------------------------------
|
||||||
|
SoGroup* pcPointRoot = new SoGroup();
|
||||||
|
pcPointRoot->addChild(pcPointStyle);
|
||||||
|
pcPointRoot->addChild(pcShapeMaterial);
|
||||||
|
pcPointRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcPointRoot, "Point");
|
||||||
|
|
||||||
|
// points shaded ---------------------------------------------
|
||||||
|
if (std::find(modes.begin(), modes.end(), std::string("Shaded")) != modes.end()) {
|
||||||
|
SoGroup* pcPointShadedRoot = new SoGroup();
|
||||||
|
pcPointShadedRoot->addChild(pcPointStyle);
|
||||||
|
pcPointShadedRoot->addChild(pcShapeMaterial);
|
||||||
|
pcPointShadedRoot->addChild(pcPointsNormal);
|
||||||
|
pcPointShadedRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcPointShadedRoot, "Shaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
// color shaded ------------------------------------------
|
||||||
|
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
|
||||||
|
std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
|
||||||
|
SoGroup* pcColorShadedRoot = new SoGroup();
|
||||||
|
pcColorShadedRoot->addChild(pcPointStyle);
|
||||||
|
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
|
||||||
|
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
|
||||||
|
pcColorShadedRoot->addChild(pcColorMat);
|
||||||
|
pcColorShadedRoot->addChild(pcMatBinding);
|
||||||
|
pcColorShadedRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcColorShadedRoot, "Color");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewProviderScattered::updateData(const App::Property* prop)
|
||||||
|
{
|
||||||
|
ViewProviderPoints::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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewProviderScattered::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
|
||||||
{
|
{
|
||||||
// create the polygon from the picked points
|
// create the polygon from the picked points
|
||||||
Base::Polygon2D cPoly;
|
Base::Polygon2D cPoly;
|
||||||
|
@ -460,15 +476,64 @@ PROPERTY_SOURCE(PointsGui::ViewProviderOrganized, PointsGui::ViewProviderPoints)
|
||||||
|
|
||||||
ViewProviderOrganized::ViewProviderOrganized()
|
ViewProviderOrganized::ViewProviderOrganized()
|
||||||
{
|
{
|
||||||
|
pcPoints = new SoIndexedPointSet();
|
||||||
|
pcPoints->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewProviderOrganized::~ViewProviderOrganized()
|
ViewProviderOrganized::~ViewProviderOrganized()
|
||||||
{
|
{
|
||||||
|
pcPoints->unref();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewProviderOrganized::attach(App::DocumentObject* pcObj)
|
||||||
|
{
|
||||||
|
// call parent's attach to define display modes
|
||||||
|
ViewProviderGeometryObject::attach(pcObj);
|
||||||
|
|
||||||
|
pcHighlight->objectName = pcObj->getNameInDocument();
|
||||||
|
pcHighlight->documentName = pcObj->getDocument()->getName();
|
||||||
|
pcHighlight->subElementName = "Main";
|
||||||
|
|
||||||
|
// Hilight for selection
|
||||||
|
pcHighlight->addChild(pcPointsCoord);
|
||||||
|
pcHighlight->addChild(pcPoints);
|
||||||
|
|
||||||
|
std::vector<std::string> modes = getDisplayModes();
|
||||||
|
|
||||||
|
// points part ---------------------------------------------
|
||||||
|
SoGroup* pcPointRoot = new SoGroup();
|
||||||
|
pcPointRoot->addChild(pcPointStyle);
|
||||||
|
pcPointRoot->addChild(pcShapeMaterial);
|
||||||
|
pcPointRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcPointRoot, "Point");
|
||||||
|
|
||||||
|
// points shaded ---------------------------------------------
|
||||||
|
if (std::find(modes.begin(), modes.end(), std::string("Shaded")) != modes.end()) {
|
||||||
|
SoGroup* pcPointShadedRoot = new SoGroup();
|
||||||
|
pcPointShadedRoot->addChild(pcPointStyle);
|
||||||
|
pcPointShadedRoot->addChild(pcShapeMaterial);
|
||||||
|
pcPointShadedRoot->addChild(pcPointsNormal);
|
||||||
|
pcPointShadedRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcPointShadedRoot, "Shaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
// color shaded ------------------------------------------
|
||||||
|
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
|
||||||
|
std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
|
||||||
|
SoGroup* pcColorShadedRoot = new SoGroup();
|
||||||
|
pcColorShadedRoot->addChild(pcPointStyle);
|
||||||
|
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
|
||||||
|
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
|
||||||
|
pcColorShadedRoot->addChild(pcColorMat);
|
||||||
|
pcColorShadedRoot->addChild(pcMatBinding);
|
||||||
|
pcColorShadedRoot->addChild(pcHighlight);
|
||||||
|
addDisplayMaskMode(pcColorShadedRoot, "Color");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderOrganized::updateData(const App::Property* prop)
|
void ViewProviderOrganized::updateData(const App::Property* prop)
|
||||||
{
|
{
|
||||||
Gui::ViewProviderGeometryObject::updateData(prop);
|
ViewProviderPoints::updateData(prop);
|
||||||
if (prop->getTypeId() == Points::PropertyPointKernel::getClassTypeId()) {
|
if (prop->getTypeId() == Points::PropertyPointKernel::getClassTypeId()) {
|
||||||
ViewProviderPointsBuilder builder;
|
ViewProviderPointsBuilder builder;
|
||||||
builder.createPoints(prop, pcPointsCoord, pcPoints);
|
builder.createPoints(prop, pcPointsCoord, pcPoints);
|
||||||
|
@ -478,15 +543,66 @@ void ViewProviderOrganized::updateData(const App::Property* prop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewProviderOrganized::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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
namespace Gui {
|
namespace Gui {
|
||||||
/// @cond DOXERR
|
/// @cond DOXERR
|
||||||
PROPERTY_SOURCE_TEMPLATE(PointsGui::ViewProviderPython, PointsGui::ViewProviderPoints)
|
PROPERTY_SOURCE_TEMPLATE(PointsGui::ViewProviderPython, PointsGui::ViewProviderScattered)
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
// explicit template instantiation
|
// explicit template instantiation
|
||||||
template class PointsGuiExport ViewProviderPythonFeatureT<PointsGui::ViewProviderPoints>;
|
template class PointsGuiExport ViewProviderPythonFeatureT<PointsGui::ViewProviderScattered>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
@ -531,3 +647,35 @@ void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordi
|
||||||
points->numPoints = cPts.size();
|
points->numPoints = cPts.size();
|
||||||
coords->point.finishEditing();
|
coords->point.finishEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordinate3* coords, SoIndexedPointSet* points) const
|
||||||
|
{
|
||||||
|
const Points::PropertyPointKernel* prop_points = static_cast<const Points::PropertyPointKernel*>(prop);
|
||||||
|
const Points::PointKernel& cPts = prop_points->getValue();
|
||||||
|
|
||||||
|
coords->point.setNum(cPts.size());
|
||||||
|
SbVec3f* vec = coords->point.startEditing();
|
||||||
|
|
||||||
|
// get all points
|
||||||
|
std::size_t idx=0;
|
||||||
|
std::vector<int32_t> indices;
|
||||||
|
indices.reserve(cPts.size());
|
||||||
|
const std::vector<Points::PointKernel::value_type>& kernel = cPts.getBasicPoints();
|
||||||
|
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
|
||||||
|
vec[idx].setValue(it->x, it->y, it->z);
|
||||||
|
// valid point?
|
||||||
|
if (!(boost::math::isnan(it->x) || boost::math::isnan(it->y) || boost::math::isnan(it->z))) {
|
||||||
|
indices.push_back(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
coords->point.finishEditing();
|
||||||
|
|
||||||
|
// get all point indices
|
||||||
|
idx=0;
|
||||||
|
points->coordIndex.setNum(indices.size());
|
||||||
|
int32_t* pos = points->coordIndex.startEditing();
|
||||||
|
for (std::vector<int32_t>::iterator it = indices.begin(); it != indices.end(); ++it) {
|
||||||
|
pos[idx++] = *it;
|
||||||
|
}
|
||||||
|
points->coordIndex.finishEditing();
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
class SoSwitch;
|
class SoSwitch;
|
||||||
class SoPointSet;
|
class SoPointSet;
|
||||||
|
class SoIndexedPointSet;
|
||||||
class SoLocateHighlight;
|
class SoLocateHighlight;
|
||||||
class SoCoordinate3;
|
class SoCoordinate3;
|
||||||
class SoNormal;
|
class SoNormal;
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
~ViewProviderPointsBuilder(){}
|
~ViewProviderPointsBuilder(){}
|
||||||
virtual void buildNodes(const App::Property*, std::vector<SoNode*>&) const;
|
virtual void buildNodes(const App::Property*, std::vector<SoNode*>&) const;
|
||||||
void createPoints(const App::Property*, SoCoordinate3*, SoPointSet*) const;
|
void createPoints(const App::Property*, SoCoordinate3*, SoPointSet*) const;
|
||||||
|
void createPoints(const App::Property*, SoCoordinate3*, SoIndexedPointSet*) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,17 +80,10 @@ public:
|
||||||
|
|
||||||
App::PropertyFloatConstraint PointSize;
|
App::PropertyFloatConstraint PointSize;
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts the point data from the feature \a pcFeature and creates
|
|
||||||
* an Inventor node \a SoNode with these data.
|
|
||||||
*/
|
|
||||||
virtual void attach(App::DocumentObject *);
|
|
||||||
/// set the viewing mode
|
/// set the viewing mode
|
||||||
virtual void setDisplayMode(const char* ModeName);
|
virtual void setDisplayMode(const char* ModeName);
|
||||||
/// returns a list of all possible modes
|
/// returns a list of all possible modes
|
||||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||||
/// Update the point representation
|
|
||||||
virtual void updateData(const App::Property*);
|
|
||||||
virtual QIcon getIcon() const;
|
virtual QIcon getIcon() const;
|
||||||
|
|
||||||
/// Sets the edit mnode
|
/// Sets the edit mnode
|
||||||
|
@ -105,12 +100,11 @@ protected:
|
||||||
void setVertexColorMode(App::PropertyColorList*);
|
void setVertexColorMode(App::PropertyColorList*);
|
||||||
void setVertexGreyvalueMode(Points::PropertyGreyValueList*);
|
void setVertexGreyvalueMode(Points::PropertyGreyValueList*);
|
||||||
void setVertexNormalMode(Points::PropertyNormalList*);
|
void setVertexNormalMode(Points::PropertyNormalList*);
|
||||||
virtual void cut( const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer);
|
virtual void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Gui::SoFCSelection * pcHighlight;
|
Gui::SoFCSelection * pcHighlight;
|
||||||
SoCoordinate3 * pcPointsCoord;
|
SoCoordinate3 * pcPointsCoord;
|
||||||
SoPointSet * pcPoints;
|
|
||||||
SoMaterial * pcColorMat;
|
SoMaterial * pcColorMat;
|
||||||
SoNormal * pcPointsNormal;
|
SoNormal * pcPointsNormal;
|
||||||
SoDrawStyle * pcPointStyle;
|
SoDrawStyle * pcPointStyle;
|
||||||
|
@ -119,6 +113,34 @@ private:
|
||||||
static App::PropertyFloatConstraint::Constraints floatRange;
|
static App::PropertyFloatConstraint::Constraints floatRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ViewProviderScattered class creates
|
||||||
|
* a node representing the scattered point cloud.
|
||||||
|
* @author Werner Mayer
|
||||||
|
*/
|
||||||
|
class PointsGuiExport ViewProviderScattered : public ViewProviderPoints
|
||||||
|
{
|
||||||
|
PROPERTY_HEADER(PointsGui::ViewProviderScattered);
|
||||||
|
|
||||||
|
public:
|
||||||
|
ViewProviderScattered();
|
||||||
|
virtual ~ViewProviderScattered();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the point data from the feature \a pcFeature and creates
|
||||||
|
* an Inventor node \a SoNode with these data.
|
||||||
|
*/
|
||||||
|
virtual void attach(App::DocumentObject *);
|
||||||
|
/// Update the point representation
|
||||||
|
virtual void updateData(const App::Property*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void cut( const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SoPointSet * pcPoints;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ViewProviderOrganized class creates
|
* The ViewProviderOrganized class creates
|
||||||
* a node representing the organized points.
|
* a node representing the organized points.
|
||||||
|
@ -132,11 +154,22 @@ public:
|
||||||
ViewProviderOrganized();
|
ViewProviderOrganized();
|
||||||
virtual ~ViewProviderOrganized();
|
virtual ~ViewProviderOrganized();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the point data from the feature \a pcFeature and creates
|
||||||
|
* an Inventor node \a SoNode with these data.
|
||||||
|
*/
|
||||||
|
virtual void attach(App::DocumentObject *);
|
||||||
/// Update the point representation
|
/// Update the point representation
|
||||||
virtual void updateData(const App::Property*);
|
virtual void updateData(const App::Property*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SoIndexedPointSet * pcPoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Gui::ViewProviderPythonFeatureT<ViewProviderPoints> ViewProviderPython;
|
typedef Gui::ViewProviderPythonFeatureT<ViewProviderScattered> ViewProviderPython;
|
||||||
|
|
||||||
} // namespace PointsGui
|
} // namespace PointsGui
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user