]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
Salome HOME
fix coding style
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-2020  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 #include <map>
28 #include <set>
29 #ifdef WIN32
30  #include<array>
31 #endif WIN32
32
33 class GeomAPI_Ax1;
34 class GeomAPI_Edge;
35 class GeomAPI_Dir;
36 class GeomAPI_Face;
37 class GeomAPI_PlanarEdges;
38 class GeomAPI_Pln;
39 class GeomAPI_Pnt;
40 class GeomAPI_Wire;
41 class GeomDataAPI_Point2D;
42 class ModelAPI_Object;
43
44 /// \class GeomAlgoAPI_ShapeTools
45 /// \ingroup DataAlgo
46 /// \brief Useful tools for working with shapes.
47 class GeomAlgoAPI_ShapeTools
48 {
49 public:
50   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
51   GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
52
53   /// \return the total area of the faces of the current shape or 0.0 if it can be computed.
54   GEOMALGOAPI_EXPORT static double area(const std::shared_ptr<GeomAPI_Shape> theShape);
55
56   /// \return the center of mass of the current face.
57   /// The coordinates returned for the center of mass
58   /// are expressed in the absolute Cartesian coordinate system.
59   /// (This function works only for surfaces).
60   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
61     centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
62
63   /// \brief Obtain radius of cylindrical face.
64   ///        Return negative value if the face is not a cylinder
65   GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr<GeomAPI_Face>& theCylinder);
66
67   /// \brief Calculate minimal distance between shapes
68   GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
69                                                    const GeomShapePtr& theShape2);
70   GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
71                                                    const GeomShapePtr& theShape2,
72                                                    std::array<double, 3> & fromShape1To2);
73
74   /// \brief Combines faces with common edges to shells, or solids to compsolids.
75   /// \param[in] theCompound compound of shapes.
76   /// \param[in] theType type of combine.
77   /// \param[out] theResults resulting shapes.
78   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
79     const std::shared_ptr<GeomAPI_Shape> theCompound,
80     const GeomAPI_Shape::ShapeType theType, ListOfShape& theResults);
81
82   /// \brief Groups shapes with shared topology to compounds.
83   /// \param[in] theCompound compound of shapes.
84   /// \return compound of compounds with shared topology.
85   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
86     groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
87
88   /// \brief Check group of shapes has shared sub-shapes of the given type
89   /// \param[in] theShapes    list of shapes
90   /// \param[in] theShapeType type of sub-shapes to check
91   /// \return \c true if shared topology exists
92   GEOMALGOAPI_EXPORT static bool hasSharedTopology(const ListOfShape& theShapes,
93                                                    const GeomAPI_Shape::ShapeType theShapeType);
94
95   /// \brief Calculates bounding box for theShapes
96   /// \return list of eight points.
97   /// \param[in] theShapes list of shapes.
98   /// \param[in] theEnlarge enlarges bounding box size.
99   GEOMALGOAPI_EXPORT static
100     std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
101                                                             const double theEnlarge = 0.0);
102
103   /// \brief Enlarges or reduces plane to fit bounding box.
104   /// \return plane that fits to bounding box.
105   /// \param[in] thePlane base plane.
106   /// \param[in] thePoints bounding box points (should be eight).
107   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
108     const std::shared_ptr<GeomAPI_Shape> thePlane,
109     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
110
111   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
112   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
113   /// Edge : theV1 is start and theV2 is end vertex;\n
114   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
115   /// contains no edges theV1 and theV2 are nullified.\n
116   /// If none of the above theV1 and theV2 are nullified.
117   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
118                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
119                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
120
121   /// \brief Creates faces with holes from wires.
122   /// \param[in] theWires base wires.
123   /// \param[out] theFaces resulting faces.
124   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
125                                                 const std::shared_ptr<GeomAPI_Dir> theDirection,
126                                                 const ListOfShape& theWires,
127                                                 ListOfShape& theFaces);
128
129   /// \brief Return a plane for list of shapes if they are all planar.
130   /// \param[in] theShapes shapes to find plane.
131   /// \return plane where all shapes lie or empty pointer if they not planar.
132   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
133
134   /// \brief Checks that vertex/edge is inside face or vertex inside wire.
135   /// \param[in] theSubShape shape that should be inside.
136   /// \param[in] theBaseShape base shape.
137   /// \return true if edge inside the face.
138   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
139     const std::shared_ptr<GeomAPI_Shape> theSubShape,
140     const std::shared_ptr<GeomAPI_Shape> theBaseShape);
141
142   /// \return true if theShape is valid.
143   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
144
145   /// \return outer wire for face. If theShape has different type returns empty pointer.
146   GEOMALGOAPI_EXPORT static
147     std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
148
149   /// \return \c true if edges are tangent in the specified point
150   GEOMALGOAPI_EXPORT static bool isTangent(const std::shared_ptr<GeomAPI_Edge> theEdge1,
151                                            const std::shared_ptr<GeomAPI_Edge> theEdge2,
152                                            const std::shared_ptr<GeomAPI_Vertex> theTgPoint);
153
154   /// \return true if edge is parallel to face.
155   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
156                                             const std::shared_ptr<GeomAPI_Face> theFace);
157
158   /// Computes intersection point between the edge curve and a face surface (only one point, with
159   /// preferences to point that belongs to edge and face boundaries.
160   /// \returns null if there is no intersection
161   GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Vertex> > intersect(
162     const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace);
163
164   typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
165                    std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
166                              std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
167   /// \brief Performs the split of the shape by points.
168   /// \param[in] theBaseShape shape that should be divided.
169   /// \param[in] thePoints container of points to split
170   /// \param[out] theShapes container of shapes after split
171   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
172                                       const PointToRefsMap& thePointsInfo,
173                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
174
175   /// \brief Performs the split of the shape by points.
176   /// \param[in] theBaseShape shape that should be divided.
177   /// \param[in] thePoints container of points to split
178   /// \param[out] theShapes container of shapes after split
179   GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
180                                       const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
181                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
182
183   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
184                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
185                                     const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
186
187 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
188   /// \brief Returns a direction from a shape and an axis.
189   /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
190   /// \param[in] theAxis axis that serves as a direction for the dir
191   /// \return dir that builds from center of mass of the base shape and the axis
192   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
193                                     const std::shared_ptr<GeomAPI_Shape> theBaseShape,
194                                     const std::shared_ptr<GeomAPI_Ax1> theAxis);
195 #endif
196
197   /// \brief Re-approximate a wire to build a single edge
198   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
199       const std::shared_ptr<GeomAPI_Wire>& theWire);
200
201   /// \brief Get non-composite sub-shapes of the given shape.
202   /// \param[in] theShape shape that should be exploded
203   /// \return list of sub-shapes (vertices, edges, faces, solids)
204   GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);
205
206   /// \brief Calculate prism sizes to ensure that it passes through all objects
207   /// \param[in] theObjects objects to be joined/cutted by the prism
208   /// \param[in] theBaseShapes bases of the prism
209   /// \param[in] theDir direction of the prism
210   /// \param[out] theToSize upper offset of the prism
211   /// \param[out] theFromSize lower offset of the prism
212   GEOMALGOAPI_EXPORT static void computeThroughAll(const ListOfShape& theObjects,
213                                                    const ListOfShape& theBaseShapes,
214                                                    const std::shared_ptr<GeomAPI_Dir> theDir,
215                                                    double& theToSize, double& theFromSize);
216 };
217
218 #endif