Thu, 05/31/2007 - 02:53
Hi,
I'm trying to use OpenCascade just for generating geometry, and I want to export all the primitives (just triangles, for now) to my own OpenGL-based 3D engine. Now, I'm creating the bodies properly (basically copying the code from some of the samples) and I'm using the standard triangulation loop, like so:
TopoDS_Shape topoShape;
TopExp_Explorer exp(topoShape, TopAbs_FACE);
for ( ; exp.More(); exp.Next())
{
TopoDS_Face face = TopoDS::Face(exp.Current());
if (!face.IsNull())
{
Handle(Poly_Triangulation) triangles = Handle(BRep_TFace)::DownCast(face.TShape())->Triangulation();
// OR using the BRep_Tool::Triangulation method
if (!triangles.IsNull())
{
nbTriangles += triangles->NbTriangles();
// Then do whatever...
}
}
}
So the point is, triangles.IsNull() is always false here, even though the are faces in the shape, I can't get to any triangles. Does anyone have any ideas? Btw. I'm using VS2005, just headers and libraries, no QT, TCL or whatever's it's name and other stuff.
Thx,
Janko Jerinic
Thu, 05/31/2007 - 14:51
The problem is that the triangulation was never created on the shape. If you were using OCC for visualization, this would typically happen to allow the part to be seen. Since you are using your own visualization, you need to triangulate the shape. Look at the BRepMesh package. In particular, BRepMesh::Mesh.
Fri, 06/01/2007 - 12:19
I'm using too opencascade to tesselate the 3D shapes and I'm importing these tesselated solids in my OpenGl-based software.
You can see below the function to get the triangles composing a shape, face by face :
gp_Pnt[n][3] => list of n triangles (3 sumits by triangle)
gp_Pnt[n][3] GetTesselatedFace(TopoDS_Face face)
{
TopLoc_Location loc;
BRepAdaptor_Surface sf(face, Standard_False);
BRepLProp_SLProps prop(sf, 1, 1e-3);
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
if (triangulation.IsNull()) return;
gp_Pnt2d uv;
gp_Pnt pt;
gp_Pnt listTriangles[n][3];
for (int j = 1; j <= triangulation->NbTriangles(); j++)
{
Poly_Triangle triangle = (triangulation -> Triangles())(j);
for (int k = 1; k <= 3; k++)
{
uv = (triangulation->UVNodes())(triangle(k));
prop.SetParameters(uv.X(), uv.Y());
pt = (triangulation -> Nodes())(triangle(k)).Transformed(loc);
listTriangles[j-1][k-1] = pt;
}
}}
It works fine !
Sat, 06/02/2007 - 11:33
Hello jeancharlesthomas!
I compeled your programm by MS 2005 VC++,
bat I have compiler error:
error C2064: term does not evaluate to a function taking 1 arguments
in line: uv = (triangulation->UVNodes())(triangle(k));
Why? Can you help me?
Best regards!
AlexProk
Thu, 10/04/2007 - 01:21
Hi, Alex,
That error happens to me as well and after I put following sentence
#include
Then error was gone.
Hope that helps.
Wei