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;
49 //! The intersection Context contains geometrical
50 //! and topological toolkit (classifiers, projectors, etc).
51 //! The intersection Context is for caching the tools
52 //! to increase the performance.
53 class IntTools_Context : public Standard_Transient
58 Standard_EXPORT IntTools_Context();
59 Standard_EXPORT virtual ~IntTools_Context();
61 Standard_EXPORT IntTools_Context(const Handle(NCollection_BaseAllocator)& theAllocator);
64 //! Returns a reference to point classifier
66 Standard_EXPORT IntTools_FClass2d& FClass2d (const TopoDS_Face& aF);
69 //! Returns a reference to point projector
71 Standard_EXPORT GeomAPI_ProjectPointOnSurf& ProjPS (const TopoDS_Face& aF);
74 //! Returns a reference to point projector
76 Standard_EXPORT GeomAPI_ProjectPointOnCurve& ProjPC (const TopoDS_Edge& aE);
79 //! Returns a reference to point projector
81 Standard_EXPORT GeomAPI_ProjectPointOnCurve& ProjPT (const Handle(Geom_Curve)& aC);
84 //! Returns a reference to surface localization data
86 Standard_EXPORT IntTools_SurfaceRangeLocalizeData& SurfaceData (const TopoDS_Face& aF);
89 //! Returns a reference to solid classifier
91 Standard_EXPORT BRepClass3d_SolidClassifier& SolidClassifier (const TopoDS_Solid& aSolid);
94 //! Returns a reference to 2D hatcher
96 Standard_EXPORT Geom2dHatch_Hatcher& Hatcher (const TopoDS_Face& aF);
98 //! Returns a reference to surface adaptor for given face
99 Standard_EXPORT BRepAdaptor_Surface& SurfaceAdaptor (const TopoDS_Face& theFace);
101 //! Computes the boundaries of the face using surface adaptor
102 Standard_EXPORT void UVBounds (const TopoDS_Face& theFace,
106 Standard_Real& VMax);
108 //! Computes parameter of the Point theP on
110 //! Returns zero if the distance between point
111 //! and edge is less than sum of tolerance value of edge and theTopP,
112 //! otherwise and for following conditions returns
114 //! 1. the edge is degenerated (-1)
115 //! 2. the edge does not contain 3d curve and pcurves (-2)
116 //! 3. projection algorithm failed (-3)
117 Standard_EXPORT Standard_Integer ComputePE (const gp_Pnt& theP, const Standard_Real theTolP,
118 const TopoDS_Edge& theE, Standard_Real& theT,
119 Standard_Real& theDist);
122 //! Computes parameter of the vertex aV on
123 //! the edge aE and correct tolerance value for
124 //! the vertex on the edge.
125 //! Returns zero if the distance between vertex
126 //! and edge is less than sum of tolerances and the fuzzy value,
127 //! otherwise and for following conditions returns
128 //! negative value: <br>
129 //! 1. the edge is degenerated (-1) <br>
130 //! 2. the edge does not contain 3d curve and pcurves (-2) <br>
131 //! 3. projection algorithm failed (-3)
132 Standard_EXPORT Standard_Integer ComputeVE (const TopoDS_Vertex& theV,
133 const TopoDS_Edge& theE,
135 Standard_Real& theTol,
136 const Standard_Real theFuzz = Precision::Confusion());
139 //! Computes UV parameters of the vertex aV on face aF
140 //! and correct tolerance value for the vertex on the face.
141 //! Returns zero if the distance between vertex and face is
142 //! less than or equal the sum of tolerances and the fuzzy value
143 //! and the projection point lays inside boundaries of the face.
144 //! For following conditions returns negative value <br>
145 //! 1. projection algorithm failed (-1) <br>
146 //! 2. distance is more than sum of tolerances (-2) <br>
147 //! 3. projection point out or on the boundaries of face (-3)
148 Standard_EXPORT Standard_Integer ComputeVF (const TopoDS_Vertex& theVertex,
149 const TopoDS_Face& theFace,
152 Standard_Real& theTol,
153 const Standard_Real theFuzz = Precision::Confusion());
156 //! Returns the state of the point aP2D
157 //! relative to face aF
158 Standard_EXPORT TopAbs_State StatePointFace (const TopoDS_Face& aF, const gp_Pnt2d& aP2D);
161 //! Returns true if the point aP2D is
162 //! inside the boundaries of the face aF,
163 //! otherwise returns false
164 Standard_EXPORT Standard_Boolean IsPointInFace (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 gp_Pnt& aP3D, const TopoDS_Face& aF, const Standard_Real aTol);
173 //! Returns true if the point aP2D is
174 //! inside or on the boundaries of aF
175 Standard_EXPORT Standard_Boolean IsPointInOnFace (const TopoDS_Face& aF, const gp_Pnt2d& aP2D);
178 //! Returns true if the distance between point aP3D
179 //! and face aF is less or equal to tolerance aTol
180 //! and projection point is inside or on the boundaries
182 Standard_EXPORT Standard_Boolean IsValidPointForFace (const gp_Pnt& aP3D, const TopoDS_Face& aF, const Standard_Real aTol);
185 //! Returns true if IsValidPointForFace returns true
186 //! for both face aF1 and aF2
187 Standard_EXPORT Standard_Boolean IsValidPointForFaces (const gp_Pnt& aP3D, const TopoDS_Face& aF1, const TopoDS_Face& aF2, const Standard_Real aTol);
190 //! Returns true if IsValidPointForFace returns true
191 //! for some 3d point that lay on the curve aIC bounded by
192 //! parameters aT1 and aT2
193 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);
196 //! Returns true if IsValidBlockForFace returns true
197 //! for both faces aF1 and aF2
198 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);
201 //! Computes parameter of the vertex aV on
203 //! Returns true if the distance between vertex and
204 //! curve is less than sum of tolerance of aV and aTolC,
205 //! otherwise or if projection algorithm failed
206 //! returns false (in this case aT isn't significant)
207 Standard_EXPORT Standard_Boolean IsVertexOnLine (const TopoDS_Vertex& aV, const IntTools_Curve& aIC, const Standard_Real aTolC, Standard_Real& aT);
210 //! Computes parameter of the vertex aV on
212 //! Returns true if the distance between vertex and
213 //! curve is less than sum of tolerance of aV and aTolC,
214 //! otherwise or if projection algorithm failed
215 //! returns false (in this case aT isn't significant)
216 Standard_EXPORT Standard_Boolean IsVertexOnLine (const TopoDS_Vertex& aV, const Standard_Real aTolV, const IntTools_Curve& aIC, const Standard_Real aTolC, Standard_Real& aT);
219 //! Computes parameter of the point aP on
221 //! Returns false if projection algorithm failed
222 //! other wiese returns true.
223 Standard_EXPORT Standard_Boolean ProjectPointOnEdge (const gp_Pnt& aP, const TopoDS_Edge& aE, Standard_Real& aT);
225 Standard_EXPORT Bnd_Box& BndBox (const TopoDS_Shape& theS);
227 //! Returns true if the solid <theFace> has
229 Standard_EXPORT Standard_Boolean IsInfiniteFace (const TopoDS_Face& theFace);
231 //! Sets tolerance to be used for projection of point on surface.
232 //! Clears map of already cached projectors in order to maintain
233 //! correct value for all projectors
234 Standard_EXPORT void SetPOnSProjectionTolerance (const Standard_Real theValue);
238 DEFINE_STANDARD_RTTIEXT(IntTools_Context,Standard_Transient)
242 typedef NCollection_DataMap<TopoDS_Shape,
244 TopTools_ShapeMapHasher> DataMapOfShapeAddress;
245 typedef NCollection_DataMap<Handle(Standard_Transient),
247 TColStd_MapTransientHasher> DataMapOfTransientAddress;
249 Handle(NCollection_BaseAllocator) myAllocator;
250 DataMapOfShapeAddress myFClass2dMap;
251 DataMapOfShapeAddress myProjPSMap;
252 DataMapOfShapeAddress myProjPCMap;
253 DataMapOfShapeAddress mySClassMap;
254 DataMapOfTransientAddress myProjPTMap;
255 DataMapOfShapeAddress myHatcherMap;
256 DataMapOfShapeAddress myProjSDataMap;
257 DataMapOfShapeAddress myBndBoxDataMap;
258 DataMapOfShapeAddress mySurfAdaptorMap;
259 Standard_Integer myCreateFlag;
260 Standard_Real myPOnSTolerance;
266 //! Clears map of already cached projectors.
267 Standard_EXPORT void clearCachedPOnSProjectors();
271 DEFINE_STANDARD_HANDLE(IntTools_Context, Standard_Transient)
273 #endif // _IntTools_Context_HeaderFile