Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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_Edge;
33 class GeomAPI_Dir;
34 class GeomAPI_Face;
35 class GeomAPI_PlanarEdges;
36 class GeomAPI_Pln;
37 class GeomAPI_Pnt;
38 class GeomDataAPI_Point2D;
39 class ModelAPI_Object;
40
41 /// \class GeomAlgoAPI_ShapeTools
42 /// \ingroup DataAlgo
43 /// \brief Useful tools for working with shapes.
44 class GeomAlgoAPI_ShapeTools
45 {
46 public:
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);
49
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);
56
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);
67
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);
73
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);
81
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);
85
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);
93
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);
103
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);
111
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);
116
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);
124
125   /// \return true if theShape is valid.
126   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
127
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);
131
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);
135
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);
146
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);
154
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);
158
159 };
160
161 #endif