19#ifdef DEAL_II_WITH_OPENCASCADE
27# include <IGESControl_Controller.hxx>
28# include <IGESControl_Reader.hxx>
29# include <IGESControl_Writer.hxx>
30# include <STEPControl_Controller.hxx>
31# include <STEPControl_Reader.hxx>
32# include <STEPControl_Writer.hxx>
33# include <TopExp_Explorer.hxx>
35# include <TopoDS_Edge.hxx>
36# include <TopoDS_Face.hxx>
37# include <TopoDS_Shape.hxx>
41# if DEAL_II_OPENCASCADE_VERSION_GTE(7, 0, 0)
42# include <Standard_Transient.hxx>
44# include <Handle_Standard_Transient.hxx>
47# include <BRepAdaptor_Curve.hxx>
48# if DEAL_II_OPENCASCADE_VERSION_GTE(7, 6, 0)
49# include <BRepAlgoAPI_Section.hxx>
51# include <BRepAdaptor_HCompCurve.hxx>
52# include <BRepAdaptor_HCurve.hxx>
53# include <BRepAlgo_Section.hxx>
55# include <BRepAdaptor_Surface.hxx>
56# include <BRepBndLib.hxx>
57# include <BRepBuilderAPI_MakeEdge.hxx>
58# include <BRepBuilderAPI_Sewing.hxx>
59# include <BRepBuilderAPI_Transform.hxx>
60# include <BRepMesh_IncrementalMesh.hxx>
61# include <BRepTools.hxx>
62# include <BRep_Builder.hxx>
63# include <GCPnts_AbscissaPoint.hxx>
64# include <GeomAPI_Interpolate.hxx>
65# include <GeomAPI_ProjectPointOnCurve.hxx>
66# include <GeomAPI_ProjectPointOnSurf.hxx>
67# include <GeomConvert_CompCurveToBSplineCurve.hxx>
68# include <GeomLProp_SLProps.hxx>
69# include <Geom_BoundedCurve.hxx>
70# include <Geom_Plane.hxx>
71# include <IntCurvesFace_ShapeIntersector.hxx>
72# include <Poly_Triangulation.hxx>
73# include <ShapeAnalysis_Surface.hxx>
74# include <StlAPI_Reader.hxx>
75# include <StlAPI_Writer.hxx>
76# include <TColStd_HSequenceOfTransient.hxx>
77# include <TColStd_SequenceOfTransient.hxx>
78# include <TColgp_HArray1OfPnt.hxx>
79# include <TopLoc_Location.hxx>
92 std::tuple<unsigned int, unsigned int, unsigned int>
96 unsigned int n_faces = 0,
n_edges = 0, n_vertices = 0;
97 for (exp.Init(shape,
TopAbs_FACE); exp.More(); exp.Next(), ++n_faces)
103 for (exp.Init(shape,
TopAbs_VERTEX); exp.More(); exp.Next(), ++n_vertices)
106 return std::tuple<unsigned int, unsigned int, unsigned int>(n_faces,
113 std::vector<TopoDS_Face> &faces,
114 std::vector<TopoDS_Edge> &
edges,
115 std::vector<TopoDS_Vertex> &vertices)
122 for (exp.Init(shape,
TopAbs_FACE); exp.More(); exp.Next())
126 for (exp.Init(shape,
TopAbs_EDGE); exp.More(); exp.Next())
128 edges.push_back(TopoDS::Edge(exp.Current()));
132 vertices.push_back(TopoDS::Vertex(exp.Current()));
141 std::vector<TopoDS_Solid> &
solids,
142 std::vector<TopoDS_Shell> &
shells,
143 std::vector<TopoDS_Wire> &
wires)
160 for (exp.Init(shape,
TopAbs_SOLID); exp.More(); exp.Next())
164 for (exp.Init(shape,
TopAbs_SHELL); exp.More(); exp.Next())
168 for (exp.Init(shape,
TopAbs_WIRE); exp.More(); exp.Next())
174 template <
int spacedim>
181 return gp_Pnt(p[0], 0, 0);
183 return gp_Pnt(p[0], p[1], 0);
185 return gp_Pnt(p[0], p[1], p[2]);
191 template <
int spacedim>
201 "Cannot convert OpenCASCADE point to 1d if p.Y() != 0."));
204 "Cannot convert OpenCASCADE point to 1d if p.Z() != 0."));
209 "Cannot convert OpenCASCADE point to 2d if p.Z() != 0."));
223 const double tolerance)
225 const double rel_tol =
227 if (direction.
norm() > 0.0)
228 return (
p1 * direction <
p2 * direction - rel_tol);
230 for (
int d = dim; d >= 0; --d)
231 if (
p1[d] <
p2[d] - rel_tol)
233 else if (
p2[d] <
p1[d] - rel_tol)
268 return trans.Shape();
305 std::vector<TopoDS_Vertex> vertices;
306 std::vector<TopoDS_Edge>
edges;
307 std::vector<TopoDS_Face> faces;
310 std::none_of(faces.begin(), faces.end(), [&
Loc](
const TopoDS_Face &face) {
311 Handle(Poly_Triangulation) theTriangulation =
312 BRep_Tool::Triangulation(face, Loc);
313 return theTriangulation.IsNull();
339# if DEAL_II_OPENCASCADE_VERSION_GTE(6, 9, 0)
344# if !DEAL_II_OPENCASCADE_VERSION_GTE(7, 2, 0)
385 return trans.Shape();
396 ExcMessage(
"Failed to add shape to STEP controller."));
401 ExcMessage(
"Failed to write translated shape to STEP file."));
407 double tolerance = 0.0;
409 std::vector<TopoDS_Face> faces;
410 std::vector<TopoDS_Edge>
edges;
411 std::vector<TopoDS_Vertex> vertices;
415 for (
const auto &vertex : vertices)
421 for (
const auto &face : faces)
437# if DEAL_II_OPENCASCADE_VERSION_GTE(7, 6, 0)
483 if (
added[i] ==
false)
505 ExcMessage(
"Joining some of the Edges failed."));
518 const double tolerance)
525 dim > 1 ? direction[1] : 0,
526 dim > 2 ? direction[2] : 0));
544 for (
int i = 0; i <
Inters.NbPnt(); ++i)
564 const double tolerance)
568 if (direction * direction > 0)
573 return OpenCASCADE::point_compare(p1,
583 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
592 ExcMessage(
"Interpolated bspline generation failed"));
602 template <
int spacedim>
603 std::vector<TopoDS_Edge>
611 std::map<unsigned int, std::pair<unsigned int, unsigned int>>
vert_to_faces;
612 std::map<unsigned int, std::pair<unsigned int, unsigned int>>
face_to_verts;
616 unsigned int face_index;
618 for (
const auto &cell :
triangulation.active_cell_iterators())
620 if (cell->face(f)->at_boundary())
623 face_index = cell->face(f)->index();
624 const unsigned int v0 = cell->face(f)->vertex_index(0);
625 const unsigned int v1 = cell->face(f)->vertex_index(1);
631 const auto verts = mapping.get_vertices(cell);
633 f, 0,
true,
false,
false)];
635 f, 1,
true,
false,
false)];
694 if (f.second ==
false)
696 face_index = f.first;
709 const double tolerance)
776 u =
Proj.LowerDistanceParameter();
783 return std::tuple<Point<dim>,
TopoDS_Shape, double,
double>(
792 const double tolerance)
796 return std::get<0>(
ref);
802 const double tolerance)
814 std::tuple<unsigned int, unsigned int, unsigned int>
numbers =
821 "Could not find normal: the shape containing the closest point has 0 faces."));
825 "Could not find normal: the shape containing the closest point has more than 1 face."));
868 ExcMessage(
"Curvature is not well defined!"));
892 template <
int spacedim>
898 const double u0 =
surf.FirstUParameter();
899 const double u1 =
surf.LastUParameter();
900 const double v0 =
surf.FirstVParameter();
901 const double v1 =
surf.LastVParameter();
903 std::vector<CellData<2>> cells;
904 std::vector<Point<spacedim>> vertices;
913 for (
unsigned int i = 0; i < 4; ++i)
914 cell.vertices[i] = i;
916 cells.push_back(cell);
917 tria.create_triangulation(vertices, cells, t);
925# include "opencascade/utilities.inst"
numbers::NumberTraits< Number >::real_type norm() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcUnsupportedShape()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
TopoDS_Edge interpolation_curve(std::vector< Point< dim > > &curve_points, const Tensor< 1, dim > &direction=Tensor< 1, dim >(), const bool closed=false, const double tolerance=1e-7)
std::tuple< Point< 3 >, Tensor< 1, 3 >, double, double > push_forward_and_differential_forms(const TopoDS_Face &face, const double u, const double v, const double tolerance=1e-7)
void extract_compound_shapes(const TopoDS_Shape &shape, std::vector< TopoDS_Compound > &compounds, std::vector< TopoDS_CompSolid > &compsolids, std::vector< TopoDS_Solid > &solids, std::vector< TopoDS_Shell > &shells, std::vector< TopoDS_Wire > &wires)
Point< dim > push_forward(const TopoDS_Shape &in_shape, const double u, const double v)
std::tuple< unsigned int, unsigned int, unsigned int > count_elements(const TopoDS_Shape &shape)
void write_STEP(const TopoDS_Shape &shape, const std::string &filename)
std::tuple< Point< 3 >, Tensor< 1, 3 >, double, double > closest_point_and_differential_forms(const TopoDS_Shape &in_shape, const Point< 3 > &origin, const double tolerance=1e-7)
void extract_geometrical_shapes(const TopoDS_Shape &shape, std::vector< TopoDS_Face > &faces, std::vector< TopoDS_Edge > &edges, std::vector< TopoDS_Vertex > &vertices)
TopoDS_Edge join_edges(const TopoDS_Shape &in_shape, const double tolerance=1e-7)
TopoDS_Shape read_STEP(const std::string &filename, const double scale_factor=1e-3)
bool point_compare(const Point< dim > &p1, const Point< dim > &p2, const Tensor< 1, dim > &direction=Tensor< 1, dim >(), const double tolerance=1e-10)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Point< dim > closest_point(const TopoDS_Shape &in_shape, const Point< dim > &origin, const double tolerance=1e-7)
std::tuple< Point< dim >, TopoDS_Shape, double, double > project_point_and_pull_back(const TopoDS_Shape &in_shape, const Point< dim > &origin, const double tolerance=1e-7)
Point< dim > line_intersection(const TopoDS_Shape &in_shape, const Point< dim > &origin, const Tensor< 1, dim > &direction, const double tolerance=1e-7)
void write_STL(const TopoDS_Shape &shape, const std::string &filename, const double deflection, const bool sew_different_faces=false, const double sewer_tolerance=1e-6, const bool is_relative=false, const double angular_deflection=0.5, const bool in_parallel=false)
void create_triangulation(const TopoDS_Face &face, Triangulation< 2, spacedim > &tria)
TopoDS_Shape read_STL(const std::string &filename)
TopoDS_Shape intersect_plane(const TopoDS_Shape &in_shape, const double c_x, const double c_y, const double c_z, const double c, const double tolerance=1e-7)
std::vector< TopoDS_Edge > create_curves_from_triangulation_boundary(const Triangulation< 2, spacedim > &triangulation, const Mapping< 2, spacedim > &mapping=StaticMappingQ1< 2, spacedim >::mapping)
double get_shape_tolerance(const TopoDS_Shape &shape)
void write_IGES(const TopoDS_Shape &shape, const std::string &filename)
TopoDS_Shape read_IGES(const std::string &filename, const double scale_factor=1e-3)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
static unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > face_indices()