2c2f0fbcd446cd2d6855ce516efb4ee4de6da3c3
[occt.git] / src / BRepAdaptor / BRepAdaptor_Surface.cxx
1 // Created on: 1993-02-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepAdaptor_Surface.ixx>
18 #include <BRep_Tool.hxx>
19 #include <BRepTools.hxx>
20 #include <GeomAdaptor_HSurface.hxx>
21 #include <GeomAdaptor_HCurve.hxx>
22
23 //=======================================================================
24 //function : BRepAdaptor_Surface
25 //purpose  : 
26 //=======================================================================
27
28 BRepAdaptor_Surface::BRepAdaptor_Surface() 
29 {
30 }
31
32
33 //=======================================================================
34 //function : BRepAdaptor_Surface
35 //purpose  : 
36 //=======================================================================
37
38 BRepAdaptor_Surface::BRepAdaptor_Surface(const TopoDS_Face& F,
39                                          const Standard_Boolean R) 
40 {
41   Initialize(F,R);
42 }
43
44
45 //=======================================================================
46 //function : Initialize
47 //purpose  : 
48 //=======================================================================
49
50 void BRepAdaptor_Surface::Initialize(const TopoDS_Face& F,
51                                      const Standard_Boolean Restriction) 
52 {
53   myFace = F;
54   TopLoc_Location L;
55   if (Restriction) {
56     Standard_Real umin,umax,vmin,vmax;
57     BRepTools::UVBounds(F,umin,umax,vmin,vmax);
58     mySurf.Load(BRep_Tool::Surface(F,L),umin,umax,vmin,vmax);
59   }
60   else 
61     mySurf.Load(BRep_Tool::Surface(F,L));
62   myTrsf = L.Transformation();
63 }
64
65
66 //=======================================================================
67 //function : Surface
68 //purpose  : 
69 //=======================================================================
70
71 const GeomAdaptor_Surface& BRepAdaptor_Surface::Surface() const 
72 {
73   return mySurf;
74 }
75
76
77 //=======================================================================
78 //function : ChangeSurface
79 //purpose  : 
80 //=======================================================================
81
82 GeomAdaptor_Surface& BRepAdaptor_Surface::ChangeSurface()
83 {
84   return mySurf;
85 }
86
87
88 //=======================================================================
89 //function : Trsf
90 //purpose  : 
91 //=======================================================================
92
93 const gp_Trsf& BRepAdaptor_Surface::Trsf() const 
94 {
95   return myTrsf;
96 }
97
98
99 //=======================================================================
100 //function : Face
101 //purpose  : 
102 //=======================================================================
103
104 const TopoDS_Face& BRepAdaptor_Surface::Face() const
105 {
106   return myFace;
107 }
108
109 //=======================================================================
110 //function : Tolerance
111 //purpose  : 
112 //=======================================================================
113
114 Standard_Real BRepAdaptor_Surface::Tolerance() const
115 {
116   return BRep_Tool::Tolerance(myFace);
117 }
118
119
120 //=======================================================================
121 //function : UIntervals
122 //purpose  : 
123 //=======================================================================
124
125 void BRepAdaptor_Surface::UIntervals(TColStd_Array1OfReal& T,
126                                      const GeomAbs_Shape S) const 
127 {
128   mySurf.UIntervals(T,S);
129 }
130
131
132 //=======================================================================
133 //function : VIntervals
134 //purpose  : 
135 //=======================================================================
136
137 void BRepAdaptor_Surface::VIntervals(TColStd_Array1OfReal& T,
138                                      const GeomAbs_Shape S) const 
139 {
140   mySurf.VIntervals(T,S);
141 }
142
143
144 //=======================================================================
145 //function : UTrim
146 //purpose  : 
147 //=======================================================================
148
149 Handle(Adaptor3d_HSurface) BRepAdaptor_Surface::UTrim
150 (const Standard_Real First,
151  const Standard_Real Last ,
152  const Standard_Real Tol   ) const 
153 {
154   Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
155   HS->ChangeSurface().Load
156     (Handle(Geom_Surface)::DownCast(mySurf.Surface()->Transformed(myTrsf)));
157   return HS->UTrim(First,Last,Tol);
158 }
159
160
161 //=======================================================================
162 //function : VTrim
163 //purpose  : 
164 //=======================================================================
165
166 Handle(Adaptor3d_HSurface) BRepAdaptor_Surface::VTrim
167 (const Standard_Real First,
168  const Standard_Real Last, 
169  const Standard_Real Tol) const 
170 {
171   Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
172   HS->ChangeSurface().Load
173     (Handle(Geom_Surface)::DownCast(mySurf.Surface()->Transformed(myTrsf)));
174   return HS->VTrim(First,Last,Tol);
175 }
176
177
178 //=======================================================================
179 //function : Value
180 //purpose  : 
181 //=======================================================================
182
183 gp_Pnt BRepAdaptor_Surface::Value(const Standard_Real U,
184                                   const Standard_Real V) const
185 {
186   return mySurf.Value(U,V).Transformed(myTrsf);
187 }
188
189 //=======================================================================
190 //function : D0
191 //purpose  : 
192 //=======================================================================
193
194 void  BRepAdaptor_Surface::D0(const Standard_Real U, 
195                               const Standard_Real V, 
196                               gp_Pnt& P) const
197 {
198   mySurf.D0(U,V,P);
199   P.Transform(myTrsf);
200 }
201
202 //=======================================================================
203 //function : D1
204 //purpose  : 
205 //=======================================================================
206
207 void  BRepAdaptor_Surface::D1(const Standard_Real U, 
208                               const Standard_Real V, 
209                               gp_Pnt& P, 
210                               gp_Vec& D1U,
211                               gp_Vec& D1V)const 
212 {
213   mySurf.D1(U,V,P,D1U,D1V);
214   P.Transform(myTrsf);
215   D1U.Transform(myTrsf);
216   D1V.Transform(myTrsf);
217 }
218
219
220 //=======================================================================
221 //function : D2
222 //purpose  : 
223 //=======================================================================
224
225 void  BRepAdaptor_Surface::D2(const Standard_Real U, 
226                               const Standard_Real V,
227                               gp_Pnt& P, gp_Vec& D1U, 
228                               gp_Vec& D1V,
229                               gp_Vec& D2U, 
230                               gp_Vec& D2V, 
231                               gp_Vec& D2UV)const 
232 {
233   mySurf.D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
234   P.Transform(myTrsf);
235   D1U.Transform(myTrsf);
236   D1V.Transform(myTrsf);
237   D2U.Transform(myTrsf);
238   D2V.Transform(myTrsf);
239   D2UV.Transform(myTrsf);
240 }
241
242 //=======================================================================
243 //function : D3
244 //purpose  : 
245 //=======================================================================
246
247 void  BRepAdaptor_Surface::D3(const Standard_Real U, 
248                               const Standard_Real V,
249                               gp_Pnt& P,
250                               gp_Vec& D1U, gp_Vec& D1V,
251                               gp_Vec& D2U, gp_Vec& D2V, 
252                               gp_Vec& D2UV,
253                               gp_Vec& D3U, gp_Vec& D3V,
254                               gp_Vec& D3UUV, gp_Vec& D3UVV)const 
255 {
256   mySurf.D3(U,V,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
257   P.Transform(myTrsf);
258   D1U.Transform(myTrsf);
259   D1V.Transform(myTrsf);
260   D2U.Transform(myTrsf);
261   D2V.Transform(myTrsf);
262   D2UV.Transform(myTrsf);
263   D3U.Transform(myTrsf);
264   D3V.Transform(myTrsf);
265   D3UUV.Transform(myTrsf);
266   D3UVV.Transform(myTrsf);
267 }
268
269
270 //=======================================================================
271 //function : DN
272 //purpose  : 
273 //=======================================================================
274
275 gp_Vec BRepAdaptor_Surface::DN(const Standard_Real U,
276                                const Standard_Real V,
277                                const Standard_Integer Nu,
278                                const Standard_Integer Nv) const
279 {
280   return mySurf.DN(U,V,Nu,Nv).Transformed(myTrsf);
281 }
282
283 //=======================================================================
284 //function : Plane
285 //purpose  : 
286 //=======================================================================
287
288 gp_Pln  BRepAdaptor_Surface::Plane()const 
289 {
290   return mySurf.Plane().Transformed(myTrsf);
291 }
292
293
294 //=======================================================================
295 //function : Cylinder
296 //purpose  : 
297 //=======================================================================
298
299 gp_Cylinder  BRepAdaptor_Surface::Cylinder()const 
300 {
301   return mySurf.Cylinder().Transformed(myTrsf);
302 }
303
304
305 //=======================================================================
306 //function : Sphere
307 //purpose  : 
308 //=======================================================================
309
310 gp_Sphere  BRepAdaptor_Surface::Sphere()const 
311 {
312   return mySurf.Sphere().Transformed(myTrsf);
313 }
314
315
316 //=======================================================================
317 //function : Cone
318 //purpose  : 
319 //=======================================================================
320
321 gp_Cone  BRepAdaptor_Surface::Cone()const 
322 {
323   return mySurf.Cone().Transformed(myTrsf);
324 }
325
326 //=======================================================================
327 //function : Torus
328 //purpose  : 
329 //=======================================================================
330
331 gp_Torus  BRepAdaptor_Surface::Torus()const 
332 {
333   return mySurf.Torus().Transformed(myTrsf);
334 }
335
336 //=======================================================================
337 //function : Bezier
338 //purpose  : 
339 //=======================================================================
340
341 Handle(Geom_BezierSurface) BRepAdaptor_Surface::Bezier() const 
342 {
343   return Handle(Geom_BezierSurface)::DownCast
344     (mySurf.Bezier()->Transformed(myTrsf));
345 }
346
347
348 //=======================================================================
349 //function : BSpline
350 //purpose  : 
351 //=======================================================================
352
353 Handle(Geom_BSplineSurface) BRepAdaptor_Surface::BSpline() const 
354 {
355   return Handle(Geom_BSplineSurface)::DownCast
356     (mySurf.BSpline()->Transformed(myTrsf));
357 }
358
359
360 //=======================================================================
361 //function : AxeOfRevolution
362 //purpose  : 
363 //=======================================================================
364
365 gp_Ax1 BRepAdaptor_Surface::AxeOfRevolution() const 
366 {
367   return mySurf.AxeOfRevolution().Transformed(myTrsf);
368 }
369
370
371 //=======================================================================
372 //function : Direction
373 //purpose  : 
374 //=======================================================================
375
376 gp_Dir BRepAdaptor_Surface::Direction() const 
377 {
378   return mySurf.Direction().Transformed(myTrsf);
379 }
380
381
382 //=======================================================================
383 //function : BasisCurve
384 //purpose  : 
385 //=======================================================================
386
387 Handle(Adaptor3d_HCurve) BRepAdaptor_Surface::BasisCurve() const 
388 {
389   Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
390   HS->ChangeSurface().Load
391     (Handle(Geom_Surface)::DownCast(mySurf.Surface()->Transformed(myTrsf)));
392
393   return HS->BasisCurve();
394 }
395
396
397 //=======================================================================
398 //function : BasisSurface
399 //purpose  : 
400 //=======================================================================
401
402 Handle(Adaptor3d_HSurface) BRepAdaptor_Surface::BasisSurface() const 
403 {  
404   Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
405   HS->ChangeSurface().Load
406     (Handle(Geom_Surface)::DownCast(mySurf.Surface()->Transformed(myTrsf)));
407   return HS->BasisSurface();
408 }
409
410
411 //=======================================================================
412 //function : OffsetValue
413 //purpose  : 
414 //=======================================================================
415
416 Standard_Real BRepAdaptor_Surface::OffsetValue() const 
417 {
418   return mySurf.OffsetValue();
419 }
420