0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[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(),
87       myMapOfShape(theMapOfShape),
88       myIsValid(Standard_True)
89   {}
90
91   Standard_Boolean Reject (const Bnd_Box& theBox) const
92   {
93     return (theBox.IsOut (myL));
94   }
95
96   Standard_Boolean Accept (const Standard_Integer& theObj);
97
98   //Sets current line for boxes-line collisions
99   void SetCurrentLine (const gp_Lin& theL,
100                        const Standard_Real theMaxParam) 
101   {
102     myL = theL;
103     myLC.Load(new Geom_Line(theL), -Precision::PConfusion(), theMaxParam);
104   }
105   
106   void GetEdgeParam(const Standard_Integer i,
107                     TopoDS_Edge& theOutE,
108                     Standard_Real &theOutParam,
109                     Standard_Real &outLParam ) const
110   {
111     const EdgeParam& EP = myEP.Value(i);
112     theOutE = EP.myE;
113     theOutParam = EP.myParam;
114     outLParam = EP.myLParam;
115   }
116
117   void GetVertParam(const Standard_Integer i,
118                     TopoDS_Vertex& theOutV,
119                     Standard_Real &outLParam ) const
120   {
121     const VertParam& VP = myVP.Value(i);
122     theOutV = VP.myV;
123     outLParam = VP.myLParam;
124   }
125
126   Standard_Integer GetNbEdgeParam() const
127   {
128     return myEP.Length();
129   }
130
131   Standard_Integer GetNbVertParam() const
132   {
133     return myVP.Length();
134   }
135
136   void ClearResults()
137   {
138     myEP.Clear();
139     myVP.Clear();
140     myIsValid = Standard_True;
141   }
142
143   //! Returns TRUE if correct classification is possible
144   Standard_Boolean IsCorrect() const
145   {
146     return myIsValid;
147   }
148
149 private:
150   BRepClass3d_BndBoxTreeSelectorLine(const BRepClass3d_BndBoxTreeSelectorLine& );
151   BRepClass3d_BndBoxTreeSelectorLine& operator=(const BRepClass3d_BndBoxTreeSelectorLine& );
152
153 private:
154   const TopTools_IndexedMapOfShape& myMapOfShape; //shapes (vertices + edges)
155   gp_Lin myL;
156   NCollection_Sequence<EdgeParam> myEP; //output result (edge vs line)
157   NCollection_Sequence<VertParam> myVP; //output result (vertex vs line)
158   GeomAdaptor_Curve myLC;
159   Standard_Boolean myIsValid;
160 };
161
162 #endif