1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef GeomAlgoAPI_ShapeTools_H_
22 #define GeomAlgoAPI_ShapeTools_H_
24 #include "GeomAlgoAPI.h"
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_Vertex.h>
36 class GeomAPI_PlanarEdges;
40 class GeomDataAPI_Point2D;
41 class ModelAPI_Object;
43 /// \class GeomAlgoAPI_ShapeTools
45 /// \brief Useful tools for working with shapes.
46 class GeomAlgoAPI_ShapeTools
49 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
50 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
52 /// \return the total area of the faces of the current shape or 0.0 if it can be computed.
53 GEOMALGOAPI_EXPORT static double area(const std::shared_ptr<GeomAPI_Shape> theShape);
55 /// \return the center of mass of the current face.
56 /// The coordinates returned for the center of mass
57 /// are expressed in the absolute Cartesian coordinate system.
58 /// (This function works only for surfaces).
59 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
60 centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
62 /// \brief Obtain radius of cylindrical face.
63 /// Return negative value if the face is not a cylinder
64 GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr<GeomAPI_Face>& theCylinder);
66 /// \brief Calculate minimal distance between shapes
67 GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
68 const GeomShapePtr& theShape2);
70 /// \brief Combines faces with common edges to shells, or solids to compsolids.
71 /// \param[in] theCompound compound of shapes.
72 /// \param[in] theType type of combine.
73 /// \param[out] theCombinedShapes resulting shapes.
74 /// \param[out] theFreeShapes shapes that does not have common subshapes.
75 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
76 const std::shared_ptr<GeomAPI_Shape> theCompound,
77 const GeomAPI_Shape::ShapeType theType,
78 ListOfShape& theCombinedShapes,
79 ListOfShape& theFreeShapes);
81 /// \brief Groups shapes with shared topology to compounds.
82 /// \param[in] theCompound compound of shapes.
83 /// \return compound of compounds with shared topology.
84 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
85 groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
87 /// \brief Calculates bounding box for theShapes
88 /// \return list of eight points.
89 /// \param[in] theShapes list of shapes.
90 /// \param[in] theEnlarge enlarges bounding box size.
91 GEOMALGOAPI_EXPORT static
92 std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
93 const double theEnlarge = 0.0);
95 /// \brief Enlarges or reduces plane to fit bounding box.
96 /// \return plane that fits to bounding box.
97 /// \param[in] thePlane base plane.
98 /// \param[in] thePoints bounding box points (should be eight).
99 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
100 const std::shared_ptr<GeomAPI_Shape> thePlane,
101 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
103 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
104 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
105 /// Edge : theV1 is start and theV2 is end vertex;\n
106 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
107 /// contains no edges theV1 and theV2 are nullified.\n
108 /// If none of the above theV1 and theV2 are nullified.
109 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
110 std::shared_ptr<GeomAPI_Vertex>& theV1,
111 std::shared_ptr<GeomAPI_Vertex>& theV2);
113 /// \brief Creates faces with holes from wires.
114 /// \param[in] theWires base wires.
115 /// \param[out] theFaces resulting faces.
116 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
117 const std::shared_ptr<GeomAPI_Dir> theDirection,
118 const ListOfShape& theWires,
119 ListOfShape& theFaces);
121 /// \brief Return a plane for list of shapes if they are all planar.
122 /// \param[in] theShapes shapes to find plane.
123 /// \return plane where all shapes lie or empty pointer if they not planar.
124 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
126 /// \brief Checks that vertex/edge is inside face or vertex inside wire.
127 /// \param[in] theSubShape shape that should be inside.
128 /// \param[in] theBaseShape base shape.
129 /// \return true if edge inside the face.
130 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
131 const std::shared_ptr<GeomAPI_Shape> theSubShape,
132 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
134 /// \return true if theShape is valid.
135 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
137 /// \return outer wire for face. If theShape has different type returns empty pointer.
138 GEOMALGOAPI_EXPORT static
139 std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
141 /// \return true if edge is parallel to face.
142 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
143 const std::shared_ptr<GeomAPI_Face> theFace);
145 // Computes intersection point between the edge curve and a face surface (only one point, with
146 // preferences to point that belongs to edge and face boundaries.
147 /// \returns null if there is no intersection
148 GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Vertex> > intersect(
149 const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace,
150 const bool thePointsOutsideFace);
152 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
153 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
154 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
155 /// \brief Performs the split of the shape by points.
156 /// \param[in] theBaseShape shape that should be divided.
157 /// \param[in] thePoints container of points to split
158 /// \param[out] theShapes container of shapes after split
159 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
160 const PointToRefsMap& thePointsInfo,
161 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
163 /// \brief Performs the split of the shape by points.
164 /// \param[in] theBaseShape shape that should be divided.
165 /// \param[in] thePoints container of points to split
166 /// \param[out] theShapes container of shapes after split
167 GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
168 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
169 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
171 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
172 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
173 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
175 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
176 /// \brief Returns a direction from a shape and an axis.
177 /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
178 /// \param[in] theAxis axis that serves as a direction for the dir
179 /// \return dir that builds from center of mass of the base shape and the axis
180 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
181 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
182 const std::shared_ptr<GeomAPI_Ax1> theAxis);
185 /// \brief Re-approximate a wire to build a single edge
186 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
187 const std::shared_ptr<GeomAPI_Wire>& theWire);
189 /// \brief Get non-composite sub-shapes of the given shape.
190 /// \param[in] theShape shape that should be exploded
191 /// \return list of sub-shapes (vertices, edges, faces, solids)
192 GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);