1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_ShapeTools.h
4 // Created: 3 August 2015
5 // Author: Dmitry Bobylev
7 #ifndef GeomAlgoAPI_ShapeTools_H_
8 #define GeomAlgoAPI_ShapeTools_H_
10 #include "GeomAlgoAPI.h"
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_Vertex.h>
21 class GeomAPI_PlanarEdges;
24 class GeomDataAPI_Point2D;
25 class ModelAPI_Object;
27 /// \class GeomAlgoAPI_ShapeTools
29 /// \brief Useful tools for working with shapes.
30 class GeomAlgoAPI_ShapeTools
33 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
34 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
36 /// \return the centre of mass of the current face.
37 /// The coordinates returned for the center of mass
38 /// are expressed in the absolute Cartesian coordinate system.
39 /// (This function works only for surfaces).
40 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
41 centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
43 /// \brief Combines faces with common edges to shells, or solids to compsolids.
44 /// \param[in] theCompound compound of shapes.
45 /// \param[in] theType type of combine.
46 /// \param[out] theCombinedShapes resulting shapes.
47 /// \param[out] theFreeShapes shapes that does not have common subshapes.
48 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
49 const std::shared_ptr<GeomAPI_Shape> theCompound,
50 const GeomAPI_Shape::ShapeType theType,
51 ListOfShape& theCombinedShapes,
52 ListOfShape& theFreeShapes);
54 /// \brief Groups shapes with shared topology to compounds.
55 /// \param[in] theCompound compound of shapes.
56 /// \return compound of compounds with shared topology.
57 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
58 groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
60 /// \brief Calculates bounding box for theShapes
61 /// \return list of eight points.
62 /// \param[in] theShapes list of shapes.
63 /// \param[in] theEnlarge enlarges bounding box size.
64 GEOMALGOAPI_EXPORT static
65 std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
66 const double theEnlarge = 0.0);
68 /// \return infinite plane received from theFace plane.
69 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
70 faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
72 /// \brief Enlarges or reduces plane to fit bounding box.
73 /// \return plane that fits to bounding box.
74 /// \param[in] thePlane base plane.
75 /// \param[in] thePoints bounding box points (shoud be eight).
76 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
77 const std::shared_ptr<GeomAPI_Shape> thePlane,
78 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
80 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
81 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
82 /// Edge : theV1 is start and theV2 is end vertex;\n
83 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
84 /// contains no edges theV1 and theV2 are nullified.\n
85 /// If none of the above theV1 and theV2 are nullified.
86 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
87 std::shared_ptr<GeomAPI_Vertex>& theV1,
88 std::shared_ptr<GeomAPI_Vertex>& theV2);
90 /// \brief Creates faces with holes from wires.
91 /// \param[in] theWires base wires.
92 /// \param[out] theFaces resulting faces.
93 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
94 const std::shared_ptr<GeomAPI_Dir> theDirection,
95 const ListOfShape& theWires,
96 ListOfShape& theFaces);
98 /// \brief Return a plane for list of shapes if they are all planar.
99 /// \param[in] theShapes shapes to find plane.
100 /// \return plane where all shapes lie or empty ptr if they not planar.
101 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
103 /// \brief Checks that vertex/edge is inside face or vertext inside wire.
104 /// \param[in] theSubShape shape that should be inside.
105 /// \param[in] theBaseShape base shape.
106 /// \return true if edge inside the face.
107 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
108 const std::shared_ptr<GeomAPI_Shape> theSubShape,
109 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
111 /// \return true if theShape is valid.
112 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
114 /// \return outer wire for face. If theShape has different type returns empty pointer.
115 GEOMALGOAPI_EXPORT static
116 std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
118 /// \return true if edge is parallel to face.
119 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
120 const std::shared_ptr<GeomAPI_Face> theFace);
122 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
123 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
124 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
125 /// \brief Performs the split of the shape by points.
126 /// \param[in] theBaseShape shape that should be splitted.
127 /// \param[in] thePoints container of points to split
128 /// \param[out] theShapes container of shapes after split
129 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
130 const PointToRefsMap& thePointsInfo,
131 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
133 /// \brief Performs the split of the shape by points.
134 /// \param[in] theBaseShape shape that should be splitted.
135 /// \param[in] thePoints container of points to split
136 /// \param[out] theShapes container of shapes after split
137 GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
138 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
139 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
141 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
142 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
143 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);