~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/vtk/interactor/ginkgointeractorstyleimage2d.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id$
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Code adapted from vtkINRIA3D
 
7
=========================================================================
 
8
 
 
9
Program:   vtkINRIA3D
 
10
Module:    $Id: GinkgoInteractorStyleImage2D.cpp 955 2009-11-24 12:54:49Z tovar $
 
11
Language:  C++
 
12
Author:    $Author: filus $
 
13
Date:      $Date: 2008-03-11 17:32:52 +0100 (mar, 11 mar 2008) $
 
14
Version:   $Revision: 752 $
 
15
 
 
16
Copyright (c) 2007 INRIA - Asclepios Project. All rights reserved.
 
17
See Copyright.txt for details.
 
18
 
 
19
This software is distributed WITHOUT ANY WARRANTY; without even
 
20
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
21
PURPOSE.  See the above copyright notices for more information.
 
22
 
 
23
=========================================================================*/
 
24
#ifdef __DEPRECATED
 
25
#undef __DEPRECATED
 
26
#endif
 
27
#include "ginkgointeractorstyleimage2d.h"
 
28
#include "../command/ginkgoimagecommand.h"
 
29
#include <vtkAbstractPropPicker.h>
 
30
#include <vtkAssemblyPath.h>
 
31
#include <vtkMath.h>
 
32
#include <vtkObjectFactory.h>
 
33
#include <vtkRenderWindowInteractor.h>
 
34
#include <vtkImageData.h>
 
35
#include <vtkRenderWindow.h>
 
36
 
 
37
vtkCxxRevisionMacro(GinkgoInteractorStyleImage2D, "$Revision: 752 $");
 
38
vtkStandardNewMacro(GinkgoInteractorStyleImage2D);
 
39
 
 
40
#include <vtkCamera.h>
 
41
#include <vtkRenderer.h>
 
42
 
 
43
//----------------------------------------------------------------------------
 
44
 
 
45
GinkgoInteractorStyleImage2D::GinkgoInteractorStyleImage2D()
 
46
: vtkInteractorStyleImage()
 
47
{
 
48
        this->View = 0;
 
49
        this->ZSliceStep = 0;
 
50
        this->LevelStep = 0.0;
 
51
        this->WindowStep = 0.0;
 
52
}
 
53
 
 
54
//----------------------------------------------------------------------------
 
55
 
 
56
GinkgoInteractorStyleImage2D::~GinkgoInteractorStyleImage2D()
 
57
{
 
58
}
 
59
 
 
60
//----------------------------------------------------------------------------
 
61
 
 
62
void GinkgoInteractorStyleImage2D::OnMouseMove()
 
63
{
 
64
        int x = this->Interactor->GetEventPosition()[0];
 
65
        int y = this->Interactor->GetEventPosition()[1];
 
66
 
 
67
        switch (this->State) {
 
68
                case VTKIS_WINDOW_LEVEL:
 
69
                        this->FindPokedRenderer(x, y);
 
70
                        this->WindowLevel();
 
71
                        this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
 
72
                        break;
 
73
 
 
74
                case VTKIS_PICK:
 
75
                        // No Drag is allowed for picking. Toggle to ZSliceMove state
 
76
                        // We force StartZSliceMove or StartPan or StartDolly without ending the picking.
 
77
                        // We don't want to pick at all
 
78
                        this->StopState();
 
79
                        this->StartZSliceMove();
 
80
                        // There we don't break to let the hand to ZSliceMove
 
81
 
 
82
                case VTKIS_ZSLICE_MOVE:
 
83
                        this->FindPokedRenderer(x, y);
 
84
                        this->ZSliceMove();
 
85
                        this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
 
86
                        break;
 
87
 
 
88
                case VTKIS_DOLLY:
 
89
                        this->FindPokedRenderer(x, y);
 
90
                        //this->Dolly();
 
91
                        //this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
 
92
                        this->InvokeEvent(GinkgoImageCommand::ZoomEvent, this);
 
93
                        break;
 
94
 
 
95
                case VTKIS_PAN:
 
96
                        this->FindPokedRenderer(x, y);
 
97
                        this->Pan();
 
98
                        this->PropagateCameraFocalAndPosition();
 
99
                        this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
 
100
                        break;
 
101
                default:
 
102
                        break;
 
103
        }
 
104
}
 
105
 
 
106
void GinkgoInteractorStyleImage2D::PropagateCameraFocalAndPosition()
 
107
{
 
108
        if (!this->GetView()) {
 
109
                return;
 
110
        }
 
111
 
 
112
        double pos[3], focal[3];
 
113
 
 
114
        if (!this->GetView()->GetRenderer()) {
 
115
                return;
 
116
        }
 
117
 
 
118
        vtkCamera* camera = this->GetView()->GetRenderer()->GetActiveCamera();
 
119
        camera->GetFocalPoint(focal);
 
120
        camera->GetPosition(pos);
 
121
 
 
122
        bool LinkCamera = this->GetView()->GetLinkCameraFocalAndPosition();
 
123
        this->GetView()->SetLinkCameraFocalAndPosition(false);
 
124
        this->GetView()->SyncSetCameraFocalAndPosition(focal, pos);
 
125
        this->GetView()->SetLinkCameraFocalAndPosition(LinkCamera);
 
126
 
 
127
        //this->GetView()->Render();
 
128
 
 
129
 
 
130
}
 
131
 
 
132
 
 
133
//----------------------------------------------------------------------------
 
134
 
 
135
void GinkgoInteractorStyleImage2D::OnLeftButtonDown()
 
136
{
 
137
        int x = this->Interactor->GetEventPosition()[0];
 
138
        int y = this->Interactor->GetEventPosition()[1];
 
139
 
 
140
        this->FindPokedRenderer(x, y);
 
141
        if (!this->CurrentRenderer) {
 
142
                return;
 
143
        }
 
144
 
 
145
        //switch ( this->View->GetInteractionStyle() )
 
146
        switch (this->View->GetLeftButtonInteractionStyle()) {
 
147
                /*
 
148
                case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
149
                        this->WindowLevelStartPosition[0] = x;
 
150
                        this->WindowLevelStartPosition[1] = y;
 
151
                        this->StartWindowLevel();
 
152
                        break;
 
153
                */
 
154
                case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
155
                        this->StartPick();
 
156
                        break;
 
157
                case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
158
                        this->StartPick();
 
159
                        this->StopState();
 
160
                        //this->StartPan();
 
161
                        break;
 
162
                /*
 
163
                case vtkGinkgoImageViewer::FULL_PAGE_INTERACTION :
 
164
                        this->FullPage();
 
165
                        break;
 
166
                case vtkGinkgoImageViewer::MEASURE_INTERACTION :
 
167
                        this->StartMeasure();
 
168
                        break;
 
169
                */
 
170
                case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
171
                        /*
 
172
                        if (this->Interactor->GetShiftKey()) {
 
173
                                this->StartPan();
 
174
                        } else {
 
175
                                this->StartDolly(); // continuous zoom
 
176
                        }
 
177
                        */
 
178
                        break;
 
179
        }
 
180
 
 
181
}
 
182
 
 
183
//----------------------------------------------------------------------------
 
184
 
 
185
void GinkgoInteractorStyleImage2D::OnMiddleButtonDown()
 
186
{
 
187
        int x = this->Interactor->GetEventPosition()[0];
 
188
        int y = this->Interactor->GetEventPosition()[1];
 
189
 
 
190
        this->FindPokedRenderer(x, y);
 
191
        if (!this->CurrentRenderer) {
 
192
                return;
 
193
        }
 
194
 
 
195
        //switch ( this->View->GetInteractionStyle() )
 
196
        switch (this->View->GetMiddleButtonInteractionStyle()) {
 
197
                /*
 
198
                case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
199
                        this->WindowLevelStartPosition[0] = x;
 
200
                        this->WindowLevelStartPosition[1] = y;
 
201
                        this->StartWindowLevel();
 
202
                        break;
 
203
                */
 
204
                case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
205
                        this->StartPick();
 
206
                        break;
 
207
                case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
208
                        //this->StartPan();
 
209
                        break;
 
210
                /*
 
211
                case vtkGinkgoImageViewer::FULL_PAGE_INTERACTION :
 
212
                        this->FullPage();
 
213
                        break;
 
214
                case vtkGinkgoImageViewer::MEASURE_INTERACTION :
 
215
                        this->StartMeasure();
 
216
                        break;
 
217
                */
 
218
                case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
219
                        //this->StartPan();
 
220
                        break;
 
221
        }
 
222
}
 
223
 
 
224
//----------------------------------------------------------------------------
 
225
 
 
226
void GinkgoInteractorStyleImage2D::OnMiddleButtonUp()
 
227
{
 
228
        switch (this->State) {
 
229
                case VTKIS_ZSLICE_MOVE:
 
230
                        this->EndZSliceMove();
 
231
                        break;
 
232
                case VTKIS_WINDOW_LEVEL:
 
233
                        this->EndWindowLevel();
 
234
                        break;
 
235
                case VTKIS_PICK:
 
236
                        this->EndPick();
 
237
                        break;
 
238
                case VTKIS_MEASURE:
 
239
                        this->EndMeasure();
 
240
                        break;
 
241
                case VTKIS_PAN:
 
242
                        this->EndPan();
 
243
                        break;
 
244
                case VTKIS_DOLLY:
 
245
                        this->EndDolly(); // continuous zoom
 
246
                        break;
 
247
        }
 
248
 
 
249
}
 
250
 
 
251
//----------------------------------------------------------------------------
 
252
 
 
253
void GinkgoInteractorStyleImage2D::OnLeftButtonUp()
 
254
{
 
255
        switch (this->State) {
 
256
                case VTKIS_ZSLICE_MOVE:
 
257
                        this->EndZSliceMove();
 
258
                        break;
 
259
                case VTKIS_WINDOW_LEVEL:
 
260
                        this->EndWindowLevel();
 
261
                        break;
 
262
                case VTKIS_PICK:
 
263
                        this->EndPick();
 
264
                        break;
 
265
                case VTKIS_MEASURE:
 
266
                        this->EndMeasure();
 
267
                        break;
 
268
                case VTKIS_DOLLY: // continuous zoom
 
269
                        this->EndDolly();
 
270
                        break;
 
271
                case VTKIS_PAN: // continuous zoom
 
272
                        this->EndPan();
 
273
                        break;
 
274
        }
 
275
}
 
276
 
 
277
//----------------------------------------------------------------------------
 
278
 
 
279
void GinkgoInteractorStyleImage2D::OnRightButtonDown()
 
280
{
 
281
        int x = this->Interactor->GetEventPosition()[0];
 
282
        int y = this->Interactor->GetEventPosition()[1];
 
283
 
 
284
        this->FindPokedRenderer(x, y);
 
285
        if (!this->CurrentRenderer) {
 
286
                return;
 
287
        }
 
288
 
 
289
        //switch ( this->View->GetInteractionStyle() )
 
290
        switch (this->View->GetRightButtonInteractionStyle()) {
 
291
                /*
 
292
                case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
293
                        this->WindowLevelStartPosition[0] = x;
 
294
                        this->WindowLevelStartPosition[1] = y;
 
295
                        this->StartWindowLevel();
 
296
                        break;
 
297
                */
 
298
                case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
299
                        this->StartPick();
 
300
                        break;
 
301
                case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
302
                        this->StartPan();
 
303
                        break;
 
304
                /*
 
305
                case vtkGinkgoImageViewer::FULL_PAGE_INTERACTION :
 
306
                        this->FullPage();
 
307
                        break;
 
308
                case vtkGinkgoImageViewer::MEASURE_INTERACTION :
 
309
                        this->StartMeasure();
 
310
                        break;
 
311
                */
 
312
                case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
313
                        this->StartPan();
 
314
                        break;
 
315
        }
 
316
}
 
317
 
 
318
//----------------------------------------------------------------------------
 
319
 
 
320
void GinkgoInteractorStyleImage2D::OnRightButtonUp()
 
321
{
 
322
        switch (this->State) {
 
323
                case VTKIS_ZSLICE_MOVE:
 
324
                        this->EndZSliceMove();
 
325
                        break;
 
326
                case VTKIS_WINDOW_LEVEL:
 
327
                        this->EndWindowLevel();
 
328
                        break;
 
329
                case VTKIS_PICK:
 
330
                        this->EndPick();
 
331
                        break;
 
332
                case VTKIS_MEASURE:
 
333
                        this->EndMeasure();
 
334
                        break;
 
335
                case VTKIS_DOLLY: // continuous zoom
 
336
                        this->EndDolly();
 
337
                        break;
 
338
                case VTKIS_PAN:
 
339
                        this->EndPan();
 
340
                        break;
 
341
        }
 
342
}
 
343
 
 
344
//----------------------------------------------------------------------------
 
345
 
 
346
void GinkgoInteractorStyleImage2D::OnChar()
 
347
{
 
348
        vtkRenderWindowInteractor *rwi = this->Interactor;
 
349
 
 
350
        double factor = 0.0;
 
351
        //int *size = this->View->GetRenderWindow()->GetSize();
 
352
 
 
353
        std::string key_sym(rwi->GetKeySym());
 
354
 
 
355
        if ((key_sym.compare("Up") == 0) || (key_sym.compare("KP_Up") == 0)) {
 
356
 
 
357
                switch (this->View->GetInteractionStyle()) {
 
358
                        /*
 
359
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
360
                                this->StartWindowLevel();
 
361
                                this->SetWindowStep(0.0);
 
362
                                this->SetLevelStep(4.0 / size[1]);
 
363
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
364
                                this->EndWindowLevel();
 
365
                                break;
 
366
 
 
367
                        */
 
368
                        case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
369
                                this->StartZSliceMove();
 
370
                                this->ZSliceStep = 1;
 
371
                                this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
372
                                this->EndZSliceMove();
 
373
                                break;
 
374
 
 
375
                        case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
376
                                this->StartDolly();
 
377
                                factor = 2.0;
 
378
                                //this->Dolly(pow((double)1.1, factor));
 
379
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
380
                                this->EndDolly();
 
381
                                break;
 
382
 
 
383
                        case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
384
                                this->StartDolly();
 
385
                                factor = 2.0;
 
386
                                //this->Dolly(pow((double)1.1, factor));
 
387
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
388
                                this->EndDolly();
 
389
                                break;
 
390
 
 
391
                        default:
 
392
                                break;
 
393
                }
 
394
        } else if ((key_sym.compare("Right") == 0) || (key_sym.compare("KP_Right") == 0)) {
 
395
                
 
396
        /*      switch (this->View->GetInteractionStyle()) {
 
397
                        
 
398
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
399
                                this->StartWindowLevel();
 
400
                                this->SetWindowStep(4.0 / size[1]);
 
401
                                this->SetLevelStep(0.0);
 
402
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
403
                                this->EndWindowLevel();
 
404
                                break;
 
405
                        
 
406
                        default:
 
407
                                break;
 
408
                }*/
 
409
        } else if ((key_sym.compare("Left") == 0) || (key_sym.compare("KP_Left") == 0)) {
 
410
 
 
411
        /*      switch (this->View->GetInteractionStyle()) {
 
412
                        
 
413
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
414
                                this->StartWindowLevel();
 
415
                                this->SetWindowStep(-4.0 / size[1]);
 
416
                                this->SetLevelStep(0.0);
 
417
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
418
                                this->EndWindowLevel();
 
419
                                break;
 
420
                        
 
421
                        default:
 
422
                                break;
 
423
                }*/
 
424
        } else if ((key_sym.compare("Down") == 0) || (key_sym.compare("KP_Down") == 0)) {
 
425
 
 
426
                switch (this->View->GetInteractionStyle()) {
 
427
                        /*
 
428
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
429
                                this->StartWindowLevel();
 
430
                                this->SetWindowStep(0.0);
 
431
                                this->SetLevelStep(-4.0 / size[1]);
 
432
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
433
                                this->EndWindowLevel();
 
434
                                break;
 
435
                        */
 
436
                        case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
437
                                this->StartZSliceMove();
 
438
                                this->ZSliceStep = -1;
 
439
                                this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
440
                                this->EndZSliceMove();
 
441
                                break;
 
442
 
 
443
                        case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
444
                                this->StartDolly();
 
445
                                factor = -2.0;
 
446
                                //this->Dolly(pow((double)1.1, factor));
 
447
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
448
                                this->EndDolly();
 
449
                                break;
 
450
                        /*
 
451
                        case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
452
                                this->StartDolly();
 
453
                                factor = -2.0;
 
454
                                //this->Dolly(pow((double)1.1, factor));
 
455
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
456
                                this->EndDolly();
 
457
                                break;
 
458
                        */
 
459
                        default:
 
460
                                break;
 
461
                }
 
462
        } else if ((key_sym.compare("Page_Down") == 0) || (key_sym.compare("KP_Page_Down") == 0)) {
 
463
                switch (this->View->GetInteractionStyle()) {
 
464
                        /*
 
465
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
466
                                this->StartWindowLevel();
 
467
                                this->SetWindowStep(0.0);
 
468
                                this->SetLevelStep(-40.0 / size[1]);
 
469
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
470
                                this->EndWindowLevel();
 
471
                                break;
 
472
                        */
 
473
                        case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
474
                                this->StartZSliceMove();
 
475
                                this->ZSliceStep = -10;
 
476
                                this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
477
                                this->EndZSliceMove();
 
478
                                break;
 
479
 
 
480
                        case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
481
                                this->StartDolly();
 
482
                                factor = -20.0;
 
483
                                //this->Dolly(pow((double)1.1, factor));
 
484
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
485
                                this->EndDolly();
 
486
                                break;
 
487
 
 
488
                        case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
489
                                this->StartDolly();
 
490
                                factor = -20.0;
 
491
                                //this->Dolly(pow((double)1.1, factor));
 
492
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
493
                                this->EndDolly();
 
494
                                break;
 
495
 
 
496
                        default:
 
497
                                break;
 
498
                }
 
499
 
 
500
        } else if ((key_sym.compare("Page_Up") == 0) || (key_sym.compare("KP_Page_Up") == 0)) {
 
501
                switch (this->View->GetInteractionStyle()) {
 
502
                        /*
 
503
                        case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
504
                                this->StartWindowLevel();
 
505
                                this->SetWindowStep(0.0);
 
506
                                this->SetLevelStep(40.0 / size[1]);
 
507
                                this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
508
                                this->EndWindowLevel();
 
509
                                break;
 
510
                        */
 
511
                        case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
512
                                this->StartZSliceMove();
 
513
                                this->ZSliceStep = 10;
 
514
                                this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
515
                                this->EndZSliceMove();
 
516
                                break;
 
517
 
 
518
                        case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
519
                                this->StartDolly();
 
520
                                factor = 20.0;
 
521
                                //this->Dolly(pow((double)1.1, factor));
 
522
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
523
                                this->EndDolly();
 
524
                                break;
 
525
 
 
526
                        case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
527
                                this->StartDolly();
 
528
                                factor = 20.0;
 
529
                                //this->Dolly(pow((double)1.1, factor));
 
530
                                this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
531
                                this->EndDolly();
 
532
                                break;
 
533
 
 
534
                        default:
 
535
                                break;
 
536
                }
 
537
        }
 
538
 
 
539
 
 
540
 
 
541
        vtkAssemblyPath *path = 0;
 
542
        vtkAbstractPropPicker *picker = 0;
 
543
 
 
544
        switch (rwi->GetKeyCode()) {
 
545
 
 
546
                case 'f':
 
547
                case 'F':
 
548
                {
 
549
                        this->AnimState = VTKIS_ANIM_ON;
 
550
                        this->FindPokedRenderer(rwi->GetEventPosition()[0],
 
551
                                                rwi->GetEventPosition()[1]);
 
552
                        rwi->GetPicker()->Pick(rwi->GetEventPosition()[0],
 
553
                                                rwi->GetEventPosition()[1], 0.0,
 
554
                                                this->CurrentRenderer);
 
555
                        picker = vtkAbstractPropPicker::SafeDownCast(rwi->GetPicker());
 
556
                        if (picker) {
 
557
                                path = picker->GetPath();
 
558
                        }
 
559
                        if (path) {
 
560
                                rwi->FlyToImage(this->CurrentRenderer, picker->GetPickPosition());
 
561
                        }
 
562
                        this->AnimState = VTKIS_ANIM_OFF;
 
563
                        break;
 
564
                }
 
565
 
 
566
                case 'r':
 
567
                case 'R':
 
568
                        /*
 
569
                        if (this->View->GetLeftButtonInteractionStyle() == vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION ||
 
570
                                                this->View->GetRightButtonInteractionStyle() == vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION ||
 
571
                                                this->View->GetMiddleButtonInteractionStyle() == vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION ||
 
572
                                                this->View->GetWheelInteractionStyle() == vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION) {
 
573
                                this->InvokeEvent(vtkCommand::ResetWindowLevelEvent, this);
 
574
                        }
 
575
                        */
 
576
                        if (this->View->GetLeftButtonInteractionStyle() == vtkGinkgoImageViewer::SELECT_INTERACTION ||
 
577
                                                this->View->GetRightButtonInteractionStyle() == vtkGinkgoImageViewer::SELECT_INTERACTION ||
 
578
                                                this->View->GetMiddleButtonInteractionStyle() == vtkGinkgoImageViewer::SELECT_INTERACTION ||
 
579
                                                this->View->GetWheelInteractionStyle() == vtkGinkgoImageViewer::SELECT_INTERACTION) {
 
580
                                this->InvokeEvent(GinkgoImageCommand::ResetPositionEvent, this);
 
581
                        }
 
582
                        if (this->View->GetLeftButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION ||
 
583
                                                this->View->GetRightButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION ||
 
584
                                                this->View->GetMiddleButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION ||
 
585
                                                this->View->GetWheelInteractionStyle() == vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION) {
 
586
                                this->InvokeEvent(GinkgoImageCommand::ResetPositionEvent, this);
 
587
                                this->InvokeEvent(GinkgoImageCommand::ResetZoomEvent, this);
 
588
                        }
 
589
                        if (this->View->GetLeftButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_INTERACTION ||
 
590
                                                this->View->GetRightButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_INTERACTION ||
 
591
                                                this->View->GetMiddleButtonInteractionStyle() == vtkGinkgoImageViewer::ZOOM_INTERACTION ||
 
592
                                                this->View->GetWheelInteractionStyle() == vtkGinkgoImageViewer::ZOOM_INTERACTION) {
 
593
                                this->InvokeEvent(GinkgoImageCommand::ResetZoomEvent, this);
 
594
                        }
 
595
 
 
596
                        break;
 
597
        }
 
598
 
 
599
}
 
600
 
 
601
//----------------------------------------------------------------------------
 
602
 
 
603
void
 
604
GinkgoInteractorStyleImage2D::StartZSliceMove()
 
605
{
 
606
        if ((this->State != VTKIS_NONE) && (this->State != VTKIS_PICK)) {
 
607
                return;
 
608
        }
 
609
        this->StartState(VTKIS_ZSLICE_MOVE);
 
610
        this->InvokeEvent(GinkgoImageCommand::StartZSliceMoveEvent, this);
 
611
}
 
612
 
 
613
void
 
614
GinkgoInteractorStyleImage2D::ZSliceMove()
 
615
{
 
616
        vtkRenderWindowInteractor *rwi = this->Interactor;
 
617
        int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
 
618
        this->ZSliceStep = dy;
 
619
        this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
620
}
 
621
 
 
622
void
 
623
GinkgoInteractorStyleImage2D::ZSliceWheelForward()
 
624
{
 
625
        int dy = (int) this->MouseWheelMotionFactor;
 
626
        this->ZSliceStep = dy;
 
627
        this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
628
}
 
629
 
 
630
void
 
631
GinkgoInteractorStyleImage2D::ZSliceWheelBackward()
 
632
{
 
633
        int dy = (int) (-1.0 * this->MouseWheelMotionFactor);
 
634
        this->ZSliceStep = dy;
 
635
        this->InvokeEvent(GinkgoImageCommand::ZSliceMoveEvent, this);
 
636
}
 
637
 
 
638
void
 
639
GinkgoInteractorStyleImage2D::EndZSliceMove()
 
640
{
 
641
        if (this->State != VTKIS_ZSLICE_MOVE) {
 
642
                return;
 
643
        }
 
644
        this->InvokeEvent(GinkgoImageCommand::EndZSliceMoveEvent, this);
 
645
        this->StopState();
 
646
}
 
647
 
 
648
//----------------------------------------------------------------------------
 
649
 
 
650
void
 
651
GinkgoInteractorStyleImage2D::FullPage()
 
652
{
 
653
        this->InvokeEvent(GinkgoImageCommand::FullPageEvent, this);
 
654
}
 
655
 
 
656
//----------------------------------------------------------------------------
 
657
 
 
658
void
 
659
GinkgoInteractorStyleImage2D::StartMeasure()
 
660
{
 
661
        if (this->State != VTKIS_NONE) {
 
662
                return;
 
663
        }
 
664
        this->StartState(VTKIS_MEASURE);
 
665
        this->InvokeEvent(GinkgoImageCommand::StartMeasureEvent, this);
 
666
}
 
667
 
 
668
void
 
669
GinkgoInteractorStyleImage2D::Measure()
 
670
{
 
671
        this->InvokeEvent(GinkgoImageCommand::MeasureEvent, this);
 
672
}
 
673
 
 
674
void
 
675
GinkgoInteractorStyleImage2D::EndMeasure()
 
676
{
 
677
        if (this->State != VTKIS_MEASURE) {
 
678
                return;
 
679
        }
 
680
        this->InvokeEvent(GinkgoImageCommand::EndMeasureEvent, this);
 
681
        this->StopState();
 
682
}
 
683
//----------------------------------------------------------------------------
 
684
 
 
685
void
 
686
GinkgoInteractorStyleImage2D::WindowLevel()
 
687
{
 
688
        vtkRenderWindowInteractor *rwi = this->Interactor;
 
689
 
 
690
        this->WindowLevelCurrentPosition[0] = rwi->GetEventPosition()[0];
 
691
        this->WindowLevelCurrentPosition[1] = rwi->GetEventPosition()[1];
 
692
 
 
693
        int *size = this->View->GetRenderWindow()->GetSize();
 
694
 
 
695
        // Compute normalized delta
 
696
        double dx = 4.0 *
 
697
                                (this->GetWindowLevelCurrentPosition()[0] -
 
698
                                this->GetWindowLevelStartPosition()[0]) / size[0];
 
699
        double dy = 4.0 *
 
700
                                (this->GetWindowLevelStartPosition()[1] -
 
701
                                this->GetWindowLevelCurrentPosition()[1]) / size[1];
 
702
 
 
703
        this->SetWindowStep(dx);
 
704
        this->SetLevelStep(dy);
 
705
 
 
706
        this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
707
}
 
708
 
 
709
void
 
710
GinkgoInteractorStyleImage2D::WindowLevelWheelForward()
 
711
{
 
712
        int *size = this->View->GetRenderWindow()->GetSize();
 
713
 
 
714
        double dy = 4.0 * (double) (this->MouseWheelMotionFactor) / size[1];
 
715
 
 
716
        this->SetWindowStep(0.0);
 
717
        this->SetLevelStep(dy);
 
718
 
 
719
        this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
720
}
 
721
 
 
722
void
 
723
GinkgoInteractorStyleImage2D::WindowLevelWheelBackward()
 
724
{
 
725
        int *size = this->View->GetRenderWindow()->GetSize();
 
726
 
 
727
        double dy = 4.0 * (double) (-1.0 * this->MouseWheelMotionFactor) / size[1];
 
728
 
 
729
        this->SetWindowStep(0.0);
 
730
        this->SetLevelStep(dy);
 
731
 
 
732
        this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
 
733
}
 
734
//----------------------------------------------------------------------------
 
735
 
 
736
void GinkgoInteractorStyleImage2D::OnMouseWheelForward()
 
737
{
 
738
 
 
739
        int x = this->Interactor->GetEventPosition()[0];
 
740
        int y = this->Interactor->GetEventPosition()[1];
 
741
 
 
742
        double factor = 0.0;
 
743
 
 
744
        this->FindPokedRenderer(x, y);
 
745
 
 
746
        if (this->CurrentRenderer == NULL) {
 
747
                return;
 
748
        }
 
749
 
 
750
        switch (this->View->GetWheelInteractionStyle()) {
 
751
                /*
 
752
                case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
753
                        this->StartWindowLevel();
 
754
                        this->WindowLevelWheelForward();
 
755
                        this->EndWindowLevel();
 
756
                        break;          
 
757
                */
 
758
                case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
759
                        this->StartZSliceMove();
 
760
                        this->ZSliceWheelForward();
 
761
                        this->EndZSliceMove();
 
762
                        break;
 
763
                case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
764
                        this->StartDolly();
 
765
                        factor = 10.0 * 0.2 * this->MouseWheelMotionFactor;
 
766
                        //this->Dolly(pow((double)1.1, factor));
 
767
                        this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
768
                        this->EndDolly();
 
769
                        break;
 
770
                /*
 
771
                case vtkGinkgoImageViewer::FULL_PAGE_INTERACTION :
 
772
 
 
773
                        break;
 
774
                */
 
775
                case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
776
                        this->StartDolly();
 
777
                        factor = 10.0 * 0.2 * this->MouseWheelMotionFactor;
 
778
                        //this->Dolly(pow((double)1.1, factor));
 
779
                        this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
780
                        this->EndDolly();
 
781
                        break;
 
782
 
 
783
                default:
 
784
                        break;
 
785
        }
 
786
 
 
787
}
 
788
 
 
789
void GinkgoInteractorStyleImage2D::OnMouseWheelBackward()
 
790
{
 
791
        int x = this->Interactor->GetEventPosition()[0];
 
792
        int y = this->Interactor->GetEventPosition()[1];
 
793
 
 
794
        double factor = 0.0;
 
795
 
 
796
        this->FindPokedRenderer(x, y);
 
797
 
 
798
        if (this->CurrentRenderer == NULL) {
 
799
                return;
 
800
        }
 
801
 
 
802
 
 
803
        switch (this->View->GetWheelInteractionStyle()) {
 
804
                /*
 
805
                case vtkGinkgoImageViewer::WINDOW_LEVEL_INTERACTION :
 
806
                        this->StartWindowLevel();
 
807
                        this->WindowLevelWheelBackward();
 
808
                        this->EndWindowLevel();
 
809
                        break;
 
810
                */
 
811
                case vtkGinkgoImageViewer::SELECT_INTERACTION :
 
812
                        this->StartZSliceMove();
 
813
                        this->ZSliceWheelBackward();
 
814
                        this->EndZSliceMove();
 
815
                        break;
 
816
                        break;
 
817
                case vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION :
 
818
                        this->StartDolly();
 
819
                        factor = 10.0 * -0.2 * this->MouseWheelMotionFactor;
 
820
                        //this->Dolly(pow((double)1.1, factor));
 
821
                        this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
822
                        this->EndDolly();
 
823
                        break;
 
824
                        /*
 
825
                case vtkGinkgoImageViewer::FULL_PAGE_INTERACTION :
 
826
 
 
827
                        break;
 
828
                */
 
829
                case vtkGinkgoImageViewer::ZOOM_INTERACTION :
 
830
                        this->StartDolly();
 
831
                        factor = 10.0 * -0.2 * this->MouseWheelMotionFactor;
 
832
                        //this->Dolly(pow((double)1.1, factor));
 
833
                        this->View->SyncSetZoom(pow((double) 1.1, factor) * this->View->GetZoom());
 
834
                        this->EndDolly();
 
835
                        break;
 
836
 
 
837
                default:
 
838
                        break;
 
839
        }
 
840
 
 
841
}
 
842
 
 
843
 
 
844