+ optimize view provider for points, improve white spacing
This commit is contained in:
parent
1274967208
commit
7d96d0f0c8
|
@ -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,61 +199,63 @@ 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);
|
||||||
{
|
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 {
|
}
|
||||||
|
else {
|
||||||
setVertexColorMode(colors);
|
setVertexColorMode(colors);
|
||||||
setDisplayMaskMode("Color");
|
setDisplayMaskMode("Color");
|
||||||
}
|
}
|
||||||
|
@ -267,24 +263,22 @@ 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);
|
||||||
{
|
if (numPoints != greyValues->getSize()) {
|
||||||
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 {
|
}
|
||||||
|
else {
|
||||||
setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second);
|
setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second);
|
||||||
setDisplayMaskMode("Color");
|
setDisplayMaskMode("Color");
|
||||||
}
|
}
|
||||||
|
@ -292,24 +286,22 @@ 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);
|
||||||
{
|
if (numPoints != normals->getSize()) {
|
||||||
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 {
|
}
|
||||||
|
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();
|
||||||
|
@ -442,7 +431,7 @@ void ViewProviderPoints::cut(const std::vector<SbVec2f>& picked, Gui::View3DInve
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user