Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Select3D / Select3D_SensitiveCurve.cxx
1 // Copyright:   Matra-Datavision 1995
2 // File:    Select3D_SensitiveCurve.cxx
3 // Created: Mon Mar 13 09:57:58 1995
4 // Author:  Robert COUBLANC
5 //      <rob>
6
7
8
9 #include <Select3D_SensitiveCurve.ixx>
10 #include <SelectBasics_BasicTool.hxx>
11 #include <gp_Lin2d.hxx>
12 #include <Precision.hxx>
13 #include <ElCLib.hxx>
14 #include <CSLib_Class2d.hxx>
15
16
17 //==================================================
18 // Function: 
19 // Purpose :
20 //==================================================
21
22 Select3D_SensitiveCurve
23 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
24               const Handle(Geom_Curve)& C,
25               const Standard_Integer NbPoints):
26 Select3D_SensitivePoly(OwnerId, NbPoints),
27 mylastseg(0)     
28 {
29   LoadPoints(C,NbPoints);
30 }
31 //==================================================
32 // Function: Creation
33 // Purpose :
34 //==================================================
35 Select3D_SensitiveCurve
36 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
37               const Handle(TColgp_HArray1OfPnt)& ThePoints):
38 Select3D_SensitivePoly(OwnerId, ThePoints),
39 mylastseg(0)     
40 {
41 }
42 //==================================================
43 // Function: Creation
44 // Purpose :
45 //==================================================
46 Select3D_SensitiveCurve
47 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
48               const TColgp_Array1OfPnt& ThePoints):
49 Select3D_SensitivePoly(OwnerId, ThePoints),
50 mylastseg(0)     
51 {
52 }
53
54 //==================================================
55 // Function: Matches
56 // Purpose :
57 //==================================================
58 Standard_Boolean Select3D_SensitiveCurve
59 ::Matches(const Standard_Real X,
60       const Standard_Real Y,
61       const Standard_Real aTol,
62       Standard_Real& DMin)
63 {
64   Standard_Integer Rank;
65   TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
66   Points2D(aArrayOf2dPnt);
67   Standard_Boolean KK = SelectBasics_BasicTool::MatchPolyg2d(aArrayOf2dPnt,
68                                  X,Y,
69                                  aTol,
70                                  DMin,
71                                  Rank);
72   if(KK){
73     Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
74     mylastseg = Rank;
75   }
76   return KK;
77
78 }
79 //==================================================
80 // Function: Matches
81 // Purpose : know if a box touches the projected polygon
82 //           of the Curve.
83 //==================================================
84
85 Standard_Boolean Select3D_SensitiveCurve::
86 Matches (const Standard_Real XMin,
87      const Standard_Real YMin,
88      const Standard_Real XMax,
89      const Standard_Real YMax,
90      const Standard_Real aTol)
91 {  
92   Bnd_Box2d BoundBox;
93   BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
94   
95   for(Standard_Integer j=0; j<mynbpoints-1; j++)
96     {
97       if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
98     }
99   return Standard_True;
100 }
101
102 //=======================================================================
103 //function : Matches
104 //purpose  : 
105 //=======================================================================
106
107 Standard_Boolean Select3D_SensitiveCurve::
108 Matches (const TColgp_Array1OfPnt2d& aPoly,
109      const Bnd_Box2d& aBox,
110      const Standard_Real aTol)
111
112   Standard_Real Umin,Vmin,Umax,Vmax;
113   aBox.Get(Umin,Vmin,Umax,Vmax);
114   Standard_Real Tolu,Tolv;
115   Tolu = 1e-7;
116   Tolv = 1e-7;
117   CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
118
119   for(Standard_Integer j=0;j<mynbpoints;j++){
120     Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]);
121     if(RES!=1) return Standard_False;
122   }
123   return Standard_True;
124 }
125
126
127
128 //==================================================
129 // Function: 
130 // Purpose :
131 //==================================================
132
133 void Select3D_SensitiveCurve
134 ::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
135 {
136   /*this method is private and it used only inside of constructor. 
137     That's why check !NbP==mypolyg3d->Length() was removed*/
138
139   Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
140   Standard_Real Curparam = aCurve->FirstParameter();
141   for(Standard_Integer i=0;i<mynbpoints;i++)
142     {
143       ((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam);
144       Curparam+=Step;
145     }
146 }
147
148 //=======================================================================
149 //function : Dump
150 //purpose  : 
151 //=======================================================================
152
153 void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const 
154 {
155   S<<"\tSensitiveCurve 3D :"<<endl;
156   if(HasLocation())
157     S<<"\t\tExisting Location"<<endl;
158
159   S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
160
161   if(FullDump){
162 //    S<<"\t\t\tOwner:"<<myOwnerId<<endl;
163     Select3D_SensitiveEntity::DumpBox(S,mybox2d);
164   }
165 }
166 //=======================================================================
167 //function : ComputeDepth
168 //purpose  : 
169 //=======================================================================
170
171 Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
172 {
173
174   if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
175   gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
176   TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
177   TheCDG/=2.;
178   return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));
179 }