1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_ShapeTools.h
4 // Created: 3 August 2015
5 // Author: Dmitry Bobylev
7 #ifndef GeomAlgoAPI_ShapeTools_H_
8 #define GeomAlgoAPI_ShapeTools_H_
10 #include "GeomAlgoAPI.h"
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_Vertex.h>
16 class GeomAPI_PlanarEdges;
20 /// \class GeomAlgoAPI_ShapeTools
22 /// \brief Useful tools for working with shapes.
23 class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeTools
26 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
27 static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
29 /// \return the centre of mass of the current face. The coordinates returned for the center of mass
30 /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
31 static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
33 /// \brief Combines faces with common edges to shells, or solids to compsolids.
34 /// \param[in] theCompound compound of shapes.
35 /// \param[in] theType type of combine.
36 /// \param[out] theCombinedShapes resulting shapes.
37 /// \param[out] theFreeShapes shapes that does not have common subshapes.
38 static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
39 const GeomAPI_Shape::ShapeType theType,
40 ListOfShape& theCombinedShapes,
41 ListOfShape& theFreeShapes);
43 /// \brief Calculates bounding box for theShapes
44 /// \return list of eight points.
45 /// \param[in] theShapes list of shapes.
46 /// \param[in] theEnlarge enlarges bounding box size.
47 static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
49 /// \return infinite plane received from theFace plane.
50 static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
52 /// \brief Enlarges or reduces plane to fit bounding box.
53 /// \return plane that fits to bounding box.
54 /// \param[in] thePlane base plane.
55 /// \param[in] thePoints bounding box points (shoud be eight).
56 static std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
57 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
59 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
60 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
61 /// Edge : theV1 is start and theV2 is end vertex;\n
62 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
63 /// contains no edges theV1 and theV2 are nullified.\n
64 /// If none of the above theV1 and theV2 are nullified.
65 static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
66 std::shared_ptr<GeomAPI_Vertex>& theV1,
67 std::shared_ptr<GeomAPI_Vertex>& theV2);
69 /// \brief Creates faces with holes from wires.
70 /// \param[in] theWires base wires.
71 /// \param[out] theFaces resulting faces.
72 static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
73 const std::shared_ptr<GeomAPI_Dir> theDirection,
74 const ListOfShape& theWires,
75 ListOfShape& theFaces);
77 /// \brief Return a plane for list of shapes if they are all planar.
78 /// \param[in] theShapes shapes to find plane.
79 /// \return plane where all shapes lie or empty ptr if they not planar.
80 static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
82 /// \brief Checks that vertex/edge is inside face or vertext inside wire.
83 /// \param[in] theSubShape shape that should be inside.
84 /// \param[in] theBaseShape base shape.
85 /// \return true if edge inside the face.
86 static bool isSubShapeInShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
87 const std::shared_ptr<GeomAPI_Shape> theBaseShape);