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