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