Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
9 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
7fd59977 | 14 | /*********************************************************************** |
7fd59977 | 15 | FONCTION : |
16 | ---------- | |
17 | Classe V3d_View : | |
7fd59977 | 18 | HISTORIQUE DES MODIFICATIONS : |
19 | -------------------------------- | |
20 | 00-09-92 : GG ; Creation. | |
21 | 02-10-96 : FMN ; Suppression appel Redraw sans MustBeResized() | |
22 | 05-06-97 : FMN ; Correction FitAll() | |
23 | 30-06-97 : GG ; Correction + Optimisation de Panning(...) | |
24 | On fait la translation + le zoom en une seule | |
25 | operation au lieu de 2 precedemment qui etait buggee. | |
26 | 09-07-97 : FMN ; Correction FitAll() sur le Ratio | |
27 | 16-07-97 : FMN ; Correction FitAll() sur le calcul de la Box | |
28 | 22-07-97 : FMN ; Ajout mode RetainMode pour le Transient | |
29 | 15-12-97 : FMN ; Ajout texture mapping | |
30 | 17-12-97 : FMN ; CTS19129 Correction FitAll() multiple | |
31 | 18-12-97 : FMN ; Ajout mode Ajout | |
32 | 24-12-97 : FMN ; Remplacement de math par MathGra | |
33 | 24-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window | |
34 | 31-12-97 : CAL ; Remplacement de MathGra par Array2OfReal | |
35 | 07-01-98 : CAL ; Ajout de la methode DoMapping. | |
36 | 07-01-98 : CAL ; Retrait de tous les "this->" inutiles | |
37 | 21-01-98 : CAL ; Remplacement des Window->Position () par Window->Size () | |
38 | 27-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM) | |
39 | 12-02-98 : GG ; Reactivation du Redraw dans MustBeResized() | |
40 | 23-02-98 : FMN ; Remplacement PI par Standard_PI | |
41 | 25-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view | |
42 | 11-03-98 : STT ; S3558 | |
43 | 19-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real) | |
44 | ne marche pas. | |
45 | 08-04-98 : STT ; suppr. S3558 | |
46 | 10-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef | |
47 | 13-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real) | |
48 | ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int). | |
49 | 16-08-98 : CAL ; S3892. Ajout grilles 3d. | |
50 | 09-09-98 : CAL ; S3892. Generalisation de TrsPoint. | |
7fd59977 | 51 | 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie. |
52 | 16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie. | |
53 | 06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue. | |
7fd59977 | 54 | 29-OCT-98 : DCB : Adding ScreenCopy () method. |
7fd59977 | 55 | REMARQUES : |
56 | ----------- | |
57 | About FitAll() multiple. This probleme is caused by missing | |
58 | precision of transformation matrices. If it is supposed that | |
59 | projection is made in the plane (U,V), there is a difference | |
60 | after several Zoom - compared to the exact value (cf ZoomX). | |
61 | Don't forget that the matrices work in float and not in double. | |
62 | To solve the problem (for lack of a better solution) I make 2 passes. | |
7fd59977 | 63 | ************************************************************************/ |
7fd59977 | 64 | /*----------------------------------------------------------------------*/ |
65 | /* | |
66 | * Includes | |
67 | */ | |
68 | ||
42cf5bc1 | 69 | #include <Aspect_GradientBackground.hxx> |
70 | #include <Aspect_Grid.hxx> | |
71 | #include <Aspect_Window.hxx> | |
72 | #include <Bnd_Box.hxx> | |
73 | #include <gp_Ax3.hxx> | |
7fd59977 | 74 | #include <gp_Dir.hxx> |
b5ac8292 | 75 | #include <gp_Pln.hxx> |
42cf5bc1 | 76 | #include <Graphic3d_AspectMarker3d.hxx> |
77 | #include <Graphic3d_GraphicDriver.hxx> | |
78 | #include <Graphic3d_Group.hxx> | |
b5ac8292 | 79 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
80 | #include <Graphic3d_MapOfStructure.hxx> | |
42cf5bc1 | 81 | #include <Graphic3d_Structure.hxx> |
b5ac8292 | 82 | #include <Graphic3d_TextureEnv.hxx> |
42cf5bc1 | 83 | #include <Graphic3d_Vector.hxx> |
84 | #include <Image_AlienPixMap.hxx> | |
85 | #include <NCollection_Array1.hxx> | |
86 | #include <Precision.hxx> | |
87 | #include <Quantity_Color.hxx> | |
88 | #include <Standard_Assert.hxx> | |
89 | #include <Standard_DivideByZero.hxx> | |
90 | #include <Standard_ErrorHandler.hxx> | |
91 | #include <Standard_MultiplyDefined.hxx> | |
92 | #include <Standard_ShortReal.hxx> | |
93 | #include <Standard_Type.hxx> | |
94 | #include <Standard_TypeMismatch.hxx> | |
95 | #include <TColStd_Array2OfReal.hxx> | |
96 | #include <TColStd_HSequenceOfInteger.hxx> | |
97 | #include <V3d.hxx> | |
98 | #include <V3d_BadValue.hxx> | |
42cf5bc1 | 99 | #include <V3d_Light.hxx> |
100 | #include <V3d_StereoDumpOptions.hxx> | |
101 | #include <V3d_UnMapped.hxx> | |
102 | #include <V3d_View.hxx> | |
103 | #include <V3d_Viewer.hxx> | |
42cf5bc1 | 104 | #include <Visual3d_Light.hxx> |
105 | #include <Visual3d_View.hxx> | |
106 | #include <Visual3d_ViewManager.hxx> | |
7fd59977 | 107 | |
de75ed09 | 108 | #define V3d_FLAG_COMPUTATION 0x00000004 |
7fd59977 | 109 | |
110 | // Perspective | |
111 | #include <OSD_Environment.hxx> | |
112 | ||
113 | /*----------------------------------------------------------------------*/ | |
114 | /* | |
115 | * Constant | |
116 | */ | |
117 | ||
c6541a0c | 118 | #define DEUXPI (2. * M_PI) |
7fd59977 | 119 | |
4af098ba | 120 | namespace |
121 | { | |
122 | static const Standard_Integer THE_NB_BOUND_POINTS = 8; | |
123 | } | |
124 | ||
197ac94e | 125 | //============================================================================= |
126 | //function : Constructor | |
127 | //purpose : | |
128 | //============================================================================= | |
7fd59977 | 129 | V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) : |
b5ac8292 | 130 | MyViewer(VM.operator->()), |
131 | MyActiveLights(), | |
132 | MyViewContext (), | |
133 | myActiveLightsIterator(), | |
197ac94e | 134 | SwitchSetFront(Standard_False), |
6bc6a6fc | 135 | MyTrsf (1, 4, 1, 4) |
7fd59977 | 136 | { |
7fd59977 | 137 | myImmediateUpdate = Standard_False; |
138 | MyView = new Visual3d_View(MyViewer->Viewer()); | |
139 | ||
140 | // { Begin to retrieve the definition from ViewContext. | |
141 | // Step MyViewContext = MyView->Context() ; | |
142 | // to permit MyView->SetContext to compare | |
143 | // the old and the new context. | |
144 | // No problem for MyViewMapping, MyViewOrientation | |
145 | // as MyView->SetViewMapping and MyView->SetViewOrientation | |
146 | // don't try to optimize the modifications introduced to | |
147 | // viewmapping and vieworientation. | |
148 | ||
149 | // Aliasing | |
150 | if ((MyView->Context ()).AliasingIsOn ()) | |
151 | MyViewContext.SetAliasingOn (); | |
152 | else | |
153 | MyViewContext.SetAliasingOff (); | |
154 | ||
155 | // DepthCueing | |
156 | MyViewContext.SetDepthCueingBackPlane | |
157 | ((MyView->Context ()).DepthCueingBackPlane ()); | |
158 | MyViewContext.SetDepthCueingFrontPlane | |
159 | ((MyView->Context ()).DepthCueingFrontPlane ()); | |
160 | ||
161 | if ((MyView->Context ()).DepthCueingIsOn ()) | |
162 | MyViewContext.SetDepthCueingOn (); | |
163 | else | |
164 | MyViewContext.SetDepthCueingOff (); | |
165 | ||
166 | // ZClipping | |
167 | MyViewContext.SetZClippingBackPlane | |
168 | ((MyView->Context ()).ZClippingBackPlane ()); | |
169 | MyViewContext.SetZClippingFrontPlane | |
170 | ((MyView->Context ()).ZClippingFrontPlane ()); | |
171 | ||
172 | if ((MyView->Context ()).FrontZClippingIsOn ()) | |
173 | MyViewContext.SetFrontZClippingOn (); | |
174 | else | |
175 | MyViewContext.SetFrontZClippingOff (); | |
176 | ||
177 | if ((MyView->Context ()).BackZClippingIsOn ()) | |
178 | MyViewContext.SetBackZClippingOn (); | |
179 | else | |
180 | MyViewContext.SetBackZClippingOff (); | |
181 | ||
b5ac8292 | 182 | // Visualization and Shading Model |
7fd59977 | 183 | MyViewContext.SetModel ((MyView->Context ()).Model ()); |
184 | MyViewContext.SetVisualization ((MyView->Context ()).Visualization ()); | |
185 | ||
186 | // Texture Mapping | |
187 | MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ()); | |
188 | MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ()); | |
189 | // } End of retrieval of the definition of ViewContext. | |
190 | ||
7fd59977 | 191 | MyBackground = VM->GetBackgroundColor() ; |
192 | MyGradientBackground = VM->GetGradientBackground() ; | |
193 | ||
b5ac8292 | 194 | // camera init |
195 | Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera(); | |
196 | aCamera->SetFOVy (45.0); | |
197 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05); | |
198 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0); | |
199 | SetCamera (aCamera); | |
200 | ||
201 | SetAxis (0.,0.,0.,1.,1.,1.); | |
202 | SetVisualization (VM->DefaultVisualization()); | |
203 | SetShadingModel (VM->DefaultShadingModel()); | |
204 | SetSurfaceDetail (VM->DefaultSurfaceDetail()); | |
205 | SetTwist (0.); | |
206 | SetAt (0.,0.,0.); | |
207 | SetProj (VM->DefaultViewProj()); | |
208 | SetSize (VM->DefaultViewSize()); | |
7fd59977 | 209 | Standard_Real zsize = VM->DefaultViewSize(); |
b5ac8292 | 210 | SetZSize (2.*zsize); |
211 | SetZClippingDepth (0.); | |
212 | SetZClippingWidth (zsize); | |
213 | SetZCueingDepth (0.); | |
214 | SetZCueingWidth (zsize); | |
215 | SetDepth (VM->DefaultViewSize()/2.0); | |
7fd59977 | 216 | SetViewMappingDefault(); |
fc8eab5e | 217 | SetViewOrientationDefault(); |
b5ac8292 | 218 | VM->AddView (this); |
7fd59977 | 219 | Init(); |
220 | myImmediateUpdate = Standard_True; | |
221 | ||
b5ac8292 | 222 | aCamera->SetProjectionType ((Type == V3d_ORTHOGRAPHIC) |
223 | ? Graphic3d_Camera::Projection_Orthographic | |
224 | : Graphic3d_Camera::Projection_Perspective); | |
7fd59977 | 225 | } |
226 | ||
197ac94e | 227 | //============================================================================= |
228 | //function : Constructor | |
229 | //purpose : | |
230 | //============================================================================= | |
b5ac8292 | 231 | V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) : |
197ac94e | 232 | MyViewer(theVM.operator->()), |
233 | MyActiveLights(), | |
234 | MyViewContext (), | |
235 | myActiveLightsIterator(), | |
236 | SwitchSetFront(Standard_False), | |
237 | MyTrsf (1, 4, 1, 4) | |
7fd59977 | 238 | { |
b5ac8292 | 239 | Handle(Visual3d_View) aFromView = theView->View(); |
7fd59977 | 240 | |
241 | myImmediateUpdate = Standard_False; | |
b5ac8292 | 242 | MyView = new Visual3d_View (MyViewer->Viewer()); |
7fd59977 | 243 | |
b5ac8292 | 244 | for (theView->InitActiveLights(); theView->MoreActiveLights(); theView->NextActiveLights()) |
245 | { | |
246 | MyActiveLights.Append (theView->ActiveLight()); | |
247 | } | |
7fd59977 | 248 | |
b5ac8292 | 249 | MyViewContext = aFromView->Context() ; |
7fd59977 | 250 | |
b5ac8292 | 251 | SetCamera (new Graphic3d_Camera (theView->Camera())); |
6bc6a6fc | 252 | View()->SetAutoZFitMode (theView->View()->AutoZFitMode(), theView->View()->AutoZFitScaleFactor()); |
7fd59977 | 253 | |
b5ac8292 | 254 | MyBackground = aFromView->Background() ; |
255 | MyGradientBackground = aFromView->GradientBackground(); | |
256 | ||
257 | MyView->SetContext (MyViewContext) ; | |
258 | ||
259 | SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0); | |
260 | ||
fc8eab5e | 261 | SetViewMappingDefault(); |
262 | SetViewOrientationDefault(); | |
b5ac8292 | 263 | theVM->AddView (this); |
7fd59977 | 264 | |
7fd59977 | 265 | Init(); |
b5ac8292 | 266 | |
7fd59977 | 267 | myImmediateUpdate = Standard_True; |
7fd59977 | 268 | } |
269 | ||
197ac94e | 270 | //============================================================================= |
271 | //function : SetMagnify | |
272 | //purpose : | |
273 | //============================================================================= | |
7fd59977 | 274 | void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow, |
275 | const Handle(V3d_View)& aPreviousView, | |
276 | const Standard_Integer x1, | |
277 | const Standard_Integer y1, | |
278 | const Standard_Integer x2, | |
279 | const Standard_Integer y2) | |
280 | { | |
7fd59977 | 281 | if( !MyView->IsDefined() ) { |
282 | Standard_Real a,b,c,d; | |
283 | aPreviousView->Convert(x1,y1,a,b); | |
284 | aPreviousView->Convert(x2,y2,c,d); | |
285 | MyView->SetWindow(TheWindow) ; | |
286 | FitAll(TheWindow,a,b,c,d); | |
287 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 288 | MyView->SetBackground(MyBackground) ; |
289 | MyViewer->SetViewOn(this) ; | |
290 | MyWindow = TheWindow; | |
291 | MyView->Redraw() ; | |
292 | SetViewMappingDefault(); | |
293 | } | |
7fd59977 | 294 | } |
295 | ||
197ac94e | 296 | //============================================================================= |
297 | //function : SetWindow | |
298 | //purpose : | |
299 | //============================================================================= | |
7fd59977 | 300 | void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow) |
301 | { | |
7fd59977 | 302 | MyView->SetWindow(TheWindow) ; |
05e2200b | 303 | // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw() |
cdc2203b | 304 | MyWindow = TheWindow; |
7fd59977 | 305 | // SetWindow carries out SetRatio and modifies |
7fd59977 | 306 | MyView->SetContext(MyViewContext) ; |
7fd59977 | 307 | MyView->SetBackground(MyBackground) ; |
f42753ed | 308 | MyView->SetGradientBackground (MyGradientBackground, Standard_False); |
7fd59977 | 309 | MyViewer->SetViewOn(this) ; |
7fd59977 | 310 | MyView->Redraw() ; |
7fd59977 | 311 | } |
312 | ||
197ac94e | 313 | //============================================================================= |
314 | //function : SetWindow | |
315 | //purpose : | |
316 | //============================================================================= | |
7fd59977 | 317 | void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow, |
318 | const Aspect_RenderingContext aContext, | |
319 | const Aspect_GraphicCallbackProc& aDisplayCB, | |
320 | const Standard_Address aClientData) | |
321 | { | |
05e2200b | 322 | // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw() |
cdc2203b | 323 | MyWindow = aWindow; |
7fd59977 | 324 | MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ; |
7fd59977 | 325 | MyView->SetContext(MyViewContext) ; |
7fd59977 | 326 | MyView->SetBackground(MyBackground) ; |
ba38396e | 327 | MyView->SetGradientBackground (MyGradientBackground, Standard_False); |
7fd59977 | 328 | MyViewer->SetViewOn(this) ; |
329 | MyView->Redraw() ; | |
7fd59977 | 330 | } |
7fd59977 | 331 | |
197ac94e | 332 | //============================================================================= |
333 | //function : Remove | |
334 | //purpose : | |
335 | //============================================================================= | |
5e27df78 | 336 | void V3d_View::Remove() const |
337 | { | |
338 | MyViewer->DelView (this); | |
339 | MyView->Remove(); | |
340 | Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow); | |
341 | aWin.Nullify(); | |
7fd59977 | 342 | } |
343 | ||
197ac94e | 344 | //============================================================================= |
345 | //function : Update | |
346 | //purpose : | |
347 | //============================================================================= | |
b8ddfc2f | 348 | void V3d_View::Update() const |
349 | { | |
6bc6a6fc | 350 | if( MyView->IsDefined() ) MyView->Update (Aspect_TOU_ASAP) ; |
7fd59977 | 351 | } |
352 | ||
197ac94e | 353 | //============================================================================= |
354 | //function : Redraw | |
355 | //purpose : | |
356 | //============================================================================= | |
b8ddfc2f | 357 | void V3d_View::Redraw() const |
358 | { | |
7fd59977 | 359 | if( MyView->IsDefined() ) MyView->Redraw() ; |
360 | } | |
b8ddfc2f | 361 | |
679ecdee | 362 | //============================================================================= |
363 | //function : RedrawImmediate | |
364 | //purpose : | |
365 | //============================================================================= | |
366 | void V3d_View::RedrawImmediate() const | |
367 | { | |
368 | if (MyView->IsDefined()) | |
369 | { | |
370 | MyView->RedrawImmediate(); | |
371 | } | |
372 | } | |
373 | ||
374 | //============================================================================= | |
375 | //function : Invalidate | |
376 | //purpose : | |
377 | //============================================================================= | |
378 | void V3d_View::Invalidate() const | |
379 | { | |
380 | if (MyView->IsDefined()) | |
381 | { | |
382 | MyView->Invalidate(); | |
383 | } | |
384 | } | |
385 | ||
6bc6a6fc | 386 | //============================================================================= |
62e1beed | 387 | //function : IsInvalidated |
388 | //purpose : | |
389 | //============================================================================= | |
390 | Standard_Boolean V3d_View::IsInvalidated() const | |
391 | { | |
392 | return !MyView->IsDefined() | |
393 | || MyView->IsInvalidated(); | |
394 | } | |
395 | ||
396 | //============================================================================= | |
6bc6a6fc | 397 | //function : AutoZFit |
398 | //purpose : | |
399 | //============================================================================= | |
400 | void V3d_View::AutoZFit() | |
401 | { | |
402 | View()->AutoZFit(); | |
403 | } | |
404 | ||
405 | //============================================================================= | |
406 | //function : ZFitAll | |
407 | //purpose : | |
408 | //============================================================================= | |
409 | void V3d_View::ZFitAll (const Standard_Real theScaleFactor) | |
410 | { | |
411 | View()->ZFitAll (theScaleFactor); | |
412 | } | |
413 | ||
197ac94e | 414 | //============================================================================= |
415 | //function : Redraw | |
416 | //purpose : | |
417 | //============================================================================= | |
7fd59977 | 418 | void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc, |
419 | const Standard_Integer width,const Standard_Integer height) const | |
420 | { | |
421 | if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ; | |
422 | } | |
423 | ||
197ac94e | 424 | //============================================================================= |
425 | //function : IsEmpty | |
426 | //purpose : | |
427 | //============================================================================= | |
b8ddfc2f | 428 | Standard_Boolean V3d_View::IsEmpty() const |
429 | { | |
7fd59977 | 430 | Standard_Boolean TheStatus = Standard_True ; |
431 | if( MyView->IsDefined() ) { | |
432 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
433 | if( Nstruct > 0 ) TheStatus = Standard_False ; | |
434 | } | |
435 | return (TheStatus) ; | |
7fd59977 | 436 | } |
437 | ||
197ac94e | 438 | //============================================================================= |
439 | //function : UpdateLights | |
440 | //purpose : | |
441 | //============================================================================= | |
b8ddfc2f | 442 | void V3d_View::UpdateLights() const |
443 | { | |
7fd59977 | 444 | MyView->SetContext(MyViewContext); |
445 | Update(); | |
446 | } | |
447 | ||
197ac94e | 448 | //============================================================================= |
449 | //function : DoMapping | |
450 | //purpose : | |
451 | //============================================================================= | |
b8ddfc2f | 452 | void V3d_View::DoMapping() |
453 | { | |
7fd59977 | 454 | if( MyView->IsDefined() ) { |
455 | (MyView->Window())->DoMapping() ; | |
456 | } | |
457 | } | |
458 | ||
197ac94e | 459 | //============================================================================= |
460 | //function : MustBeResized | |
461 | //purpose : | |
462 | //============================================================================= | |
b8ddfc2f | 463 | void V3d_View::MustBeResized() |
464 | { | |
7fd59977 | 465 | if( MyView->IsDefined() ) { |
466 | MyView->Resized() ; | |
7fd59977 | 467 | MyView->Redraw(); |
468 | } | |
7fd59977 | 469 | } |
470 | ||
197ac94e | 471 | //============================================================================= |
472 | //function : SetBackgroundColor | |
473 | //purpose : | |
474 | //============================================================================= | |
7fd59977 | 475 | void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) |
476 | { | |
477 | Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 ); | |
478 | Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 ); | |
479 | Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 ); | |
480 | ||
481 | Quantity_Color C( V1, V2, V3, Type ); | |
7fd59977 | 482 | SetBackgroundColor( C ); |
7fd59977 | 483 | } |
484 | ||
197ac94e | 485 | //============================================================================= |
486 | //function : SetBackgroundColor | |
487 | //purpose : | |
488 | //============================================================================= | |
7fd59977 | 489 | void V3d_View::SetBackgroundColor(const Quantity_Color &Color) |
490 | { | |
491 | MyBackground.SetColor( Color ); | |
492 | if ( MyView->IsDefined() ) | |
493 | MyView->SetBackground( MyBackground ); | |
7fd59977 | 494 | } |
7fd59977 | 495 | |
197ac94e | 496 | //============================================================================= |
497 | //function : SetBackgroundColor | |
498 | //purpose : | |
499 | //============================================================================= | |
7fd59977 | 500 | void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name) |
501 | { | |
502 | Quantity_Color C( Name ); | |
7fd59977 | 503 | SetBackgroundColor( C ); |
7fd59977 | 504 | } |
505 | ||
197ac94e | 506 | //============================================================================= |
507 | //function : SetBgGradientColors | |
508 | //purpose : | |
509 | //============================================================================= | |
7fd59977 | 510 | void V3d_View::SetBgGradientColors( const Quantity_Color& Color1, |
511 | const Quantity_Color& Color2, | |
512 | const Aspect_GradientFillMethod FillStyle, | |
513 | const Standard_Boolean status) | |
514 | { | |
7fd59977 | 515 | MyGradientBackground.SetColors(Color1, Color2, FillStyle); |
516 | if ( MyView->IsDefined() ) | |
517 | MyView->SetGradientBackground( MyGradientBackground, status ); | |
7fd59977 | 518 | } |
519 | ||
197ac94e | 520 | //============================================================================= |
521 | //function : SetBgGradientColors | |
522 | //purpose : | |
523 | //============================================================================= | |
7fd59977 | 524 | void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1, |
525 | const Quantity_NameOfColor Color2, | |
526 | const Aspect_GradientFillMethod FillStyle, | |
527 | const Standard_Boolean status ) | |
528 | { | |
529 | Quantity_Color C1( Color1 ); | |
530 | Quantity_Color C2( Color2 ); | |
531 | MyGradientBackground.SetColors( C1, C2, FillStyle ); | |
532 | if ( MyView->IsDefined() ) | |
533 | MyView->SetGradientBackground( MyGradientBackground, status ); | |
534 | } | |
535 | ||
197ac94e | 536 | //============================================================================= |
537 | //function : SetBgGradientStyle | |
538 | //purpose : | |
539 | //============================================================================= | |
7fd59977 | 540 | void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle, |
f8b2ed36 | 541 | const Standard_Boolean update) |
7fd59977 | 542 | { |
f8b2ed36 | 543 | Quantity_Color Color1, Color2; |
544 | MyGradientBackground.Colors( Color1, Color2 ); | |
545 | MyGradientBackground.SetColors( Color1, Color2, FillStyle ); | |
7fd59977 | 546 | if( MyView->IsDefined() ) |
f8b2ed36 | 547 | MyView->SetBgGradientStyle( FillStyle, update ) ; |
7fd59977 | 548 | } |
549 | ||
197ac94e | 550 | //============================================================================= |
551 | //function : SetBackgroundImage | |
552 | //purpose : | |
553 | //============================================================================= | |
7fd59977 | 554 | void V3d_View::SetBackgroundImage( const Standard_CString FileName, |
555 | const Aspect_FillMethod FillStyle, | |
556 | const Standard_Boolean update ) | |
557 | { | |
7fd59977 | 558 | if( MyView->IsDefined() ) |
559 | MyView->SetBackgroundImage( FileName, FillStyle, update ) ; | |
7fd59977 | 560 | } |
561 | ||
197ac94e | 562 | //============================================================================= |
563 | //function : SetBgImageStyle | |
564 | //purpose : | |
565 | //============================================================================= | |
7fd59977 | 566 | void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle, |
567 | const Standard_Boolean update ) | |
568 | { | |
7fd59977 | 569 | if( MyView->IsDefined() ) |
570 | MyView->SetBgImageStyle( FillStyle, update ) ; | |
7fd59977 | 571 | } |
572 | ||
197ac94e | 573 | //============================================================================= |
574 | //function : SetAxis | |
575 | //purpose : | |
576 | //============================================================================= | |
b8ddfc2f | 577 | void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) |
578 | { | |
7fd59977 | 579 | Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ; |
580 | ||
581 | D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ; | |
6942f04a | 582 | V3d_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis"); |
7fd59977 | 583 | Nx /= D ; Ny /= D ; Nz /= D ; |
584 | MyDefaultViewPoint.SetCoord(X,Y,Z) ; | |
585 | MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ; | |
7fd59977 | 586 | } |
587 | ||
197ac94e | 588 | //============================================================================= |
589 | //function : SetShadingModel | |
590 | //purpose : | |
591 | //============================================================================= | |
b8ddfc2f | 592 | void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) |
593 | { | |
7fd59977 | 594 | MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ; |
595 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 596 | } |
597 | ||
197ac94e | 598 | //============================================================================= |
599 | //function : SetSurfaceDetail | |
600 | //purpose : | |
601 | //============================================================================= | |
b8ddfc2f | 602 | void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) |
603 | { | |
7fd59977 | 604 | MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ; |
605 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 606 | } |
607 | ||
197ac94e | 608 | //============================================================================= |
609 | //function : SetTextureEnv | |
610 | //purpose : | |
611 | //============================================================================= | |
b8ddfc2f | 612 | void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) |
613 | { | |
7fd59977 | 614 | MyViewContext.SetTextureEnv(ATexture) ; |
615 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 616 | } |
617 | ||
197ac94e | 618 | //============================================================================= |
619 | //function : SetVisualization | |
620 | //purpose : | |
621 | //============================================================================= | |
b8ddfc2f | 622 | void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) |
623 | { | |
7fd59977 | 624 | MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode); |
625 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 626 | } |
627 | ||
197ac94e | 628 | //============================================================================= |
629 | //function : SetFront | |
630 | //purpose : | |
631 | //============================================================================= | |
b8ddfc2f | 632 | void V3d_View::SetFront() |
633 | { | |
7fd59977 | 634 | gp_Ax3 a = MyViewer->PrivilegedPlane(); |
b5ac8292 | 635 | Standard_Real xo, yo, zo, vx, vy, vz, xu, yu, zu; |
7fd59977 | 636 | |
637 | a.Direction().Coord(vx,vy,vz); | |
638 | a.YDirection().Coord(xu,yu,zu); | |
639 | a.Location().Coord(xo,yo,zo); | |
640 | ||
b5ac8292 | 641 | myCamera->SetCenter (gp_Pnt (xo, yo, zo)); |
7fd59977 | 642 | if(SwitchSetFront) |
b5ac8292 | 643 | myCamera->SetDirection (gp_Dir (vx, vy, vz)); |
7fd59977 | 644 | else |
b5ac8292 | 645 | myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed()); |
646 | myCamera->SetUp (gp_Dir (xu, yu, zu)); | |
7fd59977 | 647 | |
6bc6a6fc | 648 | View()->AutoZFit(); |
7fd59977 | 649 | |
b5ac8292 | 650 | SwitchSetFront = !SwitchSetFront; |
7fd59977 | 651 | |
652 | ImmediateUpdate(); | |
7fd59977 | 653 | } |
654 | ||
197ac94e | 655 | //============================================================================= |
656 | //function : Rotate | |
657 | //purpose : | |
658 | //============================================================================= | |
b5ac8292 | 659 | void V3d_View::Rotate (const Standard_Real ax, |
660 | const Standard_Real ay, | |
661 | const Standard_Real az, | |
662 | const Standard_Boolean Start) | |
b8ddfc2f | 663 | { |
b5ac8292 | 664 | Standard_Real Ax = ax; |
665 | Standard_Real Ay = ay; | |
666 | Standard_Real Az = az; | |
7fd59977 | 667 | |
b5ac8292 | 668 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI; |
669 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI; | |
670 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI; | |
671 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI; | |
672 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI; | |
673 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI; | |
674 | ||
675 | if (Start) | |
676 | { | |
677 | myCamStartOpUp = myCamera->Up(); | |
678 | myCamStartOpEye = myCamera->Eye(); | |
679 | myCamStartOpCenter = myCamera->Center(); | |
680 | } | |
681 | ||
b5ac8292 | 682 | myCamera->SetUp (myCamStartOpUp); |
683 | myCamera->SetEye (myCamStartOpEye); | |
684 | myCamera->SetCenter (myCamStartOpCenter); | |
685 | ||
686 | // rotate camera around 3 initial axes | |
687 | gp_Dir aBackDir (gp_Vec (myCamStartOpCenter, myCamStartOpEye)); | |
688 | gp_Dir aXAxis (myCamStartOpUp.Crossed (aBackDir)); | |
689 | gp_Dir aYAxis (aBackDir.Crossed (aXAxis)); | |
690 | gp_Dir aZAxis (aXAxis.Crossed (aYAxis)); | |
691 | ||
692 | gp_Trsf aRot[3], aTrsf; | |
693 | aRot[0].SetRotation (gp_Ax1 (myCamStartOpCenter, aYAxis), -Ax); | |
694 | aRot[1].SetRotation (gp_Ax1 (myCamStartOpCenter, aXAxis), Ay); | |
695 | aRot[2].SetRotation (gp_Ax1 (myCamStartOpCenter, aZAxis), Az); | |
696 | aTrsf.Multiply (aRot[0]); | |
697 | aTrsf.Multiply (aRot[1]); | |
698 | aTrsf.Multiply (aRot[2]); | |
699 | ||
700 | myCamera->Transform (aTrsf); | |
701 | ||
6bc6a6fc | 702 | View()->AutoZFit(); |
7fd59977 | 703 | |
7fd59977 | 704 | ImmediateUpdate(); |
7fd59977 | 705 | } |
706 | ||
197ac94e | 707 | //============================================================================= |
708 | //function : Rotate | |
709 | //purpose : | |
710 | //============================================================================= | |
7fd59977 | 711 | void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, |
712 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start) | |
713 | { | |
b5ac8292 | 714 | |
7fd59977 | 715 | Standard_Real Ax = ax ; |
716 | Standard_Real Ay = ay ; | |
717 | Standard_Real Az = az ; | |
7fd59977 | 718 | |
719 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ; | |
720 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ; | |
721 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ; | |
722 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ; | |
723 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; | |
724 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; | |
725 | ||
b5ac8292 | 726 | if (Start) |
727 | { | |
728 | myGravityReferencePoint.SetCoord (X, Y, Z); | |
729 | myCamStartOpUp = myCamera->Up(); | |
730 | myCamStartOpEye = myCamera->Eye(); | |
731 | myCamStartOpCenter = myCamera->Center(); | |
732 | } | |
733 | ||
734 | const Graphic3d_Vertex& aVref = myGravityReferencePoint; | |
735 | ||
b5ac8292 | 736 | myCamera->SetUp (myCamStartOpUp); |
737 | myCamera->SetEye (myCamStartOpEye); | |
738 | myCamera->SetCenter (myCamStartOpCenter); | |
739 | ||
740 | // rotate camera around 3 initial axes | |
741 | gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z()); | |
742 | ||
743 | gp_Dir aZAxis (myCamera->Direction().Reversed()); | |
744 | gp_Dir aYAxis (myCamera->Up()); | |
745 | gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); | |
746 | ||
747 | gp_Trsf aRot[3], aTrsf; | |
748 | aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax); | |
749 | aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay); | |
750 | aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az); | |
751 | aTrsf.Multiply (aRot[0]); | |
752 | aTrsf.Multiply (aRot[1]); | |
753 | aTrsf.Multiply (aRot[2]); | |
754 | ||
755 | myCamera->Transform (aTrsf); | |
b5ac8292 | 756 | |
6bc6a6fc | 757 | View()->AutoZFit(); |
b5ac8292 | 758 | |
7fd59977 | 759 | ImmediateUpdate(); |
7fd59977 | 760 | } |
761 | ||
197ac94e | 762 | //============================================================================= |
763 | //function : Rotate | |
764 | //purpose : | |
765 | //============================================================================= | |
b8ddfc2f | 766 | void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) |
767 | { | |
7fd59977 | 768 | switch (Axe) { |
769 | case V3d_X : | |
770 | Rotate(angle,0.,0.,Start); | |
771 | break ; | |
772 | case V3d_Y : | |
773 | Rotate(0.,angle,0.,Start); | |
774 | break ; | |
775 | case V3d_Z : | |
776 | Rotate(0.,0.,angle,Start); | |
777 | break ; | |
778 | } | |
7fd59977 | 779 | } |
780 | ||
197ac94e | 781 | //============================================================================= |
782 | //function : Rotate | |
783 | //purpose : | |
784 | //============================================================================= | |
7fd59977 | 785 | void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, |
786 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start) | |
787 | { | |
7fd59977 | 788 | Standard_Real Angle = angle ; |
7fd59977 | 789 | |
790 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
791 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
792 | ||
b5ac8292 | 793 | if (Start) |
794 | { | |
795 | myGravityReferencePoint.SetCoord (X, Y, Z); | |
796 | myCamStartOpUp = myCamera->Up(); | |
797 | myCamStartOpEye = myCamera->Eye(); | |
798 | myCamStartOpCenter = myCamera->Center(); | |
799 | ||
7fd59977 | 800 | switch (Axe) { |
801 | case V3d_X : | |
b5ac8292 | 802 | myViewAxis.SetCoord(1.,0.,0.) ; |
7fd59977 | 803 | break ; |
804 | case V3d_Y : | |
b5ac8292 | 805 | myViewAxis.SetCoord(0.,1.,0.) ; |
7fd59977 | 806 | break ; |
807 | case V3d_Z : | |
b5ac8292 | 808 | myViewAxis.SetCoord(0.,0.,1.) ; |
7fd59977 | 809 | break ; |
810 | } | |
b5ac8292 | 811 | |
812 | myCamStartOpUp = myCamera->Up(); | |
813 | myCamStartOpEye = myCamera->Eye(); | |
814 | myCamStartOpCenter = myCamera->Center(); | |
7fd59977 | 815 | } |
816 | ||
b5ac8292 | 817 | const Graphic3d_Vertex& aVref = myGravityReferencePoint; |
818 | ||
b5ac8292 | 819 | myCamera->SetUp (myCamStartOpUp); |
820 | myCamera->SetEye (myCamStartOpEye); | |
821 | myCamera->SetCenter (myCamStartOpCenter); | |
822 | ||
823 | // rotate camera around passed axis | |
824 | gp_Trsf aRotation; | |
825 | gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z()); | |
826 | gp_Dir aRAxis ((Axe == V3d_X) ? 1.0 : 0.0, | |
827 | (Axe == V3d_Y) ? 1.0 : 0.0, | |
828 | (Axe == V3d_Z) ? 1.0 : 0.0); | |
829 | ||
830 | aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); | |
831 | myCamera->Transform (aRotation); | |
832 | ||
6bc6a6fc | 833 | View()->AutoZFit(); |
b5ac8292 | 834 | |
7fd59977 | 835 | ImmediateUpdate(); |
7fd59977 | 836 | } |
837 | ||
197ac94e | 838 | //============================================================================= |
839 | //function : Rotate | |
840 | //purpose : | |
841 | //============================================================================= | |
b8ddfc2f | 842 | void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) |
843 | { | |
b5ac8292 | 844 | Standard_Real Angle = angle; |
7fd59977 | 845 | |
846 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
847 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
848 | ||
849 | if( Start ) { | |
b5ac8292 | 850 | myCamStartOpUp = myCamera->Up(); |
851 | myCamStartOpEye = myCamera->Eye(); | |
852 | myCamStartOpCenter = myCamera->Center(); | |
7fd59977 | 853 | } |
854 | ||
b5ac8292 | 855 | const Graphic3d_Vertex& aPnt = MyDefaultViewPoint; |
856 | const Graphic3d_Vector& anAxis = MyDefaultViewAxis; | |
857 | ||
b5ac8292 | 858 | myCamera->SetUp (myCamStartOpUp); |
859 | myCamera->SetEye (myCamStartOpEye); | |
860 | myCamera->SetCenter (myCamStartOpCenter); | |
861 | ||
862 | gp_Trsf aRotation; | |
863 | gp_Pnt aRCenter (aPnt.X(), aPnt.Y(), aPnt.Z()); | |
864 | gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z()); | |
865 | aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); | |
866 | myCamera->Transform (aRotation); | |
867 | ||
6bc6a6fc | 868 | View()->AutoZFit(); |
b5ac8292 | 869 | |
7fd59977 | 870 | ImmediateUpdate(); |
7fd59977 | 871 | } |
872 | ||
197ac94e | 873 | //============================================================================= |
874 | //function : Turn | |
875 | //purpose : | |
876 | //============================================================================= | |
7fd59977 | 877 | void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) |
878 | { | |
b5ac8292 | 879 | Standard_Real Ax = ax; |
880 | Standard_Real Ay = ay; | |
881 | Standard_Real Az = az; | |
7fd59977 | 882 | |
883 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ; | |
884 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ; | |
885 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ; | |
886 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ; | |
887 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; | |
888 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; | |
889 | ||
890 | if( Start ) { | |
b5ac8292 | 891 | myCamStartOpUp = myCamera->Up(); |
892 | myCamStartOpEye = myCamera->Eye(); | |
893 | myCamStartOpCenter = myCamera->Center(); | |
894 | } | |
895 | ||
b5ac8292 | 896 | myCamera->SetUp (myCamStartOpUp); |
897 | myCamera->SetEye (myCamStartOpEye); | |
898 | myCamera->SetCenter (myCamStartOpCenter); | |
899 | ||
900 | // rotate camera around 3 initial axes | |
901 | gp_Pnt aRCenter = myCamera->Eye(); | |
902 | gp_Dir aZAxis (myCamera->Direction().Reversed()); | |
903 | gp_Dir aYAxis (myCamera->Up()); | |
904 | gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); | |
905 | ||
906 | gp_Trsf aRot[3], aTrsf; | |
907 | aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax); | |
908 | aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay); | |
909 | aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az); | |
910 | aTrsf.Multiply (aRot[0]); | |
911 | aTrsf.Multiply (aRot[1]); | |
912 | aTrsf.Multiply (aRot[2]); | |
913 | ||
914 | myCamera->Transform (aTrsf); | |
b5ac8292 | 915 | |
6bc6a6fc | 916 | View()->AutoZFit(); |
b5ac8292 | 917 | |
918 | ImmediateUpdate(); | |
7fd59977 | 919 | } |
920 | ||
197ac94e | 921 | //============================================================================= |
922 | //function : Turn | |
923 | //purpose : | |
924 | //============================================================================= | |
7fd59977 | 925 | void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) |
926 | { | |
7fd59977 | 927 | switch (Axe) { |
928 | case V3d_X : | |
929 | Turn(angle,0.,0.,Start); | |
930 | break ; | |
931 | case V3d_Y : | |
932 | Turn(0.,angle,0.,Start); | |
933 | break ; | |
934 | case V3d_Z : | |
935 | Turn(0.,0.,angle,Start); | |
936 | break ; | |
937 | } | |
938 | } | |
939 | ||
197ac94e | 940 | //============================================================================= |
941 | //function : Turn | |
942 | //purpose : | |
943 | //============================================================================= | |
b8ddfc2f | 944 | void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) |
945 | { | |
7fd59977 | 946 | Standard_Real Angle = angle ; |
7fd59977 | 947 | |
948 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
949 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
950 | ||
951 | if( Start ) { | |
b5ac8292 | 952 | myCamStartOpUp = myCamera->Up(); |
953 | myCamStartOpEye = myCamera->Eye(); | |
954 | myCamStartOpCenter = myCamera->Center(); | |
955 | } | |
956 | ||
b5ac8292 | 957 | myCamera->SetUp (myCamStartOpUp); |
958 | myCamera->SetEye (myCamStartOpEye); | |
959 | myCamera->SetCenter (myCamStartOpCenter); | |
960 | ||
961 | const Graphic3d_Vector& anAxis = MyDefaultViewAxis; | |
962 | ||
963 | gp_Trsf aRotation; | |
964 | gp_Pnt aRCenter = myCamera->Eye(); | |
965 | gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z()); | |
966 | aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); | |
967 | myCamera->Transform (aRotation); | |
968 | ||
6bc6a6fc | 969 | View()->AutoZFit(); |
b5ac8292 | 970 | |
971 | ImmediateUpdate(); | |
7fd59977 | 972 | } |
973 | ||
197ac94e | 974 | //============================================================================= |
975 | //function : SetTwist | |
976 | //purpose : | |
977 | //============================================================================= | |
b8ddfc2f | 978 | void V3d_View::SetTwist(const Standard_Real angle) |
979 | { | |
7fd59977 | 980 | Standard_Real Angle = angle ; |
b5ac8292 | 981 | Standard_Boolean TheStatus; |
7fd59977 | 982 | |
983 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
984 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
985 | ||
b5ac8292 | 986 | gp_Dir aReferencePlane (myCamera->Direction().Reversed()); |
987 | gp_Dir anUp; | |
988 | ||
989 | anUp = gp_Dir (0.0, 0.0, 1.0); | |
990 | ||
991 | TheStatus = ScreenAxis(aReferencePlane, anUp, | |
992 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 993 | if( !TheStatus ) { |
b5ac8292 | 994 | anUp = gp_Dir (0.0, 1.0, 0.0); |
995 | TheStatus = ScreenAxis(aReferencePlane, anUp, | |
996 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 997 | } |
998 | if( !TheStatus ) { | |
b5ac8292 | 999 | anUp = gp_Dir (1.0, 0.0, 0.0); |
1000 | TheStatus = ScreenAxis(aReferencePlane, anUp, | |
1001 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1002 | } |
1003 | ||
6942f04a | 1004 | V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,"); |
b5ac8292 | 1005 | |
1006 | gp_Pnt aRCenter = myCamera->Center(); | |
1007 | gp_Dir aZAxis (myCamera->Direction().Reversed()); | |
1008 | ||
1009 | gp_Trsf aTrsf; | |
1010 | aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle); | |
1011 | ||
1012 | Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; | |
1013 | myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); | |
197ac94e | 1014 | |
b5ac8292 | 1015 | myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); |
1016 | myCamera->Transform (aTrsf); | |
b5ac8292 | 1017 | |
6bc6a6fc | 1018 | View()->AutoZFit(); |
7fd59977 | 1019 | |
7fd59977 | 1020 | ImmediateUpdate(); |
7fd59977 | 1021 | } |
1022 | ||
197ac94e | 1023 | //============================================================================= |
1024 | //function : SetEye | |
1025 | //purpose : | |
1026 | //============================================================================= | |
1027 | void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) | |
1028 | { | |
1029 | Standard_Real aTwistBefore = Twist(); | |
7fd59977 | 1030 | |
197ac94e | 1031 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); |
b5ac8292 | 1032 | |
197ac94e | 1033 | myCamera->SetEye (gp_Pnt (X, Y, Z)); |
1034 | SetTwist (aTwistBefore); | |
b5ac8292 | 1035 | |
6bc6a6fc | 1036 | View()->AutoZFit(); |
b5ac8292 | 1037 | |
197ac94e | 1038 | SetImmediateUpdate (wasUpdateEnabled); |
1039 | ||
b5ac8292 | 1040 | ImmediateUpdate(); |
7fd59977 | 1041 | } |
1042 | ||
197ac94e | 1043 | //============================================================================= |
1044 | //function : SetDepth | |
1045 | //purpose : | |
1046 | //============================================================================= | |
b8ddfc2f | 1047 | void V3d_View::SetDepth(const Standard_Real Depth) |
1048 | { | |
b5ac8292 | 1049 | V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth"); |
7fd59977 | 1050 | |
7fd59977 | 1051 | if( Depth > 0. ) |
7fd59977 | 1052 | { |
b5ac8292 | 1053 | // Move eye using center (target) as anchor. |
1054 | myCamera->SetDistance (Depth); | |
1055 | } | |
1056 | else | |
197ac94e | 1057 | { |
b5ac8292 | 1058 | // Move the view ref point instead of the eye. |
1059 | gp_Vec aDir (myCamera->Direction()); | |
1060 | gp_Pnt aCameraEye = myCamera->Eye(); | |
197ac94e | 1061 | gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth))); |
1062 | ||
b5ac8292 | 1063 | myCamera->SetCenter (aCameraCenter); |
7fd59977 | 1064 | } |
7fd59977 | 1065 | |
6bc6a6fc | 1066 | View()->AutoZFit(); |
b5ac8292 | 1067 | |
1068 | ImmediateUpdate(); | |
7fd59977 | 1069 | } |
1070 | ||
197ac94e | 1071 | //============================================================================= |
1072 | //function : SetProj | |
1073 | //purpose : | |
1074 | //============================================================================= | |
7fd59977 | 1075 | void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz ) |
1076 | { | |
6942f04a | 1077 | V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0., |
7fd59977 | 1078 | "V3d_View::SetProj, null projection vector"); |
1079 | ||
197ac94e | 1080 | Standard_Real aTwistBefore = Twist(); |
b5ac8292 | 1081 | |
197ac94e | 1082 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); |
b5ac8292 | 1083 | |
197ac94e | 1084 | myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed()); |
b5ac8292 | 1085 | |
1521659a | 1086 | SetTwist(aTwistBefore); |
b5ac8292 | 1087 | |
6bc6a6fc | 1088 | View()->AutoZFit(); |
b5ac8292 | 1089 | |
197ac94e | 1090 | SetImmediateUpdate (wasUpdateEnabled); |
1091 | ||
7fd59977 | 1092 | ImmediateUpdate(); |
7fd59977 | 1093 | } |
1094 | ||
197ac94e | 1095 | //============================================================================= |
1096 | //function : SetProj | |
1097 | //purpose : | |
1098 | //============================================================================= | |
b8ddfc2f | 1099 | void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) |
1100 | { | |
7fd59977 | 1101 | Standard_Real Xpn=0; |
1102 | Standard_Real Ypn=0; | |
1103 | Standard_Real Zpn=0; | |
1104 | ||
1105 | switch (Orientation) { | |
1106 | case V3d_Zpos : | |
b5ac8292 | 1107 | Ypn = 1.; |
1108 | break; | |
7fd59977 | 1109 | case V3d_Zneg : |
b5ac8292 | 1110 | Ypn = -1.; |
1111 | break; | |
7fd59977 | 1112 | default: |
1113 | Zpn = 1.; | |
1114 | } | |
b5ac8292 | 1115 | |
1116 | const Graphic3d_Vector& aBck = V3d::GetProjAxis (Orientation); | |
197ac94e | 1117 | |
1118 | // retain camera panning from origin when switching projection | |
1119 | gp_Pnt anOriginVCS = myCamera->ConvertWorld2View (gp::Origin()); | |
1120 | Standard_Real aPanX = anOriginVCS.X(); | |
1121 | Standard_Real aPanY = anOriginVCS.Y(); | |
1122 | ||
b5ac8292 | 1123 | myCamera->SetCenter (gp_Pnt (0, 0, 0)); |
1124 | myCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed()); | |
1125 | myCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn)); | |
197ac94e | 1126 | myCamera->OrthogonalizeUp(); |
1127 | ||
1128 | Panning (aPanX, aPanY); | |
b5ac8292 | 1129 | |
6bc6a6fc | 1130 | View()->AutoZFit(); |
b5ac8292 | 1131 | |
7fd59977 | 1132 | ImmediateUpdate(); |
7fd59977 | 1133 | } |
1134 | ||
197ac94e | 1135 | //============================================================================= |
1136 | //function : SetAt | |
1137 | //purpose : | |
1138 | //============================================================================= | |
b8ddfc2f | 1139 | void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) |
1140 | { | |
197ac94e | 1141 | Standard_Real aTwistBefore = Twist(); |
b5ac8292 | 1142 | |
197ac94e | 1143 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); |
b5ac8292 | 1144 | |
1145 | myCamera->SetCenter (gp_Pnt (X, Y, Z)); | |
b5ac8292 | 1146 | |
197ac94e | 1147 | SetTwist (aTwistBefore); |
b5ac8292 | 1148 | |
6bc6a6fc | 1149 | View()->AutoZFit(); |
b5ac8292 | 1150 | |
197ac94e | 1151 | SetImmediateUpdate (wasUpdateEnabled); |
1152 | ||
7fd59977 | 1153 | ImmediateUpdate(); |
7fd59977 | 1154 | } |
1155 | ||
197ac94e | 1156 | //============================================================================= |
1157 | //function : SetUp | |
1158 | //purpose : | |
1159 | //============================================================================= | |
b8ddfc2f | 1160 | void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) |
1161 | { | |
7fd59977 | 1162 | Standard_Boolean TheStatus ; |
6942f04a | 1163 | V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. , |
7fd59977 | 1164 | "V3d_View::SetUp, nullUp vector"); |
1165 | ||
b5ac8292 | 1166 | gp_Dir aReferencePlane (myCamera->Direction().Reversed()); |
1167 | gp_Dir anUp (Vx, Vy, Vz); | |
1168 | ||
1169 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1170 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1171 | if( !TheStatus ) { |
b5ac8292 | 1172 | anUp = gp_Dir (0.0, 0.0, 1.0); |
1173 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1174 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1175 | } |
1176 | if( !TheStatus ) { | |
b5ac8292 | 1177 | anUp = gp_Dir (0.0, 1.0, 0.0); |
1178 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1179 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1180 | } |
1181 | if( !TheStatus ) { | |
b5ac8292 | 1182 | anUp = gp_Dir (1.0, 0.0, 0.0); |
1183 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1184 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1185 | } |
6942f04a | 1186 | V3d_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up"); |
7fd59977 | 1187 | |
b5ac8292 | 1188 | Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; |
1189 | myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); | |
1190 | ||
b5ac8292 | 1191 | myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); |
197ac94e | 1192 | |
6bc6a6fc | 1193 | View()->AutoZFit(); |
b5ac8292 | 1194 | |
7fd59977 | 1195 | ImmediateUpdate(); |
7fd59977 | 1196 | } |
1197 | ||
197ac94e | 1198 | //============================================================================= |
1199 | //function : SetUp | |
1200 | //purpose : | |
1201 | //============================================================================= | |
b8ddfc2f | 1202 | void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) |
1203 | { | |
7fd59977 | 1204 | Standard_Boolean TheStatus ; |
1205 | ||
b5ac8292 | 1206 | gp_Dir aReferencePlane (myCamera->Direction().Reversed()); |
1207 | gp_Dir anUp; | |
1208 | ||
1209 | const Graphic3d_Vector& aViewReferenceUp = V3d::GetProjAxis(Orientation) ; | |
1210 | anUp = gp_Dir (aViewReferenceUp.X(), aViewReferenceUp.Y(), aViewReferenceUp.Z()); | |
1211 | ||
1212 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1213 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1214 | if( !TheStatus ) { |
b5ac8292 | 1215 | anUp = gp_Dir (0.,0.,1.); |
1216 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1217 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1218 | } |
1219 | if( !TheStatus ) { | |
b5ac8292 | 1220 | anUp = gp_Dir (0.,1.,0.); |
1221 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1222 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1223 | } |
1224 | if( !TheStatus ) { | |
b5ac8292 | 1225 | anUp = gp_Dir (1.,0.,0.); |
1226 | TheStatus = ScreenAxis(aReferencePlane,anUp, | |
1227 | myXscreenAxis,myYscreenAxis,myZscreenAxis) ; | |
7fd59977 | 1228 | } |
6942f04a | 1229 | V3d_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up"); |
7fd59977 | 1230 | |
b5ac8292 | 1231 | Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; |
1232 | myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); | |
1233 | ||
b5ac8292 | 1234 | myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); |
197ac94e | 1235 | |
6bc6a6fc | 1236 | View()->AutoZFit(); |
7fd59977 | 1237 | |
7fd59977 | 1238 | ImmediateUpdate(); |
1239 | } | |
1240 | ||
197ac94e | 1241 | //============================================================================= |
1242 | //function : SetViewOrientationDefault | |
1243 | //purpose : | |
1244 | //============================================================================= | |
b8ddfc2f | 1245 | void V3d_View::SetViewOrientationDefault() |
1246 | { | |
7fd59977 | 1247 | MyView->SetViewOrientationDefault() ; |
b5ac8292 | 1248 | |
7fd59977 | 1249 | ImmediateUpdate(); |
1250 | } | |
1251 | ||
197ac94e | 1252 | //============================================================================= |
1253 | //function : ResetViewOrientation | |
1254 | //purpose : | |
1255 | //============================================================================= | |
b8ddfc2f | 1256 | void V3d_View::ResetViewOrientation() |
1257 | { | |
7fd59977 | 1258 | MyView->ViewOrientationReset() ; |
b5ac8292 | 1259 | |
7fd59977 | 1260 | ImmediateUpdate(); |
1261 | } | |
1262 | ||
197ac94e | 1263 | //============================================================================= |
1264 | //function : Reset | |
1265 | //purpose : | |
1266 | //============================================================================= | |
b8ddfc2f | 1267 | void V3d_View::Reset( const Standard_Boolean update ) |
1268 | { | |
b5ac8292 | 1269 | Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); |
1270 | ||
1271 | if (!aDefaultCamera.IsNull()) | |
1272 | { | |
b5ac8292 | 1273 | myCamera->CopyMappingData (aDefaultCamera); |
1274 | myCamera->CopyOrientationData (aDefaultCamera); | |
197ac94e | 1275 | |
6bc6a6fc | 1276 | View()->AutoZFit(); |
b5ac8292 | 1277 | } |
7fd59977 | 1278 | |
7fd59977 | 1279 | SwitchSetFront = Standard_False; |
b5ac8292 | 1280 | |
f0ecc0cc | 1281 | if( myImmediateUpdate || update ) Update(); |
7fd59977 | 1282 | } |
1283 | ||
197ac94e | 1284 | //======================================================================= |
1285 | //function : SetCenter | |
1286 | //purpose : | |
1287 | //======================================================================= | |
1288 | void V3d_View::SetCenter (const Standard_Integer theXp, | |
1289 | const Standard_Integer theYp) | |
b8ddfc2f | 1290 | { |
197ac94e | 1291 | Standard_Real aXv, aYv; |
1292 | Convert (theXp, theYp, aXv, aYv); | |
1293 | Translate (myCamera, aXv, aYv); | |
7fd59977 | 1294 | |
7fd59977 | 1295 | ImmediateUpdate(); |
7fd59977 | 1296 | } |
1297 | ||
197ac94e | 1298 | //============================================================================= |
1299 | //function : SetSize | |
1300 | //purpose : | |
1301 | //============================================================================= | |
3dfe95cd | 1302 | void V3d_View::SetSize (const Standard_Real theSize) |
7fd59977 | 1303 | { |
3dfe95cd | 1304 | V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL"); |
7fd59977 | 1305 | |
3dfe95cd | 1306 | myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize); |
197ac94e | 1307 | |
6bc6a6fc | 1308 | View()->AutoZFit(); |
7fd59977 | 1309 | |
7fd59977 | 1310 | ImmediateUpdate(); |
7fd59977 | 1311 | } |
1312 | ||
197ac94e | 1313 | //============================================================================= |
1314 | //function : SetZSize | |
1315 | //purpose : | |
1316 | //============================================================================= | |
7fd59977 | 1317 | void V3d_View::SetZSize(const Standard_Real Size) |
1318 | { | |
7fd59977 | 1319 | Standard_Real Zmax = Size/2.; |
1320 | ||
b5ac8292 | 1321 | Standard_Real aDistance = myCamera->Distance(); |
1322 | ||
7fd59977 | 1323 | if( Size <= 0. ) { |
b5ac8292 | 1324 | Zmax = aDistance; |
7fd59977 | 1325 | } |
7fd59977 | 1326 | |
b5ac8292 | 1327 | Standard_Real Front = MyViewContext.ZClippingFrontPlane(); |
1328 | Standard_Real Back = MyViewContext.ZClippingBackPlane(); | |
7fd59977 | 1329 | |
197ac94e | 1330 | // ShortReal precision factor used to add meaningful tolerance to |
1331 | // ZNear, ZFar values in order to avoid equality after type conversion | |
1332 | // to ShortReal matrices type. | |
1333 | const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1); | |
1334 | ||
1335 | Standard_Real aZFar = Zmax + aDistance * 2.0; | |
1336 | Standard_Real aZNear = -Zmax + aDistance; | |
1337 | aZNear -= Abs (aZNear) * aPrecision; | |
1338 | aZFar += Abs (aZFar) * aPrecision; | |
1339 | ||
1340 | if (!myCamera->IsOrthographic()) | |
1341 | { | |
1342 | if (aZFar < aPrecision) | |
1343 | { | |
1344 | // Invalid case when both values are negative | |
1345 | aZNear = aPrecision; | |
1346 | aZFar = aPrecision * 2.0; | |
1347 | } | |
1348 | else if (aZNear < Abs (aZFar) * aPrecision) | |
1349 | { | |
1350 | // Z is less than 0.0, try to fix it using any appropriate z-scale | |
1351 | aZNear = Abs (aZFar) * aPrecision; | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | // If range is too small | |
1356 | if (aZFar < (aZNear + Abs (aZFar) * aPrecision)) | |
1357 | { | |
1358 | aZFar = aZNear + Abs (aZFar) * aPrecision; | |
1359 | } | |
1360 | ||
1361 | myCamera->SetZRange (aZNear, aZFar); | |
7fd59977 | 1362 | |
b5ac8292 | 1363 | if (MyViewContext.FrontZClippingIsOn() || |
1364 | MyViewContext.BackZClippingIsOn()) | |
b8ddfc2f | 1365 | { |
b5ac8292 | 1366 | MyViewContext.SetZClippingFrontPlane (Front); |
1367 | MyViewContext.SetZClippingBackPlane (Back); | |
1368 | MyView->SetContext (MyViewContext); | |
b8ddfc2f | 1369 | } |
7fd59977 | 1370 | } |
1371 | ||
197ac94e | 1372 | //============================================================================= |
1373 | //function : SetZoom | |
1374 | //purpose : | |
1375 | //============================================================================= | |
7fd59977 | 1376 | void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start) |
1377 | { | |
6942f04a | 1378 | V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient"); |
7fd59977 | 1379 | |
b5ac8292 | 1380 | if (Start) |
1381 | { | |
1382 | myCamStartOpEye = myCamera->Eye(); | |
1383 | myCamStartOpCenter = myCamera->Center(); | |
7fd59977 | 1384 | } |
1385 | ||
b5ac8292 | 1386 | Standard_Real aViewWidth = myCamera->ViewDimensions().X(); |
1387 | Standard_Real aViewHeight = myCamera->ViewDimensions().Y(); | |
1388 | ||
7fd59977 | 1389 | // ensure that zoom will not be too small or too big |
1390 | Standard_Real coef = Coef; | |
b5ac8292 | 1391 | if (aViewWidth < coef * Precision::Confusion()) |
1392 | { | |
1393 | coef = aViewWidth / Precision::Confusion(); | |
1394 | } | |
1395 | else if (aViewWidth > coef * 1e12) | |
1396 | { | |
1397 | coef = aViewWidth / 1e12; | |
1398 | } | |
1399 | if (aViewHeight < coef * Precision::Confusion()) | |
1400 | { | |
1401 | coef = aViewHeight / Precision::Confusion(); | |
1402 | } | |
1403 | else if (aViewHeight > coef * 1e12) | |
1404 | { | |
1405 | coef = aViewHeight / 1e12; | |
1406 | } | |
1407 | ||
b5ac8292 | 1408 | myCamera->SetEye (myCamStartOpEye); |
1409 | myCamera->SetCenter (myCamStartOpCenter); | |
1410 | myCamera->SetScale (myCamera->Scale() / Coef); | |
6bc6a6fc | 1411 | View()->AutoZFit(); |
b5ac8292 | 1412 | |
7fd59977 | 1413 | ImmediateUpdate(); |
1414 | } | |
1415 | ||
197ac94e | 1416 | //============================================================================= |
1417 | //function : SetScale | |
1418 | //purpose : | |
1419 | //============================================================================= | |
b8ddfc2f | 1420 | void V3d_View::SetScale( const Standard_Real Coef ) |
1421 | { | |
6942f04a | 1422 | V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient"); |
7fd59977 | 1423 | |
b5ac8292 | 1424 | Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); |
1425 | ||
b5ac8292 | 1426 | // Strange behavior for the sake of compatibility. |
1427 | if (!aDefaultCamera.IsNull()) | |
1428 | { | |
1429 | myCamera->SetAspect (aDefaultCamera->Aspect()); | |
1430 | Standard_Real aDefaultScale = aDefaultCamera->Scale(); | |
1431 | myCamera->SetScale (aDefaultScale / Coef); | |
1432 | } | |
1433 | else | |
1434 | { | |
1435 | myCamera->SetScale (myCamera->Scale() / Coef); | |
1436 | } | |
1437 | ||
6bc6a6fc | 1438 | View()->AutoZFit(); |
b5ac8292 | 1439 | |
7fd59977 | 1440 | ImmediateUpdate(); |
7fd59977 | 1441 | } |
1442 | ||
197ac94e | 1443 | //============================================================================= |
1444 | //function : SetAxialScale | |
1445 | //purpose : | |
1446 | //============================================================================= | |
b8ddfc2f | 1447 | void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) |
1448 | { | |
6942f04a | 1449 | V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient"); |
7fd59977 | 1450 | |
197ac94e | 1451 | myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz)); |
6bc6a6fc | 1452 | View()->AutoZFit(); |
7fd59977 | 1453 | } |
1454 | ||
197ac94e | 1455 | //============================================================================= |
1456 | //function : FitAll | |
1457 | //purpose : | |
1458 | //============================================================================= | |
b586500b | 1459 | void V3d_View::FitAll (const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate) |
7fd59977 | 1460 | { |
b586500b | 1461 | FitAll (MyView->MinMaxValues(), theMargin, theToUpdate); |
1462 | } | |
1463 | ||
1464 | //============================================================================= | |
1465 | //function : FitAll | |
1466 | //purpose : | |
1467 | //============================================================================= | |
1468 | void V3d_View::FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate) | |
1469 | { | |
1470 | Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient"); | |
197ac94e | 1471 | |
1472 | if (MyView->NumberOfDisplayedStructures() == 0) | |
1473 | { | |
1474 | return; | |
1475 | } | |
35617823 | 1476 | |
b586500b | 1477 | if (!FitMinMax (myCamera, theBox, theMargin, 10.0 * Precision::Confusion())) |
35617823 | 1478 | { |
35617823 K |
1479 | return; |
1480 | } | |
7fd59977 | 1481 | |
6bc6a6fc | 1482 | View()->AutoZFit(); |
b5ac8292 | 1483 | |
197ac94e | 1484 | if (myImmediateUpdate || theToUpdate) |
35617823 | 1485 | { |
b5ac8292 | 1486 | Update(); |
35617823 | 1487 | } |
b5ac8292 | 1488 | } |
35617823 | 1489 | |
197ac94e | 1490 | //============================================================================= |
1491 | //function : DepthFitAll | |
1492 | //purpose : | |
1493 | //============================================================================= | |
7fd59977 | 1494 | void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect, |
1495 | const Quantity_Coefficient Margin) | |
1496 | { | |
1497 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ; | |
1498 | Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ; | |
b5ac8292 | 1499 | Standard_Real Dx,Dy,Dz,Size; |
7fd59977 | 1500 | |
1501 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
1502 | ||
b5ac8292 | 1503 | if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) { |
7fd59977 | 1504 | ImmediateUpdate(); |
1505 | return ; | |
1506 | } | |
1507 | ||
ed063270 | 1508 | Bnd_Box aBox = MyView->MinMaxValues(); |
1509 | if (aBox.IsVoid()) | |
1510 | { | |
1511 | ImmediateUpdate(); | |
1512 | return ; | |
1513 | } | |
1514 | aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); | |
7fd59977 | 1515 | MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ; |
1516 | MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ; | |
1517 | Umin = Min(U,U1) ; Umax = Max(U,U1) ; | |
1518 | Vmin = Min(V,V1) ; Vmax = Max(V,V1) ; | |
1519 | Wmin = Min(W,W1) ; Wmax = Max(W,W1) ; | |
1520 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
1521 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1522 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1523 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1524 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
1525 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1526 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1527 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1528 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
1529 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1530 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1531 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1532 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
1533 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1534 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1535 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1536 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
1537 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1538 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1539 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1540 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
1541 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1542 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1543 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1544 | ||
1545 | // Adjust Z size | |
1546 | Wmax = Max(Abs(Wmin),Abs(Wmax)) ; | |
1547 | Dz = 2.*Wmax + Margin * Wmax; | |
1548 | ||
1549 | // Compute depth value | |
1550 | Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin); | |
1551 | Dx += Margin * Dx; Dy += Margin * Dy; | |
1552 | Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz); | |
1553 | if( Size > 0. ) { | |
1554 | SetZSize(Size) ; | |
1555 | SetDepth( Aspect * Size / 2.); | |
1556 | } | |
1557 | ||
1558 | ImmediateUpdate(); | |
1559 | } | |
1560 | ||
197ac94e | 1561 | //============================================================================= |
1562 | //function : FitAll | |
1563 | //purpose : | |
1564 | //============================================================================= | |
1565 | void V3d_View::FitAll(const Standard_Real theMinXv, | |
1566 | const Standard_Real theMinYv, | |
1567 | const Standard_Real theMaxXv, | |
1568 | const Standard_Real theMaxYv) | |
b8ddfc2f | 1569 | { |
197ac94e | 1570 | FitAll (MyWindow, theMinXv, theMinYv, theMaxXv, theMaxYv); |
7fd59977 | 1571 | } |
1572 | ||
197ac94e | 1573 | //============================================================================= |
1574 | //function : WindowFitAll | |
1575 | //purpose : | |
1576 | //============================================================================= | |
1577 | void V3d_View::WindowFitAll(const Standard_Integer Xmin, | |
1578 | const Standard_Integer Ymin, | |
1579 | const Standard_Integer Xmax, | |
1580 | const Standard_Integer Ymax) | |
b8ddfc2f | 1581 | { |
7fd59977 | 1582 | WindowFit(Xmin,Ymin,Xmax,Ymax); |
7fd59977 | 1583 | } |
b8ddfc2f | 1584 | |
197ac94e | 1585 | //======================================================================= |
1586 | //function : WindowFit | |
1587 | //purpose : | |
1588 | //======================================================================= | |
1589 | void V3d_View::WindowFit (const Standard_Integer theMinXp, | |
1590 | const Standard_Integer theMinYp, | |
1591 | const Standard_Integer theMaxXp, | |
1592 | const Standard_Integer theMaxYp) | |
b8ddfc2f | 1593 | { |
197ac94e | 1594 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); |
1595 | ||
b5ac8292 | 1596 | if (!myCamera->IsOrthographic()) |
1597 | { | |
ab1c121b | 1598 | // normalize view coordinates |
b5ac8292 | 1599 | Standard_Integer aWinWidth, aWinHeight; |
1600 | MyWindow->Size (aWinWidth, aWinHeight); | |
7fd59977 | 1601 | |
b5ac8292 | 1602 | // z coordinate of camera center |
1603 | Standard_Real aDepth = myCamera->Project (myCamera->Center()).Z(); | |
1604 | ||
1605 | // camera projection coordinate are in NDC which are normalized [-1, 1] | |
197ac94e | 1606 | Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp - 1.0; |
1607 | Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp - 1.0; | |
1608 | Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0; | |
1609 | Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0; | |
b5ac8292 | 1610 | |
1611 | // compute camera panning | |
1612 | gp_Pnt aScreenCenter (0.0, 0.0, aDepth); | |
1613 | gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth); | |
1614 | gp_Pnt aPanTo = myCamera->ConvertProj2View (aFitCenter); | |
1615 | gp_Pnt aPanFrom = myCamera->ConvertProj2View (aScreenCenter); | |
1616 | gp_Vec aPanVec (aPanFrom, aPanTo); | |
1617 | ||
b5ac8292 | 1618 | // compute section size |
1619 | gp_Pnt aFitTopRight (aUMax, aVMax, aDepth); | |
1620 | gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth); | |
1621 | gp_Pnt aViewBotLeft = myCamera->ConvertProj2View (aFitBotLeft); | |
1622 | gp_Pnt aViewTopRight = myCamera->ConvertProj2View (aFitTopRight); | |
1623 | ||
1624 | Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X(); | |
1625 | Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y(); | |
1626 | ||
197ac94e | 1627 | Translate (myCamera, aPanVec.X(), -aPanVec.Y()); |
1628 | Scale (myCamera, aUSize, aVSize); | |
6bc6a6fc | 1629 | View()->AutoZFit(); |
b5ac8292 | 1630 | } |
1631 | else | |
1632 | { | |
197ac94e | 1633 | Standard_Real aX1, aY1, aX2, aY2; |
1634 | Convert (theMinXp, theMinYp, aX1, aY1); | |
1635 | Convert (theMaxXp, theMaxYp, aX2, aY2); | |
1636 | FitAll (aX1, aY1, aX2, aY2); | |
b5ac8292 | 1637 | } |
197ac94e | 1638 | |
1639 | SetImmediateUpdate (wasUpdateEnabled); | |
1640 | ||
1641 | ImmediateUpdate(); | |
7fd59977 | 1642 | } |
1643 | ||
197ac94e | 1644 | //======================================================================= |
1645 | //function : SetViewMappingDefault | |
1646 | //purpose : | |
1647 | //======================================================================= | |
b8ddfc2f | 1648 | void V3d_View::SetViewMappingDefault() |
1649 | { | |
7fd59977 | 1650 | MyView->SetViewMappingDefault(); |
b5ac8292 | 1651 | |
7fd59977 | 1652 | ImmediateUpdate(); |
1653 | } | |
1654 | ||
197ac94e | 1655 | //======================================================================= |
1656 | //function : ResetViewMapping | |
1657 | //purpose : | |
1658 | //======================================================================= | |
b8ddfc2f | 1659 | void V3d_View::ResetViewMapping() |
1660 | { | |
7fd59977 | 1661 | MyView->ViewMappingReset(); |
b5ac8292 | 1662 | |
7fd59977 | 1663 | Update(); |
7fd59977 | 1664 | } |
1665 | ||
197ac94e | 1666 | //======================================================================= |
1667 | //function : ConvertToGrid | |
1668 | //purpose : | |
1669 | //======================================================================= | |
1670 | void V3d_View::ConvertToGrid(const Standard_Integer Xp, | |
1671 | const Standard_Integer Yp, | |
1672 | Standard_Real& Xg, | |
1673 | Standard_Real& Yg, | |
1674 | Standard_Real& Zg) const | |
b5ac8292 | 1675 | { |
1676 | Graphic3d_Vertex aVrp; | |
1677 | Standard_Real anX, anY, aZ; | |
1678 | Convert (Xp, Yp, anX, anY, aZ); | |
1679 | aVrp.SetCoord (anX, anY, aZ); | |
1680 | ||
1681 | if( MyViewer->Grid()->IsActive() ) { | |
1682 | Graphic3d_Vertex aNewVrp = Compute (aVrp) ; | |
1683 | aNewVrp.Coord (Xg,Yg,Zg) ; | |
1684 | } else | |
1685 | aVrp.Coord (Xg,Yg,Zg) ; | |
1686 | } | |
1687 | ||
197ac94e | 1688 | //======================================================================= |
1689 | //function : ConvertToGrid | |
1690 | //purpose : | |
1691 | //======================================================================= | |
1692 | void V3d_View::ConvertToGrid(const Standard_Real X, | |
1693 | const Standard_Real Y, | |
1694 | const Standard_Real Z, | |
1695 | Standard_Real& Xg, | |
1696 | Standard_Real& Yg, | |
1697 | Standard_Real& Zg) const | |
b5ac8292 | 1698 | { |
1699 | if( MyViewer->Grid()->IsActive() ) { | |
1700 | Graphic3d_Vertex aVrp (X,Y,Z) ; | |
1701 | Graphic3d_Vertex aNewVrp = Compute (aVrp) ; | |
1702 | aNewVrp.Coord(Xg,Yg,Zg) ; | |
1703 | } else { | |
1704 | Xg = X; Yg = Y; Zg = Z; | |
1705 | } | |
1706 | } | |
1707 | ||
197ac94e | 1708 | //======================================================================= |
1709 | //function : Convert | |
1710 | //purpose : | |
1711 | //======================================================================= | |
b8ddfc2f | 1712 | Standard_Real V3d_View::Convert(const Standard_Integer Vp) const |
1713 | { | |
b5ac8292 | 1714 | Standard_Integer aDxw, aDyw ; |
7fd59977 | 1715 | |
b5ac8292 | 1716 | V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); |
7fd59977 | 1717 | |
b5ac8292 | 1718 | MyWindow->Size (aDxw, aDyw); |
1719 | Standard_Real aValue; | |
197ac94e | 1720 | |
b5ac8292 | 1721 | gp_Pnt aViewDims = myCamera->ViewDimensions(); |
1722 | aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw; | |
7fd59977 | 1723 | |
b5ac8292 | 1724 | return aValue; |
7fd59977 | 1725 | } |
1726 | ||
197ac94e | 1727 | //======================================================================= |
1728 | //function : Convert | |
1729 | //purpose : | |
1730 | //======================================================================= | |
1731 | void V3d_View::Convert(const Standard_Integer Xp, | |
1732 | const Standard_Integer Yp, | |
1733 | Standard_Real& Xv, | |
1734 | Standard_Real& Yv) const | |
b8ddfc2f | 1735 | { |
b5ac8292 | 1736 | Standard_Integer aDxw, aDyw; |
7fd59977 | 1737 | |
b5ac8292 | 1738 | V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); |
1739 | ||
1740 | MyWindow->Size (aDxw, aDyw); | |
1741 | ||
1742 | gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0); | |
1743 | aPoint = myCamera->ConvertProj2View (aPoint); | |
7fd59977 | 1744 | |
b5ac8292 | 1745 | Xv = aPoint.X(); |
1746 | Yv = aPoint.Y(); | |
7fd59977 | 1747 | } |
1748 | ||
197ac94e | 1749 | //======================================================================= |
1750 | //function : Convert | |
1751 | //purpose : | |
1752 | //======================================================================= | |
7fd59977 | 1753 | Standard_Integer V3d_View::Convert(const Standard_Real Vv) const |
1754 | { | |
b5ac8292 | 1755 | V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); |
1756 | ||
1757 | Standard_Integer aDxw, aDyw; | |
1758 | MyWindow->Size (aDxw, aDyw); | |
7fd59977 | 1759 | |
b5ac8292 | 1760 | gp_Pnt aViewDims = myCamera->ViewDimensions(); |
1761 | Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X())); | |
7fd59977 | 1762 | |
b5ac8292 | 1763 | return aValue; |
7fd59977 | 1764 | } |
1765 | ||
197ac94e | 1766 | //======================================================================= |
1767 | //function : Convert | |
1768 | //purpose : | |
1769 | //======================================================================= | |
1770 | void V3d_View::Convert(const Standard_Real Xv, | |
1771 | const Standard_Real Yv, | |
1772 | Standard_Integer& Xp, | |
1773 | Standard_Integer& Yp) const | |
7fd59977 | 1774 | { |
b5ac8292 | 1775 | V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); |
7fd59977 | 1776 | |
b5ac8292 | 1777 | Standard_Integer aDxw, aDyw; |
1778 | MyWindow->Size (aDxw, aDyw); | |
7fd59977 | 1779 | |
b5ac8292 | 1780 | gp_Pnt aPoint (Xv, Yv, 0.0); |
1781 | aPoint = myCamera->ConvertView2Proj (aPoint); | |
1782 | aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0); | |
7fd59977 | 1783 | |
b5ac8292 | 1784 | Xp = RealToInt (aPoint.X()); |
1785 | Yp = RealToInt (aPoint.Y()); | |
7fd59977 | 1786 | } |
1787 | ||
197ac94e | 1788 | //======================================================================= |
1789 | //function : Convert | |
1790 | //purpose : | |
1791 | //======================================================================= | |
1792 | void V3d_View::Convert(const Standard_Integer Xp, | |
1793 | const Standard_Integer Yp, | |
1794 | Standard_Real& X, | |
1795 | Standard_Real& Y, | |
1796 | Standard_Real& Z) const | |
b8ddfc2f | 1797 | { |
b5ac8292 | 1798 | V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); |
1799 | Standard_Integer aHeight, aWidth; | |
1800 | MyWindow->Size (aWidth, aHeight); | |
1801 | ||
1802 | Standard_Real anX = 2.0 * Xp / aWidth - 1.0; | |
1803 | Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0; | |
1804 | Standard_Real aZ = 2.0 * 0.0 - 1.0; | |
1805 | ||
1806 | gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ)); | |
1807 | ||
1808 | X = aResult.X(); | |
1809 | Y = aResult.Y(); | |
1810 | Z = aResult.Z(); | |
7fd59977 | 1811 | } |
1812 | ||
197ac94e | 1813 | //======================================================================= |
1814 | //function : ConvertWithProj | |
1815 | //purpose : | |
1816 | //======================================================================= | |
1817 | void V3d_View::ConvertWithProj(const Standard_Integer Xp, | |
1818 | const Standard_Integer Yp, | |
1819 | Standard_Real& X, | |
1820 | Standard_Real& Y, | |
1821 | Standard_Real& Z, | |
1822 | Standard_Real& Dx, | |
1823 | Standard_Real& Dy, | |
1824 | Standard_Real& Dz) const | |
7fd59977 | 1825 | { |
b5ac8292 | 1826 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); |
1827 | Standard_Integer aHeight, aWidth; | |
1828 | MyWindow->Size (aWidth, aHeight); | |
7fd59977 | 1829 | |
b5ac8292 | 1830 | Standard_Real anX = 2.0 * Xp / aWidth - 1.0; |
1831 | Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0; | |
1832 | Standard_Real aZ = 2.0 * 0.0 - 1.0; | |
7fd59977 | 1833 | |
b5ac8292 | 1834 | gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ)); |
1835 | ||
1836 | X = aResult.X(); | |
1837 | Y = aResult.Y(); | |
1838 | Z = aResult.Z(); | |
1839 | ||
1840 | Graphic3d_Vertex aVrp; | |
1841 | aVrp.SetCoord (X, Y, Z); | |
1842 | ||
1843 | aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0)); | |
1844 | ||
3910bc65 | 1845 | Graphic3d_Vec3d aNormDir; |
1846 | aNormDir.x() = X - aResult.X(); | |
1847 | aNormDir.y() = Y - aResult.Y(); | |
1848 | aNormDir.z() = Z - aResult.Z(); | |
1849 | aNormDir.Normalize(); | |
1850 | ||
1851 | Dx = aNormDir.x(); | |
1852 | Dy = aNormDir.y(); | |
1853 | Dz = aNormDir.z(); | |
7fd59977 | 1854 | } |
7fd59977 | 1855 | |
197ac94e | 1856 | //======================================================================= |
1857 | //function : Convert | |
1858 | //purpose : | |
1859 | //======================================================================= | |
1860 | void V3d_View::Convert(const Standard_Real X, | |
1861 | const Standard_Real Y, | |
1862 | const Standard_Real Z, | |
1863 | Standard_Integer& Xp, | |
1864 | Standard_Integer& Yp) const | |
b8ddfc2f | 1865 | { |
b5ac8292 | 1866 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); |
1867 | Standard_Integer aHeight, aWidth; | |
1868 | MyWindow->Size (aWidth, aHeight); | |
1869 | ||
1870 | gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z)); | |
1871 | ||
1872 | Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth); | |
72b11796 | 1873 | Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight); |
7fd59977 | 1874 | } |
1875 | ||
197ac94e | 1876 | //======================================================================= |
1877 | //function : Project | |
1878 | //purpose : | |
1879 | //======================================================================= | |
1880 | void V3d_View::Project(const Standard_Real X, | |
1881 | const Standard_Real Y, | |
1882 | const Standard_Real Z, | |
1883 | Standard_Real &Xp, | |
1884 | Standard_Real &Yp) const | |
7fd59977 | 1885 | { |
b5ac8292 | 1886 | Standard_Real Zp; |
1887 | MyView->Projects (X, Y, Z, Xp, Yp, Zp); | |
7fd59977 | 1888 | } |
1889 | ||
197ac94e | 1890 | //======================================================================= |
1891 | //function : BackgroundColor | |
1892 | //purpose : | |
1893 | //======================================================================= | |
1894 | void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type, | |
1895 | Standard_Real& V1, | |
1896 | Standard_Real& V2, | |
1897 | Standard_Real& V3) const | |
b8ddfc2f | 1898 | { |
7fd59977 | 1899 | Quantity_Color C = BackgroundColor() ; |
7fd59977 | 1900 | C.Values(V1,V2,V3,Type) ; |
1901 | } | |
1902 | ||
197ac94e | 1903 | //======================================================================= |
1904 | //function : BackgroundColor | |
1905 | //purpose : | |
1906 | //======================================================================= | |
b8ddfc2f | 1907 | Quantity_Color V3d_View::BackgroundColor() const |
1908 | { | |
7fd59977 | 1909 | return MyBackground.Color() ; |
1910 | } | |
7fd59977 | 1911 | |
197ac94e | 1912 | //======================================================================= |
1913 | //function : GradientBackgroundColors | |
1914 | //purpose : | |
1915 | //======================================================================= | |
b8ddfc2f | 1916 | void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const |
1917 | { | |
7fd59977 | 1918 | MyGradientBackground.Colors(Color1, Color2); |
1919 | } | |
1920 | ||
197ac94e | 1921 | //======================================================================= |
1922 | //function : GradientBackground | |
1923 | //purpose : | |
1924 | //======================================================================= | |
b8ddfc2f | 1925 | Aspect_GradientBackground V3d_View::GradientBackground() const |
1926 | { | |
7fd59977 | 1927 | return MyGradientBackground; |
1928 | } | |
1929 | ||
197ac94e | 1930 | //======================================================================= |
1931 | //function : Scale | |
1932 | //purpose : | |
1933 | //======================================================================= | |
b8ddfc2f | 1934 | Standard_Real V3d_View::Scale() const |
1935 | { | |
b5ac8292 | 1936 | Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); |
1937 | ||
1938 | Standard_Real aCameraScale; | |
1939 | ||
1940 | // Strange behavior for the sake of compatibility. | |
1941 | if (!aDefaultCamera.IsNull()) | |
1942 | { | |
1943 | Standard_Real aDefaultScale = aDefaultCamera->Scale(); | |
1944 | aCameraScale = aDefaultScale / myCamera->Scale(); | |
1945 | } | |
1946 | else | |
1947 | { | |
1948 | aCameraScale = myCamera->Scale(); | |
1949 | } | |
7fd59977 | 1950 | |
b5ac8292 | 1951 | return aCameraScale; |
7fd59977 | 1952 | } |
1953 | ||
197ac94e | 1954 | //======================================================================= |
1955 | //function : AxialScale | |
1956 | //purpose : | |
1957 | //======================================================================= | |
b8ddfc2f | 1958 | void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const |
1959 | { | |
b5ac8292 | 1960 | gp_Pnt anAxialScale = myCamera->AxialScale(); |
1961 | Sx = anAxialScale.X(); | |
1962 | Sy = anAxialScale.Y(); | |
1963 | Sz = anAxialScale.Z(); | |
7fd59977 | 1964 | } |
1965 | ||
197ac94e | 1966 | //======================================================================= |
1967 | //function : Size | |
1968 | //purpose : | |
1969 | //======================================================================= | |
b8ddfc2f | 1970 | void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const |
1971 | { | |
b5ac8292 | 1972 | gp_Pnt aViewDims = myCamera->ViewDimensions(); |
7fd59977 | 1973 | |
b5ac8292 | 1974 | Width = aViewDims.X(); |
1975 | Height = aViewDims.Y(); | |
7fd59977 | 1976 | } |
1977 | ||
197ac94e | 1978 | //======================================================================= |
1979 | //function : ZSize | |
1980 | //purpose : | |
1981 | //======================================================================= | |
b8ddfc2f | 1982 | Standard_Real V3d_View::ZSize() const |
1983 | { | |
b5ac8292 | 1984 | gp_Pnt aViewDims = myCamera->ViewDimensions(); |
7fd59977 | 1985 | |
b5ac8292 | 1986 | return aViewDims.Z(); |
7fd59977 | 1987 | } |
1988 | ||
197ac94e | 1989 | //======================================================================= |
1990 | //function : MinMax | |
1991 | //purpose : | |
1992 | //======================================================================= | |
1993 | Standard_Integer V3d_View::MinMax(Standard_Real& Umin, | |
1994 | Standard_Real& Vmin, | |
1995 | Standard_Real& Umax, | |
1996 | Standard_Real& Vmax) const | |
b8ddfc2f | 1997 | { |
7fd59977 | 1998 | Standard_Real Wmin,Wmax,U,V,W ; |
1999 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ; | |
2000 | // CAL 6/11/98 | |
2001 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
2002 | ||
2003 | if( Nstruct ) { | |
ed063270 | 2004 | Bnd_Box aBox = MyView->MinMaxValues(); |
2005 | aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); | |
7fd59977 | 2006 | MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; |
2007 | MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; | |
2008 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
2009 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2010 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2011 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2012 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
2013 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2014 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2015 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2016 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
2017 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2018 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2019 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2020 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
2021 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2022 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2023 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2024 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
2025 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2026 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2027 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2028 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
2029 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2030 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2031 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2032 | } | |
2033 | return Nstruct ; | |
2034 | } | |
2035 | ||
197ac94e | 2036 | //======================================================================= |
2037 | //function : MinMax | |
2038 | //purpose : | |
2039 | //======================================================================= | |
2040 | Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, | |
2041 | Standard_Real& Ymin, | |
2042 | Standard_Real& Zmin, | |
2043 | Standard_Real& Xmax, | |
2044 | Standard_Real& Ymax, | |
2045 | Standard_Real& Zmax) const | |
b8ddfc2f | 2046 | { |
7fd59977 | 2047 | // CAL 6/11/98 |
2048 | // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ; | |
2049 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
2050 | ||
2051 | if( Nstruct ) { | |
ed063270 | 2052 | Bnd_Box aBox = MyView->MinMaxValues(); |
2053 | aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); | |
7fd59977 | 2054 | } |
2055 | return Nstruct ; | |
2056 | } | |
2057 | ||
197ac94e | 2058 | //======================================================================= |
2059 | //function : Gravity | |
2060 | //purpose : | |
2061 | //======================================================================= | |
4af098ba | 2062 | void V3d_View::Gravity (Standard_Real& theX, |
2063 | Standard_Real& theY, | |
2064 | Standard_Real& theZ) const | |
b8ddfc2f | 2065 | { |
4af098ba | 2066 | Graphic3d_MapOfStructure aSetOfStructures; |
2067 | MyView->DisplayedStructures (aSetOfStructures); | |
2068 | ||
2069 | Standard_Boolean hasSelection = Standard_False; | |
2070 | for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures); | |
2071 | aStructIter.More(); aStructIter.Next()) | |
2072 | { | |
2073 | if (aStructIter.Key()->IsHighlighted() | |
2074 | && aStructIter.Key()->IsVisible()) | |
2075 | { | |
2076 | hasSelection = Standard_True; | |
2077 | break; | |
2078 | } | |
2079 | } | |
7fd59977 | 2080 | |
4af098ba | 2081 | Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; |
2082 | Standard_Integer aNbPoints = 0; | |
2083 | gp_XYZ aResult (0.0, 0.0, 0.0); | |
2084 | for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures); | |
2085 | aStructIter.More(); aStructIter.Next()) | |
2086 | { | |
2087 | const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); | |
2088 | if (!aStruct->IsVisible() | |
2089 | || (hasSelection && !aStruct->IsHighlighted()) | |
2090 | || aStruct->IsEmpty()) | |
2091 | { | |
2092 | continue; | |
2093 | } | |
2094 | ||
2095 | Bnd_Box aBox = aStruct->MinMaxValues(); | |
40738f9a | 2096 | if (aBox.IsVoid() || aStruct->IsInfinite()) |
4af098ba | 2097 | { |
2098 | continue; | |
2099 | } | |
2100 | ||
2101 | // use camera projection to find gravity point | |
2102 | aBox.Get (Xmin, Ymin, Zmin, | |
2103 | Xmax, Ymax, Zmax); | |
2104 | gp_Pnt aPnts[THE_NB_BOUND_POINTS] = | |
2105 | { | |
2106 | gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax), | |
2107 | gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax), | |
2108 | gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax), | |
2109 | gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax) | |
2110 | }; | |
7fd59977 | 2111 | |
4af098ba | 2112 | for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt) |
2113 | { | |
2114 | const gp_Pnt& aBndPnt = aPnts[aPntIt]; | |
2115 | const gp_Pnt aProjected = myCamera->Project (aBndPnt); | |
2116 | if (Abs (aProjected.X()) <= 1.0 | |
2117 | && Abs (aProjected.Y()) <= 1.0) | |
2118 | { | |
2119 | aResult += aBndPnt.XYZ(); | |
2120 | ++aNbPoints; | |
2121 | } | |
2122 | } | |
2123 | } | |
7fd59977 | 2124 | |
4af098ba | 2125 | if (aNbPoints == 0) |
b5ac8292 | 2126 | { |
4af098ba | 2127 | for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures); |
2128 | aStructIter.More(); aStructIter.Next()) | |
b5ac8292 | 2129 | { |
4af098ba | 2130 | const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); |
2131 | if (aStruct->IsEmpty()) | |
2132 | { | |
2133 | continue; | |
2134 | } | |
b5ac8292 | 2135 | |
4af098ba | 2136 | Bnd_Box aBox = aStruct->MinMaxValues(); |
40738f9a | 2137 | if (aBox.IsVoid() || aStruct->IsInfinite()) |
197ac94e | 2138 | { |
2139 | continue; | |
2140 | } | |
2141 | ||
4af098ba | 2142 | aBox.Get (Xmin, Ymin, Zmin, |
2143 | Xmax, Ymax, Zmax); | |
2144 | gp_Pnt aPnts[THE_NB_BOUND_POINTS] = | |
2145 | { | |
b5ac8292 | 2146 | gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax), |
2147 | gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax), | |
2148 | gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax), | |
4af098ba | 2149 | gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax) |
2150 | }; | |
b5ac8292 | 2151 | |
4af098ba | 2152 | for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt) |
b5ac8292 | 2153 | { |
2154 | const gp_Pnt& aBndPnt = aPnts[aPntIt]; | |
4af098ba | 2155 | aResult += aBndPnt.XYZ(); |
2156 | ++aNbPoints; | |
b5ac8292 | 2157 | } |
7fd59977 | 2158 | } |
2159 | } | |
7fd59977 | 2160 | |
4af098ba | 2161 | if (aNbPoints > 0) |
2162 | { | |
2163 | aResult /= aNbPoints; | |
2164 | } | |
2165 | theX = aResult.X(); | |
2166 | theY = aResult.Y(); | |
2167 | theZ = aResult.Z(); | |
7fd59977 | 2168 | } |
2169 | ||
197ac94e | 2170 | //======================================================================= |
2171 | //function : Eye | |
2172 | //purpose : | |
2173 | //======================================================================= | |
b8ddfc2f | 2174 | void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2175 | { | |
b5ac8292 | 2176 | gp_Pnt aCameraEye = myCamera->Eye(); |
2177 | X = aCameraEye.X(); | |
2178 | Y = aCameraEye.Y(); | |
2179 | Z = aCameraEye.Z(); | |
7fd59977 | 2180 | } |
2181 | ||
197ac94e | 2182 | //============================================================================= |
2183 | //function : FocalReferencePoint | |
2184 | //purpose : | |
2185 | //============================================================================= | |
b8ddfc2f | 2186 | void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const |
2187 | { | |
b5ac8292 | 2188 | Eye (X,Y,Z); |
7fd59977 | 2189 | } |
2190 | ||
197ac94e | 2191 | //============================================================================= |
2192 | //function : ProjReferenceAxe | |
2193 | //purpose : | |
2194 | //============================================================================= | |
2195 | void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, | |
2196 | const Standard_Integer Ypix, | |
2197 | Standard_Real& XP, | |
2198 | Standard_Real& YP, | |
2199 | Standard_Real& ZP, | |
2200 | Standard_Real& VX, | |
2201 | Standard_Real& VY, | |
2202 | Standard_Real& VZ) const | |
b8ddfc2f | 2203 | { |
7fd59977 | 2204 | Standard_Real Xo,Yo,Zo; |
2205 | ||
b5ac8292 | 2206 | Convert (Xpix, Ypix, XP, YP, ZP); |
2207 | if ( Type() == V3d_PERSPECTIVE ) | |
2208 | { | |
2209 | FocalReferencePoint (Xo,Yo,Zo); | |
7fd59977 | 2210 | VX = Xo - XP; |
2211 | VY = Yo - YP; | |
2212 | VZ = Zo - ZP; | |
2213 | } | |
b5ac8292 | 2214 | else |
2215 | { | |
2216 | Proj (VX,VY,VZ); | |
7fd59977 | 2217 | } |
2218 | } | |
2219 | ||
197ac94e | 2220 | //============================================================================= |
2221 | //function : Depth | |
2222 | //purpose : | |
2223 | //============================================================================= | |
b8ddfc2f | 2224 | Standard_Real V3d_View::Depth() const |
2225 | { | |
b5ac8292 | 2226 | return myCamera->Distance(); |
7fd59977 | 2227 | } |
2228 | ||
197ac94e | 2229 | //============================================================================= |
2230 | //function : Proj | |
2231 | //purpose : | |
2232 | //============================================================================= | |
b8ddfc2f | 2233 | void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const |
2234 | { | |
b5ac8292 | 2235 | gp_Dir aCameraDir = myCamera->Direction().Reversed(); |
2236 | Dx = aCameraDir.X(); | |
2237 | Dy = aCameraDir.Y(); | |
2238 | Dz = aCameraDir.Z(); | |
7fd59977 | 2239 | } |
2240 | ||
197ac94e | 2241 | //============================================================================= |
2242 | //function : At | |
2243 | //purpose : | |
2244 | //============================================================================= | |
b8ddfc2f | 2245 | void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2246 | { | |
b5ac8292 | 2247 | gp_Pnt aCameraCenter = myCamera->Center(); |
2248 | X = aCameraCenter.X(); | |
2249 | Y = aCameraCenter.Y(); | |
2250 | Z = aCameraCenter.Z(); | |
7fd59977 | 2251 | } |
2252 | ||
197ac94e | 2253 | //============================================================================= |
2254 | //function : Up | |
2255 | //purpose : | |
2256 | //============================================================================= | |
b8ddfc2f | 2257 | void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const |
2258 | { | |
b5ac8292 | 2259 | gp_Dir aCameraUp = myCamera->Up(); |
2260 | Vx = aCameraUp.X(); | |
2261 | Vy = aCameraUp.Y(); | |
2262 | Vz = aCameraUp.Z(); | |
7fd59977 | 2263 | } |
2264 | ||
197ac94e | 2265 | //============================================================================= |
2266 | //function : Twist | |
2267 | //purpose : | |
2268 | //============================================================================= | |
b8ddfc2f | 2269 | Standard_Real V3d_View::Twist() const |
2270 | { | |
7fd59977 | 2271 | Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ; |
2272 | Standard_Real pvx,pvy,pvz,pvn,sca,angle ; | |
b5ac8292 | 2273 | Graphic3d_Vector Xaxis,Yaxis,Zaxis ; |
7fd59977 | 2274 | Standard_Boolean TheStatus ; |
2275 | ||
b5ac8292 | 2276 | gp_Dir aReferencePlane (myCamera->Direction().Reversed()); |
2277 | gp_Dir anUp; | |
2278 | ||
2279 | Proj(Xpn,Ypn,Zpn); | |
2280 | anUp = gp_Dir (0.,0.,1.) ; | |
2281 | TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ; | |
7fd59977 | 2282 | if( !TheStatus ) { |
b5ac8292 | 2283 | anUp = gp_Dir (0.,1.,0.) ; |
2284 | TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ; | |
7fd59977 | 2285 | } |
2286 | if( !TheStatus ) { | |
b5ac8292 | 2287 | anUp = gp_Dir (1.,0.,0.) ; |
2288 | TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ; | |
7fd59977 | 2289 | } |
2290 | Yaxis.Coord(X0,Y0,Z0) ; | |
b5ac8292 | 2291 | |
2292 | Up(Xup,Yup,Zup) ; | |
7fd59977 | 2293 | /* Compute Cross Vector From Up & Origin */ |
2294 | pvx = Y0*Zup - Z0*Yup ; | |
2295 | pvy = Z0*Xup - X0*Zup ; | |
2296 | pvz = X0*Yup - Y0*Xup ; | |
2297 | pvn = pvx*pvx + pvy*pvy + pvz*pvz ; | |
2298 | sca = X0*Xup + Y0*Yup + Z0*Zup ; | |
2299 | /* Compute Angle */ | |
2300 | angle = Sqrt(pvn) ; | |
2301 | if( angle > 1. ) angle = 1. ; | |
2302 | else if( angle < -1. ) angle = -1. ; | |
2303 | angle = asin(angle) ; | |
c6541a0c D |
2304 | if( sca < 0. ) angle = M_PI - angle ; |
2305 | if( angle > 0. && angle < M_PI ) { | |
7fd59977 | 2306 | sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ; |
2307 | if( sca < 0. ) angle = DEUXPI - angle ; | |
2308 | } | |
2309 | return angle ; | |
2310 | } | |
2311 | ||
197ac94e | 2312 | //============================================================================= |
2313 | //function : ShadingModel | |
2314 | //purpose : | |
2315 | //============================================================================= | |
b8ddfc2f | 2316 | V3d_TypeOfShadingModel V3d_View::ShadingModel() const |
2317 | { | |
7fd59977 | 2318 | V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ; |
2319 | return SM ; | |
2320 | } | |
2321 | ||
197ac94e | 2322 | //============================================================================= |
2323 | //function : SurfaceDetail | |
2324 | //purpose : | |
2325 | //============================================================================= | |
b8ddfc2f | 2326 | V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const |
2327 | { | |
7fd59977 | 2328 | V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ; |
2329 | return SM ; | |
2330 | } | |
2331 | ||
197ac94e | 2332 | //============================================================================= |
2333 | //function : TextureEnv | |
2334 | //purpose : | |
2335 | //============================================================================= | |
857ffd5e | 2336 | Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const |
b8ddfc2f | 2337 | { |
7fd59977 | 2338 | Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ; |
2339 | return SM ; | |
2340 | } | |
2341 | ||
197ac94e | 2342 | //============================================================================= |
2343 | //function : Visualization | |
2344 | //purpose : | |
2345 | //============================================================================= | |
b8ddfc2f | 2346 | V3d_TypeOfVisualization V3d_View::Visualization() const |
2347 | { | |
7fd59977 | 2348 | V3d_TypeOfVisualization V = |
2349 | (V3d_TypeOfVisualization)MyViewContext.Visualization() ; | |
2350 | return V ; | |
2351 | } | |
2352 | ||
197ac94e | 2353 | //============================================================================= |
2354 | //function : Antialiasing | |
2355 | //purpose : | |
2356 | //============================================================================= | |
b8ddfc2f | 2357 | Standard_Boolean V3d_View::Antialiasing() const |
2358 | { | |
7fd59977 | 2359 | Standard_Boolean A = MyViewContext.AliasingIsOn() ; |
2360 | return A ; | |
2361 | } | |
2362 | ||
197ac94e | 2363 | //============================================================================= |
2364 | //function : Viewer | |
2365 | //purpose : | |
2366 | //============================================================================= | |
b8ddfc2f | 2367 | Handle(V3d_Viewer) V3d_View::Viewer() const |
2368 | { | |
7fd59977 | 2369 | return MyViewer ; |
2370 | } | |
2371 | ||
197ac94e | 2372 | //============================================================================= |
2373 | //function : IfWindow | |
2374 | //purpose : | |
2375 | //============================================================================= | |
b8ddfc2f | 2376 | Standard_Boolean V3d_View::IfWindow() const |
2377 | { | |
7fd59977 | 2378 | Standard_Boolean TheStatus = MyView->IsDefined() ; |
2379 | return TheStatus ; | |
2380 | } | |
2381 | ||
197ac94e | 2382 | //============================================================================= |
2383 | //function : Window | |
2384 | //purpose : | |
2385 | //============================================================================= | |
b8ddfc2f | 2386 | Handle(Aspect_Window) V3d_View::Window() const |
2387 | { | |
7fd59977 | 2388 | return MyWindow; |
2389 | } | |
2390 | ||
197ac94e | 2391 | //============================================================================= |
2392 | //function : Type | |
2393 | //purpose : | |
2394 | //============================================================================= | |
b8ddfc2f | 2395 | V3d_TypeOfView V3d_View::Type() const |
2396 | { | |
b5ac8292 | 2397 | return myCamera->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE; |
7fd59977 | 2398 | } |
2399 | ||
197ac94e | 2400 | //============================================================================= |
2401 | //function : SetFocale | |
2402 | //purpose : | |
2403 | //============================================================================= | |
b8ddfc2f | 2404 | void V3d_View::SetFocale( const Standard_Real focale ) |
2405 | { | |
b5ac8292 | 2406 | if (myCamera->IsOrthographic()) |
2407 | { | |
2408 | return; | |
7fd59977 | 2409 | } |
b5ac8292 | 2410 | |
2411 | Standard_Real aFOVyRad = ATan (focale / (myCamera->Distance() * 2.0)); | |
2412 | ||
2413 | myCamera->SetFOVy (aFOVyRad * (360 / M_PI)); | |
7fd59977 | 2414 | |
2415 | ImmediateUpdate(); | |
2416 | } | |
2417 | ||
197ac94e | 2418 | //============================================================================= |
2419 | //function : Focale | |
2420 | //purpose : | |
2421 | //============================================================================= | |
b5ac8292 | 2422 | Standard_Real V3d_View::Focale() const |
b8ddfc2f | 2423 | { |
b5ac8292 | 2424 | if (myCamera->IsOrthographic()) |
2425 | { | |
2426 | return 0.0; | |
7fd59977 | 2427 | } |
b5ac8292 | 2428 | |
2429 | return myCamera->Distance() * 2.0 * Tan(myCamera->FOVy() * M_PI / 360.0); | |
7fd59977 | 2430 | } |
2431 | ||
197ac94e | 2432 | //============================================================================= |
2433 | //function : View | |
2434 | //purpose : | |
2435 | //============================================================================= | |
7fd59977 | 2436 | Handle(Visual3d_View) V3d_View::View() const |
2437 | { | |
2438 | return MyView ; | |
2439 | } | |
2440 | ||
197ac94e | 2441 | //============================================================================= |
2442 | //function : ScreenAxis | |
2443 | //purpose : | |
2444 | //============================================================================= | |
b5ac8292 | 2445 | Standard_Boolean V3d_View::ScreenAxis( const gp_Dir &Vpn, const gp_Dir &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) |
2446 | { | |
2447 | Standard_Real Xpn, Ypn, Zpn, Xup, Yup, Zup; | |
2448 | Standard_Real dx1, dy1, dz1, xx, yy, zz; | |
2449 | ||
2450 | Xpn = Vpn.X(); Ypn = Vpn.Y(); Zpn = Vpn.Z(); | |
2451 | Xup = Vup.X(); Yup = Vup.Y(); Zup = Vup.Z(); | |
2452 | xx = Yup*Zpn - Zup*Ypn; | |
2453 | yy = Zup*Xpn - Xup*Zpn; | |
2454 | zz = Xup*Ypn - Yup*Xpn; | |
2455 | Xaxe.SetCoord (xx, yy, zz); | |
2456 | if (Xaxe.LengthZero()) return Standard_False; | |
2457 | Xaxe.Normalize(); | |
2458 | Xaxe.Coord(dx1, dy1, dz1); | |
2459 | xx = Ypn*dz1 - Zpn*dy1; | |
2460 | yy = Zpn*dx1 - Xpn*dz1; | |
2461 | zz = Xpn*dy1 - Ypn*dx1; | |
2462 | Yaxe.SetCoord (xx, yy, zz) ; | |
2463 | if (Yaxe.LengthZero()) return Standard_False; | |
2464 | Yaxe.Normalize(); | |
2465 | ||
2466 | Zaxe.SetCoord (Xpn, Ypn, Zpn); | |
2467 | Zaxe.Normalize(); | |
7fd59977 | 2468 | return Standard_True; |
2469 | } | |
2470 | ||
197ac94e | 2471 | //============================================================================= |
2472 | //function : TrsPoint | |
2473 | //purpose : | |
2474 | //============================================================================= | |
b8ddfc2f | 2475 | Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) |
2476 | { | |
7fd59977 | 2477 | Graphic3d_Vertex PP ; |
2478 | Standard_Real X,Y,Z,XX,YY,ZZ ; | |
2479 | ||
2480 | // CAL. S3892 | |
2481 | Standard_Integer lr, ur, lc, uc; | |
2482 | lr = Matrix.LowerRow (); | |
2483 | ur = Matrix.UpperRow (); | |
2484 | lc = Matrix.LowerCol (); | |
2485 | uc = Matrix.UpperCol (); | |
b5ac8292 | 2486 | if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) { |
7fd59977 | 2487 | P.Coord(X,Y,Z) ; |
2488 | PP.SetCoord(X,Y,Z) ; | |
2489 | return PP ; | |
2490 | } | |
2491 | P.Coord(X,Y,Z) ; | |
2492 | XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+ | |
2493 | Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ; | |
2494 | ||
2495 | YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) + | |
2496 | Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ; | |
2497 | ||
2498 | ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) + | |
2499 | Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ; | |
2500 | PP.SetCoord(XX,YY,ZZ) ; | |
2501 | return PP ; | |
2502 | } | |
2503 | ||
197ac94e | 2504 | //======================================================================= |
2505 | //function : Pan | |
2506 | //purpose : | |
2507 | //======================================================================= | |
2508 | void V3d_View::Pan (const Standard_Integer theDXp, | |
2509 | const Standard_Integer theDYp, | |
2510 | const Quantity_Factor theZoomFactor, | |
2511 | const Standard_Boolean theToStart) | |
b8ddfc2f | 2512 | { |
197ac94e | 2513 | Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart); |
7fd59977 | 2514 | } |
2515 | ||
197ac94e | 2516 | //======================================================================= |
2517 | //function : Panning | |
2518 | //purpose : | |
2519 | //======================================================================= | |
2520 | void V3d_View::Panning (const Standard_Real theDXv, | |
2521 | const Standard_Real theDYv, | |
2522 | const Quantity_Factor theZoomFactor, | |
2523 | const Standard_Boolean theToStart) | |
7fd59977 | 2524 | { |
197ac94e | 2525 | Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor"); |
7fd59977 | 2526 | |
197ac94e | 2527 | if (theToStart) |
2528 | { | |
2529 | myCamStartOpEye = myCamera->Eye(); | |
2530 | myCamStartOpCenter = myCamera->Center(); | |
7fd59977 | 2531 | } |
197ac94e | 2532 | |
2533 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); | |
2534 | ||
2535 | gp_Pnt aViewDims = myCamera->ViewDimensions(); | |
2536 | ||
2537 | myCamera->SetEye (myCamStartOpEye); | |
2538 | myCamera->SetCenter (myCamStartOpCenter); | |
2539 | Translate (myCamera, -theDXv, -theDYv); | |
2540 | Scale (myCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor); | |
2541 | ||
2542 | SetImmediateUpdate (wasUpdateEnabled); | |
2543 | ||
2544 | ImmediateUpdate(); | |
7fd59977 | 2545 | } |
2546 | ||
197ac94e | 2547 | //======================================================================= |
2548 | //function : Zoom | |
2549 | //purpose : | |
2550 | //======================================================================= | |
2551 | void V3d_View::Zoom (const Standard_Integer theXp1, | |
2552 | const Standard_Integer theYp1, | |
2553 | const Standard_Integer theXp2, | |
2554 | const Standard_Integer theYp2) | |
2555 | { | |
2556 | Standard_Integer aDx = theXp2 - theXp1; | |
2557 | Standard_Integer aDy = theYp2 - theYp1; | |
2558 | if (aDx != 0 || aDy != 0) | |
2559 | { | |
2560 | Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0; | |
2561 | aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff; | |
2562 | SetZoom (aCoeff, Standard_True); | |
2563 | } | |
7fd59977 | 2564 | } |
2565 | ||
197ac94e | 2566 | //======================================================================= |
2567 | //function : StartZoomAtPoint | |
2568 | //purpose : | |
2569 | //======================================================================= | |
2570 | void V3d_View::StartZoomAtPoint (const Standard_Integer theXp, | |
2571 | const Standard_Integer theYp) | |
7fd59977 | 2572 | { |
197ac94e | 2573 | MyZoomAtPointX = theXp; |
2574 | MyZoomAtPointY = theYp; | |
7fd59977 | 2575 | } |
2576 | ||
197ac94e | 2577 | //======================================================================= |
2578 | //function : ZoomAtPoint | |
2579 | //purpose : | |
2580 | //======================================================================= | |
2581 | void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX, | |
2582 | const Standard_Integer theMouseStartY, | |
2583 | const Standard_Integer theMouseEndX, | |
2584 | const Standard_Integer theMouseEndY) | |
7fd59977 | 2585 | { |
197ac94e | 2586 | Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); |
7fd59977 | 2587 | |
197ac94e | 2588 | // zoom |
2589 | Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY)); | |
2590 | Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0; | |
2591 | aDZoom = (aDxy > 0.0) ? aDZoom : 1.0 / aDZoom; | |
7fd59977 | 2592 | |
197ac94e | 2593 | V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient"); |
7fd59977 | 2594 | |
197ac94e | 2595 | Standard_Real aViewWidth = myCamera->ViewDimensions().X(); |
2596 | Standard_Real aViewHeight = myCamera->ViewDimensions().Y(); | |
7fd59977 | 2597 | |
197ac94e | 2598 | // ensure that zoom will not be too small or too big. |
2599 | Standard_Real aCoef = aDZoom; | |
2600 | if (aViewWidth < aCoef * Precision::Confusion()) | |
2601 | { | |
2602 | aCoef = aViewWidth / Precision::Confusion(); | |
2603 | } | |
2604 | else if (aViewWidth > aCoef * 1e12) | |
2605 | { | |
2606 | aCoef = aViewWidth / 1e12; | |
2607 | } | |
2608 | if (aViewHeight < aCoef * Precision::Confusion()) | |
2609 | { | |
2610 | aCoef = aViewHeight / Precision::Confusion(); | |
2611 | } | |
2612 | else if (aViewHeight > aCoef * 1e12) | |
2613 | { | |
2614 | aCoef = aViewHeight / 1e12; | |
2615 | } | |
7fd59977 | 2616 | |
197ac94e | 2617 | Standard_Real aZoomAtPointXv = 0.0; |
2618 | Standard_Real aZoomAtPointYv = 0.0; | |
2619 | Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv); | |
7fd59977 | 2620 | |
197ac94e | 2621 | V3d_Coordinate aDxv = aZoomAtPointXv / aCoef; |
2622 | V3d_Coordinate aDyv = aZoomAtPointYv / aCoef; | |
7fd59977 | 2623 | |
197ac94e | 2624 | myCamera->SetScale (myCamera->Scale() / aCoef); |
2625 | Translate (myCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv); | |
b5ac8292 | 2626 | |
6bc6a6fc | 2627 | View()->AutoZFit(); |
b5ac8292 | 2628 | |
197ac94e | 2629 | SetImmediateUpdate (wasUpdateEnabled); |
7fd59977 | 2630 | |
197ac94e | 2631 | ImmediateUpdate(); |
7fd59977 | 2632 | } |
2633 | ||
197ac94e | 2634 | //============================================================================= |
2635 | //function : AxialScale | |
2636 | //purpose : | |
2637 | //============================================================================= | |
7fd59977 | 2638 | void V3d_View::AxialScale (const Standard_Integer Dx, |
2639 | const Standard_Integer Dy, | |
2640 | const V3d_TypeOfAxe Axis) | |
2641 | { | |
2642 | if( Dx != 0. || Dy != 0. ) { | |
2643 | Standard_Real Sx, Sy, Sz; | |
2644 | AxialScale( Sx, Sy, Sz ); | |
2645 | Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1; | |
2646 | dscale = (Dx > 0) ? dscale : 1./dscale; | |
2647 | if( Axis == V3d_X ) Sx = dscale; | |
2648 | if( Axis == V3d_Y ) Sy = dscale; | |
2649 | if( Axis == V3d_Z ) Sz = dscale; | |
2650 | SetAxialScale( Sx, Sy, Sz ); | |
2651 | } | |
2652 | } | |
2653 | ||
197ac94e | 2654 | //============================================================================= |
2655 | //function : FitAll | |
2656 | //purpose : | |
2657 | //============================================================================= | |
7fd59977 | 2658 | void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow, |
2659 | const Standard_Real Xmin, | |
2660 | const Standard_Real Ymin, | |
2661 | const Standard_Real Xmax, | |
2662 | const Standard_Real Ymax) | |
2663 | { | |
b5ac8292 | 2664 | Standard_Integer aWinWidth, aWinHeight; |
2665 | aWindow->Size (aWinWidth, aWinHeight); | |
7fd59977 | 2666 | |
197ac94e | 2667 | Standard_Real aWinAspect = (Standard_Real)aWinWidth / aWinHeight; |
2668 | Standard_Real aFitSizeU = Abs (Xmax - Xmin); | |
2669 | Standard_Real aFitSizeV = Abs (Ymax - Ymin); | |
2670 | Standard_Real aFitAspect = aFitSizeU / aFitSizeV; | |
2671 | if (aFitAspect >= aWinAspect) | |
2672 | { | |
2673 | aFitSizeV = aFitSizeU / aWinAspect; | |
2674 | } | |
2675 | else | |
2676 | { | |
2677 | aFitSizeU = aFitSizeV * aWinAspect; | |
2678 | } | |
b5ac8292 | 2679 | |
197ac94e | 2680 | myCamera->SetAspect (aWinAspect); |
2681 | Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5); | |
2682 | Scale (myCamera, aFitSizeU, aFitSizeV); | |
6bc6a6fc | 2683 | View()->AutoZFit(); |
7fd59977 | 2684 | |
197ac94e | 2685 | ImmediateUpdate(); |
7fd59977 | 2686 | } |
2687 | ||
197ac94e | 2688 | //============================================================================= |
2689 | //function : StartRotation | |
2690 | //purpose : | |
2691 | //============================================================================= | |
7fd59977 | 2692 | static Standard_Boolean zRotation = Standard_False; |
7fd59977 | 2693 | void V3d_View::StartRotation(const Standard_Integer X, |
2694 | const Standard_Integer Y, | |
2695 | const Quantity_Ratio zRotationThreshold) | |
2696 | { | |
7fd59977 | 2697 | sx = X; sy = Y; |
2698 | Standard_Real x,y; | |
2699 | Size(x,y); | |
2700 | rx = Standard_Real(Convert(x)); | |
2701 | ry = Standard_Real(Convert(y)); | |
2702 | Gravity(gx,gy,gz); | |
2703 | Rotate(0.,0.,0.,gx,gy,gz,Standard_True); | |
7fd59977 | 2704 | zRotation = Standard_False; |
2705 | if( zRotationThreshold > 0. ) { | |
2706 | Standard_Real dx = Abs(sx - rx/2.); | |
2707 | Standard_Real dy = Abs(sy - ry/2.); | |
2708 | // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True; | |
2709 | Standard_Real dd = zRotationThreshold * (rx + ry)/2.; | |
2710 | if( dx > dd || dy > dd ) zRotation = Standard_True; | |
2711 | } | |
7fd59977 | 2712 | |
2713 | } | |
2714 | ||
197ac94e | 2715 | //============================================================================= |
2716 | //function : Rotation | |
2717 | //purpose : | |
2718 | //============================================================================= | |
7fd59977 | 2719 | void V3d_View::Rotation(const Standard_Integer X, |
2720 | const Standard_Integer Y) | |
2721 | { | |
7fd59977 | 2722 | if( rx == 0. || ry == 0. ) { |
2723 | StartRotation(X,Y); | |
2724 | return; | |
2725 | } | |
7fd59977 | 2726 | Standard_Real dx=0.,dy=0.,dz=0.; |
2727 | if( zRotation ) { | |
2728 | dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) - | |
2729 | atan2(sx-rx/2.,ry/2.-sy); | |
2730 | } else { | |
c6541a0c D |
2731 | dx = (Standard_Real(X) - sx) * M_PI / rx; |
2732 | dy = (sy - Standard_Real(Y)) * M_PI / ry; | |
7fd59977 | 2733 | } |
b12a3e54 | 2734 | |
7fd59977 | 2735 | Rotate(dx, dy, dz, gx, gy, gz, Standard_False); |
7fd59977 | 2736 | } |
2737 | ||
197ac94e | 2738 | //============================================================================= |
2739 | //function : SetComputedMode | |
2740 | //purpose : | |
2741 | //============================================================================= | |
2742 | void V3d_View::SetComputedMode (const Standard_Boolean aMode) | |
7fd59977 | 2743 | { |
197ac94e | 2744 | if (aMode) |
2745 | { | |
2746 | if (myComputedMode) | |
2747 | { | |
2748 | MyView->SetComputedMode (Standard_True); | |
2749 | Update(); | |
7fd59977 | 2750 | } |
197ac94e | 2751 | } |
2752 | else | |
2753 | { | |
2754 | MyView->SetComputedMode (Standard_False); | |
2755 | Update(); | |
7fd59977 | 2756 | } |
b8ddfc2f | 2757 | } |
7fd59977 | 2758 | |
197ac94e | 2759 | //============================================================================= |
2760 | //function : ComputedMode | |
2761 | //purpose : | |
2762 | //============================================================================= | |
2763 | Standard_Boolean V3d_View::ComputedMode() const | |
7fd59977 | 2764 | { |
197ac94e | 2765 | return MyView->ComputedMode(); |
b8ddfc2f | 2766 | } |
7fd59977 | 2767 | |
197ac94e | 2768 | //============================================================================= |
2769 | //function : SetBackFacingModel | |
2770 | //purpose : | |
2771 | //============================================================================= | |
2772 | void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel) | |
7fd59977 | 2773 | { |
197ac94e | 2774 | MyView->SetBackFacingModel (Visual3d_TypeOfBackfacingModel(aModel)); |
7fd59977 | 2775 | Redraw(); |
b8ddfc2f | 2776 | } |
7fd59977 | 2777 | |
197ac94e | 2778 | //============================================================================= |
2779 | //function : BackFacingModel | |
2780 | //purpose : | |
2781 | //============================================================================= | |
2782 | V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const | |
b8ddfc2f | 2783 | { |
7fd59977 | 2784 | return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ()); |
b8ddfc2f | 2785 | } |
7fd59977 | 2786 | |
b8ddfc2f | 2787 | void V3d_View::Init() |
2788 | { | |
7fd59977 | 2789 | myComputedMode = MyViewer->ComputedMode(); |
7fd59977 | 2790 | if( !myComputedMode || !MyViewer->DefaultComputedMode() ) { |
2791 | SetComputedMode(Standard_False); | |
2792 | } | |
7fd59977 | 2793 | } |
2794 | ||
197ac94e | 2795 | //============================================================================= |
2796 | //function : Dump | |
2797 | //purpose : | |
2798 | //============================================================================= | |
692613e5 | 2799 | Standard_Boolean V3d_View::Dump (const Standard_CString theFile, |
2800 | const Graphic3d_BufferType& theBufferType) | |
7fd59977 | 2801 | { |
2802 | Standard_Integer aWinWidth, aWinHeight; | |
2803 | MyWindow->Size (aWinWidth, aWinHeight); | |
692613e5 | 2804 | Image_AlienPixMap anImage; |
b5ac8292 | 2805 | |
692613e5 | 2806 | return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile); |
7fd59977 | 2807 | } |
2808 | ||
197ac94e | 2809 | //============================================================================= |
2810 | //function : ToPixMap | |
2811 | //purpose : | |
2812 | //============================================================================= | |
692613e5 | 2813 | Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, |
2814 | const Standard_Integer theWidth, | |
2815 | const Standard_Integer theHeight, | |
2816 | const Graphic3d_BufferType& theBufferType, | |
197ac94e | 2817 | const Standard_Boolean theToKeepAspect, |
b5ac8292 | 2818 | const V3d_StereoDumpOptions theStereoOptions) |
7fd59977 | 2819 | { |
7fd59977 | 2820 | Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView(); |
1981cb22 | 2821 | |
2822 | // always prefer hardware accelerated offscreen buffer | |
7fd59977 | 2823 | Graphic3d_PtrFrameBuffer aFBOPtr = NULL; |
2824 | Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO; | |
85e096c3 | 2825 | Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0); |
7fd59977 | 2826 | Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0); |
2827 | if (aPrevFBOPtr != NULL) | |
2828 | { | |
2829 | MyView->FBOGetDimensions (aPrevFBOPtr, | |
2830 | aPrevFBOVPSizeX, aPrevFBOVPSizeY, | |
2831 | aPrevFBOSizeXMax, aPrevFBOSizeYMax); | |
85e096c3 | 2832 | if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax) |
7fd59977 | 2833 | { |
85e096c3 | 2834 | MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY); |
7fd59977 | 2835 | aFBOPtr = aPrevFBOPtr; |
2836 | } | |
2837 | } | |
2838 | ||
2839 | if (aFBOPtr == NULL) | |
2840 | { | |
2841 | // Try to create hardware accelerated buffer | |
85e096c3 | 2842 | aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY); |
2843 | if (aFBOPtr != NULL) | |
2844 | { | |
2845 | MyView->FBOGetDimensions (aFBOPtr, | |
2846 | aFBOVPSizeX, aFBOVPSizeY, | |
2847 | aFBOSizeXMax, aFBOSizeYMax); | |
2848 | // reduce viewport in case of hardware limits | |
2849 | if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax; | |
2850 | if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax; | |
2851 | MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY); | |
2852 | } | |
7fd59977 | 2853 | } |
2854 | cView->ptrFBO = aFBOPtr; | |
2855 | ||
2856 | // If hardware accelerated buffer - try to use onscreen buffer | |
2857 | // Results may be bad! | |
2858 | if (aFBOPtr == NULL) | |
2859 | { | |
2860 | // retrieve window sizes | |
2861 | Standard_Integer aWinWidth, aWinHeight; | |
2862 | MyWindow->Size (aWinWidth, aWinHeight); | |
2863 | ||
2864 | // technically we can reduce existing viewport... | |
2865 | // but currently allow only dumping the window itself | |
85e096c3 | 2866 | if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight) |
7fd59977 | 2867 | { |
692613e5 | 2868 | return Standard_False; |
7fd59977 | 2869 | } |
2870 | } | |
2871 | ||
b5ac8292 | 2872 | Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera(); |
2873 | ||
2874 | aStoreMapping->Copy (myCamera); | |
7fd59977 | 2875 | |
b5ac8292 | 2876 | if (myCamera->IsStereo()) |
2877 | { | |
2878 | switch (theStereoOptions) | |
2879 | { | |
f978241f | 2880 | case V3d_SDO_MONO: |
2881 | { | |
b5ac8292 | 2882 | myCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); |
2883 | break; | |
f978241f | 2884 | } |
2885 | case V3d_SDO_LEFT_EYE: | |
2886 | { | |
b5ac8292 | 2887 | myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); |
2888 | break; | |
f978241f | 2889 | } |
2890 | case V3d_SDO_RIGHT_EYE: | |
2891 | { | |
b5ac8292 | 2892 | myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); |
2893 | break; | |
f978241f | 2894 | } |
2895 | case V3d_SDO_BLENDED: | |
2896 | { | |
2897 | break; // dump as is | |
2898 | } | |
b5ac8292 | 2899 | } |
2900 | } | |
2901 | ||
679ecdee | 2902 | // render immediate structures into back buffer rather than front |
2903 | Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver()); | |
2904 | const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False); | |
2905 | ||
2906 | const Standard_Boolean toAutoUpdate = myImmediateUpdate; | |
2907 | myImmediateUpdate = Standard_False; | |
6bc6a6fc | 2908 | View()->AutoZFit(); |
679ecdee | 2909 | myImmediateUpdate = toAutoUpdate; |
7fd59977 | 2910 | |
197ac94e | 2911 | if (theToKeepAspect) |
2912 | { | |
54328915 | 2913 | myCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY); |
7fd59977 | 2914 | } |
2915 | ||
7fd59977 | 2916 | Redraw(); |
2917 | ||
1981cb22 | 2918 | if (!aDriver.IsNull()) |
2919 | { | |
2920 | aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode); | |
2921 | } | |
2922 | ||
b5ac8292 | 2923 | myCamera->Copy (aStoreMapping); |
7fd59977 | 2924 | |
692613e5 | 2925 | Standard_Boolean isSuccess = Standard_True; |
2926 | ||
7fd59977 | 2927 | // allocate image buffer for dumping |
692613e5 | 2928 | if (theImage.IsEmpty() |
2929 | || (Standard_Size )aFBOVPSizeX != theImage.SizeX() | |
2930 | || (Standard_Size )aFBOVPSizeY != theImage.SizeY()) | |
7fd59977 | 2931 | { |
692613e5 | 2932 | bool isBigEndian = Image_PixMap::IsBigEndianHost(); |
2933 | Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN; | |
2934 | switch (theBufferType) | |
2935 | { | |
2936 | case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break; | |
2937 | case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break; | |
2938 | case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break; | |
2939 | } | |
2940 | ||
2941 | isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY); | |
7fd59977 | 2942 | } |
692613e5 | 2943 | isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType); |
7fd59977 | 2944 | |
2945 | // FBO now useless, free resources | |
2946 | if (aFBOPtr != aPrevFBOPtr) | |
2947 | { | |
2948 | MyView->FBORelease (aFBOPtr); | |
2949 | } | |
2950 | else if (aPrevFBOPtr != NULL) | |
2951 | { | |
2952 | MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY); | |
2953 | } | |
2954 | cView->ptrFBO = aPrevFBOPtr; | |
692613e5 | 2955 | return isSuccess; |
7fd59977 | 2956 | } |
6942f04a | 2957 | |
2958 | void V3d_View::ImmediateUpdate() const | |
2959 | { | |
2960 | if (myImmediateUpdate) Update(); | |
2961 | } | |
2962 | ||
2963 | Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate) | |
2964 | { | |
2965 | Standard_Boolean aPreviousMode = myImmediateUpdate; | |
2966 | myImmediateUpdate = theImmediateUpdate; | |
2967 | return aPreviousMode; | |
2968 | } | |
b5ac8292 | 2969 | |
2970 | // ======================================================================= | |
2971 | // function : SetCamera | |
2972 | // purpose : | |
2973 | // ======================================================================= | |
2974 | void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera) | |
2975 | { | |
197ac94e | 2976 | Standard_ASSERT_RAISE (!theCamera.IsNull(), "Void camera is not allowed"); |
2977 | ||
b5ac8292 | 2978 | myCamera = theCamera; |
2979 | ||
2980 | MyView->SetCamera (theCamera); | |
2981 | } | |
2982 | ||
2983 | // ======================================================================= | |
2984 | // function : GetCamera | |
2985 | // purpose : | |
2986 | // ======================================================================= | |
197ac94e | 2987 | const Handle(Graphic3d_Camera)& V3d_View::Camera() const |
b5ac8292 | 2988 | { |
2989 | return myCamera; | |
2990 | } | |
2991 | ||
2992 | // ======================================================================= | |
197ac94e | 2993 | // function : FitMinMax |
2994 | // purpose : Internal | |
b5ac8292 | 2995 | // ======================================================================= |
197ac94e | 2996 | Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera, |
ed063270 | 2997 | const Bnd_Box& theBox, |
197ac94e | 2998 | const Standard_Real theMargin, |
2999 | const Standard_Real theResolution, | |
3000 | const Standard_Boolean theToEnlargeIfLine) const | |
3001 | { | |
3002 | // Check bounding box for validness | |
ed063270 | 3003 | if (theBox.IsVoid()) |
b5ac8292 | 3004 | { |
197ac94e | 3005 | return Standard_False; // bounding box is out of bounds... |
3006 | } | |
3007 | ||
3008 | // Apply "axial scaling" to the bounding points. | |
3009 | // It is not the best approach to make this scaling as a part of fit all operation, | |
3010 | // but the axial scale is integrated into camera orientation matrix and the other | |
3011 | // option is to perform frustum plane adjustment algorithm in view camera space, | |
3012 | // which will lead to a number of additional world-view space conversions and | |
3013 | // loosing precision as well. | |
ab1c121b | 3014 | gp_Pnt aBndMin = theBox.CornerMin().XYZ().Multiplied (theCamera->AxialScale()); |
3015 | gp_Pnt aBndMax = theBox.CornerMax().XYZ().Multiplied (theCamera->AxialScale()); | |
3016 | ||
3017 | if (aBndMax.IsEqual (aBndMin, RealEpsilon())) | |
b5ac8292 | 3018 | { |
197ac94e | 3019 | return Standard_False; // nothing to fit all |
3020 | } | |
3021 | ||
ab1c121b | 3022 | // Prepare camera frustum planes. |
3023 | NCollection_Array1<gp_Pln> aFrustumPlane (1, 6); | |
3024 | theCamera->Frustum (aFrustumPlane.ChangeValue (1), | |
3025 | aFrustumPlane.ChangeValue (2), | |
3026 | aFrustumPlane.ChangeValue (3), | |
3027 | aFrustumPlane.ChangeValue (4), | |
3028 | aFrustumPlane.ChangeValue (5), | |
3029 | aFrustumPlane.ChangeValue (6)); | |
197ac94e | 3030 | |
ab1c121b | 3031 | // Prepare camera up, side, direction vectors. |
197ac94e | 3032 | gp_Dir aCamUp = theCamera->OrthogonalizedUp(); |
3033 | gp_Dir aCamDir = theCamera->Direction(); | |
3034 | gp_Dir aCamSide = aCamDir ^ aCamUp; | |
3035 | ||
ab1c121b | 3036 | // Prepare scene bounding box parameters. |
3037 | gp_Pnt aBndCenter = (aBndMin.XYZ() + aBndMax.XYZ()) / 2.0; | |
3038 | ||
3039 | NCollection_Array1<gp_Pnt> aBndCorner (1, 8); | |
3040 | aBndCorner.ChangeValue (1) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMin.Z()); | |
3041 | aBndCorner.ChangeValue (2) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMax.Z()); | |
3042 | aBndCorner.ChangeValue (3) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMin.Z()); | |
3043 | aBndCorner.ChangeValue (4) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMax.Z()); | |
3044 | aBndCorner.ChangeValue (5) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMin.Z()); | |
3045 | aBndCorner.ChangeValue (6) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMax.Z()); | |
3046 | aBndCorner.ChangeValue (7) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMin.Z()); | |
3047 | aBndCorner.ChangeValue (8) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMax.Z()); | |
3048 | ||
197ac94e | 3049 | // Perspective-correct camera projection vector, matching the bounding box is determined geometrically. |
3050 | // Knowing the initial shape of a frustum it is possible to match it to a bounding box. | |
3051 | // Then, knowing the relation of camera projection vector to the frustum shape it is possible to | |
3052 | // set up perspective-correct camera projection matching the bounding box. | |
3053 | // These steps support non-asymmetric transformations of view-projection space provided by camera. | |
3054 | // The zooming can be done by calculating view plane size matching the bounding box at center of | |
3055 | // the bounding box. The only limitation here is that the scale of camera should define size of | |
3056 | // its view plane passing through the camera center, and the center of camera should be on the | |
3057 | // same line with the center of bounding box. | |
3058 | ||
3059 | // The following method is applied: | |
3060 | // 1) Determine normalized asymmetry of camera projection vector by frustum planes. | |
3061 | // 2) Determine new location of frustum planes, "matching" the bounding box. | |
3062 | // 3) Determine new camera projection vector using the normalized asymmetry. | |
3063 | // 4) Determine new zooming in view space. | |
3064 | ||
ab1c121b | 3065 | // 1. Determine normalized projection asymmetry (if any). |
3066 | Standard_Real anAssymX = Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction())) | |
3067 | - Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction())); | |
3068 | Standard_Real anAssymY = Tan ( aCamUp.Angle (aFrustumPlane (3).Axis().Direction())) | |
3069 | - Tan (-aCamUp.Angle (aFrustumPlane (4).Axis().Direction())); | |
3070 | ||
3071 | // 2. Determine how far should be the frustum planes placed from center | |
3072 | // of bounding box, in order to match the bounding box closely. | |
3073 | NCollection_Array1<Standard_Real> aFitDistance (1, 6); | |
3074 | aFitDistance.ChangeValue (1) = 0.0; | |
3075 | aFitDistance.ChangeValue (2) = 0.0; | |
3076 | aFitDistance.ChangeValue (3) = 0.0; | |
3077 | aFitDistance.ChangeValue (4) = 0.0; | |
3078 | aFitDistance.ChangeValue (5) = 0.0; | |
3079 | aFitDistance.ChangeValue (6) = 0.0; | |
3080 | ||
3081 | for (Standard_Integer anI = aFrustumPlane.Lower(); anI <= aFrustumPlane.Upper(); ++anI) | |
197ac94e | 3082 | { |
ab1c121b | 3083 | // Measure distances from center of bounding box to its corners towards the frustum plane. |
3084 | const gp_Dir& aPlaneN = aFrustumPlane.ChangeValue (anI).Axis().Direction(); | |
197ac94e | 3085 | |
ab1c121b | 3086 | Standard_Real& aFitDist = aFitDistance.ChangeValue (anI); |
197ac94e | 3087 | |
ab1c121b | 3088 | for (Standard_Integer aJ = aBndCorner.Lower(); aJ <= aBndCorner.Upper(); ++aJ) |
3089 | { | |
3090 | aFitDist = Max (aFitDist, gp_Vec (aBndCenter, aBndCorner (aJ)).Dot (aPlaneN)); | |
3091 | } | |
197ac94e | 3092 | } |
3093 | // The center of camera is placed on the same line with center of bounding box. | |
3094 | // The view plane section crosses the bounding box at its center. | |
3095 | // To compute view plane size, evaluate coefficients converting "point -> plane distance" | |
3096 | // into view section size between the point and the frustum plane. | |
3097 | // proj | |
3098 | // /|\ right half of frame // | |
3099 | // | // | |
3100 | // point o<-- distance * coeff -->//---- (view plane section) | |
3101 | // \ // | |
3102 | // (distance) // | |
3103 | // ~ // | |
3104 | // (distance) // | |
3105 | // \/\// | |
3106 | // \// | |
3107 | // // | |
3108 | // (frustum plane) | |
ab1c121b | 3109 | aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction())), 2.0)); |
3110 | aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction())), 2.0)); | |
3111 | aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan ( aCamUp.Angle (aFrustumPlane (3).Axis().Direction())), 2.0)); | |
3112 | aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan (-aCamUp.Angle (aFrustumPlane (4).Axis().Direction())), 2.0)); | |
3113 | aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan ( aCamDir.Angle (aFrustumPlane (5).Axis().Direction())), 2.0)); | |
3114 | aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan (-aCamDir.Angle (aFrustumPlane (6).Axis().Direction())), 2.0)); | |
3115 | ||
3116 | Standard_Real aViewSizeXv = aFitDistance (1) + aFitDistance (2); | |
3117 | Standard_Real aViewSizeYv = aFitDistance (3) + aFitDistance (4); | |
3118 | Standard_Real aViewSizeZv = aFitDistance (5) + aFitDistance (6); | |
3119 | ||
3120 | // 3. Place center of camera on the same line with center of bounding | |
3121 | // box applying corresponding projection asymmetry (if any). | |
197ac94e | 3122 | Standard_Real anAssymXv = anAssymX * aViewSizeXv * 0.5; |
3123 | Standard_Real anAssymYv = anAssymY * aViewSizeYv * 0.5; | |
ab1c121b | 3124 | Standard_Real anOffsetXv = (aFitDistance (2) - aFitDistance (1)) * 0.5 + anAssymXv; |
3125 | Standard_Real anOffsetYv = (aFitDistance (4) - aFitDistance (3)) * 0.5 + anAssymYv; | |
197ac94e | 3126 | gp_Vec aTranslateSide = gp_Vec (aCamSide) * anOffsetXv; |
3127 | gp_Vec aTranslateUp = gp_Vec (aCamUp) * anOffsetYv; | |
ab1c121b | 3128 | gp_Pnt aCamNewCenter = aBndCenter.Translated (aTranslateSide).Translated (aTranslateUp); |
197ac94e | 3129 | |
3130 | gp_Trsf aCenterTrsf; | |
ab1c121b | 3131 | aCenterTrsf.SetTranslation (theCamera->Center(), aCamNewCenter); |
197ac94e | 3132 | theCamera->Transform (aCenterTrsf); |
ab1c121b | 3133 | theCamera->SetDistance (aFitDistance (6) + aFitDistance (5)); |
197ac94e | 3134 | |
3135 | // Bounding box collapses to a point or thin line going in depth of the screen | |
3136 | if (aViewSizeXv < theResolution && aViewSizeYv < theResolution) | |
b5ac8292 | 3137 | { |
197ac94e | 3138 | if (aViewSizeXv < theResolution || !theToEnlargeIfLine) |
3139 | { | |
3140 | return Standard_True; // This is just one point or line and zooming has no effect. | |
3141 | } | |
3142 | ||
3143 | // Looking along line and "theToEnlargeIfLine" is requested. | |
3144 | // Fit view to see whole scene on rotation. | |
3145 | aViewSizeXv = aViewSizeZv; | |
3146 | aViewSizeYv = aViewSizeZv; | |
b5ac8292 | 3147 | } |
3148 | ||
197ac94e | 3149 | Scale (theCamera, aViewSizeXv * (1.0 + theMargin), aViewSizeYv * (1.0 + theMargin)); |
b5ac8292 | 3150 | |
197ac94e | 3151 | return Standard_True; |
b5ac8292 | 3152 | } |
3153 | ||
3154 | // ======================================================================= | |
197ac94e | 3155 | // function : Scale |
3156 | // purpose : Internal | |
b5ac8292 | 3157 | // ======================================================================= |
197ac94e | 3158 | void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera, |
3159 | const Standard_Real theSizeXv, | |
3160 | const Standard_Real theSizeYv) const | |
b5ac8292 | 3161 | { |
197ac94e | 3162 | Standard_Real anAspect = theCamera->Aspect(); |
ab1c121b | 3163 | if (anAspect > 1.0) |
3164 | { | |
3165 | theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv)); | |
3166 | } | |
3167 | else | |
3168 | { | |
3169 | theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect)); | |
3170 | } | |
b5ac8292 | 3171 | } |
3172 | ||
3173 | // ======================================================================= | |
197ac94e | 3174 | // function : Translate |
3175 | // purpose : Internal | |
b5ac8292 | 3176 | // ======================================================================= |
197ac94e | 3177 | void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera, |
3178 | const Standard_Real theDXv, | |
3179 | const Standard_Real theDYv) const | |
3180 | { | |
3181 | const gp_Pnt& aCenter = theCamera->Center(); | |
3182 | const gp_Dir& aDir = theCamera->Direction(); | |
3183 | const gp_Dir& anUp = theCamera->Up(); | |
3184 | gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp); | |
3185 | ||
3186 | gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv; | |
3187 | gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv; | |
3188 | gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv; | |
3189 | gp_Trsf aPanTrsf; | |
3190 | aPanTrsf.SetTranslation (aCameraPan); | |
3191 | ||
3192 | theCamera->Transform (aPanTrsf); | |
b5ac8292 | 3193 | } |
b7cd4ba7 | 3194 | |
3195 | // ======================================================================= | |
3196 | // function : IsCullingEnabled | |
3197 | // purpose : | |
3198 | // ======================================================================= | |
3199 | Standard_Boolean V3d_View::IsCullingEnabled() const | |
3200 | { | |
3201 | Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView(); | |
3202 | return aView->IsCullingEnabled; | |
3203 | } | |
3204 | ||
3205 | // ======================================================================= | |
3206 | // function : SetFrustumCulling | |
3207 | // purpose : | |
3208 | // ======================================================================= | |
3209 | void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip) | |
3210 | { | |
3211 | Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView(); | |
3212 | aView->IsCullingEnabled = theToClip; | |
3213 | } |