Tessellation and Surface Tolerance

Vladimir Savelyev

May 23, 2019

Tessellation allows controlling the number of triangles used to represent 3D entities. Use the parameter for surface tolerance, which is the maximum distance between the source analytical surface and triangle mesh. The more precise the tolerance, the more triangles you get.

Rendering of different files (such as .dwg, .dgn, .rvt) with ODA SDKs requires providing surface tolerance information to BrepRenderer. The same is true for other operations based on vectorization, for example exports (STL, Collada) and conversions between different formats. BrepRenderer is a library that performs B-Rep geometry data tessellation computation, caching and drawing to an OdGiCommonDraw object. Surface tolerance is one of its main input parameters.

The deviation must be provided by an inheritor of the OdGiCommonDraw class in a virtual function:

virtual double deviation(
    const OdGiDeviationType deviationType, 
    const OdGePoint3d& pointOnCurve) const;

For tessellation, deviationType must be kOdGiMaxDevForFacet and pointOnCurve must contain a point on the rendering object if you have perspective mode turned on.

The current implementation of the OdGsView class calculates the deviation for the current camera position based on the physical pixel size. This means that the closer you zoom in to the 3D object, the better (more detailed, but with more triangles) the tessellation is calculated. And zooming out from the object makes the tessellation more rough. You can see this effect in the OdaMfcApp sample application. For example, open any 3D solid and vectorize it in flat shaded mode (triangles are better seen in flat mode). Then try zooming in and out and click Regen. You will see that the number of triangles changes.

 

image1

 

This is an example of renderings with different surface tolerances. The upper number is the tolerance, and the lower number is the number of triangles.

If a caller wants to control the surface tolerance, they should implement their own “deviation” function in their own view class. An example is the STLModule::exportSTL function. It gets the tolerance as an input parameter and stores it in an export view class:

class StubVectorizeView : public OdGsBaseVectorizeViewDef, public OdGiGeometrySimplifier
  {
    double m_dDeviation;
    …

And then it returns it as:


virtual double deviation(const OdGiDeviationType deviationType, const OdGePoint3d& pointOnCurve) const
{
 return m_dDeviation;
}