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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef GeomAlgoAPI_ShapeTools_H_
21 #define GeomAlgoAPI_ShapeTools_H_
23 #include "GeomAlgoAPI.h"
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Vertex.h>
34 class GeomAPI_PlanarEdges;
37 class GeomDataAPI_Point2D;
38 class ModelAPI_Object;
40 /// \class GeomAlgoAPI_ShapeTools
42 /// \brief Useful tools for working with shapes.
43 class GeomAlgoAPI_ShapeTools
46 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
47 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
49 /// \return the centre of mass of the current face.
50 /// The coordinates returned for the center of mass
51 /// are expressed in the absolute Cartesian coordinate system.
52 /// (This function works only for surfaces).
53 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
54 centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
56 /// \brief Combines faces with common edges to shells, or solids to compsolids.
57 /// \param[in] theCompound compound of shapes.
58 /// \param[in] theType type of combine.
59 /// \param[out] theCombinedShapes resulting shapes.
60 /// \param[out] theFreeShapes shapes that does not have common subshapes.
61 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
62 const std::shared_ptr<GeomAPI_Shape> theCompound,
63 const GeomAPI_Shape::ShapeType theType,
64 ListOfShape& theCombinedShapes,
65 ListOfShape& theFreeShapes);
67 /// \brief Groups shapes with shared topology to compounds.
68 /// \param[in] theCompound compound of shapes.
69 /// \return compound of compounds with shared topology.
70 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
71 groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
73 /// \brief Calculates bounding box for theShapes
74 /// \return list of eight points.
75 /// \param[in] theShapes list of shapes.
76 /// \param[in] theEnlarge enlarges bounding box size.
77 GEOMALGOAPI_EXPORT static
78 std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
79 const double theEnlarge = 0.0);
81 /// \return infinite plane received from theFace plane.
82 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
83 faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
85 /// \brief Enlarges or reduces plane to fit bounding box.
86 /// \return plane that fits to bounding box.
87 /// \param[in] thePlane base plane.
88 /// \param[in] thePoints bounding box points (shoud be eight).
89 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
90 const std::shared_ptr<GeomAPI_Shape> thePlane,
91 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
93 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
94 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
95 /// Edge : theV1 is start and theV2 is end vertex;\n
96 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
97 /// contains no edges theV1 and theV2 are nullified.\n
98 /// If none of the above theV1 and theV2 are nullified.
99 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
100 std::shared_ptr<GeomAPI_Vertex>& theV1,
101 std::shared_ptr<GeomAPI_Vertex>& theV2);
103 /// \brief Creates faces with holes from wires.
104 /// \param[in] theWires base wires.
105 /// \param[out] theFaces resulting faces.
106 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
107 const std::shared_ptr<GeomAPI_Dir> theDirection,
108 const ListOfShape& theWires,
109 ListOfShape& theFaces);
111 /// \brief Return a plane for list of shapes if they are all planar.
112 /// \param[in] theShapes shapes to find plane.
113 /// \return plane where all shapes lie or empty ptr if they not planar.
114 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
116 /// \brief Checks that vertex/edge is inside face or vertext inside wire.
117 /// \param[in] theSubShape shape that should be inside.
118 /// \param[in] theBaseShape base shape.
119 /// \return true if edge inside the face.
120 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
121 const std::shared_ptr<GeomAPI_Shape> theSubShape,
122 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
124 /// \return true if theShape is valid.
125 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
127 /// \return outer wire for face. If theShape has different type returns empty pointer.
128 GEOMALGOAPI_EXPORT static
129 std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
131 /// \return true if edge is parallel to face.
132 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
133 const std::shared_ptr<GeomAPI_Face> theFace);
135 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
136 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
137 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
138 /// \brief Performs the split of the shape by points.
139 /// \param[in] theBaseShape shape that should be splitted.
140 /// \param[in] thePoints container of points to split
141 /// \param[out] theShapes container of shapes after split
142 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
143 const PointToRefsMap& thePointsInfo,
144 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
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_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
151 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
152 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
154 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
155 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
156 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);