For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Creating dynamic TopoDS_Compound & AIS_Shape in a incrementing way

Cédric Saillard's picture
Forums: 

Hello everybody,

I am using the mesh components of OCC, and I try to display the mesh while adding color to each face that is created.

In that way, I use the code given in the samples with the "TopExp_Explorer" to explore the mesh. Then I create faces in loops and I would like to associate a color (different for each face). So I think I must use the AIS_Shape, the only object we can associate color with. The problem is that I do not achieve to create AIS_Shape dynamically with an incremental index for example.
Here is the code I use :

//************************TEST MAILLAGE*******************************************

BRepMesh::Mesh(myFaceB,1);

double a, b, c;
a=0;
b=0;
c=0;
int ais=0;
Quantity_Color CouleurFace = Quantity_Color (a, b, c, Quantity_TOC_RGB);

for (TopExp_Explorer ex(myFaceB,TopAbs_FACE) ; ex.More(); ex.Next())
{
TopoDS_Face F =TopoDS::Face(ex.Current());
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
tri = facing->Triangles();

for (Standard_Integer i=1;iNbTriangles());i++)
{
Poly_Triangle trian = tri.Value(i);
Standard_Integer index1,index2,index3,M,N;
trian.Get(index1,index2,index3);

//*******création d'une face à partir des points du triangle

BRepBuilderAPI_MakeWire myWire2;

for (Standard_Integer j=1;j {
switch (j)
{
case 1 :
M = index1;
N = index2;
break;
case 2 :
N = index3;
break;
case 3 :
M = index2;
}

BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N));
if (ME.IsDone())
{
myWire2.Add(ME);
// Builder.Add(Bearing1, ME.Edge());
}
}
TopoDS_Shape myFace = BRepBuilderAPI_MakeFace(myWire2);

Builder.Add(Bearing1, myFace);

//*******************couleur***********************************

if (b b=b+0.1;
if (b==1)
{
AfxMessageBox(" b = 1 ");
b=0;
}
if (c c=c+0.1;
if (c==1)
{
AfxMessageBox(" c = 1 ");
c=0;
}

Handle(AIS_Shape) myAIS_ais = new AIS_Shape(Bearing1);

CouleurFace.SetValues (a,b,c,Quantity_TOC_RGB);
myAIS_ais->SetColor(CouleurFace);
myAISContext->Display(myAIS_ais);

//*********************fin couleur*****************************

It works but only display a color, the last created I think.
I'm asking if I may create a TopoDS_Compound in he loop to add to the BRep_Builder.

The main problem is to create some AIS_Shape in the loop and to be able to put an index on it...That's what I tried with "myAIS_ais", but doesn't works.

Thanks for help!

Cédric Saillard
French Student (UTT)