+ optimize view provider for points, improve white spacing

This commit is contained in:
wmayer 2015-12-30 15:19:47 +01:00
parent 1274967208
commit 7d96d0f0c8
2 changed files with 155 additions and 169 deletions

View File

@ -80,7 +80,7 @@ ViewProviderPoints::ViewProviderPoints()
pcPointsCoord->ref(); pcPointsCoord->ref();
pcPoints = new SoPointSet(); pcPoints = new SoPointSet();
pcPoints->ref(); pcPoints->ref();
pcPointsNormal = new SoNormal(); pcPointsNormal = new SoNormal();
pcPointsNormal->ref(); pcPointsNormal->ref();
pcColorMat = new SoMaterial; pcColorMat = new SoMaterial;
pcColorMat->ref(); pcColorMat->ref();
@ -137,7 +137,7 @@ Gui::SoFCSelection* ViewProviderPoints::createFromSettings() const
void ViewProviderPoints::onChanged(const App::Property* prop) void ViewProviderPoints::onChanged(const App::Property* prop)
{ {
if ( prop == &PointSize ) { if (prop == &PointSize) {
pcPointStyle->pointSize = PointSize.getValue(); pcPointStyle->pointSize = PointSize.getValue();
} }
else { else {
@ -148,52 +148,46 @@ void ViewProviderPoints::onChanged(const App::Property* prop)
void ViewProviderPoints::setVertexColorMode(App::PropertyColorList* pcProperty) void ViewProviderPoints::setVertexColorMode(App::PropertyColorList* pcProperty)
{ {
const std::vector<App::Color>& val = pcProperty->getValues(); const std::vector<App::Color>& val = pcProperty->getValues();
unsigned long i=0;
pcColorMat->enableNotify(false);
pcColorMat->diffuseColor.deleteValues(0);
pcColorMat->diffuseColor.setNum(val.size()); pcColorMat->diffuseColor.setNum(val.size());
SbColor* col = pcColorMat->diffuseColor.startEditing();
for ( std::vector<App::Color>::const_iterator it = val.begin(); it != val.end(); ++it ) { std::size_t i=0;
pcColorMat->diffuseColor.set1Value(i++, SbColor(it->r, it->g, it->b)); for (std::vector<App::Color>::const_iterator it = val.begin(); it != val.end(); ++it) {
col[i++].setValue(it->r, it->g, it->b);
} }
pcColorMat->enableNotify(true); pcColorMat->diffuseColor.finishEditing();
pcColorMat->touch();
} }
void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* pcProperty) void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* pcProperty)
{ {
const std::vector<float>& val = pcProperty->getValues(); const std::vector<float>& val = pcProperty->getValues();
unsigned long i=0;
pcColorMat->enableNotify(false);
pcColorMat->diffuseColor.deleteValues(0);
pcColorMat->diffuseColor.setNum(val.size()); pcColorMat->diffuseColor.setNum(val.size());
SbColor* col = pcColorMat->diffuseColor.startEditing();
for ( std::vector<float>::const_iterator it = val.begin(); it != val.end(); ++it ) { std::size_t i=0;
pcColorMat->diffuseColor.set1Value(i++, SbColor(*it, *it, *it)); for (std::vector<float>::const_iterator it = val.begin(); it != val.end(); ++it) {
col[i++].setValue(*it, *it, *it);
} }
pcColorMat->enableNotify(true); pcColorMat->diffuseColor.finishEditing();
pcColorMat->touch();
} }
void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcProperty) void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcProperty)
{ {
const std::vector<Base::Vector3f>& val = pcProperty->getValues(); const std::vector<Base::Vector3f>& val = pcProperty->getValues();
unsigned long i=0;
pcPointsNormal->enableNotify(false);
pcPointsNormal->vector.deleteValues(0);
pcPointsNormal->vector.setNum(val.size()); pcPointsNormal->vector.setNum(val.size());
SbVec3f* norm = pcPointsNormal->vector.startEditing();
for ( std::vector<Base::Vector3f>::const_iterator it = val.begin(); it != val.end(); ++it ) { std::size_t i=0;
pcPointsNormal->vector.set1Value(i++, it->x, it->y, it->z); for (std::vector<Base::Vector3f>::const_iterator it = val.begin(); it != val.end(); ++it) {
norm[i++].setValue(it->x, it->y, it->z);
} }
pcPointsNormal->enableNotify(true); pcPointsNormal->vector.finishEditing();
pcPointsNormal->touch();
} }
void ViewProviderPoints::attach(App::DocumentObject* pcObj) void ViewProviderPoints::attach(App::DocumentObject* pcObj)
@ -205,149 +199,144 @@ void ViewProviderPoints::attach(App::DocumentObject* pcObj)
pcHighlight->documentName = pcObj->getDocument()->getName(); pcHighlight->documentName = pcObj->getDocument()->getName();
pcHighlight->subElementName = "Main"; pcHighlight->subElementName = "Main";
SoGroup* pcPointRoot = new SoGroup();
SoGroup* pcPointShadedRoot = new SoGroup();
SoGroup* pcColorShadedRoot = new SoGroup();
// Hilight for selection // Hilight for selection
pcHighlight->addChild(pcPointsCoord); pcHighlight->addChild(pcPointsCoord);
pcHighlight->addChild(pcPoints); pcHighlight->addChild(pcPoints);
std::vector<std::string> modes = getDisplayModes();
// points part --------------------------------------------- // points part ---------------------------------------------
SoGroup* pcPointRoot = new SoGroup();
pcPointRoot->addChild(pcPointStyle); pcPointRoot->addChild(pcPointStyle);
pcPointRoot->addChild(pcShapeMaterial); pcPointRoot->addChild(pcShapeMaterial);
pcPointRoot->addChild(pcHighlight); pcPointRoot->addChild(pcHighlight);
addDisplayMaskMode(pcPointRoot, "Point");
// points shaded --------------------------------------------- // points shaded ---------------------------------------------
pcPointShadedRoot->addChild(pcPointStyle); if (std::find(modes.begin(), modes.end(), std::string("Shaded")) != modes.end()) {
pcPointShadedRoot->addChild(pcShapeMaterial); SoGroup* pcPointShadedRoot = new SoGroup();
pcPointShadedRoot->addChild(pcPointsNormal); pcPointShadedRoot->addChild(pcPointStyle);
pcPointShadedRoot->addChild(pcHighlight); pcPointShadedRoot->addChild(pcShapeMaterial);
pcPointShadedRoot->addChild(pcPointsNormal);
pcPointShadedRoot->addChild(pcHighlight);
addDisplayMaskMode(pcPointShadedRoot, "Shaded");
}
// color shaded ------------------------------------------ // color shaded ------------------------------------------
pcColorShadedRoot->addChild(pcPointStyle); if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
SoMaterialBinding* pcMatBinding = new SoMaterialBinding; std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED; SoGroup* pcColorShadedRoot = new SoGroup();
pcColorShadedRoot->addChild(pcColorMat); pcColorShadedRoot->addChild(pcPointStyle);
pcColorShadedRoot->addChild(pcMatBinding); SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
pcColorShadedRoot->addChild(pcHighlight); pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
pcColorShadedRoot->addChild(pcColorMat);
// putting all together with a switch pcColorShadedRoot->addChild(pcMatBinding);
addDisplayMaskMode(pcPointRoot, "Point"); pcColorShadedRoot->addChild(pcHighlight);
addDisplayMaskMode(pcColorShadedRoot, "Color"); addDisplayMaskMode(pcColorShadedRoot, "Color");
addDisplayMaskMode(pcPointShadedRoot, "Shaded"); }
} }
void ViewProviderPoints::setDisplayMode(const char* ModeName) void ViewProviderPoints::setDisplayMode(const char* ModeName)
{ {
int numPoints = pcPointsCoord->point.getNum(); int numPoints = pcPointsCoord->point.getNum();
if ( strcmp("Color",ModeName)==0 ) if (strcmp("Color",ModeName) == 0) {
{ std::map<std::string,App::Property*> Map;
std::map<std::string,App::Property*> Map; pcObject->getPropertyMap(Map);
pcObject->getPropertyMap(Map); for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
for( std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it ) Base::Type type = it->second->getTypeId();
{ if (type == App::PropertyColorList::getClassTypeId()) {
Base::Type t = it->second->getTypeId(); App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it->second);
if ( t==App::PropertyColorList::getClassTypeId() ) if (numPoints != colors->getSize()) {
{
App::PropertyColorList* colors = (App::PropertyColorList*)it->second;
if ( numPoints != colors->getSize() ) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of colors (%d).", numPoints, colors->getSize()); "The number of points (%d) doesn't match with the number of colors (%d).", numPoints, colors->getSize());
#endif #endif
// fallback // fallback
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} else { }
setVertexColorMode(colors); else {
setDisplayMaskMode("Color"); setVertexColorMode(colors);
setDisplayMaskMode("Color");
}
break;
}
} }
break;
}
} }
} else if (strcmp("Intensity",ModeName) == 0) {
else if ( strcmp("Intensity",ModeName)==0 ) std::map<std::string,App::Property*> Map;
{ pcObject->getPropertyMap(Map);
std::map<std::string,App::Property*> Map; for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
pcObject->getPropertyMap(Map); Base::Type type = it->second->getTypeId();
for( std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it ) if (type == Points::PropertyGreyValueList::getClassTypeId()) {
{ Points::PropertyGreyValueList* greyValues = static_cast<Points::PropertyGreyValueList*>(it->second);
Base::Type t = it->second->getTypeId(); if (numPoints != greyValues->getSize()) {
if ( t==Points::PropertyGreyValueList::getClassTypeId() )
{
Points::PropertyGreyValueList* greyValues = (Points::PropertyGreyValueList*)it->second;
if ( numPoints != greyValues->getSize() ) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of grey values (%d).", numPoints, greyValues->getSize()); "The number of points (%d) doesn't match with the number of grey values (%d).", numPoints, greyValues->getSize());
#endif #endif
// Intensity mode is not possible then set the default () mode instead. // Intensity mode is not possible then set the default () mode instead.
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} else { }
setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second); else {
setDisplayMaskMode("Color"); setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second);
setDisplayMaskMode("Color");
}
break;
}
} }
break;
}
} }
} else if (strcmp("Shaded",ModeName) == 0) {
else if ( strcmp("Shaded",ModeName)==0 ) std::map<std::string,App::Property*> Map;
{ pcObject->getPropertyMap(Map);
std::map<std::string,App::Property*> Map; for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
pcObject->getPropertyMap(Map); Base::Type type = it->second->getTypeId();
for( std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it ) if (type == Points::PropertyNormalList::getClassTypeId()) {
{ Points::PropertyNormalList* normals = static_cast<Points::PropertyNormalList*>(it->second);
Base::Type t = it->second->getTypeId(); if (numPoints != normals->getSize()) {
if ( t==Points::PropertyNormalList::getClassTypeId() )
{
Points::PropertyNormalList* normals = (Points::PropertyNormalList*)it->second;
if ( numPoints != normals->getSize() ) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of normals (%d).", numPoints, normals->getSize()); "The number of points (%d) doesn't match with the number of normals (%d).", numPoints, normals->getSize());
#endif #endif
// fallback // fallback
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} else { }
setVertexNormalMode(normals); else {
setDisplayMaskMode("Shaded"); setVertexNormalMode(normals);
setDisplayMaskMode("Shaded");
}
break;
}
} }
break;
}
} }
} else if (strcmp("Points",ModeName) == 0) {
else if ( strcmp("Points",ModeName)==0 ) setDisplayMaskMode("Point");
{ }
setDisplayMaskMode("Point");
}
ViewProviderGeometryObject::setDisplayMode(ModeName); ViewProviderGeometryObject::setDisplayMode(ModeName);
} }
std::vector<std::string> ViewProviderPoints::getDisplayModes(void) const std::vector<std::string> ViewProviderPoints::getDisplayModes(void) const
{ {
std::vector<std::string> StrList; std::vector<std::string> StrList;
StrList.push_back("Points"); StrList.push_back("Points");
if ( pcObject ) if (pcObject) {
{ std::map<std::string,App::Property*> Map;
std::map<std::string,App::Property*> Map; pcObject->getPropertyMap(Map);
pcObject->getPropertyMap(Map);
for( std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it ) for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
{ Base::Type type = it->second->getTypeId();
Base::Type t = it->second->getTypeId(); if (type == Points::PropertyNormalList::getClassTypeId())
if ( t==Points::PropertyNormalList::getClassTypeId() ) StrList.push_back("Shaded");
StrList.push_back("Shaded"); else if (type == Points::PropertyGreyValueList::getClassTypeId())
else if ( t==Points::PropertyGreyValueList::getClassTypeId() ) StrList.push_back("Intensity");
StrList.push_back("Intensity"); else if (type == App::PropertyColorList::getClassTypeId())
else if ( t==App::PropertyColorList::getClassTypeId() ) StrList.push_back("Color");
StrList.push_back("Color"); }
} }
}
return StrList; return StrList;
} }
void ViewProviderPoints::updateData(const App::Property* prop) void ViewProviderPoints::updateData(const App::Property* prop)
@ -364,30 +353,30 @@ void ViewProviderPoints::updateData(const App::Property* prop)
QIcon ViewProviderPoints::getIcon() const QIcon ViewProviderPoints::getIcon() const
{ {
static const char * const Points_Feature_xpm[] = { static const char * const Points_Feature_xpm[] = {
"16 16 4 1", "16 16 4 1",
". c none", ". c none",
"s c #000000", "s c #000000",
"b c #FFFF00", "b c #FFFF00",
"r c #FF0000", "r c #FF0000",
"ss.....ss.....bb", "ss.....ss.....bb",
"ss..ss.ss.....bb", "ss..ss.ss.....bb",
"....ss..........", "....ss..........",
"...........bb...", "...........bb...",
".ss..ss....bb...", ".ss..ss....bb...",
".ss..ss.........", ".ss..ss.........",
"........bb....bb", "........bb....bb",
"ss......bb....bb", "ss......bb....bb",
"ss..rr......bb..", "ss..rr......bb..",
"....rr......bb..", "....rr......bb..",
"........bb......", "........bb......",
"..rr....bb..bb..", "..rr....bb..bb..",
"..rr........bb..", "..rr........bb..",
".....rr.........", ".....rr.........",
"rr...rr..rr..rr.", "rr...rr..rr..rr.",
"rr.......rr..rr."}; "rr.......rr..rr."};
QPixmap px(Points_Feature_xpm); QPixmap px(Points_Feature_xpm);
return px; return px;
} }
bool ViewProviderPoints::setEdit(int) bool ViewProviderPoints::setEdit(int)
@ -434,15 +423,15 @@ void ViewProviderPoints::cut(const std::vector<SbVec2f>& picked, Gui::View3DInve
} }
// get a reference to the point feature // get a reference to the point feature
Points::Feature* fea = (Points::Feature*)pcObject; Points::Feature* fea = static_cast<Points::Feature*>(pcObject);
const Points::PointKernel& points = fea->Points.getValue(); const Points::PointKernel& points = fea->Points.getValue();
SoCamera* pCam = Viewer.getSoRenderManager()->getCamera(); SoCamera* pCam = Viewer.getSoRenderManager()->getCamera();
SbViewVolume vol = pCam->getViewVolume(); SbViewVolume vol = pCam->getViewVolume();
// search for all points inside/outside the polygon // search for all points inside/outside the polygon
Points::PointKernel newKernel; Points::PointKernel newKernel;
for ( Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt ) { for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt) {
SbVec3f pt(jt->x,jt->y,jt->z); SbVec3f pt(jt->x,jt->y,jt->z);
// project from 3d to 2d // project from 3d to 2d
@ -505,19 +494,16 @@ void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordi
const Points::PropertyPointKernel* prop_points = static_cast<const Points::PropertyPointKernel*>(prop); const Points::PropertyPointKernel* prop_points = static_cast<const Points::PropertyPointKernel*>(prop);
const Points::PointKernel& cPts = prop_points->getValue(); const Points::PointKernel& cPts = prop_points->getValue();
// disable the notification, otherwise whenever a point is inserted SoPointSet gets notified
coords->enableNotify(false);
coords->point.deleteValues(0);
coords->point.setNum(cPts.size()); coords->point.setNum(cPts.size());
SbVec3f* vec = coords->point.startEditing();
// get all points // get all points
int idx=0; std::size_t idx=0;
const std::vector<Points::PointKernel::value_type>& kernel = cPts.getBasicPoints(); 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++) { for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
coords->point.set1Value(idx, (float)it->x, (float)it->y, (float)it->z); vec[idx].setValue(it->x, it->y, it->z);
} }
points->numPoints = cPts.size(); points->numPoints = cPts.size();
coords->enableNotify(true); coords->point.finishEditing();
coords->touch();
} }

View File

@ -38,18 +38,18 @@ class SoNormal;
class SoEventCallback; class SoEventCallback;
namespace App { namespace App {
class PropertyColorList; class PropertyColorList;
} }
namespace Gui { namespace Gui {
class SoFCSelection; class SoFCSelection;
} }
namespace Points { namespace Points {
class PropertyGreyValueList; class PropertyGreyValueList;
class PropertyNormalList; class PropertyNormalList;
class PointKernel; class PointKernel;
class Feature; class Feature;
} }
namespace PointsGui { namespace PointsGui {