1 // Copyright: Matra-Datavision 1995
2 // File: Select3D_SensitiveCurve.cxx
3 // Created: Mon Mar 13 09:57:58 1995
4 // Author: Robert COUBLANC
9 #include <Select3D_SensitiveCurve.ixx>
10 #include <SelectBasics_BasicTool.hxx>
11 #include <gp_Lin2d.hxx>
12 #include <Precision.hxx>
14 #include <CSLib_Class2d.hxx>
17 //==================================================
20 //==================================================
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),
29 LoadPoints(C,NbPoints);
31 //==================================================
34 //==================================================
35 Select3D_SensitiveCurve
36 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
37 const Handle(TColgp_HArray1OfPnt)& ThePoints):
38 Select3D_SensitivePoly(OwnerId, ThePoints),
42 //==================================================
45 //==================================================
46 Select3D_SensitiveCurve
47 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
48 const TColgp_Array1OfPnt& ThePoints):
49 Select3D_SensitivePoly(OwnerId, ThePoints),
54 //==================================================
57 //==================================================
58 Standard_Boolean Select3D_SensitiveCurve
59 ::Matches(const Standard_Real X,
60 const Standard_Real Y,
61 const Standard_Real aTol,
64 Standard_Integer Rank;
65 TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
66 Points2D(aArrayOf2dPnt);
67 Standard_Boolean KK = SelectBasics_BasicTool::MatchPolyg2d(aArrayOf2dPnt,
73 Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
79 //==================================================
81 // Purpose : know if a box touches the projected polygon
83 //==================================================
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)
93 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
95 for(Standard_Integer j=0; j<mynbpoints-1; j++)
97 if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
102 //=======================================================================
105 //=======================================================================
107 Standard_Boolean Select3D_SensitiveCurve::
108 Matches (const TColgp_Array1OfPnt2d& aPoly,
109 const Bnd_Box2d& aBox,
110 const Standard_Real aTol)
112 Standard_Real Umin,Vmin,Umax,Vmax;
113 aBox.Get(Umin,Vmin,Umax,Vmax);
114 Standard_Real Tolu,Tolv;
117 CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
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;
123 return Standard_True;
128 //==================================================
131 //==================================================
133 void Select3D_SensitiveCurve
134 ::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
136 /*this method is private and it used only inside of constructor.
137 That's why check !NbP==mypolyg3d->Length() was removed*/
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++)
143 ((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam);
148 //=======================================================================
151 //=======================================================================
153 void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
155 S<<"\tSensitiveCurve 3D :"<<endl;
157 S<<"\t\tExisting Location"<<endl;
159 S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
162 // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
163 Select3D_SensitiveEntity::DumpBox(S,mybox2d);
166 //=======================================================================
167 //function : ComputeDepth
169 //=======================================================================
171 Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
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];
178 return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));