0025991: Cyclic dependency in OCCT detected by WOK compiler
[occt.git] / src / IVtkVTK / IVtkVTK_View.cxx
CommitLineData
913a4c4a 1// Created on: 2011-10-14
2// Created by: Roman KOZLOV
3// Copyright (c) 2011-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16
17#include <IVtkVTK_View.hxx>
18#include <vtkAutoInit.h>
19#include <vtkCamera.h>
20#include <vtkRenderer.h>
21#include <vtkTransform.h>
22
23// Initialization of VTK object factories.
24// Since VTK 6 the factory methods require "auto-initialization" depending on
25// what modules are enabled at VTK configure time.
26// Some defines are needed in order to make the factories work properly.
27VTK_MODULE_INIT(vtkRenderingOpenGL);
28VTK_MODULE_INIT(vtkInteractionStyle);
29
30// Handle implementation
31IMPLEMENT_STANDARD_HANDLE(IVtkVTK_View, IVtk_IView)
32IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_View, IVtk_IView)
33
34//================================================================
35// Function : Constructor
36// Purpose :
37//================================================================
38IVtkVTK_View::IVtkVTK_View (vtkRenderer* theRenderer)
39: myRenderer (theRenderer)
40{ }
41
42//================================================================
43// Function : Destructor
44// Purpose :
45//================================================================
46IVtkVTK_View::~IVtkVTK_View()
47{ }
48
49//================================================================
50// Function : IsPerspective
51// Purpose :
52//================================================================
53bool IVtkVTK_View::IsPerspective() const
54{
55 return !myRenderer->GetActiveCamera()->GetParallelProjection();
56}
57
58//================================================================
59// Function : GetDistance
60// Purpose :
61//================================================================
62double IVtkVTK_View::GetDistance() const
63{
64 return myRenderer->GetActiveCamera()->GetDistance();
65}
66
67//================================================================
68// Function : GetPosition
69// Purpose :
70//================================================================
71void IVtkVTK_View::GetPosition (double& theX, double& theY, double& theZ) const
72{
73 myRenderer->GetActiveCamera()->GetFocalPoint (theX, theY, theZ);
74}
75
76//================================================================
77// Function : GetViewUp
78// Purpose :
79//================================================================
80void IVtkVTK_View::GetViewUp (double& theDx, double& theDy, double& theDz) const
81{
82 myRenderer->GetActiveCamera()->OrthogonalizeViewUp();
83 myRenderer->GetActiveCamera()->GetViewUp (theDx, theDy, theDz);
84}
85
86//================================================================
87// Function : GetDirectionOfProjection
88// Purpose :
89//================================================================
90void IVtkVTK_View::GetDirectionOfProjection (double& theDx,
91 double& theDy,
92 double& theDz) const
93{
94 myRenderer->GetActiveCamera()->GetDirectionOfProjection (theDx, theDy, theDz);
95 theDx = -theDx;
96 theDy = -theDy;
97 theDz = -theDz;
98}
99
100//================================================================
101// Function : GetScale
102// Purpose :
103//================================================================
104void IVtkVTK_View::GetScale (double& theX, double& theY, double& theZ) const
105{
106 double aScale[3];
107 myRenderer->GetActiveCamera()->GetViewTransformObject()->GetScale (aScale);
108 theX = aScale[0];
109 theY = aScale[1];
110 theZ = aScale[2];
111}
112
113//================================================================
114// Function : GetParallelScale
115// Purpose :
116//================================================================
117double IVtkVTK_View::GetParallelScale() const
118{
119 return myRenderer->GetActiveCamera()->GetParallelScale();
120}
121
122//================================================================
123// Function : GetViewAngle
124// Purpose :
125//================================================================
126double IVtkVTK_View::GetViewAngle() const
127{
128 return myRenderer->GetActiveCamera()->GetViewAngle();
129}
130
131//================================================================
132// Function : GetViewCenter
133// Purpose :
134//================================================================
135void IVtkVTK_View::GetViewCenter (double& theX, double& theY) const
136{
137 double* aCenter = myRenderer->GetCenter();
138 theX = aCenter[0];
139 theY = aCenter[1];
140}
141
142//================================================================
143// Function : DisplayToWorld
144// Purpose :
145//================================================================
146bool IVtkVTK_View::DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const
147{
148 // Convert the selection point into world coordinates.
149 myRenderer->SetDisplayPoint (theDisplayPnt.X(), theDisplayPnt.Y(), 0.0);
150 myRenderer->DisplayToWorld();
151
152 vtkFloatingPointType* const aCoords = myRenderer->GetWorldPoint();
153 if (aCoords[3] == 0.0) // Point at infinity in homogeneous coordinates
154 {
155 return false;
156 }
157
158 theWorldPnt = gp_XYZ (aCoords[0] / aCoords[3], aCoords[1] / aCoords[3], aCoords[2] / aCoords[3]);
159
160 return true;
161}