Drawing 3d lines / OpenGL

Hi, I am using qocc and an opengl paint callback function is starting like:

glOrtho(-1, 1, -1, 1, 1, -1);

My question is, can I convert an 3d coordinate(gp_Pnt) into these (-1,1) bounded volume so that I can draw lines using glVertex3d from a point to a point.

Or is there another way to draw lines in a fast way (there are too many lines)

Thanks

Carlos's picture

Hi Maili,

I would suggest you to use NIS_objects to display lines, specially if each line must be and independent object.

At the moment there are some minor problems, see http://www.opencascade.org/org/forum/thread_15167/

but my experience is that lines with NIS are much faster than with AIS (I have created lines in the order of 10000 in one or two seconds).

The basic code for displaying a line with NIS I have created is:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DISPLAY A LINE
int IDnis=-1;
Handle(NCollection_BaseAllocator) theAlloc;
Handle_NIS_Triangulated miNIS=new NIS_Triangulated(2,theAlloc);
int nnodos=3;
int nodo=1;

miNIS->SetLinePrs(2,Standard_False,2);
nodo=0;
gp_XYZ Coord0(0, 0, 0);
miNIS->SetNode(nodo, Coord0);
nodo=1;
gp_XYZ Coord1(1000, 200, 300);
miNIS->SetNode(nodo, Coord1);
miNIS->SetLineNode(0,0);
miNIS->SetLineNode(1,1);
myNISContext->Display(miNIS,Standard_False);

Quantity_Color aColor (0.1, 0.7, 0.7, Quantity_TOC_RGB);
miNIS->SetColor(aColor,Standard_False);
IDnis=miNIS->ID();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I'm almost sure that there is not the best way to do it as there are some items I do not fully understand, but it works.

This is only to display lines. If you want to add other features, like selection, Windowfit, etc, you can look at code in TKViewerTest.dll as it changes with respect to the standard AIS.

One thing you can do and it is implemented in Drawexe / TKViewertest is that you can work at the same time with AIS and NIS objects.

Other way already commented in the forum is to create a unique AIS_Object that also works faster than the standard method.

Hope this helps.

Carlos

Maili's picture

Thanks for reply but I forgot to mention that I use OCC6.2

Carlos's picture

Hi,

Then I can not suggest other method, but my experience is that with OCC6.2 it is really difficult to solve this problem. A search in this forum can confirm this.

One suggestion that I have not tried is to include directly the TKNIS package in your code and see if it works or see what are the lacks in the code. I bet there are not too many methods with other packages as to display lines are only related with NIS objects and visualzation, includes in the Package. It needs the following dlls: TKBRep.dll TKV3d.dll TKMath.dll and TKernel.dll.

The other thing that it could help you trying to use GL calls directly as you propose it to use as much code as possible from the TKNIS package, specially from NIS_TriangulatedDrawer.cpp.

Of course the third one would be to update to OCC6.3 :)

Please take note that I'm NOT an expert at all in OCC so these suggestions may be completly wrong.

Regards,

Carlos