summaryrefslogtreecommitdiff
path: root/src/Select3D/Select3D_SensitiveCurve.cxx
blob: a0aca12393cedba0b9f427653ad8a8fa2a591c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright:   Matra-Datavision 1995
// File:    Select3D_SensitiveCurve.cxx
// Created: Mon Mar 13 09:57:58 1995
// Author:  Robert COUBLANC
//      <rob>



#include <Select3D_SensitiveCurve.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Lin2d.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>


//==================================================
// Function: 
// Purpose :
//==================================================

Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
              const Handle(Geom_Curve)& C,
              const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, NbPoints),
mylastseg(0)     
{
  LoadPoints(C,NbPoints);
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
              const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)     
{
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
              const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)     
{
}

//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveCurve
::Matches(const Standard_Real X,
      const Standard_Real Y,
      const Standard_Real aTol,
      Standard_Real& DMin)
{
  Standard_Integer Rank;
  TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
  Points2D(aArrayOf2dPnt);
  if (SelectBasics_BasicTool::MatchPolyg2d (aArrayOf2dPnt,
                                            X, Y,
                                            aTol,
                                            DMin,
                                            Rank))
  {
    mylastseg = Rank;
    // compute and validate the depth (::Depth()) along the eyeline
    return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin);
    
  }
  return Standard_False;

}
//==================================================
// Function: Matches
// Purpose : know if a box touches the projected polygon
//           of the Curve.
//==================================================

Standard_Boolean Select3D_SensitiveCurve::
Matches (const Standard_Real XMin,
     const Standard_Real YMin,
     const Standard_Real XMax,
     const Standard_Real YMax,
     const Standard_Real aTol)
{  
  Bnd_Box2d BoundBox;
  BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
  
  for(Standard_Integer j=0; j<mynbpoints; j++)
    {
      if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
    }
  return Standard_True;
}

//=======================================================================
//function : Matches
//purpose  : 
//=======================================================================

Standard_Boolean Select3D_SensitiveCurve::
Matches (const TColgp_Array1OfPnt2d& aPoly,
     const Bnd_Box2d& aBox,
     const Standard_Real aTol)
{ 
  Standard_Real Umin,Vmin,Umax,Vmax;
  aBox.Get(Umin,Vmin,Umax,Vmax);
  CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);

  for(Standard_Integer j=0;j<mynbpoints;j++){
    Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]);
    if(RES!=1) return Standard_False;
  }
  return Standard_True;
}



//==================================================
// Function: 
// Purpose :
//==================================================

void Select3D_SensitiveCurve
::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
{
  /*this method is private and it used only inside of constructor. 
    That's why check !NbP==mypolyg3d->Length() was removed*/

  Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
  Standard_Real Curparam = aCurve->FirstParameter();
  for(Standard_Integer i=0;i<mynbpoints;i++)
    {
      ((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam);
      Curparam+=Step;
    }
}

//=======================================================================
//function : Dump
//purpose  : 
//=======================================================================

void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const 
{
  S<<"\tSensitiveCurve 3D :"<<endl;
  if(HasLocation())
    S<<"\t\tExisting Location"<<endl;

  S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;

  if(FullDump){
//    S<<"\t\t\tOwner:"<<myOwnerId<<endl;
    Select3D_SensitiveEntity::DumpBox(S,mybox2d);
  }
}
//=======================================================================
//function : ComputeDepth
//purpose  : 
//=======================================================================

Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
{

  if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
  gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
  TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
  TheCDG/=2.;
  return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));
}