Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef GeomAlgoAPI_ShapeTools_H_
22 #define GeomAlgoAPI_ShapeTools_H_
23
24 #include "GeomAlgoAPI.h"
25
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_Vertex.h>
28
29 #include <map>
30 #include <set>
31
32 class GeomAPI_Ax1;
33 class GeomAPI_Edge;
34 class GeomAPI_Dir;
35 class GeomAPI_Face;
36 class GeomAPI_PlanarEdges;
37 class GeomAPI_Pln;
38 class GeomAPI_Pnt;
39 class GeomDataAPI_Point2D;
40 class ModelAPI_Object;
41
42 /// \class GeomAlgoAPI_ShapeTools
43 /// \ingroup DataAlgo
44 /// \brief Useful tools for working with shapes.
45 class GeomAlgoAPI_ShapeTools
46 {
47 public:
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);
50
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);
57
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);
68
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);
74
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);
82
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);
86
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);
94
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);
104
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);
112
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);
117
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);
125
126   /// \return true if theShape is valid.
127   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
128
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);
132
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);
136
137   typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
138                    std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
139                              std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
140   /// \brief Performs the split of the shape by points.
141   /// \param[in] theBaseShape shape that should be splitted.
142   /// \param[in] thePoints container of points to split
143   /// \param[out] theShapes container of shapes after split
144   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
145                                       const PointToRefsMap& thePointsInfo,
146                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
147
148   /// \brief Performs the split of the shape by points.
149   /// \param[in] theBaseShape shape that should be splitted.
150   /// \param[in] thePoints container of points to split
151   /// \param[out] theShapes container of shapes after split
152   GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
153                                       const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
154                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
155
156   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
157                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
158                                     const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
159
160   /// \brief Returns a dir from a shape and an axis.
161   /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
162   /// \param[in] theAxis axis that serves as a direction for the dir
163   /// \return dir that builds from center of mass of the base shape and the axis
164   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
165                                     const std::shared_ptr<GeomAPI_Shape> theBaseShape,
166                                     const std::shared_ptr<GeomAPI_Ax1> theAxis);
167 };
168
169 #endif