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