18 #include "vtkRenderWindow.h"
19 #include "vtkRendererCollection.h"
20 #include "vtkRenderer.h"
21 #include "vtkRenderWindow.h"
22 #include "vtkRenderWindowInteractor.h"
23 #include "vtkObjectFactory.h"
24 #include "vtkCellPicker.h"
26 #include "vtkLightCollection.h"
27 #include "vtkMapper.h"
28 #include "vtkRenderLargeImage.h"
29 #include "vtkVRMLExporter.h"
30 #include "vtkTIFFWriter.h"
31 #include "vtkJPEGWriter.h"
32 #include "vtkCamera.h"
33 #include "vtkProperty.h"
47 vtkObject* ret = vtkObjectFactory::CreateInstance(
"a_interactor");
66 vtkRenderWindowInteractor * rwi = this->Interactor;
67 int ctrl = rwi->GetControlKey();
68 int shift = rwi->GetShiftKey();
69 vtkRendererCollection * col = rwi->GetRenderWindow()->GetRenderers();
71 vtkRenderer *
ren = col->GetNextItem();
72 vtkRenderWindow * renWin = this->GetInteractor()->GetRenderWindow();
74 int * size = renWin->GetSize();
75 rwi->GetEventPosition(X,Y);
76 if ((ctrl >= 1)&&(shift >= 1))
79 float * Zbuffer = renWin->GetZbufferData(0,0,size[0]-1,size[1]-1);
80 float Z = Zbuffer[X+Y*size[0]];
84 ren->SetDisplayPoint(X,Y,Z);
85 ren->DisplayToWorld();
86 double * dp =
ren->GetWorldPoint();
87 std::cout << dp[0]/dp[3] <<
" " << dp[1]/dp[3] <<
" " << dp[2]/dp[3] << std::endl;
92 for (
int i=-2; i<3; i++) {
93 for (
int j=-2; j<3; j++) {
94 Z = Zbuffer[X+i+(Y+j)*size[0]];
97 ren->SetDisplayPoint(X+i,Y+j,Z);
98 ren->DisplayToWorld();
99 double * dp =
ren->GetWorldPoint();
100 std::cout << dp[0]/dp[3] <<
" " << dp[1]/dp[3] <<
" " << dp[2]/dp[3] << std::endl;
109 vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
114 vtkInteractorStyleTrackballCamera::OnRightButtonDown();
119 vtkInteractorStyleTrackballCamera::OnRightButtonUp();
124 vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
129 vtkInteractorStyleTrackballCamera::OnMiddleButtonUp();
134 vtkRenderWindowInteractor *rwi = this->Interactor;
135 char c = rwi->GetKeyCode();
136 int ctrl = rwi->GetControlKey();
137 vtkRendererCollection * col = rwi->GetRenderWindow()->GetRenderers();
138 col->InitTraversal();
139 vtkRenderer *
ren = col->GetNextItem();
140 vtkCamera * cam =
ren->GetActiveCamera();
141 if ((c==
'p')||(c==
'P'))
143 cam->ParallelProjectionOn();
144 std::string
name =
name_ + std::string(
" (parallel)");
145 rwi->GetRenderWindow()->SetWindowName(
name.c_str());
146 rwi->GetRenderWindow()->Render();
148 else if ((c==
'i')||(c==
'I'))
150 vtkActorCollection *ac;
153 rwi->GetEventPosition(X,Y);
154 this->FindPokedRenderer(X,Y);
155 ac = this->CurrentRenderer->GetActors();
158 ren->SetBackground(1.,1.,1.);
161 for (ac->InitTraversal(); (anActor = ac->GetNextItem()); )
162 anActor->GetProperty()->SetColor(0.,0.,0.);
167 ren->SetBackground(0.,0.,0.);
170 for (ac->InitTraversal(); (anActor = ac->GetNextItem()); )
171 anActor->GetProperty()->SetColor(1.,1.,1.);
175 rwi->GetRenderWindow()->Render();
177 else if ((c==
'c')||(c==
'C'))
179 cam->ParallelProjectionOff();
180 std::string
name =
name_ + std::string(
" (central)");
181 rwi->GetRenderWindow()->SetWindowName(
name.c_str());
182 rwi->GetRenderWindow()->Render();
184 else if ((c==
'v')||(c==
'V'))
186 std::string
name =
name_ + std::string(
".wrl");
187 vtkVRMLExporter * writer = vtkVRMLExporter::New();
188 writer->SetFileName(
name.c_str());
189 writer->SetInput(rwi->GetRenderWindow());
193 else if ((c==
'j')||(c==
'J'))
195 vtkRenderLargeImage * large = vtkRenderLargeImage::New();
196 large->SetInput(
ren);
198 std::string
name =
name_ + std::string(
".jpg");
199 vtkJPEGWriter * writer = vtkJPEGWriter::New();
200 writer->SetFileName(
name.c_str());
201 writer->SetInputConnection(large->GetOutputPort());
202 writer->SetQuality(100);
207 else if ((c==
't')||(c==
'T'))
209 vtkRenderLargeImage * large = vtkRenderLargeImage::New();
210 large->SetInput(
ren);
212 std::string
name =
name_ + std::string(
".tif");
213 vtkTIFFWriter * writer = vtkTIFFWriter::New();
214 writer->SetFileName(
name.c_str());
215 writer->SetInputConnection(large->GetOutputPort());
220 else if ((c==
'm')||(c==
'M'))
223 cam->GetPosition(po);
224 cam->GetFocalPoint(fo);
225 vtkLightCollection * lights =
ren->GetLights();
226 lights->InitTraversal();
227 vtkLight * light = lights->GetNextItem();
228 light->SetPosition(po);
229 light->SetFocalPoint(fo);
230 light->SetIntensity(1);
231 ren->LightFollowCameraOn();
234 else if ((c==
'b')||(c==
'B'))
237 cam->GetPosition(po);
238 cam->GetFocalPoint(fo);
239 vtkLightCollection * lights =
ren->GetLights();
240 lights->InitTraversal();
241 vtkLight * light = lights->GetNextItem();
242 light->SetPosition(po);
243 light->SetFocalPoint(fo);
244 light->SetIntensity(1);
245 ren->LightFollowCameraOn();
247 ren->LightFollowCameraOff();
249 else if ((c==
'w')||(c==
'W'))
251 vtkActorCollection *ac;
252 vtkActor *anActor, *aPart;
254 rwi->GetEventPosition(X,Y);
255 this->FindPokedRenderer(X,Y);
256 ac = this->CurrentRenderer->GetActors();
257 for (ac->InitTraversal(); (anActor = ac->GetNextItem()); )
259 anActor->GetProperty()->SetRepresentationToWireframe();
260 anActor->GetProperty()->LightingOff();
261 anActor->SetBackfaceProperty(anActor->GetProperty());
265 else if ((c==
's')||(c==
'S'))
267 vtkActorCollection *ac;
268 vtkActor *anActor, *aPart;
270 rwi->GetEventPosition(X,Y);
271 this->FindPokedRenderer(X,Y);
272 ac = this->CurrentRenderer->GetActors();
273 for (ac->InitTraversal(); (anActor = ac->GetNextItem()); )
275 anActor->GetProperty()->SetRepresentationToSurface();
276 anActor->GetProperty()->LightingOn();
277 anActor->GetMapper()->ScalarVisibilityOn();
281 else if ((c==
'x')||(c==
'X'))
284 cam->GetPosition(po);
285 cam->GetFocalPoint(fo);
288 a_point
dir(1.,0.,0.);
291 double dist = (p_fo-p_po).norm();
292 a_point np_po = p_fo-
dir*dist;
293 cam->SetPosition(np_po.x(),np_po.y(),np_po.z());
294 cam->SetViewUp(0.,0.,1.);
297 else if ((c==
'y')||(c==
'Y'))
300 cam->GetPosition(po);
301 cam->GetFocalPoint(fo);
304 a_point
dir(0.,1.,0.);
307 double dist = (p_fo-p_po).norm();
308 a_point np_po = p_fo-
dir*dist;
309 cam->SetPosition(np_po.x(),np_po.y(),np_po.z());
310 cam->SetViewUp(0.,0.,1.);
313 else if ((c==
'z')||(c==
'Z'))
316 cam->GetPosition(po);
317 cam->GetFocalPoint(fo);
320 a_point
dir(0.,0.,1.);
323 double dist = (p_fo-p_po).norm();
324 a_point np_po = p_fo-
dir*dist;
325 cam->SetPosition(np_po.x(),np_po.y(),np_po.z());
326 cam->SetViewUp(1.,0.,0.);
329 else if ((c==
'o')||(c==
'O'))
332 cam->GetPosition(po);
333 cam->GetFocalPoint(fo);
336 a_point
dir = (p_fo-p_po).normalise();
338 if (fabs(
dir.x())<0.2) {
dir.x(0.); moved=
true;}
339 if (fabs(
dir.y())<0.2) {
dir.y(0.); moved=
true;}
340 if (fabs(
dir.z())<0.2) {
dir.z(0.); moved=
true;}
344 double dist = (p_fo-p_po).norm();
345 a_point np_fo = p_po+
dir*dist;
346 std::cerr <<
"view direction: " <<
dir << std::endl;
347 cam->SetFocalPoint(np_fo.x(),np_fo.y(),np_fo.z());
354 cam->GetFocalPoint(fo);
355 std::cout << fo[0] <<
" " << fo[1] <<
" " << fo[2] << std::endl;
359 double r = cam->GetRoll();
360 std::cout << r << std::endl;
365 cam->GetPosition(po);
366 cam->GetFocalPoint(fo);
367 std::cout << po[0] <<
" " << po[1] <<
" " << po[2] <<
" ";
368 std::cout << fo[0] <<
" " << fo[1] <<
" " << fo[2] << std::endl;
370 else if ((c!=
'r')&&(c!=
'R'))
371 vtkInteractorStyleTrackballCamera::OnChar();
376 this->Superclass::PrintSelf(os,indent);
377 os << indent <<
"P.Smars" <<
"\n";
virtual void OnLeftButtonDown() override
virtual void OnRightButtonUp() override
static a_interactor * New()
virtual void OnMiddleButtonDown() override
virtual void OnRightButtonDown() override
virtual void OnMiddleButtonUp() override
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void OnChar() override
a_point dir(int i, int l)