Version: 9.16.0
GEOMUtils.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23#ifndef _GEOMUtils_HXX_
24#define _GEOMUtils_HXX_
25
26#include <Standard_Macro.hxx>
27#include <TopoDS_Shape.hxx>
28#include <TopoDS_Vertex.hxx>
29
30#include <TopTools_ListOfShape.hxx>
31
32#include <TopAbs.hxx>
33
34#include <gp_Ax3.hxx>
35#include <gp_Vec.hxx>
36
37#include <V3d_View.hxx>
38
39#include <NCollection_DataMap.hxx>
40
41#include <functional>
42
43#include <map>
44#include <vector>
45#include <string>
46#include <utility>
47
48class Bnd_Box;
49
50inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
51{
52 return S1.IsSame(S2);
53}
54
55namespace GEOMUtils
56{
57
65 CC_LE
66 };
67
68 typedef std::vector<std::string> NodeLinks;
69 typedef std::map<std::string, NodeLinks> LevelInfo;
70 typedef std::vector<LevelInfo> LevelsList;
71 typedef std::map<std::string,std::pair<LevelsList,LevelsList> > TreeModel;
72
92 Standard_EXPORT std::pair<double, double> ShapeToDouble (const TopoDS_Shape& theShape,
93 bool isOldSorting = false);
94
102 Standard_EXPORT gp_Ax3 GetPosition (const TopoDS_Shape& theShape);
103
112 Standard_EXPORT gp_Vec GetVector (const TopoDS_Shape& theShape,
113 Standard_Boolean doConsiderOrientation);
114
119 struct CompareShapes //: public std::binary_function<TopoDS_Shape, TopoDS_Shape, bool>
120 {
121 CompareShapes (bool isOldSorting)
122 : myIsOldSorting(isOldSorting) {}
123
124 bool operator() (const TopoDS_Shape& lhs, const TopoDS_Shape& rhs);
125
126 typedef NCollection_DataMap<TopoDS_Shape, std::pair<double, double> > GEOMUtils_DataMapOfShapeDouble;
129 };
130
134 Standard_EXPORT void SortShapes (TopTools_ListOfShape& SL,
135 const Standard_Boolean isOldSorting = Standard_True);
136
145 Standard_EXPORT TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid);
146
155 Standard_EXPORT void AddSimpleShapes (const TopoDS_Shape& theShape,
156 TopTools_ListOfShape& theList);
157
163 Standard_EXPORT TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape);
164
174 Standard_EXPORT TopAbs_ShapeEnum GetCommonShapeType (const TopoDS_Shape& theShape);
175
183 Standard_EXPORT TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape,
184 const TopoDS_Vertex& thePoint);
185
193 Standard_EXPORT Standard_Boolean PreciseBoundingBox(const TopoDS_Shape &theShape, Bnd_Box &theBox);
194
204 Standard_EXPORT Standard_Real GetMinDistance(const TopoDS_Shape& theShape1,
205 const TopoDS_Shape& theShape2,
206 gp_Pnt& thePnt1, gp_Pnt& thePnt2);
207
218 Standard_EXPORT gp_Pnt ProjectPointOnFace(const gp_Pnt& thePoint,
219 const TopoDS_Shape& theFace,
220 double& theU, double& theV,
221 const double theTol = 1e-04);
222
231 Standard_EXPORT Standard_Real DistanceToProjectionOnFace(const gp_Pnt& thePoint,
232 const TopoDS_Shape& theFace,
233 const double theTol = 1e-04);
234
243 Standard_EXPORT gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView );
244
251 Standard_EXPORT void ConvertTreeToString( const TreeModel& tree,
252 std::string& dependencyStr );
253
260 Standard_EXPORT void ConvertStringToTree( const std::string& dependencyStr,
261 TreeModel& tree );
262
272 Standard_EXPORT bool CheckShape( TopoDS_Shape& shape,
273 bool checkGeometry = false,
274 bool isExact = false );
275
283 Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape);
284
300 Standard_EXPORT bool FixShapeTolerance( TopoDS_Shape& shape,
301 TopAbs_ShapeEnum type = TopAbs_SHAPE,
302 Standard_Real tolerance = Precision::Confusion(),
303 bool checkGeometry = false,
304 bool isExactAdjust = false );
305
318 Standard_EXPORT bool FixShapeCurves( TopoDS_Shape& shape );
319
326 Standard_EXPORT bool Write( const TopoDS_Shape& shape,
327 const char* fileName );
328
339 Standard_EXPORT TopoDS_Shape ReduceCompound( const TopoDS_Shape& shape );
340
345 Standard_EXPORT double DefaultDeflection();
346
361 Standard_EXPORT bool MeshShape( const TopoDS_Shape theShape,
362 const double theDeflection = DefaultDeflection(),
363 const bool theForced = true,
364 const double theAngleDeflection = 0.5,
365 const bool isRelative = true,
366 const bool doPostCheck = false);
367
373 Standard_EXPORT bool CheckTriangulation (const TopoDS_Shape& theShape);
374
385 Standard_EXPORT bool IsOpenPath(const TopoDS_Shape &theShape);
386
401 Standard_EXPORT int CompareToleranceValues(const double theTolShape,
402 const double theTolRef);
403
413 Standard_EXPORT bool IsFitCondition(const ComparisonCondition theCondition,
414 const double theTolShape,
415 const double theTolRef);
416
417}
418
419#endif
Handle(TColStd_HSequenceOfTransient) AdvancedEngine_IOperations
Create a T-shape object with specified caracteristics for the main and the incident pipes (radius,...
Definition: AdvancedEngine_IOperations.cxx:1907
Standard_Boolean IsEqual(const TopoDS_Shape &S1, const TopoDS_Shape &S2)
Definition: GEOMUtils.hxx:50
Definition: GEOMUtils.hxx:56
Standard_EXPORT bool CheckTriangulation(const TopoDS_Shape &theShape)
Build a triangulation on theShape if it is absent.
Definition: GEOMUtils.cxx:1134
Standard_EXPORT bool Write(const TopoDS_Shape &shape, const char *fileName)
Write shape to the BREP file.
Definition: GEOMUtils.cxx:1082
Standard_EXPORT int CompareToleranceValues(const double theTolShape, const double theTolRef)
This function compares two tolerances.
Definition: GEOMUtils.cxx:1195
Standard_EXPORT TopAbs_ShapeEnum GetTypeOfSimplePart(const TopoDS_Shape &theShape)
Return type of shape for explode. In case of compound it will be a type of its first sub shape.
Definition: GEOMUtils.cxx:578
Standard_EXPORT TopoDS_Shape ReduceCompound(const TopoDS_Shape &shape)
Extract single SOLID from COMPSOLID or COMPOUND.
Definition: GEOMUtils.cxx:1087
Standard_EXPORT bool FixShapeTolerance(TopoDS_Shape &shape, TopAbs_ShapeEnum type=TopAbs_SHAPE, Standard_Real tolerance=Precision::Confusion(), bool checkGeometry=false, bool isExactAdjust=false)
Limit shape tolerance to the given value.
Definition: GEOMUtils.cxx:1014
Standard_EXPORT void ConvertTreeToString(const TreeModel &tree, std::string &dependencyStr)
Convert dependency tree data to the string representation.
Definition: GEOMUtils.cxx:939
Standard_EXPORT TopoDS_Shape GetEdgeNearPoint(const TopoDS_Shape &theShape, const TopoDS_Vertex &thePoint)
Find an edge of theShape, closest to thePoint.
Definition: GEOMUtils.cxx:627
Standard_EXPORT gp_Ax3 GetPosition(const TopoDS_Shape &theShape)
Get Local Coordinate System, corresponding to the given shape.
Definition: GEOMUtils.cxx:236
Standard_EXPORT gp_Pnt ConvertClickToPoint(int x, int y, Handle(V3d_View) theView)
Returns the point clicked in 3D view.
Definition: GEOMUtils.cxx:913
Standard_EXPORT double DefaultDeflection()
Get default deflection coefficient used for triangulation.
Definition: GEOMUtils.cxx:1110
std::vector< std::string > NodeLinks
Definition: GEOMUtils.hxx:68
Standard_EXPORT void ConvertStringToTree(const std::string &dependencyStr, TreeModel &tree)
Restore dependency tree data from the string representation.
Definition: GEOMUtils.cxx:959
Standard_EXPORT std::pair< double, double > ShapeToDouble(const TopoDS_Shape &theShape, bool isOldSorting=false)
Compute numerical functor for the shape.
Definition: GEOMUtils.cxx:196
Standard_EXPORT gp_Pnt ProjectPointOnFace(const gp_Pnt &thePoint, const TopoDS_Shape &theFace, double &theU, double &theV, const double theTol=1e-04)
Computes normal projection of thePoint to theFace.
Definition: GEOMUtils.cxx:794
Standard_EXPORT void SortShapes(TopTools_ListOfShape &SL, const Standard_Boolean isOldSorting=Standard_True)
Sort shapes by their centers of mass, using formula X*999 + Y*99 + Z*0.9.
Definition: GEOMUtils.cxx:385
std::map< std::string, std::pair< LevelsList, LevelsList > > TreeModel
Definition: GEOMUtils.hxx:71
Standard_EXPORT Standard_Boolean PreciseBoundingBox(const TopoDS_Shape &theShape, Bnd_Box &theBox)
Compute precise bounding box of the shape based on the rough bounding box.
Definition: GEOMUtils.cxx:696
Standard_EXPORT bool CheckShape(TopoDS_Shape &shape, bool checkGeometry=false, bool isExact=false)
Check shape.
Definition: GEOMUtils.cxx:980
Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape)
Check boolean and partition operations arguments.
Definition: GEOMUtils.cxx:991
Standard_EXPORT Standard_Real DistanceToProjectionOnFace(const gp_Pnt &thePoint, const TopoDS_Shape &theFace, const double theTol=1e-04)
Computes distance from thePoint to its normal projection on theFace.
Definition: GEOMUtils.cxx:855
Standard_EXPORT bool IsFitCondition(const ComparisonCondition theCondition, const double theTolShape, const double theTolRef)
Check if the comarison of tolerances fit the condition.
Definition: GEOMUtils.cxx:1216
Standard_EXPORT bool FixShapeCurves(TopoDS_Shape &shape)
Fix curves of the given shape.
Definition: GEOMUtils.cxx:1030
std::vector< LevelInfo > LevelsList
Definition: GEOMUtils.hxx:70
Standard_EXPORT bool IsOpenPath(const TopoDS_Shape &theShape)
Check if the shape is not a closed wire or edge.
Definition: GEOMUtils.cxx:1144
Standard_EXPORT gp_Vec GetVector(const TopoDS_Shape &theShape, Standard_Boolean doConsiderOrientation)
Get vector, defined by the given edge.
Definition: GEOMUtils.cxx:296
Standard_EXPORT TopAbs_ShapeEnum GetCommonShapeType(const TopoDS_Shape &theShape)
Get the common shape type of the top-level shapes contained in the given shape.
Definition: GEOMUtils.cxx:599
Standard_EXPORT Standard_Real GetMinDistance(const TopoDS_Shape &theShape1, const TopoDS_Shape &theShape2, gp_Pnt &thePnt1, gp_Pnt &thePnt2)
Computes minumal distance between two shapes.
Definition: GEOMUtils.cxx:764
std::map< std::string, NodeLinks > LevelInfo
Definition: GEOMUtils.hxx:69
Standard_EXPORT void AddSimpleShapes(const TopoDS_Shape &theShape, TopTools_ListOfShape &theList)
Recursively extract all shapes from compounds and compsolids of the given shape into theList.
Definition: GEOMUtils.cxx:550
Standard_EXPORT TopoDS_Shape CompsolidToCompound(const TopoDS_Shape &theCompsolid)
Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
Definition: GEOMUtils.cxx:523
ComparisonCondition
This enumeration represents comparison conditions.
Definition: GEOMUtils.hxx:61
@ CC_LE
Less then or equal to.
Definition: GEOMUtils.hxx:65
@ CC_LT
Less then.
Definition: GEOMUtils.hxx:64
@ CC_GT
Greater then.
Definition: GEOMUtils.hxx:62
@ CC_GE
Greater then or equal to.
Definition: GEOMUtils.hxx:63
Standard_EXPORT bool MeshShape(const TopoDS_Shape theShape, const double theDeflection=DefaultDeflection(), const bool theForced=true, const double theAngleDeflection=0.5, const bool isRelative=true, const bool doPostCheck=false)
Generate triangulation for theShape.
Definition: GEOMUtils.cxx:1119
Sort shapes in the list by their coordinates.
Definition: GEOMUtils.hxx:120
NCollection_DataMap< TopoDS_Shape, std::pair< double, double > > GEOMUtils_DataMapOfShapeDouble
Definition: GEOMUtils.hxx:126
bool operator()(const TopoDS_Shape &lhs, const TopoDS_Shape &rhs)
Definition: GEOMUtils.cxx:325
GEOMUtils_DataMapOfShapeDouble myMap
Definition: GEOMUtils.hxx:127
bool myIsOldSorting
Definition: GEOMUtils.hxx:128
CompareShapes(bool isOldSorting)
Definition: GEOMUtils.hxx:121