GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkInteractorStyleImage3D.cxx
Go to the documentation of this file.
1 /*========================================================================
2  Copyright (c) INRIA - ASCLEPIOS Project (http://www-sop.inria.fr/asclepios).
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of INRIA or ASCLEPIOS, nor the names of any contributors
16  may be used to endorse or promote products derived from this software
17  without specific prior written permission.
18 
19  * Modified source versions must be plainly marked as such, and must not be
20  misrepresented as being the original software.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
26  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  =========================================================================*/
33 
34 /*=========================================================================
35  Modifications were made by the GoFigure Dev. Team.
36  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
37 
38  Copyright (c) 2009-11, President and Fellows of Harvard College.
39  All rights reserved.
40 
41  Redistribution and use in source and binary forms, with or without
42  modification, are permitted provided that the following conditions are met:
43 
44  Redistributions of source code must retain the above copyright notice,
45  this list of conditions and the following disclaimer.
46  Redistributions in binary form must reproduce the above copyright notice,
47  this list of conditions and the following disclaimer in the documentation
48  and/or other materials provided with the distribution.
49  Neither the name of the President and Fellows of Harvard College
50  nor the names of its contributors may be used to endorse or promote
51  products derived from this software without specific prior written
52  permission.
53 
54  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
56  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
58  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
59  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
60  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
61  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
62  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
63  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
64  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 
66  =========================================================================*/
67 
69 
70 #include <vtkObjectFactory.h>
71 #include <vtkRenderWindowInteractor.h>
72 #include "vtkRenderer.h"
73 #include "vtkProperty.h"
74 #include "vtkViewImage3DCommand.h"
75 
76 #include <vtkProp.h>
77 
78 // For picking
79 #include "vtkAbstractPropPicker.h"
80 #include "vtkAssemblyPath.h"
81 
84 
85 //----------------------------------------------------------------------------
87 {
89 
90  m_State = false;
91 }
92 
93 //----------------------------------------------------------------------------
96 {
97 }
98 
99 //----------------------------------------------------------------------------
100 void
102 {
103  switch ( this->State )
104  {
105  case VTKIS_PICK3D:
107  break;
108  }
109 
110  this->Superclass::OnMouseMove();
111 }
112 
113 //----------------------------------------------------------------------------
114 void
116 {
117  switch ( this->m_Mode )
118  {
119  case InteractionTypeZoom:
120  this->InvokeEvent(vtkViewImage3DCommand::ZoomEvent);
121  this->Superclass::OnRightButtonDown();
122  break;
123  case InteractionTypePan:
124  this->InvokeEvent(vtkViewImage3DCommand::PanEvent);
125  this->Superclass::OnMiddleButtonDown();
126  break;
128  this->SetCurrentProp(this->CurrentProp);
129  this->InvokeEvent(vtkViewImage3DCommand::MeshPickingEvent);
130  this->State = VTKIS_NONE;
131  this->Superclass::OnLeftButtonDown();
132  break;
133  default:
134  this->Superclass::OnLeftButtonDown();
135  break;
136  }
137 }
138 
139 //----------------------------------------------------------------------------
140 void
142 {
143  switch ( this->m_Mode )
144  {
145  case InteractionTypeZoom:
146  this->Superclass::OnRightButtonUp();
147  break;
148  case InteractionTypePan:
149  this->Superclass::OnMiddleButtonUp();
150  break;
152  this->State = VTKIS_NONE;
153  this->StartPick();
154  break;
155  default:
156  this->Superclass::OnLeftButtonUp();
157  break;
158  }
159 }
160 
161 //----------------------------------------------------------------------------
162 void
164 {
165  switch ( this->m_Mode )
166  {
167  case InteractionTypePan:
168  this->Superclass::OnMiddleButtonDown();
169  break;
171  this->State = VTKIS_NONE;
172  this->Superclass::OnRightButtonDown();
173  break;
174  default:
175  this->Superclass::OnRightButtonDown();
176  break;
177  }
178 }
179 
180 //----------------------------------------------------------------------------
181 void
183 {
184  switch ( this->m_Mode )
185  {
186  case InteractionTypePan:
187  this->Superclass::OnMiddleButtonUp();
188  break;
190  this->State = VTKIS_NONE;
191  this->StartPick();
192  break;
193  default:
194  this->Superclass::OnRightButtonUp();
195  break;
196  }
197 }
198 
199 //----------------------------------------------------------------------------
200 void
202 {
203  switch ( this->m_Mode )
204  {
205  case InteractionTypeZoom:
206  this->Superclass::OnRightButtonDown();
207  break;
209  this->State = VTKIS_NONE;
210  this->Superclass::OnMiddleButtonDown();
211  break;
212  default:
213  this->Superclass::OnMiddleButtonDown();
214  break;
215  }
216 }
217 
218 //----------------------------------------------------------------------------
219 void
221 {
222  switch ( this->m_Mode )
223  {
224  case InteractionTypeZoom:
225  this->Superclass::OnRightButtonUp();
226  break;
228  this->State = VTKIS_NONE;
229  this->StartPick();
230  break;
231  default:
232  this->Superclass::OnMiddleButtonUp();
233  break;
234  }
235 }
236 //----------------------------------------------------------------------------
237 void
239 {
240  vtkRenderWindowInteractor *rwi = this->Interactor;
241 
242  if ( ( rwi->GetKeyCode() == 'w' ) || ( rwi->GetKeyCode() == 'W' ) )
243  {
244  vtkActorCollection *ac;
245  vtkActor *anActor, *aPart;
246  vtkAssemblyPath *path;
247  this->FindPokedRenderer(rwi->GetEventPosition()[0],
248  rwi->GetEventPosition()[1]);
249  if(this->CurrentRenderer!=0)
250  {
251  ac = this->CurrentRenderer->GetActors();
252  vtkCollectionSimpleIterator ait;
253  for (ac->InitTraversal(ait); (anActor = ac->GetNextActor(ait)); )
254  {
255  for (anActor->InitPathTraversal(); (path=anActor->GetNextPath()); )
256  {
257 
258  // make sure we don't modify the planes actors
259  if ( path != NULL )
260  {
261  std::vector< vtkProp3D * >::iterator it2 = m_PlanesActors.begin();
262  while(it2!=m_PlanesActors.end())
263  {
264  if(path && dynamic_cast<vtkProp*>(*it2) == path->GetLastNode()->GetViewProp())
265  {
266  path = NULL;
267  }
268  ++it2;
269  }
270  }
271 
272  // go on if target is not a plane
273  if(path)
274  {
275  aPart=static_cast<vtkActor *>(path->GetLastNode()->GetViewProp());
276  aPart->GetProperty()->SetRepresentationToWireframe();
277  }
278  }
279  }
280  }
281  else
282  {
283  vtkWarningMacro(<<"no current renderer on the interactor style.");
284  }
285  rwi->Render();
286  return;
287  }
288  else if ( ( rwi->GetKeyCode() == 's' ) || ( rwi->GetKeyCode() == 'S' ) )
289  {
290  vtkActorCollection *ac;
291  vtkActor *anActor, *aPart;
292  vtkAssemblyPath *path;
293  this->FindPokedRenderer(rwi->GetEventPosition()[0],
294  rwi->GetEventPosition()[1]);
295  if(this->CurrentRenderer!=0)
296  {
297  ac = this->CurrentRenderer->GetActors();
298  vtkCollectionSimpleIterator ait;
299  for (ac->InitTraversal(ait); (anActor = ac->GetNextActor(ait)); )
300  {
301  for (anActor->InitPathTraversal(); (path=anActor->GetNextPath()); )
302  {
303 
304  // make sure we don't modify the planes actors
305  if ( path != NULL )
306  {
307  std::vector< vtkProp3D * >::iterator it2 = m_PlanesActors.begin();
308  while(it2!=m_PlanesActors.end())
309  {
310  if(path && dynamic_cast<vtkProp*>(*it2) == path->GetLastNode()->GetViewProp())
311  {
312  path = NULL;
313  }
314  ++it2;
315  }
316  }
317 
318  // go on if target is not a plane
319  if(path)
320  {
321  aPart=static_cast<vtkActor *>(path->GetLastNode()->GetViewProp());
322  aPart->GetProperty()->SetRepresentationToSurface();
323  }
324  }
325  }
326  }
327  else
328  {
329  vtkWarningMacro(<<"no current renderer on the interactor style.");
330  }
331  rwi->Render();
332  return;
333  }
334 
335  this->Superclass::OnChar();
336 }
337 
338 //----------------------------------------------------------------------------
339 void
341 {
342  this->m_CurrentProp = iCurrent;
343 }
344 
345 //----------------------------------------------------------------------------
346 vtkProp *
348 {
349  return this->m_CurrentProp;
350 }
351 
352 //----------------------------------------------------------------------------
353 void
355 {
356  m_State = iState;
357 }
358 
359 //----------------------------------------------------------------------------
360 bool
362 {
363  return m_State;
364 }
365 
366 //----------------------------------------------------------------------------
367 void
369 {
370  if ( this->State != VTKIS_NONE )
371  {
372  return;
373  }
374  this->StartState(VTKIS_PICK3D);
375  this->InvokeEvent(vtkCommand::StartPickEvent, this);
376 }
377 
378 //----------------------------------------------------------------------------
379 void
381 {
382  vtkRenderWindowInteractor *rwi = this->Interactor;
383 
384  if ( this->CurrentRenderer != 0 )
385  {
386  vtkAssemblyPath *path = NULL;
387  int * eventPos = rwi->GetEventPosition();
388  this->FindPokedRenderer(eventPos[0], eventPos[1]);
389  rwi->StartPickCallback();
390  vtkAbstractPropPicker *picker =
391  vtkAbstractPropPicker::SafeDownCast( rwi->GetPicker() );
392 
393  if ( picker != NULL )
394  {
395  picker->Pick(eventPos[0], eventPos[1],
396  0.0, this->CurrentRenderer);
397  path = picker->GetPath();
398  }
399 
400  // check if item does does not belong to phantom[]
401  if ( path != NULL )
402  {
403  std::vector< vtkProp3D * >::iterator it2 = m_PlanesActors.begin();
404  while(it2!=m_PlanesActors.end())
405  {
406  if(path && dynamic_cast<vtkProp*>(*it2) == path->GetFirstNode()->GetViewProp())
407  {
408  path = NULL;
409  }
410  ++it2;
411  }
412  }
413 
414  if ( path == NULL )
415  {
416  this->HighlightProp(NULL);
417  this->PropPicked = 0;
418  }
419  else
420  {
421  this->HighlightProp( path->GetFirstNode()->GetViewProp() );
422  this->PropPicked = 1;
423  }
424  rwi->EndPickCallback();
425  }
426 }
427 
428 //----------------------------------------------------------------------------
429 void
431 {
432  this->State = VTKIS_NONE;
434  this->StartPick();
435 }
436 
437 //----------------------------------------------------------------------------
438 void
440 {
441  this->State = VTKIS_NONE;
442  this->m_Mode = InteractionTypeZoom;
443 }
444 
445 //----------------------------------------------------------------------------
446 void
448 {
449  this->State = VTKIS_NONE;
450  this->m_Mode = InteractionTypePan;
451 }
452 
453 //----------------------------------------------------------------------------
454 void
456 {
457  this->State = VTKIS_NONE;
459 }
460 //----------------------------------------------------------------------------
461 void
463 SetPlanesActors( std::vector< vtkProp3D * > iBounds)
464 {
465  this->m_PlanesActors = iBounds;
466 }
467 //----------------------------------------------------------------------------
void EnableZoomMode()
Start the Zoom Mode.
#define VTKIS_PICK3D
void EnablePickMode()
Start the Pick Mode.
void EnableDefaultMode()
Start the Default Mode.
void SetCurrentProp(vtkProp *iCurrent)
Store the actor which is pointed by the cursor into "m_CurrentProp".
void SetPlanesActors(std::vector< vtkProp3D * > iBounds)
vtkStandardNewMacro(vtkInteractorStyleImage3D)
void SetCurrentState(bool iSate)
Store the actor which is pointed by the cursor into "m_CurrentProp".
std::vector< vtkProp3D * > m_PlanesActors
bool GetCurrentState()
Store the actor which is pointed by the cursor into "m_CurrentProp".
void StartPick()
Start Pick Mode by updating the "State" and sending the "StartPickEvent".
vtkCxxRevisionMacro(vtkInteractorStyleImage3D,"$Revision: 1 $")
void HighlightCurrentActor()
Draw a bounding box around the "m_CurrentProp" (i.e. actor pointed by the mouse)
void EnablePanMode()
Start the Pan Mode.
vtkProp * GetCurrentProp()
Return the actor which is pointed by the cursor.
Define the interactor behavior withing a vtkImage3D. 4 modes (Default, Zoom, Pan and Pick) ...