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