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>
20 class GeomAPI_PlanarEdges;
24 /// \class GeomAlgoAPI_ShapeTools
26 /// \brief Useful tools for working with shapes.
27 class GeomAlgoAPI_ShapeTools
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
98 /// \return true if theShape is valid.
99 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
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);
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);
108 /// \brief Performs the split of the shape by points.
109 /// \param[in] theBaseShape shape that should be splitted.
110 /// \param[in] thePoints container of points to split
111 /// \param[out] theShapes container of shapes after split
112 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
113 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
114 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
117 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
118 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
119 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);