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