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>
18 class GeomAPI_PlanarEdges;
22 /// \class GeomAlgoAPI_ShapeTools
24 /// \brief Useful tools for working with shapes.
25 class GeomAlgoAPI_ShapeTools
28 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
29 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
31 /// \return the centre of mass of the current face. The coordinates returned for the center of mass
32 /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
33 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
35 /// \brief Combines faces with common edges to shells, or solids to compsolids.
36 /// \param[in] theCompound compound of shapes.
37 /// \param[in] theType type of combine.
38 /// \param[out] theCombinedShapes resulting shapes.
39 /// \param[out] theFreeShapes shapes that does not have common subshapes.
40 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
41 const GeomAPI_Shape::ShapeType theType,
42 ListOfShape& theCombinedShapes,
43 ListOfShape& theFreeShapes);
45 /// \brief Groups shapes with shared topology to compounds.
46 /// \param[in] theCompound compound of shapes.
47 /// \return compound of compounds with shared topology.
48 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
50 /// \brief Calculates bounding box for theShapes
51 /// \return list of eight points.
52 /// \param[in] theShapes list of shapes.
53 /// \param[in] theEnlarge enlarges bounding box size.
54 GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
56 /// \return infinite plane received from theFace plane.
57 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
59 /// \brief Enlarges or reduces plane to fit bounding box.
60 /// \return plane that fits to bounding box.
61 /// \param[in] thePlane base plane.
62 /// \param[in] thePoints bounding box points (shoud be eight).
63 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
64 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
66 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
67 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
68 /// Edge : theV1 is start and theV2 is end vertex;\n
69 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
70 /// contains no edges theV1 and theV2 are nullified.\n
71 /// If none of the above theV1 and theV2 are nullified.
72 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
73 std::shared_ptr<GeomAPI_Vertex>& theV1,
74 std::shared_ptr<GeomAPI_Vertex>& theV2);
76 /// \brief Creates faces with holes from wires.
77 /// \param[in] theWires base wires.
78 /// \param[out] theFaces resulting faces.
79 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
80 const std::shared_ptr<GeomAPI_Dir> theDirection,
81 const ListOfShape& theWires,
82 ListOfShape& theFaces);
84 /// \brief Return a plane for list of shapes if they are all planar.
85 /// \param[in] theShapes shapes to find plane.
86 /// \return plane where all shapes lie or empty ptr if they not planar.
87 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
89 /// \brief Checks that vertex/edge is inside face or vertext inside wire.
90 /// \param[in] theSubShape shape that should be inside.
91 /// \param[in] theBaseShape base shape.
92 /// \return true if edge inside the face.
93 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
94 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
96 /// \return true if theShape is valid.
97 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
99 /// \return outer wire for face. If theShape has different type returns empty pointer.
100 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
102 /// \return true if edge is parallel to face.
103 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
104 const std::shared_ptr<GeomAPI_Face> theFace);