From 4f4849a77a45f372a9ad13953ea53d89bc1c538c Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Tue, 16 Dec 2025 10:14:07 +0100 Subject: [PATCH 1/7] changed t8_cad to t8_cad_handle for explicit cad shapemanagement --- src/CMakeLists.txt | 4 +- .../t8_cad_handle.cxx} | 119 ++++++++++++------ .../t8_cad_handle.hxx} | 80 ++++++++++-- .../t8_cmesh_io/t8_cmesh_readmshfile.cxx | 76 +++++------ src/t8_geometry/t8_geometry_hash.hxx | 4 +- .../t8_geometry_cad.cxx | 26 ++-- .../t8_geometry_cad.hxx | 10 +- 7 files changed, 212 insertions(+), 107 deletions(-) rename src/{t8_cad/t8_cad.cxx => t8_cad_handle/t8_cad_handle.cxx} (68%) rename src/{t8_cad/t8_cad.hxx => t8_cad_handle/t8_cad_handle.hxx} (83%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f1f44b9dd..8f228f53c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,12 +108,12 @@ if( T8CODE_ENABLE_OCC ) target_link_libraries( T8 PUBLIC ${OpenCASCADE_LIBRARIES} ) target_sources(T8 PRIVATE t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx - t8_cad/t8_cad.cxx + t8_cad_handle/t8_cad_handle.cxx ) install( FILES t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx t8_geometry/t8_geometry_implementations/t8_geometry_cad.h - t8_cad/t8_cad.hxx + t8_cad_handle/t8_cad_handle.hxx DESTINATION include ) endif() diff --git a/src/t8_cad/t8_cad.cxx b/src/t8_cad_handle/t8_cad_handle.cxx similarity index 68% rename from src/t8_cad/t8_cad.cxx rename to src/t8_cad_handle/t8_cad_handle.cxx index f1a8f9d991..8e0cfe02f0 100644 --- a/src/t8_cad/t8_cad.cxx +++ b/src/t8_cad_handle/t8_cad_handle.cxx @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include @@ -33,8 +33,10 @@ #include #include -t8_cad::t8_cad (std::string fileprefix) +TopoDS_Shape +t8_cad_handle::load_cad_shape (const std::string fileprefix) { + TopoDS_Shape cad_shape; BRep_Builder builder; std::ifstream is (fileprefix + ".brep"); if (is.is_open () == false) { @@ -48,18 +50,24 @@ t8_cad::t8_cad (std::string fileprefix) "Linked cad version: %s", OCC_VERSION_COMPLETE); } - TopExp::MapShapes (cad_shape, TopAbs_VERTEX, cad_shape_vertex_map); - TopExp::MapShapes (cad_shape, TopAbs_EDGE, cad_shape_edge_map); - TopExp::MapShapes (cad_shape, TopAbs_FACE, cad_shape_face_map); - TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_VERTEX, TopAbs_EDGE, cad_shape_vertex2edge_map); - TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); + return cad_shape; } -t8_cad::t8_cad (const TopoDS_Shape cad_shape) +void +t8_cad_handle::map_cad_shape (const TopoDS_Shape &cad_shape_in) { - if (cad_shape.IsNull ()) { + if (cad_shape_in.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } + /* Clear maps before map the new data. */ + cad_shape_vertex_map.Clear (); + cad_shape_edge_map.Clear (); + cad_shape_face_map.Clear (); + cad_shape_vertex2edge_map.Clear (); + cad_shape_edge2face_map.Clear (); + + cad_shape = cad_shape_in; + TopExp::MapShapes (cad_shape, TopAbs_VERTEX, cad_shape_vertex_map); TopExp::MapShapes (cad_shape, TopAbs_EDGE, cad_shape_edge_map); TopExp::MapShapes (cad_shape, TopAbs_FACE, cad_shape_face_map); @@ -67,13 +75,51 @@ t8_cad::t8_cad (const TopoDS_Shape cad_shape) TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); } -t8_cad::t8_cad () +t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) +{ + if (cad_shape_in.IsNull ()) { + SC_ABORTF ("Shape is null. \n"); + } + t8_refcount_init (&rc); + t8_debugf ("Constructed the cad_handle.\n"); + + t8_cad_handle::map_cad_shape (cad_shape_in); +} + +t8_cad_handle::t8_cad_handle (std::string fileprefix): t8_cad_handle (load_cad_shape (fileprefix)) { +} + +t8_cad_handle::t8_cad_handle () +{ + t8_refcount_init (&rc); + t8_debugf ("Constructed the empty cad_handle.\n"); cad_shape.Nullify (); } +t8_cad_handle::~t8_cad_handle () +{ + t8_debugf ("Deleted the cad_handle.\n"); +} + +void +t8_cad_handle::update_cad_shape (const std::string fileprefix) +{ + /* Load the new cad shape from the fileprefix. */ + TopoDS_Shape new_cad_shape = t8_cad_handle::load_cad_shape (fileprefix); + /* Map the new cad shape. */ + t8_cad_handle::map_cad_shape (new_cad_shape); +} + +void +t8_cad_handle::update_cad_shape (const TopoDS_Shape &new_cad_shape) +{ + /* Map the new cad shape. */ + t8_cad_handle::map_cad_shape (new_cad_shape); +} + int -t8_cad::t8_geom_is_line (const int curve_index) const +t8_cad_handle::t8_geom_is_line (const int curve_index) const { const Handle_Geom_Curve curve = t8_geom_get_cad_curve (curve_index); const GeomAdaptor_Curve curve_adaptor (curve); @@ -81,7 +127,7 @@ t8_cad::t8_geom_is_line (const int curve_index) const } int -t8_cad::t8_geom_is_plane (const int surface_index) const +t8_cad_handle::t8_geom_is_plane (const int surface_index) const { const Handle_Geom_Surface surface = t8_geom_get_cad_surface (surface_index); const GeomAdaptor_Surface surface_adaptor (surface); @@ -89,14 +135,14 @@ t8_cad::t8_geom_is_plane (const int surface_index) const } const gp_Pnt -t8_cad::t8_geom_get_cad_point (const int index) const +t8_cad_handle::t8_geom_get_cad_point (const int index) const { T8_ASSERT (index <= cad_shape_vertex_map.Size ()); return BRep_Tool::Pnt (TopoDS::Vertex (cad_shape_vertex_map.FindKey (index))); } const Handle_Geom_Curve -t8_cad::t8_geom_get_cad_curve (const int index) const +t8_cad_handle::t8_geom_get_cad_curve (const int index) const { T8_ASSERT (index <= cad_shape_edge_map.Size ()); Standard_Real first, last; @@ -104,32 +150,32 @@ t8_cad::t8_geom_get_cad_curve (const int index) const } const Handle_Geom_Surface -t8_cad::t8_geom_get_cad_surface (const int index) const +t8_cad_handle::t8_geom_get_cad_surface (const int index) const { T8_ASSERT (index <= cad_shape_face_map.Size ()); return BRep_Tool::Surface (TopoDS::Face (cad_shape_face_map.FindKey (index))); } const TopTools_IndexedMapOfShape -t8_cad::t8_geom_get_cad_shape_vertex_map () const +t8_cad_handle::t8_geom_get_cad_shape_vertex_map () const { return cad_shape_vertex_map; } const TopTools_IndexedMapOfShape -t8_cad::t8_geom_get_cad_shape_edge_map () const +t8_cad_handle::t8_geom_get_cad_shape_edge_map () const { return cad_shape_edge_map; } const TopTools_IndexedMapOfShape -t8_cad::t8_geom_get_cad_shape_face_map () const +t8_cad_handle::t8_geom_get_cad_shape_face_map () const { return cad_shape_face_map; } int -t8_cad::t8_geom_get_common_edge (const int vertex1_index, const int vertex2_index) const +t8_cad_handle::t8_geom_get_common_edge (const int vertex1_index, const int vertex2_index) const { const TopTools_ListOfShape collection1 = cad_shape_vertex2edge_map.FindFromIndex (vertex1_index); const TopTools_ListOfShape collection2 = cad_shape_vertex2edge_map.FindFromIndex (vertex2_index); @@ -145,7 +191,7 @@ t8_cad::t8_geom_get_common_edge (const int vertex1_index, const int vertex2_inde } int -t8_cad::t8_geom_get_common_face (const int edge1_index, const int edge2_index) const +t8_cad_handle::t8_geom_get_common_face (const int edge1_index, const int edge2_index) const { const TopTools_ListOfShape collection1 = cad_shape_edge2face_map.FindFromIndex (edge1_index); const TopTools_ListOfShape collection2 = cad_shape_edge2face_map.FindFromIndex (edge2_index); @@ -161,21 +207,21 @@ t8_cad::t8_geom_get_common_face (const int edge1_index, const int edge2_index) c } int -t8_cad::t8_geom_is_vertex_on_edge (const int vertex_index, const int edge_index) const +t8_cad_handle::t8_geom_is_vertex_on_edge (const int vertex_index, const int edge_index) const { const TopTools_ListOfShape collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); return collection.Contains (cad_shape_edge_map.FindKey (edge_index)); } int -t8_cad::t8_geom_is_edge_on_face (const int edge_index, const int face_index) const +t8_cad_handle::t8_geom_is_edge_on_face (const int edge_index, const int face_index) const { const TopTools_ListOfShape collection = cad_shape_edge2face_map.FindFromIndex (edge_index); return collection.Contains (cad_shape_face_map.FindKey (face_index)); } int -t8_cad::t8_geom_is_vertex_on_face (const int vertex_index, const int face_index) const +t8_cad_handle::t8_geom_is_vertex_on_face (const int vertex_index, const int face_index) const { const TopTools_ListOfShape edge_collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); for (auto edge = edge_collection.begin (); edge != edge_collection.end (); ++edge) { @@ -188,19 +234,20 @@ t8_cad::t8_geom_is_vertex_on_face (const int vertex_index, const int face_index) } void -t8_cad::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param) const +t8_cad_handle::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, + double *edge_param) const { - T8_ASSERT (t8_cad::t8_geom_is_vertex_on_edge (vertex_index, edge_index)); + T8_ASSERT (t8_cad_handle::t8_geom_is_vertex_on_edge (vertex_index, edge_index)); TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); *edge_param = BRep_Tool::Parameter (vertex, edge); } void -t8_cad::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, - double *face_params) const +t8_cad_handle::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, + double *face_params) const { - T8_ASSERT (t8_cad::t8_geom_is_vertex_on_face (vertex_index, face_index)); + T8_ASSERT (t8_cad_handle::t8_geom_is_vertex_on_face (vertex_index, face_index)); gp_Pnt2d uv; TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Face face = TopoDS::Face (cad_shape_face_map.FindKey (face_index)); @@ -210,11 +257,11 @@ t8_cad::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const } void -t8_cad::t8_geom_edge_parameter_to_face_parameters (const int edge_index, const int face_index, const int num_face_nodes, - const double edge_param, const double *surface_params, - double *face_params) const +t8_cad_handle::t8_geom_edge_parameter_to_face_parameters (const int edge_index, const int face_index, + const int num_face_nodes, const double edge_param, + const double *surface_params, double *face_params) const { - T8_ASSERT (t8_cad::t8_geom_is_edge_on_face (edge_index, face_index)); + T8_ASSERT (t8_cad_handle::t8_geom_is_edge_on_face (edge_index, face_index)); Standard_Real first, last; gp_Pnt2d uv; TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); @@ -263,14 +310,14 @@ t8_cad::t8_geom_edge_parameter_to_face_parameters (const int edge_index, const i } void -t8_cad::t8_geom_get_face_parametric_bounds (const int surface_index, double *bounds) const +t8_cad_handle::t8_geom_get_face_parametric_bounds (const int surface_index, double *bounds) const { const Handle_Geom_Surface cad_surface = t8_geom_get_cad_surface (surface_index); cad_surface->Bounds (bounds[0], bounds[1], bounds[2], bounds[3]); } void -t8_cad::t8_geom_get_edge_parametric_bounds (const int edge_index, double *bounds) const +t8_cad_handle::t8_geom_get_edge_parametric_bounds (const int edge_index, double *bounds) const { const Handle_Geom_Curve cad_edge = t8_geom_get_cad_curve (edge_index); bounds[0] = cad_edge->FirstParameter (); @@ -278,14 +325,14 @@ t8_cad::t8_geom_get_edge_parametric_bounds (const int edge_index, double *bounds } int -t8_cad::t8_geom_is_edge_closed (int edge_index) const +t8_cad_handle::t8_geom_is_edge_closed (int edge_index) const { const Handle_Geom_Curve cad_edge = t8_geom_get_cad_curve (edge_index); return cad_edge->IsClosed (); } int -t8_cad::t8_geom_is_surface_closed (int geometry_index, int parameter) const +t8_cad_handle::t8_geom_is_surface_closed (int geometry_index, int parameter) const { const Handle_Geom_Surface cad_surface = t8_geom_get_cad_surface (geometry_index); switch (parameter) { diff --git a/src/t8_cad/t8_cad.hxx b/src/t8_cad_handle/t8_cad_handle.hxx similarity index 83% rename from src/t8_cad/t8_cad.hxx rename to src/t8_cad_handle/t8_cad_handle.hxx index 25ebd82f89..3de2364a05 100644 --- a/src/t8_cad/t8_cad.hxx +++ b/src/t8_cad_handle/t8_cad_handle.hxx @@ -20,26 +20,27 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file t8_geometry_cad.hxx - * This file implements the t8_cad class. It manages OpenCASCADE shapes and implements +/** \file t8_cad_handle.hxx + * This file implements the t8_cad_handle class. It manages OpenCASCADE shapes and implements * helper functions for working with the shapes. */ -#ifndef T8_CAD_HXX -#define T8_CAD_HXX +#ifndef T8_CAD_HANDLE_HXX +#define T8_CAD_HANDLE_HXX #include #include #include #include +#include /** * This class manages OpenCASCADE shapes and implements helper functions for working with the shapes. */ -class t8_cad { +class t8_cad_handle { public: /** - * Constructor of the cad shape. + * Constructor of the cad shape handler. * The shape is initialized based on a .brep file with the given prefix. * The internal structure extracts and stores geometric information such as * vertices, edges, and faces from this file. The number and type of vertices @@ -48,8 +49,7 @@ class t8_cad { * * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ - t8_cad (std::string fileprefix); - + t8_cad_handle (std::string fileprefix); /** * Constructor of the cad shape. * The shape is initialized directly from an existing TopoDS_Shape. @@ -59,12 +59,46 @@ class t8_cad { * * \param [in] cad_shape cad shape geometry object. */ - t8_cad (const TopoDS_Shape cad_shape); + t8_cad_handle (const TopoDS_Shape cad_shape); /** * Constructor of the cad shape for testing purposes. Sets an invalid cad_shape. */ - t8_cad (); + t8_cad_handle (); + + /** + * Destructor of the cad shape handler. + */ + ~t8_cad_handle (); + + /** + * Loads a cad shape from a .brep file with the given prefix. + * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. + * \return The loaded cad shape. + */ + static TopoDS_Shape + load_cad_shape (const std::string fileprefix); + + /** + * Map the cad shape to extract vertices, edges, faces, and their relationships. + * \param [in] cad_shape_in The input cad shape to be mapped. + */ + void + map_cad_shape (const TopoDS_Shape &cad_shape_in); + + /** + * Updates the cad shape from a .brep file with the given prefix. + * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. + */ + void + update_cad_shape (const std::string fileprefix); + + /** + * Updates the cad shape directly from an existing TopoDS_Shape. + * \param [in] new_cad_shape cad shape geometry object. + */ + void + update_cad_shape (const TopoDS_Shape &new_cad_shape); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. @@ -226,6 +260,28 @@ class t8_cad { int t8_geom_is_surface_closed (int geometry_index, int parameter) const; + /** + * Increase the reference count of the cad handler. + */ + inline void + ref () + { + t8_refcount_ref (&rc); + } + + /** + * Decrease the reference count of the cad handler. + * If the reference count reaches zero, the cad handler is deleted. + */ + inline void + unref () + { + if (t8_refcount_unref (&rc)) { + t8_debugf ("Deleting the cad_handler.\n"); + delete this; + } + } + private: TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex in shape. */ @@ -235,6 +291,8 @@ class t8_cad { cad_shape_vertex2edge_map; /**< Maps all TopoDS_Vertex of shape to all its connected TopoDS_Edge */ TopTools_IndexedDataMapOfShapeListOfShape cad_shape_edge2face_map; /**< Maps all TopoDS_Edge of shape to all its connected TopoDS_Face */ + /** The reference count of the cad handler. TODO: Replace by shared_ptr when cmesh becomes a class. */ + t8_refcount_t rc; }; -#endif /* !T8_CAD_HXX */ +#endif /* !T8_CAD_HANDLE_HXX */ diff --git a/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx b/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx index 690bb85a11..798a7ed57d 100644 --- a/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx +++ b/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx @@ -805,13 +805,13 @@ t8_cmesh_correct_parameters_on_closed_geometry (const int geometry_dim, const in /* Check for closed U parameter in case of an edge. */ case 1: /* Only correct the U parameter if the edge is closed. */ - if (geometry_cad->get_cad_manager ()->t8_geom_is_edge_closed (geometry_index)) { + if (geometry_cad->get_cad_handle ()->t8_geom_is_edge_closed (geometry_index)) { /* Get the parametric bounds of the closed geometry * edge -> [Umin, Umax] */ double parametric_bounds[2]; /* Get the parametric edge bounds. */ - geometry_cad->get_cad_manager ()->t8_geom_get_edge_parametric_bounds (geometry_index, parametric_bounds); + geometry_cad->get_cad_handle ()->t8_geom_get_edge_parametric_bounds (geometry_index, parametric_bounds); /* Check the upper an the lower parametric bound. */ for (int bound = 0; bound < 2; ++bound) { /* Iterate over both nodes of the edge. */ @@ -843,12 +843,12 @@ t8_cmesh_correct_parameters_on_closed_geometry (const int geometry_dim, const in /* Iterate over both parameters. 0 stands for the U parameter an 1 for the V parameter. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { /* Only correct the surface parameters if they are closed */ - if (geometry_cad->get_cad_manager ()->t8_geom_is_surface_closed (geometry_index, param_dim)) { + if (geometry_cad->get_cad_handle ()->t8_geom_is_surface_closed (geometry_index, param_dim)) { /* Get the parametric bounds of the closed geometry * surface -> [Umin, Umax, Vmin, Vmax] */ double parametric_bounds[4]; - geometry_cad->get_cad_manager ()->t8_geom_get_face_parametric_bounds (geometry_index, parametric_bounds); + geometry_cad->get_cad_handle ()->t8_geom_get_face_parametric_bounds (geometry_index, parametric_bounds); /* Check the upper an the lower parametric bound. */ for (int bound = 0; bound < 2; ++bound) { /* Iterate over every corner node of the tree. */ @@ -1057,7 +1057,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If both nodes are on a vertex we look if both vertices share an edge */ if (node1.entity_dim == 0 && node2.entity_dim == 0) { int common_edge - = cad_geometry->get_cad_manager ()->t8_geom_get_common_edge (node1.entity_tag, node2.entity_tag); + = cad_geometry->get_cad_handle ()->t8_geom_get_common_edge (node1.entity_tag, node2.entity_tag); if (common_edge > 0) { if (edge1_index == 0) { edge1_index = common_edge; @@ -1071,7 +1071,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (edge2_index > 0) { - surface_index = cad_geometry->get_cad_manager ()->t8_geom_get_common_face (edge1_index, edge2_index); + surface_index = cad_geometry->get_cad_handle ()->t8_geom_get_common_face (edge1_index, edge2_index); } else { continue; @@ -1092,9 +1092,9 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t else { /* If it is on another geometry we retrieve its parameters */ if (face_nodes[i_face_nodes].entity_dim == 0) { - if (cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_face (face_nodes[i_face_nodes].entity_tag, - surface_index)) { - cad_geometry->get_cad_manager ()->t8_geom_get_parameters_of_vertex_on_face ( + if (cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (face_nodes[i_face_nodes].entity_tag, + surface_index)) { + cad_geometry->get_cad_handle ()->t8_geom_get_parameters_of_vertex_on_face ( face_nodes[i_face_nodes].entity_tag, surface_index, face_nodes[i_face_nodes].parameters.data ()); face_nodes[i_face_nodes].entity_dim = 2; } @@ -1104,9 +1104,9 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (face_nodes[i_face_nodes].entity_dim == 1) { - if (cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face (face_nodes[i_face_nodes].entity_tag, - surface_index)) { - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + if (cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (face_nodes[i_face_nodes].entity_tag, + surface_index)) { + cad_geometry->get_cad_handle ()->t8_geom_edge_parameter_to_face_parameters ( face_nodes[i_face_nodes].entity_tag, surface_index, num_face_nodes, face_nodes[i_face_nodes].parameters[0], NULL, face_nodes[i_face_nodes].parameters.data ()); face_nodes[i_face_nodes].entity_dim = 2; @@ -1119,7 +1119,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } /* Abort if not all nodes are on the surface or if the surface is a plane */ - if (!all_nodes_on_surface || cad_geometry->get_cad_manager ()->t8_geom_is_plane (surface_index)) { + if (!all_nodes_on_surface || cad_geometry->get_cad_handle ()->t8_geom_is_plane (surface_index)) { continue; } /* If we have found a surface we link it to the face */ @@ -1145,7 +1145,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } /* Corrects the parameters on the surface if it is closed to prevent disorted elements. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { - if (cad_geometry->get_cad_manager ()->t8_geom_is_surface_closed (surface_index, param_dim)) { + if (cad_geometry->get_cad_handle ()->t8_geom_is_surface_closed (surface_index, param_dim)) { t8_cmesh_correct_parameters_on_closed_geometry (2, surface_index, num_face_nodes, cad_geometry, parameters); } } @@ -1200,22 +1200,22 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t int is_on_geom = 1; for (int i_edge = 0; i_edge < 2; ++i_edge) { if (edge_geometry_dim == 2 && edge_nodes[i_edge].entity_dim == 1) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (edge_nodes[i_edge].entity_tag, + edge_geometry_tag)) { is_on_geom = 0; break; } } else if (edge_geometry_dim == 2 && edge_nodes[i_edge].entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge].entity_tag, + edge_geometry_tag)) { is_on_geom = 0; break; } } else if (edge_geometry_dim == 1 && edge_nodes[i_edge].entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge].entity_tag, + edge_geometry_tag)) { is_on_geom = 0; break; } @@ -1230,8 +1230,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t * But we can look if both vertices share an edge and use this edge. * If not we can skip this edge. */ if (edge_geometry_dim == 0 && edge_geometry_tag == 0) { - int common_curve = cad_geometry->get_cad_manager ()->t8_geom_get_common_edge (edge_nodes[0].entity_tag, - edge_nodes[1].entity_tag); + int common_curve + = cad_geometry->get_cad_handle ()->t8_geom_get_common_edge (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); if (common_curve > 0) { edge_geometry_tag = common_curve; edge_geometry_dim = 1; @@ -1244,8 +1244,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t * If not we can skip this edge */ if (edge_nodes[0].entity_dim == 1 && edge_nodes[1].entity_dim == 1 && edge_nodes[0].entity_tag != edge_nodes[1].entity_tag) { - int common_surface = cad_geometry->get_cad_manager ()->t8_geom_get_common_face (edge_nodes[0].entity_tag, - edge_nodes[1].entity_tag); + int common_surface + = cad_geometry->get_cad_handle ()->t8_geom_get_common_face (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); if (common_surface > 0) { edge_geometry_tag = common_surface; edge_geometry_dim = 2; @@ -1259,7 +1259,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* Check if adjacent faces carry a surface and if this edge lies on the surface */ for (int i_adjacent_face = 0; i_adjacent_face < 2; ++i_adjacent_face) { if (face_geometries[t8_edge_to_face[eclass][i_tree_edges][i_adjacent_face]] > 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face ( + if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face ( edge_geometry_tag, face_geometries[t8_edge_to_face[eclass][i_tree_edges][i_adjacent_face]])) { t8_global_errorf ("Error: Adjacent edge and face of a tree carry " "incompatible geometries.\n"); @@ -1282,8 +1282,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t return 0; } if (edge_nodes[i_edge_node].entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on a vertex which lies on an edge, " "but the vertex does not lie on that edge.\n", edge_nodes[i_edge_node].index); @@ -1293,14 +1293,14 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If the node lies on a vertex we retrieve its parameter on the curve */ if (edge_nodes[i_edge_node].entity_dim == 0) { - cad_geometry->get_cad_manager ()->t8_geom_get_parameter_of_vertex_on_edge ( + cad_geometry->get_cad_handle ()->t8_geom_get_parameter_of_vertex_on_edge ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 1; } } /* Abort if the edge is a line */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_line (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->t8_geom_is_line (edge_geometry_tag)) { continue; } @@ -1310,7 +1310,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t parameters[1] = edge_nodes[1].parameters[0]; /* Corrects the parameters on the edge if it is closed to prevent disorted elements. */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_edge_closed (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->t8_geom_is_edge_closed (edge_geometry_tag)) { t8_cmesh_correct_parameters_on_closed_geometry (1, edge_geometry_tag, 2, cad_geometry, parameters); } @@ -1330,8 +1330,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t return 0; } if (edge_nodes[i_edge_node].entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on a vertex which lies on a face, " "but the vertex does not lie on that face.\n", edge_nodes[i_edge_node].index); @@ -1339,8 +1339,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (edge_nodes[i_edge_node].entity_dim == 1) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on an edge which lies on a face, " "but the edge does not lie on that face.\n", edge_nodes[i_edge_node].index); @@ -1350,14 +1350,14 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If the node lies on a vertex we retrieve its parameters on the surface */ if (edge_nodes[i_edge_node].entity_dim == 0) { - cad_geometry->get_cad_manager ()->t8_geom_get_parameters_of_vertex_on_face ( + cad_geometry->get_cad_handle ()->t8_geom_get_parameters_of_vertex_on_face ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 2; } /* If the node lies on an edge we have to do the same */ if (edge_nodes[i_edge_node].entity_dim == 1) { const int num_face_nodes = t8_eclass_num_vertices[eclass]; - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->t8_geom_edge_parameter_to_face_parameters ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, num_face_nodes, edge_nodes[i_edge_node].parameters[0], parameters, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 2; @@ -1365,7 +1365,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } /* Abort if the edge is a line */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_line (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->t8_geom_is_line (edge_geometry_tag)) { continue; } @@ -1378,7 +1378,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* Corrects the parameters on the surface if it is closed to prevent disorted elements. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { - if (cad_geometry->get_cad_manager ()->t8_geom_is_surface_closed (edge_geometry_tag, param_dim)) { + if (cad_geometry->get_cad_handle ()->t8_geom_is_surface_closed (edge_geometry_tag, param_dim)) { t8_cmesh_correct_parameters_on_closed_geometry (2, edge_geometry_tag, 2, cad_geometry, parameters); } } diff --git a/src/t8_geometry/t8_geometry_hash.hxx b/src/t8_geometry/t8_geometry_hash.hxx index 68084d87d8..4fc3201f64 100644 --- a/src/t8_geometry/t8_geometry_hash.hxx +++ b/src/t8_geometry/t8_geometry_hash.hxx @@ -49,7 +49,7 @@ static const t8_geometry_hash t8_geometry_empty_hash (std::hash {}( /** * Compute the hash value of a geometry's name. * - * \param [in] name The name of a geoemetry. + * \param [in] name The name of a geometry. * \return The hash value of \a name. * \note \a name being empty here is explicitly allowed and used as hash values for non-existing geometries. */ @@ -61,7 +61,7 @@ t8_geometry_compute_hash (const std::string &name) } /** - * Query whether a given hash value corresponds to en empty string and hence + * Query whether a given hash value corresponds to an empty string and hence * a non-existing geometry. * * \param [in] hash A hash value of a geometry. diff --git a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx index f7225ca0d7..1ec6e2629f 100644 --- a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx +++ b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx @@ -51,13 +51,13 @@ const int t8_face_ref_coords_tet[4][2] = { { 2, 1 }, { 0, 1 }, { 0, 1 }, { 0, 2 t8_geometry_cad::t8_geometry_cad (std::string fileprefix, std::string name_in): t8_geometry_with_vertices (name_in) { - cad_manager = std::make_shared (fileprefix); + cad_handle = std::make_shared (fileprefix); } t8_geometry_cad::t8_geometry_cad (const TopoDS_Shape cad_shape, std::string name_in) : t8_geometry_with_vertices (name_in) { - cad_manager = std::make_shared (cad_shape); + cad_handle = std::make_shared (cad_shape); } t8_geometry_cad::t8_geometry_cad (): t8_geometry_with_vertices ("t8_geom_cad") @@ -222,9 +222,9 @@ t8_geometry_cad::t8_geom_evaluate_cad_tri (t8_cmesh_t cmesh, t8_gloidx_t gtreeid t8_geom_linear_interpolation (&ref_intersection[(i_edge == 0) + offset_2d], edge_parameters, 1, 1, &interpolated_curve_parameter); /* Convert the interpolated edge parameter of each reference point to surface parameters */ - cad_manager->t8_geom_edge_parameter_to_face_parameters (edges[i_edge], *faces, num_face_nodes, - interpolated_curve_parameter, face_parameters, - converted_edge_surface_parameters + offset_2d); + cad_handle->t8_geom_edge_parameter_to_face_parameters (edges[i_edge], *faces, num_face_nodes, + interpolated_curve_parameter, face_parameters, + converted_edge_surface_parameters + offset_2d); } double edge_surface_parameters[4]; @@ -396,7 +396,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei pnt = process_curve (i_edge, temp_edge_parameters[0]); /* Convert curve parameter to surface parameters */ - cad_manager->t8_geom_edge_parameter_to_face_parameters ( + cad_handle->t8_geom_edge_parameter_to_face_parameters ( edges[i_edge], *faces, num_face_nodes, temp_edge_parameters[0], face_parameters, temp_edge_parameters); /* Interpolate between the surface parameters of the current edge */ @@ -420,7 +420,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei } /* Retrieve surface */ - auto surface = cad_manager->t8_geom_get_cad_surface (*faces); + auto surface = cad_handle->t8_geom_get_cad_surface (*faces); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -478,7 +478,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei if (edges[i_edge] > 0) { /* Retrieve curve */ - auto curve = cad_manager->t8_geom_get_cad_curve (edges[i_edge]); + auto curve = cad_handle->t8_geom_get_cad_curve (edges[i_edge]); /* Check if curve are valid */ T8_ASSERT (!curve.IsNull ()); @@ -510,7 +510,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei } else { /* Get surface */ - auto surface = cad_manager->t8_geom_get_cad_surface (edges[i_edge + num_edges]); + auto surface = cad_handle->t8_geom_get_cad_surface (edges[i_edge + num_edges]); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -618,7 +618,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_tet (t8_cmesh_t cmesh, t8_gloidx_t gtreeid /* Linear interpolation between parameters */ t8_geom_linear_interpolation (&interpolation_coeff, parameters, 2, 1, interpolated_surface_params); - T8_ASSERT (edges[i_edge + num_edges] <= cad_manager->t8_geom_get_cad_shape_face_map ().Size ()); + T8_ASSERT (edges[i_edge + num_edges] <= cad_handle->t8_geom_get_cad_shape_face_map ().Size ()); pnt = process_surface (i_edge + num_edges, interpolated_surface_params, 0); } @@ -965,7 +965,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_hex (t8_cmesh_t cmesh, t8_gloidx_t gtreeid } /* Convert the interpolated parameter of the curve into the corresponding parameters on the surface */ const int num_face_nodes = t8_eclass_num_vertices[T8_ECLASS_QUAD]; - cad_manager->t8_geom_edge_parameter_to_face_parameters ( + cad_handle->t8_geom_edge_parameter_to_face_parameters ( edges[t8_face_edge_to_tree_edge[T8_ECLASS_HEX][i_faces][i_face_edge]], faces[i_faces], num_face_nodes, interpolated_curve_param, surface_parameters, surface_parameters_from_curve); @@ -1276,7 +1276,7 @@ t8_geometry_cad::process_curve (const int edge_index, const double interpolated_ gp_Pnt pnt; /* Retrieve the curve of the edge */ - auto curve = cad_manager->t8_geom_get_cad_curve (edges[edge_index]); + auto curve = cad_handle->t8_geom_get_cad_curve (edges[edge_index]); /* Check if curve is valid */ T8_ASSERT (!curve.IsNull ()); @@ -1293,7 +1293,7 @@ t8_geometry_cad::process_surface (const int face_index, const double *interpolat gp_Pnt pnt; /* Retrieve the surface of the edge */ - auto surface = cad_manager->t8_geom_get_cad_surface (faces[face_index]); + auto surface = cad_handle->t8_geom_get_cad_surface (faces[face_index]); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); diff --git a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx index 5ec99951d8..543e4dbcd0 100644 --- a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx +++ b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -147,10 +147,10 @@ struct t8_geometry_cad: public t8_geometry_with_vertices * * \return The CAD manager of the geometry. */ - std::shared_ptr - get_cad_manager () const + std::shared_ptr + get_cad_handle () const { - return cad_manager; + return cad_handle; } private: @@ -217,7 +217,7 @@ struct t8_geometry_cad: public t8_geometry_with_vertices const int *edges; /**< The linked edges of the currently active tree. */ const int *faces; /**< The linked faces of the currently active tree. */ - std::shared_ptr cad_manager; /**< The CAD manager of the geometry. */ + std::shared_ptr cad_handle; /**< The CAD manager of the geometry. */ gp_Pnt process_curve (const int edge_index, const double interpolated_curve_param) const; From 32b7cb6e5fb24cb730b19b89ecf7a5c7c097c5dc Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Mon, 12 Jan 2026 13:05:49 +0100 Subject: [PATCH 2/7] removed t8_geom prefix from t8_cad_handle --- src/t8_cad_handle/t8_cad_handle.cxx | 65 +++++++++-------- src/t8_cad_handle/t8_cad_handle.hxx | 43 ++++++------ .../t8_cmesh_io/t8_cmesh_readmshfile.cxx | 69 +++++++++---------- .../t8_geometry_cad.cxx | 24 +++---- 4 files changed, 97 insertions(+), 104 deletions(-) diff --git a/src/t8_cad_handle/t8_cad_handle.cxx b/src/t8_cad_handle/t8_cad_handle.cxx index 8e0cfe02f0..2b18834e56 100644 --- a/src/t8_cad_handle/t8_cad_handle.cxx +++ b/src/t8_cad_handle/t8_cad_handle.cxx @@ -119,30 +119,30 @@ t8_cad_handle::update_cad_shape (const TopoDS_Shape &new_cad_shape) } int -t8_cad_handle::t8_geom_is_line (const int curve_index) const +t8_cad_handle::is_line (const int curve_index) const { - const Handle_Geom_Curve curve = t8_geom_get_cad_curve (curve_index); + const Handle_Geom_Curve curve = get_cad_curve (curve_index); const GeomAdaptor_Curve curve_adaptor (curve); return curve_adaptor.GetType () == GeomAbs_Line; } int -t8_cad_handle::t8_geom_is_plane (const int surface_index) const +t8_cad_handle::is_plane (const int surface_index) const { - const Handle_Geom_Surface surface = t8_geom_get_cad_surface (surface_index); + const Handle_Geom_Surface surface = get_cad_surface (surface_index); const GeomAdaptor_Surface surface_adaptor (surface); return surface_adaptor.GetType () == GeomAbs_Plane; } const gp_Pnt -t8_cad_handle::t8_geom_get_cad_point (const int index) const +t8_cad_handle::get_cad_point (const int index) const { T8_ASSERT (index <= cad_shape_vertex_map.Size ()); return BRep_Tool::Pnt (TopoDS::Vertex (cad_shape_vertex_map.FindKey (index))); } const Handle_Geom_Curve -t8_cad_handle::t8_geom_get_cad_curve (const int index) const +t8_cad_handle::get_cad_curve (const int index) const { T8_ASSERT (index <= cad_shape_edge_map.Size ()); Standard_Real first, last; @@ -150,32 +150,32 @@ t8_cad_handle::t8_geom_get_cad_curve (const int index) const } const Handle_Geom_Surface -t8_cad_handle::t8_geom_get_cad_surface (const int index) const +t8_cad_handle::get_cad_surface (const int index) const { T8_ASSERT (index <= cad_shape_face_map.Size ()); return BRep_Tool::Surface (TopoDS::Face (cad_shape_face_map.FindKey (index))); } const TopTools_IndexedMapOfShape -t8_cad_handle::t8_geom_get_cad_shape_vertex_map () const +t8_cad_handle::get_cad_shape_vertex_map () const { return cad_shape_vertex_map; } const TopTools_IndexedMapOfShape -t8_cad_handle::t8_geom_get_cad_shape_edge_map () const +t8_cad_handle::get_cad_shape_edge_map () const { return cad_shape_edge_map; } const TopTools_IndexedMapOfShape -t8_cad_handle::t8_geom_get_cad_shape_face_map () const +t8_cad_handle::get_cad_shape_face_map () const { return cad_shape_face_map; } int -t8_cad_handle::t8_geom_get_common_edge (const int vertex1_index, const int vertex2_index) const +t8_cad_handle::get_common_edge (const int vertex1_index, const int vertex2_index) const { const TopTools_ListOfShape collection1 = cad_shape_vertex2edge_map.FindFromIndex (vertex1_index); const TopTools_ListOfShape collection2 = cad_shape_vertex2edge_map.FindFromIndex (vertex2_index); @@ -191,7 +191,7 @@ t8_cad_handle::t8_geom_get_common_edge (const int vertex1_index, const int verte } int -t8_cad_handle::t8_geom_get_common_face (const int edge1_index, const int edge2_index) const +t8_cad_handle::get_common_face (const int edge1_index, const int edge2_index) const { const TopTools_ListOfShape collection1 = cad_shape_edge2face_map.FindFromIndex (edge1_index); const TopTools_ListOfShape collection2 = cad_shape_edge2face_map.FindFromIndex (edge2_index); @@ -207,21 +207,21 @@ t8_cad_handle::t8_geom_get_common_face (const int edge1_index, const int edge2_i } int -t8_cad_handle::t8_geom_is_vertex_on_edge (const int vertex_index, const int edge_index) const +t8_cad_handle::is_vertex_on_edge (const int vertex_index, const int edge_index) const { const TopTools_ListOfShape collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); return collection.Contains (cad_shape_edge_map.FindKey (edge_index)); } int -t8_cad_handle::t8_geom_is_edge_on_face (const int edge_index, const int face_index) const +t8_cad_handle::is_edge_on_face (const int edge_index, const int face_index) const { const TopTools_ListOfShape collection = cad_shape_edge2face_map.FindFromIndex (edge_index); return collection.Contains (cad_shape_face_map.FindKey (face_index)); } int -t8_cad_handle::t8_geom_is_vertex_on_face (const int vertex_index, const int face_index) const +t8_cad_handle::is_vertex_on_face (const int vertex_index, const int face_index) const { const TopTools_ListOfShape edge_collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); for (auto edge = edge_collection.begin (); edge != edge_collection.end (); ++edge) { @@ -234,20 +234,19 @@ t8_cad_handle::t8_geom_is_vertex_on_face (const int vertex_index, const int face } void -t8_cad_handle::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, - double *edge_param) const +t8_cad_handle::get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param) const { - T8_ASSERT (t8_cad_handle::t8_geom_is_vertex_on_edge (vertex_index, edge_index)); + T8_ASSERT (t8_cad_handle::is_vertex_on_edge (vertex_index, edge_index)); TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); *edge_param = BRep_Tool::Parameter (vertex, edge); } void -t8_cad_handle::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, - double *face_params) const +t8_cad_handle::get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, + double *face_params) const { - T8_ASSERT (t8_cad_handle::t8_geom_is_vertex_on_face (vertex_index, face_index)); + T8_ASSERT (t8_cad_handle::is_vertex_on_face (vertex_index, face_index)); gp_Pnt2d uv; TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Face face = TopoDS::Face (cad_shape_face_map.FindKey (face_index)); @@ -257,11 +256,11 @@ t8_cad_handle::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, } void -t8_cad_handle::t8_geom_edge_parameter_to_face_parameters (const int edge_index, const int face_index, - const int num_face_nodes, const double edge_param, - const double *surface_params, double *face_params) const +t8_cad_handle::edge_parameter_to_face_parameters (const int edge_index, const int face_index, const int num_face_nodes, + const double edge_param, const double *surface_params, + double *face_params) const { - T8_ASSERT (t8_cad_handle::t8_geom_is_edge_on_face (edge_index, face_index)); + T8_ASSERT (t8_cad_handle::is_edge_on_face (edge_index, face_index)); Standard_Real first, last; gp_Pnt2d uv; TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); @@ -310,31 +309,31 @@ t8_cad_handle::t8_geom_edge_parameter_to_face_parameters (const int edge_index, } void -t8_cad_handle::t8_geom_get_face_parametric_bounds (const int surface_index, double *bounds) const +t8_cad_handle::get_face_parametric_bounds (const int surface_index, double *bounds) const { - const Handle_Geom_Surface cad_surface = t8_geom_get_cad_surface (surface_index); + const Handle_Geom_Surface cad_surface = get_cad_surface (surface_index); cad_surface->Bounds (bounds[0], bounds[1], bounds[2], bounds[3]); } void -t8_cad_handle::t8_geom_get_edge_parametric_bounds (const int edge_index, double *bounds) const +t8_cad_handle::get_edge_parametric_bounds (const int edge_index, double *bounds) const { - const Handle_Geom_Curve cad_edge = t8_geom_get_cad_curve (edge_index); + const Handle_Geom_Curve cad_edge = get_cad_curve (edge_index); bounds[0] = cad_edge->FirstParameter (); bounds[1] = cad_edge->LastParameter (); } int -t8_cad_handle::t8_geom_is_edge_closed (int edge_index) const +t8_cad_handle::is_edge_closed (int edge_index) const { - const Handle_Geom_Curve cad_edge = t8_geom_get_cad_curve (edge_index); + const Handle_Geom_Curve cad_edge = get_cad_curve (edge_index); return cad_edge->IsClosed (); } int -t8_cad_handle::t8_geom_is_surface_closed (int geometry_index, int parameter) const +t8_cad_handle::is_surface_closed (int geometry_index, int parameter) const { - const Handle_Geom_Surface cad_surface = t8_geom_get_cad_surface (geometry_index); + const Handle_Geom_Surface cad_surface = get_cad_surface (geometry_index); switch (parameter) { case 0: return cad_surface->IsUClosed (); diff --git a/src/t8_cad_handle/t8_cad_handle.hxx b/src/t8_cad_handle/t8_cad_handle.hxx index 3de2364a05..c6511ec518 100644 --- a/src/t8_cad_handle/t8_cad_handle.hxx +++ b/src/t8_cad_handle/t8_cad_handle.hxx @@ -105,53 +105,53 @@ class t8_cad_handle { * \return 1 if curve is a line, 0 if curve is not a line. */ int - t8_geom_is_line (const int curve_index) const; + is_line (const int curve_index) const; /** Check if a cad_surface is a plane. * \param [in] surface_index The index of the cad_surface. * \return 1 if surface is a plane linear, 0 if surface is not a plane. */ int - t8_geom_is_plane (const int surface_index) const; + is_plane (const int surface_index) const; /** Get an cad point from the cad_shape. * \param [in] index The index of the point in the cad_shape. * \return The cad point. */ const gp_Pnt - t8_geom_get_cad_point (const int index) const; + get_cad_point (const int index) const; /** Get an cad curve from the cad_shape. * \param [in] index The index of the curve in the cad_shape. * \return The cad curve. */ const Handle_Geom_Curve - t8_geom_get_cad_curve (const int index) const; + get_cad_curve (const int index) const; /** Get an cad surface from the cad_shape. * \param [in] index The index of the surface in the cad_shape. * \return The cad surface. */ const Handle_Geom_Surface - t8_geom_get_cad_surface (const int index) const; + get_cad_surface (const int index) const; /** Get the cad_shape_vertex2edge_map. * \return The cad_shape_vertex_map. */ const TopTools_IndexedMapOfShape - t8_geom_get_cad_shape_vertex_map () const; + get_cad_shape_vertex_map () const; /** Get the cad_shape_edge2face_map. * \return The cad_shape_edge_map. */ const TopTools_IndexedMapOfShape - t8_geom_get_cad_shape_edge_map () const; + get_cad_shape_edge_map () const; /** Get the cad_shape_face_map. * \return The cad_shape_face_map. */ const TopTools_IndexedMapOfShape - t8_geom_get_cad_shape_face_map () const; + get_cad_shape_face_map () const; /** Check if two cad points share a common cad edge. * \param [in] vertex1_index The index of the first cad point. @@ -159,7 +159,7 @@ class t8_cad_handle { * \return Index of the shared edge. 0 if there is no shared edge. */ int - t8_geom_get_common_edge (const int vertex1_index, const int vertex2_index) const; + get_common_edge (const int vertex1_index, const int vertex2_index) const; /** Check if two cad edges share a common cad face. * \param [in] edge1_index The index of the first cad edge. @@ -167,7 +167,7 @@ class t8_cad_handle { * \return Index of the shared face. 0 if there is no shared face. */ int - t8_geom_get_common_face (const int edge1_index, const int edge2_index) const; + get_common_face (const int edge1_index, const int edge2_index) const; /** Check if a cad vertex lies on an cad edge. * \param [in] vertex_index The index of the cad vertex. @@ -175,7 +175,7 @@ class t8_cad_handle { * \return 1 if vertex lies on edge, otherwise 0. */ int - t8_geom_is_vertex_on_edge (const int vertex_index, const int edge_index) const; + is_vertex_on_edge (const int vertex_index, const int edge_index) const; /** Check if a cad vertex lies on an cad edge. * \param [in] edge_index The index of the cad vertex. @@ -183,7 +183,7 @@ class t8_cad_handle { * \return 1 if vertex lies on edge, otherwise 0. */ int - t8_geom_is_edge_on_face (const int edge_index, const int face_index) const; + is_edge_on_face (const int edge_index, const int face_index) const; /** Check if a cad vertex lies on an cad face. * \param [in] vertex_index The index of the cad vertex. @@ -191,7 +191,7 @@ class t8_cad_handle { * \return 1 if vertex lies on face, otherwise 0. */ int - t8_geom_is_vertex_on_face (const int vertex_index, const int face_index) const; + is_vertex_on_face (const int vertex_index, const int face_index) const; /** Retrieves the parameter of an cad vertex on an cad edge. * The vertex has to lie on the edge. @@ -200,7 +200,7 @@ class t8_cad_handle { * \param [out] edge_param The parameter of the vertex on the edge. */ void - t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param) const; + get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param) const; /** Retrieves the parameters of an cad vertex on a cad face. * The vertex has to lie on the face. @@ -209,7 +209,7 @@ class t8_cad_handle { * \param [out] face_params The parameters of the vertex on the face. */ void - t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double *face_params) const; + get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double *face_params) const; /** Converts the parameters of an cad edge to the corresponding parameters on an cad face. * The edge has to lie on the face. @@ -226,30 +226,29 @@ class t8_cad_handle { * \param [out] face_params The corresponding parameters on the face. */ void - t8_geom_edge_parameter_to_face_parameters (const int edge_index, const int face_index, const int num_face_nodes, - const double edge_param, const double *surface_params, - double *face_params) const; + edge_parameter_to_face_parameters (const int edge_index, const int face_index, const int num_face_nodes, + const double edge_param, const double *surface_params, double *face_params) const; /** Finds the parametric bounds of an cad face. * \param [in] surface_index The index of the cad face. * \param [out] bounds The parametric bounds of the cad face. */ void - t8_geom_get_face_parametric_bounds (const int surface_index, double *bounds) const; + get_face_parametric_bounds (const int surface_index, double *bounds) const; /** Finds the parametric bounds of an cad edge. * \param [in] edge_index The index of the cad edge. * \param [out] bounds The parametric bounds of the cad edge. */ void - t8_geom_get_edge_parametric_bounds (const int edge_index, double *bounds) const; + get_edge_parametric_bounds (const int edge_index, double *bounds) const; /** Checks if an edge is closed in its U parameter. * \param [in] edge_index The index of the closed edge. * \return 1 if edge is closed in U. 0 if edge is not closed in U. */ int - t8_geom_is_edge_closed (int edge_index) const; + is_edge_closed (int edge_index) const; /** Checks if a surface is closed in its U parameter or V parameter. * \param [in] geometry_index The index of the closed geometry. @@ -258,7 +257,7 @@ class t8_cad_handle { * \return 1 if geometry is closed in U. 0 if geometry is not closed in U. */ int - t8_geom_is_surface_closed (int geometry_index, int parameter) const; + is_surface_closed (int geometry_index, int parameter) const; /** * Increase the reference count of the cad handler. diff --git a/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx b/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx index 798a7ed57d..784c6fa66c 100644 --- a/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx +++ b/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx @@ -805,13 +805,13 @@ t8_cmesh_correct_parameters_on_closed_geometry (const int geometry_dim, const in /* Check for closed U parameter in case of an edge. */ case 1: /* Only correct the U parameter if the edge is closed. */ - if (geometry_cad->get_cad_handle ()->t8_geom_is_edge_closed (geometry_index)) { + if (geometry_cad->get_cad_handle ()->is_edge_closed (geometry_index)) { /* Get the parametric bounds of the closed geometry * edge -> [Umin, Umax] */ double parametric_bounds[2]; /* Get the parametric edge bounds. */ - geometry_cad->get_cad_handle ()->t8_geom_get_edge_parametric_bounds (geometry_index, parametric_bounds); + geometry_cad->get_cad_handle ()->get_edge_parametric_bounds (geometry_index, parametric_bounds); /* Check the upper an the lower parametric bound. */ for (int bound = 0; bound < 2; ++bound) { /* Iterate over both nodes of the edge. */ @@ -843,12 +843,12 @@ t8_cmesh_correct_parameters_on_closed_geometry (const int geometry_dim, const in /* Iterate over both parameters. 0 stands for the U parameter an 1 for the V parameter. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { /* Only correct the surface parameters if they are closed */ - if (geometry_cad->get_cad_handle ()->t8_geom_is_surface_closed (geometry_index, param_dim)) { + if (geometry_cad->get_cad_handle ()->is_surface_closed (geometry_index, param_dim)) { /* Get the parametric bounds of the closed geometry * surface -> [Umin, Umax, Vmin, Vmax] */ double parametric_bounds[4]; - geometry_cad->get_cad_handle ()->t8_geom_get_face_parametric_bounds (geometry_index, parametric_bounds); + geometry_cad->get_cad_handle ()->get_face_parametric_bounds (geometry_index, parametric_bounds); /* Check the upper an the lower parametric bound. */ for (int bound = 0; bound < 2; ++bound) { /* Iterate over every corner node of the tree. */ @@ -1056,8 +1056,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If both nodes are on a vertex we look if both vertices share an edge */ if (node1.entity_dim == 0 && node2.entity_dim == 0) { - int common_edge - = cad_geometry->get_cad_handle ()->t8_geom_get_common_edge (node1.entity_tag, node2.entity_tag); + int common_edge = cad_geometry->get_cad_handle ()->get_common_edge (node1.entity_tag, node2.entity_tag); if (common_edge > 0) { if (edge1_index == 0) { edge1_index = common_edge; @@ -1071,7 +1070,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (edge2_index > 0) { - surface_index = cad_geometry->get_cad_handle ()->t8_geom_get_common_face (edge1_index, edge2_index); + surface_index = cad_geometry->get_cad_handle ()->get_common_face (edge1_index, edge2_index); } else { continue; @@ -1092,9 +1091,9 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t else { /* If it is on another geometry we retrieve its parameters */ if (face_nodes[i_face_nodes].entity_dim == 0) { - if (cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (face_nodes[i_face_nodes].entity_tag, - surface_index)) { - cad_geometry->get_cad_handle ()->t8_geom_get_parameters_of_vertex_on_face ( + if (cad_geometry->get_cad_handle ()->is_vertex_on_face (face_nodes[i_face_nodes].entity_tag, + surface_index)) { + cad_geometry->get_cad_handle ()->get_parameters_of_vertex_on_face ( face_nodes[i_face_nodes].entity_tag, surface_index, face_nodes[i_face_nodes].parameters.data ()); face_nodes[i_face_nodes].entity_dim = 2; } @@ -1104,9 +1103,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (face_nodes[i_face_nodes].entity_dim == 1) { - if (cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (face_nodes[i_face_nodes].entity_tag, - surface_index)) { - cad_geometry->get_cad_handle ()->t8_geom_edge_parameter_to_face_parameters ( + if (cad_geometry->get_cad_handle ()->is_edge_on_face (face_nodes[i_face_nodes].entity_tag, surface_index)) { + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( face_nodes[i_face_nodes].entity_tag, surface_index, num_face_nodes, face_nodes[i_face_nodes].parameters[0], NULL, face_nodes[i_face_nodes].parameters.data ()); face_nodes[i_face_nodes].entity_dim = 2; @@ -1119,7 +1117,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } /* Abort if not all nodes are on the surface or if the surface is a plane */ - if (!all_nodes_on_surface || cad_geometry->get_cad_handle ()->t8_geom_is_plane (surface_index)) { + if (!all_nodes_on_surface || cad_geometry->get_cad_handle ()->is_plane (surface_index)) { continue; } /* If we have found a surface we link it to the face */ @@ -1145,7 +1143,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } /* Corrects the parameters on the surface if it is closed to prevent disorted elements. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { - if (cad_geometry->get_cad_handle ()->t8_geom_is_surface_closed (surface_index, param_dim)) { + if (cad_geometry->get_cad_handle ()->is_surface_closed (surface_index, param_dim)) { t8_cmesh_correct_parameters_on_closed_geometry (2, surface_index, num_face_nodes, cad_geometry, parameters); } } @@ -1200,22 +1198,19 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t int is_on_geom = 1; for (int i_edge = 0; i_edge < 2; ++i_edge) { if (edge_geometry_dim == 2 && edge_nodes[i_edge].entity_dim == 1) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_edge_on_face (edge_nodes[i_edge].entity_tag, edge_geometry_tag)) { is_on_geom = 0; break; } } else if (edge_geometry_dim == 2 && edge_nodes[i_edge].entity_dim == 0) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_face (edge_nodes[i_edge].entity_tag, edge_geometry_tag)) { is_on_geom = 0; break; } } else if (edge_geometry_dim == 1 && edge_nodes[i_edge].entity_dim == 0) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_edge (edge_nodes[i_edge].entity_tag, edge_geometry_tag)) { is_on_geom = 0; break; } @@ -1231,7 +1226,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t * If not we can skip this edge. */ if (edge_geometry_dim == 0 && edge_geometry_tag == 0) { int common_curve - = cad_geometry->get_cad_handle ()->t8_geom_get_common_edge (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); + = cad_geometry->get_cad_handle ()->get_common_edge (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); if (common_curve > 0) { edge_geometry_tag = common_curve; edge_geometry_dim = 1; @@ -1245,7 +1240,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t if (edge_nodes[0].entity_dim == 1 && edge_nodes[1].entity_dim == 1 && edge_nodes[0].entity_tag != edge_nodes[1].entity_tag) { int common_surface - = cad_geometry->get_cad_handle ()->t8_geom_get_common_face (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); + = cad_geometry->get_cad_handle ()->get_common_face (edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); if (common_surface > 0) { edge_geometry_tag = common_surface; edge_geometry_dim = 2; @@ -1259,7 +1254,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* Check if adjacent faces carry a surface and if this edge lies on the surface */ for (int i_adjacent_face = 0; i_adjacent_face < 2; ++i_adjacent_face) { if (face_geometries[t8_edge_to_face[eclass][i_tree_edges][i_adjacent_face]] > 0) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face ( + if (!cad_geometry->get_cad_handle ()->is_edge_on_face ( edge_geometry_tag, face_geometries[t8_edge_to_face[eclass][i_tree_edges][i_adjacent_face]])) { t8_global_errorf ("Error: Adjacent edge and face of a tree carry " "incompatible geometries.\n"); @@ -1282,8 +1277,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t return 0; } if (edge_nodes[i_edge_node].entity_dim == 0) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_edge (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_edge (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on a vertex which lies on an edge, " "but the vertex does not lie on that edge.\n", edge_nodes[i_edge_node].index); @@ -1293,14 +1288,14 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If the node lies on a vertex we retrieve its parameter on the curve */ if (edge_nodes[i_edge_node].entity_dim == 0) { - cad_geometry->get_cad_handle ()->t8_geom_get_parameter_of_vertex_on_edge ( + cad_geometry->get_cad_handle ()->get_parameter_of_vertex_on_edge ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 1; } } /* Abort if the edge is a line */ - if (cad_geometry->get_cad_handle ()->t8_geom_is_line (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->is_line (edge_geometry_tag)) { continue; } @@ -1310,7 +1305,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t parameters[1] = edge_nodes[1].parameters[0]; /* Corrects the parameters on the edge if it is closed to prevent disorted elements. */ - if (cad_geometry->get_cad_handle ()->t8_geom_is_edge_closed (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->is_edge_closed (edge_geometry_tag)) { t8_cmesh_correct_parameters_on_closed_geometry (1, edge_geometry_tag, 2, cad_geometry, parameters); } @@ -1330,8 +1325,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t return 0; } if (edge_nodes[i_edge_node].entity_dim == 0) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_vertex_on_face (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_face (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on a vertex which lies on a face, " "but the vertex does not lie on that face.\n", edge_nodes[i_edge_node].index); @@ -1339,8 +1334,8 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } } if (edge_nodes[i_edge_node].entity_dim == 1) { - if (!cad_geometry->get_cad_handle ()->t8_geom_is_edge_on_face (edge_nodes[i_edge_node].entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_edge_on_face (edge_nodes[i_edge_node].entity_tag, + edge_geometry_tag)) { t8_global_errorf ("Error: Node %li should lie on an edge which lies on a face, " "but the edge does not lie on that face.\n", edge_nodes[i_edge_node].index); @@ -1350,14 +1345,14 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* If the node lies on a vertex we retrieve its parameters on the surface */ if (edge_nodes[i_edge_node].entity_dim == 0) { - cad_geometry->get_cad_handle ()->t8_geom_get_parameters_of_vertex_on_face ( + cad_geometry->get_cad_handle ()->get_parameters_of_vertex_on_face ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 2; } /* If the node lies on an edge we have to do the same */ if (edge_nodes[i_edge_node].entity_dim == 1) { const int num_face_nodes = t8_eclass_num_vertices[eclass]; - cad_geometry->get_cad_handle ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( edge_nodes[i_edge_node].entity_tag, edge_geometry_tag, num_face_nodes, edge_nodes[i_edge_node].parameters[0], parameters, edge_nodes[i_edge_node].parameters.data ()); edge_nodes[i_edge_node].entity_dim = 2; @@ -1365,7 +1360,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t } /* Abort if the edge is a line */ - if (cad_geometry->get_cad_handle ()->t8_geom_is_line (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->is_line (edge_geometry_tag)) { continue; } @@ -1378,7 +1373,7 @@ t8_cmesh_process_tree_geometry (t8_cmesh_t cmesh, t8_eclass_t eclass, int dim, t /* Corrects the parameters on the surface if it is closed to prevent disorted elements. */ for (int param_dim = 0; param_dim < 2; ++param_dim) { - if (cad_geometry->get_cad_handle ()->t8_geom_is_surface_closed (edge_geometry_tag, param_dim)) { + if (cad_geometry->get_cad_handle ()->is_surface_closed (edge_geometry_tag, param_dim)) { t8_cmesh_correct_parameters_on_closed_geometry (2, edge_geometry_tag, 2, cad_geometry, parameters); } } diff --git a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx index 1ec6e2629f..204b5f9df3 100644 --- a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx +++ b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx @@ -222,9 +222,9 @@ t8_geometry_cad::t8_geom_evaluate_cad_tri (t8_cmesh_t cmesh, t8_gloidx_t gtreeid t8_geom_linear_interpolation (&ref_intersection[(i_edge == 0) + offset_2d], edge_parameters, 1, 1, &interpolated_curve_parameter); /* Convert the interpolated edge parameter of each reference point to surface parameters */ - cad_handle->t8_geom_edge_parameter_to_face_parameters (edges[i_edge], *faces, num_face_nodes, - interpolated_curve_parameter, face_parameters, - converted_edge_surface_parameters + offset_2d); + cad_handle->edge_parameter_to_face_parameters (edges[i_edge], *faces, num_face_nodes, + interpolated_curve_parameter, face_parameters, + converted_edge_surface_parameters + offset_2d); } double edge_surface_parameters[4]; @@ -396,8 +396,8 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei pnt = process_curve (i_edge, temp_edge_parameters[0]); /* Convert curve parameter to surface parameters */ - cad_handle->t8_geom_edge_parameter_to_face_parameters ( - edges[i_edge], *faces, num_face_nodes, temp_edge_parameters[0], face_parameters, temp_edge_parameters); + cad_handle->edge_parameter_to_face_parameters (edges[i_edge], *faces, num_face_nodes, temp_edge_parameters[0], + face_parameters, temp_edge_parameters); /* Interpolate between the surface parameters of the current edge */ double edge_surface_parameters[4]; @@ -420,7 +420,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei } /* Retrieve surface */ - auto surface = cad_handle->t8_geom_get_cad_surface (*faces); + auto surface = cad_handle->get_cad_surface (*faces); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -478,7 +478,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei if (edges[i_edge] > 0) { /* Retrieve curve */ - auto curve = cad_handle->t8_geom_get_cad_curve (edges[i_edge]); + auto curve = cad_handle->get_cad_curve (edges[i_edge]); /* Check if curve are valid */ T8_ASSERT (!curve.IsNull ()); @@ -510,7 +510,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei } else { /* Get surface */ - auto surface = cad_handle->t8_geom_get_cad_surface (edges[i_edge + num_edges]); + auto surface = cad_handle->get_cad_surface (edges[i_edge + num_edges]); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -618,7 +618,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_tet (t8_cmesh_t cmesh, t8_gloidx_t gtreeid /* Linear interpolation between parameters */ t8_geom_linear_interpolation (&interpolation_coeff, parameters, 2, 1, interpolated_surface_params); - T8_ASSERT (edges[i_edge + num_edges] <= cad_handle->t8_geom_get_cad_shape_face_map ().Size ()); + T8_ASSERT (edges[i_edge + num_edges] <= cad_handle->get_cad_shape_face_map ().Size ()); pnt = process_surface (i_edge + num_edges, interpolated_surface_params, 0); } @@ -965,7 +965,7 @@ t8_geometry_cad::t8_geom_evaluate_cad_hex (t8_cmesh_t cmesh, t8_gloidx_t gtreeid } /* Convert the interpolated parameter of the curve into the corresponding parameters on the surface */ const int num_face_nodes = t8_eclass_num_vertices[T8_ECLASS_QUAD]; - cad_handle->t8_geom_edge_parameter_to_face_parameters ( + cad_handle->edge_parameter_to_face_parameters ( edges[t8_face_edge_to_tree_edge[T8_ECLASS_HEX][i_faces][i_face_edge]], faces[i_faces], num_face_nodes, interpolated_curve_param, surface_parameters, surface_parameters_from_curve); @@ -1276,7 +1276,7 @@ t8_geometry_cad::process_curve (const int edge_index, const double interpolated_ gp_Pnt pnt; /* Retrieve the curve of the edge */ - auto curve = cad_handle->t8_geom_get_cad_curve (edges[edge_index]); + auto curve = cad_handle->get_cad_curve (edges[edge_index]); /* Check if curve is valid */ T8_ASSERT (!curve.IsNull ()); @@ -1293,7 +1293,7 @@ t8_geometry_cad::process_surface (const int face_index, const double *interpolat gp_Pnt pnt; /* Retrieve the surface of the edge */ - auto surface = cad_handle->t8_geom_get_cad_surface (faces[face_index]); + auto surface = cad_handle->get_cad_surface (faces[face_index]); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); From b6974115d6762b974e54d418327e72a4e2d6fc23 Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Tue, 17 Feb 2026 11:30:26 +0100 Subject: [PATCH 3/7] refactor: clean up cad_handle constructors and loading --- src/CMakeLists.txt | 4 +- .../t8_cad_handle.cxx | 48 ++++++++----------- .../t8_cad_handle.hxx | 46 ++++++++---------- .../t8_geometry_cad.hxx | 2 +- 4 files changed, 43 insertions(+), 57 deletions(-) rename src/{t8_cad_handle => t8_cad}/t8_cad_handle.cxx (93%) rename src/{t8_cad_handle => t8_cad}/t8_cad_handle.hxx (91%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f228f53c8..8a0a81e3bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,12 +108,12 @@ if( T8CODE_ENABLE_OCC ) target_link_libraries( T8 PUBLIC ${OpenCASCADE_LIBRARIES} ) target_sources(T8 PRIVATE t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx - t8_cad_handle/t8_cad_handle.cxx + t8_cad/t8_cad_handle.cxx ) install( FILES t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx t8_geometry/t8_geometry_implementations/t8_geometry_cad.h - t8_cad_handle/t8_cad_handle.hxx + t8_cad/t8_cad_handle.hxx DESTINATION include ) endif() diff --git a/src/t8_cad_handle/t8_cad_handle.cxx b/src/t8_cad/t8_cad_handle.cxx similarity index 93% rename from src/t8_cad_handle/t8_cad_handle.cxx rename to src/t8_cad/t8_cad_handle.cxx index 2b18834e56..e31d32831a 100644 --- a/src/t8_cad_handle/t8_cad_handle.cxx +++ b/src/t8_cad/t8_cad_handle.cxx @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include @@ -33,8 +33,8 @@ #include #include -TopoDS_Shape -t8_cad_handle::load_cad_shape (const std::string fileprefix) +void +t8_cad_handle::load_cad_from_file (const std::string fileprefix) { TopoDS_Shape cad_shape; BRep_Builder builder; @@ -50,7 +50,16 @@ t8_cad_handle::load_cad_shape (const std::string fileprefix) "Linked cad version: %s", OCC_VERSION_COMPLETE); } - return cad_shape; + map_cad_shape (cad_shape); +} + +void +t8_cad_handle::load_cad_from_shape (const TopoDS_Shape &cad_shape) +{ + if (cad_shape.IsNull ()) { + SC_ABORTF ("Shape is null. \n"); + } + map_cad_shape (cad_shape); } void @@ -75,19 +84,20 @@ t8_cad_handle::map_cad_shape (const TopoDS_Shape &cad_shape_in) TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); } -t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) +t8_cad_handle::t8_cad_handle (std::string fileprefix) { - if (cad_shape_in.IsNull ()) { - SC_ABORTF ("Shape is null. \n"); - } t8_refcount_init (&rc); - t8_debugf ("Constructed the cad_handle.\n"); + t8_debugf ("Constructed the cad_handle from file.\n"); - t8_cad_handle::map_cad_shape (cad_shape_in); + t8_cad_handle::load_cad_from_file (fileprefix); } -t8_cad_handle::t8_cad_handle (std::string fileprefix): t8_cad_handle (load_cad_shape (fileprefix)) +t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) { + t8_refcount_init (&rc); + t8_debugf ("Constructed the cad_handle from shape.\n"); + + t8_cad_handle::load_cad_from_shape (cad_shape_in); } t8_cad_handle::t8_cad_handle () @@ -102,22 +112,6 @@ t8_cad_handle::~t8_cad_handle () t8_debugf ("Deleted the cad_handle.\n"); } -void -t8_cad_handle::update_cad_shape (const std::string fileprefix) -{ - /* Load the new cad shape from the fileprefix. */ - TopoDS_Shape new_cad_shape = t8_cad_handle::load_cad_shape (fileprefix); - /* Map the new cad shape. */ - t8_cad_handle::map_cad_shape (new_cad_shape); -} - -void -t8_cad_handle::update_cad_shape (const TopoDS_Shape &new_cad_shape) -{ - /* Map the new cad shape. */ - t8_cad_handle::map_cad_shape (new_cad_shape); -} - int t8_cad_handle::is_line (const int curve_index) const { diff --git a/src/t8_cad_handle/t8_cad_handle.hxx b/src/t8_cad/t8_cad_handle.hxx similarity index 91% rename from src/t8_cad_handle/t8_cad_handle.hxx rename to src/t8_cad/t8_cad_handle.hxx index c6511ec518..36e36a9b68 100644 --- a/src/t8_cad_handle/t8_cad_handle.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -40,7 +40,7 @@ class t8_cad_handle { public: /** - * Constructor of the cad shape handler. + * Constructor of the cad shape handle. * The shape is initialized based on a .brep file with the given prefix. * The internal structure extracts and stores geometric information such as * vertices, edges, and faces from this file. The number and type of vertices @@ -67,38 +67,23 @@ class t8_cad_handle { t8_cad_handle (); /** - * Destructor of the cad shape handler. + * Destructor of the cad shape handle. */ ~t8_cad_handle (); /** - * Loads a cad shape from a .brep file with the given prefix. - * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. - * \return The loaded cad shape. - */ - static TopoDS_Shape - load_cad_shape (const std::string fileprefix); - - /** - * Map the cad shape to extract vertices, edges, faces, and their relationships. - * \param [in] cad_shape_in The input cad shape to be mapped. - */ - void - map_cad_shape (const TopoDS_Shape &cad_shape_in); - - /** - * Updates the cad shape from a .brep file with the given prefix. + * Loads a cad shape from a .brep file with the given prefix and maps it. * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ void - update_cad_shape (const std::string fileprefix); + load_cad_from_file (const std::string fileprefix); /** - * Updates the cad shape directly from an existing TopoDS_Shape. - * \param [in] new_cad_shape cad shape geometry object. + * Loads a cad shape from an existing TopoDS_Shape and maps it. + * \param [in] new_cad_shape The input cad shape. */ void - update_cad_shape (const TopoDS_Shape &new_cad_shape); + load_cad_from_shape (const TopoDS_Shape &cad_shape); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. @@ -260,7 +245,7 @@ class t8_cad_handle { is_surface_closed (int geometry_index, int parameter) const; /** - * Increase the reference count of the cad handler. + * Increase the reference count of the cad handle. */ inline void ref () @@ -269,19 +254,26 @@ class t8_cad_handle { } /** - * Decrease the reference count of the cad handler. - * If the reference count reaches zero, the cad handler is deleted. + * Decrease the reference count of the cad handle. + * If the reference count reaches zero, the cad handle is deleted. */ inline void unref () { if (t8_refcount_unref (&rc)) { - t8_debugf ("Deleting the cad_handler.\n"); + t8_debugf ("Deleting the cad_handle.\n"); delete this; } } private: + /** + * Map the cad shape to extract vertices, edges, faces, and their relationships. + * \param [in] cad_shape_in The input cad shape to be mapped. + */ + void + map_cad_shape (const TopoDS_Shape &cad_shape_in); + TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex in shape. */ TopTools_IndexedMapOfShape cad_shape_edge_map; /**< Map of all TopoDS_Edge in shape. */ @@ -290,7 +282,7 @@ class t8_cad_handle { cad_shape_vertex2edge_map; /**< Maps all TopoDS_Vertex of shape to all its connected TopoDS_Edge */ TopTools_IndexedDataMapOfShapeListOfShape cad_shape_edge2face_map; /**< Maps all TopoDS_Edge of shape to all its connected TopoDS_Face */ - /** The reference count of the cad handler. TODO: Replace by shared_ptr when cmesh becomes a class. */ + /** The reference count of the cad handle. TODO: Replace by shared_ptr when cmesh becomes a class. */ t8_refcount_t rc; }; diff --git a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx index 543e4dbcd0..808f099c56 100644 --- a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx +++ b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include From 6324f7d252c6673c884706ab949b08e6fdc3b5a7 Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Wed, 18 Feb 2026 14:21:10 +0100 Subject: [PATCH 4/7] fix parameter mismatch in documentation in t8_cad_handle --- src/t8_cad/t8_cad_handle.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_cad/t8_cad_handle.hxx b/src/t8_cad/t8_cad_handle.hxx index 45f9e5cee3..469361c549 100644 --- a/src/t8_cad/t8_cad_handle.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -85,7 +85,7 @@ class t8_cad_handle { /** * Loads a cad shape from an existing TopoDS_Shape and maps it. - * \param [in] new_cad_shape The input cad shape. + * \param [in] cad_shape The input cad shape. */ void load_cad_from_shape (const TopoDS_Shape &cad_shape); From fafefe6d3c03fdc98bd76662e01e7462ca0699bd Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Thu, 19 Feb 2026 13:11:12 +0100 Subject: [PATCH 5/7] review comments regarding refcount and simplify function names --- src/t8_cad/t8_cad_handle.cxx | 22 +++++++++++++--------- src/t8_cad/t8_cad_handle.hxx | 10 +++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/t8_cad/t8_cad_handle.cxx b/src/t8_cad/t8_cad_handle.cxx index cf857fef6c..c492e99489 100644 --- a/src/t8_cad/t8_cad_handle.cxx +++ b/src/t8_cad/t8_cad_handle.cxx @@ -40,15 +40,15 @@ #endif void -t8_cad_handle::load_cad_from_file (const std::string fileprefix) +t8_cad_handle::load (const std::string fileprefix) { TopoDS_Shape cad_shape; - BRep_Builder builder; + BRep_Builder bob; std::ifstream is (fileprefix + ".brep"); if (is.is_open () == false) { SC_ABORTF ("Cannot find the file %s.brep.\n", fileprefix.c_str ()); } - BRepTools::Read (cad_shape, is, builder); + BRepTools::Read (cad_shape, is, bob); is.close (); if (cad_shape.IsNull ()) { SC_ABORTF ("Could not read brep file or brep file contains no shape. " @@ -56,20 +56,20 @@ t8_cad_handle::load_cad_from_file (const std::string fileprefix) "Linked cad version: %s", OCC_VERSION_COMPLETE); } - map_cad_shape (cad_shape); + map (cad_shape); } void -t8_cad_handle::load_cad_from_shape (const TopoDS_Shape &cad_shape) +t8_cad_handle::load (const TopoDS_Shape &cad_shape) { if (cad_shape.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } - map_cad_shape (cad_shape); + map (cad_shape); } void -t8_cad_handle::map_cad_shape (const TopoDS_Shape &cad_shape_in) +t8_cad_handle::map (const TopoDS_Shape &cad_shape_in) { if (cad_shape_in.IsNull ()) { SC_ABORTF ("Shape is null. \n"); @@ -95,7 +95,7 @@ t8_cad_handle::t8_cad_handle (std::string fileprefix) t8_refcount_init (&rc); t8_debugf ("Constructed the cad_handle from file.\n"); - t8_cad_handle::load_cad_from_file (fileprefix); + t8_cad_handle::load (fileprefix); } t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) @@ -103,7 +103,7 @@ t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) t8_refcount_init (&rc); t8_debugf ("Constructed the cad_handle from shape.\n"); - t8_cad_handle::load_cad_from_shape (cad_shape_in); + t8_cad_handle::load (cad_shape_in); } t8_cad_handle::t8_cad_handle () @@ -115,6 +115,10 @@ t8_cad_handle::t8_cad_handle () t8_cad_handle::~t8_cad_handle () { + if (sc_refcount_is_active (&rc)) { + T8_ASSERT (t8_refcount_is_last (&rc)); + t8_refcount_unref (&rc); + } t8_debugf ("Deleted the cad_handle.\n"); } diff --git a/src/t8_cad/t8_cad_handle.hxx b/src/t8_cad/t8_cad_handle.hxx index 469361c549..b5b0a92afc 100644 --- a/src/t8_cad/t8_cad_handle.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -62,9 +62,9 @@ class t8_cad_handle { * or integration with mesh generators that already provide geometry in memory. * It avoids file I/O and allows full control over the CAD input. * - * \param [in] cad_shape cad shape geometry object. + * \param [in] cad_shape_in cad shape geometry object. */ - t8_cad_handle (const TopoDS_Shape cad_shape); + t8_cad_handle (const TopoDS_Shape cad_shape_in); /** * Constructor of the cad shape for testing purposes. Sets an invalid cad_shape. @@ -81,14 +81,14 @@ class t8_cad_handle { * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ void - load_cad_from_file (const std::string fileprefix); + load (const std::string fileprefix); /** * Loads a cad shape from an existing TopoDS_Shape and maps it. * \param [in] cad_shape The input cad shape. */ void - load_cad_from_shape (const TopoDS_Shape &cad_shape); + load (const TopoDS_Shape &cad_shape); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. @@ -368,7 +368,7 @@ class t8_cad_handle { * \param [in] cad_shape_in The input cad shape to be mapped. */ void - map_cad_shape (const TopoDS_Shape &cad_shape_in); + map (const TopoDS_Shape &cad_shape_in); TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex. */ From 94451b21cd6d39248c38e8e6fde884e88d234edd Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Fri, 20 Feb 2026 16:52:22 +0100 Subject: [PATCH 6/7] refactor shape handling --- src/t8_cad/t8_cad_handle.cxx | 24 +++++++++++++----------- src/t8_cad/t8_cad_handle.hxx | 12 ++++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/t8_cad/t8_cad_handle.cxx b/src/t8_cad/t8_cad_handle.cxx index c492e99489..fcaf88a063 100644 --- a/src/t8_cad/t8_cad_handle.cxx +++ b/src/t8_cad/t8_cad_handle.cxx @@ -34,19 +34,21 @@ #include #include #include +#include #if T8_ENABLE_DEBUG #include #endif void -t8_cad_handle::load (const std::string fileprefix) +t8_cad_handle::load (const std::string_view fileprefix) { TopoDS_Shape cad_shape; BRep_Builder bob; - std::ifstream is (fileprefix + ".brep"); + const std::string filename = std::string (fileprefix) + ".brep"; + std::ifstream is (filename); if (is.is_open () == false) { - SC_ABORTF ("Cannot find the file %s.brep.\n", fileprefix.c_str ()); + SC_ABORTF ("Cannot find the file %s.\n", filename.c_str ()); } BRepTools::Read (cad_shape, is, bob); is.close (); @@ -56,20 +58,20 @@ t8_cad_handle::load (const std::string fileprefix) "Linked cad version: %s", OCC_VERSION_COMPLETE); } - map (cad_shape); + map (std::move (cad_shape)); } void -t8_cad_handle::load (const TopoDS_Shape &cad_shape) +t8_cad_handle::load (TopoDS_Shape cad_shape) { if (cad_shape.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } - map (cad_shape); + map (std::move (cad_shape)); } void -t8_cad_handle::map (const TopoDS_Shape &cad_shape_in) +t8_cad_handle::map (TopoDS_Shape cad_shape_in) { if (cad_shape_in.IsNull ()) { SC_ABORTF ("Shape is null. \n"); @@ -81,7 +83,7 @@ t8_cad_handle::map (const TopoDS_Shape &cad_shape_in) cad_shape_vertex2edge_map.Clear (); cad_shape_edge2face_map.Clear (); - cad_shape = cad_shape_in; + cad_shape = std::move (cad_shape_in); TopExp::MapShapes (cad_shape, TopAbs_VERTEX, cad_shape_vertex_map); TopExp::MapShapes (cad_shape, TopAbs_EDGE, cad_shape_edge_map); @@ -90,7 +92,7 @@ t8_cad_handle::map (const TopoDS_Shape &cad_shape_in) TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); } -t8_cad_handle::t8_cad_handle (std::string fileprefix) +t8_cad_handle::t8_cad_handle (const std::string_view fileprefix) { t8_refcount_init (&rc); t8_debugf ("Constructed the cad_handle from file.\n"); @@ -98,12 +100,12 @@ t8_cad_handle::t8_cad_handle (std::string fileprefix) t8_cad_handle::load (fileprefix); } -t8_cad_handle::t8_cad_handle (const TopoDS_Shape cad_shape_in) +t8_cad_handle::t8_cad_handle (TopoDS_Shape cad_shape_in) { t8_refcount_init (&rc); t8_debugf ("Constructed the cad_handle from shape.\n"); - t8_cad_handle::load (cad_shape_in); + load (std::move (cad_shape_in)); } t8_cad_handle::t8_cad_handle () diff --git a/src/t8_cad/t8_cad_handle.hxx b/src/t8_cad/t8_cad_handle.hxx index b5b0a92afc..b7b7c98e36 100644 --- a/src/t8_cad/t8_cad_handle.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -37,7 +37,7 @@ #include #include #include - +#include #include /** * This class manages OpenCASCADE shapes and implements helper functions for working with the shapes. @@ -54,7 +54,7 @@ class t8_cad_handle { * * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ - t8_cad_handle (std::string fileprefix); + t8_cad_handle (const std::string_view fileprefix); /** * Constructor of the cad shape. * The shape is initialized directly from an existing TopoDS_Shape. @@ -64,7 +64,7 @@ class t8_cad_handle { * * \param [in] cad_shape_in cad shape geometry object. */ - t8_cad_handle (const TopoDS_Shape cad_shape_in); + t8_cad_handle (TopoDS_Shape cad_shape_in); /** * Constructor of the cad shape for testing purposes. Sets an invalid cad_shape. @@ -81,14 +81,14 @@ class t8_cad_handle { * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ void - load (const std::string fileprefix); + load (const std::string_view fileprefix); /** * Loads a cad shape from an existing TopoDS_Shape and maps it. * \param [in] cad_shape The input cad shape. */ void - load (const TopoDS_Shape &cad_shape); + load (TopoDS_Shape cad_shape); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. @@ -368,7 +368,7 @@ class t8_cad_handle { * \param [in] cad_shape_in The input cad shape to be mapped. */ void - map (const TopoDS_Shape &cad_shape_in); + map (TopoDS_Shape cad_shape_in); TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex. */ From cb0c420cd7706d200f1d92b31061b27a0a4595a5 Mon Sep 17 00:00:00 2001 From: Lena Radmer Date: Mon, 23 Feb 2026 15:38:00 +0100 Subject: [PATCH 7/7] optimize connectivity and map function and clean up scope --- src/t8_cad/t8_cad_handle.cxx | 80 +++++++++++++++++------------------- src/t8_cad/t8_cad_handle.hxx | 9 ++-- 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/t8_cad/t8_cad_handle.cxx b/src/t8_cad/t8_cad_handle.cxx index fcaf88a063..dafa849d7e 100644 --- a/src/t8_cad/t8_cad_handle.cxx +++ b/src/t8_cad/t8_cad_handle.cxx @@ -43,14 +43,14 @@ void t8_cad_handle::load (const std::string_view fileprefix) { - TopoDS_Shape cad_shape; + TopoDS_Shape loaded_cad_shape; BRep_Builder bob; const std::string filename = std::string (fileprefix) + ".brep"; std::ifstream is (filename); if (is.is_open () == false) { SC_ABORTF ("Cannot find the file %s.\n", filename.c_str ()); } - BRepTools::Read (cad_shape, is, bob); + BRepTools::Read (loaded_cad_shape, is, bob); is.close (); if (cad_shape.IsNull ()) { SC_ABORTF ("Could not read brep file or brep file contains no shape. " @@ -58,22 +58,24 @@ t8_cad_handle::load (const std::string_view fileprefix) "Linked cad version: %s", OCC_VERSION_COMPLETE); } - map (std::move (cad_shape)); + this->cad_shape = std::move (loaded_cad_shape); + map (); } void -t8_cad_handle::load (TopoDS_Shape cad_shape) +t8_cad_handle::load (TopoDS_Shape cad_shape_in) { - if (cad_shape.IsNull ()) { + if (cad_shape_in.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } - map (std::move (cad_shape)); + this->cad_shape = std::move (cad_shape_in); + map (); } void -t8_cad_handle::map (TopoDS_Shape cad_shape_in) +t8_cad_handle::map () { - if (cad_shape_in.IsNull ()) { + if (this->cad_shape.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } /* Clear maps before map the new data. */ @@ -82,14 +84,14 @@ t8_cad_handle::map (TopoDS_Shape cad_shape_in) cad_shape_face_map.Clear (); cad_shape_vertex2edge_map.Clear (); cad_shape_edge2face_map.Clear (); + cad_shape_vertex2face_map.Clear (); - cad_shape = std::move (cad_shape_in); - - TopExp::MapShapes (cad_shape, TopAbs_VERTEX, cad_shape_vertex_map); - TopExp::MapShapes (cad_shape, TopAbs_EDGE, cad_shape_edge_map); - TopExp::MapShapes (cad_shape, TopAbs_FACE, cad_shape_face_map); - TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_VERTEX, TopAbs_EDGE, cad_shape_vertex2edge_map); - TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); + TopExp::MapShapes (this->cad_shape, TopAbs_VERTEX, cad_shape_vertex_map); + TopExp::MapShapes (this->cad_shape, TopAbs_EDGE, cad_shape_edge_map); + TopExp::MapShapes (this->cad_shape, TopAbs_FACE, cad_shape_face_map); + TopExp::MapShapesAndUniqueAncestors (this->cad_shape, TopAbs_VERTEX, TopAbs_EDGE, cad_shape_vertex2edge_map); + TopExp::MapShapesAndUniqueAncestors (this->cad_shape, TopAbs_EDGE, TopAbs_FACE, cad_shape_edge2face_map); + TopExp::MapShapesAndUniqueAncestors (this->cad_shape, TopAbs_VERTEX, TopAbs_FACE, cad_shape_vertex2face_map); } t8_cad_handle::t8_cad_handle (const std::string_view fileprefix) @@ -97,7 +99,7 @@ t8_cad_handle::t8_cad_handle (const std::string_view fileprefix) t8_refcount_init (&rc); t8_debugf ("Constructed the cad_handle from file.\n"); - t8_cad_handle::load (fileprefix); + load (fileprefix); } t8_cad_handle::t8_cad_handle (TopoDS_Shape cad_shape_in) @@ -164,20 +166,20 @@ t8_cad_handle::get_cad_face (const int index) const const gp_Pnt t8_cad_handle::get_cad_point (const int index) const { - return BRep_Tool::Pnt (t8_cad_handle::get_cad_vertex (index)); + return BRep_Tool::Pnt (get_cad_vertex (index)); } const Handle_Geom_Curve t8_cad_handle::get_cad_curve (const int index) const { Standard_Real first, last; - return BRep_Tool::Curve (t8_cad_handle::get_cad_edge (index), first, last); + return BRep_Tool::Curve (get_cad_edge (index), first, last); } const Handle_Geom_Surface t8_cad_handle::get_cad_surface (const int index) const { - return BRep_Tool::Surface (t8_cad_handle::get_cad_face (index)); + return BRep_Tool::Surface (get_cad_face (index)); } const TopTools_IndexedMapOfShape @@ -209,7 +211,7 @@ t8_cad_handle::get_common_edge_of_vertices (const int vertex1_index, const int v for (auto edge1 = collection1.begin (); edge1 != collection1.end (); ++edge1) { for (auto edge2 = collection2.begin (); edge2 != collection2.end (); ++edge2) { if (edge1->IsEqual (*edge2)) { - return cad_shape_edge2face_map.FindIndex (*edge1); + return cad_shape_edge_map.FindIndex (*edge1); } } } @@ -287,16 +289,10 @@ t8_cad_handle::is_edge_on_face (const int edge_index, const int face_index) cons int t8_cad_handle::is_vertex_on_face (const int vertex_index, const int face_index) const { - T8_ASSERT (vertex_index <= cad_shape_vertex2edge_map.Size ()); + T8_ASSERT (vertex_index <= cad_shape_vertex2face_map.Size ()); T8_ASSERT (face_index <= cad_shape_face_map.Size ()); - const TopTools_ListOfShape edge_collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); - for (auto edge = edge_collection.begin (); edge != edge_collection.end (); ++edge) { - const TopTools_ListOfShape face_collection = cad_shape_edge2face_map.FindFromKey (*edge); - if (face_collection.Contains (cad_shape_face_map.FindKey (face_index))) { - return 1; - } - } - return 0; + const TopTools_ListOfShape collection = cad_shape_vertex2face_map.FindFromIndex (vertex_index); + return collection.Contains (cad_shape_face_map.FindKey (face_index)); } bool @@ -304,8 +300,8 @@ t8_cad_handle::vertex_is_seam (const int vertex_index, const int edge_index) con { T8_ASSERT (vertex_index <= cad_shape_vertex_map.Size ()); T8_ASSERT (edge_index <= cad_shape_edge_map.Size ()); - const auto vertex = t8_cad_handle::get_cad_vertex (vertex_index); - const auto edge = t8_cad_handle::get_cad_edge (edge_index); + const auto vertex = get_cad_vertex (vertex_index); + const auto edge = get_cad_edge (edge_index); double u = BRep_Tool::Parameter (vertex, edge); double first = 0, last = 0; const auto curve = BRep_Tool::Curve (edge, first, last); @@ -328,7 +324,7 @@ t8_cad_handle::vertex_is_on_seam_edge (const int vertex_index, const int face_in { T8_ASSERT (vertex_index <= cad_shape_vertex2edge_map.Size ()); T8_ASSERT (face_index <= cad_shape_face_map.Size ()); - const auto face = t8_cad_handle::get_cad_face (face_index); + const auto face = get_cad_face (face_index); const TopTools_ListOfShape edge_collection = cad_shape_vertex2edge_map.FindFromIndex (vertex_index); const ShapeAnalysis_Edge edge_analyzer; for (auto edge = edge_collection.begin (); edge != edge_collection.end (); ++edge) { @@ -343,8 +339,8 @@ t8_cad_handle::edge_is_seam (const int edge_index, const int face_index) const { T8_ASSERT (edge_index <= cad_shape_edge_map.Size ()); T8_ASSERT (face_index <= cad_shape_face_map.Size ()); - const auto face = t8_cad_handle::get_cad_face (face_index); - const auto edge = t8_cad_handle::get_cad_edge (edge_index); + const auto face = get_cad_face (face_index); + const auto edge = get_cad_edge (edge_index); const ShapeAnalysis_Edge edge_analyzer; return edge_analyzer.IsSeam (edge, face); } @@ -353,7 +349,7 @@ void t8_cad_handle::get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param, std::optional reference_edge_param) const { - T8_ASSERT (t8_cad_handle::is_vertex_on_edge (vertex_index, edge_index)); + T8_ASSERT (is_vertex_on_edge (vertex_index, edge_index)); TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); @@ -361,8 +357,8 @@ t8_cad_handle::get_parameter_of_vertex_on_edge (const int vertex_index, const in the parameter of the vertex on the edge. But if the edge is closed and the user provided said reference parameters it gets more sophisticated:*/ - const bool edge_is_closed = t8_cad_handle::edge_is_closed (edge_index); - if (reference_edge_param.has_value () && edge_is_closed) { + const bool is_closed = edge_is_closed (edge_index); + if (reference_edge_param.has_value () && is_closed) { /* Edge is closed and the user provided reference parameters. We iterate over all vertices of the edge. Since the edge is closed, the start and end vertex should be in the same physical location. We choose the point where the parameters are closer to the reference parameters. For debugging reasons @@ -411,19 +407,19 @@ t8_cad_handle::get_parameters_of_vertex_on_face (const int vertex_index, const i And thats why this algorithm does not work. What you see here is the more complicated workaround: */ - T8_ASSERT (t8_cad_handle::is_vertex_on_face (vertex_index, face_index)); + T8_ASSERT (is_vertex_on_face (vertex_index, face_index)); std::optional uv = std::nullopt; /** Final parameters on the surface */ TopoDS_Vertex vertex = TopoDS::Vertex (cad_shape_vertex_map.FindKey (vertex_index)); TopoDS_Face face = TopoDS::Face (cad_shape_face_map.FindKey (face_index)); /* If the surface is not closed or the user did not provide any reference params we just query the parameters. */ - if (!t8_cad_handle::surface_is_closed (face_index) || !reference_face_params.has_value ()) { + if (!surface_is_closed (face_index) || !reference_face_params.has_value ()) { uv.emplace (BRep_Tool::Parameters (vertex, face)); } /* If the vertex is not on the seam we can also just query the parameters. */ else { - const bool is_on_seam = t8_cad_handle::vertex_is_on_seam_edge (vertex_index, face_index); + const bool is_on_seam = vertex_is_on_seam_edge (vertex_index, face_index); if (!is_on_seam) { uv.emplace (BRep_Tool::Parameters (vertex, face)); } @@ -498,13 +494,13 @@ t8_cad_handle::edge_parameter_to_face_parameters (const int edge_index, const in double face_params_out[2], std::optional> reference_face_params) const { - T8_ASSERT (t8_cad_handle::is_edge_on_face (edge_index, face_index)); + T8_ASSERT (is_edge_on_face (edge_index, face_index)); Standard_Real first, last; std::optional uv = std::nullopt; TopoDS_Face face = TopoDS::Face (cad_shape_face_map.FindKey (face_index)); TopoDS_Edge edge = TopoDS::Edge (cad_shape_edge_map.FindKey (edge_index)); - const bool is_seam = t8_cad_handle::edge_is_seam (edge_index, face_index); + const bool is_seam = edge_is_seam (edge_index, face_index); if (is_seam && reference_face_params.has_value ()) { /* Convert reference parameters to OCCT point */ gp_Pnt2d reference_point (reference_face_params.value ()[0], reference_face_params.value ()[1]); diff --git a/src/t8_cad/t8_cad_handle.hxx b/src/t8_cad/t8_cad_handle.hxx index b7b7c98e36..ec7c3c3809 100644 --- a/src/t8_cad/t8_cad_handle.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -85,10 +85,10 @@ class t8_cad_handle { /** * Loads a cad shape from an existing TopoDS_Shape and maps it. - * \param [in] cad_shape The input cad shape. + * \param [in] cad_shape_in The input cad shape. */ void - load (TopoDS_Shape cad_shape); + load (TopoDS_Shape cad_shape_in); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. @@ -365,10 +365,9 @@ class t8_cad_handle { private: /** * Map the cad shape to extract vertices, edges, faces, and their relationships. - * \param [in] cad_shape_in The input cad shape to be mapped. */ void - map (TopoDS_Shape cad_shape_in); + map (); TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex. */ @@ -378,9 +377,9 @@ class t8_cad_handle { cad_shape_vertex2edge_map; /**< Maps all TopoDS_Vertex to all its connected TopoDS_Edge */ TopTools_IndexedDataMapOfShapeListOfShape cad_shape_edge2face_map; /**< Maps all TopoDS_Edge to all its connected TopoDS_Face */ - /** The reference count of the cad handle. TODO: Replace by shared_ptr when cmesh becomes a class. */ TopTools_IndexedDataMapOfShapeListOfShape cad_shape_vertex2face_map; /**< Maps all TopoDS_Vertex to all its connected TopoDS_Face */ + /** The reference count of the cad handle. TODO: Replace by shared_ptr when cmesh becomes a class. */ t8_refcount_t rc; };