Add new interfaces GetEyePosition(), GetClippingRange(), GetAspectRatio() to IVTK_IView
Add ivtkviewparams command to print current parameters of view
Add ivtkcamera comand to print current camera parameters or manages camera parameters (set ortho or persp projection)
//! @return The focal distance of the view
virtual double GetDistance() const = 0;
+ //! @return The world coordinates of the camera position
+ virtual void GetEyePosition (double& theX, double& theY, double& theZ) const = 0;
+
//! @return The world coordinates of the view position
virtual void GetPosition (double& theX, double& theY, double& theZ) const = 0;
//! @return The current view angle (for perspective projection)
virtual double GetViewAngle() const = 0;
+ //! @return The location of the near and far clipping planes along the direction of projection
+ virtual void GetClippingRange (double& theZNear, double& theZFar) const = 0;
+
+ //! @return The current view the aspect ratio
+ virtual double GetAspectRatio() const = 0;
+
//! @return Two doubles containing the display coordinates of the view window center
virtual void GetViewCenter (double& theX, double& theY) const = 0;
#include <vtkImageWriter.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkJPEGWriter.h>
+#include <vtkMatrix4x4.h>
#include <vtkPNGWriter.h>
#include <vtkPNMWriter.h>
#include <vtkPolyDataMapper.h>
return 0;
}
+//=================================================================================================
+//function : VtkViewParams
+//purpose :
+//=================================================================================================
+static int VtkViewParams (Draw_Interpretor& theDI, Standard_Integer theArgsNb, const char** /*theArgVec*/)
+{
+ if (!GetInteractor()
+ || !GetInteractor()->IsEnabled())
+ {
+ Message::SendFail() << "Error: call ivtkinit before";
+ return 1;
+ }
+ else if (theArgsNb != 1)
+ {
+ Message::SendFail() << "Syntax error: wrong number of arguments";
+ return 1;
+ }
+
+ vtkCamera* aCam = GetRenderer()->GetActiveCamera();
+
+ gp_XYZ aViewUp, aViewProj, aViewEye, aViewAt;
+ aCam->GetViewUp (aViewUp.ChangeCoord(1), aViewUp.ChangeCoord(2), aViewUp.ChangeCoord(3));
+ aCam->GetDirectionOfProjection (aViewProj.ChangeCoord(1), aViewProj.ChangeCoord(2), aViewProj.ChangeCoord(3));
+ aViewProj.Reverse();
+ aCam->GetPosition (aViewEye.ChangeCoord(1), aViewEye.ChangeCoord(2), aViewEye.ChangeCoord(3));
+ aCam->GetFocalPoint (aViewAt.ChangeCoord(1), aViewAt.ChangeCoord(2), aViewAt.ChangeCoord(3));
+ const Standard_Real aViewScale = aCam->GetParallelScale();
+ const Standard_Real aViewAspect = GetRenderer()->GetTiledAspectRatio();
+ vtkMatrix4x4* aProjMat = aCam->GetProjectionTransformMatrix (GetRenderer()->GetTiledAspectRatio(), -1, 1);
+ vtkMatrix4x4* aViewMat = aCam->GetViewTransformMatrix();
+ // print all of the available view parameters
+ char aText[4096];
+ Sprintf (aText,
+ "Scale: %g\n"
+ "Aspect: %g\n"
+ "Proj: %12g %12g %12g\n"
+ "Up: %12g %12g %12g\n"
+ "At: %12g %12g %12g\n"
+ "Eye: %12g %12g %12g\n"
+ "ViewMat: %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ "ProjMat: %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n",
+ aViewScale, aViewAspect,
+ aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
+ aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
+ aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
+ aViewEye.X(), aViewEye.Y(), aViewEye.Z(),
+ aViewMat->GetElement (0, 0), aViewMat->GetElement(0, 1), aViewMat->GetElement(0, 2), aViewMat->GetElement(0, 3),
+ aViewMat->GetElement (1, 0), aViewMat->GetElement(1, 1), aViewMat->GetElement(1, 2), aViewMat->GetElement(1, 3),
+ aViewMat->GetElement (2, 0), aViewMat->GetElement(2, 1), aViewMat->GetElement(2, 2), aViewMat->GetElement(2, 3),
+ aViewMat->GetElement (3, 0), aViewMat->GetElement(3, 1), aViewMat->GetElement(3, 2), aViewMat->GetElement(3, 3),
+ aProjMat->GetElement (0, 0), aProjMat->GetElement(0, 1), aProjMat->GetElement(0, 2), aProjMat->GetElement(0, 3),
+ aProjMat->GetElement (1, 0), aProjMat->GetElement(1, 1), aProjMat->GetElement(1, 2), aProjMat->GetElement(1, 3),
+ aProjMat->GetElement (2, 0), aProjMat->GetElement(2, 1), aProjMat->GetElement(2, 2), aProjMat->GetElement(2, 3),
+ aProjMat->GetElement (3, 0), aProjMat->GetElement(3, 1), aProjMat->GetElement(3, 2), aProjMat->GetElement(3, 3));
+ theDI << aText;
+ return 0;
+}
+
+//=================================================================================================
+//function : VtkCamera
+//purpose :
+//=================================================================================================
+static int VtkCamera (Draw_Interpretor& theDI, Standard_Integer theArgsNb, const char** theArgVec)
+{
+ if (!GetInteractor()
+ || !GetInteractor()->IsEnabled())
+ {
+ Message::SendFail() << "Error: call ivtkinit before";
+ return 1;
+ }
+
+ vtkCamera* aCamera = GetRenderer()->GetActiveCamera();
+
+ if (theArgsNb < 2)
+ {
+ Standard_Real aZNear = 0.0, aZFar = 0.0;
+ aCamera->GetClippingRange (aZNear, aZFar);
+ theDI << "ProjType: " << (aCamera->GetParallelProjection() ? "orthographic" : "perspective") << "\n";
+ theDI << "FOVy: " << aCamera->GetViewAngle() << "\n";
+ theDI << "Distance: " << aCamera->GetDistance() << "\n";
+ theDI << "ZNear: " << aZNear << "\n";
+ theDI << "ZFar: " << aZFar << "\n";
+ return 0;
+ }
+
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
+ {
+ Standard_CString anArg = theArgVec[anArgIter];
+ TCollection_AsciiString anArgCase(anArg);
+ anArgCase.LowerCase();
+ if (anArgCase == "-ortho"
+ || anArgCase == "-orthographic")
+ {
+ aCamera->SetParallelProjection (true);
+ }
+ else if (anArgCase == "-persp"
+ || anArgCase == "-perspective")
+ {
+ aCamera->SetParallelProjection (false);
+ }
+ else
+ {
+ Message::SendFail() << "Error: unknown argument '" << anArg << "'";
+ return 1;
+ }
+ }
+ GetRenderer()->ResetCamera();
+ GetInteractor()->Render();
+ return 0;
+}
+
//===================================================================
// Fubction : VtkDump
// Purpose :
"ivtksettransparency name 0..1"
"\n\t\t: Sets transparency to the object with name 'name'.",
__FILE__, VtkSetTransparency, group);
+
+ theCommands.Add("ivtkviewparams",
+ "ivtkviewparams: Prints all current view parameters.",
+ __FILE__, VtkViewParams, group);
+
+ theCommands.Add("ivtkcamera",
+ "ivtkcamera [-ortho] [-persp]"
+ "\n\t\t: Manages camera parameters."
+ "\n\t\t: Prints current value when option called without argument."
+ "\n\t\t: Orthographic camera:"
+ "\n\t\t: -ortho activate orthographic projection"
+ "\n\t\t: Perspective camera:"
+ "\n\t\t: -persp activate perspective projection",
+ __FILE__, VtkCamera, group);
}
//================================================================
{
}
+//============================================================================
+// Method: ConvertVtkToOccCamera
+// Purpose:
+//============================================================================
+Handle(Graphic3d_Camera) IVtkOCC_ViewerSelector::ConvertVtkToOccCamera (const IVtk_IView::Handle& theView)
+{
+ Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
+ aCamera->SetZeroToOneDepth (true);
+ Standard_Boolean isOrthographic = !theView->IsPerspective();
+ aCamera->SetProjectionType (isOrthographic ? Graphic3d_Camera::Projection_Orthographic : Graphic3d_Camera::Projection_Perspective);
+ if (isOrthographic)
+ {
+ aCamera->SetScale (2 * theView->GetParallelScale());
+ }
+ else
+ {
+ aCamera->SetFOVy (theView->GetViewAngle());
+ }
+ Standard_Real aZNear = 0.0, aZFar = 0.0;
+ theView->GetClippingRange (aZNear, aZFar);
+ aCamera->SetZRange (aZNear, aZFar);
+ aCamera->SetAspect (theView->GetAspectRatio());
+ gp_XYZ anAxialScale;
+ theView->GetScale (anAxialScale.ChangeCoord (1), anAxialScale.ChangeCoord (2), anAxialScale.ChangeCoord (3));
+ aCamera->SetAxialScale (anAxialScale);
+
+ gp_XYZ anUp, aDir, anEyePos;
+ theView->GetViewUp (anUp.ChangeCoord(1), anUp.ChangeCoord(2), anUp.ChangeCoord(3));
+ theView->GetDirectionOfProjection (aDir.ChangeCoord(1), aDir.ChangeCoord(2), aDir.ChangeCoord(3));
+ theView->GetEyePosition (anEyePos.ChangeCoord(1), anEyePos.ChangeCoord(2), anEyePos.ChangeCoord(3));
+
+ aCamera->SetDistance (theView->GetDistance());
+ aCamera->SetUp (anUp);
+ aCamera->SetDirectionFromEye (aDir.Reversed());
+ aCamera->MoveEyeTo (anEyePos);
+
+ return aCamera;
+}
+
//============================================================================
// Method: Pick
// Purpose: Implements point picking
myToUpdateTol = Standard_False;
}
- Standard_Integer aWidth = 0, aHeight = 0;
- Graphic3d_Mat4d aProj, anOrient;
- Standard_Boolean isOrthographic = Standard_False;
- Standard_Real aX = RealLast(), aY = RealLast();
- Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
-
- theView->GetCamera (aProj, anOrient, isOrthographic);
- mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
+ mySelectingVolumeMgr.SetCamera (ConvertVtkToOccCamera (theView));
+ Standard_Integer aWidth = 0, aHeight = 0;
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
-
+ Standard_Real aX = RealLast(), aY = RealLast();
+ Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
Standard_Integer aWidth = 0, aHeight = 0;
Graphic3d_Mat4d aProj, anOrient;
- Standard_Boolean isOrthographic = Standard_False;
Standard_Real aX = RealLast(), aY = RealLast();
Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
- theView->GetCamera (aProj, anOrient, isOrthographic);
- mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
+ mySelectingVolumeMgr.SetCamera (ConvertVtkToOccCamera (theView));
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
Standard_Integer aWidth = 0, aHeight = 0;
Graphic3d_Mat4d aProj, anOrient;
- Standard_Boolean isOrthographic = Standard_False;
Standard_Real aX = RealLast(), aY = RealLast();
Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
- theView->GetCamera (aProj, anOrient, isOrthographic);
- mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
+ mySelectingVolumeMgr.SetCamera (ConvertVtkToOccCamera (theView));
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
//! Deactivate the given selection
void Deactivate (const Handle(SelectMgr_Selection)& theSelection);
+ //! Converts VTK camera defiened for input view to OCC camera
+ static Handle(Graphic3d_Camera) ConvertVtkToOccCamera (const IVtk_IView::Handle& theView);
+
DEFINE_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
private:
return myRenderer->GetActiveCamera()->GetDistance();
}
+//================================================================
+// Function : GetEyePosition
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetEyePosition (double& theX, double& theY, double& theZ) const
+{
+ myRenderer->GetActiveCamera()->GetPosition (theX, theY, theZ);
+}
+
//================================================================
// Function : GetPosition
// Purpose :
return myRenderer->GetActiveCamera()->GetViewAngle();
}
+//================================================================
+// Function : GetAspectRatio
+// Purpose :
+//================================================================
+double IVtkVTK_View::GetAspectRatio() const
+{
+ return myRenderer->GetTiledAspectRatio();
+}
+
+//================================================================
+// Function : GetClippingRange
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetClippingRange (double& theZNear, double& theZFar) const
+{
+ myRenderer->GetActiveCamera()->GetClippingRange (theZNear, theZFar);
+}
+
//================================================================
// Function : GetViewCenter
// Purpose :
//! @return The focal distance of the view
Standard_EXPORT virtual double GetDistance() const Standard_OVERRIDE;
+ //! @return The world coordinates of the camera position
+ Standard_EXPORT virtual void GetEyePosition (double& theX, double& theY, double& theZ) const Standard_OVERRIDE;
+
//! @return The world coordinates of the view position
Standard_EXPORT virtual void GetPosition (double& theX, double& theY, double& theZ) const Standard_OVERRIDE;
//! @return The current view angle (for perspective projection)
Standard_EXPORT virtual double GetViewAngle() const Standard_OVERRIDE;
+ //! @return The location of the near and far clipping planes along the direction of projection
+ Standard_EXPORT virtual void GetClippingRange (double& theZNear, double& theZFar) const Standard_OVERRIDE;
+
+ //! @return The current view the aspect ratio
+ Standard_EXPORT virtual double GetAspectRatio() const Standard_OVERRIDE;
+
//! @return Two doubles containing the display coordinates of the view window center
Standard_EXPORT virtual void GetViewCenter (double& theX, double& theY) const Standard_OVERRIDE;
Standard_Boolean toSetSize = Standard_False;
Standard_Boolean toSetCenter2d = Standard_False;
Standard_Real aViewScale = aView->Scale();
+ Standard_Real aViewAspect = aView->Camera()->Aspect();
Standard_Real aViewSize = 1.0;
Graphic3d_Vec2i aCenter2d;
gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
+ const Graphic3d_Mat4d& anOrientMat = aView->Camera()->OrientationMatrix();
+ const Graphic3d_Mat4d& aProjMat = aView->Camera()->ProjectionMatrix();
if (theArgsNb == 1)
{
// print all of the available view parameters
char aText[4096];
Sprintf (aText,
- "Scale: %g\n"
- "Proj: %12g %12g %12g\n"
- "Up: %12g %12g %12g\n"
- "At: %12g %12g %12g\n"
- "Eye: %12g %12g %12g\n",
- aViewScale,
+ "Scale: %g\n"
+ "Aspect: %g\n"
+ "Proj: %12g %12g %12g\n"
+ "Up: %12g %12g %12g\n"
+ "At: %12g %12g %12g\n"
+ "Eye: %12g %12g %12g\n"
+ "OrientMat: %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ "ProjMat: %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n"
+ " %12g %12g %12g %12g\n",
+ aViewScale, aViewAspect,
aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
- aViewEye.X(), aViewEye.Y(), aViewEye.Z());
+ aViewEye.X(), aViewEye.Y(), aViewEye.Z(),
+ anOrientMat.GetValue (0, 0), anOrientMat.GetValue (0, 1), anOrientMat.GetValue (0, 2), anOrientMat.GetValue (0, 3),
+ anOrientMat.GetValue (1, 0), anOrientMat.GetValue (1, 1), anOrientMat.GetValue (1, 2), anOrientMat.GetValue (1, 3),
+ anOrientMat.GetValue (2, 0), anOrientMat.GetValue (2, 1), anOrientMat.GetValue (2, 2), anOrientMat.GetValue (2, 3),
+ anOrientMat.GetValue (3, 0), anOrientMat.GetValue (3, 1), anOrientMat.GetValue (3, 2), anOrientMat.GetValue (3, 3),
+ aProjMat.GetValue (0, 0), aProjMat.GetValue (0, 1), aProjMat.GetValue (0, 2), aProjMat.GetValue (0, 3),
+ aProjMat.GetValue (1, 0), aProjMat.GetValue (1, 1), aProjMat.GetValue (1, 2), aProjMat.GetValue (1, 3),
+ aProjMat.GetValue (2, 0), aProjMat.GetValue (2, 1), aProjMat.GetValue (2, 2), aProjMat.GetValue (2, 3),
+ aProjMat.GetValue (3, 0), aProjMat.GetValue (3, 1), aProjMat.GetValue (3, 2), aProjMat.GetValue (3, 3));
theDi << aText;
return 0;
}
theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
+ theDI << "ZNear: " << aCamera->ZNear() << "\n";
+ theDI << "ZFar: " << aCamera->ZFar() << "\n";
return 0;
}
--- /dev/null
+puts "============"
+puts "0032400: Visualization, TKIVtk - convert VTK camera to OCC"
+puts "============"
+puts ""
+
+pload MODELING VIS
+box b 1 1 1
+ivtkinit
+ivtkdisplay b
+ivtkmoveto 100 100
+
+
+psphere ss 2
+box bb -min -1 -1 2 -max 1 1 4
+ivtkinit
+ivtkdisplay bb
+ivtksetdispmode bb 1
+ivtkdisplay ss
+ivtksetdispmode ss 1
+ivtkcamera -ortho
+ivtktop
+ivtkfit
+
+ivtkcamera
+ivtkviewparams
+set point [ivtkmoveto 200 200]
+regexp {([-0-9.+eE]+ [-0-9.+eE]+ [-0-9.+eE]+)} ${point} full p
+checkpoint "point_ortho" $p {-0.090334585045725627 0.07055554071451263 4} 0.001
+ivtkdump $imagedir/${casename}_ortho.png
+
+ivtkcamera -persp
+set point [ivtkmoveto 200 200]
+regexp {([-0-9.+eE]+ [-0-9.+eE]+ [-0-9.+eE]+)} ${point} full p
+checkpoint "point_persp" $p {-0.075846060294573109 0.059286688130282886 3.9999999999999996} 0.001
+ivtkdump $imagedir/${casename}_persp.png