0027117: BRepClass3d_SolidClassifier doesn't take into account vertex/edge/face toler...
[occt.git] / src / BRepClass3d / BRepClass3d_BndBoxTree.hxx
1 // Copyright (c) 1994-1999 Matra Datavision
2 // Copyright (c) 1999-2016 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _BRepClass3d_BndBoxTree_HeaderFile
16 #define _BRepClass3d_BndBoxTree_HeaderFile
17
18
19 #include <NCollection_Sequence.hxx>
20 #include <NCollection_UBTreeFiller.hxx>
21 #include <NCollection_UBTree.hxx>
22 #include <TopTools_IndexedMapOfShape.hxx>
23 #include <BRepBndLib.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <Geom_Line.hxx>
27 #include <Bnd_Box.hxx>
28 #include <gp_Lin.hxx>
29 #include <GeomAdaptor_Curve.hxx>
30 #include <Precision.hxx>
31
32 // Typedef to reduce code complexity.
33 typedef NCollection_UBTree <Standard_Integer, Bnd_Box> BRepClass3d_BndBoxTree;
34
35 // Class representing tree selector for point object.
36 class BRepClass3d_BndBoxTreeSelectorPoint : public BRepClass3d_BndBoxTree::Selector
37 {
38 public:
39   BRepClass3d_BndBoxTreeSelectorPoint(const TopTools_IndexedMapOfShape& theMapOfShape)
40     : BRepClass3d_BndBoxTreeSelectorPoint::Selector(), myMapOfShape (theMapOfShape)
41   {}
42
43   Standard_Boolean Reject (const Bnd_Box& theBox) const
44   {
45     return (theBox.IsOut (myP));
46   }
47
48   Standard_Boolean Accept (const Standard_Integer& theObj);
49
50   // Sets current point for boxes-point collisions.
51   void SetCurrentPoint (const gp_Pnt& theP) 
52   { 
53     myP = theP;
54   }
55
56 private:
57   BRepClass3d_BndBoxTreeSelectorPoint(const BRepClass3d_BndBoxTreeSelectorPoint& );
58   BRepClass3d_BndBoxTreeSelectorPoint& operator=(const BRepClass3d_BndBoxTreeSelectorPoint& );
59
60 private:
61   const TopTools_IndexedMapOfShape& myMapOfShape; //shapes (vertices + edges)
62   gp_Pnt myP;
63 };
64
65 // Class representing tree selector for line object.
66 class BRepClass3d_BndBoxTreeSelectorLine : public BRepClass3d_BndBoxTree::Selector
67 {
68 public:
69
70   struct EdgeParam
71   {
72     TopoDS_Edge myE;
73     Standard_Real myParam; //par on myE
74     Standard_Real myLParam; //par on line
75   };
76
77   struct VertParam
78   {
79     TopoDS_Vertex myV;
80     Standard_Real myLParam; //par on line
81   };
82
83
84 public:
85   BRepClass3d_BndBoxTreeSelectorLine(const TopTools_IndexedMapOfShape& theMapOfShape) 
86     : BRepClass3d_BndBoxTreeSelectorLine::Selector(), myMapOfShape (theMapOfShape)
87   {}
88
89   Standard_Boolean Reject (const Bnd_Box& theBox) const
90   {
91     return (theBox.IsOut (myL));
92   }
93
94   Standard_Boolean Accept (const Standard_Integer& theObj);
95
96   //Sets current line for boxes-line collisions
97   void SetCurrentLine (const gp_Lin& theL,
98                        const Standard_Real theMaxParam) 
99   {
100     myL = theL;
101     myLC.Load(new Geom_Line(theL), -Precision::PConfusion(), theMaxParam);
102   }
103   
104   void GetEdgeParam(const Standard_Integer i,
105                     TopoDS_Edge& theOutE,
106                     Standard_Real &theOutParam,
107                     Standard_Real &outLParam ) const
108   {
109     const EdgeParam& EP = myEP.Value(i);
110     theOutE = EP.myE;
111     theOutParam = EP.myParam;
112     outLParam = EP.myLParam;
113   }
114
115   void GetVertParam(const Standard_Integer i,
116                     TopoDS_Vertex& theOutV,
117                     Standard_Real &outLParam ) const
118   {
119     const VertParam& VP = myVP.Value(i);
120     theOutV = VP.myV;
121     outLParam = VP.myLParam;
122   }
123
124   Standard_Integer GetNbEdgeParam() const
125   {
126     return myEP.Length();
127   }
128
129   Standard_Integer GetNbVertParam() const
130   {
131     return myVP.Length();
132   }
133
134   void ClearResults()
135   {
136     myEP.Clear();
137     myVP.Clear();
138   }
139
140 private:
141   BRepClass3d_BndBoxTreeSelectorLine(const BRepClass3d_BndBoxTreeSelectorLine& );
142   BRepClass3d_BndBoxTreeSelectorLine& operator=(const BRepClass3d_BndBoxTreeSelectorLine& );
143
144 private:
145   const TopTools_IndexedMapOfShape& myMapOfShape; //shapes (vertices + edges)
146   gp_Lin myL;
147   NCollection_Sequence<EdgeParam> myEP; //output result (edge vs line)
148   NCollection_Sequence<VertParam> myVP; //output result (vertex vs line)
149   GeomAdaptor_Curve myLC;
150 };
151
152 #endif