Postprocessing: Color per Element at FemMesh

This commit is contained in:
jriegel
2013-12-31 13:52:02 +01:00
parent ff77ad4cb3
commit fd62480958
4 changed files with 72 additions and 6 deletions

View File

@@ -574,6 +574,39 @@ void ViewProviderFemMesh::animateNodes(double factor)
DisplacementFactor = factor;
}
void ViewProviderFemMesh::setColorByElementId(const std::map<long,App::Color> &ElementColorMap)
{
pcShapeMaterial->diffuseColor;
pcMatBinding->value = SoMaterialBinding::PER_FACE ;
// resizing and writing the color vector:
pcShapeMaterial->diffuseColor.setNum(vFaceElementIdx.size());
SbColor* colors = pcShapeMaterial->diffuseColor.startEditing();
int i=0;
for(std::vector<unsigned long>::const_iterator it=vFaceElementIdx.begin()
;it!=vFaceElementIdx.end()
;++it,i++){
unsigned long ElemIdx = ((*it)>>3);
const std::map<long,App::Color>::const_iterator pos = ElementColorMap.find(ElemIdx);
if(pos == ElementColorMap.end())
colors[i] = SbColor(0,1,0);
else
colors[i] = SbColor(pos->second.r,pos->second.g,pos->second.b);
}
pcShapeMaterial->diffuseColor.finishEditing();
}
void ViewProviderFemMesh::resetColorByElementId(void)
{
pcMatBinding->value = SoMaterialBinding::OVERALL;
pcShapeMaterial->diffuseColor.setNum(0);
const App::Color& c = ShapeColor.getValue();
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
}
// ----------------------------------------------------------------------------

View File

@@ -113,6 +113,11 @@ public:
void resetDisplacementByNodeId(void);
/// reaply the node displacement with a certain factor and do a redraw
void animateNodes(double factor);
/// set the color for each element
void setColorByElementId(const std::map<long,App::Color> &ElementColorMap);
/// reset the view of the element colors
void resetColorByElementId(void);
//@}
const std::vector<unsigned long> &getVisibleElementFaces(void)const{return vFaceElementIdx;}

View File

@@ -20,12 +20,18 @@
<UserDocu></UserDocu>
</Documentation>
</Methode>
<Attribute Name="NodeColor" ReadOnly="false">
<Documentation>
<UserDocu>Postprocessing color of the the nodes. The faces between the nodes gets interpolated. </UserDocu>
</Documentation>
<Parameter Name="NodeColor" Type="Dict"/>
</Attribute>
<Attribute Name="NodeColor" ReadOnly="false">
<Documentation>
<UserDocu>Postprocessing color of the nodes. The faces between the nodes gets interpolated. </UserDocu>
</Documentation>
<Parameter Name="NodeColor" Type="Dict"/>
</Attribute>
<Attribute Name="ElementColor" ReadOnly="false">
<Documentation>
<UserDocu>Postprocessing color of the elements. All faces of the element get the same color. </UserDocu>
</Documentation>
<Parameter Name="ElementColor" Type="Dict"/>
</Attribute>
<Attribute Name="NodeDisplacement" ReadOnly="false">
<Documentation>
<UserDocu>Postprocessing color of the the nodes. The faces between the nodes gets interpolated. </UserDocu>

View File

@@ -57,6 +57,28 @@ void ViewProviderFemMeshPy::setNodeColor(Py::Dict arg)
}
}
Py::Dict ViewProviderFemMeshPy::getElementColor(void) const
{
//return Py::List();
throw Py::AttributeError("Not yet implemented");
}
void ViewProviderFemMeshPy::setElementColor(Py::Dict arg)
{
if(arg.size() == 0)
this->getViewProviderFemMeshPtr()->resetColorByNodeId();
else {
std::map<long,App::Color> NodeColorMap;
for( Py::Dict::iterator it = arg.begin(); it!= arg.end();++it){
Py::Int id((*it).first);
Py::Tuple color((*it).second);
NodeColorMap[id] = App::Color(Py::Float(color[0]),Py::Float(color[1]),Py::Float(color[2]),0);
}
this->getViewProviderFemMeshPtr()->setColorByElementId(NodeColorMap);
}
}
Py::Dict ViewProviderFemMeshPy::getNodeDisplacement(void) const
{
//return Py::Dict();