Faster Display

I am reading a stl file and converting the triangles into TopoDS shape as mentioned in the code below. But displaying the triangles(after being converted to shape)takes a lot of time.(see Display function below). Is there anyway to display it faster?
Thanx in advance
sonu khans

In some message handler
//Displays triangles from stl file
TopoDS_Edge e1, e2, e3;

TopoDS_Vertex Vertex1, Vertex2, Vertex3;

TopoDS_Shell MyShell;

TopoDS_Face MyFace;

TopoDS_Wire MyWire;

BRep_Builder MyBrep;

MyBrep.MakeShell(MyShell);
BRep_Builder builder;
TopoDS_Compound Comp;

builder.MakeCompound(Comp);
char str[40],ch;

double vertex[3][3];

int i=0,j=0,k = 1,l=0;

int counter = 0, disp_counter = 0;

//assert(i == 1);

CMainFrame *frm_wnd = GetApplicationFrame();

ifstream input("D:\\temp1.stl");

if(!input)

{

cout << "cannot open file.\n";

}

if(input)

{

do

{

input.get(str, 40, 'x');

input.get(ch);

if(ch == 'x')

{

l+=1;

for(j = 0; j < 3; j++)

{

if(j!=0)

input.get(ch);

for(i = 0; i < 3; i++)

{

input.get(ch);

if(i!=2)

input.get(str, 40, ' ');

else

input.get(str, 40, '\n');

vertex[j][i] = atof(str);

// cout <<"v:" << vertex[j][i]<<endl;

}

// cout << endl;

input.get(str, 40, 'x');

}

gp_Pnt P1(vertex[0][0],vertex[0][1],vertex[0][2]);

gp_Pnt P2(vertex[1][0],vertex[1][1],vertex[1][2]);

gp_Pnt P3(vertex[2][0],vertex[2][1],vertex[2][2]);

Vertex1 = BRepBuilderAPI_MakeVertex(P1);

Vertex2 = BRepBuilderAPI_MakeVertex(P2);

Vertex3 = BRepBuilderAPI_MakeVertex(P3);

e1 = BRepBuilderAPI_MakeEdge(Vertex1,Vertex2);

e2 = BRepBuilderAPI_MakeEdge(Vertex2,Vertex3);

e3 = BRepBuilderAPI_MakeEdge(Vertex1,Vertex3);

MyWire = BRepBuilderAPI_MakeWire( e1, e2, e3);

MyFace = BRepBuilderAPI_MakeFace( MyWire);

MyBrep.Add(MyShell,MyFace);

}

}while((ch = input.get()) != EOF);
input.close();

}
TopoDS_Shape myShape = BRepBuilderAPI_MakeSolid(MyShell);
m = new AIS_Shape(myShape);
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ myAISContext->Display(m);
//This statement execution takes lot of time.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

Patrik's picture

Hi,

I'm afraid there isn't a better solution at the moment (I'm doing the same with my STL and 3DS reader).
I think OpenCASCADE would need a good "TopoDS_Mesh".
I've got the same huge need of memory and lack of speed.

Regards,

Patrik Müller

Francois Lauzon's picture

Hi Sonu,
what we did here for this case was to develop our how ais (AIS_Mesh) using the class Poly_Triangulation to hold our meshing data and it's a lot faster. We use Select3D_SensitiveTriangulation for selection and the Graphic3d_Group::TriangleMesh for shading display and Graphic3d_Group::Polyline for wireframe. You should have a look at the manual and at the source code for AIS_Shape to have an idea.

Good Luck,
Francois.

s-khans's picture

Dear Francois,
Please give some more details. I'm unable to figure it out.
Thanx again in advance
Sonu Khan

Francois Lauzon's picture

I'm sorry, I can't tell you much more because this is all stuff that I did at the company where I work and right now I don't have the right to publish it.
Sorry,
Francois.

Patrik's picture

Hi Francois,

good to hear there's a solution for visualisation. But I personally think the problem is you have a huge Topo_DS overhead for simple meshed files.
I haven't tested it - but if I import a mesh structure without faces - lets say a DEM or such things - how about exporting to IGES and other formats?
I think the better way is building a new TopoDS_Shape with one face and only the vertices and edges (like the ACIS mesh classes).

Any ideas or interest?

Regards,
Patrik Müller

Michael Gandyra's picture

How much faster ? Maybe I could need this too. Could you make this public ?

Regards,
Michael

Michael Gandyra's picture

I did the same thing earlier, but I had an enriched triangulation (including first and second derivatives at the vertices). So I couldn't use Poly_Triangulation for data holding. I guess, we did the same like you, but we used Graphic3d_Group with distinct calls to TriangleSet (with given color or normal). So, I guess the performance compared to your algo should be nearly the same, since it is programmed near OpenGL.

Regards,
Michael

Francois Lauzon's picture

Yes, it's very similar, we also keep first derivative, so we use Graphic3d_VertexN for each vertex.
Francois.

jens's picture

The methods TriangleMesh and Polyline work for
the Visual3d_View, but is there anything for
visualizing a Poly_Triangulation in a V3d_View ?

d-carkeet's picture

lissen mate,

You MUST write yr own class to display your triangles/lines/lo que sea.

I've realised that the classes provided with OpenCascade (AISShape etc...) are grate for the example code, but not much else.

If you take the time to develop your own class (CJoeTriangle), inserting only the funtionality that YOU NEED (normally its not much), its LOTS faster.

AISShape is a very very slow... but OpenCasCade (while it has a big footprint is not TOO bad if you don't carry around unnecessary overhead that comes with the standard classes...