diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d9d630b6d..0d8a6e3a27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,7 +96,7 @@ 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/t8_cad_handle.cxx ) install( FILES t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx @@ -104,7 +104,7 @@ if( T8CODE_ENABLE_OCC ) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/t8_geometry/t8_geometry_implementations ) install( FILES - t8_cad/t8_cad.hxx + t8_cad/t8_cad_handle.hxx DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/t8_cad ) endif() diff --git a/src/t8_cad/t8_cad.cxx b/src/t8_cad/t8_cad_handle.cxx similarity index 72% rename from src/t8_cad/t8_cad.cxx rename to src/t8_cad/t8_cad_handle.cxx index dc319f08c9..dafa849d7e 100644 --- a/src/t8_cad/t8_cad.cxx +++ b/src/t8_cad/t8_cad_handle.cxx @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include @@ -34,19 +34,23 @@ #include #include #include +#include #if T8_ENABLE_DEBUG #include #endif -t8_cad::t8_cad (std::string fileprefix) +void +t8_cad_handle::load (const std::string_view fileprefix) { - BRep_Builder builder; - std::ifstream is (fileprefix + ".brep"); + 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.brep.\n", fileprefix.c_str ()); + SC_ABORTF ("Cannot find the file %s.\n", filename.c_str ()); } - BRepTools::Read (cad_shape, is, builder); + 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. " @@ -54,107 +58,150 @@ 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); - TopExp::MapShapesAndUniqueAncestors (cad_shape, TopAbs_VERTEX, TopAbs_FACE, cad_shape_vertex2face_map); + this->cad_shape = std::move (loaded_cad_shape); + map (); } -t8_cad::t8_cad (const TopoDS_Shape cad_shape) +void +t8_cad_handle::load (TopoDS_Shape cad_shape_in) { - if (cad_shape.IsNull ()) { + if (cad_shape_in.IsNull ()) { + SC_ABORTF ("Shape is null. \n"); + } + this->cad_shape = std::move (cad_shape_in); + map (); +} + +void +t8_cad_handle::map () +{ + if (this->cad_shape.IsNull ()) { SC_ABORTF ("Shape is null. \n"); } - 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); + /* 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_vertex2face_map.Clear (); + + 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) +{ + t8_refcount_init (&rc); + t8_debugf ("Constructed the cad_handle from file.\n"); + + load (fileprefix); +} + +t8_cad_handle::t8_cad_handle (TopoDS_Shape cad_shape_in) +{ + t8_refcount_init (&rc); + t8_debugf ("Constructed the cad_handle from shape.\n"); + + load (std::move (cad_shape_in)); } -t8_cad::t8_cad () +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 () +{ + if (sc_refcount_is_active (&rc)) { + T8_ASSERT (t8_refcount_is_last (&rc)); + t8_refcount_unref (&rc); + } + t8_debugf ("Deleted the cad_handle.\n"); +} + int -t8_cad::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::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 TopoDS_Vertex -t8_cad::t8_geom_get_cad_vertex (const int index) const +t8_cad_handle::get_cad_vertex (const int index) const { T8_ASSERT (index <= cad_shape_vertex_map.Size ()); return TopoDS::Vertex (cad_shape_vertex_map.FindKey (index)); } const TopoDS_Edge -t8_cad::t8_geom_get_cad_edge (const int index) const +t8_cad_handle::get_cad_edge (const int index) const { T8_ASSERT (index <= cad_shape_edge_map.Size ()); return TopoDS::Edge (cad_shape_edge_map.FindKey (index)); } const TopoDS_Face -t8_cad::t8_geom_get_cad_face (const int index) const +t8_cad_handle::get_cad_face (const int index) const { T8_ASSERT (index <= cad_shape_face_map.Size ()); return TopoDS::Face (cad_shape_face_map.FindKey (index)); } const gp_Pnt -t8_cad::t8_geom_get_cad_point (const int index) const +t8_cad_handle::get_cad_point (const int index) const { - return BRep_Tool::Pnt (t8_cad::t8_geom_get_cad_vertex (index)); + return BRep_Tool::Pnt (get_cad_vertex (index)); } const Handle_Geom_Curve -t8_cad::t8_geom_get_cad_curve (const int index) const +t8_cad_handle::get_cad_curve (const int index) const { Standard_Real first, last; - return BRep_Tool::Curve (t8_cad::t8_geom_get_cad_edge (index), first, last); + return BRep_Tool::Curve (get_cad_edge (index), first, last); } const Handle_Geom_Surface -t8_cad::t8_geom_get_cad_surface (const int index) const +t8_cad_handle::get_cad_surface (const int index) const { - return BRep_Tool::Surface (t8_cad::t8_geom_get_cad_face (index)); + return BRep_Tool::Surface (get_cad_face (index)); } const TopTools_IndexedMapOfShape -t8_cad::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::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::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::t8_geom_get_common_edge_of_vertices (const int vertex1_index, const int vertex2_index) const +t8_cad_handle::get_common_edge_of_vertices (const int vertex1_index, const int vertex2_index) const { T8_ASSERT (vertex1_index <= cad_shape_vertex2edge_map.Size ()); T8_ASSERT (vertex2_index <= cad_shape_vertex2edge_map.Size ()); @@ -164,7 +211,7 @@ t8_cad::t8_geom_get_common_edge_of_vertices (const int vertex1_index, const int 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); } } } @@ -172,7 +219,7 @@ t8_cad::t8_geom_get_common_edge_of_vertices (const int vertex1_index, const int } int -t8_cad::t8_geom_get_common_face_of_edges (const int edge1_index, const int edge2_index) const +t8_cad_handle::get_common_face_of_edges (const int edge1_index, const int edge2_index) const { T8_ASSERT (edge1_index <= cad_shape_edge2face_map.Size ()); T8_ASSERT (edge2_index <= cad_shape_edge2face_map.Size ()); @@ -190,14 +237,14 @@ t8_cad::t8_geom_get_common_face_of_edges (const int edge1_index, const int edge2 } int -t8_cad::t8_geom_get_common_face_of_vertex_and_edge (const int vertex_index, const int edge_index) const +t8_cad_handle::get_common_face_of_vertex_and_edge (const int vertex_index, const int edge_index) const { T8_ASSERT (vertex_index <= cad_shape_vertex_map.Size ()); T8_ASSERT (edge_index <= cad_shape_edge2face_map.Size ()); const TopTools_ListOfShape edge_collection = cad_shape_edge2face_map.FindFromIndex (edge_index); for (auto face = edge_collection.begin (); face != edge_collection.end (); ++face) { const size_t face_index = cad_shape_face_map.FindIndex (*face); - if (t8_geom_is_vertex_on_face (vertex_index, face_index)) { + if (is_vertex_on_face (vertex_index, face_index)) { return face_index; } } @@ -205,7 +252,7 @@ t8_cad::t8_geom_get_common_face_of_vertex_and_edge (const int vertex_index, cons } int -t8_cad::t8_geom_get_common_face_of_vertices (const int vertex1_index, const int vertex2_index) const +t8_cad_handle::get_common_face_of_vertices (const int vertex1_index, const int vertex2_index) const { T8_ASSERT (vertex1_index <= cad_shape_vertex2face_map.Size ()); T8_ASSERT (vertex2_index <= cad_shape_vertex2face_map.Size ()); @@ -221,9 +268,8 @@ t8_cad::t8_geom_get_common_face_of_vertices (const int vertex1_index, const int } return 0; } - int -t8_cad::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 { T8_ASSERT (vertex_index <= cad_shape_vertex2edge_map.Size ()); T8_ASSERT (edge_index <= cad_shape_edge_map.Size ()); @@ -232,7 +278,7 @@ t8_cad::t8_geom_is_vertex_on_edge (const int vertex_index, const int edge_index) } int -t8_cad::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 { T8_ASSERT (edge_index <= cad_shape_edge2face_map.Size ()); T8_ASSERT (face_index <= cad_shape_face_map.Size ()); @@ -241,27 +287,21 @@ t8_cad::t8_geom_is_edge_on_face (const int edge_index, const int face_index) con } int -t8_cad::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 { - 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 -t8_cad::t8_geom_vertex_is_seam (const int vertex_index, const int edge_index) const +t8_cad_handle::vertex_is_seam (const int vertex_index, const int edge_index) const { T8_ASSERT (vertex_index <= cad_shape_vertex_map.Size ()); T8_ASSERT (edge_index <= cad_shape_edge_map.Size ()); - const auto vertex = t8_cad::t8_geom_get_cad_vertex (vertex_index); - const auto edge = t8_cad::t8_geom_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); @@ -280,11 +320,11 @@ t8_cad::t8_geom_vertex_is_seam (const int vertex_index, const int edge_index) co } bool -t8_cad::t8_geom_vertex_is_on_seam_edge (const int vertex_index, const int face_index) const +t8_cad_handle::vertex_is_on_seam_edge (const int vertex_index, const int face_index) const { T8_ASSERT (vertex_index <= cad_shape_vertex2edge_map.Size ()); T8_ASSERT (face_index <= cad_shape_face_map.Size ()); - const auto face = t8_cad::t8_geom_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) { @@ -295,21 +335,21 @@ t8_cad::t8_geom_vertex_is_on_seam_edge (const int vertex_index, const int face_i } bool -t8_cad::t8_geom_edge_is_seam (const int edge_index, const int face_index) const +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::t8_geom_get_cad_face (face_index); - const auto edge = t8_cad::t8_geom_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); } void -t8_cad::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param, - std::optional reference_edge_param) const +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::t8_geom_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)); @@ -317,8 +357,8 @@ t8_cad::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const i 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::t8_geom_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 @@ -353,8 +393,8 @@ t8_cad::t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const i } void -t8_cad::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double face_params[2], - std::optional> reference_face_params) const +t8_cad_handle::get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double face_params[2], + std::optional> reference_face_params) const { /* DISCLAIMER: This function is overly complicated and I do not understand why the simpler versions do not work. The overly complicated part is only the edge case where the vertex lies on a seam and reference parameters are provided. @@ -367,19 +407,19 @@ t8_cad::t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const And thats why this algorithm does not work. What you see here is the more complicated workaround: */ - T8_ASSERT (t8_cad::t8_geom_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::t8_geom_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::t8_geom_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)); } @@ -450,17 +490,17 @@ 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 double edge_param, double face_params_out[2], - std::optional> reference_face_params) const +t8_cad_handle::edge_parameter_to_face_parameters (const int edge_index, const int face_index, const double edge_param, + double face_params_out[2], + std::optional> reference_face_params) const { - T8_ASSERT (t8_cad::t8_geom_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::t8_geom_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]); @@ -504,38 +544,38 @@ t8_cad::t8_geom_edge_parameter_to_face_parameters ( } void -t8_cad::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::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 (); } -bool -t8_cad::t8_geom_edge_is_closed (int edge_index) const +int +t8_cad_handle::edge_is_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 (); } bool -t8_cad::t8_geom_surface_is_closed (int geometry_index) const +t8_cad_handle::surface_is_closed (int geometry_index) 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); return cad_surface->IsUClosed () || cad_surface->IsVClosed (); } bool -t8_cad::t8_geom_surface_is_closed (int geometry_index, int direction) const +t8_cad_handle::surface_is_closed (int geometry_index, int direction) 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 (direction) { case 0: return cad_surface->IsUClosed (); diff --git a/src/t8_cad/t8_cad.hxx b/src/t8_cad/t8_cad_handle.hxx similarity index 74% rename from src/t8_cad/t8_cad.hxx rename to src/t8_cad/t8_cad_handle.hxx index 8dea025717..ec7c3c3809 100644 --- a/src/t8_cad/t8_cad.hxx +++ b/src/t8_cad/t8_cad_handle.hxx @@ -20,13 +20,13 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file t8_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 @@ -37,15 +37,15 @@ #include #include #include - +#include +#include /** * This class manages OpenCASCADE shapes and implements helper functions for working with the shapes. */ -struct t8_cad -{ +class t8_cad_handle { public: /** - * Constructor of the cad shape. + * 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 @@ -54,8 +54,7 @@ struct t8_cad * * \param [in] fileprefix Prefix of a .brep file from which to extract cad geometry. */ - t8_cad (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. @@ -63,88 +62,107 @@ struct t8_cad * 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 (const TopoDS_Shape cad_shape); + t8_cad_handle (TopoDS_Shape cad_shape_in); /** * Constructor of the cad shape for testing purposes. Sets an invalid cad_shape. */ - t8_cad (); + t8_cad_handle (); + + /** + * Destructor of the cad shape handle. + */ + ~t8_cad_handle (); + + /** + * 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 + load (const std::string_view fileprefix); + + /** + * Loads a cad shape from an existing TopoDS_Shape and maps it. + * \param [in] cad_shape_in The input cad shape. + */ + void + load (TopoDS_Shape cad_shape_in); /** Check if a cad_curve is a line. * \param [in] curve_index The index of the cad_curve. * \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 a cad vertex from the cad_shape. * \param [in] index The index of the vertex in the cad_shape. * \return The cad vertex. */ const TopoDS_Vertex - t8_geom_get_cad_vertex (const int index) const; + get_cad_vertex (const int index) const; /** Get a cad edge from the cad_shape. * \param [in] index The index of the edge in the cad_shape. * \return The cad edge. */ const TopoDS_Edge - t8_geom_get_cad_edge (const int index) const; + get_cad_edge (const int index) const; /** Get a cad face from the cad_shape. * \param [in] index The index of the face in the cad_shape. * \return The cad face. */ const TopoDS_Face - t8_geom_get_cad_face (const int index) const; + get_cad_face (const int index) const; /** Get a 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 a 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 a 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. @@ -152,7 +170,7 @@ struct t8_cad * \return Index of the shared edge. 0 if there is no shared edge. */ int - t8_geom_get_common_edge_of_vertices (const int vertex1_index, const int vertex2_index) const; + get_common_edge_of_vertices (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. @@ -160,7 +178,8 @@ struct t8_cad * \return Index of the shared face. 0 if there is no shared face. */ int - t8_geom_get_common_face_of_edges (const int edge1_index, const int edge2_index) const; + + get_common_face_of_edges (const int edge1_index, const int edge2_index) const; /** Check if a cad vertex and cad edge share a common face. * \param [in] vertex_index The index of the cad vertex. @@ -168,7 +187,7 @@ struct t8_cad * \return Index of the shared face. 0 if there is no shared face. */ int - t8_geom_get_common_face_of_vertex_and_edge (const int vertex_index, const int edge_index) const; + get_common_face_of_vertex_and_edge (const int vertex_index, const int edge_index) const; /** Check if two cad vertices share a common cad face. * \param [in] vertex1_index The index of the first cad edge. @@ -176,7 +195,7 @@ struct t8_cad * \return Index of the shared face. 0 if there is no shared face. */ int - t8_geom_get_common_face_of_vertices (const int vertex1_index, const int vertex2_index) const; + get_common_face_of_vertices (const int vertex1_index, const int vertex2_index) const; /** Check if a cad vertex lies on an cad edge. * \param [in] vertex_index The index of the cad vertex. @@ -184,7 +203,7 @@ struct t8_cad * \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. @@ -192,7 +211,7 @@ struct t8_cad * \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. @@ -200,7 +219,7 @@ struct t8_cad * \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; /** Returns true if \a vertex_index is on a seam of \a edge_index. * A seam is a vertex which connects a curve to itself. @@ -210,7 +229,7 @@ struct t8_cad * \return true if the vertex is a seam. false otherwise. */ bool - t8_geom_vertex_is_seam (const int vertex_index, const int edge_index) const; + vertex_is_seam (const int vertex_index, const int edge_index) const; /** Returns true if \a vertex_index is on a seam of \a face_index. * A seam is an edge which connects a surface to itself. @@ -220,7 +239,7 @@ struct t8_cad * \return true if the edge is a seam. false otherwise. */ bool - t8_geom_vertex_is_on_seam_edge (const int vertex_index, const int face_index) const; + vertex_is_on_seam_edge (const int vertex_index, const int face_index) const; /** Returns true if \a edge_index is a seam of \a face_index. * A seam is an edge which connects a surface to itself. @@ -230,7 +249,7 @@ struct t8_cad * \return true if the edge is a seam. false otherwise. */ bool - t8_geom_edge_is_seam (const int edge_index, const int face_index) const; + edge_is_seam (const int edge_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. @@ -244,8 +263,8 @@ struct t8_cad * \param [in] reference_edge_param Reference parameters on the edge. */ void - t8_geom_get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param, - std::optional reference_edge_param = std::nullopt) const; + get_parameter_of_vertex_on_edge (const int vertex_index, const int edge_index, double *edge_param, + std::optional reference_edge_param = std::nullopt) const; /** Retrieves the parameters of an cad vertex on a cad face. * The vertex has to lie on the face. @@ -260,9 +279,9 @@ struct t8_cad * \param [in] reference_face_params Reference parameters on the surface. */ void - t8_geom_get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double face_params[2], - std::optional> reference_face_params - = std::nullopt) const; + get_parameters_of_vertex_on_face (const int vertex_index, const int face_index, double face_params[2], + std::optional > reference_face_params + = std::nullopt) const; /** Converts the parameters of a cad edge to the corresponding parameters on a cad face. * The edge has to lie on the face. @@ -278,38 +297,61 @@ struct t8_cad * \param [in] reference_face_params Reference parameters on the surface. */ void - t8_geom_edge_parameter_to_face_parameters (const int edge_index, const int face_index, const double edge_param, - double face_params_out[2], - std::optional> reference_face_params - = std::nullopt) const; + edge_parameter_to_face_parameters (const int edge_index, const int face_index, const double edge_param, + double face_params_out[2], + std::optional > reference_face_params + = std::nullopt) 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. * \param [in] edge_index The index of the closed edge. * \return true if edge is closed */ - bool - t8_geom_edge_is_closed (int edge_index) const; + int + edge_is_closed (int edge_index) const; + + /** + * Increase the reference count of the cad handle. + */ + inline void + ref () + { + t8_refcount_ref (&rc); + } + + /** + * 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_handle.\n"); + delete this; + } + } /** Checks if a surface is closed in any direction. * \param [in] geometry_index The index of the closed geometry. * \return true if geometry is closed in any direction. */ + bool - t8_geom_surface_is_closed (int geometry_index) const; + surface_is_closed (int geometry_index) const; /** Checks if a surface is closed in its U direction or V direction. * \param [in] geometry_index The index of the closed geometry. @@ -318,9 +360,15 @@ struct t8_cad * \return true if geometry is closed in the given direction. */ bool - t8_geom_surface_is_closed (int geometry_index, int direction) const; + surface_is_closed (int geometry_index, int direction) const; private: + /** + * Map the cad shape to extract vertices, edges, faces, and their relationships. + */ + void + map (); + TopoDS_Shape cad_shape; /**< cad geometry */ TopTools_IndexedMapOfShape cad_shape_vertex_map; /**< Map of all TopoDS_Vertex. */ TopTools_IndexedMapOfShape cad_shape_edge_map; /**< Map of all TopoDS_Edge. */ @@ -331,6 +379,8 @@ struct t8_cad cad_shape_edge2face_map; /**< Maps all TopoDS_Edge to all its connected TopoDS_Face */ 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; }; -#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 aaa39c5e92..814d1a5822 100644 --- a/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx +++ b/src/t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx @@ -717,8 +717,8 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass /* 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_of_vertices (node1.entity_tag, - node2.entity_tag); + int common_edge + = cad_geometry->get_cad_handle ()->get_common_edge_of_vertices (node1.entity_tag, node2.entity_tag); if (common_edge > 0) { if (edge1_index == 0) { edge1_index = common_edge; @@ -733,7 +733,8 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass } /* If the face is linked to a surface we should now have two curves and we can check if both share a surface. */ if (edge2_index > 0) { - surface_index = cad_geometry->get_cad_manager ()->t8_geom_get_common_face_of_edges (edge1_index, edge2_index); + + surface_index = cad_geometry->get_cad_handle ()->get_common_face_of_edges (edge1_index, edge2_index); } else { continue; @@ -763,11 +764,11 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass break; case 1: /* If the edge is on the face we can check if it is a seam and if not we can use its parameters as reference. */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face (face_node->entity_tag, surface_index)) { + if (cad_geometry->get_cad_handle ()->is_edge_on_face (face_node->entity_tag, surface_index)) { if (!reference_parameters_on_surface - && !cad_geometry->get_cad_manager ()->t8_geom_edge_is_seam (face_node->entity_tag, surface_index)) { + && !cad_geometry->get_cad_handle ()->edge_is_seam (face_node->entity_tag, surface_index)) { reference_parameters_on_surface.emplace (); - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( face_node->entity_tag, surface_index, face_node->parameters[0], reference_parameters_on_surface.value ().data ()); } @@ -780,7 +781,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass case 0: /* If the vertex is not on the face, we can stop the face linkage. We do not have to check for reference parameters since a closed face linked to four vertices makes no sense. */ - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_face (face_node->entity_tag, surface_index)) + if (!cad_geometry->get_cad_handle ()->is_vertex_on_face (face_node->entity_tag, surface_index)) all_nodes_on_surface = 0; break; default: @@ -788,7 +789,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass } } /* 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 ()->is_plane (surface_index)) { continue; } @@ -804,14 +805,14 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass /* Nothing to do. */ break; case 1: - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( face_node.entity_tag, surface_index, face_node.parameters[0], face_node.parameters.data (), reference_parameters_on_surface); face_node.entity_dim = 2; face_node.entity_tag = surface_index; break; case 0: - cad_geometry->get_cad_manager ()->t8_geom_get_parameters_of_vertex_on_face ( + cad_geometry->get_cad_handle ()->get_parameters_of_vertex_on_face ( face_node.entity_tag, surface_index, face_node.parameters.data (), reference_parameters_on_surface); face_node.entity_dim = 2; face_node.entity_tag = surface_index; @@ -898,22 +899,19 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass 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 ()->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 ()->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 ()->is_vertex_on_edge (edge_nodes[i_edge].entity_tag, edge_geometry_tag)) { is_on_geom = 0; break; } @@ -935,11 +933,11 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass if (!is_on_geom) { int common_face = 0; if (edge_nodes[0].entity_dim == 1 && edge_nodes[1].entity_dim == 0) - common_face = cad_geometry->get_cad_manager ()->t8_geom_get_common_face_of_vertex_and_edge ( - edge_nodes[1].entity_tag, edge_nodes[0].entity_tag); + common_face = cad_geometry->get_cad_handle ()->get_common_face_of_vertex_and_edge (edge_nodes[1].entity_tag, + edge_nodes[0].entity_tag); if (edge_nodes[1].entity_dim == 1 && edge_nodes[0].entity_dim == 0) - common_face = cad_geometry->get_cad_manager ()->t8_geom_get_common_face_of_vertex_and_edge ( - edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); + common_face = cad_geometry->get_cad_handle ()->get_common_face_of_vertex_and_edge (edge_nodes[0].entity_tag, + edge_nodes[1].entity_tag); /* If a common face exists we can save it. */ if (common_face > 0) { edge_geometry_dim = 2; @@ -955,15 +953,15 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass * But we can look if both vertices share an edge/face and use this edge/face. * If not we can skip this edge. */ if (edge_geometry_dim == 0 && edge_geometry_tag == 0) { - int common_edge = cad_geometry->get_cad_manager ()->t8_geom_get_common_edge_of_vertices ( - edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); + int common_edge = cad_geometry->get_cad_handle ()->get_common_edge_of_vertices (edge_nodes[0].entity_tag, + edge_nodes[1].entity_tag); if (common_edge > 0) { edge_geometry_tag = common_edge; edge_geometry_dim = 1; } else { - int common_face = cad_geometry->get_cad_manager ()->t8_geom_get_common_face_of_vertices ( - edge_nodes[0].entity_tag, edge_nodes[1].entity_tag); + int common_face = cad_geometry->get_cad_handle ()->get_common_face_of_vertices (edge_nodes[0].entity_tag, + edge_nodes[1].entity_tag); if (common_face > 0) { edge_geometry_tag = common_face; edge_geometry_dim = 2; @@ -977,8 +975,8 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass * 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_face = cad_geometry->get_cad_manager ()->t8_geom_get_common_face_of_edges (edge_nodes[0].entity_tag, - edge_nodes[1].entity_tag); + int common_face = cad_geometry->get_cad_handle ()->get_common_face_of_edges (edge_nodes[0].entity_tag, + edge_nodes[1].entity_tag); if (common_face > 0) { edge_geometry_tag = common_face; edge_geometry_dim = 2; @@ -994,14 +992,14 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass /* Abort if the edge is a line. If the edge is a line, the curved computation would * only result in more computational overhead. */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_line (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->is_line (edge_geometry_tag)) { continue; } /* 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 ()->is_edge_on_face ( edge_geometry_tag, face_geometries[t8_edge_to_face[eclass][i_tree_edges][i_adjacent_face]])) { t8_global_errorf ("Error during mesh-cad recombination: Adjacent edge and face of a tree carry " "incompatible geometries.\n"); @@ -1032,7 +1030,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass return 0; } if (edge_node.entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_edge (edge_node.entity_tag, edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_edge (edge_node.entity_tag, edge_geometry_tag)) { t8_global_errorf ( "Error during mesh-cad recombination: Node %li should lie on a vertex which lies on an edge, " "but the vertex does not lie on that edge.\n", @@ -1049,10 +1047,10 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass break; case 0: /* If the node is on a vertex we can convert the parameters safely if the vertex os not the seam of the edge. */ - if (!cad_geometry->get_cad_manager ()->t8_geom_vertex_is_seam (edge_node.entity_tag, edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->vertex_is_seam (edge_node.entity_tag, edge_geometry_tag)) { reference_param.emplace (); - cad_geometry->get_cad_manager ()->t8_geom_get_parameter_of_vertex_on_edge ( - edge_node.entity_tag, edge_geometry_tag, &reference_param.value ()); + cad_geometry->get_cad_handle ()->get_parameter_of_vertex_on_edge (edge_node.entity_tag, edge_geometry_tag, + &reference_param.value ()); } break; default: @@ -1069,7 +1067,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass for (auto &edge_node : edge_nodes) { /* If the node lies on a vertex we retrieve its parameter on the curve */ if (edge_node.entity_dim == 0) { - cad_geometry->get_cad_manager ()->t8_geom_get_parameter_of_vertex_on_edge ( + cad_geometry->get_cad_handle ()->get_parameter_of_vertex_on_edge ( edge_node.entity_tag, edge_geometry_tag, edge_node.parameters.data (), reference_param); edge_node.entity_dim = 1; } @@ -1093,7 +1091,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass /* We also skip this edge if the edge is on a plane. Planes have no curvature and * therefore only result in computational overhead. */ - if (cad_geometry->get_cad_manager ()->t8_geom_is_plane (edge_geometry_tag)) { + if (cad_geometry->get_cad_handle ()->is_plane (edge_geometry_tag)) { continue; } @@ -1113,7 +1111,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass return 0; } if (edge_node.entity_dim == 0) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_vertex_on_face (edge_node.entity_tag, edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_vertex_on_face (edge_node.entity_tag, edge_geometry_tag)) { t8_global_errorf ( "Error during mesh-cad recombination: Node %li should lie on a vertex which lies on a face, " "but the vertex does not lie on that face.\n", @@ -1122,7 +1120,7 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass } } if (edge_node.entity_dim == 1) { - if (!cad_geometry->get_cad_manager ()->t8_geom_is_edge_on_face (edge_node.entity_tag, edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->is_edge_on_face (edge_node.entity_tag, edge_geometry_tag)) { t8_global_errorf ( "Error during mesh-cad recombination: Node %li should lie on an edge which lies on a face, " "but the edge does not lie on that face.\n", @@ -1138,18 +1136,17 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass break; case 1: /* If the node is on a curve, we can use the parameters if the curve is not the seam of the surface. */ - if (!cad_geometry->get_cad_manager ()->t8_geom_edge_is_seam (edge_node.entity_tag, edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->edge_is_seam (edge_node.entity_tag, edge_geometry_tag)) { reference_params.emplace (); - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( edge_node.entity_tag, edge_geometry_tag, edge_node.parameters[0], reference_params.value ().data ()); } break; case 0: /* If the node is on a vertex we can convert the parameters safely if the vertex is not the seam of the edge. */ - if (!cad_geometry->get_cad_manager ()->t8_geom_vertex_is_on_seam_edge (edge_node.entity_tag, - edge_geometry_tag)) { + if (!cad_geometry->get_cad_handle ()->vertex_is_on_seam_edge (edge_node.entity_tag, edge_geometry_tag)) { reference_params.emplace (); - cad_geometry->get_cad_manager ()->t8_geom_get_parameters_of_vertex_on_face ( + cad_geometry->get_cad_handle ()->get_parameters_of_vertex_on_face ( edge_node.entity_tag, edge_geometry_tag, reference_params.value ().data ()); } break; @@ -1167,13 +1164,13 @@ t8_cmesh_process_tree_geometry (const t8_cmesh_t cmesh, const t8_eclass_t eclass for (auto &edge_node : edge_nodes) { /* If the node lies on a vertex we retrieve its parameters on the surface */ if (edge_node.entity_dim == 0) { - cad_geometry->get_cad_manager ()->t8_geom_get_parameters_of_vertex_on_face ( + cad_geometry->get_cad_handle ()->get_parameters_of_vertex_on_face ( edge_node.entity_tag, edge_geometry_tag, edge_node.parameters.data (), reference_params); edge_node.entity_dim = 2; } /* If the node lies on an edge we have to do the same */ if (edge_node.entity_dim == 1) { - cad_geometry->get_cad_manager ()->t8_geom_edge_parameter_to_face_parameters ( + cad_geometry->get_cad_handle ()->edge_parameter_to_face_parameters ( edge_node.entity_tag, edge_geometry_tag, edge_node.parameters[0], edge_node.parameters.data (), reference_params); edge_node.entity_dim = 2; 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 502feb834c..563e23a21b 100644 --- a/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx +++ b/src/t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx @@ -56,13 +56,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") @@ -226,9 +226,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, interpolated_curve_parameter, - converted_edge_surface_parameters + offset_2d, - std::span (face_parameters, 2)); + cad_handle->edge_parameter_to_face_parameters (edges[i_edge], *faces, interpolated_curve_parameter, + converted_edge_surface_parameters + offset_2d, + std::span (face_parameters, 2)); } double edge_surface_parameters[4]; @@ -397,9 +397,9 @@ t8_geometry_cad::t8_geom_evaluate_cad_quad (t8_cmesh_t cmesh, t8_gloidx_t gtreei temp_edge_parameters); /* Convert curve parameter to surface parameters */ - cad_manager->t8_geom_edge_parameter_to_face_parameters (edges[i_edge], *faces, temp_edge_parameters[0], - temp_edge_parameters, - std::span (face_parameters, 2)); + cad_handle->edge_parameter_to_face_parameters (edges[i_edge], *faces, temp_edge_parameters[0], + temp_edge_parameters, + std::span (face_parameters, 2)); /* Interpolate between the surface parameters of the current edge */ double edge_surface_parameters[4]; @@ -422,7 +422,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->get_cad_surface (*faces); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -480,7 +480,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->get_cad_curve (edges[i_edge]); /* Check if curve are valid */ T8_ASSERT (!curve.IsNull ()); @@ -512,7 +512,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->get_cad_surface (edges[i_edge + num_edges]); /* Check if surface is valid */ T8_ASSERT (!surface.IsNull ()); @@ -966,7 +966,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 */ - cad_manager->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], interpolated_curve_param, surface_parameters_from_curve, std::span (surface_parameters, 2)); @@ -1278,7 +1278,7 @@ t8_geometry_cad::process_curve (const int curve_index, const double param) const gp_Pnt pnt; /* Retrieve the curve of the edge */ - const auto curve = cad_manager->t8_geom_get_cad_curve (curve_index); + const auto curve = cad_handle->get_cad_curve (curve_index); /* Check if curve is valid */ T8_ASSERT (!curve.IsNull ()); @@ -1294,7 +1294,7 @@ t8_geometry_cad::process_surface (const int surface_index, const double *params) gp_Pnt pnt; /* Retrieve the surface of the edge */ - const auto surface = cad_manager->t8_geom_get_cad_surface (surface_index); + const auto surface = cad_handle->get_cad_surface (surface_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 d81e1a0454..ceb6bd85e5 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: @@ -235,7 +235,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 handle of the geometry. */ }; #endif /* !T8_GEOMETRY_CAD_HXX */