GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkViewImage2DCollectionCommand.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Author: $Author:$ // Author of last commit
3  Version: $Rev:$ // Revision of last commit
4  Date: $Date:$ // Date of last commit
5 =========================================================================*/
6 
7 /*=========================================================================
8  Authors: The GoFigure Dev. Team.
9  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
10 
11  Copyright (c) 2009-11, President and Fellows of Harvard College.
12  All rights reserved.
13 
14  Redistribution and use in source and binary forms, with or without
15  modification, are permitted provided that the following conditions are met:
16 
17  Redistributions of source code must retain the above copyright notice,
18  this list of conditions and the following disclaimer.
19  Redistributions in binary form must reproduce the above copyright notice,
20  this list of conditions and the following disclaimer in the documentation
21  and/or other materials provided with the distribution.
22  Neither the name of the President and Fellows of Harvard College
23  nor the names of its contributors may be used to endorse or promote
24  products derived from this software without specific prior written
25  permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
31  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
36  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 =========================================================================*/
42 #include "vtkViewImage2DCommand.h"
43 #include "vtkRenderer.h"
44 #include "vtkCamera.h"
45 #include "vtkMath.h"
46 #include "vtkRenderWindow.h"
47 #include "vtkRenderWindowInteractor.h"
48 #include "vtkCellPicker.h"
50 
51 //--------------------------------------------------------------------------
53 {
54  m_SynchronizeViews = true;
55 }
56 
57 //--------------------------------------------------------------------------
60 {
61 }
62 
63 //--------------------------------------------------------------------------
64 
65 //--------------------------------------------------------------------------
66 void
68 {
69  this->Collection = p;
70 }
71 
72 //--------------------------------------------------------------------------
73 
74 //--------------------------------------------------------------------------
77 {
79 }
80 
81 //--------------------------------------------------------------------------
82 
83 //--------------------------------------------------------------------------
86 {
87  return this->Collection;
88 }
89 
90 //--------------------------------------------------------------------------
91 void
93 {
94  m_SynchronizeViews = iSynchronizeViews;
95 }
96 
97 //--------------------------------------------------------------------------
99  unsigned long event,
100  void *vtkNotUsed(callData) )
101 {
102  if ( !this->Collection )
103  {
104  return;
105  }
106 
107  if( !m_SynchronizeViews )
108  {
109  return;
110  }
111 
112  if ( event == vtkCommand::EndInteractionEvent )
113  {
114  this->Collection->SyncRender();
115  return;
116  }
117 
119  vtkInteractorStyleImage2D::SafeDownCast(caller);
120  this->GetCollection()->InitTraversal();
121  vtkViewImage2D *v = this->GetCollection()->GetNextItem();
122  vtkViewImage2D *viewer = NULL;
123  while ( v )
124  {
125  if ( isi == v->GetInteractorStyle() )
126  {
127  viewer = v;
128  break;
129  }
130  v = this->GetCollection()->GetNextItem();
131  }
132 
133  if ( !isi || !viewer || !viewer->GetInput() )
134  {
135  return;
136  }
137 
138  // Reset
139  if ( event == vtkCommand::ResetWindowLevelEvent )
140  {
142  this->Collection->SyncRender();
143  return;
144  }
145  // Reset
147  {
148  this->Collection->SyncReset();
149  this->Collection->SyncRender();
150  return;
151  }
152 
153  // Adjust the window level here
154  if ( event == vtkCommand::WindowLevelEvent )
155  {
156  this->Collection->SyncSetColorWindow( viewer->GetColorWindow() );
157  this->Collection->SyncSetColorLevel( viewer->GetColorLevel() );
158  this->Collection->SyncRender();
159  }
160 
161  // Move
163  {
164  this->Collection->SyncRender();
165  }
166 
167  if ( event == vtkViewImage2DCommand::ZoomEvent )
168  {
169  double z = viewer->GetZoom();
170  double parallel_scale =
171  viewer->GetRenderer()->GetActiveCamera()->GetParallelScale();
172 
173  this->Collection->SyncSetZoomAndParallelScale(z, parallel_scale);
174  }
175 
176  if ( event == vtkViewImage2DCommand::PanEvent )
177  {
178  double motion[3];
179  viewer->GetCameraMotionVector(motion);
180 
181  this->GetCollection()->InitTraversal();
182  v = this->GetCollection()->GetNextItem();
183  double focal[3], pos[3], n[3];
184  double dot = 0., u;
185 
186  while ( v )
187  {
188  if ( v != viewer )
189  {
190  v->GetCameraFocalAndPosition(focal, pos);
191  v->GetRenderer()->GetActiveCamera()->GetViewPlaneNormal(n);
192  dot = vtkMath::Dot(n, motion);
193 
194  for ( int dim = 0; dim < 3; dim++ )
195  {
196  u = motion[dim] - dot * n[dim];
197  focal[dim] += u;
198  pos[dim] += u;
199  }
200  v->SetCameraFocalAndPosition(focal, pos);
201 
202  if ( v->GetInteractorStyle()->GetInteractor()->GetLightFollowCamera() )
203  {
204  v->GetRenderer()->UpdateLightsGeometryToFollowCamera();
205  }
206  }
207  v->Render();
208  v = this->GetCollection()->GetNextItem();
209  }
210  }
211 
212  // Position requested
214  {
215  double *position = viewer->GetWorldCoordinatesFromDisplayPosition (
216  isi->GetRequestedPosition () );
217  this->Collection->SyncSetWorldCoordinates(position);
218  this->Collection->SyncRender();
219  }
220 }
void SetCameraFocalAndPosition(double focal[3], double pos[3])
Set camera focal point and position.
virtual void SyncResetWindowLevel(void)
Description: Synchronize reset window level between views.
Manage events occuring in a 2D view and apply it to a collection.
virtual double * GetWorldCoordinatesFromDisplayPosition(int xy[2])
Useful method that transform a display position into a world corrdinate point.
void GetCameraFocalAndPosition(double focal[3], double pos[3])
Set camera focal point and position.
Define the interactor behavior withing a vtkImage2D. 4 modes (Default, Zoom, Pan and Pick) ...
virtual void SyncReset(void)
Description: Synchronize reset between views.
virtual void SyncRender()
Description: Synchronize render between views.
Manage a collection of 2D views.
virtual void Execute(vtkObject *caller, unsigned long event, void *vtkNotUsed(callData))
void SyncSetZoomAndParallelScale(double Zoom, double ParallelScale)
void SetCollection(vtkViewImage2DCollection *p)
Set the current collection.
virtual void Render(void)
virtual vtkRenderWindowInteractor * GetInteractor()
void SynchronizeViews(bool iSynchronizeViews)
Synchronize the 2d views.
static vtkViewImage2DCollectionCommand * New()
Convenient method to access the constructor.
Basic class to handle 2D/3D items such as images and polydatas visualization in 2D.
vtkViewImage2DCollection * GetCollection()
Get the current collection.