Salome HOME
Fixed Placement centering of faces (issue #1714)
[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. The coordinates returned for the center of mass
34   /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
35   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
36
37   /// \brief Combines faces with common edges to shells, or solids to compsolids.
38   /// \param[in] theCompound compound of shapes.
39   /// \param[in] theType type of combine.
40   /// \param[out] theCombinedShapes resulting shapes.
41   /// \param[out] theFreeShapes shapes that does not have common subshapes.
42   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
43                                                                          const GeomAPI_Shape::ShapeType theType,
44                                                                          ListOfShape& theCombinedShapes,
45                                                                          ListOfShape& theFreeShapes);
46
47   /// \brief Groups shapes with shared topology to compounds.
48   /// \param[in] theCompound compound of shapes.
49   /// \return compound of compounds with shared topology.
50   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
51
52   /// \brief Calculates bounding box for theShapes
53   /// \return list of eight points.
54   /// \param[in] theShapes list of shapes.
55   /// \param[in] theEnlarge enlarges bounding box size.
56   GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
57
58   /// \return infinite plane received from theFace plane.
59   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
60
61   /// \brief Enlarges or reduces plane to fit bounding box.
62   /// \return plane that fits to bounding box.
63   /// \param[in] thePlane base plane.
64   /// \param[in] thePoints bounding box points (shoud be eight).
65   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
66                                                                         const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
67
68   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
69   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
70   /// Edge : theV1 is start and theV2 is end vertex;\n
71   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
72   /// contains no edges theV1 and theV2 are nullified.\n
73   /// If none of the above theV1 and theV2 are nullified.
74   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
75                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
76                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
77
78   /// \brief Creates faces with holes from wires.
79   /// \param[in] theWires base wires.
80   /// \param[out] theFaces resulting faces.
81   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
82                                                     const std::shared_ptr<GeomAPI_Dir> theDirection,
83                                                     const ListOfShape& theWires,
84                                                     ListOfShape& theFaces);
85
86   /// \brief Return a plane for list of shapes if they are all planar.
87   /// \param[in] theShapes shapes to find plane.
88   /// \return plane where all shapes lie or empty ptr if they not planar.
89   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
90
91   /// \brief Checks that vertex/edge is inside face or vertext inside wire.
92   /// \param[in] theSubShape shape that should be inside.
93   /// \param[in] theBaseShape base shape.
94   /// \return true if edge inside the face.
95   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
96                                                        const std::shared_ptr<GeomAPI_Shape> theBaseShape);
97
98   /// \return true if theShape is valid.
99   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
100
101   /// \return outer wire for face. If theShape has different type returns empty pointer.
102   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
103
104   /// \return true if edge is parallel to face.
105   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
106                                             const std::shared_ptr<GeomAPI_Face> theFace);
107   /// \brief Performs the split of the shape by points.
108   /// \param[in] theBaseShape shape that should be splitted.
109   /// \param[in] thePoints container of points to split
110   /// \param[out] theShapes container of shapes after split
111   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
112                                             const std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
113                                             std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
114 };
115
116 #endif