-
-
Notifications
You must be signed in to change notification settings - Fork 401
Improve ShapeTesselator #1474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improve ShapeTesselator #1474
Conversation
Reviewer's GuideRefactors ShapeTesselator to support optional OpenMP-parallel face processing, improves normal computation by using precomputed triangulation normals when available, and optimizes several data paths by preallocating exact buffer sizes and avoiding repeated insert/push_back operations and intermediate string formatting. Updated class diagram for ShapeTesselator parallel processing and normals optimizationclassDiagram
class ShapeTesselator {
- bool computed
- bool use_parallel
- TopoDS_Shape myShape
- Standard_Real myDeviation
- std_vector_face_ptr face_list
- std_vector_edge edge_list
+ ShapeTesselator(aShape)
+ Tessellate(compute_edges, mesh_quality, parallel)
+ GetVerticesPositionAsTuple() const
+ GetNormalsAsTuple() const
+ ExportShapeToX3DTriangleSet() const
- ProcessFaces(faces)
- ProcessSingleFace(face, triangulation, location, face_data)
- ProcessNormals(face, triangulation, face_data)
- ProcessTriangles(face, triangulation, face_data)
}
class Face {
+ std_vector_float vertex_coords
+ std_vector_float normal_coords
+ std_vector_int triangle_indices
+ Standard_Integer number_of_triangles
+ Standard_Integer number_of_normals
+ Standard_Integer number_of_invalid_normals
}
class Edge {
+ std_vector_float vertex_coords
}
ShapeTesselator "1" *-- "*" Face
ShapeTesselator "1" *-- "*" Edge
Flow diagram for ShapeTesselator Tessellate face processing and normals computationflowchart TD
A[Tessellate] --> B[Collect faces from myShape]
B --> C[Set use_parallel flag]
C --> D{OpenMP available and use_parallel and num_faces > 1}
D -->|Yes| E[Parallel for over faces]
D -->|No| F[Sequential loop over faces]
E --> G[For each face:<br/>ProcessSingleFace]
F --> G
G --> H[ProcessNormals]
H --> I{triangulation HasNormals}
I -->|Yes| J[Copy precomputed normals<br/>from triangulation]
I -->|No| K{triangulation HasUVNodes}
K -->|Yes| L[Compute normals<br/>via BRepGProp_Face Normal]
K -->|No| M[Increment<br/>number_of_invalid_normals]
J --> N[Update face_data<br/>normal_coords]
L --> N
M --> N
N --> O[ProcessTriangles<br/>and fill triangle_indices]
O --> P[Append face_data<br/>into face_list]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- In
ExportShapeToX3DTriangleSet, normals are now derived viaconsolidated_triangle_indicesandconsolidated_normalsinstead of usingObjGetTriangle/normals_idx; please double-check that vertex and normal indexing are still aligned for all code paths, as this changes the previous separation of vertex and normal indices and may alter output for cases with distinct normal indexing. - The new
#include <mutex>appears unused after these changes; consider removing it to avoid confusion about implied synchronization mechanisms around the OpenMP parallelization. - The OpenMP branch in
ProcessFaceswrites intoface_listafter the parallel region, butface_listis only reserved tofaces.size()and not cleared beforehand; ifTessellatecan be called multiple times on the same object, consider explicitly clearingface_listbefore appending to avoid accumulating stale data.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ExportShapeToX3DTriangleSet`, normals are now derived via `consolidated_triangle_indices` and `consolidated_normals` instead of using `ObjGetTriangle`/`normals_idx`; please double-check that vertex and normal indexing are still aligned for all code paths, as this changes the previous separation of vertex and normal indices and may alter output for cases with distinct normal indexing.
- The new `#include <mutex>` appears unused after these changes; consider removing it to avoid confusion about implied synchronization mechanisms around the OpenMP parallelization.
- The OpenMP branch in `ProcessFaces` writes into `face_list` after the parallel region, but `face_list` is only reserved to `faces.size()` and not cleared beforehand; if `Tessellate` can be called multiple times on the same object, consider explicitly clearing `face_list` before appending to avoid accumulating stale data.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Optimize and extend ShapeTesselator by adding optional parallel face processing, leveraging precomputed normals when available, and reducing memory allocations and string formatting overhead across tessellation and export routines.
Enhancements: