summaryrefslogtreecommitdiff
path: root/src/DrawTrSurf/DrawTrSurf_Surface.cxx
blob: f1a4af8425b696c4c52a1ba931c948d43c1fb215 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include <DrawTrSurf_Surface.ixx>
#include <GeomTools_SurfaceSet.hxx>
#include <GeomAdaptor_HSurface.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <Precision.hxx>

Standard_Real DrawTrSurf_SurfaceLimit = 400;


//=======================================================================
//function : DrawTrSurf_Surface
//purpose  : 
//=======================================================================

DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S) 
: DrawTrSurf_Drawable (16, 0.01, 1) 
{
  surf = S;
  boundsLook = Draw_jaune;
  isosLook = Draw_bleu;
  nbUIsos = 1;
  nbVIsos = 1;
}




//=======================================================================
//function : DrawTrSurf_Surface
//purpose  : 
//=======================================================================

DrawTrSurf_Surface::DrawTrSurf_Surface 
  (const Handle(Geom_Surface)& S, const Standard_Integer Nu, 
   const Standard_Integer Nv,
   const Draw_Color& BoundsColor, const Draw_Color& IsosColor,
   const Standard_Integer Discret, const Standard_Real Deflection,
   const Standard_Integer DrawMode) 
:  DrawTrSurf_Drawable (Discret, Deflection, DrawMode) 
{
  surf = S;
  boundsLook = BoundsColor;
  isosLook = IsosColor;
  nbUIsos = Abs(Nu);
  nbVIsos = Abs(Nv);
}



//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================

void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const 
{
  DrawOn(dis,Standard_True);
}

//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================

void DrawTrSurf_Surface::DrawOn (Draw_Display& dis,
				 const Standard_Boolean Iso) const 
{
  Standard_Real UFirst, ULast, VFirst, VLast;
  surf->Bounds (UFirst, ULast, VFirst, VLast);
  
  Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
  Standard_Boolean UlastInf  = Precision::IsPositiveInfinite(ULast);
  Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
  Standard_Boolean VlastInf  = Precision::IsPositiveInfinite(VLast);
  
  if (UfirstInf || UlastInf) {
    gp_Pnt P1,P2;
    Standard_Real v;
    if (VfirstInf && VlastInf) 
      v = 0;
    else if (VfirstInf)
      v = VLast;
    else if (VlastInf)
      v = VFirst;
    else
      v = (VFirst + VLast) / 2;
    
    Standard_Real delta = 1.;

    if (UfirstInf && UlastInf) {
      do {
	delta *= 2;
	UFirst = - delta;
	ULast  =   delta;
	surf->D0(UFirst,v,P1);
	surf->D0(ULast,v,P2);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
    else if (UfirstInf) {
      surf->D0(ULast,v,P2);
      do {
	delta *= 2;
	UFirst = ULast - delta;
	surf->D0(UFirst,v,P1);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
    else if (UlastInf) {
      surf->D0(UFirst,v,P1);
      do {
	delta *= 2;
	ULast = UFirst + delta;
	surf->D0(ULast,v,P2);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
  }

  if (VfirstInf || VlastInf) {
    gp_Pnt P1,P2;
    Standard_Real u = (UFirst + ULast) /2 ;

    Standard_Real delta = 1.;

    if (VfirstInf && VlastInf) {
      do {
	delta *= 2;
	VFirst = - delta;
	VLast  =   delta;
	surf->D0(u,VFirst,P1);
	surf->D0(u,VLast,P2);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
    else if (VfirstInf) {
      surf->D0(u,VLast,P2);
      do {
	delta *= 2;
	VFirst = VLast - delta;
	surf->D0(u,VFirst,P1);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
    else if (VlastInf) {
      surf->D0(u,VFirst,P1);
      do {
	delta *= 2;
	VLast = VFirst + delta;
	surf->D0(u,VLast,P2);
      } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
    }
  }


  Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
  HS->ChangeSurface().Load(surf,UFirst,ULast,VFirst,VLast);

  Adaptor3d_IsoCurve C(HS);
  
  if (Iso) {
    dis.SetColor(isosLook);
    Standard_Integer i, j;
    
    Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1);
    Standard_Real U = UFirst;
    for (i = 1; i <= nbUIsos; i++) {
      U += Du;
      DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis);
    }
    
    Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1);
    Standard_Real V = VFirst;
    for (j = 1; j <= nbVIsos; j++) {
      V += Dv;
      DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis);
    }
  }

  // draw bounds
  dis.SetColor(boundsLook);
  if (!UfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast,dis);
  if (!UlastInf)  DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast,dis);
  if (!VfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast,dis);
  if (!VlastInf)  DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast,dis);

  // draw marker
  DrawIsoCurveOn(C,GeomAbs_IsoU,
		 UFirst+(ULast-UFirst)/10.,
		 VFirst, VFirst + (VLast-VFirst)/10.,
		 dis);
}



//=======================================================================
//function : ShowIsos
//purpose  : 
//=======================================================================

void DrawTrSurf_Surface::ShowIsos ( const Standard_Integer Nu, 
				    const Standard_Integer Nv) 
{
  nbUIsos = Abs(Nu);
  nbVIsos = Abs(Nv);
}


//=======================================================================
//function : ClearIsos
//purpose  : 
//=======================================================================

void DrawTrSurf_Surface::ClearIsos () 
{
  nbUIsos = 0;
  nbVIsos = 0;
}


//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================

Handle(Draw_Drawable3D)  DrawTrSurf_Surface::Copy() const 
{
  Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface
    (Handle(Geom_Surface)::DownCast(surf->Copy()),
     nbUIsos,nbVIsos,boundsLook,isosLook,
     GetDiscretisation(),GetDeflection(),GetDrawMode());
     
  return DS;
}


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

void  DrawTrSurf_Surface::Dump(Standard_OStream& S)const 
{
  GeomTools_SurfaceSet::PrintSurface(surf,S);
}


//=======================================================================
//function : Whatis
//purpose  : 
//=======================================================================

void  DrawTrSurf_Surface::Whatis(Draw_Interpretor& S)const 
{
  S << "a surface";
}