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>
22 class GeomAPI_PlanarEdges;
25 class GeomDataAPI_Point2D;
26 class ModelAPI_Object;
28 /// \class GeomAlgoAPI_ShapeTools
30 /// \brief Useful tools for working with shapes.
31 class GeomAlgoAPI_ShapeTools
34 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
35 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
37 /// \return the centre of mass of the current face.
38 /// The coordinates returned for the center of mass
39 /// are expressed in the absolute Cartesian coordinate system.
40 /// (This function works only for surfaces).
41 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
42 centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
44 /// \brief Combines faces with common edges to shells, or solids to compsolids.
45 /// \param[in] theCompound compound of shapes.
46 /// \param[in] theType type of combine.
47 /// \param[out] theCombinedShapes resulting shapes.
48 /// \param[out] theFreeShapes shapes that does not have common subshapes.
49 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
50 const std::shared_ptr<GeomAPI_Shape> theCompound,
51 const GeomAPI_Shape::ShapeType theType,
52 ListOfShape& theCombinedShapes,
53 ListOfShape& theFreeShapes);
55 /// \brief Groups shapes with shared topology to compounds.
56 /// \param[in] theCompound compound of shapes.
57 /// \return compound of compounds with shared topology.
58 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
59 groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
61 /// \brief Calculates bounding box for theShapes
62 /// \return list of eight points.
63 /// \param[in] theShapes list of shapes.
64 /// \param[in] theEnlarge enlarges bounding box size.
65 GEOMALGOAPI_EXPORT static
66 std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
67 const double theEnlarge = 0.0);
69 /// \return infinite plane received from theFace plane.
70 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
71 faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
73 /// \brief Enlarges or reduces plane to fit bounding box.
74 /// \return plane that fits to bounding box.
75 /// \param[in] thePlane base plane.
76 /// \param[in] thePoints bounding box points (shoud be eight).
77 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
78 const std::shared_ptr<GeomAPI_Shape> thePlane,
79 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
81 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
82 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
83 /// Edge : theV1 is start and theV2 is end vertex;\n
84 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
85 /// contains no edges theV1 and theV2 are nullified.\n
86 /// If none of the above theV1 and theV2 are nullified.
87 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
88 std::shared_ptr<GeomAPI_Vertex>& theV1,
89 std::shared_ptr<GeomAPI_Vertex>& theV2);
91 /// \brief Creates faces with holes from wires.
92 /// \param[in] theWires base wires.
93 /// \param[out] theFaces resulting faces.
94 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
95 const std::shared_ptr<GeomAPI_Dir> theDirection,
96 const ListOfShape& theWires,
97 ListOfShape& theFaces);
99 /// \brief Return a plane for list of shapes if they are all planar.
100 /// \param[in] theShapes shapes to find plane.
101 /// \return plane where all shapes lie or empty ptr if they not planar.
102 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
104 /// \brief Checks that vertex/edge is inside face or vertext inside wire.
105 /// \param[in] theSubShape shape that should be inside.
106 /// \param[in] theBaseShape base shape.
107 /// \return true if edge inside the face.
108 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
109 const std::shared_ptr<GeomAPI_Shape> theSubShape,
110 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
112 /// \return true if theShape is valid.
113 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
115 /// \return outer wire for face. If theShape has different type returns empty pointer.
116 GEOMALGOAPI_EXPORT static
117 std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
119 /// \return true if edge is parallel to face.
120 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
121 const std::shared_ptr<GeomAPI_Face> theFace);
123 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
124 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
125 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
126 /// \brief Performs the split of the shape by points.
127 /// \param[in] theBaseShape shape that should be splitted.
128 /// \param[in] thePoints container of points to split
129 /// \param[out] theShapes container of shapes after split
130 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
131 const PointToRefsMap& thePointsInfo,
132 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
134 /// \brief Performs the split of the shape by points.
135 /// \param[in] theBaseShape shape that should be splitted.
136 /// \param[in] thePoints container of points to split
137 /// \param[out] theShapes container of shapes after split
138 GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
139 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
140 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
142 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
143 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
144 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
146 /// \brief Returns a dir from a shape and an axis.
147 /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
148 /// \param[in] theAxis axis that serves as a direction for the dir
149 /// \return dir that builds from center of mass of the base shape and the axis
150 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
151 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
152 const std::shared_ptr<GeomAPI_Ax1> theAxis);