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> |
f751596e |
21 | #include <vtkRenderWindow.h> |
913a4c4a |
22 | #include <vtkTransform.h> |
23 | |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_View,IVtk_IView) |
25 | |
913a4c4a |
26 | // Initialization of VTK object factories. |
27 | // Since VTK 6 the factory methods require "auto-initialization" depending on |
28 | // what modules are enabled at VTK configure time. |
29 | // Some defines are needed in order to make the factories work properly. |
30 | VTK_MODULE_INIT(vtkRenderingOpenGL); |
31 | VTK_MODULE_INIT(vtkInteractionStyle); |
32 | |
33 | // Handle implementation |
ec357c5c |
34 | |
913a4c4a |
35 | |
36 | //================================================================ |
37 | // Function : Constructor |
38 | // Purpose : |
39 | //================================================================ |
40 | IVtkVTK_View::IVtkVTK_View (vtkRenderer* theRenderer) |
41 | : myRenderer (theRenderer) |
42 | { } |
43 | |
44 | //================================================================ |
45 | // Function : Destructor |
46 | // Purpose : |
47 | //================================================================ |
48 | IVtkVTK_View::~IVtkVTK_View() |
49 | { } |
50 | |
51 | //================================================================ |
52 | // Function : IsPerspective |
53 | // Purpose : |
54 | //================================================================ |
55 | bool IVtkVTK_View::IsPerspective() const |
56 | { |
57 | return !myRenderer->GetActiveCamera()->GetParallelProjection(); |
58 | } |
59 | |
60 | //================================================================ |
61 | // Function : GetDistance |
62 | // Purpose : |
63 | //================================================================ |
64 | double IVtkVTK_View::GetDistance() const |
65 | { |
66 | return myRenderer->GetActiveCamera()->GetDistance(); |
67 | } |
68 | |
69 | //================================================================ |
70 | // Function : GetPosition |
71 | // Purpose : |
72 | //================================================================ |
73 | void IVtkVTK_View::GetPosition (double& theX, double& theY, double& theZ) const |
74 | { |
75 | myRenderer->GetActiveCamera()->GetFocalPoint (theX, theY, theZ); |
76 | } |
77 | |
78 | //================================================================ |
79 | // Function : GetViewUp |
80 | // Purpose : |
81 | //================================================================ |
82 | void IVtkVTK_View::GetViewUp (double& theDx, double& theDy, double& theDz) const |
83 | { |
84 | myRenderer->GetActiveCamera()->OrthogonalizeViewUp(); |
85 | myRenderer->GetActiveCamera()->GetViewUp (theDx, theDy, theDz); |
86 | } |
87 | |
88 | //================================================================ |
89 | // Function : GetDirectionOfProjection |
90 | // Purpose : |
91 | //================================================================ |
92 | void IVtkVTK_View::GetDirectionOfProjection (double& theDx, |
93 | double& theDy, |
94 | double& theDz) const |
95 | { |
96 | myRenderer->GetActiveCamera()->GetDirectionOfProjection (theDx, theDy, theDz); |
97 | theDx = -theDx; |
98 | theDy = -theDy; |
99 | theDz = -theDz; |
100 | } |
101 | |
102 | //================================================================ |
103 | // Function : GetScale |
104 | // Purpose : |
105 | //================================================================ |
106 | void IVtkVTK_View::GetScale (double& theX, double& theY, double& theZ) const |
107 | { |
108 | double aScale[3]; |
109 | myRenderer->GetActiveCamera()->GetViewTransformObject()->GetScale (aScale); |
110 | theX = aScale[0]; |
111 | theY = aScale[1]; |
112 | theZ = aScale[2]; |
113 | } |
114 | |
115 | //================================================================ |
116 | // Function : GetParallelScale |
117 | // Purpose : |
118 | //================================================================ |
119 | double IVtkVTK_View::GetParallelScale() const |
120 | { |
121 | return myRenderer->GetActiveCamera()->GetParallelScale(); |
122 | } |
123 | |
124 | //================================================================ |
125 | // Function : GetViewAngle |
126 | // Purpose : |
127 | //================================================================ |
128 | double IVtkVTK_View::GetViewAngle() const |
129 | { |
130 | return myRenderer->GetActiveCamera()->GetViewAngle(); |
131 | } |
132 | |
133 | //================================================================ |
134 | // Function : GetViewCenter |
135 | // Purpose : |
136 | //================================================================ |
137 | void IVtkVTK_View::GetViewCenter (double& theX, double& theY) const |
138 | { |
139 | double* aCenter = myRenderer->GetCenter(); |
140 | theX = aCenter[0]; |
141 | theY = aCenter[1]; |
142 | } |
143 | |
144 | //================================================================ |
145 | // Function : DisplayToWorld |
146 | // Purpose : |
147 | //================================================================ |
148 | bool IVtkVTK_View::DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const |
149 | { |
150 | // Convert the selection point into world coordinates. |
151 | myRenderer->SetDisplayPoint (theDisplayPnt.X(), theDisplayPnt.Y(), 0.0); |
152 | myRenderer->DisplayToWorld(); |
153 | |
5ca413ce |
154 | double* const aCoords = myRenderer->GetWorldPoint(); |
913a4c4a |
155 | if (aCoords[3] == 0.0) // Point at infinity in homogeneous coordinates |
156 | { |
157 | return false; |
158 | } |
159 | |
160 | theWorldPnt = gp_XYZ (aCoords[0] / aCoords[3], aCoords[1] / aCoords[3], aCoords[2] / aCoords[3]); |
161 | |
162 | return true; |
163 | } |
f751596e |
164 | |
165 | //================================================================ |
166 | // Function : GetWindowSize |
167 | // Purpose : |
168 | //================================================================ |
169 | void IVtkVTK_View::GetWindowSize (int& theX, int& theY) const |
170 | { |
171 | int* aSize = myRenderer->GetRenderWindow()->GetSize(); |
172 | theX = aSize[0]; |
173 | theY = aSize[1]; |
174 | } |
175 | |
176 | //================================================================ |
177 | // Function : GetCamera |
178 | // Purpose : |
179 | //================================================================ |
180 | void IVtkVTK_View::GetCamera (Graphic3d_Mat4d& theProj, |
181 | Graphic3d_Mat4d& theOrient, |
182 | Standard_Boolean& theIsOrtho) const |
183 | { |
184 | theIsOrtho = !IsPerspective(); |
185 | |
186 | vtkMatrix4x4* aCompositeProj = |
187 | myRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(), |
188 | 0, |
189 | 1); |
190 | for (Standard_Integer aRow = 0; aRow < 4; ++aRow) |
191 | { |
192 | for (Standard_Integer aCol = 0; aCol < 4; ++aCol) |
193 | { |
194 | theProj.SetValue (aRow, aCol, aCompositeProj->GetElement (aRow, aCol)); |
195 | } |
196 | } |
197 | |
198 | theOrient.InitIdentity(); |
199 | } |
200 | |
201 | //================================================================ |
202 | // Function : GetViewport |
203 | // Purpose : |
204 | //================================================================ |
205 | void IVtkVTK_View::GetViewport (Standard_Real& theX, |
206 | Standard_Real& theY, |
207 | Standard_Real& theWidth, |
208 | Standard_Real& theHeight) const |
209 | { |
210 | Standard_Real aViewport[4]; |
211 | myRenderer->GetViewport (aViewport); |
212 | theX = aViewport[0]; |
213 | theY = aViewport[1]; |
214 | theWidth = aViewport[2]; |
215 | theHeight = aViewport[3]; |
216 | } |