Tue, 05/19/2009 - 20:50

Forums:

Hello,

I am developping a 3d viewer based on OpenGL and OpenCascade. I can display with OpenGL parts loaded with OpenCascade. I mesh independently each edge and each face with BRepMesh::Mesh(shape, deflectionAngle).

By default the deflection angle is set to 1.0 for faces and 0.1 for edges.

I want to use a more appropriate deflection angle for each face and edge that would be based on the underlying geometry.

I don't know how to compute this. Maybe with the bounding box ? How this is done with the OpenCascade AIS toolkit ? How would you do that ?

Thanks a lot.

Wed, 05/20/2009 - 10:28

Hi Hugues,

The second parameter in BRepMesh::Mesh is not a deflectionAngle, it has meaning of linear (distance) deflection of triangulation from the geometry.

In AIS, when a shape is to be displayed, its bounding box and tolerances of subshapes are taken into account to compute the deflection value. You can find this code by yourself in sources.

Bearloga

Wed, 05/20/2009 - 12:05

You can have a look at StdPrs_ShadedSurface. I was told that it can calculate the deflection relative to the model size based on an associated model Prs3d_Drawer.

Wed, 05/20/2009 - 17:14

I have found some interesting source code in AIS_Shape.cxx.

It's in the body of AIS_Shape::GetDeflection() (lines 95 to 112).

I reused this source code to compute a more adapted deflection when calling BRepMesh::Mesh() for faces and edges. For some parts, polygon offset is broken (faces overlap edges).

So I used the following code which behaves better :

const double optimalFaceDeflection(const TopoDS_Shape& shape)

{

Bnd_Box bndBox;

BRepBndLib::Add(shape, bndBox);

if (!bndBox.IsVoid())

{

double xmin, ymin, zmin, xmax, ymax, zmax;

bndBox.Get(xmin, ymin, zmin, xmax, ymax, zmax);

return std::max(xmax-xmin, std::max(ymax-ymin, zmax-zmin)) *

1e-3 * 4;

// Note : 1e-3 is the default DeviationCoefficient() of a drawer.

}

else

return 5000000.; // Default MaximalChordialDeviation() of a drawer.

}

const double optimalEdgeDeflection(const TopoDS_Shape& shape)

{

return std::min(::optimalFaceDeflection(shape), 0.1);

}

Timo, I have looked at the source code of StdPrs_ShadedSurface, it's very interesting. It builds a 3d presentation of a surface with triangle strips. No meshing is done, UV parameters are used. Do you know more about this class ? Does it only compute a presentation for surface's iso curves or does it fill the surface ?

Mon, 05/25/2009 - 13:01

Sorry, I don't know more about this class.

But you can have a look in the Visualization-documentation (pdf). There, it is used in an example to compute the shaded presentation of a shape.