Salome HOME
Fix for the issue #2225 : Incorrect face naming when creating a pipe from a face...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef GeomAlgoAPI_ShapeTools_H_
21 #define GeomAlgoAPI_ShapeTools_H_
22
23 #include "GeomAlgoAPI.h"
24
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Vertex.h>
27
28 #include <map>
29 #include <set>
30
31 class GeomAPI_Ax1;
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 GeomAPI_Wire;
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 total area of the faces of the current shape or 0.0 if it can be computed.
52   GEOMALGOAPI_EXPORT static double area(const std::shared_ptr<GeomAPI_Shape> theShape);
53
54   /// \return the center of mass of the current face.
55   /// The coordinates returned for the center of mass
56   /// are expressed in the absolute Cartesian coordinate system.
57   /// (This function works only for surfaces).
58   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
59     centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
60
61   /// \brief Obtain radius of cylindrical face.
62   ///        Return negative value if the face is not a cylinder
63   GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr<GeomAPI_Face>& theCylinder);
64
65   /// \brief Calculate minimal distance between shapes
66   GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
67                                                    const GeomShapePtr& theShape2);
68
69   /// \brief Combines faces with common edges to shells, or solids to compsolids.
70   /// \param[in] theCompound compound of shapes.
71   /// \param[in] theType type of combine.
72   /// \param[out] theResults resulting shapes.
73   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
74     const std::shared_ptr<GeomAPI_Shape> theCompound,
75     const GeomAPI_Shape::ShapeType theType, ListOfShape& theResults);
76
77   /// \brief Groups shapes with shared topology to compounds.
78   /// \param[in] theCompound compound of shapes.
79   /// \return compound of compounds with shared topology.
80   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
81     groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
82
83   /// \brief Calculates bounding box for theShapes
84   /// \return list of eight points.
85   /// \param[in] theShapes list of shapes.
86   /// \param[in] theEnlarge enlarges bounding box size.
87   GEOMALGOAPI_EXPORT static
88     std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
89                                                             const double theEnlarge = 0.0);
90
91   /// \brief Enlarges or reduces plane to fit bounding box.
92   /// \return plane that fits to bounding box.
93   /// \param[in] thePlane base plane.
94   /// \param[in] thePoints bounding box points (should be eight).
95   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
96     const std::shared_ptr<GeomAPI_Shape> thePlane,
97     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
98
99   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
100   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
101   /// Edge : theV1 is start and theV2 is end vertex;\n
102   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
103   /// contains no edges theV1 and theV2 are nullified.\n
104   /// If none of the above theV1 and theV2 are nullified.
105   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
106                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
107                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
108
109   /// \brief Creates faces with holes from wires.
110   /// \param[in] theWires base wires.
111   /// \param[out] theFaces resulting faces.
112   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
113                                                 const std::shared_ptr<GeomAPI_Dir> theDirection,
114                                                 const ListOfShape& theWires,
115                                                 ListOfShape& theFaces);
116
117   /// \brief Return a plane for list of shapes if they are all planar.
118   /// \param[in] theShapes shapes to find plane.
119   /// \return plane where all shapes lie or empty pointer if they not planar.
120   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
121
122   /// \brief Checks that vertex/edge is inside face or vertex inside wire.
123   /// \param[in] theSubShape shape that should be inside.
124   /// \param[in] theBaseShape base shape.
125   /// \return true if edge inside the face.
126   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
127     const std::shared_ptr<GeomAPI_Shape> theSubShape,
128     const std::shared_ptr<GeomAPI_Shape> theBaseShape);
129
130   /// \return true if theShape is valid.
131   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
132
133   /// \return outer wire for face. If theShape has different type returns empty pointer.
134   GEOMALGOAPI_EXPORT static
135     std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
136
137   /// \return true if edge is parallel to face.
138   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
139                                             const std::shared_ptr<GeomAPI_Face> theFace);
140
141   // Computes intersection point between the edge curve and a face surface (only one point, with
142   // preferences to point that belongs to edge and face boundaries.
143   /// \returns null if there is no intersection
144   GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Vertex> > intersect(
145     const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace,
146     const bool thePointsOutsideFace);
147
148   typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
149                    std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
150                              std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
151   /// \brief Performs the split of the shape by points.
152   /// \param[in] theBaseShape shape that should be divided.
153   /// \param[in] thePoints container of points to split
154   /// \param[out] theShapes container of shapes after split
155   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
156                                       const PointToRefsMap& thePointsInfo,
157                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
158
159   /// \brief Performs the split of the shape by points.
160   /// \param[in] theBaseShape shape that should be divided.
161   /// \param[in] thePoints container of points to split
162   /// \param[out] theShapes container of shapes after split
163   GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
164                                       const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
165                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
166
167   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
168                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
169                                     const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
170
171 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
172   /// \brief Returns a direction from a shape and an axis.
173   /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
174   /// \param[in] theAxis axis that serves as a direction for the dir
175   /// \return dir that builds from center of mass of the base shape and the axis
176   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
177                                     const std::shared_ptr<GeomAPI_Shape> theBaseShape,
178                                     const std::shared_ptr<GeomAPI_Ax1> theAxis);
179 #endif
180
181   /// \brief Re-approximate a wire to build a single edge
182   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
183       const std::shared_ptr<GeomAPI_Wire>& theWire);
184
185   /// \brief Get non-composite sub-shapes of the given shape.
186   /// \param[in] theShape shape that should be exploded
187   /// \return list of sub-shapes (vertices, edges, faces, solids)
188   GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);
189 };
190
191 #endif