7fd59977 |
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); |
4952a30a |
67 | if (SelectBasics_BasicTool::MatchPolyg2d (aArrayOf2dPnt, |
68 | X, Y, |
69 | aTol, |
70 | DMin, |
71 | Rank)) |
72 | { |
7fd59977 |
73 | mylastseg = Rank; |
4952a30a |
74 | // compute and validate the depth (::Depth()) along the eyeline |
75 | return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); |
76 | |
7fd59977 |
77 | } |
4952a30a |
78 | return Standard_False; |
7fd59977 |
79 | |
80 | } |
81 | //================================================== |
82 | // Function: Matches |
83 | // Purpose : know if a box touches the projected polygon |
84 | // of the Curve. |
85 | //================================================== |
86 | |
87 | Standard_Boolean Select3D_SensitiveCurve:: |
88 | Matches (const Standard_Real XMin, |
89 | const Standard_Real YMin, |
90 | const Standard_Real XMax, |
91 | const Standard_Real YMax, |
92 | const Standard_Real aTol) |
93 | { |
94 | Bnd_Box2d BoundBox; |
95 | BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); |
96 | |
3c34883c |
97 | for(Standard_Integer j=0; j<mynbpoints; j++) |
7fd59977 |
98 | { |
99 | if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False; |
100 | } |
101 | return Standard_True; |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : Matches |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | Standard_Boolean Select3D_SensitiveCurve:: |
110 | Matches (const TColgp_Array1OfPnt2d& aPoly, |
111 | const Bnd_Box2d& aBox, |
112 | const Standard_Real aTol) |
113 | { |
114 | Standard_Real Umin,Vmin,Umax,Vmax; |
115 | aBox.Get(Umin,Vmin,Umax,Vmax); |
116 | Standard_Real Tolu,Tolv; |
117 | Tolu = 1e-7; |
118 | Tolv = 1e-7; |
119 | CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); |
120 | |
121 | for(Standard_Integer j=0;j<mynbpoints;j++){ |
122 | Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]); |
123 | if(RES!=1) return Standard_False; |
124 | } |
125 | return Standard_True; |
126 | } |
127 | |
128 | |
129 | |
130 | //================================================== |
131 | // Function: |
132 | // Purpose : |
133 | //================================================== |
134 | |
135 | void Select3D_SensitiveCurve |
136 | ::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP) |
137 | { |
138 | /*this method is private and it used only inside of constructor. |
139 | That's why check !NbP==mypolyg3d->Length() was removed*/ |
140 | |
141 | Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1); |
142 | Standard_Real Curparam = aCurve->FirstParameter(); |
143 | for(Standard_Integer i=0;i<mynbpoints;i++) |
144 | { |
145 | ((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam); |
146 | Curparam+=Step; |
147 | } |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Dump |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const |
156 | { |
157 | S<<"\tSensitiveCurve 3D :"<<endl; |
158 | if(HasLocation()) |
159 | S<<"\t\tExisting Location"<<endl; |
160 | |
161 | S<<"\t\tNumber Of Points :"<<mynbpoints<<endl; |
162 | |
163 | if(FullDump){ |
164 | // S<<"\t\t\tOwner:"<<myOwnerId<<endl; |
165 | Select3D_SensitiveEntity::DumpBox(S,mybox2d); |
166 | } |
167 | } |
168 | //======================================================================= |
169 | //function : ComputeDepth |
170 | //purpose : |
171 | //======================================================================= |
172 | |
173 | Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const |
174 | { |
175 | |
176 | if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement... |
177 | gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]); |
178 | TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1]; |
179 | TheCDG/=2.; |
180 | return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG)); |
181 | } |