questions on BRepMesh_IncrementalMesh

I'm trying to use BRepMesh_IncrementalMesh for triangle meshing of a precise BRep in OpenCascade.
The precise BRep is generated by reading in a STP file.

These are reasonably large and complex STP models - over a 100 individual 3D components in each STP file.

As far as I can tell the STP reader is working fine and does produce a precise BRep.

Every 3D component in the STP file produces a Solid entity in the Brep.
Each Solid entity can have one or more Shells - although it is usually just one.
OpenCascade says that the Shell is Closed - I suppose I can believe that?

I then pass each such Shell in its entirety to BRepMesh_IncrementalMesh, which produces much Polygon Triangulation data

There are many controlling parameters for BRepMesh_IncrementalMesh. I don't fully understand all of them currently.

Anyway I just set 4 parameters:

- linearDeflection
- angularDeflection
- isRelative to FALSE
- inParallel to TRUE

As has been reported elsewhere, linearDefection makes a big difference to the results. angularDefection not so much.

I have set angularDeflection to 10.0 more-or-less for all my cases
I have played around with different values of linearDefection - the resulting triangles usually look reasonable visually

My points are the following:

(1) If the STP file CAD model is good, I think openCascade should, in turn, give me a good, valid, error-free precise Brep. How do I know if the STP file is good? By reading it into a commercial CAD program called SolidEdge and seeing if it complains or not, and by just visual observation of the model on the screen.

(2) This means that each Shell of each Solid should be Closed. Which, in turn, means that each Edge (of is it Wire?) of each Face in this Shell should be perfectly "shared" by its mate in the adjacent Face. Shared means that the geometric Curve defining this Edge should be identical for both Faces. There are probably ways to verify all this by exploring the precise BRep topology - but I have not done this verification.

(3) Since the tessellator begins by discretizing each Edge of each Face in this Shell, this should mean that the Vertices generated on each mate of this common boundary should be identical in number and 3D coordinates.

(4) I believe this should be true regardless of the linearDeflection and angularDeflection settings. In the worst case, there may be ZERO vertices produced in the interior of each Edge. But the two boundary Vertices of each Edge should still exist and be identical on each Edge mate.

(5) Then the tessellator discretizes the interior of each Face, honoring the boundary Vertices just produced.

(6) If all this is true, I should get a a bunch of Triangles for each Face. The Triangle Vertices along the shared Edges should geometrically coincide perfectly. Which in turn means that I can produce a topologically water-tight polyhedron by merging these common boundary Vertices. And this merging operation should be quite robust, since I can set the Vertex merging tolerance to a very small number. Also, as stated in point (4), this should be true regardless of linear and angular tolerance setting. The polyhedron may be a terrible approximation of the model, but it should still be topologically water-tight. Is that true?

(7) There are some more steps in the BRepMesh_IncrementalMesh process, such as healing, pre/post processing, etc. The documentation says these steps can be disabled if needed. But I am unable to determine how to do the disabling. And under what circumstances should I disable some of these?

(8) Please comment on the points above....

(9) Are there any other meshing controlling parameters I should/could/need-to set using IMeshTools_Parameters ?

(10) Is it necessary to explore the precise BRep topology and verify things like:
- every Edge is shared by ONLY two Faces (I only want manifold cases)
- the Vertex locations of each Edge mate are identical
- the Shell is Closed
- the Shell is Oriented
- for Faces with more than one Wire/Loop
- there is one outer Wire and all the others are inner
- they are non intersecting
- for Solids with more than one Shell
- there is one outer Shell and all the others are inner
- the Shells are non intersecting

(11) There are some other triangle meshing algorithms available to BRepMesh_IncrementalMesh. What are the recommendations on when to use which?

Sorry for this long and detailed post. I look forward to your comments.

Best,

KKL KKL

gkv311 n's picture

(1) If the STP file CAD model is good, I think openCascade should, in turn, give me a good, valid, error-free precise Brep. How do I know if the STP file is good? By reading it into a commercial CAD program called SolidEdge and seeing if it complains or not, and by just visual observation of the model on the screen.

Model validity and interoperability between CAD kernels is a complex matter - there is no simple way to say if STEP file is 'valid' or not. Checking that STEP file is fine in SolidEdge doesn't guarantee that STEP file is valid. Different CAD kernels have different shape validity criteria - for that reason, OCCT STEP translator doesn't just read STEP model, but also applies shape healing to make it closer to OCCT shape validity criteria.

There are 3 points to consider:

  1. STEP file format conformance to STEP standard specifications. If model is written incorrectly - than most likely it cannot be read back. However, OCCT reader might tolerate some issues in format. OCCT collects found problems and you may access them to make a log like this for Reading (XSControl_WorkSession::ModelCheckList()) and Translation (Transfer_TransientProcess::CheckList()) steps. Here is an example from CAD Assistant verbose log:
12:49 Count STEP Reader Failures for '1M001934.stp'
       -----    -----------
          22    F:(CONVERSION_BASED_UNIT,NAMED_UNIT,PLANE_ANGLE_UNIT): Parameter n0.1 (dimensions) not an Entity
         137    F:PROPERTY_DEFINITION: Parameter n0.3 (definition) : Entity has illegal type
          Nb Total:159  for 2 items
  1. OCCT STEP translator performs automatic shape healing in attempt to fix model to OCCT shape validity criteria. But it doesn't necessarily successes and may corrupt model due to bugs or when it doesn't know how to deal with problems in model. Shape healing failures during translation step are also logged. In addition, you may use ShapeFix tools in OCCT to check model health after STEP translation is completed on result B-Rep shapes.

  2. There are Recommended Practices for storing Geometric and Assembly Validation Properties in STEP model. Such validation properties may include volume of solid, for example. If originating CAD system writes such properties into STEP file, you may consider comparing real and validation properties to see if model looks conformant to the model from originating system. Cannot say, however, which systems actually write such validation properties into STEP files.

gkv311 n's picture

(6) If all this is true, I should get a a bunch of Triangles for each Face. The Triangle Vertices along the shared Edges should geometrically coincide perfectly. Which in turn means that I can produce a topologically water-tight polyhedron by merging these common boundary Vertices. And this merging operation should be quite robust, since I can set the Vertex merging tolerance to a very small number. Also, as stated in point (4), this should be true regardless of linear and angular tolerance setting. The polyhedron may be a terrible approximation of the model, but it should still be topologically water-tight. Is that true?

In general, your considerations about water-tight mesh generation looks correct. If input B-Rep model is a valid closed Solid shape - then BRepMesh is expected to generate a water-tight mesh on success. It doesn't validate water-tightness of result on its own, though. You might need to perform some mesh quality checks if this property is critical to your application.

Note that algorithm may generate some warnings/errors reported through BRepMesh_IncrementalMesh::GetStatusFlags() as IMeshData_Status mask - make sure to check them as a first step. And of course, you may also struggle into some BRepMesh bugs leading to mesh quality issues.

KKL KKL's picture

thank you indeed for those tips.
shall try them out.....

kkl kkl

KKL KKL's picture

I've been playing around more with the usage of BRepMesh_IncrementalMesh. I am noticing a number of things.
The .stp files are reading in just fine. I've inserted more diagnostics into the reader code and I notice no complaints.

(1) The linear-deflection setting greatly influences the meshing outcome:

(a) Total number of triangles, as expected

(b) Successful and unsuccessful face meshing, NOT as expected

Hard to understand why a 2D Delaunay triangulation would fail by just changing this number.

(c) Water-tight and NON-water-tight triangle meshes (after doing the boundary edge vertex merging)

On further investigation of my non-water-tight triangle meshes, I notice it is because some common edges (the edge shared by 2 faces) do NOT have
the same layout and number of vertex pairs. Wondering how this can happen. If indeed the meshing starts with assigning vertices to common edge boundaries,
they should always match up. During mesh refinement, does the algorithm insert additional vertices along these edge boundaries as well or only in the interior
of the face? I also wonder if some of my problems might be because of the healing, pre-processing and post-processing stages in triangle mesh generation.
Is there a way to disable these stages?

(2) Is 2D Delaunay triangle meshing the only technique available? I have seen some references to alternatives but the details are missing.

gkv311 n's picture

Hard to understand why a 2D Delaunay triangulation would fail by just changing this number.

Consider sharing some models that doesn't work for you and meshing parameters. You may try to weed out a smaller solid from complex model.

(2) Is 2D Delaunay triangle meshing the only technique available?

You may try Delabella algorithm within IMeshTools_Parameters::MeshAlgo parameters for building initial 2D tessellation. But I don't think that it will draw a considerable difference on your issues - most likely the reason is located in another place (like handling tiny edges, self-intersections and similar tricky issues).

KKL KKL's picture

Thank you, gvk311,

If I decide to bug you folks with an example, it will be the simplest one that shows my problem. But before that, I would like to dig in a bit more myself.....in the way you suggested: by systematically exploring the precise Brep and precise geometry. OpenCascade gives good tools for doing this. That seems like a good "pre-processing" step for me to consider in general too.

One more question, if I may: face meshing is always in the 2D space. In lucky cases the underlying surface is planar, making 2D conversion trivial. In other cases, I assume OpenCascade works in the U,V parametric space of the surface. Correct? If so:
(a) Does it somehow scale the U,V parameters to be give a better indication of 3D space distances?
(b) How does it deal with U,V space discontinuities? - for cases with closed surfaces in U, in V, in both?
(c) Is U,V space normalized between 0.0 and 1.0?

Best,

KKL KKL

Mikhail Sazonov's picture

If you pass 10 as angular deflection it may be incorrect as it is treated as radians.
For shape validity checking you may use BRepCheck_Shape class.

KKL KKL's picture

How do the two tolerances (linear and angular) interact?
With an AND or with an OR condition?

Dmitrii Pasukhin's picture

They are used for different things. They are not "tolerace" they are deflection.

Please take a look into documentation Open CASCADE Technology: Mesh

Best regards, Dmitrii.

Mikhail Sazonov's picture

AND