Version: 9.12.0
GEOMUtils.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 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 
48 class Bnd_Box;
49 
50 inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
51 {
52  return S1.IsSame(S2);
53 }
54 
55 namespace 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 bool CheckTriangulation (const TopoDS_Shape& theShape);
164 
170  Standard_EXPORT TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape);
171 
179  Standard_EXPORT TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape,
180  const TopoDS_Vertex& thePoint);
181 
189  Standard_EXPORT Standard_Boolean PreciseBoundingBox(const TopoDS_Shape &theShape, Bnd_Box &theBox);
190 
201  Standard_EXPORT Standard_Real GetMinDistanceSingular(const TopoDS_Shape& aSh1,
202  const TopoDS_Shape& aSh2,
203  gp_Pnt& Ptmp1, gp_Pnt& Ptmp2);
204 
214  Standard_EXPORT Standard_Real GetMinDistance(const TopoDS_Shape& theShape1,
215  const TopoDS_Shape& theShape2,
216  gp_Pnt& thePnt1, gp_Pnt& thePnt2);
217 
228  Standard_EXPORT gp_Pnt ProjectPointOnFace(const gp_Pnt& thePoint,
229  const TopoDS_Shape& theFace,
230  double& theU, double& theV,
231  const double theTol = 1e-04);
232 
241  Standard_EXPORT gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView );
242 
249  Standard_EXPORT void ConvertTreeToString( const TreeModel& tree,
250  std::string& dependencyStr );
251 
258  Standard_EXPORT void ConvertStringToTree( const std::string& dependencyStr,
259  TreeModel& tree );
260 
269  Standard_EXPORT bool CheckShape( TopoDS_Shape& shape, bool checkGeometry = false );
270 
278  Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape);
279 
295  Standard_EXPORT bool FixShapeTolerance( TopoDS_Shape& shape,
296  TopAbs_ShapeEnum type,
297  Standard_Real tolerance = Precision::Confusion(),
298  bool checkGeometry = false );
299 
304  Standard_EXPORT bool FixShapeTolerance( TopoDS_Shape& shape,
305  Standard_Real tolerance = Precision::Confusion(),
306  bool checkGeometry = false );
307 
312  Standard_EXPORT bool FixShapeTolerance( TopoDS_Shape& shape,
313  bool checkGeometry );
314 
327  Standard_EXPORT bool FixShapeCurves( TopoDS_Shape& shape );
328 
335  Standard_EXPORT bool Write( const TopoDS_Shape& shape,
336  const char* fileName );
337 
348  Standard_EXPORT TopoDS_Shape ReduceCompound( const TopoDS_Shape& shape );
349 
357  Standard_EXPORT void MeshShape( const TopoDS_Shape shape,
358  double deflection, bool forced = true );
359 
364  Standard_EXPORT double DefaultDeflection();
365 
376  Standard_EXPORT bool IsOpenPath(const TopoDS_Shape &theShape);
377 
392  Standard_EXPORT int CompareToleranceValues(const double theTolShape,
393  const double theTolRef);
394 
404  Standard_EXPORT bool IsFitCondition(const ComparisonCondition theCondition,
405  const double theTolShape,
406  const double theTolRef);
407 
408 }
409 
410 #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:684
Standard_EXPORT bool Write(const TopoDS_Shape &shape, const char *fileName)
Write shape to the BREP file.
Definition: GEOMUtils.cxx:1265
Standard_EXPORT int CompareToleranceValues(const double theTolShape, const double theTolRef)
This function compares two tolerances.
Definition: GEOMUtils.cxx:1384
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:734
Standard_EXPORT TopoDS_Shape ReduceCompound(const TopoDS_Shape &shape)
Extract single SOLID from COMPSOLID or COMPOUND.
Definition: GEOMUtils.cxx:1270
Standard_EXPORT void ConvertTreeToString(const TreeModel &tree, std::string &dependencyStr)
Convert dependency tree data to the string representation.
Definition: GEOMUtils.cxx:1116
Standard_EXPORT TopoDS_Shape GetEdgeNearPoint(const TopoDS_Shape &theShape, const TopoDS_Vertex &thePoint)
Find an edge of theShape, closest to thePoint.
Definition: GEOMUtils.cxx:755
Standard_EXPORT Standard_Real GetMinDistanceSingular(const TopoDS_Shape &aSh1, const TopoDS_Shape &aSh2, gp_Pnt &Ptmp1, gp_Pnt &Ptmp2)
Computes minumal distance between two shapes for singular cases (workaround for bugs 19899,...
Definition: GEOMUtils.cxx:891
Standard_EXPORT gp_Ax3 GetPosition(const TopoDS_Shape &theShape)
Get Local Coordinate System, corresponding to the given shape.
Definition: GEOMUtils.cxx:342
Standard_EXPORT bool FixShapeTolerance(TopoDS_Shape &shape, TopAbs_ShapeEnum type, Standard_Real tolerance=Precision::Confusion(), bool checkGeometry=false)
Limit shape tolerance to the given value.
Definition: GEOMUtils.cxx:1187
Standard_EXPORT gp_Pnt ConvertClickToPoint(int x, int y, Handle(V3d_View) theView)
Returns the point clicked in 3D view.
Definition: GEOMUtils.cxx:1090
Standard_EXPORT double DefaultDeflection()
Get default deflection coefficient used for triangulation.
Definition: GEOMUtils.cxx:1324
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:1136
Standard_EXPORT std::pair< double, double > ShapeToDouble(const TopoDS_Shape &theShape, bool isOldSorting=false)
Compute numerical functor for the shape.
Definition: GEOMUtils.cxx:302
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:1030
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:491
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:824
Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape)
Check boolean and partition operations arguments.
Definition: GEOMUtils.cxx:1164
Standard_EXPORT bool CheckShape(TopoDS_Shape &shape, bool checkGeometry=false)
Check shape.
Definition: GEOMUtils.cxx:1157
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:1405
Standard_EXPORT bool FixShapeCurves(TopoDS_Shape &shape)
Fix curves of the given shape.
Definition: GEOMUtils.cxx:1213
std::vector< LevelInfo > LevelsList
Definition: GEOMUtils.hxx:70
Standard_EXPORT void MeshShape(const TopoDS_Shape shape, double deflection, bool forced=true)
Generate triangulation for the shape.
Definition: GEOMUtils.cxx:1289
Standard_EXPORT bool IsOpenPath(const TopoDS_Shape &theShape)
Check if the shape is not a closed wire or edge.
Definition: GEOMUtils.cxx:1333
Standard_EXPORT gp_Vec GetVector(const TopoDS_Shape &theShape, Standard_Boolean doConsiderOrientation)
Get vector, defined by the given edge.
Definition: GEOMUtils.cxx:402
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:961
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:656
Standard_EXPORT TopoDS_Shape CompsolidToCompound(const TopoDS_Shape &theCompsolid)
Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
Definition: GEOMUtils.cxx:629
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
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:431
GEOMUtils_DataMapOfShapeDouble myMap
Definition: GEOMUtils.hxx:127
bool myIsOldSorting
Definition: GEOMUtils.hxx:128
CompareShapes(bool isOldSorting)
Definition: GEOMUtils.hxx:121