1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _IntTools_Context_HeaderFile
16 #define _IntTools_Context_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_Type.hxx>
21 #include <NCollection_BaseAllocator.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <TopTools_ShapeMapHasher.hxx>
24 #include <Standard_Integer.hxx>
25 #include <Standard_Real.hxx>
26 #include <Precision.hxx>
27 #include <Standard_Transient.hxx>
28 #include <TopAbs_State.hxx>
29 #include <Standard_Boolean.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <TColStd_MapTransientHasher.hxx>
32 class IntTools_FClass2d;
34 class GeomAPI_ProjectPointOnSurf;
35 class GeomAPI_ProjectPointOnCurve;
38 class IntTools_SurfaceRangeLocalizeData;
39 class BRepClass3d_SolidClassifier;
41 class Geom2dHatch_Hatcher;
50 //! The intersection Context contains geometrical
51 //! and topological toolkit (classifiers, projectors, etc).
52 //! The intersection Context is for caching the tools
53 //! to increase the performance.
54 class IntTools_Context : public Standard_Transient
59 Standard_EXPORT IntTools_Context();
60 Standard_EXPORT virtual ~IntTools_Context();
62 Standard_EXPORT IntTools_Context(const Handle(NCollection_BaseAllocator)& theAllocator);
65 //! Returns a reference to point classifier
67 Standard_EXPORT IntTools_FClass2d& FClass2d (const TopoDS_Face& aF);
70 //! Returns a reference to point projector
72 Standard_EXPORT GeomAPI_ProjectPointOnSurf& ProjPS (const TopoDS_Face& aF);
75 //! Returns a reference to point projector
77 Standard_EXPORT GeomAPI_ProjectPointOnCurve& ProjPC (const TopoDS_Edge& aE);
80 //! Returns a reference to point projector
82 Standard_EXPORT GeomAPI_ProjectPointOnCurve& ProjPT (const Handle(Geom_Curve)& aC);
85 //! Returns a reference to surface localization data
87 Standard_EXPORT IntTools_SurfaceRangeLocalizeData& SurfaceData (const TopoDS_Face& aF);
90 //! Returns a reference to solid classifier
92 Standard_EXPORT BRepClass3d_SolidClassifier& SolidClassifier (const TopoDS_Solid& aSolid);
95 //! Returns a reference to 2D hatcher
97 Standard_EXPORT Geom2dHatch_Hatcher& Hatcher (const TopoDS_Face& aF);
99 //! Returns a reference to surface adaptor for given face
100 Standard_EXPORT BRepAdaptor_Surface& SurfaceAdaptor (const TopoDS_Face& theFace);
102 //! Builds and stores an Oriented Bounding Box for the shape.
103 //! Returns a reference to OBB.
104 Standard_EXPORT Bnd_OBB& OBB(const TopoDS_Shape& theShape,
105 const Standard_Real theFuzzyValue = Precision::Confusion());
107 //! Computes the boundaries of the face using surface adaptor
108 Standard_EXPORT void UVBounds (const TopoDS_Face& theFace,
112 Standard_Real& VMax);
114 //! Computes parameter of the Point theP on
116 //! Returns zero if the distance between point
117 //! and edge is less than sum of tolerance value of edge and theTopP,
118 //! otherwise and for following conditions returns
120 //! 1. the edge is degenerated (-1)
121 //! 2. the edge does not contain 3d curve and pcurves (-2)
122 //! 3. projection algorithm failed (-3)
123 Standard_EXPORT Standard_Integer ComputePE (const gp_Pnt& theP, const Standard_Real theTolP,
124 const TopoDS_Edge& theE, Standard_Real& theT,
125 Standard_Real& theDist);
128 //! Computes parameter of the vertex aV on
129 //! the edge aE and correct tolerance value for
130 //! the vertex on the edge.
131 //! Returns zero if the distance between vertex
132 //! and edge is less than sum of tolerances and the fuzzy value,
133 //! otherwise and for following conditions returns
134 //! negative value: <br>
135 //! 1. the edge is degenerated (-1) <br>
136 //! 2. the edge does not contain 3d curve and pcurves (-2) <br>
137 //! 3. projection algorithm failed (-3)
138 Standard_EXPORT Standard_Integer ComputeVE (const TopoDS_Vertex& theV,
139 const TopoDS_Edge& theE,
141 Standard_Real& theTol,
142 const Standard_Real theFuzz = Precision::Confusion());
145 //! Computes UV parameters of the vertex aV on face aF
146 //! and correct tolerance value for the vertex on the face.
147 //! Returns zero if the distance between vertex and face is
148 //! less than or equal the sum of tolerances and the fuzzy value
149 //! and the projection point lays inside boundaries of the face.
150 //! For following conditions returns negative value <br>
151 //! 1. projection algorithm failed (-1) <br>
152 //! 2. distance is more than sum of tolerances (-2) <br>
153 //! 3. projection point out or on the boundaries of face (-3)
154 Standard_EXPORT Standard_Integer ComputeVF (const TopoDS_Vertex& theVertex,
155 const TopoDS_Face& theFace,
158 Standard_Real& theTol,
159 const Standard_Real theFuzz = Precision::Confusion());
162 //! Returns the state of the point aP2D
163 //! relative to face aF
164 Standard_EXPORT TopAbs_State StatePointFace (const TopoDS_Face& aF, const gp_Pnt2d& aP2D);
167 //! Returns true if the point aP2D is
168 //! inside the boundaries of the face aF,
169 //! otherwise returns false
170 Standard_EXPORT Standard_Boolean IsPointInFace (const TopoDS_Face& aF, const gp_Pnt2d& aP2D);
173 //! Returns true if the point aP2D is
174 //! inside the boundaries of the face aF,
175 //! otherwise returns false
176 Standard_EXPORT Standard_Boolean IsPointInFace (const gp_Pnt& aP3D, const TopoDS_Face& aF, const Standard_Real aTol);
179 //! Returns true if the point aP2D is
180 //! inside or on the boundaries of aF
181 Standard_EXPORT Standard_Boolean IsPointInOnFace (const TopoDS_Face& aF, const gp_Pnt2d& aP2D);
184 //! Returns true if the distance between point aP3D
185 //! and face aF is less or equal to tolerance aTol
186 //! and projection point is inside or on the boundaries
188 Standard_EXPORT Standard_Boolean IsValidPointForFace (const gp_Pnt& aP3D, const TopoDS_Face& aF, const Standard_Real aTol);
191 //! Returns true if IsValidPointForFace returns true
192 //! for both face aF1 and aF2
193 Standard_EXPORT Standard_Boolean IsValidPointForFaces (const gp_Pnt& aP3D, const TopoDS_Face& aF1, const TopoDS_Face& aF2, const Standard_Real aTol);
196 //! Returns true if IsValidPointForFace returns true
197 //! for some 3d point that lay on the curve aIC bounded by
198 //! parameters aT1 and aT2
199 Standard_EXPORT Standard_Boolean IsValidBlockForFace (const Standard_Real aT1, const Standard_Real aT2, const IntTools_Curve& aIC, const TopoDS_Face& aF, const Standard_Real aTol);
202 //! Returns true if IsValidBlockForFace returns true
203 //! for both faces aF1 and aF2
204 Standard_EXPORT Standard_Boolean IsValidBlockForFaces (const Standard_Real aT1, const Standard_Real aT2, const IntTools_Curve& aIC, const TopoDS_Face& aF1, const TopoDS_Face& aF2, const Standard_Real aTol);
207 //! Computes parameter of the vertex aV on
209 //! Returns true if the distance between vertex and
210 //! curve is less than sum of tolerance of aV and aTolC,
211 //! otherwise or if projection algorithm failed
212 //! returns false (in this case aT isn't significant)
213 Standard_EXPORT Standard_Boolean IsVertexOnLine (const TopoDS_Vertex& aV, const IntTools_Curve& aIC, const Standard_Real aTolC, Standard_Real& aT);
216 //! Computes parameter of the vertex aV on
218 //! Returns true if the distance between vertex and
219 //! curve is less than sum of tolerance of aV and aTolC,
220 //! otherwise or if projection algorithm failed
221 //! returns false (in this case aT isn't significant)
222 Standard_EXPORT Standard_Boolean IsVertexOnLine (const TopoDS_Vertex& aV, const Standard_Real aTolV, const IntTools_Curve& aIC, const Standard_Real aTolC, Standard_Real& aT);
225 //! Computes parameter of the point aP on
227 //! Returns false if projection algorithm failed
228 //! other wiese returns true.
229 Standard_EXPORT Standard_Boolean ProjectPointOnEdge (const gp_Pnt& aP, const TopoDS_Edge& aE, Standard_Real& aT);
231 Standard_EXPORT Bnd_Box& BndBox (const TopoDS_Shape& theS);
233 //! Returns true if the solid <theFace> has
235 Standard_EXPORT Standard_Boolean IsInfiniteFace (const TopoDS_Face& theFace);
237 //! Sets tolerance to be used for projection of point on surface.
238 //! Clears map of already cached projectors in order to maintain
239 //! correct value for all projectors
240 Standard_EXPORT void SetPOnSProjectionTolerance (const Standard_Real theValue);
244 DEFINE_STANDARD_RTTIEXT(IntTools_Context,Standard_Transient)
248 Handle(NCollection_BaseAllocator) myAllocator;
249 NCollection_DataMap<TopoDS_Shape, IntTools_FClass2d*, TopTools_ShapeMapHasher> myFClass2dMap;
250 NCollection_DataMap<TopoDS_Shape, GeomAPI_ProjectPointOnSurf*, TopTools_ShapeMapHasher> myProjPSMap;
251 NCollection_DataMap<TopoDS_Shape, GeomAPI_ProjectPointOnCurve*, TopTools_ShapeMapHasher> myProjPCMap;
252 NCollection_DataMap<TopoDS_Shape, BRepClass3d_SolidClassifier*, TopTools_ShapeMapHasher> mySClassMap;
253 NCollection_DataMap<Handle(Geom_Curve), GeomAPI_ProjectPointOnCurve*, TColStd_MapTransientHasher> myProjPTMap;
254 NCollection_DataMap<TopoDS_Shape, Geom2dHatch_Hatcher*, TopTools_ShapeMapHasher> myHatcherMap;
255 NCollection_DataMap<TopoDS_Shape, IntTools_SurfaceRangeLocalizeData*, TopTools_ShapeMapHasher> myProjSDataMap;
256 NCollection_DataMap<TopoDS_Shape, Bnd_Box*, TopTools_ShapeMapHasher> myBndBoxDataMap;
257 NCollection_DataMap<TopoDS_Shape, BRepAdaptor_Surface*, TopTools_ShapeMapHasher> mySurfAdaptorMap;
258 NCollection_DataMap<TopoDS_Shape, Bnd_OBB*, TopTools_ShapeMapHasher> myOBBMap; // Map of oriented bounding boxes
259 Standard_Integer myCreateFlag;
260 Standard_Real myPOnSTolerance;
265 //! Clears map of already cached projectors.
266 Standard_EXPORT void clearCachedPOnSProjectors();
270 DEFINE_STANDARD_HANDLE(IntTools_Context, Standard_Transient)
272 #endif // _IntTools_Context_HeaderFile