+ edit command for meshes to display components

This commit is contained in:
wmayer 2015-02-20 22:28:37 +01:00
parent 18f1cf7821
commit 312f63e43e
3 changed files with 39 additions and 1 deletions

View File

@ -189,7 +189,7 @@ public:
* Checks for the given facet indices what will be the degree for each point * Checks for the given facet indices what will be the degree for each point
* when these facets are removed from the mesh kernel. * when these facets are removed from the mesh kernel.
* The point degree information is stored in \a point_degree. The return value * The point degree information is stored in \a point_degree. The return value
* gices the number of points which will have a degree of zero. * gives the number of points which will have a degree of zero.
*/ */
unsigned long getPointDegree(const std::vector<unsigned long>& facets, unsigned long getPointDegree(const std::vector<unsigned long>& facets,
std::vector<unsigned long>& point_degree) const; std::vector<unsigned long>& point_degree) const;

View File

@ -24,6 +24,8 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <stdlib.h>
# include <QAction>
# include <QMenu> # include <QMenu>
# include <Inventor/SbBox2s.h> # include <Inventor/SbBox2s.h>
# include <Inventor/SbLine.h> # include <Inventor/SbLine.h>
@ -572,10 +574,19 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi
return false; return false;
} }
void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);
QAction* act = menu->addAction(QObject::tr("Display components"), receiver, member);
act->setData(QVariant((int)ViewProvider::Color));
}
bool ViewProviderMesh::setEdit(int ModNum) bool ViewProviderMesh::setEdit(int ModNum)
{ {
if (ModNum == ViewProvider::Transform) if (ModNum == ViewProvider::Transform)
return ViewProviderGeometryObject::setEdit(ModNum); return ViewProviderGeometryObject::setEdit(ModNum);
else if (ModNum == ViewProvider::Color)
highlightComponents();
return true; return true;
} }
@ -583,6 +594,8 @@ void ViewProviderMesh::unsetEdit(int ModNum)
{ {
if (ModNum == ViewProvider::Transform) if (ModNum == ViewProvider::Transform)
ViewProviderGeometryObject::unsetEdit(ModNum); ViewProviderGeometryObject::unsetEdit(ModNum);
else if (ModNum == ViewProvider::Color)
unhighlightSelection();
} }
bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const SbViewVolume& vol, bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const SbViewVolume& vol,
@ -1667,6 +1680,29 @@ void ViewProviderMesh::unhighlightSelection()
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b); pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
} }
void ViewProviderMesh::highlightComponents()
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
std::vector<std::vector<unsigned long> > comps = rMesh.getComponents();
// Colorize the components
pcMatBinding->value = SoMaterialBinding::PER_FACE;
int uCtFacets = (int)rMesh.countFacets();
pcShapeMaterial->diffuseColor.setNum(uCtFacets);
SbColor* cols = pcShapeMaterial->diffuseColor.startEditing();
for (std::vector<std::vector<unsigned long> >::iterator it = comps.begin(); it != comps.end(); ++it) {
float fMax = (float)RAND_MAX;
float fRed = (float)rand()/fMax;
float fGrn = (float)rand()/fMax;
float fBlu = (float)rand()/fMax;
for (std::vector<unsigned long>::iterator jt = it->begin(); jt != it->end(); ++jt) {
cols[*jt].setValue(fRed,fGrn,fBlu);
}
}
pcShapeMaterial->diffuseColor.finishEditing();
}
// ------------------------------------------------------ // ------------------------------------------------------
PROPERTY_SOURCE(MeshGui::ViewProviderIndexedFaceSet, MeshGui::ViewProviderMesh) PROPERTY_SOURCE(MeshGui::ViewProviderIndexedFaceSet, MeshGui::ViewProviderMesh)

View File

@ -129,6 +129,7 @@ public:
/// 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;
bool exportToVrml(const char* filename, const MeshCore::Material&, bool binary=false) const; bool exportToVrml(const char* filename, const MeshCore::Material&, bool binary=false) const;
void setupContextMenu(QMenu*, QObject*, const char*);
/** @name Editing */ /** @name Editing */
//@{ //@{
@ -169,6 +170,7 @@ protected:
virtual void selectArea(short, short, short, short, const SbViewportRegion&, SoCamera*); virtual void selectArea(short, short, short, short, const SbViewportRegion&, SoCamera*);
void highlightSelection(); void highlightSelection();
void unhighlightSelection(); void unhighlightSelection();
void highlightComponents();
virtual SoShape* getShapeNode() const; virtual SoShape* getShapeNode() const;
virtual SoNode* getCoordNode() const; virtual SoNode* getCoordNode() const;