How to use AIS_Triangulation?

Dear all:

I know AIS_Shape is more convenient. But some big files are not necessary to load the Topo data. So I try to load STL file just for visualization. For this goal, I hit plateaus.

First, I can't add ComputeSelection to AIS_Triangulation, because there are no topos. How to add ComputeSelection for AIS_Triangulation?

Second, Some colors are not work. For example, Quantity_NOC_BLACK is fine. But Quantity_NOC_GRAY is not work, the displayed color is similary with Brass.

Finally, the displayed model is odd, maybe it caused by there is no WireFrame.

Thanks for replys, I would glad to get some advices.

Here are the codes

 Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile(theFileNmae.c_str());
Handle(AIS_Triangulation) tris = new AIS_Triangulation(aSTLMesh);
int numNodes = aSTLMesh->NbNodes();
Quantity_Color color;
int RGB_I;
color.Color2argb(Quantity_NOC_GRAY, RGB_I);
Handle(TColStd_HArray1OfInteger) colors = new TColStd_HArray1OfInteger(1, numNodes);
for (int i = 1; i <= numNodes; ++i) 
{
    colors->SetValue(i, RGB_I);
}
tris->SetColors(colors);

Handle(Prs3d_Drawer) theDrawer = new Prs3d_Drawer();
Handle(Prs3d_LineAspect) theLineAspect = new Prs3d_LineAspect(Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0);
theDrawer->SetFaceBoundaryAspect(theLineAspect);
tris->SetAttributes(theDrawer);
//tris->SetDisplayMode(Graphic3d_TypeOfShadingModel_PhongFacet);
Attachments: 
gkv311 n's picture

There is no need to use AIS_Triangulation - just create TopoDS_Face from your Poly_Triangulation and AIS_Shape will do everything you need (and in a more flexible and efficient way). Here is how it can be done (based on readstl DRAW command in XSDRAWSTLVRML.cxx):

double aMergeAngle = M_PI / 2.0;
Handle(Poly_Triangulation) aTris = RWStl::ReadFile("mystl.stl", aMergeAngle);
...
TopoDS_Face aFace;
BRep_Builder().MakeFace (aFace, aTriangulation);
...
// you may also create TopoDS_Compound to put multiple triangulations (like multi-body STL file) into single presentation
...
Handle(AIS_Shape) aPrs = new AIS_Shape(aFace);
...

The only reason to take a look into AIS_Triangulation is when you need to assign nodal colors to your mesh (but there are better ways to do that).

wu xin's picture

Thank you so much. I tried those codes and it works. The generating time is accept. And it more convinent Lol