1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef GeomAlgoAPI_ShapeTools_H_
21 #define GeomAlgoAPI_ShapeTools_H_
23 #include "GeomAlgoAPI.h"
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Vertex.h>
35 class GeomAPI_PlanarEdges;
39 class GeomDataAPI_Point2D;
40 class ModelAPI_Object;
42 /// \class GeomAlgoAPI_ShapeTools
44 /// \brief Useful tools for working with shapes.
45 class GeomAlgoAPI_ShapeTools
48 /// \return the lenth of the edges of the current shape or 0.0 if it can be computed.
49 GEOMALGOAPI_EXPORT static double length(const std::shared_ptr<GeomAPI_Shape> theShape);
51 /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
52 GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
54 /// \return the total area of the faces of the current shape or 0.0 if it can be computed.
55 GEOMALGOAPI_EXPORT static double area(const std::shared_ptr<GeomAPI_Shape> theShape);
57 /// \return the center of mass of the current face.
58 /// The coordinates returned for the center of mass
59 /// are expressed in the absolute Cartesian coordinate system.
60 /// (This function works only for surfaces).
61 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
62 centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
64 /// \brief Obtain radius of cylindrical face.
65 /// Return negative value if the face is not a cylinder
66 GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr<GeomAPI_Face>& theCylinder);
68 /// \brief Calculate minimal distance between shapes
69 GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
70 const GeomShapePtr& theShape2);
72 /// \brief Combines faces with common edges to shells, or solids to compsolids.
73 /// \param[in] theCompound compound of shapes.
74 /// \param[in] theType type of combine.
75 /// \param[out] theResults resulting shapes.
76 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
77 const std::shared_ptr<GeomAPI_Shape> theCompound,
78 const GeomAPI_Shape::ShapeType theType, ListOfShape& theResults);
80 /// \brief Groups shapes with shared topology to compounds.
81 /// \param[in] theCompound compound of shapes.
82 /// \return compound of compounds with shared topology.
83 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
84 groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
86 /// \brief Check group of shapes has shared sub-shapes of the given type
87 /// \param[in] theShapes list of shapes
88 /// \param[in] theShapeType type of sub-shapes to check
89 /// \return \c true if shared topology exists
90 GEOMALGOAPI_EXPORT static bool hasSharedTopology(const ListOfShape& theShapes,
91 const GeomAPI_Shape::ShapeType theShapeType);
93 /// \brief Calculates bounding box for theShapes
94 /// \return list of eight points.
95 /// \param[in] theShapes list of shapes.
96 /// \param[in] theEnlarge enlarges bounding box size.
97 GEOMALGOAPI_EXPORT static
98 std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
99 const double theEnlarge = 0.0);
101 /// \brief Enlarges or reduces plane to fit bounding box.
102 /// \return plane that fits to bounding box.
103 /// \param[in] thePlane base plane.
104 /// \param[in] thePoints bounding box points (should be eight).
105 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
106 const std::shared_ptr<GeomAPI_Shape> thePlane,
107 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
109 /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
110 /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
111 /// Edge : theV1 is start and theV2 is end vertex;\n
112 /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
113 /// contains no edges theV1 and theV2 are nullified.\n
114 /// If none of the above theV1 and theV2 are nullified.
115 GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
116 std::shared_ptr<GeomAPI_Vertex>& theV1,
117 std::shared_ptr<GeomAPI_Vertex>& theV2);
119 /// \brief Creates faces with holes from wires.
120 /// \param[in] theWires base wires.
121 /// \param[out] theFaces resulting faces.
122 GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
123 const std::shared_ptr<GeomAPI_Dir> theDirection,
124 const ListOfShape& theWires,
125 ListOfShape& theFaces);
127 /// \brief Return a plane for list of shapes if they are all planar.
128 /// \param[in] theShapes shapes to find plane.
129 /// \return plane where all shapes lie or empty pointer if they not planar.
130 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
132 /// \brief Checks that vertex/edge is inside face or vertex inside wire.
133 /// \param[in] theSubShape shape that should be inside.
134 /// \param[in] theBaseShape base shape.
135 /// \return true if edge inside the face.
136 GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
137 const std::shared_ptr<GeomAPI_Shape> theSubShape,
138 const std::shared_ptr<GeomAPI_Shape> theBaseShape);
140 /// \return true if theShape is valid.
141 GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
143 /// \return outer wire for face. If theShape has different type returns empty pointer.
144 GEOMALGOAPI_EXPORT static
145 std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
147 /// \return \c true if edges are tangent in the specified point
148 GEOMALGOAPI_EXPORT static bool isTangent(const std::shared_ptr<GeomAPI_Edge> theEdge1,
149 const std::shared_ptr<GeomAPI_Edge> theEdge2,
150 const std::shared_ptr<GeomAPI_Vertex> theTgPoint);
152 /// \return true if edge is parallel to face.
153 GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
154 const std::shared_ptr<GeomAPI_Face> theFace);
156 /// Computes intersection point between the edge curve and a face surface (only one point, with
157 /// preferences to point that belongs to edge and face boundaries.
158 /// \returns null if there is no intersection
159 GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Vertex> > intersect(
160 const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace);
162 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
163 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
164 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
165 /// \brief Performs the split of the shape by points.
166 /// \param[in] theBaseShape shape that should be divided.
167 /// \param[in] thePoints container of points to split
168 /// \param[out] theShapes container of shapes after split
169 GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
170 const PointToRefsMap& thePointsInfo,
171 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
173 /// \brief Performs the split of the shape by points.
174 /// \param[in] theBaseShape shape that should be divided.
175 /// \param[in] thePoints container of points to split
176 /// \param[out] theShapes container of shapes after split
177 GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
178 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
179 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
181 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
182 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
183 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
185 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
186 /// \brief Returns a direction from a shape and an axis.
187 /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
188 /// \param[in] theAxis axis that serves as a direction for the dir
189 /// \return dir that builds from center of mass of the base shape and the axis
190 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
191 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
192 const std::shared_ptr<GeomAPI_Ax1> theAxis);
195 /// \brief Re-approximate a wire to build a single edge
196 GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
197 const std::shared_ptr<GeomAPI_Wire>& theWire);
199 /// \brief Get non-composite sub-shapes of the given shape.
200 /// \param[in] theShape shape that should be exploded
201 /// \return list of sub-shapes (vertices, edges, faces, solids)
202 GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);
204 /// \brief Calculate prism sizes to ensure that it passes through all objects
205 /// \param[in] theObjects objects to be joined/cutted by the prism
206 /// \param[in] theBaseShapes bases of the prism
207 /// \param[in] theDir direction of the prism
208 /// \param[out] theToSize upper offset of the prism
209 /// \param[out] theFromSize lower offset of the prism
210 GEOMALGOAPI_EXPORT static void computeThroughAll(const ListOfShape& theObjects,
211 const ListOfShape& theBaseShapes,
212 const std::shared_ptr<GeomAPI_Dir> theDir,
213 double& theToSize, double& theFromSize);