X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeTools.h;h=55ae6fb78792fe6910f97d9d2531446c2f83bac6;hb=4c86b629d1bf8daa737f90b64e934c7bd22f6525;hp=6a1da0e237e0b928c7c83359714a935b12c6cdab;hpb=ded1e8998ec9d6d57f5a5a122c4abced86874273;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index 6a1da0e23..55ae6fb78 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_ShapeTools.h -// Created: 3 August 2015 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #ifndef GeomAlgoAPI_ShapeTools_H_ #define GeomAlgoAPI_ShapeTools_H_ @@ -11,15 +24,23 @@ #include #include - +#include +#include #include +#ifdef WIN32 +#include +#endif +class GeomAPI_Ax1; class GeomAPI_Edge; class GeomAPI_Dir; class GeomAPI_Face; class GeomAPI_PlanarEdges; class GeomAPI_Pln; class GeomAPI_Pnt; +class GeomAPI_Wire; +class GeomDataAPI_Point2D; +class ModelAPI_Object; /// \class GeomAlgoAPI_ShapeTools /// \ingroup DataAlgo @@ -27,43 +48,87 @@ class GeomAPI_Pnt; class GeomAlgoAPI_ShapeTools { public: + /// \return the lenth of the edges of the current shape or 0.0 if it can be computed. + GEOMALGOAPI_EXPORT static double length(const std::shared_ptr theShape); + /// \return the total volume of the solids of the current shape or 0.0 if it can be computed. GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr theShape); - /// \return the centre of mass of the current face. The coordinates returned for the center of mass - /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces). - GEOMALGOAPI_EXPORT static std::shared_ptr centreOfMass(const std::shared_ptr theShape); + /// \return the total area of the faces of the current shape or 0.0 if it can be computed. + GEOMALGOAPI_EXPORT static double area(const std::shared_ptr theShape); + + /// indicate if two faces are continuous + /// with an angular tolerance used for G1 continuity to compare the angle between the normals + /// \param theFace1 the first face + /// \param theFace2 the second face + /// \param thePoint the point for the normal + /// \param theAngle the angular tolerance + /// \param theError error + GEOMALGOAPI_EXPORT static bool isContinuousFaces(const GeomShapePtr& theFace1, + const GeomShapePtr& theFace2, + const GeomPointPtr& thePoint, + const double & theAngle, + std::string& theError); + + /// \return the center of mass of the current face. + /// The coordinates returned for the center of mass + /// are expressed in the absolute Cartesian coordinate system. + /// (This function works only for surfaces). + GEOMALGOAPI_EXPORT static std::shared_ptr + centreOfMass(const std::shared_ptr theShape); + + /// \brief Obtain radius of cylindrical face. + /// Return negative value if the face is not a cylinder + GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr& theCylinder); + + /// \brief Calculate minimal distance between shapes + GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1, + const GeomShapePtr& theShape2); + GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1, + const GeomShapePtr& theShape2, + std::array & fromShape1To2); + + /// \brief Calculate maximal value of all possible distances between shapes. + /// The shapes can be two edges or two faces only. + GEOMALGOAPI_EXPORT static double shapeProximity(const GeomShapePtr& theShape1, + const GeomShapePtr& theShape2); /// \brief Combines faces with common edges to shells, or solids to compsolids. /// \param[in] theCompound compound of shapes. /// \param[in] theType type of combine. - /// \param[out] theCombinedShapes resulting shapes. - /// \param[out] theFreeShapes shapes that does not have common subshapes. - GEOMALGOAPI_EXPORT static std::shared_ptr combineShapes(const std::shared_ptr theCompound, - const GeomAPI_Shape::ShapeType theType, - ListOfShape& theCombinedShapes, - ListOfShape& theFreeShapes); + /// \param[out] theResults resulting shapes. + GEOMALGOAPI_EXPORT static std::shared_ptr combineShapes( + const std::shared_ptr theCompound, + const GeomAPI_Shape::ShapeType theType, ListOfShape& theResults); /// \brief Groups shapes with shared topology to compounds. /// \param[in] theCompound compound of shapes. /// \return compound of compounds with shared topology. - GEOMALGOAPI_EXPORT static std::shared_ptr groupSharedTopology(const std::shared_ptr theCompound); + GEOMALGOAPI_EXPORT static std::shared_ptr + groupSharedTopology(const std::shared_ptr theCompound); + + /// \brief Check group of shapes has shared sub-shapes of the given type + /// \param[in] theShapes list of shapes + /// \param[in] theShapeType type of sub-shapes to check + /// \return \c true if shared topology exists + GEOMALGOAPI_EXPORT static bool hasSharedTopology(const ListOfShape& theShapes, + const GeomAPI_Shape::ShapeType theShapeType); /// \brief Calculates bounding box for theShapes /// \return list of eight points. /// \param[in] theShapes list of shapes. /// \param[in] theEnlarge enlarges bounding box size. - GEOMALGOAPI_EXPORT static std::list > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0); - - /// \return infinite plane received from theFace plane. - GEOMALGOAPI_EXPORT static std::shared_ptr faceToInfinitePlane(const std::shared_ptr theFace); + GEOMALGOAPI_EXPORT static + std::list > getBoundingBox(const ListOfShape& theShapes, + const double theEnlarge = 0.0); /// \brief Enlarges or reduces plane to fit bounding box. /// \return plane that fits to bounding box. /// \param[in] thePlane base plane. - /// \param[in] thePoints bounding box points (shoud be eight). - GEOMALGOAPI_EXPORT static std::shared_ptr fitPlaneToBox(const std::shared_ptr thePlane, - const std::list >& thePoints); + /// \param[in] thePoints bounding box points (should be eight). + GEOMALGOAPI_EXPORT static std::shared_ptr fitPlaneToBox( + const std::shared_ptr thePlane, + const std::list >& thePoints); /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n /// Vertex: theV1 and theV2 are the same and equal to theShape;\n @@ -79,38 +144,102 @@ public: /// \param[in] theWires base wires. /// \param[out] theFaces resulting faces. GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr theOrigin, - const std::shared_ptr theDirection, - const ListOfShape& theWires, - ListOfShape& theFaces); + const std::shared_ptr theDirection, + const ListOfShape& theWires, + ListOfShape& theFaces); /// \brief Return a plane for list of shapes if they are all planar. /// \param[in] theShapes shapes to find plane. - /// \return plane where all shapes lie or empty ptr if they not planar. + /// \return plane where all shapes lie or empty pointer if they not planar. GEOMALGOAPI_EXPORT static std::shared_ptr findPlane(const ListOfShape& theShapes); - /// \brief Checks that vertex/edge is inside face or vertext inside wire. + /// \brief Checks that vertex/edge is inside face or vertex inside wire. /// \param[in] theSubShape shape that should be inside. /// \param[in] theBaseShape base shape. /// \return true if edge inside the face. - GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr theSubShape, - const std::shared_ptr theBaseShape); + GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape( + const std::shared_ptr theSubShape, + const std::shared_ptr theBaseShape); /// \return true if theShape is valid. GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr theShape); /// \return outer wire for face. If theShape has different type returns empty pointer. - GEOMALGOAPI_EXPORT static std::shared_ptr getFaceOuterWire(const std::shared_ptr theFace); + GEOMALGOAPI_EXPORT static + std::shared_ptr getFaceOuterWire(const std::shared_ptr theFace); + + /// \return \c true if edges are tangent in the specified point + GEOMALGOAPI_EXPORT static bool isTangent(const std::shared_ptr theEdge1, + const std::shared_ptr theEdge2, + const std::shared_ptr theTgPoint); /// \return true if edge is parallel to face. GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr theEdge, const std::shared_ptr theFace); + + /// Computes intersection point between the edge curve and a face surface (only one point, with + /// preferences to point that belongs to edge and face boundaries. + /// \returns null if there is no intersection + GEOMALGOAPI_EXPORT static std::list > intersect( + const std::shared_ptr theEdge, const std::shared_ptr theFace); + + typedef std::map, + std::pair >, + std::list > > > PointToRefsMap; /// \brief Performs the split of the shape by points. - /// \param[in] theBaseShape shape that should be splitted. + /// \param[in] theBaseShape shape that should be divided. /// \param[in] thePoints container of points to split /// \param[out] theShapes container of shapes after split GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr& theBaseShape, - const std::set >& thePoints, - std::set >& theShapes); + const PointToRefsMap& thePointsInfo, + std::set >& theShapes); + + /// \brief Performs the split of the shape by points. + /// \param[in] theBaseShape shape that should be divided. + /// \param[in] thePoints container of points to split + /// \param[out] theShapes container of shapes after split + GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr& theBaseShape, + const std::list >& thePoints, + std::set >& theShapes); + + GEOMALGOAPI_EXPORT static std::shared_ptr findShape( + const std::list >& thePoints, + const std::set >& theShapes); + +#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS + /// \brief Returns a direction from a shape and an axis. + /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir. + /// \param[in] theAxis axis that serves as a direction for the dir + /// \return dir that builds from center of mass of the base shape and the axis + GEOMALGOAPI_EXPORT static std::shared_ptr buildDirFromAxisAndShape( + const std::shared_ptr theBaseShape, + const std::shared_ptr theAxis); +#endif + + /// \brief Re-approximate a wire to build a single edge + GEOMALGOAPI_EXPORT static std::shared_ptr wireToEdge( + const std::shared_ptr& theWire); + + /// \brief Get non-composite sub-shapes of the given shape. + /// \param[in] theShape shape that should be exploded + /// \return list of sub-shapes (vertices, edges, faces, solids) + GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape); + + /// \brief Calculate prism sizes to ensure that it passes through all objects + /// \param[in] theObjects objects to be joined/cutted by the prism + /// \param[in] theBaseShapes bases of the prism + /// \param[in] theDir direction of the prism + /// \param[out] theToSize upper offset of the prism + /// \param[out] theFromSize lower offset of the prism + GEOMALGOAPI_EXPORT static void computeThroughAll(const ListOfShape& theObjects, + const ListOfShape& theBaseShapes, + const std::shared_ptr theDir, + double& theToSize, double& theFromSize); + + /// \brief Get shared faces of a shape + /// \param[in] theShape shape that should be exploded + /// \return list of shared faces + GEOMALGOAPI_EXPORT static ListOfShape getSharedFaces(const GeomShapePtr& theShape); }; #endif