How to accelerate the triangular mesh speed of OCCT is mainly used for visualization.

How to accelerate the triangular mesh speed of OCCT is mainly used for visualization. like mesh LOD?
I have browsed the document. Now, in my test environment, I have encountered a slow grid generation. I saw this sentence in the document.
[wiki-mesh](https://github.com/Open-Cascade-SAS/OCCT/wiki/mesh)

An additional example of a different data model is the case when it is not required to create a mesh with discrete polygons synchronized between adjacent faces, i.e. in case of necessity to speed up creation of a rough per-face tessellation used for visualization or quick computation only (the approach used in XDEDRAW_Props).

`the approach used in XDEDRAW_Props`

I looked up the relevant codes and found nothing. Could someone help me? Or give me some other ideas

Dmitrii Pasukhin's picture

Hello.

I probably expect the idea about XDEDRAW related with Bounding box using to define more preferred quality. 

For example:

namespace
{
  static const double THE_LINEAR_DEFLECTION  = 5.e-3;
  static const double THE_ANGULAR_DEFLECTION = 0.5;
  static const bool   THE_IS_PARALLEL        = false;
}
...
  bool       anIsDone      = false;
  const auto aShapeProcess = [&](const TopoDS_Shape& theSubShape)
  {
    Bnd_Box aBounds;
    BRepBndLib::Add(theSubShape, aBounds);

    IMeshTools_Parameters aParameters;
    const gp_XYZ          aMin           = aBounds.CornerMin().XYZ();
    const gp_XYZ          aMax           = aBounds.CornerMax().XYZ();
    const double          aDeflection    = std::max((aMax - aMin).Modulus() * THE_LINEAR_DEFLECTION, THE_LINEAR_DEFLECTION);
    aParameters.Deflection               = aDeflection;
    aParameters.MinSize                  = aDeflection * 2;
    aParameters.Angle                    = THE_ANGULAR_DEFLECTION;
    aParameters.InParallel               = THE_IS_PARALLEL;
    aParameters.ControlSurfaceDeflection = true;
    aParameters.EnableControlSurfaceDeflectionAllSurfaces = true;
    const BRepMesh_IncrementalMesh aTessellated(theSubShape, aParameters);
    anIsDone = anIsDone || aTessellated.IsDone();
  };

Best regards, Dmitrii.

gkv311 n's picture

I may give only a couple of suggestions:

  • Group all shapes and perform meshing algorithm for entire model with multi-threading option turned on. This would avoid remeshing/handle topological connectivity and would provide better scalability of multi-threading.
  • Start meshing from rough quality to higher quality without clearing previous triangulation after each iteration. This would allow reusing 'incremental' nature of the algorithm, which is able to reuse existing triangulation by extending it's quality (though I cannot say that I've tried this myself).
  • There are also some advanced options in algorithm, which might be tuned to avoid too long meshing on some problematic shapes.
ye na's picture

1. The first scheme (aka Group) you mentioned is also the means I am using now.
2. (Start meshing from rough quality to higher quality)This method is similar to LOD, but the code of grid generation algorithm is very complicated. I have probably read the documents and codes and have a little knowledge. If it can be combined with the visualization module (for example, using different mesh qualities in different viewports, this is also the practice of most CAD software)

ye na's picture

[There are also some advanced options in algorithm, which might be tuned to avoid too long meshing on some problematic shapes]
Some advanced options is the parameter in this class`IMeshTools_Parameters `, and it would be great if it could help me.

ye na's picture

Thank you for your reply.

I read your code. You mean to control the grid quality by controlling different linear deflection, so as to achieve the effect of LOD, right?

gkv311 n's picture

To generate triangulation of different visual quality (aka LODs), you may adjust deflection parameters of BRepMesh (both - angular and linear).

ye na's picture

My idea is to generate meshes with different qualities by controlling the parameters of linear deviation, and use different mesh qualities under different viewport conditions. But how to attach different mesh qualities to AIs_Shape?

ye na's picture

PS:
On my machine, I tested the following code and found that' -algo default' takes 1 minute and 5 seconds, while' -algo delabella' takes 5 seconds. Why is there such a big gap?

```
psphere s 10

### Default Algo ###
incmesh s 0.0001 -algo default

### Delabella Algo ###
incmesh s 0.0001 -algo delabella
```

Mikhail Sazonov's picture

The second run of incmesh reused the existing mesh. Run 'tclean s' before second run to make it fare.

ye na's picture

thanks