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