1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <V3d_View.hxx>
16 #include <Aspect_CircularGrid.hxx>
17 #include <Aspect_GradientBackground.hxx>
18 #include <Aspect_Grid.hxx>
19 #include <Aspect_NeutralWindow.hxx>
20 #include <Aspect_RectangularGrid.hxx>
21 #include <Aspect_Window.hxx>
22 #include <Bnd_Box.hxx>
26 #include <Graphic3d_GraphicDriver.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
29 #include <Graphic3d_MapOfStructure.hxx>
30 #include <Graphic3d_Structure.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Image_AlienPixMap.hxx>
33 #include <Message.hxx>
34 #include <Message_Messenger.hxx>
35 #include <NCollection_Array1.hxx>
36 #include <Precision.hxx>
37 #include <Quantity_Color.hxx>
38 #include <Standard_Assert.hxx>
39 #include <Standard_DivideByZero.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include <Standard_ShortReal.hxx>
42 #include <Standard_Type.hxx>
43 #include <Standard_TypeMismatch.hxx>
44 #include <TColStd_Array2OfReal.hxx>
46 #include <V3d_BadValue.hxx>
47 #include <V3d_Light.hxx>
48 #include <V3d_StereoDumpOptions.hxx>
49 #include <V3d_UnMapped.hxx>
50 #include <V3d_Viewer.hxx>
52 IMPLEMENT_STANDARD_RTTIEXT(V3d_View,Standard_Transient)
54 #define DEUXPI (2. * M_PI)
58 static const Standard_Integer THE_NB_BOUND_POINTS = 8;
61 //=============================================================================
62 //function : Constructor
64 //=============================================================================
65 V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType)
66 : myIsInvalidatedImmediate (Standard_True),
67 MyViewer (theViewer.operator->()),
68 SwitchSetFront (Standard_False),
69 myZRotation (Standard_False),
72 myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
74 myView->SetBackground (theViewer->GetBackgroundColor());
75 myView->SetGradientBackground (theViewer->GetGradientBackground());
77 ChangeRenderingParams() = theViewer->DefaultRenderingParams();
80 Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
81 aCamera->SetFOVy (45.0);
82 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
83 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
84 aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
85 ? Graphic3d_Camera::Projection_Orthographic
86 : Graphic3d_Camera::Projection_Perspective);
88 myDefaultCamera = new Graphic3d_Camera();
90 myImmediateUpdate = Standard_False;
91 SetAutoZFitMode (Standard_True, 1.0);
92 SetBackFacingModel (V3d_TOBM_AUTOMATIC);
94 SetAxis (0.,0.,0.,1.,1.,1.);
95 SetVisualization (theViewer->DefaultVisualization());
98 SetProj (theViewer->DefaultViewProj());
99 SetSize (theViewer->DefaultViewSize());
100 Standard_Real zsize = theViewer->DefaultViewSize();
102 SetDepth (theViewer->DefaultViewSize() / 2.0);
103 SetViewMappingDefault();
104 SetViewOrientationDefault();
105 theViewer->AddView (this);
107 myImmediateUpdate = Standard_True;
110 //=============================================================================
111 //function : Constructor
113 //=============================================================================
114 V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
115 : myIsInvalidatedImmediate (Standard_True),
116 MyViewer (theViewer.operator->()),
117 SwitchSetFront(Standard_False),
118 myZRotation (Standard_False),
121 myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
123 myView->CopySettings (theView->View());
124 myDefaultViewPoint = theView->myDefaultViewPoint;
125 myDefaultViewAxis = theView->myDefaultViewAxis;
127 myDefaultCamera = new Graphic3d_Camera (theView->DefaultCamera());
129 myImmediateUpdate = Standard_False;
130 SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
131 theViewer->AddView (this);
133 myImmediateUpdate = Standard_True;
136 //=============================================================================
137 //function : Destructor
139 //=============================================================================
140 V3d_View::~V3d_View()
142 if (myParentView != nullptr)
144 myParentView->RemoveSubview (this);
145 myParentView = nullptr;
148 NCollection_Sequence<Handle(V3d_View)> aSubviews = mySubviews;
150 for (const Handle(V3d_View)& aViewIter : aSubviews)
152 //aViewIter->Remove();
153 aViewIter->myParentView = nullptr;
154 aViewIter->MyWindow.Nullify();
155 aViewIter->myView->Remove();
156 if (aViewIter->MyViewer != nullptr)
158 aViewIter->MyViewer->SetViewOff (aViewIter);
163 if (!myView->IsRemoved())
169 //=============================================================================
170 //function : SetMagnify
172 //=============================================================================
173 void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow,
174 const Handle(V3d_View)& thePreviousView,
175 const Standard_Integer theX1,
176 const Standard_Integer theY1,
177 const Standard_Integer theX2,
178 const Standard_Integer theY2)
180 if (!myView->IsRemoved() && !myView->IsDefined())
182 Standard_Real aU1, aV1, aU2, aV2;
183 thePreviousView->Convert (theX1, theY1, aU1, aV1);
184 thePreviousView->Convert (theX2, theY2, aU2, aV2);
185 myView->SetWindow (Handle(Graphic3d_CView)(), theWindow, nullptr);
186 FitAll (aU1, aV1, aU2, aV2);
187 MyViewer->SetViewOn (this);
188 MyWindow = theWindow;
191 SetViewMappingDefault();
195 //=============================================================================
196 //function : SetWindow
198 //=============================================================================
199 void V3d_View::SetWindow (const Handle(Aspect_Window)& theWindow,
200 const Aspect_RenderingContext theContext)
202 if (myView->IsRemoved())
206 if (myParentView != nullptr)
208 throw Standard_ProgramError ("V3d_View::SetWindow() called twice");
211 // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
212 MyWindow = theWindow;
213 myView->SetWindow (Handle(Graphic3d_CView)(), theWindow, theContext);
214 MyViewer->SetViewOn (this);
216 if (myImmediateUpdate)
222 //=============================================================================
223 //function : SetWindow
225 //=============================================================================
226 void V3d_View::SetWindow (const Handle(V3d_View)& theParentView,
227 const Graphic3d_Vec2d& theSize,
228 Aspect_TypeOfTriedronPosition theCorner,
229 const Graphic3d_Vec2d& theOffset,
230 const Graphic3d_Vec2i& theMargins)
232 if (myView->IsRemoved())
237 Handle(V3d_View) aParentView = !theParentView->IsSubview()
239 : theParentView->ParentView();
240 if (aParentView != myParentView)
242 if (myParentView != nullptr)
244 throw Standard_ProgramError ("V3d_View::SetWindow() called twice");
247 myParentView = aParentView.get();
248 aParentView->AddSubview (this);
251 Handle(Aspect_NeutralWindow) aWindow = new Aspect_NeutralWindow();
252 aWindow->SetVirtual (true);
253 aWindow->SetSize (4, 4);
254 myView->SetSubviewCorner (theCorner);
255 myView->SetSubviewSize (theSize);
256 myView->SetSubviewOffset (theOffset);
257 myView->SetSubviewMargins (theMargins);
260 myView->SetWindow (aParentView->View(), aWindow, 0);
261 MyViewer->SetViewOn (this);
265 //=============================================================================
268 //=============================================================================
269 void V3d_View::Remove()
271 if (!MyGrid.IsNull())
275 if (!myTrihedron.IsNull())
277 myTrihedron->Erase();
280 if (myParentView != nullptr)
282 myParentView->RemoveSubview (this);
283 myParentView = nullptr;
286 NCollection_Sequence<Handle(V3d_View)> aSubviews = mySubviews;
288 for (const Handle(V3d_View)& aViewIter : aSubviews)
294 if (MyViewer != nullptr)
296 MyViewer->DelView (this);
303 // =======================================================================
304 // function : AddSubview
306 // =======================================================================
307 void V3d_View::AddSubview (const Handle(V3d_View)& theView)
309 mySubviews.Append (theView);
312 // =======================================================================
313 // function : RemoveSubview
315 // =======================================================================
316 bool V3d_View::RemoveSubview (const V3d_View* theView)
318 for (NCollection_Sequence<Handle(V3d_View)>::Iterator aViewIter (mySubviews); aViewIter.More(); aViewIter.Next())
320 if (aViewIter.Value() == theView)
322 mySubviews.Remove (aViewIter);
329 // =============================================================================
330 // function : PickSubview
332 // =============================================================================
333 Handle(V3d_View) V3d_View::PickSubview (const Graphic3d_Vec2i& thePnt) const
336 || thePnt.x() >= MyWindow->Dimensions().x()
338 || thePnt.y() >= MyWindow->Dimensions().y())
340 return Handle(V3d_View)();
343 // iterate in opposite direction - from front to bottom views
344 for (Standard_Integer aSubviewIter = mySubviews.Upper(); aSubviewIter >= mySubviews.Lower(); --aSubviewIter)
346 const Handle(V3d_View)& aSubview = mySubviews.Value (aSubviewIter);
347 if (aSubview->View()->IsActive()
348 && thePnt.x() >= aSubview->View()->SubviewTopLeft().x()
349 && thePnt.x() < (aSubview->View()->SubviewTopLeft().x() + aSubview->Window()->Dimensions().x())
350 && thePnt.y() >= aSubview->View()->SubviewTopLeft().y()
351 && thePnt.y() < (aSubview->View()->SubviewTopLeft().y() + aSubview->Window()->Dimensions().y()))
360 //=============================================================================
363 //=============================================================================
364 void V3d_View::Update() const
366 if (!myView->IsDefined()
367 || !myView->IsActive())
372 myIsInvalidatedImmediate = Standard_False;
379 //=============================================================================
382 //=============================================================================
383 void V3d_View::Redraw() const
385 if (!myView->IsDefined()
386 || !myView->IsActive())
391 myIsInvalidatedImmediate = Standard_False;
392 Handle(Graphic3d_StructureManager) aStructureMgr = MyViewer->StructureManager();
393 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
395 if (aStructureMgr->IsDeviceLost())
397 aStructureMgr->RecomputeStructures();
404 if (!aStructureMgr->IsDeviceLost())
411 //=============================================================================
412 //function : RedrawImmediate
414 //=============================================================================
415 void V3d_View::RedrawImmediate() const
417 if (!myView->IsDefined()
418 || !myView->IsActive())
423 myIsInvalidatedImmediate = Standard_False;
424 myView->RedrawImmediate();
427 //=============================================================================
428 //function : Invalidate
430 //=============================================================================
431 void V3d_View::Invalidate() const
433 if (!myView->IsDefined())
438 myView->Invalidate();
441 //=============================================================================
442 //function : IsInvalidated
444 //=============================================================================
445 Standard_Boolean V3d_View::IsInvalidated() const
447 return !myView->IsDefined()
448 || myView->IsInvalidated();
451 // ========================================================================
452 // function : SetAutoZFitMode
454 // ========================================================================
455 void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
456 const Standard_Real theScaleFactor)
458 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
459 myAutoZFitScaleFactor = theScaleFactor;
460 myAutoZFitIsOn = theIsOn;
463 //=============================================================================
464 //function : AutoZFit
466 //=============================================================================
467 void V3d_View::AutoZFit() const
474 ZFitAll (myAutoZFitScaleFactor);
477 //=============================================================================
480 //=============================================================================
481 void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const
483 Bnd_Box aMinMaxBox = myView->MinMaxValues (Standard_False); // applicative min max boundaries
484 Bnd_Box aGraphicBox = myView->MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag).
486 myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
489 //=============================================================================
492 //=============================================================================
493 Standard_Boolean V3d_View::IsEmpty() const
495 Standard_Boolean TheStatus = Standard_True ;
496 if( myView->IsDefined() ) {
497 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
498 if( Nstruct > 0 ) TheStatus = Standard_False ;
503 //=============================================================================
504 //function : UpdateLights
506 //=============================================================================
507 void V3d_View::UpdateLights() const
509 Handle(Graphic3d_LightSet) aLights = new Graphic3d_LightSet();
510 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
512 aLights->Add (anActiveLightIter.Value());
514 myView->SetLights (aLights);
517 //=============================================================================
518 //function : DoMapping
520 //=============================================================================
521 void V3d_View::DoMapping()
523 if (!myView->IsDefined())
528 myView->Window()->DoMapping();
531 //=============================================================================
532 //function : MustBeResized
534 //=============================================================================
535 void V3d_View::MustBeResized()
537 if (!myView->IsDefined())
545 if (myImmediateUpdate)
551 //=============================================================================
552 //function : SetBackgroundColor
554 //=============================================================================
555 void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
556 const Standard_Real theV1,
557 const Standard_Real theV2,
558 const Standard_Real theV3)
560 Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0);
561 Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0);
562 Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0);
564 SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
567 //=============================================================================
568 //function : SetBackgroundColor
570 //=============================================================================
571 void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
573 myView->SetBackground (Aspect_Background (theColor));
575 if (myImmediateUpdate)
581 //=============================================================================
582 //function : SetBgGradientColors
584 //=============================================================================
585 void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
586 const Quantity_Color& theColor2,
587 const Aspect_GradientFillMethod theFillStyle,
588 const Standard_Boolean theToUpdate)
590 Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
592 myView->SetGradientBackground (aGradientBg);
594 if (myImmediateUpdate || theToUpdate)
600 //=============================================================================
601 //function : SetBgGradientStyle
603 //=============================================================================
604 void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate)
606 Quantity_Color aColor1;
607 Quantity_Color aColor2;
608 GradientBackground().Colors (aColor1, aColor2);
610 SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
613 //=============================================================================
614 //function : SetBackgroundImage
616 //=============================================================================
617 void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
618 const Aspect_FillMethod theFillStyle,
619 const Standard_Boolean theToUpdate)
621 Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2D (theFileName);
622 aTextureMap->DisableModulate();
623 SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate);
626 //=============================================================================
627 //function : SetBackgroundImage
629 //=============================================================================
630 void V3d_View::SetBackgroundImage (const Handle(Graphic3d_Texture2D)& theTexture,
631 const Aspect_FillMethod theFillStyle,
632 const Standard_Boolean theToUpdate)
634 myView->SetBackgroundImage (theTexture);
635 myView->SetBackgroundImageStyle (theFillStyle);
636 if (myImmediateUpdate || theToUpdate)
642 //=============================================================================
643 //function : SetBgImageStyle
645 //=============================================================================
646 void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
648 myView->SetBackgroundImageStyle (theFillStyle);
650 if (myImmediateUpdate || theToUpdate)
656 //=============================================================================
657 //function : SetBackgroundCubeMap
659 //=============================================================================
660 void V3d_View::SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
661 Standard_Boolean theToUpdatePBREnv,
662 Standard_Boolean theToUpdate)
664 myView->SetBackgroundImage (theCubeMap, theToUpdatePBREnv);
665 if (myImmediateUpdate || theToUpdate)
671 //=============================================================================
672 //function : SetBackgroundSkydome
674 //=============================================================================
675 void V3d_View::SetBackgroundSkydome (const Aspect_SkydomeBackground& theAspect,
676 Standard_Boolean theToUpdatePBREnv)
678 myView->SetBackgroundSkydome (theAspect, theToUpdatePBREnv);
681 //=============================================================================
682 //function : IsImageBasedLighting
684 //=============================================================================
685 Standard_Boolean V3d_View::IsImageBasedLighting() const
687 return !myView->IBLCubeMap().IsNull();
690 //=============================================================================
691 //function : SetImageBasedLighting
693 //=============================================================================
694 void V3d_View::SetImageBasedLighting (Standard_Boolean theToEnableIBL,
695 Standard_Boolean theToUpdate)
697 myView->SetImageBasedLighting (theToEnableIBL);
698 if (myImmediateUpdate || theToUpdate)
704 //=============================================================================
707 //=============================================================================
708 void V3d_View::SetAxis (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
709 const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
711 myDefaultViewPoint.SetCoord (theX, theY, theZ);
712 myDefaultViewAxis.SetCoord (theVx, theVy, theVz);
715 //=============================================================================
716 //function : SetShadingModel
718 //=============================================================================
719 void V3d_View::SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel)
721 myView->SetShadingModel (theShadingModel);
724 //=============================================================================
725 //function : SetTextureEnv
727 //=============================================================================
728 void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
730 myView->SetTextureEnv (theTexture);
732 if (myImmediateUpdate)
738 //=============================================================================
739 //function : SetVisualization
741 //=============================================================================
742 void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
744 myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
746 if (myImmediateUpdate)
752 //=============================================================================
753 //function : SetFront
755 //=============================================================================
756 void V3d_View::SetFront()
758 gp_Ax3 a = MyViewer->PrivilegedPlane();
759 Standard_Real xo, yo, zo, vx, vy, vz, xu, yu, zu;
761 a.Direction().Coord(vx,vy,vz);
762 a.YDirection().Coord(xu,yu,zu);
763 a.Location().Coord(xo,yo,zo);
765 Handle(Graphic3d_Camera) aCamera = Camera();
767 aCamera->SetCenter (gp_Pnt (xo, yo, zo));
771 aCamera->SetDirection (gp_Dir (vx, vy, vz));
775 aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
778 aCamera->SetUp (gp_Dir (xu, yu, zu));
780 SwitchSetFront = !SwitchSetFront;
785 //=============================================================================
788 //=============================================================================
789 void V3d_View::Rotate (const Standard_Real ax,
790 const Standard_Real ay,
791 const Standard_Real az,
792 const Standard_Boolean Start)
794 Standard_Real Ax = ax;
795 Standard_Real Ay = ay;
796 Standard_Real Az = az;
798 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI;
799 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI;
800 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI;
801 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI;
802 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
803 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
805 Handle(Graphic3d_Camera) aCamera = Camera();
809 myCamStartOpUp = aCamera->Up();
810 myCamStartOpDir = aCamera->Direction();
811 myCamStartOpEye = aCamera->Eye();
812 myCamStartOpCenter = aCamera->Center();
815 aCamera->SetUp (myCamStartOpUp);
816 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
817 aCamera->SetDirectionFromEye (myCamStartOpDir);
819 // rotate camera around 3 initial axes
820 gp_Dir aBackDir = -myCamStartOpDir;
821 gp_Dir aXAxis (myCamStartOpUp.Crossed (aBackDir));
822 gp_Dir aYAxis (aBackDir.Crossed (aXAxis));
823 gp_Dir aZAxis (aXAxis.Crossed (aYAxis));
825 gp_Trsf aRot[3], aTrsf;
826 aRot[0].SetRotation (gp_Ax1 (myCamStartOpCenter, aYAxis), -Ax);
827 aRot[1].SetRotation (gp_Ax1 (myCamStartOpCenter, aXAxis), Ay);
828 aRot[2].SetRotation (gp_Ax1 (myCamStartOpCenter, aZAxis), Az);
829 aTrsf.Multiply (aRot[0]);
830 aTrsf.Multiply (aRot[1]);
831 aTrsf.Multiply (aRot[2]);
833 aCamera->Transform (aTrsf);
838 //=============================================================================
841 //=============================================================================
842 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
843 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
846 Standard_Real Ax = ax ;
847 Standard_Real Ay = ay ;
848 Standard_Real Az = az ;
850 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
851 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
852 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
853 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
854 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
855 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
857 Handle(Graphic3d_Camera) aCamera = Camera();
861 myGravityReferencePoint.SetCoord (X, Y, Z);
862 myCamStartOpUp = aCamera->Up();
863 myCamStartOpDir = aCamera->Direction();
864 myCamStartOpEye = aCamera->Eye();
865 myCamStartOpCenter = aCamera->Center();
868 const Graphic3d_Vertex& aVref = myGravityReferencePoint;
870 aCamera->SetUp (myCamStartOpUp);
871 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
872 aCamera->SetDirectionFromEye (myCamStartOpDir);
874 // rotate camera around 3 initial axes
875 gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
877 gp_Dir aZAxis (aCamera->Direction().Reversed());
878 gp_Dir aYAxis (aCamera->Up());
879 gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
881 gp_Trsf aRot[3], aTrsf;
882 aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
883 aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
884 aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
885 aTrsf.Multiply (aRot[0]);
886 aTrsf.Multiply (aRot[1]);
887 aTrsf.Multiply (aRot[2]);
889 aCamera->Transform (aTrsf);
894 //=============================================================================
897 //=============================================================================
898 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
902 Rotate(angle,0.,0.,Start);
905 Rotate(0.,angle,0.,Start);
908 Rotate(0.,0.,angle,Start);
913 //=============================================================================
916 //=============================================================================
917 void V3d_View::Rotate (const V3d_TypeOfAxe theAxe, const Standard_Real theAngle,
918 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Boolean theStart)
920 Standard_Real anAngle = theAngle;
922 if (anAngle > 0.0) while (anAngle > DEUXPI) anAngle -= DEUXPI;
923 else if (anAngle < 0.0) while (anAngle < -DEUXPI) anAngle += DEUXPI;
925 Handle(Graphic3d_Camera) aCamera = Camera();
929 myGravityReferencePoint.SetCoord (theX, theY, theZ);
930 myCamStartOpUp = aCamera->Up();
931 myCamStartOpDir = aCamera->Direction();
932 myCamStartOpEye = aCamera->Eye();
933 myCamStartOpCenter = aCamera->Center();
936 case V3d_X: myViewAxis = gp::DX(); break;
937 case V3d_Y: myViewAxis = gp::DY(); break;
938 case V3d_Z: myViewAxis = gp::DZ(); break;
942 const Graphic3d_Vertex& aVref = myGravityReferencePoint;
944 aCamera->SetUp (myCamStartOpUp);
945 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
946 aCamera->SetDirectionFromEye (myCamStartOpDir);
948 // rotate camera around passed axis
950 gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
951 gp_Dir aRAxis ((theAxe == V3d_X) ? 1.0 : 0.0,
952 (theAxe == V3d_Y) ? 1.0 : 0.0,
953 (theAxe == V3d_Z) ? 1.0 : 0.0);
955 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), anAngle);
957 aCamera->Transform (aRotation);
962 //=============================================================================
965 //=============================================================================
966 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
968 Standard_Real Angle = angle;
970 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
971 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
973 Handle(Graphic3d_Camera) aCamera = Camera();
977 myCamStartOpUp = aCamera->Up();
978 myCamStartOpDir = aCamera->Direction();
979 myCamStartOpEye = aCamera->Eye();
980 myCamStartOpCenter = aCamera->Center();
983 aCamera->SetUp (myCamStartOpUp);
984 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
985 aCamera->SetDirectionFromEye (myCamStartOpDir);
988 gp_Pnt aRCenter (myDefaultViewPoint);
989 gp_Dir aRAxis (myDefaultViewAxis);
990 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
992 aCamera->Transform (aRotation);
997 //=============================================================================
1000 //=============================================================================
1001 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1003 Standard_Real Ax = ax;
1004 Standard_Real Ay = ay;
1005 Standard_Real Az = az;
1007 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
1008 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
1009 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
1010 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
1011 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
1012 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
1014 Handle(Graphic3d_Camera) aCamera = Camera();
1018 myCamStartOpUp = aCamera->Up();
1019 myCamStartOpDir = aCamera->Direction();
1020 myCamStartOpEye = aCamera->Eye();
1021 myCamStartOpCenter = aCamera->Center();
1024 aCamera->SetUp (myCamStartOpUp);
1025 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
1026 aCamera->SetDirectionFromEye (myCamStartOpDir);
1028 // rotate camera around 3 initial axes
1029 gp_Pnt aRCenter = aCamera->Eye();
1030 gp_Dir aZAxis (aCamera->Direction().Reversed());
1031 gp_Dir aYAxis (aCamera->Up());
1032 gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
1034 gp_Trsf aRot[3], aTrsf;
1035 aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
1036 aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
1037 aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
1038 aTrsf.Multiply (aRot[0]);
1039 aTrsf.Multiply (aRot[1]);
1040 aTrsf.Multiply (aRot[2]);
1042 aCamera->Transform (aTrsf);
1047 //=============================================================================
1050 //=============================================================================
1051 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1055 Turn(angle,0.,0.,Start);
1058 Turn(0.,angle,0.,Start);
1061 Turn(0.,0.,angle,Start);
1066 //=============================================================================
1069 //=============================================================================
1070 void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
1072 Standard_Real Angle = angle ;
1074 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1075 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1077 Handle(Graphic3d_Camera) aCamera = Camera();
1081 myCamStartOpUp = aCamera->Up();
1082 myCamStartOpDir = aCamera->Direction();
1083 myCamStartOpEye = aCamera->Eye();
1084 myCamStartOpCenter = aCamera->Center();
1087 aCamera->SetUp (myCamStartOpUp);
1088 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
1089 aCamera->SetDirectionFromEye (myCamStartOpDir);
1092 gp_Pnt aRCenter = aCamera->Eye();
1093 gp_Dir aRAxis (myDefaultViewAxis);
1094 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
1096 aCamera->Transform (aRotation);
1101 //=============================================================================
1102 //function : SetTwist
1104 //=============================================================================
1105 void V3d_View::SetTwist(const Standard_Real angle)
1107 Standard_Real Angle = angle ;
1109 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1110 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1112 Handle(Graphic3d_Camera) aCamera = Camera();
1114 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1115 if (!screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1116 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1117 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1119 throw V3d_BadValue ("V3d_ViewSetTwist, alignment of Eye,At,Up,");
1122 gp_Pnt aRCenter = aCamera->Center();
1123 gp_Dir aZAxis (aCamera->Direction().Reversed());
1126 aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
1128 aCamera->SetUp (gp_Dir (myYscreenAxis));
1129 aCamera->Transform (aTrsf);
1134 //=============================================================================
1137 //=============================================================================
1138 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1140 Standard_Real aTwistBefore = Twist();
1142 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1144 Handle(Graphic3d_Camera) aCamera = Camera();
1146 aCamera->SetEye (gp_Pnt (X, Y, Z));
1148 SetTwist (aTwistBefore);
1150 SetImmediateUpdate (wasUpdateEnabled);
1155 //=============================================================================
1156 //function : SetDepth
1158 //=============================================================================
1159 void V3d_View::SetDepth(const Standard_Real Depth)
1161 V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
1163 Handle(Graphic3d_Camera) aCamera = Camera();
1167 // Move eye using center (target) as anchor.
1168 aCamera->SetDistance (Depth);
1172 // Move the view ref point instead of the eye.
1173 gp_Vec aDir (aCamera->Direction());
1174 gp_Pnt aCameraEye = aCamera->Eye();
1175 gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
1177 aCamera->SetCenter (aCameraCenter);
1183 //=============================================================================
1184 //function : SetProj
1186 //=============================================================================
1187 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1189 V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1190 "V3d_View::SetProj, null projection vector");
1192 Standard_Real aTwistBefore = Twist();
1194 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1196 Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
1198 SetTwist(aTwistBefore);
1200 SetImmediateUpdate (wasUpdateEnabled);
1205 //=============================================================================
1206 //function : SetProj
1208 //=============================================================================
1209 void V3d_View::SetProj (const V3d_TypeOfOrientation theOrientation,
1210 const Standard_Boolean theIsYup)
1212 Graphic3d_Vec3d anUp = theIsYup ? Graphic3d_Vec3d (0.0, 1.0, 0.0) : Graphic3d_Vec3d (0.0, 0.0, 1.0);
1215 if (theOrientation == V3d_Ypos
1216 || theOrientation == V3d_Yneg)
1218 anUp.SetValues (0.0, 0.0, -1.0);
1223 if (theOrientation == V3d_Zpos)
1225 anUp.SetValues (0.0, 1.0, 0.0);
1227 else if (theOrientation == V3d_Zneg)
1229 anUp.SetValues (0.0, -1.0, 0.0);
1233 const gp_Dir aBck = V3d::GetProjAxis (theOrientation);
1235 // retain camera panning from origin when switching projection
1236 const Handle(Graphic3d_Camera)& aCamera = Camera();
1237 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
1239 const Standard_Real aNewDist = aCamera->Eye().Distance (gp_Pnt (0, 0, 0));
1240 aCamera->SetEyeAndCenter (gp_XYZ (0, 0, 0) + aBck.XYZ() * aNewDist,
1242 aCamera->SetDirectionFromEye (-aBck);
1243 aCamera->SetUp (gp_Dir (anUp.x(), anUp.y(), anUp.z()));
1244 aCamera->OrthogonalizeUp();
1246 Panning (anOriginVCS.X(), anOriginVCS.Y());
1251 //=============================================================================
1254 //=============================================================================
1255 void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1257 Standard_Real aTwistBefore = Twist();
1259 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1261 Camera()->SetCenter (gp_Pnt (X, Y, Z));
1263 SetTwist (aTwistBefore);
1265 SetImmediateUpdate (wasUpdateEnabled);
1270 //=============================================================================
1273 //=============================================================================
1274 void V3d_View::SetUp (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
1276 Handle(Graphic3d_Camera) aCamera = Camera();
1278 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1279 const gp_Dir anUp (theVx, theVy, theVz);
1280 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis)
1281 && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1282 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1283 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1285 throw V3d_BadValue ("V3d_View::Setup, alignment of Eye,At,Up");
1288 aCamera->SetUp (gp_Dir (myYscreenAxis));
1293 //=============================================================================
1296 //=============================================================================
1297 void V3d_View::SetUp (const V3d_TypeOfOrientation theOrientation)
1299 Handle(Graphic3d_Camera) aCamera = Camera();
1301 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1302 const gp_Dir anUp = V3d::GetProjAxis (theOrientation);
1303 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis)
1304 && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1305 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1306 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1308 throw V3d_BadValue ("V3d_View::SetUp, alignment of Eye,At,Up");
1311 aCamera->SetUp (gp_Dir (myYscreenAxis));
1316 //=============================================================================
1317 //function : SetViewOrientationDefault
1319 //=============================================================================
1320 void V3d_View::SetViewOrientationDefault()
1322 myDefaultCamera->CopyOrientationData (Camera());
1325 //=======================================================================
1326 //function : SetViewMappingDefault
1328 //=======================================================================
1329 void V3d_View::SetViewMappingDefault()
1331 myDefaultCamera->CopyMappingData (Camera());
1334 //=============================================================================
1335 //function : ResetViewOrientation
1337 //=============================================================================
1338 void V3d_View::ResetViewOrientation()
1340 Camera()->CopyOrientationData (myDefaultCamera);
1344 //=======================================================================
1345 //function : ResetViewMapping
1347 //=======================================================================
1348 void V3d_View::ResetViewMapping()
1350 Camera()->CopyMappingData (myDefaultCamera);
1354 //=============================================================================
1357 //=============================================================================
1358 void V3d_View::Reset (const Standard_Boolean theToUpdate)
1360 Camera()->Copy (myDefaultCamera);
1362 SwitchSetFront = Standard_False;
1364 if (myImmediateUpdate || theToUpdate)
1370 //=======================================================================
1371 //function : SetCenter
1373 //=======================================================================
1374 void V3d_View::SetCenter (const Standard_Integer theXp,
1375 const Standard_Integer theYp)
1377 Standard_Real aXv, aYv;
1378 Convert (theXp, theYp, aXv, aYv);
1379 Translate (Camera(), aXv, aYv);
1384 //=============================================================================
1385 //function : SetSize
1387 //=============================================================================
1388 void V3d_View::SetSize (const Standard_Real theSize)
1390 V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
1392 Handle(Graphic3d_Camera) aCamera = Camera();
1394 aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
1399 //=============================================================================
1400 //function : SetZSize
1402 //=============================================================================
1403 void V3d_View::SetZSize (const Standard_Real theSize)
1405 Handle(Graphic3d_Camera) aCamera = Camera();
1407 Standard_Real Zmax = theSize / 2.;
1409 Standard_Real aDistance = aCamera->Distance();
1416 // ShortReal precision factor used to add meaningful tolerance to
1417 // ZNear, ZFar values in order to avoid equality after type conversion
1418 // to ShortReal matrices type.
1419 const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
1421 Standard_Real aZFar = Zmax + aDistance * 2.0;
1422 Standard_Real aZNear = -Zmax + aDistance;
1423 aZNear -= Abs (aZNear) * aPrecision;
1424 aZFar += Abs (aZFar) * aPrecision;
1426 if (!aCamera->IsOrthographic())
1428 if (aZFar < aPrecision)
1430 // Invalid case when both values are negative
1431 aZNear = aPrecision;
1432 aZFar = aPrecision * 2.0;
1434 else if (aZNear < Abs (aZFar) * aPrecision)
1436 // Z is less than 0.0, try to fix it using any appropriate z-scale
1437 aZNear = Abs (aZFar) * aPrecision;
1441 // If range is too small
1442 if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
1444 aZFar = aZNear + Abs (aZFar) * aPrecision;
1447 aCamera->SetZRange (aZNear, aZFar);
1449 if (myImmediateUpdate)
1455 //=============================================================================
1456 //function : SetZoom
1458 //=============================================================================
1459 void V3d_View::SetZoom (const Standard_Real theCoef,const Standard_Boolean theToStart)
1461 V3d_BadValue_Raise_if (theCoef <= 0., "V3d_View::SetZoom, bad coefficient");
1463 Handle(Graphic3d_Camera) aCamera = Camera();
1467 myCamStartOpEye = aCamera->Eye();
1468 myCamStartOpCenter = aCamera->Center();
1471 Standard_Real aViewWidth = aCamera->ViewDimensions().X();
1472 Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
1474 // ensure that zoom will not be too small or too big
1475 Standard_Real aCoef = theCoef;
1476 if (aViewWidth < aCoef * Precision::Confusion())
1478 aCoef = aViewWidth / Precision::Confusion();
1480 else if (aViewWidth > aCoef * 1e12)
1482 aCoef = aViewWidth / 1e12;
1484 if (aViewHeight < aCoef * Precision::Confusion())
1486 aCoef = aViewHeight / Precision::Confusion();
1488 else if (aViewHeight > aCoef * 1e12)
1490 aCoef = aViewHeight / 1e12;
1493 aCamera->SetEye (myCamStartOpEye);
1494 aCamera->SetCenter (myCamStartOpCenter);
1495 aCamera->SetScale (aCamera->Scale() / aCoef);
1500 //=============================================================================
1501 //function : SetScale
1503 //=============================================================================
1504 void V3d_View::SetScale( const Standard_Real Coef )
1506 V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1508 Handle(Graphic3d_Camera) aCamera = Camera();
1510 Standard_Real aDefaultScale = myDefaultCamera->Scale();
1511 aCamera->SetAspect (myDefaultCamera->Aspect());
1512 aCamera->SetScale (aDefaultScale / Coef);
1517 //=============================================================================
1518 //function : SetAxialScale
1520 //=============================================================================
1521 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
1523 V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1525 Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
1528 //=============================================================================
1529 //function : SetRatio
1531 //=============================================================================
1532 void V3d_View::SetRatio()
1534 if (MyWindow.IsNull())
1539 Standard_Integer aWidth = 0;
1540 Standard_Integer aHeight = 0;
1541 MyWindow->Size (aWidth, aHeight);
1542 if (aWidth > 0 && aHeight > 0)
1544 Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
1545 static_cast<Standard_Real> (aHeight);
1547 Camera() ->SetAspect (aRatio);
1548 myDefaultCamera->SetAspect (aRatio);
1552 //=============================================================================
1555 //=============================================================================
1556 void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate)
1558 FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
1561 //=============================================================================
1564 //=============================================================================
1565 void V3d_View::FitAll (const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Boolean theToUpdate)
1567 Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
1569 if (myView->NumberOfDisplayedStructures() == 0)
1574 if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
1579 if (myImmediateUpdate || theToUpdate)
1585 //=============================================================================
1586 //function : DepthFitAll
1588 //=============================================================================
1589 void V3d_View::DepthFitAll(const Standard_Real Aspect,
1590 const Standard_Real Margin)
1592 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1593 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1594 Standard_Real Dx,Dy,Dz,Size;
1596 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
1598 if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
1603 Bnd_Box aBox = myView->MinMaxValues();
1609 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
1610 Project (Xmin,Ymin,Zmin,U,V,W) ;
1611 Project (Xmax,Ymax,Zmax,U1,V1,W1) ;
1612 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
1613 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
1614 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
1615 Project (Xmin,Ymin,Zmax,U,V,W) ;
1616 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1617 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1618 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1619 Project (Xmax,Ymin,Zmax,U,V,W) ;
1620 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1621 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1622 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1623 Project (Xmax,Ymin,Zmin,U,V,W) ;
1624 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1625 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1626 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1627 Project (Xmax,Ymax,Zmin,U,V,W) ;
1628 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1629 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1630 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1631 Project (Xmin,Ymax,Zmax,U,V,W) ;
1632 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1633 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1634 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1635 Project (Xmin,Ymax,Zmin,U,V,W) ;
1636 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1637 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1638 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1641 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1642 Dz = 2.*Wmax + Margin * Wmax;
1644 // Compute depth value
1645 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
1646 Dx += Margin * Dx; Dy += Margin * Dy;
1647 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
1650 SetDepth( Aspect * Size / 2.);
1656 //=======================================================================
1657 //function : WindowFit
1659 //=======================================================================
1660 void V3d_View::WindowFit (const Standard_Integer theMinXp,
1661 const Standard_Integer theMinYp,
1662 const Standard_Integer theMaxXp,
1663 const Standard_Integer theMaxYp)
1665 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1667 Handle(Graphic3d_Camera) aCamera = Camera();
1669 if (!aCamera->IsOrthographic())
1671 // normalize view coordinates
1672 Standard_Integer aWinWidth, aWinHeight;
1673 MyWindow->Size (aWinWidth, aWinHeight);
1675 // z coordinate of camera center
1676 Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
1678 // camera projection coordinate are in NDC which are normalized [-1, 1]
1679 Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp - 1.0;
1680 Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp - 1.0;
1681 Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0;
1682 Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0;
1684 // compute camera panning
1685 gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
1686 gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
1687 gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter);
1688 gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
1689 gp_Vec aPanVec (aPanFrom, aPanTo);
1691 // compute section size
1692 gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
1693 gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
1694 gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
1695 gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
1697 Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
1698 Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
1700 Translate (aCamera, aPanVec.X(), -aPanVec.Y());
1701 Scale (aCamera, aUSize, aVSize);
1705 Standard_Real aX1, aY1, aX2, aY2;
1706 Convert (theMinXp, theMinYp, aX1, aY1);
1707 Convert (theMaxXp, theMaxYp, aX2, aY2);
1708 FitAll (aX1, aY1, aX2, aY2);
1711 SetImmediateUpdate (wasUpdateEnabled);
1716 //=======================================================================
1717 //function : ConvertToGrid
1719 //=======================================================================
1720 void V3d_View::ConvertToGrid(const Standard_Integer theXp,
1721 const Standard_Integer theYp,
1722 Standard_Real& theXg,
1723 Standard_Real& theYg,
1724 Standard_Real& theZg) const
1726 Graphic3d_Vec3d anXYZ;
1727 Convert (theXp, theYp, anXYZ.x(), anXYZ.y(), anXYZ.z());
1729 Graphic3d_Vertex aVrp;
1730 aVrp.SetCoord (anXYZ.x(), anXYZ.y(), anXYZ.z());
1731 if (MyViewer->IsGridActive())
1733 Graphic3d_Vertex aNewVrp = Compute (aVrp);
1734 aNewVrp.Coord (theXg, theYg, theZg);
1738 aVrp.Coord (theXg, theYg, theZg);
1742 //=======================================================================
1743 //function : ConvertToGrid
1745 //=======================================================================
1746 void V3d_View::ConvertToGrid(const Standard_Real theX,
1747 const Standard_Real theY,
1748 const Standard_Real theZ,
1749 Standard_Real& theXg,
1750 Standard_Real& theYg,
1751 Standard_Real& theZg) const
1753 if (MyViewer->IsGridActive())
1755 Graphic3d_Vertex aVrp (theX, theY, theZ);
1756 Graphic3d_Vertex aNewVrp = Compute (aVrp);
1757 aNewVrp.Coord (theXg, theYg, theZg);
1761 theXg = theX; theYg = theY; theZg = theZ;
1765 //=======================================================================
1766 //function : Convert
1768 //=======================================================================
1769 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
1771 Standard_Integer aDxw, aDyw ;
1773 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1775 MyWindow->Size (aDxw, aDyw);
1776 Standard_Real aValue;
1778 gp_Pnt aViewDims = Camera()->ViewDimensions();
1779 aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
1784 //=======================================================================
1785 //function : Convert
1787 //=======================================================================
1788 void V3d_View::Convert(const Standard_Integer Xp,
1789 const Standard_Integer Yp,
1791 Standard_Real& Yv) const
1793 Standard_Integer aDxw, aDyw;
1795 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1797 MyWindow->Size (aDxw, aDyw);
1799 gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
1800 aPoint = Camera()->ConvertProj2View (aPoint);
1806 //=======================================================================
1807 //function : Convert
1809 //=======================================================================
1810 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
1812 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1814 Standard_Integer aDxw, aDyw;
1815 MyWindow->Size (aDxw, aDyw);
1817 gp_Pnt aViewDims = Camera()->ViewDimensions();
1818 Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
1823 //=======================================================================
1824 //function : Convert
1826 //=======================================================================
1827 void V3d_View::Convert(const Standard_Real Xv,
1828 const Standard_Real Yv,
1829 Standard_Integer& Xp,
1830 Standard_Integer& Yp) const
1832 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1834 Standard_Integer aDxw, aDyw;
1835 MyWindow->Size (aDxw, aDyw);
1837 gp_Pnt aPoint (Xv, Yv, 0.0);
1838 aPoint = Camera()->ConvertView2Proj (aPoint);
1839 aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
1841 Xp = RealToInt (aPoint.X());
1842 Yp = RealToInt (aPoint.Y());
1845 //=======================================================================
1846 //function : Convert
1848 //=======================================================================
1849 void V3d_View::Convert(const Standard_Integer theXp,
1850 const Standard_Integer theYp,
1851 Standard_Real& theX,
1852 Standard_Real& theY,
1853 Standard_Real& theZ) const
1855 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1856 Standard_Integer aHeight = 0, aWidth = 0;
1857 MyWindow->Size (aWidth, aHeight);
1859 const gp_Pnt anXYZ (2.0 * theXp / aWidth - 1.0,
1860 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0,
1861 Camera()->IsZeroToOneDepth() ? 0.0 : -1.0);
1862 const gp_Pnt aResult = Camera()->UnProject (anXYZ);
1868 //=======================================================================
1869 //function : ConvertWithProj
1871 //=======================================================================
1872 void V3d_View::ConvertWithProj(const Standard_Integer theXp,
1873 const Standard_Integer theYp,
1874 Standard_Real& theX,
1875 Standard_Real& theY,
1876 Standard_Real& theZ,
1877 Standard_Real& theDx,
1878 Standard_Real& theDy,
1879 Standard_Real& theDz) const
1881 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1882 Standard_Integer aHeight = 0, aWidth = 0;
1883 MyWindow->Size (aWidth, aHeight);
1885 const Standard_Real anX = 2.0 * theXp / aWidth - 1.0;
1886 const Standard_Real anY = 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0;
1887 const Standard_Real aZ = 2.0 * 0.0 - 1.0;
1889 const Handle(Graphic3d_Camera)& aCamera = Camera();
1890 const gp_Pnt aResult1 = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
1891 const gp_Pnt aResult2 = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
1893 theX = aResult1.X();
1894 theY = aResult1.Y();
1895 theZ = aResult1.Z();
1896 Graphic3d_Vec3d aNormDir (theX - aResult2.X(),
1897 theY - aResult2.Y(),
1898 theZ - aResult2.Z());
1899 aNormDir.Normalize();
1901 theDx = aNormDir.x();
1902 theDy = aNormDir.y();
1903 theDz = aNormDir.z();
1906 //=======================================================================
1907 //function : Convert
1909 //=======================================================================
1910 void V3d_View::Convert(const Standard_Real X,
1911 const Standard_Real Y,
1912 const Standard_Real Z,
1913 Standard_Integer& Xp,
1914 Standard_Integer& Yp) const
1916 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1917 Standard_Integer aHeight, aWidth;
1918 MyWindow->Size (aWidth, aHeight);
1920 gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
1922 Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
1923 Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
1926 //=======================================================================
1927 //function : Project
1929 //=======================================================================
1930 void V3d_View::Project (const Standard_Real theX,
1931 const Standard_Real theY,
1932 const Standard_Real theZ,
1933 Standard_Real& theXp,
1934 Standard_Real& theYp) const
1937 Project (theX, theY, theZ, theXp, theYp, aZp);
1940 //=======================================================================
1941 //function : Project
1943 //=======================================================================
1944 void V3d_View::Project (const Standard_Real theX,
1945 const Standard_Real theY,
1946 const Standard_Real theZ,
1947 Standard_Real& theXp,
1948 Standard_Real& theYp,
1949 Standard_Real& theZp) const
1951 Handle(Graphic3d_Camera) aCamera = Camera();
1953 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1954 Standard_Real aXSize = aViewSpaceDimensions.X();
1955 Standard_Real aYSize = aViewSpaceDimensions.Y();
1956 Standard_Real aZSize = aViewSpaceDimensions.Z();
1958 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1960 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1961 theXp = aPoint.X() * aXSize * 0.5;
1962 theYp = aPoint.Y() * aYSize * 0.5;
1963 theZp = Camera()->IsZeroToOneDepth()
1964 ? aPoint.Z() * aZSize
1965 : aPoint.Z() * aZSize * 0.5;
1968 //=======================================================================
1969 //function : BackgroundColor
1971 //=======================================================================
1972 void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
1975 Standard_Real& V3) const
1977 Quantity_Color C = BackgroundColor() ;
1978 C.Values(V1,V2,V3,Type) ;
1981 //=======================================================================
1982 //function : BackgroundColor
1984 //=======================================================================
1985 Quantity_Color V3d_View::BackgroundColor() const
1987 return myView->Background().Color() ;
1990 //=======================================================================
1991 //function : GradientBackgroundColors
1993 //=======================================================================
1994 void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
1996 myView->GradientBackground().Colors (theColor1, theColor2);
1999 //=======================================================================
2000 //function : GradientBackground
2002 //=======================================================================
2003 Aspect_GradientBackground V3d_View::GradientBackground() const
2005 return myView->GradientBackground();
2008 //=======================================================================
2011 //=======================================================================
2012 Standard_Real V3d_View::Scale() const
2014 return myDefaultCamera->Scale() / Camera()->Scale();
2017 //=======================================================================
2018 //function : AxialScale
2020 //=======================================================================
2021 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
2023 gp_Pnt anAxialScale = Camera()->AxialScale();
2024 Sx = anAxialScale.X();
2025 Sy = anAxialScale.Y();
2026 Sz = anAxialScale.Z();
2029 //=======================================================================
2032 //=======================================================================
2033 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
2035 gp_Pnt aViewDims = Camera()->ViewDimensions();
2037 Width = aViewDims.X();
2038 Height = aViewDims.Y();
2041 //=======================================================================
2044 //=======================================================================
2045 Standard_Real V3d_View::ZSize() const
2047 gp_Pnt aViewDims = Camera()->ViewDimensions();
2049 return aViewDims.Z();
2052 //=======================================================================
2055 //=======================================================================
2056 Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
2057 Standard_Real& Vmin,
2058 Standard_Real& Umax,
2059 Standard_Real& Vmax) const
2061 Standard_Real Wmin,Wmax,U,V,W ;
2062 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2064 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
2067 Bnd_Box aBox = myView->MinMaxValues();
2068 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
2069 Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2070 Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2071 Project (Xmin,Ymin,Zmax,U,V,W) ;
2072 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2073 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2074 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2075 Project (Xmax,Ymin,Zmax,U,V,W) ;
2076 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2077 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2078 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2079 Project (Xmax,Ymin,Zmin,U,V,W) ;
2080 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2081 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2082 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2083 Project (Xmax,Ymax,Zmin,U,V,W) ;
2084 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2085 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2086 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2087 Project (Xmin,Ymax,Zmax,U,V,W) ;
2088 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2089 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2090 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2091 Project (Xmin,Ymax,Zmin,U,V,W) ;
2092 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2093 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2094 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2099 //=======================================================================
2102 //=======================================================================
2103 Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
2104 Standard_Real& Ymin,
2105 Standard_Real& Zmin,
2106 Standard_Real& Xmax,
2107 Standard_Real& Ymax,
2108 Standard_Real& Zmax) const
2111 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2112 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
2115 Bnd_Box aBox = myView->MinMaxValues();
2116 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
2121 //=======================================================================
2122 //function : GravityPoint
2124 //=======================================================================
2125 gp_Pnt V3d_View::GravityPoint() const
2127 Graphic3d_MapOfStructure aSetOfStructures;
2128 myView->DisplayedStructures (aSetOfStructures);
2130 Standard_Boolean hasSelection = Standard_False;
2131 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
2132 aStructIter.More(); aStructIter.Next())
2134 if (aStructIter.Key()->IsHighlighted()
2135 && aStructIter.Key()->IsVisible())
2137 hasSelection = Standard_True;
2142 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
2143 Standard_Integer aNbPoints = 0;
2144 gp_XYZ aResult (0.0, 0.0, 0.0);
2145 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
2146 aStructIter.More(); aStructIter.Next())
2148 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2149 if (!aStruct->IsVisible()
2150 || aStruct->IsInfinite()
2151 || (hasSelection && !aStruct->IsHighlighted()))
2156 const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
2157 if (!aBox.IsValid())
2162 // skip transformation-persistent objects
2163 if (!aStruct->TransformPersistence().IsNull())
2168 // use camera projection to find gravity point
2169 Xmin = aBox.CornerMin().x();
2170 Ymin = aBox.CornerMin().y();
2171 Zmin = aBox.CornerMin().z();
2172 Xmax = aBox.CornerMax().x();
2173 Ymax = aBox.CornerMax().y();
2174 Zmax = aBox.CornerMax().z();
2175 gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2177 gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2178 gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2179 gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
2180 gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2183 for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
2185 const gp_Pnt& aBndPnt = aPnts[aPntIt];
2186 const gp_Pnt aProjected = Camera()->Project (aBndPnt);
2187 if (Abs (aProjected.X()) <= 1.0
2188 && Abs (aProjected.Y()) <= 1.0)
2190 aResult += aBndPnt.XYZ();
2198 // fallback - just use bounding box of entire scene
2199 Bnd_Box aBox = myView->MinMaxValues();
2202 aBox.Get (Xmin, Ymin, Zmin,
2204 gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2206 gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2207 gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2208 gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
2209 gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2212 for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
2214 const gp_Pnt& aBndPnt = aPnts[aPntIt];
2215 aResult += aBndPnt.XYZ();
2223 aResult /= aNbPoints;
2229 //=======================================================================
2232 //=======================================================================
2233 void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2235 gp_Pnt aCameraEye = Camera()->Eye();
2241 //=============================================================================
2242 //function : ProjReferenceAxe
2244 //=============================================================================
2245 void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
2246 const Standard_Integer Ypix,
2252 Standard_Real& VZ) const
2254 Standard_Real Xo,Yo,Zo;
2256 Convert (Xpix, Ypix, XP, YP, ZP);
2257 if ( Type() == V3d_PERSPECTIVE )
2259 FocalReferencePoint (Xo,Yo,Zo);
2270 //=============================================================================
2273 //=============================================================================
2274 Standard_Real V3d_View::Depth() const
2276 return Camera()->Distance();
2279 //=============================================================================
2282 //=============================================================================
2283 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2285 gp_Dir aCameraDir = Camera()->Direction().Reversed();
2286 Dx = aCameraDir.X();
2287 Dy = aCameraDir.Y();
2288 Dz = aCameraDir.Z();
2291 //=============================================================================
2294 //=============================================================================
2295 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2297 gp_Pnt aCameraCenter = Camera()->Center();
2298 X = aCameraCenter.X();
2299 Y = aCameraCenter.Y();
2300 Z = aCameraCenter.Z();
2303 //=============================================================================
2306 //=============================================================================
2307 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
2309 gp_Dir aCameraUp = Camera()->Up();
2315 //=============================================================================
2318 //=============================================================================
2319 Standard_Real V3d_View::Twist() const
2321 gp_Vec Xaxis, Yaxis, Zaxis;
2322 const gp_Dir aReferencePlane (Camera()->Direction().Reversed());
2323 if (!screenAxis (aReferencePlane, gp::DZ(), Xaxis, Yaxis, Zaxis)
2324 && !screenAxis (aReferencePlane, gp::DY(), Xaxis, Yaxis, Zaxis)
2325 && !screenAxis (aReferencePlane, gp::DX(), Xaxis, Yaxis, Zaxis))
2330 // Compute Cross Vector From Up & Origin
2331 const gp_Dir aCameraUp = Camera()->Up();
2332 const gp_XYZ aP = Yaxis.XYZ().Crossed (aCameraUp.XYZ());
2335 Standard_Real anAngle = ASin (Max (Min (aP.Modulus(), 1.0), -1.0));
2336 if (Yaxis.Dot (aCameraUp.XYZ()) < 0.0)
2338 anAngle = M_PI - anAngle;
2343 const gp_Dir aProjDir = Camera()->Direction().Reversed();
2344 if (aP.Dot (aProjDir.XYZ()) < 0.0)
2346 anAngle = DEUXPI - anAngle;
2352 //=============================================================================
2353 //function : ShadingModel
2355 //=============================================================================
2356 Graphic3d_TypeOfShadingModel V3d_View::ShadingModel() const
2358 return myView->ShadingModel();
2361 //=============================================================================
2362 //function : TextureEnv
2364 //=============================================================================
2365 Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
2367 return myView->TextureEnv();
2370 //=============================================================================
2371 //function : Visualization
2373 //=============================================================================
2374 V3d_TypeOfVisualization V3d_View::Visualization() const
2376 return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
2379 //=============================================================================
2380 //function : IfWindow
2382 //=============================================================================
2383 Standard_Boolean V3d_View::IfWindow() const
2385 return myView->IsDefined();
2388 //=============================================================================
2391 //=============================================================================
2392 V3d_TypeOfView V3d_View::Type() const
2394 return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
2397 //=============================================================================
2398 //function : SetFocale
2400 //=============================================================================
2401 void V3d_View::SetFocale( const Standard_Real focale )
2403 Handle(Graphic3d_Camera) aCamera = Camera();
2405 if (aCamera->IsOrthographic())
2410 Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
2412 aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
2417 //=============================================================================
2420 //=============================================================================
2421 Standard_Real V3d_View::Focale() const
2423 Handle(Graphic3d_Camera) aCamera = Camera();
2425 if (aCamera->IsOrthographic())
2430 return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
2433 //=============================================================================
2434 //function : screenAxis
2436 //=============================================================================
2437 Standard_Boolean V3d_View::screenAxis (const gp_Dir& theVpn, const gp_Dir& theVup,
2438 gp_Vec& theXaxe, gp_Vec& theYaxe, gp_Vec& theZaxe)
2440 theXaxe = theVup.XYZ().Crossed (theVpn.XYZ());
2441 if (theXaxe.Magnitude() <= gp::Resolution())
2443 return Standard_False;
2445 theXaxe.Normalize();
2447 theYaxe = theVpn.XYZ().Crossed (theXaxe.XYZ());
2448 if (theYaxe.Magnitude() <= gp::Resolution())
2450 return Standard_False;
2452 theYaxe.Normalize();
2454 theZaxe = theVpn.XYZ();
2455 theZaxe.Normalize();
2456 return Standard_True;
2459 //=============================================================================
2460 //function : TrsPoint
2462 //=============================================================================
2463 gp_XYZ V3d_View::TrsPoint (const Graphic3d_Vertex& thePnt, const TColStd_Array2OfReal& theMat)
2466 const Standard_Integer lr = theMat.LowerRow();
2467 const Standard_Integer ur = theMat.UpperRow();
2468 const Standard_Integer lc = theMat.LowerCol();
2469 const Standard_Integer uc = theMat.UpperCol();
2470 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
2472 return gp_XYZ (thePnt.X(), thePnt.Y(), thePnt.Z());
2475 Standard_Real X, Y, Z;
2476 thePnt.Coord (X,Y,Z);
2477 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);
2478 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);
2479 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);
2480 return gp_XYZ (XX, YY, ZZ);
2483 //=======================================================================
2486 //=======================================================================
2487 void V3d_View::Pan (const Standard_Integer theDXp,
2488 const Standard_Integer theDYp,
2489 const Standard_Real theZoomFactor,
2490 const Standard_Boolean theToStart)
2492 Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
2495 //=======================================================================
2496 //function : Panning
2498 //=======================================================================
2499 void V3d_View::Panning (const Standard_Real theDXv,
2500 const Standard_Real theDYv,
2501 const Standard_Real theZoomFactor,
2502 const Standard_Boolean theToStart)
2504 Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
2506 Handle(Graphic3d_Camera) aCamera = Camera();
2510 myCamStartOpDir = aCamera->Direction();
2511 myCamStartOpEye = aCamera->Eye();
2512 myCamStartOpCenter = aCamera->Center();
2515 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
2517 gp_Pnt aViewDims = aCamera->ViewDimensions();
2519 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
2520 aCamera->SetDirectionFromEye (myCamStartOpDir);
2521 Translate (aCamera, -theDXv, -theDYv);
2522 Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
2524 SetImmediateUpdate (wasUpdateEnabled);
2529 //=======================================================================
2532 //=======================================================================
2533 void V3d_View::Zoom (const Standard_Integer theXp1,
2534 const Standard_Integer theYp1,
2535 const Standard_Integer theXp2,
2536 const Standard_Integer theYp2)
2538 Standard_Integer aDx = theXp2 - theXp1;
2539 Standard_Integer aDy = theYp2 - theYp1;
2540 if (aDx != 0 || aDy != 0)
2542 Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0;
2543 aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff;
2544 SetZoom (aCoeff, Standard_True);
2548 //=======================================================================
2549 //function : StartZoomAtPoint
2551 //=======================================================================
2552 void V3d_View::StartZoomAtPoint (const Standard_Integer theXp,
2553 const Standard_Integer theYp)
2555 MyZoomAtPointX = theXp;
2556 MyZoomAtPointY = theYp;
2559 //=======================================================================
2560 //function : ZoomAtPoint
2562 //=======================================================================
2563 void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
2564 const Standard_Integer theMouseStartY,
2565 const Standard_Integer theMouseEndX,
2566 const Standard_Integer theMouseEndY)
2568 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
2571 Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY));
2572 Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0;
2573 aDZoom = (aDxy > 0.0) ? aDZoom : 1.0 / aDZoom;
2575 V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
2577 Handle(Graphic3d_Camera) aCamera = Camera();
2579 Standard_Real aViewWidth = aCamera->ViewDimensions().X();
2580 Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
2582 // ensure that zoom will not be too small or too big.
2583 Standard_Real aCoef = aDZoom;
2584 if (aViewWidth < aCoef * Precision::Confusion())
2586 aCoef = aViewWidth / Precision::Confusion();
2588 else if (aViewWidth > aCoef * 1e12)
2590 aCoef = aViewWidth / 1e12;
2592 if (aViewHeight < aCoef * Precision::Confusion())
2594 aCoef = aViewHeight / Precision::Confusion();
2596 else if (aViewHeight > aCoef * 1e12)
2598 aCoef = aViewHeight / 1e12;
2601 Standard_Real aZoomAtPointXv = 0.0;
2602 Standard_Real aZoomAtPointYv = 0.0;
2603 Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv);
2605 Standard_Real aDxv = aZoomAtPointXv / aCoef;
2606 Standard_Real aDyv = aZoomAtPointYv / aCoef;
2608 aCamera->SetScale (aCamera->Scale() / aCoef);
2609 Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
2611 SetImmediateUpdate (wasUpdateEnabled);
2616 //=============================================================================
2617 //function : AxialScale
2619 //=============================================================================
2620 void V3d_View::AxialScale (const Standard_Integer Dx,
2621 const Standard_Integer Dy,
2622 const V3d_TypeOfAxe Axis)
2624 if( Dx != 0. || Dy != 0. ) {
2625 Standard_Real Sx, Sy, Sz;
2626 AxialScale( Sx, Sy, Sz );
2627 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
2628 dscale = (Dx > 0) ? dscale : 1./dscale;
2629 if( Axis == V3d_X ) Sx = dscale;
2630 if( Axis == V3d_Y ) Sy = dscale;
2631 if( Axis == V3d_Z ) Sz = dscale;
2632 SetAxialScale( Sx, Sy, Sz );
2636 //=============================================================================
2639 //=============================================================================
2640 void V3d_View::FitAll(const Standard_Real theXmin,
2641 const Standard_Real theYmin,
2642 const Standard_Real theXmax,
2643 const Standard_Real theYmax)
2645 Handle(Graphic3d_Camera) aCamera = Camera();
2646 Standard_Real anAspect = aCamera->Aspect();
2648 Standard_Real aFitSizeU = Abs (theXmax - theXmin);
2649 Standard_Real aFitSizeV = Abs (theYmax - theYmin);
2650 Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
2651 if (aFitAspect >= anAspect)
2653 aFitSizeV = aFitSizeU / anAspect;
2657 aFitSizeU = aFitSizeV * anAspect;
2660 Translate (aCamera, (theXmin + theXmax) * 0.5, (theYmin + theYmax) * 0.5);
2661 Scale (aCamera, aFitSizeU, aFitSizeV);
2666 //=============================================================================
2667 //function : StartRotation
2669 //=============================================================================
2670 void V3d_View::StartRotation(const Standard_Integer X,
2671 const Standard_Integer Y,
2672 const Standard_Real zRotationThreshold)
2677 rx = Standard_Real(Convert(x));
2678 ry = Standard_Real(Convert(y));
2679 myRotateGravity = GravityPoint();
2680 Rotate (0.0, 0.0, 0.0,
2681 myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2683 myZRotation = Standard_False;
2684 if( zRotationThreshold > 0. ) {
2685 Standard_Real dx = Abs(sx - rx/2.);
2686 Standard_Real dy = Abs(sy - ry/2.);
2687 // if( dx > rx/3. || dy > ry/3. ) myZRotation = Standard_True;
2688 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
2689 if( dx > dd || dy > dd ) myZRotation = Standard_True;
2694 //=============================================================================
2695 //function : Rotation
2697 //=============================================================================
2698 void V3d_View::Rotation(const Standard_Integer X,
2699 const Standard_Integer Y)
2701 if( rx == 0. || ry == 0. ) {
2705 Standard_Real dx=0.,dy=0.,dz=0.;
2707 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
2708 atan2(sx-rx/2.,ry/2.-sy);
2710 dx = (Standard_Real(X) - sx) * M_PI / rx;
2711 dy = (sy - Standard_Real(Y)) * M_PI / ry;
2715 myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2719 //=============================================================================
2720 //function : SetComputedMode
2722 //=============================================================================
2723 void V3d_View::SetComputedMode (const Standard_Boolean theMode)
2729 myView->SetComputedMode (Standard_True);
2734 myView->SetComputedMode (Standard_False);
2738 //=============================================================================
2739 //function : ComputedMode
2741 //=============================================================================
2742 Standard_Boolean V3d_View::ComputedMode() const
2744 return myView->ComputedMode();
2747 //=============================================================================
2748 //function : SetBackFacingModel
2750 //=============================================================================
2751 void V3d_View::SetBackFacingModel (const Graphic3d_TypeOfBackfacingModel theModel)
2753 myView->SetBackfacingModel (theModel);
2757 //=============================================================================
2758 //function : BackFacingModel
2760 //=============================================================================
2761 Graphic3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
2763 return myView->BackfacingModel();
2766 //=============================================================================
2769 //=============================================================================
2770 void V3d_View::Init()
2772 myComputedMode = MyViewer->ComputedMode();
2773 if (!myComputedMode || !MyViewer->DefaultComputedMode())
2775 SetComputedMode (Standard_False);
2779 //=============================================================================
2782 //=============================================================================
2783 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
2784 const Graphic3d_BufferType& theBufferType)
2786 Standard_Integer aWinWidth, aWinHeight;
2787 MyWindow->Size (aWinWidth, aWinHeight);
2788 Image_AlienPixMap anImage;
2790 return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
2793 //=============================================================================
2794 //function : ToPixMap
2796 //=============================================================================
2797 Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
2798 const V3d_ImageDumpOptions& theParams)
2800 Graphic3d_Vec2i aTargetSize (theParams.Width, theParams.Height);
2801 if (aTargetSize.x() != 0
2802 && aTargetSize.y() != 0)
2804 // allocate image buffer for dumping
2805 if (theImage.IsEmpty()
2806 || theImage.SizeX() != Standard_Size(aTargetSize.x())
2807 || theImage.SizeY() != Standard_Size(aTargetSize.y()))
2809 Image_Format aFormat = Image_Format_UNKNOWN;
2810 switch (theParams.BufferType)
2812 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
2813 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
2814 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
2815 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
2816 case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break;
2819 if (!theImage.InitZero (aFormat, Standard_Size(aTargetSize.x()), Standard_Size(aTargetSize.y())))
2821 Message::SendFail (TCollection_AsciiString ("Fail to allocate an image ") + aTargetSize.x() + "x" + aTargetSize.y() + " for view dump");
2822 return Standard_False;
2826 if (theImage.IsEmpty())
2828 Message::SendFail ("V3d_View::ToPixMap() has been called without image dimensions");
2829 return Standard_False;
2831 aTargetSize.x() = (Standard_Integer )theImage.SizeX();
2832 aTargetSize.y() = (Standard_Integer )theImage.SizeY();
2834 Handle(Standard_Transient) aFBOPtr;
2835 Handle(Standard_Transient) aPrevFBOPtr = myView->FBO();
2836 Graphic3d_Vec2i aFBOVPSize = aTargetSize;
2838 bool isTiling = false;
2839 if (theParams.TileSize > 0)
2841 if (aFBOVPSize.x() > theParams.TileSize
2842 || aFBOVPSize.y() > theParams.TileSize)
2844 aFBOVPSize.x() = Min (aFBOVPSize.x(), theParams.TileSize);
2845 aFBOVPSize.y() = Min (aFBOVPSize.y(), theParams.TileSize);
2850 Graphic3d_Vec2i aPrevFBOVPSize;
2851 if (!aPrevFBOPtr.IsNull())
2853 Graphic3d_Vec2i aPrevFBOSizeMax;
2854 myView->FBOGetDimensions (aPrevFBOPtr,
2855 aPrevFBOVPSize.x(), aPrevFBOVPSize.y(),
2856 aPrevFBOSizeMax.x(), aPrevFBOSizeMax.y());
2857 if (aFBOVPSize.x() <= aPrevFBOSizeMax.x()
2858 && aFBOVPSize.y() <= aPrevFBOSizeMax.y())
2860 aFBOPtr = aPrevFBOPtr;
2864 if (aFBOPtr.IsNull())
2866 Standard_Integer aMaxTexSizeX = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeX);
2867 Standard_Integer aMaxTexSizeY = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeY);
2868 if (theParams.TileSize > aMaxTexSizeX
2869 || theParams.TileSize > aMaxTexSizeY)
2871 Message::SendFail (TCollection_AsciiString ("Image dump can not be performed - specified tile size (")
2872 + theParams.TileSize + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
2873 return Standard_False;
2876 if (aFBOVPSize.x() > aMaxTexSizeX
2877 || aFBOVPSize.y() > aMaxTexSizeY)
2879 if (MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_IsWorkaroundFBO))
2881 Message::SendWarning ("Warning, workaround for Intel driver problem with empty FBO for images with big width is applied");
2883 Message::SendInfo (TCollection_AsciiString ("Info, tiling image dump is used, image size (")
2884 + aFBOVPSize.x() + "x" + aFBOVPSize.y() + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
2885 aFBOVPSize.x() = Min (aFBOVPSize.x(), aMaxTexSizeX);
2886 aFBOVPSize.y() = Min (aFBOVPSize.y(), aMaxTexSizeY);
2890 // Try to create hardware accelerated buffer
2891 aFBOPtr = myView->FBOCreate (aFBOVPSize.x(), aFBOVPSize.y());
2893 myView->SetFBO (aFBOPtr);
2895 if (aFBOPtr.IsNull())
2897 // try to use on-screen buffer
2898 Graphic3d_Vec2i aWinSize;
2899 MyWindow->Size (aWinSize.x(), aWinSize.y());
2900 if (aFBOVPSize.x() != aWinSize.x()
2901 || aFBOVPSize.y() != aWinSize.y())
2905 aFBOVPSize = aWinSize;
2907 Message::SendWarning ("Warning, on screen buffer is used for image dump - content might be invalid");
2910 // backup camera parameters
2911 Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
2912 Handle(Graphic3d_Camera) aCamera = Camera();
2913 aStoreMapping->Copy (aCamera);
2914 if (aCamera->IsStereo())
2916 switch (theParams.StereoOptions)
2920 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
2923 case V3d_SDO_LEFT_EYE:
2925 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
2928 case V3d_SDO_RIGHT_EYE:
2930 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
2933 case V3d_SDO_BLENDED:
2935 break; // dump as is
2939 if (theParams.ToAdjustAspect)
2941 aCamera->SetAspect (Standard_Real(aTargetSize.x()) / Standard_Real(aTargetSize.y()));
2944 // render immediate structures into back buffer rather than front
2945 const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
2947 Standard_Boolean isSuccess = Standard_True;
2950 if (!aFBOPtr.IsNull())
2952 myView->FBOChangeViewport (aFBOPtr, aTargetSize.x(), aTargetSize.y());
2955 isSuccess = isSuccess && myView->BufferDump (theImage, theParams.BufferType);
2959 Image_PixMap aTilePixMap;
2960 aTilePixMap.SetTopDown (theImage.IsTopDown());
2962 Graphic3d_Vec2i anOffset (0, 0);
2963 for (; anOffset.y() < aTargetSize.y(); anOffset.y() += aFBOVPSize.y())
2966 for (; anOffset.x() < aTargetSize.x(); anOffset.x() += aFBOVPSize.x())
2968 Graphic3d_CameraTile aTileUncropped;
2969 aTileUncropped.Offset = anOffset;
2970 aTileUncropped.TotalSize = aTargetSize;
2971 aTileUncropped.TileSize = aFBOVPSize;
2972 const Graphic3d_CameraTile aTile = aTileUncropped.Cropped();
2973 if (aTile.TileSize.x() < 1
2974 || aTile.TileSize.y() < 1)
2979 const Standard_Integer aLeft = aTile.Offset.x();
2980 Standard_Integer aBottom = aTile.Offset.y();
2981 if (theImage.IsTopDown())
2983 const Standard_Integer aTop = aTile.Offset.y() + aTile.TileSize.y();
2984 aBottom = aTargetSize.y() - aTop;
2986 aTilePixMap.InitWrapper (theImage.Format(), theImage.ChangeData()
2987 + theImage.SizeRowBytes() * aBottom + theImage.SizePixelBytes() * aLeft,
2988 aTile.TileSize.x(), aTile.TileSize.y(),
2989 theImage.SizeRowBytes());
2991 if (!aFBOPtr.IsNull())
2993 aCamera->SetTile (aTile);
2994 myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
2998 // no API to resize viewport of on-screen buffer - render uncropped
2999 aCamera->SetTile (aTileUncropped);
3002 isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
3016 myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
3017 aCamera->Copy (aStoreMapping);
3018 if (aFBOPtr != aPrevFBOPtr)
3020 myView->FBORelease (aFBOPtr);
3022 else if (!aPrevFBOPtr.IsNull())
3024 myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSize.x(), aPrevFBOVPSize.y());
3026 myView->SetFBO (aPrevFBOPtr);
3030 //=============================================================================
3031 //function : ImmediateUpdate
3033 //=============================================================================
3034 void V3d_View::ImmediateUpdate() const
3036 if (myImmediateUpdate)
3042 //=============================================================================
3043 //function : SetImmediateUpdate
3045 //=============================================================================
3046 Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
3048 Standard_Boolean aPreviousMode = myImmediateUpdate;
3049 myImmediateUpdate = theImmediateUpdate;
3050 return aPreviousMode;
3053 // =======================================================================
3054 // function : SetCamera
3056 // =======================================================================
3057 void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
3059 myView->SetCamera (theCamera);
3064 // =======================================================================
3065 // function : GetCamera
3067 // =======================================================================
3068 const Handle(Graphic3d_Camera)& V3d_View::Camera() const
3070 return myView->Camera();
3073 // =======================================================================
3074 // function : FitMinMax
3075 // purpose : Internal
3076 // =======================================================================
3077 Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
3078 const Bnd_Box& theBox,
3079 const Standard_Real theMargin,
3080 const Standard_Real theResolution,
3081 const Standard_Boolean theToEnlargeIfLine) const
3083 if (!theCamera->FitMinMax (theBox, theResolution, theToEnlargeIfLine))
3085 return Standard_False; // bounding box is out of bounds...
3088 const Standard_Real aZoomCoef = myView->ConsiderZoomPersistenceObjects();
3089 Scale (theCamera, theCamera->ViewDimensions().X() * (aZoomCoef + theMargin), theCamera->ViewDimensions().Y() * (aZoomCoef + theMargin));
3090 return Standard_True;
3093 // =======================================================================
3095 // purpose : Internal
3096 // =======================================================================
3097 void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera,
3098 const Standard_Real theSizeXv,
3099 const Standard_Real theSizeYv) const
3101 Standard_Real anAspect = theCamera->Aspect();
3104 theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv));
3108 theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect));
3113 // =======================================================================
3114 // function : Translate
3115 // purpose : Internal
3116 // =======================================================================
3117 void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
3118 const Standard_Real theDXv,
3119 const Standard_Real theDYv) const
3121 const gp_Pnt& aCenter = theCamera->Center();
3122 const gp_Dir& aDir = theCamera->Direction();
3123 const gp_Dir& anUp = theCamera->Up();
3124 gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp);
3126 gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv;
3127 gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv;
3128 gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv;
3130 aPanTrsf.SetTranslation (aCameraPan);
3132 theCamera->Transform (aPanTrsf);
3136 // =======================================================================
3137 // function : DiagnosticInformation
3139 // =======================================================================
3140 void V3d_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
3141 Graphic3d_DiagnosticInfo theFlags) const
3143 myView->DiagnosticInformation (theDict, theFlags);
3146 //=======================================================================
3147 //function : StatisticInformation
3149 //=======================================================================
3150 void V3d_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
3152 myView->StatisticInformation (theDict);
3155 // =======================================================================
3156 // function : StatisticInformation
3158 // =======================================================================
3159 TCollection_AsciiString V3d_View::StatisticInformation() const
3161 return myView->StatisticInformation();
3164 //=============================================================================
3165 //function : RenderingParams
3167 //=============================================================================
3168 const Graphic3d_RenderingParams& V3d_View::RenderingParams() const
3170 return myView->RenderingParams();
3173 //=============================================================================
3174 //function : ChangeRenderingParams
3176 //=============================================================================
3177 Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams()
3179 return myView->ChangeRenderingParams();
3183 //=============================================================================
3184 //function : SetLightOn
3186 //=============================================================================
3187 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
3189 if (!myActiveLights.Contains (theLight))
3191 myActiveLights.Append (theLight);
3196 //=============================================================================
3197 //function : SetLightOff
3199 //=============================================================================
3200 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
3202 if (MyViewer->IsGlobalLight (theLight))
3203 throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
3204 myActiveLights.Remove (theLight);
3208 //=============================================================================
3209 //function : IsActiveLight
3211 //=============================================================================
3212 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
3214 return !theLight.IsNull()
3215 && myActiveLights.Contains (theLight);
3218 //=============================================================================
3219 //function : SetLightOn
3221 //=============================================================================
3222 void V3d_View::SetLightOn()
3224 for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
3226 if (!myActiveLights.Contains (aDefLightIter.Value()))
3228 myActiveLights.Append (aDefLightIter.Value());
3234 //=============================================================================
3235 //function : SetLightOff
3237 //=============================================================================
3238 void V3d_View::SetLightOff()
3240 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
3242 if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
3244 myActiveLights.Remove (anActiveLightIter);
3248 anActiveLightIter.Next();
3254 //=============================================================================
3255 //function : IfMoreLights
3257 //=============================================================================
3258 Standard_Boolean V3d_View::IfMoreLights() const
3260 return myActiveLights.Extent() < LightLimit();
3263 //=======================================================================
3264 //function : LightLimit
3266 //=======================================================================
3267 Standard_Integer V3d_View::LightLimit() const
3269 return Viewer()->Driver()->InquireLightLimit();
3272 //=======================================================================
3273 //function : AddClipPlane
3275 //=======================================================================
3276 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3278 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3279 if (aSeqOfPlanes.IsNull())
3281 aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
3285 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3287 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3288 if (aPlane == thePlane)
3290 // plane is already defined in view
3296 aSeqOfPlanes->Append (thePlane);
3297 SetClipPlanes (aSeqOfPlanes);
3300 //=======================================================================
3301 //function : RemoveClipPlane
3303 //=======================================================================
3304 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3306 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3307 if (aSeqOfPlanes.IsNull())
3312 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3314 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3315 if (aPlane != thePlane)
3320 aSeqOfPlanes->Remove (aPlaneIt);
3321 SetClipPlanes (aSeqOfPlanes);
3326 //=======================================================================
3327 //function : SetClipPlanes
3329 //=======================================================================
3330 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
3332 myView->SetClipPlanes (thePlanes);
3335 //=======================================================================
3336 //function : ClipPlanes
3338 //=======================================================================
3339 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
3341 return myView->ClipPlanes();
3344 //=======================================================================
3345 //function : PlaneLimit
3347 //=======================================================================
3348 Standard_Integer V3d_View::PlaneLimit() const
3350 return Viewer()->Driver()->InquirePlaneLimit();
3353 //=============================================================================
3356 //=============================================================================
3357 void V3d_View::Move (const Standard_Real theDx,
3358 const Standard_Real theDy,
3359 const Standard_Real theDz,
3360 const Standard_Boolean theStart)
3362 Handle(Graphic3d_Camera) aCamera = Camera();
3365 myCamStartOpEye = aCamera->Eye();
3367 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3368 gp_Dir anUp (aCamera->Up());
3369 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3371 throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3375 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
3376 myXscreenAxis.Coord (XX,XY,XZ);
3377 myYscreenAxis.Coord (YX,YY,YZ);
3378 myZscreenAxis.Coord (ZX,ZY,ZZ);
3380 aCamera->SetEye (myCamStartOpEye);
3382 aCamera->SetEye (aCamera->Eye().XYZ()
3383 + theDx * gp_Pnt (XX, XY, XZ).XYZ()
3384 + theDy * gp_Pnt (YX, YY, YZ).XYZ()
3385 + theDz * gp_Pnt (ZX, ZY, ZZ).XYZ()
3391 //=============================================================================
3394 //=============================================================================
3395 void V3d_View::Move (const Standard_Real theLength, const Standard_Boolean theStart)
3397 Handle(Graphic3d_Camera) aCamera = Camera();
3400 myCamStartOpEye = aCamera->Eye();
3402 aCamera->SetEye (myCamStartOpEye);
3403 aCamera->SetEye (aCamera->Eye().XYZ() + theLength * myDefaultViewAxis.XYZ());
3408 //=============================================================================
3411 //=============================================================================
3412 void V3d_View::Move (const V3d_TypeOfAxe theAxe,
3413 const Standard_Real theLength,
3414 const Standard_Boolean theStart)
3419 Move (theLength,0.,0.,theStart);
3422 Move (0.,theLength,0.,theStart);
3425 Move (0.,0.,theLength,theStart);
3430 //=============================================================================
3431 //function : Translate
3433 //=============================================================================
3434 void V3d_View::Translate (const Standard_Real theDx,
3435 const Standard_Real theDy,
3436 const Standard_Real theDz,
3437 const Standard_Boolean theStart)
3439 Handle(Graphic3d_Camera) aCamera = Camera();
3442 myCamStartOpEye = aCamera->Eye();
3443 myCamStartOpCenter = aCamera->Center();
3445 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3446 gp_Dir anUp (aCamera->Up());
3447 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3449 throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3453 aCamera->SetEye (myCamStartOpEye);
3454 aCamera->SetCenter (myCamStartOpCenter);
3456 aCamera->SetCenter (aCamera->Center().XYZ()
3457 - theDx * myXscreenAxis.XYZ()
3458 - theDy * myYscreenAxis.XYZ()
3459 - theDz * myZscreenAxis.XYZ()
3462 aCamera->SetEye (aCamera->Eye().XYZ()
3463 - theDx * myXscreenAxis.XYZ()
3464 - theDy * myYscreenAxis.XYZ()
3465 - theDz * myZscreenAxis.XYZ()
3471 //=============================================================================
3472 //function : Translate
3474 //=============================================================================
3475 void V3d_View::Translate (const V3d_TypeOfAxe theAxe, const Standard_Real theLength,const Standard_Boolean theStart)
3480 Translate (theLength,0.,0., theStart);
3483 Translate (0.,theLength,0., theStart);
3486 Translate (0.,0.,theLength, theStart);
3491 //=======================================================================
3494 //=======================================================================
3495 void V3d_View::Place (const Standard_Integer theXp,
3496 const Standard_Integer theYp,
3497 const Standard_Real theZoomFactor)
3499 Standard_Integer aWinWidth = 0;
3500 Standard_Integer aWinHeight = 0;
3501 View()->Window()->Size (aWinWidth, aWinHeight);
3503 Standard_Integer aWinCXp = aWinWidth / 2;
3504 Standard_Integer aWinCYp = aWinHeight / 2;
3505 Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
3508 //=======================================================================
3509 //function : Translate
3511 //=======================================================================
3512 void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
3514 Handle(Graphic3d_Camera) aCamera = Camera();
3517 myCamStartOpCenter = aCamera->Center() ;
3520 gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - myDefaultViewAxis.XYZ() * theLength);
3521 aCamera->SetCenter (aNewCenter);
3526 //=============================================================================
3527 //function : SetGrid
3529 //=============================================================================
3530 void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid)
3535 Standard_Real xl, yl, zl;
3536 Standard_Real xdx, xdy, xdz;
3537 Standard_Real ydx, ydy, ydz;
3538 Standard_Real dx, dy, dz;
3539 aPlane.Location ().Coord (xl, yl, zl);
3540 aPlane.XDirection ().Coord (xdx, xdy, xdz);
3541 aPlane.YDirection ().Coord (ydx, ydy, ydz);
3542 aPlane.Direction ().Coord (dx, dy, dz);
3544 Standard_Real CosAlpha = Cos (MyGrid->RotationAngle ());
3545 Standard_Real SinAlpha = Sin (MyGrid->RotationAngle ());
3547 TColStd_Array2OfReal Trsf1 (1, 4, 1, 4);
3549 Trsf1 (4, 1) = Trsf1 (4, 2) = Trsf1 (4, 3) = 0.0;
3554 // Transformation change of marker
3565 TColStd_Array2OfReal Trsf2 (1, 4, 1, 4);
3567 Trsf2 (4, 1) = Trsf2 (4, 2) = Trsf2 (4, 3) = 0.0;
3568 // Translation of the origin
3569 Trsf2 (1, 4) = -MyGrid->XOrigin (),
3570 Trsf2 (2, 4) = -MyGrid->YOrigin (),
3572 // Rotation Alpha around axis -Z
3573 Trsf2 (1, 1) = CosAlpha,
3574 Trsf2 (2, 1) = -SinAlpha,
3576 Trsf2 (1, 2) = SinAlpha,
3577 Trsf2 (2, 2) = CosAlpha,
3583 Standard_Real valuetrsf;
3584 Standard_Real valueoldtrsf;
3585 Standard_Real valuenewtrsf;
3586 Standard_Integer i, j, k;
3587 // Calculation of the product of matrices
3588 for (i=1; i<=4; i++)
3589 for (j=1; j<=4; j++) {
3590 MyTrsf (i, j) = 0.0;
3591 for (k=1; k<=4; k++) {
3592 valueoldtrsf = Trsf1 (i, k);
3593 valuetrsf = Trsf2 (k, j);
3594 valuenewtrsf = MyTrsf (i, j) + valueoldtrsf * valuetrsf;
3595 MyTrsf (i, j) = valuenewtrsf;
3600 //=============================================================================
3601 //function : SetGridActivity
3603 //=============================================================================
3604 void V3d_View::SetGridActivity (const Standard_Boolean AFlag)
3606 if (AFlag) MyGrid->Activate ();
3607 else MyGrid->Deactivate ();
3610 //=============================================================================
3611 //function : toPolarCoords
3613 //=============================================================================
3614 void toPolarCoords (const Standard_Real theX, const Standard_Real theY,
3615 Standard_Real& theR, Standard_Real& thePhi)
3617 theR = Sqrt (theX * theX + theY * theY);
3618 thePhi = ATan2 (theY, theX);
3621 //=============================================================================
3622 //function : toCartesianCoords
3624 //=============================================================================
3625 void toCartesianCoords (const Standard_Real theR, const Standard_Real thePhi,
3626 Standard_Real& theX, Standard_Real& theY)
3628 theX = theR * Cos (thePhi);
3629 theY = theR * Sin (thePhi);
3632 //=============================================================================
3633 //function : Compute
3635 //=============================================================================
3636 Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex& theVertex) const
3638 const Handle(Graphic3d_Camera)& aCamera = Camera();
3639 gp_Dir VPN = aCamera->Direction().Reversed(); // RefPlane
3640 gp_Dir GPN = MyPlane.Direction();
3642 Standard_Real XPp = 0.0, YPp = 0.0;
3643 Project (theVertex.X(), theVertex.Y(), theVertex.Z(), XPp, YPp);
3645 // Casw when the plane of the grid and the plane of the view
3646 // are perpendicular to MYEPSILON2 close radians
3647 #define MYEPSILON2 M_PI / 180.0 // Delta between 2 angles
3648 if (Abs (VPN.Angle (GPN) - M_PI / 2.) < MYEPSILON2)
3653 const gp_XYZ aPnt0 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 0.0, 0.0), MyTrsf);
3655 // get grid axes in world space
3656 const gp_XYZ aPnt1 = V3d_View::TrsPoint (Graphic3d_Vertex (1.0, 0.0, 0.0), MyTrsf);
3657 gp_Vec aGridX (aPnt0, aPnt1);
3660 const gp_XYZ aPnt2 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 1.0, 0.0), MyTrsf);
3661 gp_Vec aGridY (aPnt0, aPnt2);
3664 // project ray from camera onto grid plane
3665 const gp_Vec aProjection = aCamera->IsOrthographic()
3666 ? gp_Vec (aCamera->Direction())
3667 : gp_Vec (aCamera->Eye(), gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z())).Normalized();
3668 const gp_Vec aPointOrigin = gp_Vec (gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z()), aPnt0);
3669 const Standard_Real aT = aPointOrigin.Dot (MyPlane.Direction()) / aProjection.Dot (MyPlane.Direction());
3670 const gp_XYZ aPointOnPlane = gp_XYZ (theVertex.X(), theVertex.Y(), theVertex.Z()) + aProjection.XYZ() * aT;
3672 if (Handle(Aspect_RectangularGrid) aRectGrid = Handle(Aspect_RectangularGrid)::DownCast (MyGrid))
3674 // project point on plane to grid local space
3675 const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3676 const Standard_Real anXSteps = Round (aGridX.Dot (aToPoint) / aRectGrid->XStep());
3677 const Standard_Real anYSteps = Round (aGridY.Dot (aToPoint) / aRectGrid->YStep());
3679 // clamp point to grid
3680 const gp_Vec aResult = aGridX * anXSteps * aRectGrid->XStep()
3681 + aGridY * anYSteps * aRectGrid->YStep()
3683 return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3685 else if (Handle(Aspect_CircularGrid) aCircleGrid = Handle(Aspect_CircularGrid)::DownCast (MyGrid))
3687 const Standard_Real anAlpha = M_PI / Standard_Real (aCircleGrid->DivisionNumber());
3689 // project point on plane to grid local space
3690 const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3691 Standard_Real aLocalX = aGridX.Dot (aToPoint);
3692 Standard_Real aLocalY = aGridY.Dot (aToPoint);
3693 Standard_Real anR = 0.0, aPhi = 0.0;
3694 toPolarCoords (aLocalX, aLocalY, anR, aPhi);
3696 // clamp point to grid
3697 const Standard_Real anRSteps = Round (anR / aCircleGrid->RadiusStep());
3698 const Standard_Real aPhiSteps = Round (aPhi / anAlpha);
3699 toCartesianCoords (anRSteps * aCircleGrid->RadiusStep(), aPhiSteps * anAlpha, aLocalX, aLocalY);
3701 const gp_Vec aResult = aGridX * aLocalX + aGridY * aLocalY + gp_Vec (aPnt0);
3702 return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3704 return Graphic3d_Vertex (0.0, 0.0, 0.0);
3707 //=============================================================================
3708 //function : ZBufferTriedronSetup
3710 //=============================================================================
3711 void V3d_View::ZBufferTriedronSetup (const Quantity_Color& theXColor,
3712 const Quantity_Color& theYColor,
3713 const Quantity_Color& theZColor,
3714 const Standard_Real theSizeRatio,
3715 const Standard_Real theAxisDiametr,
3716 const Standard_Integer theNbFacettes)
3718 const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3719 aTrihedron->SetArrowsColor (theXColor, theYColor, theZColor);
3720 aTrihedron->SetSizeRatio (theSizeRatio);
3721 aTrihedron->SetNbFacets (theNbFacettes);
3722 aTrihedron->SetArrowDiameter (theAxisDiametr);
3725 //=============================================================================
3726 //function : TriedronDisplay
3728 //=============================================================================
3729 void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
3730 const Quantity_Color& theColor,
3731 const Standard_Real theScale,
3732 const V3d_TypeOfVisualization theMode)
3734 const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3735 aTrihedron->SetLabelsColor (theColor);
3736 aTrihedron->SetScale (theScale);
3737 aTrihedron->SetPosition (thePosition);
3738 aTrihedron->SetWireframe (theMode == V3d_WIREFRAME);
3740 aTrihedron->Display (*this);
3743 //=============================================================================
3744 //function : TriedronErase
3746 //=============================================================================
3747 void V3d_View::TriedronErase()
3749 if (!myTrihedron.IsNull())
3751 myTrihedron->Erase();
3755 //=============================================================================
3756 //function : GetGraduatedTrihedron
3758 //=============================================================================
3759 const Graphic3d_GraduatedTrihedron& V3d_View::GetGraduatedTrihedron() const
3761 return myView->GetGraduatedTrihedron();
3764 //=============================================================================
3765 //function : GraduatedTrihedronDisplay
3767 //=============================================================================
3768 void V3d_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
3770 myView->GraduatedTrihedronDisplay (theTrihedronData);
3773 //=============================================================================
3774 //function : GraduatedTrihedronErase
3776 //=============================================================================
3777 void V3d_View::GraduatedTrihedronErase()
3779 myView->GraduatedTrihedronErase();
3782 // =======================================================================
3783 // function : DumpJson
3785 // =======================================================================
3786 void V3d_View::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
3788 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
3790 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseX)
3791 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseY)
3792 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpUp)
3793 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpDir)
3794 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpEye)
3795 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpCenter)
3796 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDefaultCamera.get())
3797 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myView.get())
3798 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myImmediateUpdate)
3799 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsInvalidatedImmediate)
3801 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, MyViewer)
3802 for (V3d_ListOfLight::Iterator anIterator (myActiveLights); anIterator.More(); anIterator.Next())
3804 class Handle(Graphic3d_CLight)& anActiveLight = anIterator.Value();
3805 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, anActiveLight)
3807 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewAxis)
3808 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewPoint)
3809 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyWindow.get())
3810 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sx)
3811 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sy)
3812 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, rx)
3813 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, ry)
3814 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myRotateGravity)
3815 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
3816 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, SwitchSetFront)
3817 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myZRotation)
3818 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointX)
3819 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointY)
3820 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTrihedron.get())
3821 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGrid.get())
3822 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &MyPlane)
3823 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoStructure.get())
3824 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoGroup.get())
3825 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myXscreenAxis)
3826 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myYscreenAxis)
3827 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZscreenAxis)
3828 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myViewAxis)
3829 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGravityReferencePoint)
3830 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitIsOn)
3831 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitScaleFactor)