+ 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

@ -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();
std::size_t i=0;
for (std::vector<App::Color>::const_iterator it = val.begin(); it != val.end(); ++it) { for (std::vector<App::Color>::const_iterator it = val.begin(); it != val.end(); ++it) {
pcColorMat->diffuseColor.set1Value(i++, SbColor(it->r, it->g, it->b)); 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();
std::size_t i=0;
for (std::vector<float>::const_iterator it = val.begin(); it != val.end(); ++it) { for (std::vector<float>::const_iterator it = val.begin(); it != val.end(); ++it) {
pcColorMat->diffuseColor.set1Value(i++, SbColor(*it, *it, *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();
std::size_t i=0;
for (std::vector<Base::Vector3f>::const_iterator it = val.begin(); it != val.end(); ++it) { for (std::vector<Base::Vector3f>::const_iterator it = val.begin(); it != val.end(); ++it) {
pcPointsNormal->vector.set1Value(i++, it->x, it->y, it->z); 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,53 +199,54 @@ 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 ---------------------------------------------
if (std::find(modes.begin(), modes.end(), std::string("Shaded")) != modes.end()) {
SoGroup* pcPointShadedRoot = new SoGroup();
pcPointShadedRoot->addChild(pcPointStyle); pcPointShadedRoot->addChild(pcPointStyle);
pcPointShadedRoot->addChild(pcShapeMaterial); pcPointShadedRoot->addChild(pcShapeMaterial);
pcPointShadedRoot->addChild(pcPointsNormal); pcPointShadedRoot->addChild(pcPointsNormal);
pcPointShadedRoot->addChild(pcHighlight); pcPointShadedRoot->addChild(pcHighlight);
addDisplayMaskMode(pcPointShadedRoot, "Shaded");
}
// color 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); pcColorShadedRoot->addChild(pcPointStyle);
SoMaterialBinding* pcMatBinding = new SoMaterialBinding; SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED; pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
pcColorShadedRoot->addChild(pcColorMat); pcColorShadedRoot->addChild(pcColorMat);
pcColorShadedRoot->addChild(pcMatBinding); pcColorShadedRoot->addChild(pcMatBinding);
pcColorShadedRoot->addChild(pcHighlight); pcColorShadedRoot->addChild(pcHighlight);
// putting all together with a switch
addDisplayMaskMode(pcPointRoot, "Point");
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();
Base::Type t = it->second->getTypeId(); if (type == App::PropertyColorList::getClassTypeId()) {
if ( t==App::PropertyColorList::getClassTypeId() ) App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it->second);
{
App::PropertyColorList* colors = (App::PropertyColorList*)it->second;
if (numPoints != colors->getSize()) { if (numPoints != colors->getSize()) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
@ -259,7 +254,8 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
#endif #endif
// fallback // fallback
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} else { }
else {
setVertexColorMode(colors); setVertexColorMode(colors);
setDisplayMaskMode("Color"); setDisplayMaskMode("Color");
} }
@ -267,16 +263,13 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
} }
} }
} }
else if ( strcmp("Intensity",ModeName)==0 ) else if (strcmp("Intensity",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();
Base::Type t = it->second->getTypeId(); if (type == Points::PropertyGreyValueList::getClassTypeId()) {
if ( t==Points::PropertyGreyValueList::getClassTypeId() ) Points::PropertyGreyValueList* greyValues = static_cast<Points::PropertyGreyValueList*>(it->second);
{
Points::PropertyGreyValueList* greyValues = (Points::PropertyGreyValueList*)it->second;
if (numPoints != greyValues->getSize()) { if (numPoints != greyValues->getSize()) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
@ -284,7 +277,8 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
#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 { }
else {
setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second); setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second);
setDisplayMaskMode("Color"); setDisplayMaskMode("Color");
} }
@ -292,16 +286,13 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
} }
} }
} }
else if ( strcmp("Shaded",ModeName)==0 ) else if (strcmp("Shaded",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();
Base::Type t = it->second->getTypeId(); if (type == Points::PropertyNormalList::getClassTypeId()) {
if ( t==Points::PropertyNormalList::getClassTypeId() ) Points::PropertyNormalList* normals = static_cast<Points::PropertyNormalList*>(it->second);
{
Points::PropertyNormalList* normals = (Points::PropertyNormalList*)it->second;
if (numPoints != normals->getSize()) { if (numPoints != normals->getSize()) {
#ifdef FC_DEBUG #ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
@ -309,7 +300,8 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
#endif #endif
// fallback // fallback
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} else { }
else {
setVertexNormalMode(normals); setVertexNormalMode(normals);
setDisplayMaskMode("Shaded"); setDisplayMaskMode("Shaded");
} }
@ -317,8 +309,7 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
} }
} }
} }
else if ( strcmp("Points",ModeName)==0 ) else if (strcmp("Points",ModeName) == 0) {
{
setDisplayMaskMode("Point"); setDisplayMaskMode("Point");
} }
@ -330,19 +321,17 @@ 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 ( t==Points::PropertyGreyValueList::getClassTypeId() ) else if (type == Points::PropertyGreyValueList::getClassTypeId())
StrList.push_back("Intensity"); StrList.push_back("Intensity");
else if ( t==App::PropertyColorList::getClassTypeId() ) else if (type == App::PropertyColorList::getClassTypeId())
StrList.push_back("Color"); StrList.push_back("Color");
} }
} }
@ -434,7 +423,7 @@ 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();
@ -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();
} }