//
// This file is part of Open CASCADE Technology software library.
//
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
// commercial license or contractual agreement.
/***********************************************************************
-
FONCTION :
----------
Classe V3d_View :
-
HISTORIQUE DES MODIFICATIONS :
--------------------------------
00-09-92 : GG ; Creation.
ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
16-08-98 : CAL ; S3892. Ajout grilles 3d.
09-09-98 : CAL ; S3892. Generalisation de TrsPoint.
-24-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
-13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
29-OCT-98 : DCB : Adding ScreenCopy () method.
-10-11-99 : GG ; PRO19603 Add Redraw( area ) method
-IMP130100 : GG
--> Don't increase too much the ZSize.
--> Initialize correctly the Z clipping and D cueing
-planes.
-IMP100701 : SZV ; Add ToPixMap() method
-
REMARQUES :
-----------
About FitAll() multiple. This probleme is caused by missing
after several Zoom - compared to the exact value (cf ZoomX).
Don't forget that the matrices work in float and not in double.
To solve the problem (for lack of a better solution) I make 2 passes.
-
************************************************************************/
-
-//GER61351 //GG_15/12/99 Add SetBackgroundColor() and BackgroundColor() methods
-
-
-#define IMP020300 //GG Don't use ZFitAll in during Rotation
-// for perf improvment
-
-#define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
-// without call before StartRotation().
-// This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
-
-#define IMP250900 //GG Enable rotation around screen Z axis when
-// rotation begin far the center of the screen.
-// Thanks to Patrick REGINSTER (SAMTECH)
-// GG 21/12/00 Due to a regression on the previous specifications
-// this new functionnality is right now deactivated
-// by default (see StartRotation(...,zRotationThreshold)
-// method.
-
-#define BUC60952 //GG Enable to rotate around the view axis
-// and the required view point
-
-#define RIC120302 //GG Add a NEW SetWindow method which enable
-// to connect a graphic widget and context to OGL.
-
-#define IMP260302 //GG To avoid conflicting in Window destructor
-// nullify this handle in Remove method
-
-#define OCC280 //SAV fix for FitAll problem in the perspective view.
-
-#define OCC1188 //SAV Added methods to set background image
-
/*----------------------------------------------------------------------*/
/*
* Includes
*/
-#include <Standard_TypeMismatch.hxx>
-#include <Visual3d_ViewManager.hxx>
-#include <Visual3d_Light.hxx>
-#include <Image_AlienPixMap.hxx>
-#include <V3d.hxx>
-#include <V3d_View.ixx>
-#include <V3d_BadValue.hxx>
-#include <V3d_StereoDumpOptions.hxx>
-#include <Standard_ShortReal.hxx>
+#include <Aspect_GradientBackground.hxx>
+#include <Aspect_Grid.hxx>
+#include <Aspect_Window.hxx>
+#include <Bnd_Box.hxx>
+#include <gp_Ax3.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
-#include <TColStd_Array2OfReal.hxx>
-#include <Visual3d_TransientManager.hxx>
-#include <Precision.hxx>
-
-#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_Group.hxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
#include <Graphic3d_MapOfStructure.hxx>
+#include <Graphic3d_Structure.hxx>
#include <Graphic3d_TextureEnv.hxx>
-#include <Graphic3d_AspectMarker3d.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
-
-// S3603
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_TypeMap.hxx>
-#include <Aspect_WidthMap.hxx>
-#include <Aspect_MarkMap.hxx>
-#include <Aspect_FontMap.hxx>
+#include <Graphic3d_Vector.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <NCollection_Array1.hxx>
+#include <Precision.hxx>
+#include <Quantity_Color.hxx>
+#include <Standard_Assert.hxx>
+#include <Standard_DivideByZero.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_MultiplyDefined.hxx>
+#include <Standard_ShortReal.hxx>
+#include <Standard_Type.hxx>
+#include <Standard_TypeMismatch.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColStd_Array2OfReal.hxx>
#include <TColStd_HSequenceOfInteger.hxx>
+#include <V3d.hxx>
+#include <V3d_BadValue.hxx>
+#include <V3d_Light.hxx>
+#include <V3d_StereoDumpOptions.hxx>
+#include <V3d_UnMapped.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
#define V3d_FLAG_COMPUTATION 0x00000004
#define DEUXPI (2. * M_PI)
-/*----------------------------------------------------------------------*/
-//-Constructors
+namespace
+{
+ static const Standard_Integer THE_NB_BOUND_POINTS = 8;
+}
-V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
- MyProjModel(V3d_TPM_SCREEN),
- MyViewer(VM.operator->()),
+//=============================================================================
+//function : Constructor
+//purpose :
+//=============================================================================
+V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType)
+: MyViewer (theViewer.operator->()),
MyActiveLights(),
- MyViewContext (),
myActiveLightsIterator(),
- SwitchSetFront(Standard_False),
- MyTrsf (1, 4, 1, 4),
- myAutoZFitMode (Standard_True)
+ SwitchSetFront (Standard_False),
+ MyTrsf (1, 4, 1, 4)
{
- myImmediateUpdate = Standard_False;
- MyView = new Visual3d_View(MyViewer->Viewer());
-
- // { Begin to retrieve the definition from ViewContext.
- // Step MyViewContext = MyView->Context() ;
- // to permit MyView->SetContext to compare
- // the old and the new context.
- // No problem for MyViewMapping, MyViewOrientation
- // as MyView->SetViewMapping and MyView->SetViewOrientation
- // don't try to optimize the modifications introduced to
- // viewmapping and vieworientation.
-
- // Aliasing
- if ((MyView->Context ()).AliasingIsOn ())
- MyViewContext.SetAliasingOn ();
- else
- MyViewContext.SetAliasingOff ();
+ myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
- // DepthCueing
- MyViewContext.SetDepthCueingBackPlane
- ((MyView->Context ()).DepthCueingBackPlane ());
- MyViewContext.SetDepthCueingFrontPlane
- ((MyView->Context ()).DepthCueingFrontPlane ());
+ myView->SetBackground (theViewer->GetBackgroundColor());
+ myView->SetGradientBackground (theViewer->GetGradientBackground());
- if ((MyView->Context ()).DepthCueingIsOn ())
- MyViewContext.SetDepthCueingOn ();
- else
- MyViewContext.SetDepthCueingOff ();
-
- // ZClipping
- MyViewContext.SetZClippingBackPlane
- ((MyView->Context ()).ZClippingBackPlane ());
- MyViewContext.SetZClippingFrontPlane
- ((MyView->Context ()).ZClippingFrontPlane ());
-
- if ((MyView->Context ()).FrontZClippingIsOn ())
- MyViewContext.SetFrontZClippingOn ();
- else
- MyViewContext.SetFrontZClippingOff ();
-
- if ((MyView->Context ()).BackZClippingIsOn ())
- MyViewContext.SetBackZClippingOn ();
- else
- MyViewContext.SetBackZClippingOff ();
-
- // Visualization and Shading Model
- MyViewContext.SetModel ((MyView->Context ()).Model ());
- MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
-
- // Texture Mapping
- MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
- MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
- // } End of retrieval of the definition of ViewContext.
-
- MyBackground = VM->GetBackgroundColor() ;
- MyGradientBackground = VM->GetGradientBackground() ;
+ ChangeRenderingParams() = theViewer->DefaultRenderingParams();
// camera init
Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
aCamera->SetFOVy (45.0);
aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
- SetCamera (aCamera);
+ aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
+ ? Graphic3d_Camera::Projection_Orthographic
+ : Graphic3d_Camera::Projection_Perspective);
+ myDefaultCamera = new Graphic3d_Camera();
+
+ myImmediateUpdate = Standard_False;
+ SetAntialiasingOff();
+ SetAutoZFitMode (Standard_True, 1.0);
+ SetBackFacingModel (V3d_TOBM_AUTOMATIC);
+ SetCamera (aCamera);
SetAxis (0.,0.,0.,1.,1.,1.);
- SetVisualization (VM->DefaultVisualization());
- SetShadingModel (VM->DefaultShadingModel());
- SetSurfaceDetail (VM->DefaultSurfaceDetail());
+ SetVisualization (theViewer->DefaultVisualization());
+ SetShadingModel (theViewer->DefaultShadingModel());
+ SetSurfaceDetail (theViewer->DefaultSurfaceDetail());
SetTwist (0.);
SetAt (0.,0.,0.);
- SetProj (VM->DefaultViewProj());
- SetSize (VM->DefaultViewSize());
- Standard_Real zsize = VM->DefaultViewSize();
+ SetProj (theViewer->DefaultViewProj());
+ SetSize (theViewer->DefaultViewSize());
+ Standard_Real zsize = theViewer->DefaultViewSize();
SetZSize (2.*zsize);
+ SetZClippingType (V3d_OFF);
SetZClippingDepth (0.);
SetZClippingWidth (zsize);
+ SetZCueingOff();
SetZCueingDepth (0.);
SetZCueingWidth (zsize);
- SetDepth (VM->DefaultViewSize()/2.0);
- SetCenter (0.,0.);
+ SetDepth (theViewer->DefaultViewSize() / 2.0);
SetViewMappingDefault();
- VM->AddView (this);
+ SetViewOrientationDefault();
+ theViewer->AddView (this);
Init();
myImmediateUpdate = Standard_True;
-
- aCamera->SetProjectionType ((Type == V3d_ORTHOGRAPHIC)
- ? Graphic3d_Camera::Projection_Orthographic
- : Graphic3d_Camera::Projection_Perspective);
-
- MyTransparencyFlag = Standard_False;
}
-/*----------------------------------------------------------------------*/
-
-V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) :
-MyProjModel(V3d_TPM_SCREEN),
-MyViewer(theVM.operator->()),
-MyActiveLights(),
-MyViewContext (),
-myActiveLightsIterator(),
-SwitchSetFront(Standard_False),
-MyTrsf (1, 4, 1, 4),
-myAutoZFitMode (Standard_True)
+//=============================================================================
+//function : Constructor
+//purpose :
+//=============================================================================
+V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
+: MyViewer (theViewer.operator->()),
+ MyActiveLights(),
+ myActiveLightsIterator(),
+ SwitchSetFront(Standard_False),
+ MyTrsf (1, 4, 1, 4)
{
- Handle(Visual3d_View) aFromView = theView->View();
+ myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
+
+ myView->CopySettings (theView->View());
+
+ myDefaultCamera = new Graphic3d_Camera();
myImmediateUpdate = Standard_False;
- MyView = new Visual3d_View (MyViewer->Viewer());
+ SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
+ SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
+ SetViewMappingDefault();
+ SetViewOrientationDefault();
+ theViewer->AddView (this);
+ Init();
+ myImmediateUpdate = Standard_True;
+}
- for (theView->InitActiveLights(); theView->MoreActiveLights(); theView->NextActiveLights())
+//=============================================================================
+//function : Destructor
+//purpose :
+//=============================================================================
+V3d_View::~V3d_View()
+{
+ if (!myView->IsRemoved())
{
- MyActiveLights.Append (theView->ActiveLight());
+ myView->Remove();
}
+}
- MyViewContext = aFromView->Context() ;
+//=============================================================================
+//function : SetMagnify
+//purpose :
+//=============================================================================
+void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow,
+ const Handle(V3d_View)& thePreviousView,
+ const Standard_Integer theX1,
+ const Standard_Integer theY1,
+ const Standard_Integer theX2,
+ const Standard_Integer theY2)
+{
+ if (!myView->IsRemoved() && !myView->IsDefined())
+ {
+ Standard_Real aU1, aV1, aU2, aV2;
+ thePreviousView->Convert (theX1, theY1, aU1, aV1);
+ thePreviousView->Convert (theX2, theY2, aU2, aV2);
+ myView->SetWindow (theWindow);
+ FitAll (theWindow, aU1, aV1, aU2, aV2);
+ MyViewer->SetViewOn (this);
+ MyWindow = theWindow;
+ SetRatio();
+ Redraw();
+ SetViewMappingDefault();
+ }
+}
- SetCamera (new Graphic3d_Camera (theView->Camera()));
+//=============================================================================
+//function : SetWindow
+//purpose :
+//=============================================================================
+void V3d_View::SetWindow (const Handle(Aspect_Window)& theWindow,
+ const Aspect_RenderingContext theContext)
+{
+ if (myView->IsRemoved())
+ {
+ return;
+ }
- MyBackground = aFromView->Background() ;
- MyGradientBackground = aFromView->GradientBackground();
+ // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
+ MyWindow = theWindow;
+ myView->SetWindow (theWindow, theContext);
+ MyViewer->SetViewOn (this);
+ SetRatio();
+ Redraw();
+}
- MyView->SetContext (MyViewContext) ;
+//=============================================================================
+//function : Remove
+//purpose :
+//=============================================================================
+void V3d_View::Remove() const
+{
+ MyViewer->DelView (this);
+ myView->Remove();
+ Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
+ aWin.Nullify();
+}
- SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
+//=============================================================================
+//function : Update
+//purpose :
+//=============================================================================
+void V3d_View::Update() const
+{
+ if (!myView->IsDefined()
+ || !myView->IsActive())
+ {
+ return;
+ }
- theVM->AddView (this);
+ myView->Update (Aspect_TOU_ASAP);
+}
- Init();
+//=============================================================================
+//function : Redraw
+//purpose :
+//=============================================================================
+void V3d_View::Redraw() const
+{
+ if (!myView->IsDefined()
+ || !myView->IsActive())
+ {
+ return;
+ }
- myImmediateUpdate = Standard_True;
-}
+ Handle(Graphic3d_GraphicDriver) aGraphicDriver = MyViewer->Driver();
+ Handle(Graphic3d_StructureManager) aStructureMgr = MyViewer->StructureManager();
+ for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
+ {
+ if (aGraphicDriver->IsDeviceLost())
+ {
+ aStructureMgr->RecomputeStructures();
+ aGraphicDriver->ResetDeviceLostFlag();
+ }
-/*----------------------------------------------------------------------*/
+ AutoZFit();
-//-Methods, in order
-
-void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
- const Handle(V3d_View)& aPreviousView,
- const Standard_Integer x1,
- const Standard_Integer y1,
- const Standard_Integer x2,
- const Standard_Integer y2)
-{
- if( !MyView->IsDefined() ) {
- Standard_Real a,b,c,d;
- aPreviousView->Convert(x1,y1,a,b);
- aPreviousView->Convert(x2,y2,c,d);
- MyView->SetWindow(TheWindow) ;
- FitAll(TheWindow,a,b,c,d);
- MyView->SetContext(MyViewContext) ;
- MyView->SetBackground(MyBackground) ;
- MyViewer->SetViewOn(this) ;
- MyWindow = TheWindow;
- MyView->Redraw() ;
- SetViewMappingDefault();
+ myView->Redraw();
+
+ if (!aGraphicDriver->IsDeviceLost())
+ {
+ return;
+ }
}
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
+//=============================================================================
+//function : RedrawImmediate
+//purpose :
+//=============================================================================
+void V3d_View::RedrawImmediate() const
{
- Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
- "V3d_View::SetWindow, window of view already defined");
+ if (!myView->IsDefined()
+ || !myView->IsActive())
+ {
+ return;
+ }
- MyView->SetWindow(TheWindow) ;
- // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
- // calling Redraw(). Otherwise it is impossible to call certain methods of
- // V3d_View like Convert() inside the context of Redraw(),
- // particularly in class NIS_View.
- MyWindow = TheWindow;
- // SetWindow carries out SetRatio and modifies
- MyView->SetContext(MyViewContext) ;
- MyView->SetBackground(MyBackground) ;
- MyViewer->SetViewOn(this) ;
- MyView->Redraw() ;
+ myView->RedrawImmediate();
}
-// RIC120302
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
- const Aspect_RenderingContext aContext,
- const Aspect_GraphicCallbackProc& aDisplayCB,
- const Standard_Address aClientData)
-{
- Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
- "V3d_View::SetWindow, "
- "window of view already defined");
- // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
- // calling Redraw(). Otherwise it is impossible to call certain methods of
- // V3d_View like Convert() inside the context of Redraw(),
- // particularly in class NIS_View.
- MyWindow = aWindow;
- MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
- MyView->SetContext(MyViewContext) ;
- MyView->SetBackground(MyBackground) ;
- MyViewer->SetViewOn(this) ;
- MyView->Redraw() ;
-}
-// RIC120302
+//=============================================================================
+//function : Invalidate
+//purpose :
+//=============================================================================
+void V3d_View::Invalidate() const
+{
+ if (!myView->IsDefined())
+ {
+ return;
+ }
-/*----------------------------------------------------------------------*/
+ myView->Invalidate();
+}
-void V3d_View::Remove() const
+//=============================================================================
+//function : IsInvalidated
+//purpose :
+//=============================================================================
+Standard_Boolean V3d_View::IsInvalidated() const
{
- MyViewer->DelView (this);
- MyView->Remove();
- Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
- aWin.Nullify();
+ return !myView->IsDefined()
+ || myView->IsInvalidated();
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Update() const
+// ========================================================================
+// function : SetAutoZFitMode
+// purpose :
+// ========================================================================
+void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
+ const Standard_Real theScaleFactor)
{
- if( MyView->IsDefined() ) MyView->Update() ;
+ Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+ myAutoZFitScaleFactor = theScaleFactor;
+ myAutoZFitIsOn = theIsOn;
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Redraw() const
+// ========================================================================
+// function : AutoZFitMode
+// purpose :
+// ========================================================================
+Standard_Boolean V3d_View::AutoZFitMode() const
{
- if( MyView->IsDefined() ) MyView->Redraw() ;
+ return myAutoZFitIsOn;
}
-/*----------------------------------------------------------------------*/
+// ========================================================================
+// function : AutoZFitScaleFactor
+// purpose :
+// ========================================================================
+Standard_Real V3d_View::AutoZFitScaleFactor() const
+{
+ return myAutoZFitScaleFactor;
+}
-void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
- const Standard_Integer width,const Standard_Integer height) const
+//=============================================================================
+//function : AutoZFit
+//purpose :
+//=============================================================================
+void V3d_View::AutoZFit() const
{
- if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
+ if (!AutoZFitMode())
+ {
+ return;
+ }
+
+ ZFitAll (myAutoZFitScaleFactor);
}
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : ZFitAll
+//purpose :
+//=============================================================================
+void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const
+{
+ Bnd_Box aMinMaxBox = myView->MinMaxValues (Standard_False); // applicative min max boundaries
+ Bnd_Box aGraphicBox = myView->MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag).
+ myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
+}
+
+//=============================================================================
+//function : IsEmpty
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::IsEmpty() const
{
Standard_Boolean TheStatus = Standard_True ;
- if( MyView->IsDefined() ) {
- Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+ if( myView->IsDefined() ) {
+ Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
if( Nstruct > 0 ) TheStatus = Standard_False ;
}
return (TheStatus) ;
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : UpdateLights
+//purpose :
+//=============================================================================
void V3d_View::UpdateLights() const
{
- MyView->SetContext(MyViewContext);
+ Graphic3d_ListOfCLight aLights;
+
+ for (TColStd_ListIteratorOfListOfTransient anIt (MyActiveLights); anIt.More(); anIt.Next())
+ {
+ aLights.Append (Handle(V3d_Light)::DownCast (anIt.Value())->Light());
+ }
+
+ myView->SetLights (aLights);
+
Update();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : DoMapping
+//purpose :
+//=============================================================================
void V3d_View::DoMapping()
{
- if( MyView->IsDefined() ) {
- (MyView->Window())->DoMapping() ;
+ if (!myView->IsDefined())
+ {
+ return;
}
-}
-/*----------------------------------------------------------------------*/
+ myView->Window()->DoMapping();
+}
+//=============================================================================
+//function : MustBeResized
+//purpose :
+//=============================================================================
void V3d_View::MustBeResized()
{
- if ( !MyLayerMgr.IsNull() )
- MyLayerMgr->Resized();
-
- if( MyView->IsDefined() ) {
- MyView->Resized() ;
- MyView->Redraw();
+ if (!myView->IsDefined())
+ {
+ return;
}
-}
-/*----------------------------------------------------------------------*/
+ myView->Resized();
-void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
-{
- Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
- Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
- Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
+ SetRatio();
- Quantity_Color C( V1, V2, V3, Type );
- SetBackgroundColor( C );
+ Redraw();
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
+//=============================================================================
+//function : SetBackgroundColor
+//purpose :
+//=============================================================================
+void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
+ const Standard_Real theV1,
+ const Standard_Real theV2,
+ const Standard_Real theV3)
{
- MyBackground.SetColor( Color );
- if ( MyView->IsDefined() )
- MyView->SetBackground( MyBackground );
- //szv: Why?
- if ( !MyLayerMgr.IsNull() )
- MyLayerMgr->Resized();
-}
+ Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0);
+ Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0);
+ Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0);
-/*----------------------------------------------------------------------*/
+ SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
+}
-void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
+//=============================================================================
+//function : SetBackgroundColor
+//purpose :
+//=============================================================================
+void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
{
- Quantity_Color C( Name );
- SetBackgroundColor( C );
-}
+ myView->SetBackground (Aspect_Background (theColor));
-/*----------------------------------------------------------------------*/
+ if (myImmediateUpdate)
+ {
+ Redraw();
+ }
+}
-void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
- const Quantity_Color& Color2,
- const Aspect_GradientFillMethod FillStyle,
- const Standard_Boolean status)
+//=============================================================================
+//function : SetBackgroundColor
+//purpose :
+//=============================================================================
+void V3d_View::SetBackgroundColor (const Quantity_NameOfColor theName)
{
- MyGradientBackground.SetColors(Color1, Color2, FillStyle);
- if ( MyView->IsDefined() )
- MyView->SetGradientBackground( MyGradientBackground, status );
+ SetBackgroundColor (Quantity_Color (theName));
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
- const Quantity_NameOfColor Color2,
- const Aspect_GradientFillMethod FillStyle,
- const Standard_Boolean status )
+//=============================================================================
+//function : SetBgGradientColors
+//purpose :
+//=============================================================================
+void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
+ const Quantity_Color& theColor2,
+ const Aspect_GradientFillMethod theFillStyle,
+ const Standard_Boolean theToUpdate)
{
- Quantity_Color C1( Color1 );
- Quantity_Color C2( Color2 );
- MyGradientBackground.SetColors( C1, C2, FillStyle );
- if ( MyView->IsDefined() )
- MyView->SetGradientBackground( MyGradientBackground, status );
-}
+ Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
-/*----------------------------------------------------------------------*/
+ myView->SetGradientBackground (aGradientBg);
-void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
- const Standard_Boolean update)
-{
- Quantity_Color Color1, Color2;
- MyGradientBackground.Colors( Color1, Color2 );
- MyGradientBackground.SetColors( Color1, Color2, FillStyle );
- if( MyView->IsDefined() )
- MyView->SetBgGradientStyle( FillStyle, update ) ;
+ if (myImmediateUpdate || theToUpdate)
+ {
+ Redraw();
+ }
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundImage( const Standard_CString FileName,
- const Aspect_FillMethod FillStyle,
- const Standard_Boolean update )
+//=============================================================================
+//function : SetBgGradientColors
+//purpose :
+//=============================================================================
+void V3d_View::SetBgGradientColors (const Quantity_NameOfColor theColor1,
+ const Quantity_NameOfColor theColor2,
+ const Aspect_GradientFillMethod theFillStyle,
+ const Standard_Boolean theToUpdate)
{
-#ifdef OCC1188
- if( MyView->IsDefined() )
- MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
-#endif
+ Quantity_Color aColor1 (theColor1);
+ Quantity_Color aColor2 (theColor2);
+
+ SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
}
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : SetBgGradientStyle
+//purpose :
+//=============================================================================
+void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate)
+{
+ Quantity_Color aColor1;
+ Quantity_Color aColor2;
+ GradientBackground().Colors (aColor1, aColor2);
+
+ SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
+}
-void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
- const Standard_Boolean update )
+//=============================================================================
+//function : SetBackgroundImage
+//purpose :
+//=============================================================================
+void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
+ const Aspect_FillMethod theFillStyle,
+ const Standard_Boolean theToUpdate)
{
-#ifdef OCC1188
- if( MyView->IsDefined() )
- MyView->SetBgImageStyle( FillStyle, update ) ;
-#endif
+ myView->SetBackgroundImage (theFileName);
+ myView->SetBackgroundImageStyle (theFillStyle);
+
+ if (myImmediateUpdate || theToUpdate)
+ {
+ Redraw();
+ }
}
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : SetBgImageStyle
+//purpose :
+//=============================================================================
+void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
+{
+ myView->SetBackgroundImageStyle (theFillStyle);
+
+ if (myImmediateUpdate || theToUpdate)
+ {
+ Redraw();
+ }
+}
+//=============================================================================
+//function : SetAxis
+//purpose :
+//=============================================================================
void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz)
{
Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model)
+//=============================================================================
+//function : SetShadingModel
+//purpose :
+//=============================================================================
+void V3d_View::SetShadingModel (const V3d_TypeOfShadingModel theShadingModel)
{
- MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
- MyView->SetContext(MyViewContext) ;
+ myView->SetShadingModel (static_cast<Graphic3d_TypeOfShadingModel> (theShadingModel));
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model)
+//=============================================================================
+//function : SetSurfaceDetail
+//purpose :
+//=============================================================================
+void V3d_View::SetSurfaceDetail (const V3d_TypeOfSurfaceDetail theSurfaceDetail)
{
- MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
- MyView->SetContext(MyViewContext) ;
+ myView->SetSurfaceDetailType (static_cast<Graphic3d_TypeOfSurfaceDetail> (theSurfaceDetail));
}
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
+//=============================================================================
+//function : SetTextureEnv
+//purpose :
+//=============================================================================
+void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
{
- MyViewContext.SetTextureEnv(ATexture) ;
- MyView->SetContext(MyViewContext) ;
-}
+ myView->SetTextureEnv (theTexture);
-/*----------------------------------------------------------------------*/
+ if (myImmediateUpdate)
+ {
+ Redraw();
+ }
+}
-void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode)
+//=============================================================================
+//function : SetVisualization
+//purpose :
+//=============================================================================
+void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
{
- MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
- MyView->SetContext(MyViewContext) ;
-}
+ myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
-/*----------------------------------------------------------------------*/
+ if (myImmediateUpdate)
+ {
+ Redraw();
+ }
+}
+//=============================================================================
+//function : SetFront
+//purpose :
+//=============================================================================
void V3d_View::SetFront()
{
gp_Ax3 a = MyViewer->PrivilegedPlane();
a.YDirection().Coord(xu,yu,zu);
a.Location().Coord(xo,yo,zo);
- myCamera->BeginUpdate();
- myCamera->SetCenter (gp_Pnt (xo, yo, zo));
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ aCamera->SetCenter (gp_Pnt (xo, yo, zo));
+
if(SwitchSetFront)
- myCamera->SetDirection (gp_Dir (vx, vy, vz));
+ {
+ aCamera->SetDirection (gp_Dir (vx, vy, vz));
+ }
else
- myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
- myCamera->SetUp (gp_Dir (xu, yu, zu));
+ {
+ aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
+ }
+
+ aCamera->SetUp (gp_Dir (xu, yu, zu));
AutoZFit();
- myCamera->EndUpdate();
SwitchSetFront = !SwitchSetFront;
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose :
+//=============================================================================
void V3d_View::Rotate (const Standard_Real ax,
const Standard_Real ay,
const Standard_Real az,
if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if (Start)
{
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
// rotate camera around 3 initial axes
gp_Dir aBackDir (gp_Vec (myCamStartOpCenter, myCamStartOpEye));
aTrsf.Multiply (aRot[1]);
aTrsf.Multiply (aRot[2]);
- myCamera->Transform (aTrsf);
-
- myCamera->EndUpdate();
+ aCamera->Transform (aTrsf);
AutoZFit();
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose :
+//=============================================================================
void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
{
if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if (Start)
{
myGravityReferencePoint.SetCoord (X, Y, Z);
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
const Graphic3d_Vertex& aVref = myGravityReferencePoint;
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
// rotate camera around 3 initial axes
gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
- gp_Dir aZAxis (myCamera->Direction().Reversed());
- gp_Dir aYAxis (myCamera->Up());
+ gp_Dir aZAxis (aCamera->Direction().Reversed());
+ gp_Dir aYAxis (aCamera->Up());
gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
gp_Trsf aRot[3], aTrsf;
aTrsf.Multiply (aRot[1]);
aTrsf.Multiply (aRot[2]);
- myCamera->Transform (aTrsf);
- myCamera->EndUpdate();
+ aCamera->Transform (aTrsf);
AutoZFit();
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose :
+//=============================================================================
void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
{
switch (Axe) {
}
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose :
+//=============================================================================
void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
{
if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if (Start)
{
myGravityReferencePoint.SetCoord (X, Y, Z);
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
switch (Axe) {
case V3d_X :
break ;
}
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
const Graphic3d_Vertex& aVref = myGravityReferencePoint;
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
// rotate camera around passed axis
gp_Trsf aRotation;
(Axe == V3d_Z) ? 1.0 : 0.0);
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
- myCamera->Transform (aRotation);
- myCamera->EndUpdate();
+ aCamera->Transform (aRotation);
AutoZFit();
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose :
+//=============================================================================
void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
{
Standard_Real Angle = angle;
if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if( Start ) {
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
const Graphic3d_Vertex& aPnt = MyDefaultViewPoint;
const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
gp_Trsf aRotation;
gp_Pnt aRCenter (aPnt.X(), aPnt.Y(), aPnt.Z());
gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
- myCamera->Transform (aRotation);
- myCamera->EndUpdate();
+ aCamera->Transform (aRotation);
AutoZFit();
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Turn
+//purpose :
+//=============================================================================
void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
{
Standard_Real Ax = ax;
if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if( Start ) {
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
// rotate camera around 3 initial axes
- gp_Pnt aRCenter = myCamera->Eye();
- gp_Dir aZAxis (myCamera->Direction().Reversed());
- gp_Dir aYAxis (myCamera->Up());
+ gp_Pnt aRCenter = aCamera->Eye();
+ gp_Dir aZAxis (aCamera->Direction().Reversed());
+ gp_Dir aYAxis (aCamera->Up());
gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
gp_Trsf aRot[3], aTrsf;
aTrsf.Multiply (aRot[1]);
aTrsf.Multiply (aRot[2]);
- myCamera->Transform (aTrsf);
- myCamera->EndUpdate();
+ aCamera->Transform (aTrsf);
AutoZFit();
ImmediateUpdate();
}
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Turn
+//purpose :
+//=============================================================================
void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
{
switch (Axe) {
}
}
+//=============================================================================
+//function : Turn
+//purpose :
+//=============================================================================
void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
{
Standard_Real Angle = angle ;
if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if( Start ) {
- myCamStartOpUp = myCamera->Up();
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpUp = aCamera->Up();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
- myCamera->BeginUpdate();
- myCamera->SetUp (myCamStartOpUp);
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetUp (myCamStartOpUp);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
gp_Trsf aRotation;
- gp_Pnt aRCenter = myCamera->Eye();
+ gp_Pnt aRCenter = aCamera->Eye();
gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
- myCamera->Transform (aRotation);
- myCamera->EndUpdate();
+ aCamera->Transform (aRotation);
AutoZFit();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetTwist
+//purpose :
+//=============================================================================
void V3d_View::SetTwist(const Standard_Real angle)
{
Standard_Real Angle = angle ;
if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
- gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_Dir aReferencePlane (aCamera->Direction().Reversed());
gp_Dir anUp;
anUp = gp_Dir (0.0, 0.0, 1.0);
V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
- gp_Pnt aRCenter = myCamera->Center();
- gp_Dir aZAxis (myCamera->Direction().Reversed());
+ gp_Pnt aRCenter = aCamera->Center();
+ gp_Dir aZAxis (aCamera->Direction().Reversed());
gp_Trsf aTrsf;
aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
-
- myCamera->BeginUpdate();
- myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
- myCamera->Transform (aTrsf);
- myCamera->EndUpdate();
+
+ aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+ aCamera->Transform (aTrsf);
AutoZFit();
ImmediateUpdate();
}
-void V3d_View::SetAutoZFitMode (Standard_Boolean theMode)
-{
- myAutoZFitMode = theMode;
-}
-
-Standard_Boolean V3d_View::AutoZFitMode () const
-{
- return myAutoZFitMode;
-}
-
+//=============================================================================
+//function : SetEye
+//purpose :
+//=============================================================================
void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
{
- Standard_Real Angle;
- Angle = Twist();
+ Standard_Real aTwistBefore = Twist();
- myCamera->SetEye (gp_Pnt (X, Y, Z));
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
- Standard_Boolean update = myImmediateUpdate;
- myImmediateUpdate = Standard_False;
+ Handle(Graphic3d_Camera) aCamera = Camera();
- SetTwist(Angle);
+ aCamera->SetEye (gp_Pnt (X, Y, Z));
+
+ SetTwist (aTwistBefore);
AutoZFit();
- myImmediateUpdate = update;
+ SetImmediateUpdate (wasUpdateEnabled);
+
ImmediateUpdate();
}
+//=============================================================================
+//function : SetDepth
+//purpose :
+//=============================================================================
void V3d_View::SetDepth(const Standard_Real Depth)
{
V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if( Depth > 0. )
{
// Move eye using center (target) as anchor.
- myCamera->SetDistance (Depth);
+ aCamera->SetDistance (Depth);
}
else
- {
+ {
// Move the view ref point instead of the eye.
- gp_Vec aDir (myCamera->Direction());
- gp_Pnt aCameraEye = myCamera->Eye();
- gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
-
- myCamera->SetCenter (aCameraCenter);
+ gp_Vec aDir (aCamera->Direction());
+ gp_Pnt aCameraEye = aCamera->Eye();
+ gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
+
+ aCamera->SetCenter (aCameraCenter);
}
AutoZFit();
ImmediateUpdate();
}
-
+//=============================================================================
+//function : SetProj
+//purpose :
+//=============================================================================
void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
{
- Standard_Real Angle ;
-
V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
"V3d_View::SetProj, null projection vector");
- Angle = Twist();
+ Standard_Real aTwistBefore = Twist();
- myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
- Standard_Boolean update = myImmediateUpdate;
- myImmediateUpdate = Standard_False;
+ Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
- if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
+ SetTwist(aTwistBefore);
AutoZFit();
- myImmediateUpdate = update;
+ SetImmediateUpdate (wasUpdateEnabled);
+
ImmediateUpdate();
}
+//=============================================================================
+//function : SetProj
+//purpose :
+//=============================================================================
void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
{
Standard_Real Xpn=0;
}
const Graphic3d_Vector& aBck = V3d::GetProjAxis (Orientation);
- myCamera->BeginUpdate();
- myCamera->SetCenter (gp_Pnt (0, 0, 0));
- myCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed());
- myCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn));
- myCamera->EndUpdate();
+
+ // retain camera panning from origin when switching projection
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
+ Standard_Real aPanX = anOriginVCS.X();
+ Standard_Real aPanY = anOriginVCS.Y();
+
+ aCamera->SetCenter (gp_Pnt (0, 0, 0));
+ aCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed());
+ aCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn));
+ aCamera->OrthogonalizeUp();
+
+ Panning (aPanX, aPanY);
AutoZFit();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetAt
+//purpose :
+//=============================================================================
void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
{
- Standard_Real Angle;
+ Standard_Real aTwistBefore = Twist();
- Angle = Twist();
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
- myCamera->SetCenter (gp_Pnt (X, Y, Z));
- Standard_Boolean update = myImmediateUpdate;
- myImmediateUpdate = Standard_False;
+ Camera()->SetCenter (gp_Pnt (X, Y, Z));
- SetTwist(Angle) ;
+ SetTwist (aTwistBefore);
AutoZFit();
- myImmediateUpdate = update;
+ SetImmediateUpdate (wasUpdateEnabled);
+
ImmediateUpdate();
}
+//=============================================================================
+//function : SetUp
+//purpose :
+//=============================================================================
void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz)
{
Standard_Boolean TheStatus ;
V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
"V3d_View::SetUp, nullUp vector");
- gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_Dir aReferencePlane (aCamera->Direction().Reversed());
gp_Dir anUp (Vx, Vy, Vz);
TheStatus = ScreenAxis(aReferencePlane,anUp,
Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
- myCamera->BeginUpdate();
- myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+ aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+
AutoZFit();
- myCamera->EndUpdate();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetUp
+//purpose :
+//=============================================================================
void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
{
Standard_Boolean TheStatus ;
- gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_Dir aReferencePlane (aCamera->Direction().Reversed());
gp_Dir anUp;
const Graphic3d_Vector& aViewReferenceUp = V3d::GetProjAxis(Orientation) ;
Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
- myCamera->BeginUpdate();
- myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+ aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+
AutoZFit();
- myCamera->EndUpdate();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetViewOrientationDefault
+//purpose :
+//=============================================================================
void V3d_View::SetViewOrientationDefault()
{
- MyView->SetViewOrientationDefault() ;
+ myDefaultCamera->CopyOrientationData (Camera());
+}
- ImmediateUpdate();
+//=======================================================================
+//function : SetViewMappingDefault
+//purpose :
+//=======================================================================
+void V3d_View::SetViewMappingDefault()
+{
+ myDefaultCamera->CopyMappingData (Camera());
}
+//=============================================================================
+//function : ResetViewOrientation
+//purpose :
+//=============================================================================
void V3d_View::ResetViewOrientation()
{
- MyView->ViewOrientationReset() ;
+ Camera()->CopyOrientationData (myDefaultCamera);
+
+ AutoZFit();
ImmediateUpdate();
}
-void V3d_View::Reset( const Standard_Boolean update )
+//=======================================================================
+//function : ResetViewMapping
+//purpose :
+//=======================================================================
+void V3d_View::ResetViewMapping()
{
- Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
-
- if (!aDefaultCamera.IsNull())
- {
- myCamera->BeginUpdate();
- myCamera->CopyMappingData (aDefaultCamera);
- myCamera->CopyOrientationData (aDefaultCamera);
- myCamera->EndUpdate();
- }
+ Camera()->CopyMappingData (myDefaultCamera);
AutoZFit();
- SwitchSetFront = Standard_False;
- if( !myImmediateUpdate && update ) Update();
+ ImmediateUpdate();
}
-void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
+//=============================================================================
+//function : Reset
+//purpose :
+//=============================================================================
+void V3d_View::Reset (const Standard_Boolean theToUpdate)
{
- V3d_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
-
- if( Start ) {
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
- myCamProjectionShift = myCamera->ProjectionShift();
- }
+ Camera()->Copy (myDefaultCamera);
- myCamera->BeginUpdate();
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
- myCamera->SetProjectionShift (myCamProjectionShift);
- PanCamera (-Dx, -Dy);
- gp_Pnt aViewDims = myCamera->ViewDimensions();
- ZoomCamera (aViewDims.X() / aZoomFactor, aViewDims.Y() / aZoomFactor);
- myCamera->EndUpdate();
+ AutoZFit();
- ImmediateUpdate();
-}
+ SwitchSetFront = Standard_False;
-void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y)
-{
- Standard_Real x,y;
- Convert(X,Y,x,y);
- SetCenter(x,y);
+ if (myImmediateUpdate || theToUpdate)
+ {
+ Update();
+ }
}
-void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc)
+//=======================================================================
+//function : SetCenter
+//purpose :
+//=======================================================================
+void V3d_View::SetCenter (const Standard_Integer theXp,
+ const Standard_Integer theYp)
{
- myCamera->SetProjectionShift (gp_Pnt (-Xc, -Yc, 0.0));
+ Standard_Real aXv, aYv;
+ Convert (theXp, theYp, aXv, aYv);
+ Translate (Camera(), aXv, aYv);
ImmediateUpdate();
}
-void V3d_View::SetSize(const Standard_Real Size)
+//=============================================================================
+//function : SetSize
+//purpose :
+//=============================================================================
+void V3d_View::SetSize (const Standard_Real theSize)
{
- V3d_BadValue_Raise_if( Size <= 0.,
- "V3d_View::SetSize, Window Size is NULL");
+ V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
+
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
- myCamera->BeginUpdate();
- myCamera->SetScale (Size);
AutoZFit();
- myCamera->EndUpdate();
ImmediateUpdate();
}
-void V3d_View::SetZSize(const Standard_Real Size)
+//=============================================================================
+//function : SetZSize
+//purpose :
+//=============================================================================
+void V3d_View::SetZSize (const Standard_Real theSize)
{
- Standard_Real Zmax = Size/2.;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ Standard_Real Zmax = theSize / 2.;
- Standard_Real aDistance = myCamera->Distance();
+ Standard_Real aDistance = aCamera->Distance();
- if( Size <= 0. ) {
+ if (theSize <= 0.)
+ {
Zmax = aDistance;
}
- Standard_Real Front = MyViewContext.ZClippingFrontPlane();
- Standard_Real Back = MyViewContext.ZClippingBackPlane();
+ // ShortReal precision factor used to add meaningful tolerance to
+ // ZNear, ZFar values in order to avoid equality after type conversion
+ // to ShortReal matrices type.
+ const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
- myCamera->SetZFar (Zmax + aDistance * 2.0);
- myCamera->SetZNear (-Zmax + aDistance);
+ Standard_Real aZFar = Zmax + aDistance * 2.0;
+ Standard_Real aZNear = -Zmax + aDistance;
+ aZNear -= Abs (aZNear) * aPrecision;
+ aZFar += Abs (aZFar) * aPrecision;
- if (MyViewContext.FrontZClippingIsOn() ||
- MyViewContext.BackZClippingIsOn())
+ if (!aCamera->IsOrthographic())
{
- MyViewContext.SetZClippingFrontPlane (Front);
- MyViewContext.SetZClippingBackPlane (Back);
- MyView->SetContext (MyViewContext);
+ if (aZFar < aPrecision)
+ {
+ // Invalid case when both values are negative
+ aZNear = aPrecision;
+ aZFar = aPrecision * 2.0;
+ }
+ else if (aZNear < Abs (aZFar) * aPrecision)
+ {
+ // Z is less than 0.0, try to fix it using any appropriate z-scale
+ aZNear = Abs (aZFar) * aPrecision;
+ }
+ }
+
+ // If range is too small
+ if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
+ {
+ aZFar = aZNear + Abs (aZFar) * aPrecision;
+ }
+
+ aCamera->SetZRange (aZNear, aZFar);
+
+ if (myImmediateUpdate)
+ {
+ Redraw();
}
}
+//=============================================================================
+//function : SetZoom
+//purpose :
+//=============================================================================
void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
{
V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
if (Start)
{
- myCamStartOpEye = myCamera->Eye();
- myCamStartOpCenter = myCamera->Center();
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
- Standard_Real aViewWidth = myCamera->ViewDimensions().X();
- Standard_Real aViewHeight = myCamera->ViewDimensions().Y();
+ Standard_Real aViewWidth = aCamera->ViewDimensions().X();
+ Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
// ensure that zoom will not be too small or too big
Standard_Real coef = Coef;
coef = aViewHeight / 1e12;
}
- myCamera->BeginUpdate();
- myCamera->SetEye (myCamStartOpEye);
- myCamera->SetCenter (myCamStartOpCenter);
- myCamera->SetScale (myCamera->Scale() / Coef);
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
+ aCamera->SetScale (aCamera->Scale() / Coef);
+
AutoZFit();
- myCamera->EndUpdate();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetScale
+//purpose :
+//=============================================================================
void V3d_View::SetScale( const Standard_Real Coef )
{
V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
- Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
+ Handle(Graphic3d_Camera) aCamera = Camera();
- myCamera->BeginUpdate();
-
- // Strange behavior for the sake of compatibility.
- if (!aDefaultCamera.IsNull())
- {
- myCamera->SetAspect (aDefaultCamera->Aspect());
- Standard_Real aDefaultScale = aDefaultCamera->Scale();
- myCamera->SetScale (aDefaultScale / Coef);
- }
- else
- {
- myCamera->SetScale (myCamera->Scale() / Coef);
- }
+ Standard_Real aDefaultScale = myDefaultCamera->Scale();
+ aCamera->SetAspect (myDefaultCamera->Aspect());
+ aCamera->SetScale (aDefaultScale / Coef);
AutoZFit();
- myCamera->EndUpdate();
ImmediateUpdate();
}
+//=============================================================================
+//function : SetAxialScale
+//purpose :
+//=============================================================================
void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
{
V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
- myCamera->BeginUpdate();
- myCamera->SetAxialScale (gp_Pnt (Sx, Sy, Sz));
+ Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
+
AutoZFit();
- myCamera->EndUpdate();
}
-void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean update)
+//=============================================================================
+//function : SetRatio
+//purpose :
+//=============================================================================
+void V3d_View::SetRatio()
{
- Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-
- // retrieve min / max values for current displayed objects
- MyView->MinMaxValues (Xmin, Ymin, Zmin,
- Xmax, Ymax, Zmax);
-
- Standard_Real LIM = ShortRealLast() - 1.0;
- if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
- || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
+ if (MyWindow.IsNull())
{
- ImmediateUpdate();
return;
}
- myCamera->BeginUpdate();
- FitCamera (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
- myCamera->SetScale (myCamera->Scale() * (1.0 + Coef));
- AutoZFit();
- myCamera->EndUpdate();
-
- if (myImmediateUpdate || update)
+ Standard_Integer aWidth = 0;
+ Standard_Integer aHeight = 0;
+ MyWindow->Size (aWidth, aHeight);
+ if (aWidth > 0 && aHeight > 0)
{
- Update();
+ Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
+ static_cast<Standard_Real> (aHeight);
+
+ Camera() ->SetAspect (aRatio);
+ myDefaultCamera->SetAspect (aRatio);
}
}
-//===============================================================================================
-//function : AutoZFit
+//=============================================================================
+//function : FitAll
//purpose :
-//===============================================================================================
-void V3d_View::AutoZFit()
+//=============================================================================
+void V3d_View::FitAll (const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate)
{
- if (myAutoZFitMode)
- {
- ZFitAll();
- }
+ FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
}
-void V3d_View::ZFitAll (const Standard_Real theCoeff)
+//=============================================================================
+//function : FitAll
+//purpose :
+//=============================================================================
+void V3d_View::FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate)
{
- V3d_BadValue_Raise_if (theCoeff <= 0.0, "V3d_View::ZFitAll, bad margin coefficient");
-
- Standard_Real aMinMax[6];
-
- MyView->MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2], aMinMax[3], aMinMax[4], aMinMax[5]);
-
- gp_Pnt aBMin = gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2]);
- gp_Pnt aBMax = gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5]);
+ Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
- // check bounding box for validness
- Standard_Real aLim = (ShortRealLast() - 1.0);
- if (Abs (aBMin.X()) > aLim || Abs (aBMin.Y()) > aLim || Abs (aBMin.Z()) > aLim ||
- Abs (aBMax.X()) > aLim || Abs (aBMax.Y()) > aLim || Abs (aBMax.Z()) > aLim)
+ if (myView->NumberOfDisplayedStructures() == 0)
{
- SetZSize (0.0);
- ImmediateUpdate();
return;
}
- // adapt bound points
- gp_Pnt aPnts[8] =
- { gp_Pnt (aBMin.X(), aBMin.Y(), aBMin.Z()),
- gp_Pnt (aBMin.X(), aBMin.Y(), aBMax.Z()),
- gp_Pnt (aBMin.X(), aBMax.Y(), aBMin.Z()),
- gp_Pnt (aBMin.X(), aBMax.Y(), aBMax.Z()),
- gp_Pnt (aBMax.X(), aBMin.Y(), aBMin.Z()),
- gp_Pnt (aBMax.X(), aBMin.Y(), aBMax.Z()),
- gp_Pnt (aBMax.X(), aBMax.Y(), aBMin.Z()),
- gp_Pnt (aBMax.X(), aBMax.Y(), aBMax.Z()) };
-
- // camera Eye plane
- gp_Dir aDir = myCamera->Direction();
- gp_Pnt anEye = myCamera->Eye();
- gp_Pln aCamPln (anEye, aDir);
-
- Standard_Real aMinDist = RealLast() - 1;
- Standard_Real aMaxDist = RealFirst() + 1;
-
- gp_Pnt anAxialScale = myCamera->AxialScale();
-
- // get minimum and maximum distances to the eye plane
- for (Standard_Integer aPntIt = 0; aPntIt < 8; ++aPntIt)
+ if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
{
- gp_Pnt aPnt = aPnts[aPntIt];
-
- aPnt = gp_Pnt (aPnt.X() * anAxialScale.X(),
- aPnt.Y() * anAxialScale.Y(),
- aPnt.Z() * anAxialScale.Z());
-
- Standard_Real aDistance = aCamPln.Distance (aPnt);
-
- // check if the camera is intruded into the scene
- if (aDir.IsOpposite (gp_Vec (anEye, aPnt), M_PI * 0.5))
- {
- aDistance *= -1;
- }
-
- aMinDist = Min (aDistance, aMinDist);
- aMaxDist = Max (aDistance, aMaxDist);
+ return;
}
- // compute depth of bounding box center
- Standard_Real aMidDepth = (aMinDist + aMaxDist) * 0.5;
- Standard_Real aHalfDepth = (aMaxDist - aMinDist) * 0.5;
-
- // compute enlarged or shrank near and far z ranges.
- Standard_Real aZNear = aMidDepth - aHalfDepth * theCoeff;
- Standard_Real aZFar = aMidDepth + aHalfDepth * theCoeff;
-
- myCamera->BeginUpdate();
-
- if (myCamera->IsOrthographic())
- {
- myCamera->SetZFar (myCamera->Distance() * 3.0);
- myCamera->SetZNear (0.0);
+ AutoZFit();
- if (aZNear < 0.0)
- {
- myCamera->SetDistance (myCamera->Distance() - (aZNear + myCamera->ZNear()) + 10.0);
- }
- }
- else
+ if (myImmediateUpdate || theToUpdate)
{
- myCamera->SetZFar (aZFar);
- myCamera->SetZNear (aZNear);
+ Update();
}
-
- myCamera->EndUpdate();
-
- ImmediateUpdate();
}
-
-// Better to use ZFitAll instead.
+//=============================================================================
+//function : DepthFitAll
+//purpose :
+//=============================================================================
void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
const Quantity_Coefficient Margin)
{
Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
Standard_Real Dx,Dy,Dz,Size;
- Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+ Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
ImmediateUpdate();
return ;
}
- MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
-
- Standard_Real LIM = ShortRealLast() -1.;
- if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
- || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
- ImmediateUpdate();
- return ;
- }
-
- if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
- ImmediateUpdate();
- return ;
- }
- MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
- MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
+ Bnd_Box aBox = myView->MinMaxValues();
+ if (aBox.IsVoid())
+ {
+ ImmediateUpdate();
+ return ;
+ }
+ aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
+ Project (Xmin,Ymin,Zmin,U,V,W) ;
+ Project (Xmax,Ymax,Zmax,U1,V1,W1) ;
Umin = Min(U,U1) ; Umax = Max(U,U1) ;
Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
- MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
+ Project (Xmin,Ymin,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
+ Project (Xmax,Ymin,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
+ Project (Xmax,Ymin,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
+ Project (Xmax,Ymax,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
+ Project (Xmin,Ymax,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
+ Project (Xmin,Ymax,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
ImmediateUpdate();
}
-void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax)
+//=============================================================================
+//function : FitAll
+//purpose :
+//=============================================================================
+void V3d_View::FitAll(const Standard_Real theMinXv,
+ const Standard_Real theMinYv,
+ const Standard_Real theMaxXv,
+ const Standard_Real theMaxYv)
{
- FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
-
- ImmediateUpdate();
+ FitAll (MyWindow, theMinXv, theMinYv, theMaxXv, theMaxYv);
}
-void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax)
+//=============================================================================
+//function : WindowFitAll
+//purpose :
+//=============================================================================
+void V3d_View::WindowFitAll(const Standard_Integer Xmin,
+ const Standard_Integer Ymin,
+ const Standard_Integer Xmax,
+ const Standard_Integer Ymax)
{
WindowFit(Xmin,Ymin,Xmax,Ymax);
}
-void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax)
+//=======================================================================
+//function : WindowFit
+//purpose :
+//=======================================================================
+void V3d_View::WindowFit (const Standard_Integer theMinXp,
+ const Standard_Integer theMinYp,
+ const Standard_Integer theMaxXp,
+ const Standard_Integer theMaxYp)
{
- if (!myCamera->IsOrthographic())
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ if (!aCamera->IsOrthographic())
{
- // normalize view coordiantes
+ // normalize view coordinates
Standard_Integer aWinWidth, aWinHeight;
MyWindow->Size (aWinWidth, aWinHeight);
// z coordinate of camera center
- Standard_Real aDepth = myCamera->Project (myCamera->Center()).Z();
+ Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
// camera projection coordinate are in NDC which are normalized [-1, 1]
- Standard_Real aUMin = (2.0 / aWinWidth) * Xmin - 1.0;
- Standard_Real aUMax = (2.0 / aWinWidth) * Xmax - 1.0;
- Standard_Real aVMin = (2.0 / aWinHeight) * Ymin - 1.0;
- Standard_Real aVMax = (2.0 / aWinHeight) * Ymax - 1.0;
+ Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp - 1.0;
+ Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp - 1.0;
+ Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0;
+ Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0;
// compute camera panning
gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
- gp_Pnt aPanTo = myCamera->ConvertProj2View (aFitCenter);
- gp_Pnt aPanFrom = myCamera->ConvertProj2View (aScreenCenter);
+ gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter);
+ gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
gp_Vec aPanVec (aPanFrom, aPanTo);
- gp_Pnt a1 (aUMin, aVMin, 0.0);
- gp_Pnt a2 (aUMax, aVMax, 0.0);
- gp_Pnt ap1 = myCamera->ConvertProj2View (a1);
- gp_Pnt ap2 = myCamera->ConvertProj2View (a2);
-
// compute section size
gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
- gp_Pnt aViewBotLeft = myCamera->ConvertProj2View (aFitBotLeft);
- gp_Pnt aViewTopRight = myCamera->ConvertProj2View (aFitTopRight);
+ gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
+ gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
- myCamera->BeginUpdate();
- PanCamera (aPanVec.X(), -aPanVec.Y());
- ZoomCamera (aUSize, aVSize);
+ Translate (aCamera, aPanVec.X(), -aPanVec.Y());
+ Scale (aCamera, aUSize, aVSize);
AutoZFit();
- myCamera->EndUpdate();
}
else
{
- Standard_Real x1,y1,x2,y2;
- Convert(Xmin,Ymin,x1,y1);
- Convert(Xmax,Ymax,x2,y2);
-
- FitAll(x1,y1,x2,y2);
+ Standard_Real aX1, aY1, aX2, aY2;
+ Convert (theMinXp, theMinYp, aX1, aY1);
+ Convert (theMaxXp, theMaxYp, aX2, aY2);
+ FitAll (aX1, aY1, aX2, aY2);
}
-}
-void V3d_View::SetViewMappingDefault()
-{
- MyView->SetViewMappingDefault();
+ SetImmediateUpdate (wasUpdateEnabled);
ImmediateUpdate();
}
-void V3d_View::ResetViewMapping()
-{
- MyView->ViewMappingReset();
-
- Update();
-}
-
-void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const
+//=======================================================================
+//function : ConvertToGrid
+//purpose :
+//=======================================================================
+void V3d_View::ConvertToGrid(const Standard_Integer Xp,
+ const Standard_Integer Yp,
+ Standard_Real& Xg,
+ Standard_Real& Yg,
+ Standard_Real& Zg) const
{
Graphic3d_Vertex aVrp;
Standard_Real anX, anY, aZ;
aVrp.Coord (Xg,Yg,Zg) ;
}
-void V3d_View::ConvertToGrid(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const
+//=======================================================================
+//function : ConvertToGrid
+//purpose :
+//=======================================================================
+void V3d_View::ConvertToGrid(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real Z,
+ Standard_Real& Xg,
+ Standard_Real& Yg,
+ Standard_Real& Zg) const
{
if( MyViewer->Grid()->IsActive() ) {
Graphic3d_Vertex aVrp (X,Y,Z) ;
}
}
-
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
{
Standard_Integer aDxw, aDyw ;
- V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
MyWindow->Size (aDxw, aDyw);
Standard_Real aValue;
-
- gp_Pnt aViewDims = myCamera->ViewDimensions();
+
+ gp_Pnt aViewDims = Camera()->ViewDimensions();
aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
return aValue;
}
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
+void V3d_View::Convert(const Standard_Integer Xp,
+ const Standard_Integer Yp,
+ Standard_Real& Xv,
+ Standard_Real& Yv) const
{
Standard_Integer aDxw, aDyw;
- V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
MyWindow->Size (aDxw, aDyw);
gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
- aPoint = myCamera->ConvertProj2View (aPoint);
+ aPoint = Camera()->ConvertProj2View (aPoint);
Xv = aPoint.X();
Yv = aPoint.Y();
}
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
{
- V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
Standard_Integer aDxw, aDyw;
MyWindow->Size (aDxw, aDyw);
- gp_Pnt aViewDims = myCamera->ViewDimensions();
+ gp_Pnt aViewDims = Camera()->ViewDimensions();
Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
return aValue;
}
-void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
+void V3d_View::Convert(const Standard_Real Xv,
+ const Standard_Real Yv,
+ Standard_Integer& Xp,
+ Standard_Integer& Yp) const
{
- V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
Standard_Integer aDxw, aDyw;
MyWindow->Size (aDxw, aDyw);
gp_Pnt aPoint (Xv, Yv, 0.0);
- aPoint = myCamera->ConvertView2Proj (aPoint);
+ aPoint = Camera()->ConvertView2Proj (aPoint);
aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
Xp = RealToInt (aPoint.X());
Yp = RealToInt (aPoint.Y());
}
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
-{
- V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
+void V3d_View::Convert(const Standard_Integer Xp,
+ const Standard_Integer Yp,
+ Standard_Real& X,
+ Standard_Real& Y,
+ Standard_Real& Z) const
+{
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
Standard_Integer aHeight, aWidth;
MyWindow->Size (aWidth, aHeight);
Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0;
Standard_Real aZ = 2.0 * 0.0 - 1.0;
- gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+ gp_Pnt aResult = Camera()->UnProject (gp_Pnt (anX, anY, aZ));
X = aResult.X();
Y = aResult.Y();
Z = aResult.Z();
-
- Graphic3d_Vertex aVrp;
- aVrp.SetCoord (X, Y, Z);
-
- if( MyViewer->Grid()->IsActive() ) {
- Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
- aNewVrp.Coord (X, Y, Z) ;
- }
}
-void V3d_View::ConvertWithProj(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
-{
- V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+//=======================================================================
+//function : ConvertWithProj
+//purpose :
+//=======================================================================
+void V3d_View::ConvertWithProj(const Standard_Integer Xp,
+ const Standard_Integer Yp,
+ Standard_Real& X,
+ Standard_Real& Y,
+ Standard_Real& Z,
+ Standard_Real& Dx,
+ Standard_Real& Dy,
+ Standard_Real& Dz) const
+{
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
Standard_Integer aHeight, aWidth;
MyWindow->Size (aWidth, aHeight);
Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0;
Standard_Real aZ = 2.0 * 0.0 - 1.0;
- gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_Pnt aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
X = aResult.X();
Y = aResult.Y();
Graphic3d_Vertex aVrp;
aVrp.SetCoord (X, Y, Z);
- aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
+ aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
- Dx = X - aResult.X();
- Dy = Y - aResult.Y();
- Dz = Z - aResult.Z();
+ Graphic3d_Vec3d aNormDir;
+ aNormDir.x() = X - aResult.X();
+ aNormDir.y() = Y - aResult.Y();
+ aNormDir.z() = Z - aResult.Z();
+ aNormDir.Normalize();
- if( MyViewer->Grid()->IsActive() ) {
- Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
- aNewVrp.Coord (X, Y, Z) ;
- }
+ Dx = aNormDir.x();
+ Dy = aNormDir.y();
+ Dz = aNormDir.z();
}
-void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const
-{
- V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+//=======================================================================
+//function : Convert
+//purpose :
+//=======================================================================
+void V3d_View::Convert(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real Z,
+ Standard_Integer& Xp,
+ Standard_Integer& Yp) const
+{
+ V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
Standard_Integer aHeight, aWidth;
MyWindow->Size (aWidth, aHeight);
- gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z));
+ gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
- Yp = RealToInt ((aPoint.Y() + 1) * 0.5 * aHeight);
+ Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
+}
+
+//=======================================================================
+//function : Project
+//purpose :
+//=======================================================================
+void V3d_View::Project (const Standard_Real theX,
+ const Standard_Real theY,
+ const Standard_Real theZ,
+ Standard_Real& theXp,
+ Standard_Real& theYp) const
+{
+ Standard_Real aZp;
+ Project (theX, theY, theZ, theXp, theYp, aZp);
}
-void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
+//=======================================================================
+//function : Project
+//purpose :
+//=======================================================================
+void V3d_View::Project (const Standard_Real theX,
+ const Standard_Real theY,
+ const Standard_Real theZ,
+ Standard_Real& theXp,
+ Standard_Real& theYp,
+ Standard_Real& theZp) const
{
- Standard_Real Zp;
- MyView->Projects (X, Y, Z, Xp, Yp, Zp);
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
+ Standard_Real aXSize = aViewSpaceDimensions.X();
+ Standard_Real aYSize = aViewSpaceDimensions.Y();
+ Standard_Real aZSize = aViewSpaceDimensions.Z();
+
+ gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
+
+ // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
+ theXp = aPoint.X() * aXSize * 0.5;
+ theYp = aPoint.Y() * aYSize * 0.5;
+ theZp = aPoint.Z() * aZSize * 0.5;
}
-void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const
+//=======================================================================
+//function : BackgroundColor
+//purpose :
+//=======================================================================
+void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
+ Standard_Real& V1,
+ Standard_Real& V2,
+ Standard_Real& V3) const
{
Quantity_Color C = BackgroundColor() ;
C.Values(V1,V2,V3,Type) ;
}
+//=======================================================================
+//function : BackgroundColor
+//purpose :
+//=======================================================================
Quantity_Color V3d_View::BackgroundColor() const
{
- return MyBackground.Color() ;
+ return myView->Background().Color() ;
}
-void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const
+//=======================================================================
+//function : GradientBackgroundColors
+//purpose :
+//=======================================================================
+void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
{
- MyGradientBackground.Colors(Color1, Color2);
+ myView->GradientBackground().Colors (theColor1, theColor2);
}
+//=======================================================================
+//function : GradientBackground
+//purpose :
+//=======================================================================
Aspect_GradientBackground V3d_View::GradientBackground() const
{
- return MyGradientBackground;
+ return myView->GradientBackground();
}
+//=======================================================================
+//function : Scale
+//purpose :
+//=======================================================================
Standard_Real V3d_View::Scale() const
{
- Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
-
- Standard_Real aCameraScale;
-
- // Strange behavior for the sake of compatibility.
- if (!aDefaultCamera.IsNull())
- {
- Standard_Real aDefaultScale = aDefaultCamera->Scale();
- aCameraScale = aDefaultScale / myCamera->Scale();
- }
- else
- {
- aCameraScale = myCamera->Scale();
- }
-
- return aCameraScale;
+ return myDefaultCamera->Scale() / Camera()->Scale();
}
+//=======================================================================
+//function : AxialScale
+//purpose :
+//=======================================================================
void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
{
- gp_Pnt anAxialScale = myCamera->AxialScale();
+ gp_Pnt anAxialScale = Camera()->AxialScale();
Sx = anAxialScale.X();
Sy = anAxialScale.Y();
Sz = anAxialScale.Z();
}
-void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const
-{
- gp_Pnt aCamProjShift = myCamera->ProjectionShift();
-
- Xc = -aCamProjShift.X();
- Yc = -aCamProjShift.Y();
-}
-
+//=======================================================================
+//function : Size
+//purpose :
+//=======================================================================
void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
{
- gp_Pnt aViewDims = myCamera->ViewDimensions();
+ gp_Pnt aViewDims = Camera()->ViewDimensions();
Width = aViewDims.X();
Height = aViewDims.Y();
}
+//=======================================================================
+//function : ZSize
+//purpose :
+//=======================================================================
Standard_Real V3d_View::ZSize() const
{
- gp_Pnt aViewDims = myCamera->ViewDimensions();
+ gp_Pnt aViewDims = Camera()->ViewDimensions();
return aViewDims.Z();
}
-Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const
+//=======================================================================
+//function : MinMax
+//purpose :
+//=======================================================================
+Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
+ Standard_Real& Vmin,
+ Standard_Real& Umax,
+ Standard_Real& Vmax) const
{
Standard_Real Wmin,Wmax,U,V,W ;
Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
// CAL 6/11/98
- Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+ Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
if( Nstruct ) {
- MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
- MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
- MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
- MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
+ Bnd_Box aBox = myView->MinMaxValues();
+ aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
+ Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
+ Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
+ Project (Xmin,Ymin,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
+ Project (Xmax,Ymin,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
+ Project (Xmax,Ymin,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
+ Project (Xmax,Ymax,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
+ Project (Xmin,Ymax,Zmax,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
- MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
+ Project (Xmin,Ymax,Zmin,U,V,W) ;
Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
return Nstruct ;
}
-Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const
+//=======================================================================
+//function : MinMax
+//purpose :
+//=======================================================================
+Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
+ Standard_Real& Ymin,
+ Standard_Real& Zmin,
+ Standard_Real& Xmax,
+ Standard_Real& Ymax,
+ Standard_Real& Zmax) const
{
// CAL 6/11/98
// Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
- Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+ Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
if( Nstruct ) {
- MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
+ Bnd_Box aBox = myView->MinMaxValues();
+ aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
}
return Nstruct ;
}
-Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
+//=======================================================================
+//function : Gravity
+//purpose :
+//=======================================================================
+void V3d_View::Gravity (Standard_Real& theX,
+ Standard_Real& theY,
+ Standard_Real& theZ) const
{
- Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax;
- Standard_Integer Nstruct,Npoint ;
- Graphic3d_MapOfStructure MySetOfStructures;
+ Graphic3d_MapOfStructure aSetOfStructures;
+ myView->DisplayedStructures (aSetOfStructures);
+
+ Standard_Boolean hasSelection = Standard_False;
+ for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
+ aStructIter.More(); aStructIter.Next())
+ {
+ if (aStructIter.Key()->IsHighlighted()
+ && aStructIter.Key()->IsVisible())
+ {
+ hasSelection = Standard_True;
+ break;
+ }
+ }
+
+ Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
+ Standard_Integer aNbPoints = 0;
+ gp_XYZ aResult (0.0, 0.0, 0.0);
+ for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
+ aStructIter.More(); aStructIter.Next())
+ {
+ const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+ if (!aStruct->IsVisible()
+ || (hasSelection && !aStruct->IsHighlighted())
+ || aStruct->IsEmpty())
+ {
+ continue;
+ }
+
+ Bnd_Box aBox = aStruct->MinMaxValues();
+ if (aBox.IsVoid() || aStruct->IsInfinite())
+ {
+ continue;
+ }
- MyView->DisplayedStructures (MySetOfStructures);
- Nstruct = MySetOfStructures.Extent() ;
+ // use camera projection to find gravity point
+ aBox.Get (Xmin, Ymin, Zmin,
+ Xmax, Ymax, Zmax);
+ gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
+ {
+ gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
+ gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
+ gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
+ gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
+ };
- Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
+ for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
+ {
+ const gp_Pnt& aBndPnt = aPnts[aPntIt];
+ const gp_Pnt aProjected = Camera()->Project (aBndPnt);
+ if (Abs (aProjected.X()) <= 1.0
+ && Abs (aProjected.Y()) <= 1.0)
+ {
+ aResult += aBndPnt.XYZ();
+ ++aNbPoints;
+ }
+ }
+ }
- Npoint = 0 ; X = Y = Z = 0. ;
- for (; MyIterator.More(); MyIterator.Next())
+ if (aNbPoints == 0)
{
- const Handle(Graphic3d_Structure)& aStruct = MyIterator.Key();
- if (!aStruct->IsEmpty())
+ for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
+ aStructIter.More(); aStructIter.Next())
{
- aStruct->MinMaxValues (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+ const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+ if (aStruct->IsEmpty())
+ {
+ continue;
+ }
- // use camera projection to find gravity point
- gp_Pnt aPnts[8] = {
+ Bnd_Box aBox = aStruct->MinMaxValues();
+ if (aBox.IsVoid() || aStruct->IsInfinite())
+ {
+ continue;
+ }
+
+ aBox.Get (Xmin, Ymin, Zmin,
+ Xmax, Ymax, Zmax);
+ gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
+ {
gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
- gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax) };
+ gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
+ };
- for (Standard_Integer aPntIt = 0; aPntIt < 8; ++aPntIt)
+ for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
{
const gp_Pnt& aBndPnt = aPnts[aPntIt];
-
- gp_Pnt aProjected = myCamera->Project (aBndPnt);
- const Standard_Real& U = aProjected.X();
- const Standard_Real& V = aProjected.Y();
- if (Abs(U) <= 1.0 && Abs(V) <= 1.0)
- {
- Npoint++;
- X += aBndPnt.X();
- Y += aBndPnt.Y();
- Z += aBndPnt.Z();
- }
+ aResult += aBndPnt.XYZ();
+ ++aNbPoints;
}
}
}
- if( Npoint > 0 ) {
- X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
- }
- return Nstruct ;
+ if (aNbPoints > 0)
+ {
+ aResult /= aNbPoints;
+ }
+ theX = aResult.X();
+ theY = aResult.Y();
+ theZ = aResult.Z();
}
+//=======================================================================
+//function : Eye
+//purpose :
+//=======================================================================
void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
{
- gp_Pnt aCameraEye = myCamera->Eye();
+ gp_Pnt aCameraEye = Camera()->Eye();
X = aCameraEye.X();
Y = aCameraEye.Y();
Z = aCameraEye.Z();
}
+//=============================================================================
+//function : FocalReferencePoint
+//purpose :
+//=============================================================================
void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const
{
Eye (X,Y,Z);
}
-void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, const Standard_Integer Ypix, Standard_Real& XP, Standard_Real& YP, Standard_Real& ZP, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ) const
+//=============================================================================
+//function : ProjReferenceAxe
+//purpose :
+//=============================================================================
+void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
+ const Standard_Integer Ypix,
+ Standard_Real& XP,
+ Standard_Real& YP,
+ Standard_Real& ZP,
+ Standard_Real& VX,
+ Standard_Real& VY,
+ Standard_Real& VZ) const
{
Standard_Real Xo,Yo,Zo;
}
}
+//=============================================================================
+//function : Depth
+//purpose :
+//=============================================================================
Standard_Real V3d_View::Depth() const
{
- return myCamera->Distance();
+ return Camera()->Distance();
}
+//=============================================================================
+//function : Proj
+//purpose :
+//=============================================================================
void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
{
- gp_Dir aCameraDir = myCamera->Direction().Reversed();
+ gp_Dir aCameraDir = Camera()->Direction().Reversed();
Dx = aCameraDir.X();
Dy = aCameraDir.Y();
Dz = aCameraDir.Z();
}
+//=============================================================================
+//function : At
+//purpose :
+//=============================================================================
void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
{
- gp_Pnt aCameraCenter = myCamera->Center();
+ gp_Pnt aCameraCenter = Camera()->Center();
X = aCameraCenter.X();
Y = aCameraCenter.Y();
Z = aCameraCenter.Z();
}
+//=============================================================================
+//function : Up
+//purpose :
+//=============================================================================
void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
{
- gp_Dir aCameraUp = myCamera->Up();
+ gp_Dir aCameraUp = Camera()->Up();
Vx = aCameraUp.X();
Vy = aCameraUp.Y();
Vz = aCameraUp.Z();
}
+//=============================================================================
+//function : Twist
+//purpose :
+//=============================================================================
Standard_Real V3d_View::Twist() const
{
Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
Graphic3d_Vector Xaxis,Yaxis,Zaxis ;
Standard_Boolean TheStatus ;
- gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+ gp_Dir aReferencePlane (Camera()->Direction().Reversed());
gp_Dir anUp;
Proj(Xpn,Ypn,Zpn);
return angle ;
}
+//=============================================================================
+//function : ShadingModel
+//purpose :
+//=============================================================================
V3d_TypeOfShadingModel V3d_View::ShadingModel() const
{
- V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
- return SM ;
+ return static_cast<V3d_TypeOfShadingModel> (myView->ShadingModel());
}
+//=============================================================================
+//function : SurfaceDetail
+//purpose :
+//=============================================================================
V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const
{
- V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
- return SM ;
+ return static_cast<V3d_TypeOfSurfaceDetail> (myView->SurfaceDetailType());
}
-Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const
+//=============================================================================
+//function : TextureEnv
+//purpose :
+//=============================================================================
+Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
{
- Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
- return SM ;
+ return myView->TextureEnv();
}
+//=============================================================================
+//function : Visualization
+//purpose :
+//=============================================================================
V3d_TypeOfVisualization V3d_View::Visualization() const
{
- V3d_TypeOfVisualization V =
- (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
- return V ;
+ return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
}
+//=============================================================================
+//function : Antialiasing
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::Antialiasing() const
{
- Standard_Boolean A = MyViewContext.AliasingIsOn() ;
- return A ;
+ return myView->IsAntialiasingEnabled();
}
+//=============================================================================
+//function : Viewer
+//purpose :
+//=============================================================================
Handle(V3d_Viewer) V3d_View::Viewer() const
{
- return MyViewer ;
+ return MyViewer;
}
+//=============================================================================
+//function : IfWindow
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::IfWindow() const
{
- Standard_Boolean TheStatus = MyView->IsDefined() ;
- return TheStatus ;
+ return myView->IsDefined();
}
+//=============================================================================
+//function : Window
+//purpose :
+//=============================================================================
Handle(Aspect_Window) V3d_View::Window() const
{
return MyWindow;
}
+//=============================================================================
+//function : Type
+//purpose :
+//=============================================================================
V3d_TypeOfView V3d_View::Type() const
{
- return myCamera->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
+ return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
}
+//=============================================================================
+//function : SetFocale
+//purpose :
+//=============================================================================
void V3d_View::SetFocale( const Standard_Real focale )
{
- if (myCamera->IsOrthographic())
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ if (aCamera->IsOrthographic())
{
return;
}
- Standard_Real aFOVyRad = ATan (focale / (myCamera->Distance() * 2.0));
+ Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
- myCamera->SetFOVy (aFOVyRad * (360 / M_PI));
+ aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
ImmediateUpdate();
}
+//=============================================================================
+//function : Focale
+//purpose :
+//=============================================================================
Standard_Real V3d_View::Focale() const
{
- if (myCamera->IsOrthographic())
- {
- return 0.0;
- }
-
- return myCamera->Distance() * 2.0 * Tan(myCamera->FOVy() * M_PI / 360.0);
-}
-
-void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
- const Standard_Real Bottom, const Standard_Real Top,
- const Standard_Real ZNear, const Standard_Real ZFar)
-{
- V3d_BadValue_Raise_if (ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
+ Handle(Graphic3d_Camera) aCamera = Camera();
-
- myCamera->BeginUpdate();
-
- myCamera->SetZFar (ZFar);
- myCamera->SetZNear (ZNear);
-
- myCamera->SetScale (Top - Bottom);
- myCamera->SetAspect ((Right - Left) / (Top - Bottom));
- gp_Pnt aCameraProjShift (-(Left + Right) / 2.0, -(Bottom + Top) / 2.0, 0.0);
- myCamera->SetProjectionShift (aCameraProjShift);
- if (myCamera->IsOrthographic())
+ if (aCamera->IsOrthographic())
{
- myCamera->SetDistance (Abs (ZNear));
+ return 0.0;
}
- AutoZFit();
- myCamera->EndUpdate();
- ImmediateUpdate();
+ return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
}
-Handle(Visual3d_View) V3d_View::View() const
+//=============================================================================
+//function : View
+//purpose :
+//=============================================================================
+Handle(Graphic3d_CView) V3d_View::View() const
{
- return MyView ;
+ return myView;
}
+//=============================================================================
+//function : ScreenAxis
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::ScreenAxis( const gp_Dir &Vpn, const gp_Dir &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe)
{
Standard_Real Xpn, Ypn, Zpn, Xup, Yup, Zup;
return Standard_True;
}
+//=============================================================================
+//function : TrsPoint
+//purpose :
+//=============================================================================
Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix )
{
Graphic3d_Vertex PP ;
return PP ;
}
-void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor)
+//=======================================================================
+//function : Pan
+//purpose :
+//=======================================================================
+void V3d_View::Pan (const Standard_Integer theDXp,
+ const Standard_Integer theDYp,
+ const Quantity_Factor theZoomFactor,
+ const Standard_Boolean theToStart)
{
- Panning (Convert(Dx), Convert(Dy), aZoomFactor, Standard_True);
+ Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
}
-void V3d_View::Zoom (const Standard_Integer X1,
- const Standard_Integer Y1,
- const Standard_Integer X2,
- const Standard_Integer Y2)
+//=======================================================================
+//function : Panning
+//purpose :
+//=======================================================================
+void V3d_View::Panning (const Standard_Real theDXv,
+ const Standard_Real theDYv,
+ const Quantity_Factor theZoomFactor,
+ const Standard_Boolean theToStart)
{
+ Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
+
+ Handle(Graphic3d_Camera) aCamera = Camera();
- Standard_Real dx = Standard_Real (X2-X1);
- Standard_Real dy = Standard_Real (Y2-Y1);
- if ( dx != 0. || dy != 0. ) {
- Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
- dzoom = (dx > 0) ? dzoom : 1./dzoom;
- SetZoom(dzoom, Standard_True);
+ if (theToStart)
+ {
+ myCamStartOpEye = aCamera->Eye();
+ myCamStartOpCenter = aCamera->Center();
}
+
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+ gp_Pnt aViewDims = aCamera->ViewDimensions();
+
+ aCamera->SetEye (myCamStartOpEye);
+ aCamera->SetCenter (myCamStartOpCenter);
+ Translate (aCamera, -theDXv, -theDYv);
+ Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
+
+ SetImmediateUpdate (wasUpdateEnabled);
+
+ ImmediateUpdate();
}
-void V3d_View::Zoom (const Standard_Integer X1,
- const Standard_Integer Y1)
-{
- Standard_Real x,y;
- Center(x,y);
- Standard_Integer ix,iy;
- Convert(x,y,ix,iy);
- Zoom(ix,iy,X1,Y1);
+//=======================================================================
+//function : Zoom
+//purpose :
+//=======================================================================
+void V3d_View::Zoom (const Standard_Integer theXp1,
+ const Standard_Integer theYp1,
+ const Standard_Integer theXp2,
+ const Standard_Integer theYp2)
+{
+ Standard_Integer aDx = theXp2 - theXp1;
+ Standard_Integer aDy = theYp2 - theYp1;
+ if (aDx != 0 || aDy != 0)
+ {
+ Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0;
+ aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff;
+ SetZoom (aCoeff, Standard_True);
+ }
}
-// Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
-void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
+//=======================================================================
+//function : StartZoomAtPoint
+//purpose :
+//=======================================================================
+void V3d_View::StartZoomAtPoint (const Standard_Integer theXp,
+ const Standard_Integer theYp)
{
- MyZoomAtPointX = xpix;
- MyZoomAtPointY = ypix;
+ MyZoomAtPointX = theXp;
+ MyZoomAtPointY = theYp;
}
-// Zooms the model at a pixel defined by the method StartZoomAtPoint().
-void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
- const Standard_Integer mouseStartY,
- const Standard_Integer mouseEndX,
- const Standard_Integer mouseEndY)
+//=======================================================================
+//function : ZoomAtPoint
+//purpose :
+//=======================================================================
+void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
+ const Standard_Integer theMouseStartY,
+ const Standard_Integer theMouseEndX,
+ const Standard_Integer theMouseEndY)
{
- Standard_Boolean update;
- V3d_Coordinate X0, Y0, XS, YS;
+ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
- // Forbid any update.
- update = SetImmediateUpdate(Standard_False);
+ // zoom
+ Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY));
+ Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0;
+ aDZoom = (aDxy > 0.0) ? aDZoom : 1.0 / aDZoom;
- // Get center point
- Center(X0, Y0);
+ V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
- // Pan the point to the center of window.
- Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
- Panning(X0-XS, Y0-YS);
+ Handle(Graphic3d_Camera) aCamera = Camera();
- // Zoom
- Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
+ Standard_Real aViewWidth = aCamera->ViewDimensions().X();
+ Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
- Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
- dzoom = (d > 0) ? dzoom : 1.0 / dzoom;
- V3d_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
+ // ensure that zoom will not be too small or too big.
+ Standard_Real aCoef = aDZoom;
+ if (aViewWidth < aCoef * Precision::Confusion())
+ {
+ aCoef = aViewWidth / Precision::Confusion();
+ }
+ else if (aViewWidth > aCoef * 1e12)
+ {
+ aCoef = aViewWidth / 1e12;
+ }
+ if (aViewHeight < aCoef * Precision::Confusion())
+ {
+ aCoef = aViewHeight / Precision::Confusion();
+ }
+ else if (aViewHeight > aCoef * 1e12)
+ {
+ aCoef = aViewHeight / 1e12;
+ }
- Standard_Real aViewWidth = myCamera->ViewDimensions().X();
- Standard_Real aViewHeight = myCamera->ViewDimensions().Y();
+ Standard_Real aZoomAtPointXv = 0.0;
+ Standard_Real aZoomAtPointYv = 0.0;
+ Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv);
- // Ensure that zoom will not be too small or too big.
- Standard_Real coef = dzoom;
- if (aViewWidth < coef * Precision::Confusion())
- {
- coef = aViewWidth / Precision::Confusion();
- }
- else if (aViewWidth > coef * 1e12)
- {
- coef = aViewWidth / 1e12;
- }
- if (aViewHeight < coef * Precision::Confusion())
- {
- coef = aViewHeight / Precision::Confusion();
- }
- else if (aViewHeight > coef * 1e12)
- {
- coef = aViewHeight / 1e12;
- }
+ V3d_Coordinate aDxv = aZoomAtPointXv / aCoef;
+ V3d_Coordinate aDyv = aZoomAtPointYv / aCoef;
- V3d_Coordinate Dxv = (XS - X0) / coef;
- V3d_Coordinate Dyv = (YS - Y0) / coef;
+ aCamera->SetScale (aCamera->Scale() / aCoef);
+ Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
- myCamera->SetScale (myCamera->Scale() / coef);
- PanCamera (-Dxv, -Dyv);
+ AutoZFit();
- AutoZFit();
+ SetImmediateUpdate (wasUpdateEnabled);
- // Update the view.
- SetImmediateUpdate(update);
- ImmediateUpdate();
+ ImmediateUpdate();
}
+//=============================================================================
+//function : AxialScale
+//purpose :
+//=============================================================================
void V3d_View::AxialScale (const Standard_Integer Dx,
const Standard_Integer Dy,
const V3d_TypeOfAxe Axis)
}
}
-
+//=============================================================================
+//function : FitAll
+//purpose :
+//=============================================================================
void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
const Standard_Real Xmin,
const Standard_Real Ymin,
const Standard_Real Xmax,
const Standard_Real Ymax)
{
- // normalize view coordinates
Standard_Integer aWinWidth, aWinHeight;
aWindow->Size (aWinWidth, aWinHeight);
- // compute camera panning
- gp_Vec aPanVec ((Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5, 0.0);
-
- // compute section size
- gp_Pnt aViewBotLeft (Xmin, Ymin, 0.0);
- gp_Pnt aViewTopRight (Xmax, Ymax, 0.0);
+ Standard_Real aWinAspect = (Standard_Real)aWinWidth / aWinHeight;
+ Standard_Real aFitSizeU = Abs (Xmax - Xmin);
+ Standard_Real aFitSizeV = Abs (Ymax - Ymin);
+ Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
+ if (aFitAspect >= aWinAspect)
+ {
+ aFitSizeV = aFitSizeU / aWinAspect;
+ }
+ else
+ {
+ aFitSizeU = aFitSizeV * aWinAspect;
+ }
- Standard_Real aUSize = Abs (Xmax - Xmin);
- Standard_Real aVSize = Abs (Ymax - Ymin);
+ Handle(Graphic3d_Camera) aCamera = Camera();
- myCamera->BeginUpdate();
- myCamera->SetProjectionShift (gp_Pnt (0.0, 0.0, 0.0));
- PanCamera (aPanVec.X(), aPanVec.Y());
- ZoomCamera (aUSize, aVSize);
- myCamera->EndUpdate();
+ aCamera->SetAspect (aWinAspect);
+ Translate (aCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5);
+ Scale (aCamera, aFitSizeU, aFitSizeV);
AutoZFit();
- Update();
+ ImmediateUpdate();
}
-#ifdef IMP250900
+//=============================================================================
+//function : StartRotation
+//purpose :
+//=============================================================================
static Standard_Boolean zRotation = Standard_False;
-#endif
void V3d_View::StartRotation(const Standard_Integer X,
const Standard_Integer Y,
const Quantity_Ratio zRotationThreshold)
ry = Standard_Real(Convert(y));
Gravity(gx,gy,gz);
Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
-#ifdef IMP250900
zRotation = Standard_False;
if( zRotationThreshold > 0. ) {
Standard_Real dx = Abs(sx - rx/2.);
Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
if( dx > dd || dy > dd ) zRotation = Standard_True;
}
-#endif
}
+//=============================================================================
+//function : Rotation
+//purpose :
+//=============================================================================
void V3d_View::Rotation(const Standard_Integer X,
const Standard_Integer Y)
{
-#ifdef IMP210600
if( rx == 0. || ry == 0. ) {
StartRotation(X,Y);
return;
}
-#endif
-#ifdef IMP250900
Standard_Real dx=0.,dy=0.,dz=0.;
if( zRotation ) {
dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
dx = (Standard_Real(X) - sx) * M_PI / rx;
dy = (sy - Standard_Real(Y)) * M_PI / ry;
}
+
Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
-#else
- Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
- Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
- Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
-#endif
-#ifdef IMP020300
- if( !myImmediateUpdate ) Update();
-#else
- myImmediateUpdate = Standard_False;
- Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
- ZFitAll (Zmargin); //Don't do that, perf improvment
- myImmediateUpdate = Standard_True;
- ImmediateUpdate();
-#endif
}
-void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
+//=============================================================================
+//function : SetComputedMode
+//purpose :
+//=============================================================================
+void V3d_View::SetComputedMode (const Standard_Boolean theMode)
{
- if( aMode ) {
- if( myComputedMode ) {
- MyView -> SetComputedMode ( Standard_True );
- Update ();
+ if (theMode)
+ {
+ if (myComputedMode)
+ {
+ myView->SetComputedMode (Standard_True);
+ Update();
}
- } else {
- MyView -> SetComputedMode ( Standard_False );
- Update ();
+ }
+ else
+ {
+ myView->SetComputedMode (Standard_False);
+ Update();
}
}
-Standard_Boolean V3d_View :: ComputedMode () const
+//=============================================================================
+//function : ComputedMode
+//purpose :
+//=============================================================================
+Standard_Boolean V3d_View::ComputedMode() const
{
- return MyView -> ComputedMode ();
+ return myView->ComputedMode();
}
-void V3d_View :: SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
+//=============================================================================
+//function : SetBackFacingModel
+//purpose :
+//=============================================================================
+void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel theModel)
{
- MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
+ myView->SetBackfacingModel (static_cast<Graphic3d_TypeOfBackfacingModel> (theModel));
Redraw();
}
-V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const
-{
- return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
-}
-
-Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const
-{
- return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
-}
-
-void V3d_View::TransientManagerClearDraw() const
-{
- Visual3d_TransientManager::ClearDraw(MyView);
-}
-
-Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const
+//=============================================================================
+//function : BackFacingModel
+//purpose :
+//=============================================================================
+V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
{
- return Visual3d_TransientManager::BeginAddDraw(MyView);
+ return static_cast<V3d_TypeOfBackfacingModel> (myView->BackfacingModel());
}
+//=============================================================================
+//function : Init
+//purpose :
+//=============================================================================
void V3d_View::Init()
{
myComputedMode = MyViewer->ComputedMode();
- if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
- SetComputedMode(Standard_False);
+ if (!myComputedMode || !MyViewer->DefaultComputedMode())
+ {
+ SetComputedMode (Standard_False);
}
}
-void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter)
-{
- MyPlotter = aPlotter;
-}
-
-void V3d_View::Plot()
+//=============================================================================
+//function : Export
+//purpose :
+//=============================================================================
+Standard_Boolean V3d_View::Export (const Standard_CString theFileName,
+ const Graphic3d_ExportFormat theFormat,
+ const Graphic3d_SortType theSortType)
{
- V3d_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
- MyView->Plot(MyPlotter);
+ return myView->Export (theFileName, theFormat, theSortType);
}
-#include <Aspect.hxx>
-#include <Visual3d_Layer.hxx>
-
-////////////////////////////////////////////////////////////////
+//=============================================================================
+//function : Dump
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
const Graphic3d_BufferType& theBufferType)
{
return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
}
-////////////////////////////////////////////////////////////////
+//=============================================================================
+//function : ToPixMap
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
const Standard_Integer theWidth,
const Standard_Integer theHeight,
const Graphic3d_BufferType& theBufferType,
- const Standard_Boolean theIsForceCentred,
+ const Standard_Boolean theToKeepAspect,
const V3d_StereoDumpOptions theStereoOptions)
{
- Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
-
// always prefer hardware accelerated offscreen buffer
Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
- Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
+ Graphic3d_PtrFrameBuffer aPrevFBOPtr = myView->FBO();
Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0);
Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
if (aPrevFBOPtr != NULL)
{
- MyView->FBOGetDimensions (aPrevFBOPtr,
+ myView->FBOGetDimensions (aPrevFBOPtr,
aPrevFBOVPSizeX, aPrevFBOVPSizeY,
aPrevFBOSizeXMax, aPrevFBOSizeYMax);
if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax)
{
- MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
+ myView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
aFBOPtr = aPrevFBOPtr;
}
}
if (aFBOPtr == NULL)
{
// Try to create hardware accelerated buffer
- aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
+ aFBOPtr = myView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
if (aFBOPtr != NULL)
{
- MyView->FBOGetDimensions (aFBOPtr,
+ myView->FBOGetDimensions (aFBOPtr,
aFBOVPSizeX, aFBOVPSizeY,
aFBOSizeXMax, aFBOSizeYMax);
// reduce viewport in case of hardware limits
if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax;
if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax;
- MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
+ myView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
}
}
- cView->ptrFBO = aFBOPtr;
+ myView->SetFBO (aFBOPtr);
// If hardware accelerated buffer - try to use onscreen buffer
// Results may be bad!
Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
- aStoreMapping->Copy (myCamera);
- Standard_Real Umin, Vmin, Umax, Vmax;
+ Handle(Graphic3d_Camera) aCamera = Camera();
+
+ aStoreMapping->Copy (aCamera);
- if (myCamera->IsStereo())
+ if (aCamera->IsStereo())
{
switch (theStereoOptions)
{
- case V3d_SDO_MONO :
- myCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+ case V3d_SDO_MONO:
+ {
+ aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
break;
-
- case V3d_SDO_LEFT_EYE :
- myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
+ }
+ case V3d_SDO_LEFT_EYE:
+ {
+ aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
break;
-
- case V3d_SDO_RIGHT_EYE :
- myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
+ }
+ case V3d_SDO_RIGHT_EYE:
+ {
+ aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
break;
+ }
+ case V3d_SDO_BLENDED:
+ {
+ break; // dump as is
+ }
}
}
- if (theIsForceCentred)
- {
- Standard_Real PUmin, PVmin, PUmax, PVmax;
- myCamera->WindowLimit (PUmin, PVmin, PUmax, PVmax);
-
- // calculate expansion
- Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
- Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
- Standard_Real newWidth = (oldHeight * aFBOVPSizeX) / aFBOVPSizeY;
- if (newWidth < oldWidth)
- {
- Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX;
- // Expand height
- Standard_Real delta = 0.5 * (newHeight - oldHeight);
- Vmin = PVmin - delta;
- Vmax = PVmax + delta;
- }
- else
- {
- // Expand width
- Standard_Real delta = 0.5 * (newWidth - oldWidth);
- Umin = PUmin - delta;
- Umax = PUmax + delta;
- }
+ // render immediate structures into back buffer rather than front
+ const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
- FitAll (Umin, Vmin, Umax, Vmax);
- }
+ const Standard_Boolean toAutoUpdate = myImmediateUpdate;
+ myImmediateUpdate = Standard_False;
+ AutoZFit();
+ myImmediateUpdate = toAutoUpdate;
- //workaround for rendering list of Over and Under Layers
- if (!MyLayerMgr.IsNull())
+ if (theToKeepAspect)
{
- MyLayerMgr->Compute();
+ aCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY);
}
- // render immediate structures into back buffer rather than front
- Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver());
- const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False);
Redraw();
- if (!aDriver.IsNull())
- {
- aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode);
- }
+ myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
- myCamera->Copy (aStoreMapping);
+ aCamera->Copy (aStoreMapping);
Standard_Boolean isSuccess = Standard_True;
isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY);
}
- isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType);
+ isSuccess = isSuccess && myView->BufferDump (theImage, theBufferType);
// FBO now useless, free resources
if (aFBOPtr != aPrevFBOPtr)
{
- MyView->FBORelease (aFBOPtr);
+ myView->FBORelease (aFBOPtr);
}
else if (aPrevFBOPtr != NULL)
{
- MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
+ myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
}
- cView->ptrFBO = aPrevFBOPtr;
+ myView->SetFBO (aPrevFBOPtr);
+
return isSuccess;
}
+//=============================================================================
+//function : ImmediateUpdate
+//purpose :
+//=============================================================================
void V3d_View::ImmediateUpdate() const
{
- if (myImmediateUpdate) Update();
+ if (myImmediateUpdate)
+ {
+ Update();
+ }
}
+//=============================================================================
+//function : SetImmediateUpdate
+//purpose :
+//=============================================================================
Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
{
Standard_Boolean aPreviousMode = myImmediateUpdate;
// =======================================================================
void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
{
- myCamera = theCamera;
+ myView->SetCamera (theCamera);
- MyView->SetCamera (theCamera);
+ ImmediateUpdate();
}
// =======================================================================
// function : GetCamera
// purpose :
// =======================================================================
-Handle(Graphic3d_Camera) V3d_View::Camera() const
+const Handle(Graphic3d_Camera)& V3d_View::Camera() const
{
- return myCamera;
+ return myView->Camera();
}
// =======================================================================
-// function : FitCamera
-// purpose :
+// function : FitMinMax
+// purpose : Internal
// =======================================================================
-void V3d_View::FitCamera (const Standard_Real theXmin,
- const Standard_Real theYmin,
- const Standard_Real theZmin,
- const Standard_Real theXmax,
- const Standard_Real theYmax,
- const Standard_Real theZmax)
-{
- if (myCamera.IsNull())
- return;
+Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
+ const Bnd_Box& theBox,
+ const Standard_Real theMargin,
+ const Standard_Real theResolution,
+ const Standard_Boolean theToEnlargeIfLine) const
+{
+ // Check bounding box for validness
+ if (theBox.IsVoid())
+ {
+ return Standard_False; // bounding box is out of bounds...
+ }
- // check bounding box for validness
- Standard_Real aLim = (ShortRealLast() - 1.0);
- if (Abs (theXmin) > aLim || Abs (theYmin) > aLim || Abs (theZmin) > aLim ||
- Abs (theXmax) > aLim || Abs (theYmax) > aLim || Abs (theZmax) > aLim)
- return;
+ // Apply "axial scaling" to the bounding points.
+ // It is not the best approach to make this scaling as a part of fit all operation,
+ // but the axial scale is integrated into camera orientation matrix and the other
+ // option is to perform frustum plane adjustment algorithm in view camera space,
+ // which will lead to a number of additional world-view space conversions and
+ // loosing precision as well.
+ gp_Pnt aBndMin = theBox.CornerMin().XYZ().Multiplied (theCamera->AxialScale());
+ gp_Pnt aBndMax = theBox.CornerMax().XYZ().Multiplied (theCamera->AxialScale());
+
+ if (aBndMax.IsEqual (aBndMin, RealEpsilon()))
+ {
+ return Standard_False; // nothing to fit all
+ }
+
+ // Prepare camera frustum planes.
+ NCollection_Array1<gp_Pln> aFrustumPlane (1, 6);
+ theCamera->Frustum (aFrustumPlane.ChangeValue (1),
+ aFrustumPlane.ChangeValue (2),
+ aFrustumPlane.ChangeValue (3),
+ aFrustumPlane.ChangeValue (4),
+ aFrustumPlane.ChangeValue (5),
+ aFrustumPlane.ChangeValue (6));
+
+ // Prepare camera up, side, direction vectors.
+ gp_Dir aCamUp = theCamera->OrthogonalizedUp();
+ gp_Dir aCamDir = theCamera->Direction();
+ gp_Dir aCamSide = aCamDir ^ aCamUp;
+
+ // Prepare scene bounding box parameters.
+ gp_Pnt aBndCenter = (aBndMin.XYZ() + aBndMax.XYZ()) / 2.0;
+
+ NCollection_Array1<gp_Pnt> aBndCorner (1, 8);
+ aBndCorner.ChangeValue (1) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMin.Z());
+ aBndCorner.ChangeValue (2) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMax.Z());
+ aBndCorner.ChangeValue (3) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMin.Z());
+ aBndCorner.ChangeValue (4) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMax.Z());
+ aBndCorner.ChangeValue (5) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMin.Z());
+ aBndCorner.ChangeValue (6) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMax.Z());
+ aBndCorner.ChangeValue (7) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMin.Z());
+ aBndCorner.ChangeValue (8) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMax.Z());
+
+ // Perspective-correct camera projection vector, matching the bounding box is determined geometrically.
+ // Knowing the initial shape of a frustum it is possible to match it to a bounding box.
+ // Then, knowing the relation of camera projection vector to the frustum shape it is possible to
+ // set up perspective-correct camera projection matching the bounding box.
+ // These steps support non-asymmetric transformations of view-projection space provided by camera.
+ // The zooming can be done by calculating view plane size matching the bounding box at center of
+ // the bounding box. The only limitation here is that the scale of camera should define size of
+ // its view plane passing through the camera center, and the center of camera should be on the
+ // same line with the center of bounding box.
+
+ // The following method is applied:
+ // 1) Determine normalized asymmetry of camera projection vector by frustum planes.
+ // 2) Determine new location of frustum planes, "matching" the bounding box.
+ // 3) Determine new camera projection vector using the normalized asymmetry.
+ // 4) Determine new zooming in view space.
+
+ // 1. Determine normalized projection asymmetry (if any).
+ Standard_Real anAssymX = Tan (( aCamSide).Angle (aFrustumPlane (1).Axis().Direction()))
+ - Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction()));
+ Standard_Real anAssymY = Tan (( aCamUp) .Angle (aFrustumPlane (3).Axis().Direction()))
+ - Tan ((-aCamUp) .Angle (aFrustumPlane (4).Axis().Direction()));
+
+ // 2. Determine how far should be the frustum planes placed from center
+ // of bounding box, in order to match the bounding box closely.
+ NCollection_Array1<Standard_Real> aFitDistance (1, 6);
+ aFitDistance.ChangeValue (1) = 0.0;
+ aFitDistance.ChangeValue (2) = 0.0;
+ aFitDistance.ChangeValue (3) = 0.0;
+ aFitDistance.ChangeValue (4) = 0.0;
+ aFitDistance.ChangeValue (5) = 0.0;
+ aFitDistance.ChangeValue (6) = 0.0;
+
+ for (Standard_Integer anI = aFrustumPlane.Lower(); anI <= aFrustumPlane.Upper(); ++anI)
+ {
+ // Measure distances from center of bounding box to its corners towards the frustum plane.
+ const gp_Dir& aPlaneN = aFrustumPlane.ChangeValue (anI).Axis().Direction();
- // place camera center at the geometrical center
- // of the passed bounding box
- gp_Pnt aCenter ((theXmin + theXmax) * 0.5,
- (theYmin + theYmax) * 0.5,
- (theZmin + theZmax) * 0.5);
-
- // adapt bound points
- gp_Pnt aPnts[8] =
- { gp_Pnt (theXmin, theYmin, theZmin),
- gp_Pnt (theXmin, theYmin, theZmax),
- gp_Pnt (theXmin, theYmax, theZmin),
- gp_Pnt (theXmin, theYmax, theZmax),
- gp_Pnt (theXmax, theYmin, theZmin),
- gp_Pnt (theXmax, theYmin, theZmax),
- gp_Pnt (theXmax, theYmax, theZmin),
- gp_Pnt (theXmax, theYmax, theZmax) };
-
- Standard_Real aViewMinX = (RealLast() - 1);
- Standard_Real aViewMinY = (RealLast() - 1);
- Standard_Real aViewMinZ = (RealLast() - 1);
- Standard_Real aViewMaxX = (RealFirst() + 1);
- Standard_Real aViewMaxY = (RealFirst() + 1);
- Standard_Real aViewMaxZ = (RealFirst() + 1);
-
- // find out minimum and maximum values of bounding box
- // converted to view space. the limits point out a rectangular
- // section parallel to the screen that camera should zoom in.
- for (Standard_Integer aPntIt = 0; aPntIt < 8; ++aPntIt)
- {
- gp_Pnt aView = myCamera->ConvertWorld2View (aPnts[aPntIt]);
- aViewMinX = Min (aViewMinX, aView.X());
- aViewMinY = Min (aViewMinY, aView.Y());
- aViewMaxX = Max (aViewMaxX, aView.X());
- aViewMaxY = Max (aViewMaxY, aView.Y());
- aViewMinZ = Min (aViewMinZ, aView.Z());
- aViewMaxZ = Max (aViewMaxZ, aView.Z());
- }
-
- // evaluate section size for x1 zoom.
- Standard_Real aSectU = (aViewMaxX - aViewMinX);
- Standard_Real aSectV = (aViewMaxY - aViewMinY);
-
- // zoom camera to front plane of bounding box. the camera
- // is set up at the center of bbox, so the depth is half
- // space of it in view coordinate space.
- Standard_Real aSectDepth = (aViewMaxZ - aViewMinZ) * 0.5;
-
- // re-compute Eye position
- gp_Vec aBck = gp_Vec (myCamera->Center(), myCamera->Eye());
- gp_Pnt aEye = aCenter.Translated (aBck);
-
- // start camera updates
- myCamera->BeginUpdate();
-
- if (myCamera->IsOrthographic())
- {
- Standard_Real anX = (aViewMaxX + aViewMinX) * 0.5;
- Standard_Real anY = (aViewMaxY + aViewMinY) * 0.5;
- myCamera->SetProjectionShift (gp_Pnt (-anX, -anY, 0.0));
+ Standard_Real& aFitDist = aFitDistance.ChangeValue (anI);
+
+ for (Standard_Integer aJ = aBndCorner.Lower(); aJ <= aBndCorner.Upper(); ++aJ)
+ {
+ aFitDist = Max (aFitDist, gp_Vec (aBndCenter, aBndCorner (aJ)).Dot (aPlaneN));
+ }
}
- else
+ // The center of camera is placed on the same line with center of bounding box.
+ // The view plane section crosses the bounding box at its center.
+ // To compute view plane size, evaluate coefficients converting "point -> plane distance"
+ // into view section size between the point and the frustum plane.
+ // proj
+ // /|\ right half of frame //
+ // | //
+ // point o<-- distance * coeff -->//---- (view plane section)
+ // \ //
+ // (distance) //
+ // ~ //
+ // (distance) //
+ // \/\//
+ // \//
+ // //
+ // (frustum plane)
+ aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan ( aCamSide .Angle (aFrustumPlane (1).Axis().Direction())), 2.0));
+ aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction())), 2.0));
+ aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan ( aCamUp .Angle (aFrustumPlane (3).Axis().Direction())), 2.0));
+ aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan ((-aCamUp) .Angle (aFrustumPlane (4).Axis().Direction())), 2.0));
+ aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan ( aCamDir .Angle (aFrustumPlane (5).Axis().Direction())), 2.0));
+ aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan ((-aCamDir) .Angle (aFrustumPlane (6).Axis().Direction())), 2.0));
+
+ Standard_Real aViewSizeXv = aFitDistance (1) + aFitDistance (2);
+ Standard_Real aViewSizeYv = aFitDistance (3) + aFitDistance (4);
+ Standard_Real aViewSizeZv = aFitDistance (5) + aFitDistance (6);
+
+ // 3. Place center of camera on the same line with center of bounding
+ // box applying corresponding projection asymmetry (if any).
+ Standard_Real anAssymXv = anAssymX * aViewSizeXv * 0.5;
+ Standard_Real anAssymYv = anAssymY * aViewSizeYv * 0.5;
+ Standard_Real anOffsetXv = (aFitDistance (2) - aFitDistance (1)) * 0.5 + anAssymXv;
+ Standard_Real anOffsetYv = (aFitDistance (4) - aFitDistance (3)) * 0.5 + anAssymYv;
+ gp_Vec aTranslateSide = gp_Vec (aCamSide) * anOffsetXv;
+ gp_Vec aTranslateUp = gp_Vec (aCamUp) * anOffsetYv;
+ gp_Pnt aCamNewCenter = aBndCenter.Translated (aTranslateSide).Translated (aTranslateUp);
+
+ gp_Trsf aCenterTrsf;
+ aCenterTrsf.SetTranslation (theCamera->Center(), aCamNewCenter);
+ theCamera->Transform (aCenterTrsf);
+ theCamera->SetDistance (aFitDistance (6) + aFitDistance (5));
+
+ // Bounding box collapses to a point or thin line going in depth of the screen
+ if (aViewSizeXv < theResolution && aViewSizeYv < theResolution)
{
- myCamera->SetProjectionShift (gp_Pnt (0.0, 0.0, 0.0));
- myCamera->SetCenter (aCenter);
- myCamera->SetEye (aEye);
+ if (aViewSizeXv < theResolution || !theToEnlargeIfLine)
+ {
+ return Standard_True; // This is just one point or line and zooming has no effect.
+ }
+
+ // Looking along line and "theToEnlargeIfLine" is requested.
+ // Fit view to see whole scene on rotation.
+ aViewSizeXv = aViewSizeZv;
+ aViewSizeYv = aViewSizeZv;
}
- // zoom camera to fit in the bounding box.
- ZoomCamera (aSectU, aSectV, aSectDepth);
+ Scale (theCamera, aViewSizeXv * (1.0 + theMargin), aViewSizeYv * (1.0 + theMargin));
- // re-evaluate camera
- myCamera->EndUpdate();
+ return Standard_True;
}
// =======================================================================
-// function : ZoomCamera
-// purpose :
+// function : Scale
+// purpose : Internal
// =======================================================================
-void V3d_View::ZoomCamera (const Standard_Real theUSize,
- const Standard_Real theVSize,
- const Standard_Real theZDepth)
+void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera,
+ const Standard_Real theSizeXv,
+ const Standard_Real theSizeYv) const
{
- if (myCamera.IsNull())
- return;
-
- // compute maximum section size along both directions.
- Standard_Real anAspect = myCamera->Aspect();
- Standard_Real aSize = Max (theUSize / anAspect, theVSize);
-
- myCamera->BeginUpdate();
- myCamera->SetScale (aSize);
-
- if (!myCamera->IsOrthographic())
+ Standard_Real anAspect = theCamera->Aspect();
+ if (anAspect > 1.0)
{
- myCamera->SetDistance (myCamera->Distance() + theZDepth);
+ theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv));
+ }
+ else
+ {
+ theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect));
}
-
- AutoZFit();
-
- myCamera->EndUpdate();
}
// =======================================================================
-// function : PanCamera
-// purpose : panning is fun
+// function : Translate
+// purpose : Internal
// =======================================================================
-void V3d_View::PanCamera (const Standard_Real theU,
- const Standard_Real theV)
+void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
+ const Standard_Real theDXv,
+ const Standard_Real theDYv) const
{
- if (myCamera.IsNull())
- return;
+ const gp_Pnt& aCenter = theCamera->Center();
+ const gp_Dir& aDir = theCamera->Direction();
+ const gp_Dir& anUp = theCamera->Up();
+ gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp);
- if (myCamera->IsOrthographic())
- {
- // Projection based panning for compatibility.
- myCamera->SetProjectionShift (myCamera->ProjectionShift().
- Translated (gp_Vec (-theU, -theV, 0.0)));
- }
- else
- {
- gp_Vec anUp = myCamera->Up();
- gp_Vec aSide = myCamera->Direction().Crossed (anUp);
-
- gp_Vec aPanU = aSide.Scaled (theU);
- gp_Vec aPanV = anUp.Scaled (theV);
- gp_Pnt aPannedEye (myCamera->Eye());
- gp_Pnt aPannedCenter (myCamera->Center());
+ gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv;
+ gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv;
+ gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv;
+ gp_Trsf aPanTrsf;
+ aPanTrsf.SetTranslation (aCameraPan);
- aPannedEye.Translate (aPanU);
- aPannedEye.Translate (aPanV);
- aPannedCenter.Translate (aPanU);
- aPannedCenter.Translate (aPanV);
+ theCamera->Transform (aPanTrsf);
+}
- myCamera->BeginUpdate();
- myCamera->SetEye (aPannedEye);
- myCamera->SetCenter (aPannedCenter);
- myCamera->EndUpdate();
- }
+// =======================================================================
+// function : IsCullingEnabled
+// purpose :
+// =======================================================================
+Standard_Boolean V3d_View::IsCullingEnabled() const
+{
+ return myView->IsCullingEnabled();
+}
- AutoZFit();
+// =======================================================================
+// function : SetFrustumCulling
+// purpose :
+// =======================================================================
+void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip)
+{
+ myView->SetCullingEnabled (theToClip);
}