OpenGL color tracking and Open Cascade

I'm going to develop a FEM postprocessor with OCC.

In FEM postprocessing, it is very important to assign respective color to each node(or vertex), but I can not find a method to do that.

I know that in Graphic3d_group I can assign each color to each vertex, but in that case I can not shade that triangle.

In OpenGL there is a way to do that easily. that is to use GL_COLOR_MATERIAL switch, which enalbles color tracking capability which forces the vertex material color to be the color assigned to that vertex automatically.

I tested it with exoTK. and here is my modification to test.

The following code displays a mesh with random color at each vertex. but it is never shaded at all. If I use material properties, then the color values don't work, and all mesh is shaded with the one color of the material.

Is there a method to do that in OCC?

void exotkAIS_StdPrs::DisplayShading(const Handle_exotkMesh_Mesh& aMesh,const Handle_Prs3d_Presentation& aPresentation,const Handle_AIS_Drawer& aDrawer)
{
if ( aMesh.IsNull() || (aMesh->NbSubMeshes() == 0) )
return;

exotkGUI::ShowWaitCursor();
Handle_Graphic3d_Structure theStructure = Handle_Graphic3d_Structure::DownCast(aPresentation);
Handle_Graphic3d_Group theGroup= new Graphic3d_Group(theStructure);

Handle(Graphic3d_AspectFillArea3d) AsptArea = new Graphic3d_AspectFillArea3d();
AsptArea->SetInteriorStyle(Aspect_IS_SOLID);
Graphic3d_MaterialAspect mat = AsptArea->FrontMaterial();
mat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
mat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
mat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
mat.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
AsptArea->SetFrontMaterial(mat);

theGroup->SetPrimitivesAspect(AsptArea);

theGroup->BeginPrimitives();

exotkMesh_ListIteratorOfListOfSubMesh theSubMeshIter;
exotkMesh_ListOfSubMesh theSubMeshes;
aMesh->SubMeshes(theSubMeshes);
exotkMesh_IndexedMapOfVertex theVertices;
exotkMesh_MapOfTriangle theTriangles;
exotkMesh_MapIteratorOfMapOfTriangle theMapIter;
Standard_Integer i1,i2,i3;
for ( theSubMeshIter.Initialize(theSubMeshes) ; theSubMeshIter.More() ; theSubMeshIter.Next() )
{
Handle_exotkMesh_SubMesh theCurrentSubMesh = theSubMeshIter.Value();
if ( !theCurrentSubMesh.IsNull() )
{
theCurrentSubMesh->Vertices(theVertices);
theCurrentSubMesh->Triangles(theTriangles);

for ( theMapIter.Initialize(theTriangles) ; theMapIter.More() ; theMapIter.Next() )
{
Handle_exotkMesh_Triangle theTriangle = theMapIter.Key();
theTriangle->Components(i1,i2,i3);
gp_Pnt P1 = theVertices.FindKey(i1)->Point();
gp_Pnt P2 = theVertices.FindKey(i2)->Point();
gp_Pnt P3 = theVertices.FindKey(i3)->Point();
gp_Vec V1 = theVertices.FindKey(i1)->Normal();
gp_Vec V2 = theVertices.FindKey(i2)->Normal();
gp_Vec V3 = theVertices.FindKey(i3)->Normal();

Aspect_Array1OfEdge aListEdge(1, 3 );
aListEdge.SetValue(1,Aspect_Edge(1,2,Aspect_TOE_VISIBLE));
aListEdge.SetValue(2,Aspect_Edge(2,3,Aspect_TOE_VISIBLE));
aListEdge.SetValue(3,Aspect_Edge(3,1,Aspect_TOE_VISIBLE));

Graphic3d_Array1OfVertexNC theArray1(1,3);
Quantity_Color color1,color2,color3;

color1 = exotkUtils::RandomColor();
theArray1.SetValue(1,Graphic3d_VertexNC(P1.X(),P1.Y(),P1.Z(),V1.X(),V1.Y(),V1.Z(),color1));
color2 = exotkUtils::RandomColor();
theArray1.SetValue(2,Graphic3d_VertexNC(P2.X(),P2.Y(),P2.Z(),V2.X(),V2.Y(),V2.Z(),color2));
color3 = exotkUtils::RandomColor();
theArray1.SetValue(3,Graphic3d_VertexNC(P3.X(),P3.Y(),P3.Z(),V3.X(),V3.Y(),V3.Z(),color3));

theGroup->TriangleSet(theArray1,aListEdge);

}
}
}
theGroup->EndPrimitives();

DisplayBoundaryBox(aPresentation,aDrawer);

exotkGUI::HideWaitCursor();

}

Mauricio Coelho Alves's picture

Hi, i'm trying to do something like you. I read from a neutral file the coordinates and connectives, like FEM. After a read a scalar file that contain some values for each node. This values can be temperature, stress, fluxes for instance.

So i've to draw this transition of stress, fluxes or temperature on the object (net). I'm use glColor but it's nor efficient bacaude it doesn't do the transition of color. For example if i've one node blue and the adjacent is red, i thing thar the transition must show yellow, green and others color.

If u can help me reply this e-mail. Sorry about my english.

mbd's picture

Hi,

I don't have enough code to test but ... could you try to replace :

AsptArea = new Graphic3d_AspectFillArea3d();

with :

AsptArea = (new Prs3d_ShadingAspect())->Aspect();

... keep me informed,

mbd