Salome HOME
22c8867870bc64c40eb835092d90ecc918d406f4
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_ShapeTools.h
4 // Created:     3 August 2015
5 // Author:      Dmitry Bobylev
6
7 #ifndef GeomAlgoAPI_ShapeTools_H_
8 #define GeomAlgoAPI_ShapeTools_H_
9
10 #include "GeomAlgoAPI.h"
11
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_Vertex.h>
14
15 #include <set>
16
17 class GeomAPI_Edge;
18 class GeomAPI_Dir;
19 class GeomAPI_Face;
20 class GeomAPI_PlanarEdges;
21 class GeomAPI_Pln;
22 class GeomAPI_Pnt;
23
24 /// \class GeomAlgoAPI_ShapeTools
25 /// \ingroup DataAlgo
26 /// \brief Useful tools for working with shapes.
27 class GeomAlgoAPI_ShapeTools
28 {
29 public:
30   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
31   GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
32
33   /// \return the centre of mass of the current face.
34   /// The coordinates returned for the center of mass
35   /// are expressed in the absolute Cartesian coordinate system.
36   /// (This function works only for surfaces).
37   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
38     centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
39
40   /// \brief Combines faces with common edges to shells, or solids to compsolids.
41   /// \param[in] theCompound compound of shapes.
42   /// \param[in] theType type of combine.
43   /// \param[out] theCombinedShapes resulting shapes.
44   /// \param[out] theFreeShapes shapes that does not have common subshapes.
45   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
46     const std::shared_ptr<GeomAPI_Shape> theCompound,
47     const GeomAPI_Shape::ShapeType theType,
48     ListOfShape& theCombinedShapes,
49     ListOfShape& theFreeShapes);
50
51   /// \brief Groups shapes with shared topology to compounds.
52   /// \param[in] theCompound compound of shapes.
53   /// \return compound of compounds with shared topology.
54   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
55     groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
56
57   /// \brief Calculates bounding box for theShapes
58   /// \return list of eight points.
59   /// \param[in] theShapes list of shapes.
60   /// \param[in] theEnlarge enlarges bounding box size.
61   GEOMALGOAPI_EXPORT static
62     std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
63                                                             const double theEnlarge = 0.0);
64
65   /// \return infinite plane received from theFace plane.
66   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
67     faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
68
69   /// \brief Enlarges or reduces plane to fit bounding box.
70   /// \return plane that fits to bounding box.
71   /// \param[in] thePlane base plane.
72   /// \param[in] thePoints bounding box points (shoud be eight).
73   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
74     const std::shared_ptr<GeomAPI_Shape> thePlane,
75     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
76
77   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
78   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
79   /// Edge : theV1 is start and theV2 is end vertex;\n
80   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
81   /// contains no edges theV1 and theV2 are nullified.\n
82   /// If none of the above theV1 and theV2 are nullified.
83   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
84                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
85                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
86
87   /// \brief Creates faces with holes from wires.
88   /// \param[in] theWires base wires.
89   /// \param[out] theFaces resulting faces.
90   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
91                                                 const std::shared_ptr<GeomAPI_Dir> theDirection,
92                                                 const ListOfShape& theWires,
93                                                 ListOfShape& theFaces);
94
95   /// \brief Return a plane for list of shapes if they are all planar.
96   /// \param[in] theShapes shapes to find plane.
97   /// \return plane where all shapes lie or empty ptr if they not planar.
98   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
99
100   /// \brief Checks that vertex/edge is inside face or vertext inside wire.
101   /// \param[in] theSubShape shape that should be inside.
102   /// \param[in] theBaseShape base shape.
103   /// \return true if edge inside the face.
104   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
105     const std::shared_ptr<GeomAPI_Shape> theSubShape,
106     const std::shared_ptr<GeomAPI_Shape> theBaseShape);
107
108   /// \return true if theShape is valid.
109   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
110
111   /// \return outer wire for face. If theShape has different type returns empty pointer.
112   GEOMALGOAPI_EXPORT static
113     std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
114
115   /// \return true if edge is parallel to face.
116   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
117                                             const std::shared_ptr<GeomAPI_Face> theFace);
118
119   /// \brief Performs the split of the shape by points.
120   /// \param[in] theBaseShape shape that should be splitted.
121   /// \param[in] thePoints container of points to split
122   /// \param[out] theShapes container of shapes after split
123   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
124                                       const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
125                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
126
127
128   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
129                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
130                                     const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
131
132 };
133
134 #endif