how to color the surface of a triangle?

Hello,
in my project I'm tesselelating a TopoDS_Shape.
Then I use a meanshift-algorithm to divide the triangle-mesh in different segments.
Now, I'd like to color the surface of each segment in a different color.
I know, how to color each edge of a triangle, but how can I color the surface?

Here is the code I use to color the edge of a triangle:
colors is an array of Quantity_NameOfColor.
point1 and point2 are ColumnVector which represent the coordinates of the vertices.

BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);

BRepBuilderAPI_MakeEdge ME(gp_Pnt(point1(1),point1(2), point1(3)), gp_Pnt(point2(1),point2(2), point2(3)));
if (ME.IsDone())
{
builder.Add(Comp,ME.Edge());
}
Handle_AIS_Shape ctriangulation = new AIS_Shape(Comp);
myAISContext->SetDisplayMode(ctriangulation,0);
myAISContext->SetColor(ctriangulation,colors[i%11]);
myAISContext->Display(ctriangulation);

Seth Jackson's picture

i believe you would first need to build edges, then a face for your triangle, before creating the AIS_Shape. then the color you apply with SetColor() will hold...

Matthias Teich's picture

You want colored Faces, but you only create edges!
The following code-snippet creates wires from the edges and faces from the wires.
Edges is an Array which must be fillded with the edges for the face.

TopoDS_Edge edges[3];

BRepBuilderAPI_MakeEdge ME(gp_Pnt(point1(1),point1(2), point1(3)),gp_Pnt(point2(1),point2(2), point2(3)));
if (ME.IsDone())
{
TopoDS_Edge edge = ME.Edge();
edges[k-1] = edge;
}
}
BRepBuilderAPI_MakeWire MW (edges[0],edges[1],edges[2]);
BRepBuilderAPI_MakeFace MF(MW.Wire());
Handle_AIS_Shape f = new AIS_Shape(MF.Face());
myAISContext->SetColor(f,colors[i%11]);
myAISContext->SetDisplayMode(f,1);
myAISContext->Display(f);

Best Regards, Matthias :)