GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkViewImage2D.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 
68 #include "vtkViewImage2D.h"
69 
70 #include "vtkSmartPointer.h"
71 
72 #include "vtkCamera.h"
73 #include "vtkCommand.h"
74 #include "vtkImageActor.h"
75 #include "vtkImageData.h"
76 #include "vtkImageMapToWindowLevelColors.h"
77 #include "vtkInteractorStyleImage.h"
78 #include "vtkObjectFactory.h"
79 #include "vtkRenderWindow.h"
80 #include "vtkRenderWindowInteractor.h"
81 #include "vtkRenderer.h"
82 #include "vtkMatrix4x4.h"
83 #include "vtkTransform.h"
84 #include "vtkScalarBarActor.h"
86 #include "vtkCornerAnnotation.h"
87 #include "vtkTextProperty.h"
88 #include "vtkLookupTable.h"
89 #include "vtkMath.h"
90 #include "vtkPlane.h"
91 #include "vtkPlaneCutter.h"
92 // #include "vtkQuadricLODActor.h"
93 #include "vtkActor.h"
94 #include "vtkPolyDataMapper.h"
95 #include "vtkPoints.h"
96 #include "vtkIdList.h"
97 #include "vtkOutlineSource.h"
98 #include "vtkMatrixToLinearTransform.h"
99 #include "vtkPointData.h"
100 #include "vtkUnsignedCharArray.h"
101 #include "vtkIntArray.h"
102 #include "vtkImageAccumulate.h"
104 #include "vtkViewImage2DCommand.h"
105 #include "vtkProperty.h"
107 #include <vtkViewImage2DCommand.h>
108 #include <vtkProperty2D.h>
109 #include <vtkAxisActor2D.h>
110 #include <vtkCursor2D.h>
111 #include <vtkPointHandleRepresentation2D.h>
112 
113 #include <vtkExtractPolyDataGeometry.h>
114 
115 #include <vector>
116 #include <string>
117 #include <sstream>
118 #include <cmath>
119 
120 vtkCxxRevisionMacro(vtkViewImage2D, "$Revision: 541 $");
122 
123 //----------------------------------------------------------------------------
125 {
126  this->ConventionMatrix = vtkMatrix4x4::New();
127  this->SliceImplicitPlane = vtkSmartPointer< vtkPlane >::New();
128  this->SlicePlane = vtkPolyData::New();
131 
132  this->Command->SetViewer(this);
133 
134  this->SliceImplicitPlane->SetOrigin(0, 0, 0);
135  this->SliceImplicitPlane->SetNormal(0, 0, 1);
136 
139  this->ViewCenter[0] = this->ViewCenter[1] = this->ViewCenter[2] = 0;
140 
141  this->ConventionMatrix->Zero();
142  this->ConventionMatrix->SetElement(2, 0, 1);
143  this->ConventionMatrix->SetElement(2, 1, 1);
144  this->ConventionMatrix->SetElement(1, 2, -1);
145  this->ConventionMatrix->SetElement(0, 3, 1);
146  this->ConventionMatrix->SetElement(1, 3, -1);
147  this->ConventionMatrix->SetElement(2, 3, -1);
148 
149  this->OrientationAnnotation->SetTextProperty(this->TextProperty);
150  this->Renderer->AddViewProp (this->OrientationAnnotation);
151 
152  this->CursorGenerator = vtkCursor2D::New();
153  this->CursorGenerator->AllOff();
154  this->CursorGenerator->AxesOn();
155  this->CursorGenerator->SetRadius(3);
156  this->CursorGenerator->SetModelBounds (-40, 40, -40, 40, 0, 0);
157 
158  this->Cursor = vtkPointHandleRepresentation2D::New();
159  this->Cursor->ActiveRepresentationOff();
160  this->Cursor->SetCursorShape( this->CursorGenerator->GetOutput() );
161  this->Cursor->GetProperty()->SetColor (0.9, 0.9, 0.1);
162  this->Cursor->SetVisibility (0);
163 
164  this->Renderer->AddViewProp(this->Cursor);
165 
166  this->ShowAnnotationsOn();
167  this->InitializeSlicePlane();
168  this->Zoom = 1.;
169  this->Slice = -1;
170 }
171 
172 //----------------------------------------------------------------------------
175 {
176  this->ConventionMatrix->Delete();
177  this->SlicePlane->Delete();
178  this->Command->Delete();
179  this->OrientationAnnotation->Delete();
180 
181  this->Cursor->Delete();
182  this->CursorGenerator->Delete();
183 }
184 
185 //----------------------------------------------------------------------------
186 void
188 {
190  || convention == this->ViewConvention )
191  {
192  return;
193  }
194 
195  this->ViewConvention = convention;
196 
197  this->ConventionMatrix->SetElement(2, 0, 1);
198  this->ConventionMatrix->SetElement(2, 1, 1);
199  this->ConventionMatrix->SetElement(1, 2, -1);
200 
201  int x_watcher, y_watcher, z_watcher;
202 
203  switch ( convention )
204  {
205  default:
207  {
208  x_watcher = 1;
209  y_watcher = -1;
210  z_watcher = -1;
211  break;
212  }
214  {
215  x_watcher = 1;
216  y_watcher = 1;
217  z_watcher = 1;
218  break;
219  }
221  // view ?
223  // of
225  }
226  this->ConventionMatrix->SetElement(0, 3, x_watcher);
227  this->ConventionMatrix->SetElement(1, 3, y_watcher);
228  this->ConventionMatrix->SetElement(2, 3, z_watcher);
229 
230  this->UpdateOrientation();
231 }
232 
233 //----------------------------------------------------------------------------
234 void
235 vtkViewImage2D::SetShowAnnotations(const int & iShowAnnotations)
236 {
237  this->Superclass::SetShowAnnotations (iShowAnnotations);
238  this->OrientationAnnotation->SetVisibility (iShowAnnotations);
239 }
240 
241 //----------------------------------------------------------------------------
242 void
244 {
247  if ( ( orientation < vtkViewImage2D::VIEW_ORIENTATION_SAGITTAL )
248  || orientation == this->ViewOrientation )
249  {
250  return;
251  }
252 
253  this->ViewOrientation = orientation;
254  unsigned int sliceorientation = 2;
255  double dot = 0;
256  for ( unsigned int i = 0; i < 3; i++ )
257  {
258  if ( dot < fabs( this->GetOrientationMatrix()->GetElement(orientation, i) ) )
259  {
260  dot = fabs( this->GetOrientationMatrix()->GetElement(orientation, i) );
261  sliceorientation = i;
262  }
263  }
264  this->SetSliceOrientation(sliceorientation);
265 }
266 
267 //----------------------------------------------------------------------------
268 void
270 {
271  this->Superclass::SetOrientationMatrix(matrix);
272  this->UpdateOrientation();
273 }
274 
275 //----------------------------------------------------------------------------
276 void
278 {
279  vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints >::New();
280  this->SlicePlane->SetPoints(points);
281  points->InsertNextPoint(0, 0, 0);
282  points->InsertNextPoint(1, 0, 0);
283  points->InsertNextPoint(0, 1, 0);
284  points->InsertNextPoint(1, 1, 0);
285  this->SlicePlane->Allocate(4);
286 
287  vtkIdType pts[4];
288  pts[0] = 0; pts[1] = 1; pts[2] = 3; pts[3] = 2;
289  this->SlicePlane->InsertNextCell(VTK_QUAD, 4, pts);
290  pts[0] = 0; pts[1] = 2; pts[2] = 3; pts[3] = 1;
291  this->SlicePlane->InsertNextCell(VTK_QUAD, 4, pts);
292 
293  vtkSmartPointer< vtkUnsignedCharArray > array =
294  vtkSmartPointer< vtkUnsignedCharArray >::New();
295  array->SetName("Colors");
296  array->SetNumberOfComponents(3);
297  unsigned char vals[3];
298  vals[0] = 255; vals[1] = 0; vals[2] = 0;
299  array->InsertNextTupleValue(vals);
300  array->InsertNextTupleValue(vals);
301  array->InsertNextTupleValue(vals);
302  array->InsertNextTupleValue(vals);
303 
304  this->SlicePlane->GetPointData()->SetScalars(array);
305 }
306 
307 //----------------------------------------------------------------------------
308 void
310 {
311  this->Superclass::UpdateOrientation();
312  this->PostUpdateOrientation();
313 }
314 
315 //----------------------------------------------------------------------------
316 void
318 {
319  this->SetSlice( this->GetSliceForWorldCoordinates(pos) );
320 }
321 
322 //----------------------------------------------------------------------------
323 int
325 {
326  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
327 
328  if ( !cam )
329  {
330  return -1;
331  }
332 
333  double position[4], focalpoint[4], viewup[4];
334 
335  double conventionposition[4];
336  conventionposition[0] = 0.;
337  conventionposition[1] = 0.;
338  conventionposition[2] = 0.;
339  conventionposition[3] = 0.;
340 
341  double conventionview[4];
342  double focaltoposition[3];
343  double abs_focaltoposition[3];
344  std::vector< double * > viewupchoices;
345  double first[3], second[3], third[3], fourth[3];
346 
347  // First recover information from the camera.
348  // Recover also information from the convention matrix
349  unsigned int i;
350  for ( i = 0; i < 3; i++ )
351  {
352  position[i] = cam->GetPosition()[i];
353  focalpoint[i] = cam->GetFocalPoint()[i];
354  conventionposition[i] = this->ConventionMatrix->GetElement(i, 3);
355  conventionview[i] = this->ConventionMatrix->GetElement(i,
356  this->SliceOrientation);
357  }
358 
359  position[3] = 1;
360  focalpoint[3] = 1;
361  conventionview[3] = 0;
362  viewup[3] = 0;
363 
364  // Apply the orientation matrix to all this information
365  this->GetOrientationMatrix()->MultiplyPoint(position, position);
366  this->GetOrientationMatrix()->MultiplyPoint(focalpoint, focalpoint);
367  this->GetOrientationMatrix()->MultiplyPoint(conventionview, conventionview);
368  this->GetOrientationMatrix()->MultiplyPoint(conventionposition,
369  conventionposition);
370 
371  // Compute the vector perpendicular to the view
372  for ( i = 0; i < 3; i++ )
373  {
374  focaltoposition[i] = position[i] - focalpoint[i];
375  abs_focaltoposition[i] = fabs(focaltoposition[i]);
376  }
377 
378  // Deal with the position :
379  // invert it if necessary( symetry among the focal point)
380  if ( vtkMath::Dot(focaltoposition, conventionposition) < 0 )
381  {
382  for ( i = 0; i < 3; i++ )
383  {
384  position[i] -= 2 * focaltoposition[i];
385  }
386  }
387 
388  // Now we now we have 4 choices for the View-Up information
389  for ( i = 0; i < 3; i++ )
390  {
391  first[i] = conventionview[i];
392  second[i] = -conventionview[i];
393  }
394 
395  vtkMath::Cross(first, focaltoposition, third);
396  vtkMath::Cross(second, focaltoposition, fourth);
397  vtkMath::Normalize(third);
398  vtkMath::Normalize(fourth);
399 
400  viewupchoices.push_back(first);
401  viewupchoices.push_back(second);
402  viewupchoices.push_back(third);
403  viewupchoices.push_back(fourth);
404 
405  // To choose between these choices, first we find the axis
406  // the closest to the focaltoposition vector
407  unsigned int id = 0;
408  double dot = 0;
409  for ( i = 0; i < 3; i++ )
410  {
411  if ( dot < fabs(focaltoposition[i]) )
412  {
413  dot = fabs(focaltoposition[i]);
414  id = i;
415  }
416  }
417 
418  // Then we choose the convention matrix vector correspondant to the
419  // one we just found
420  for ( i = 0; i < 3; i++ )
421  {
422  conventionview[i] = this->ConventionMatrix->GetElement(i, id);
423  }
424 
425  // Then we pick from the 4 solutions the closest to the
426  // vector just found
427  unsigned int id2 = 0;
428  double dot2 = 0;
429  for ( i = 0; i < viewupchoices.size(); i++ )
430  {
431  if ( dot2 < vtkMath::Dot(viewupchoices[i], conventionview) )
432  {
433  dot2 = vtkMath::Dot(viewupchoices[i], conventionview);
434  id2 = i;
435  }
436  }
437 
438  // We found the solution
439  for ( i = 0; i < 3; i++ )
440  {
441  viewup[i] = viewupchoices[id2][i];
442  }
443 
444  cam->SetPosition(position[0], position[1], position[2]);
445  cam->SetFocalPoint(focalpoint[0], focalpoint[1], focalpoint[2]);
446  cam->SetViewUp(viewup[0], viewup[1], viewup[2]);
447 
448  this->SliceImplicitPlane->SetNormal(abs_focaltoposition);
449 
450  double view_plane_normal[3];
451  cam->GetViewPlaneNormal(view_plane_normal);
452 
453  // Rotation of the( Anterior-Posterior)( Ventral-Dorsal) View
454  if ( this->ViewOrientation == 0 )
455  {
456  cam->Roll(-90.);
457  }
458 
459  return id;
460 }
461 
462 //----------------------------------------------------------------------------
463 void
465 {
466  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
467 
468  if ( !cam )
469  {
470  return;
471  }
472 
473  std::string solution[4];
474 
476 
477  double *viewup = cam->GetViewUp();
478  double *normal = cam->GetViewPlaneNormal();
479  double rightvector[3];
480  vtkMath::Cross(normal, viewup, rightvector);
481 
482  unsigned int id1 = 0;
483  unsigned int id2 = 0;
484  // unsigned int id3 = 0;
485  double dot1 = 0;
486  double dot2 = 0;
487  double dot3 = 0;
488 
489  for ( unsigned int i = 0; i < 3; i++ )
490  {
491  if ( dot1 <= fabs(viewup[i]) )
492  {
493  dot1 = fabs(viewup[i]);
494  id1 = i;
495  }
496  if ( dot2 <= fabs(rightvector[i]) )
497  {
498  dot2 = fabs(rightvector[i]);
499  id2 = i;
500  }
501  if ( dot3 <= fabs(normal[i]) )
502  {
503  dot3 = fabs(normal[i]);
504  // id3 = i;
505  }
506  }
507 
508  if ( viewup[id1] > 0 )
509  {
510  solution[3] = this->DirectionAnnotationMatrix[id1][0];
511  solution[1] = this->DirectionAnnotationMatrix[id1][1];
512  }
513  else
514  {
515  solution[3] = this->DirectionAnnotationMatrix[id1][1];
516  solution[1] = this->DirectionAnnotationMatrix[id1][0];
517  }
518  if ( rightvector[id2] > 0 )
519  {
520  solution[0] = this->DirectionAnnotationMatrix[id2][0];
521  solution[2] = this->DirectionAnnotationMatrix[id2][1];
522  }
523  else
524  {
525  solution[0] = this->DirectionAnnotationMatrix[id2][1];
526  solution[2] = this->DirectionAnnotationMatrix[id2][0];
527  }
528 
529  for ( unsigned int i = 0; i < 4; i++ )
530  {
531  this->OrientationAnnotation->SetText( i, solution[i].c_str() );
532  }
533 }
534 
535 //----------------------------------------------------------------------------
536 void
538 {
539  unsigned char vals[3] = { 0, 0, 0 };
540 
541  vals[axis] = 255;
542 
543  vtkUnsignedCharArray *array = vtkUnsignedCharArray::SafeDownCast(
544  this->SlicePlane->GetPointData()->GetScalars() );
545 
546  if ( !array )
547  {
548  return;
549  }
550 
551  array->SetTupleValue(0, vals);
552  array->SetTupleValue(1, vals);
553  array->SetTupleValue(2, vals);
554  array->SetTupleValue(3, vals);
555 }
556 
557 //----------------------------------------------------------------------------
558 void
560 {
561  if ( slice != this->Slice )
562  {
563  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
564 
565  if ( !cam )
566  {
567  return;
568  }
569 
570  this->Superclass::SetSlice(slice);
571  this->UpdateSlicePlane();
572  }
573 }
574 
575 //----------------------------------------------------------------------------
576 void
578 {
579  vtkSmartPointer< vtkPoints > oldpoints = vtkSmartPointer< vtkPoints >::New();
580  vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints >::New();
581  double x[3];
582  double * bounds = this->ImageActor->GetDisplayBounds();
583  unsigned int added1;
584  unsigned int added2;
585 
586  for ( unsigned int i = 0; i < 4; i++ )
587  {
588  added1 = ( !( i % 2 ) ) ? 1 : 0;
589  added2 = ( i < 2 ) ? 1 : 0;
590  x[( this->SliceOrientation + 1 ) % 3] =
591  bounds[2 * ( ( this->SliceOrientation + 1 ) % 3 ) + added1];
592  x[( this->SliceOrientation + 2 ) % 3] =
593  bounds[2 * ( ( this->SliceOrientation + 2 ) % 3 ) + added2];
594  x[this->SliceOrientation] = bounds[2 * this->SliceOrientation];
595  oldpoints->InsertPoint(i, x);
596  }
597 
598  this->OrientationTransform->TransformPoints(oldpoints, points);
599  this->SlicePlane->SetPoints(points);
600 
601  points->GetPoint(0, x);
602  this->SliceImplicitPlane->SetOrigin(x);
603 }
604 
605 //----------------------------------------------------------------------------
606 double *
608 {
609  int xy[2] = { x, y };
610 
612 }
613 
614 //----------------------------------------------------------------------------
615 int
617 {
618  int *indices = this->GetImageCoordinatesFromWorldCoordinates(pos);
619  int slice = indices[this->SliceOrientation];
620 
621  delete[] indices;
622 
623  return slice;
624 }
625 
626 //----------------------------------------------------------------------------
627 double *
629 {
630  int indices[3] = { slice, slice, slice };
631 
632  return this->GetWorldCoordinatesFromImageCoordinates(indices);
633 }
634 
635 //----------------------------------------------------------------------------
636 
637 //----------------------------------------------------------------------------
638 void
640 {
641  if ( !this->GetInput() )
642  {
643  return;
644  }
645 
646  int *range = this->GetSliceRange();
647  if ( range )
648  {
649  this->SetSlice( ( range[1] + range[0] ) / 2 );
650  }
651 }
652 
653 //----------------------------------------------------------------------------
654 void
656 {
657  this->Zoom = 1.;
658 
659  double bounds[6];
660  this->GetInput()->GetBounds(bounds);
661 
662  double focal[3];
663  focal[0] = 0.5 * ( bounds[0] + bounds[1] );
664  focal[1] = 0.5 * ( bounds[2] + bounds[3] );
665  focal[2] = 0.5 * ( bounds[4] + bounds[5] );
666 
667  double pos[3];
668  pos[0] = focal[0];
669  pos[1] = focal[1];
670  pos[2] = focal[2];
671 
672  double length[3];
673  length[0] = 0.5 * ( bounds[1] - bounds[0] );
674  length[1] = 0.5 * ( bounds[3] - bounds[2] );
675  length[2] = 0.5 * ( bounds[5] - bounds[4] );
676 
677  double radius = 0.75 * sqrt(length[0] * length[0]
678  + length[1] * length[1]
679  + length[2] * length[2]);
680 
681  vtkCamera *camera = this->GetRenderer()->GetActiveCamera();
682  double distance =
683  radius / sin(camera->GetViewAngle() * vtkMath::Pi() / 360.0);
684 
685  double view_plane_normal[3];
686  camera->GetViewPlaneNormal(view_plane_normal);
687  double *vup = camera->GetViewUp();
688 
689  if ( fabs( vtkMath::Dot(vup, view_plane_normal) ) > 0.999 )
690  {
691  vtkWarningMacro(<< "Resetting view-up since view plane normal is parallel");
692  camera->SetViewUp(-vup[2], vup[0], vup[1]);
693  }
694 
695  pos[0] += distance * view_plane_normal[0];
696  pos[1] += distance * view_plane_normal[1];
697  pos[2] += distance * view_plane_normal[2];
698 
699  this->SetCameraFocalAndPosition(focal, pos);
700 
701  double max_length = std::max( length[0], std::max(length[1], length[2]) );
702  bounds[0] = focal[0] - 50. * max_length;
703  bounds[1] = focal[0] + 50. * max_length;
704  bounds[2] = focal[1] - 50. * max_length;
705  bounds[3] = focal[1] + 50. * max_length;
706  bounds[4] = focal[2] - 50. * max_length;
707  bounds[5] = focal[2] + 50. * max_length;
708  this->GetRenderer()->ResetCameraClippingRange(bounds);
709 
710  camera->SetParallelScale(radius);
711 }
712 
713 //----------------------------------------------------------------------------
714 void
716 {
717  //this->ResetPosition();
718  //this->ResetWindowLevel();
719  //this->ResetCamera();
720 }
721 
722 //----------------------------------------------------------------------------
723 void
724 vtkViewImage2D::SetCameraFocalAndPosition(double focal[3], double pos[3])
725 {
726  vtkRenderer *ren = this->GetRenderer();
727 
728  if ( !ren )
729  {
730  return;
731  }
732  vtkCamera *camera = ren->GetActiveCamera();
733 
734  if ( !camera )
735  {
736  return;
737  }
738 
739  camera->SetFocalPoint(focal[0], focal[1], focal[2]);
740  camera->SetPosition(pos[0], pos[1], pos[2]);
741 }
742 
743 //----------------------------------------------------------------------------
744 void
745 vtkViewImage2D::GetCameraFocalAndPosition(double focal[3], double pos[3])
746 {
747  vtkRenderer *ren = this->GetRenderer();
748 
749  if ( !ren )
750  {
751  return;
752  }
753  vtkCamera *camera = ren->GetActiveCamera();
754 
755  if ( !camera )
756  {
757  return;
758  }
759 
760  camera->GetPosition(pos);
761  camera->GetFocalPoint(focal);
762 }
763 
764 //----------------------------------------------------------------------------
765 double *
767 {
768  // in one case this function creates an array and don't manage it
769  // in another case, it gives a pointer to a managed array :
770  // MEMORY LEAKS
771 
772  if ( !this->GetInput() || !this->GetRenderer() )
773  {
774  // case 1 : non managed array pointer
775  double *nullpos = new double[3];
776  nullpos[0] = 0; nullpos[1] = 0; nullpos[2] = 0;
777  return nullpos;
778  }
779 
780  double *slicepos = this->GetWorldCoordinatesForSlice( this->GetSlice() );
781  this->GetRenderer()->SetWorldPoint(slicepos[0], slicepos[1], slicepos[2],
782  1.0);
783  this->GetRenderer()->WorldToDisplay();
784  this->GetRenderer()->SetDisplayPoint(xy[0], xy[1],
785  this->GetRenderer()->GetDisplayPoint()[2]);
786  this->GetRenderer()->DisplayToWorld();
787  // think about deleting the temporary created array
788  delete[] slicepos;
789 
790  // case 2 : pointer to managed array
791  return this->GetRenderer()->GetWorldPoint();
792 }
793 
794 //----------------------------------------------------------------------------
795 void
797 {
798  if ( this->RenderWindow && this->Renderer )
799  {
800  if ( !this->RenderWindow->HasRenderer(this->Renderer) )
801  {
802  this->RenderWindow->AddRenderer(this->Renderer);
803  }
804  }
805 
806  if ( this->Interactor )
807  {
808  if ( !this->InteractorStyle )
809  {
810  this->InteractorStyle = vtkInteractorStyleImage2D::New();
811  this->Interactor->SetInteractorStyle(this->InteractorStyle);
812  this->InteractorStyle->AddObserver(
813  vtkCommand::KeyPressEvent, this->Command);
814  this->InteractorStyle->AddObserver(
816  this->InteractorStyle->AddObserver(
818  this->InteractorStyle->AddObserver(
820  this->InteractorStyle->AddObserver(
822  this->InteractorStyle->AddObserver(
824  this->InteractorStyle->AddObserver(
826  this->InteractorStyle->AddObserver(
827  vtkCommand::InteractionEvent, this->Command);
828  this->InteractorStyle->AddObserver(
830  this->InteractorStyle->AddObserver(
832  this->InteractorStyle->AddObserver(
834 
835  this->InteractorStyle->AddObserver(
836  vtkCommand::StartWindowLevelEvent, this->Command);
837  this->InteractorStyle->AddObserver(
838  vtkCommand::WindowLevelEvent, this->Command);
839  }
840  this->InteractorStyleSwitcher = this->InteractorStyle;
841  this->Interactor->SetInteractorStyle(this->InteractorStyle);
842  this->Interactor->SetRenderWindow(this->RenderWindow);
843  }
844 
845  if ( this->Renderer && this->ImageActor )
846  {
847  this->ImageActor->SetInterpolate(false);
848  }
849 
850  if ( this->Renderer && this->ImageActor )
851  {
852  if ( !this->Renderer->GetActors()->IsItemPresent(this->ImageActor) )
853  {
854  this->Renderer->AddViewProp(this->ImageActor);
855  }
856  }
857 
858  if ( this->ImageActor && this->WindowLevel )
859  {
860  this->ImageActor->SetInput( this->WindowLevel->GetOutput() );
861  }
862 }
863 
864 //----------------------------------------------------------------------------
865 void
867 {
868  if ( this->ImageActor )
869  {
870  this->ImageActor->SetInterpolate(val);
871  }
872 }
873 
874 //----------------------------------------------------------------------------
875 int
877 {
878  if ( this->ImageActor )
879  {
880  return this->ImageActor->GetInterpolate();
881  }
882  else
883  {
884  return 0;
885  }
886 }
887 
888 //----------------------------------------------------------------------------
889 // vtkQuadricLODActor*
890 vtkActor *
891 vtkViewImage2D::AddDataSet(vtkPolyData *dataset,
892  vtkProperty *property,
893  const bool & intersection,
894  const bool & iDataVisibility)
895 {
896 // vtkCamera *cam = NULL;
897 
898  if ( !this->Renderer )
899  {
900 // cam = this->Renderer->GetActiveCamera();
901 // }
902 // else
903 // {
904  return NULL;
905  }
906 
907  if ( !dataset )
908  {
909  return NULL;
910  }
911 
912  if ( dataset->GetNumberOfPoints() <= 0 )
913  {
914  return NULL;
915  }
916 
917  vtkSmartPointer<vtkPolyDataMapper> mapper =
918  vtkSmartPointer<vtkPolyDataMapper>::New();
919  mapper->SetScalarVisibility(iDataVisibility);
920  mapper->ImmediateModeRenderingOn();
921 
922  // check if input data is 2D
923  double *bounds = dataset->GetBounds();
924  // get normal
925  double *normal = this->SliceImplicitPlane->GetNormal();
926 
927  // if in 2d
928  if ( ( ( bounds[0] == bounds[1] ) && ( normal[1] == 0 ) && ( normal[2] == 0 ) )
929  || ( ( bounds[2] == bounds[3] ) && ( normal[2] == 0 ) && ( normal[0] == 0 ) )
930  || ( ( bounds[4] == bounds[5] ) && ( normal[0] == 0 ) && ( normal[1] == 0 ) ) )
931  {
932  vtkSmartPointer<vtkExtractPolyDataGeometry> extracter =
933  vtkSmartPointer<vtkExtractPolyDataGeometry>::New();
934  extracter->SetInput(dataset);
935  extracter->SetImplicitFunction(this->SliceImplicitPlane);
936  extracter->Update();
937  mapper->SetInput( extracter->GetOutput() );
938  }
939  // i.e. if we cut a volume
940  else
941  {
942  if ( intersection )
943  {
944  vtkSmartPointer<vtkPlaneCutter> cutter =
945  vtkSmartPointer<vtkPlaneCutter>::New();
946  cutter->SetInput(dataset);
947  cutter->SetCutFunction(this->SliceImplicitPlane);
948  mapper->SetInput( cutter->GetOutput() );
949  }
950  else
951  {
952  mapper->SetInput(dataset);
953  }
954  }
955 
956  vtkActor * actor = vtkActor::New();
957  actor->SetMapper(mapper);
958 
959  if ( property )
960  {
961  actor->SetProperty(property);
962  }
963  actor->GetProperty()->BackfaceCullingOn();
964  actor->GetProperty()->SetLineWidth(this->IntersectionLineWidth);
965 
966  this->Renderer->AddViewProp(actor);
967 
968  return actor;
969 }
970 //----------------------------------------------------------------------------
971 
972 //----------------------------------------------------------------------------
973 std::map<double, vtkActor *>
975 ExtractActors(vtkPolyData *iDataSet, ORIENTATION iOrientation)
976 {
977  std::map<double, vtkActor*> contours;
978 
979  // create plane to extract contours (based on orientation)
980  double normal[3] = {0., 0., 0.};
981 
982  switch (iOrientation)
983  {
984  case XY:
985  {
986  normal[2] = 1;
987  break;
988  }
989  case XZ:
990  {
991  normal[1] = 1;
992  break;
993  }
994  case YZ:
995  {
996  normal[0] = 1;
997  break;
998  }
999  default:
1000  {
1001  break;
1002  }
1003  }
1004 
1005  double origin[3] = {0., 0., 0.};
1006  origin[0] = iDataSet->GetCenter()[0];
1007  origin[1] = iDataSet->GetCenter()[1];
1008  origin[2] = iDataSet->GetCenter()[2];
1009 
1010  double position = iDataSet->GetBounds()[4 - 2*iOrientation];
1011  double maxPosition = iDataSet->GetBounds()[5 - 2*iOrientation];
1012 
1013  /*std::cout << "position: "
1014  << position << "-"
1015  << maxPosition << std::endl;*/
1016 
1017  // get information about image (spacing)
1018  double spacing = this->GetInput()->GetSpacing()[2-iOrientation];
1019 
1020  while( position < maxPosition)
1021  {
1022  origin[2-iOrientation] = position;
1023 
1024 /*
1025  std::cout << "origin: "
1026  << origin[0] << "-"
1027  << origin[1] << "-"
1028  << origin[2] << std::endl;
1029 
1030  std::cout << "normal: "
1031  << normal[0] << "-"
1032  << normal[1] << "-"
1033  << normal[2] << std::endl;
1034  */
1035 
1036  vtkPlane* plane = vtkPlane::New();
1037  plane->SetNormal(normal);
1038  plane->SetOrigin(origin);
1039 
1040  // cut
1041  vtkCutter* cutter = vtkCutter::New();
1042  cutter->SetInput(iDataSet);
1043  cutter->SetCutFunction(plane);
1044  cutter->Update();
1045  plane->Delete();
1046 
1047  vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
1048  mapper->SetInput( cutter->GetOutput() );
1049  cutter->Delete();
1050 
1051  vtkActor* actor = vtkActor::New();
1052  actor->SetMapper(mapper);
1053  actor->VisibilityOn();
1054  mapper->Delete();
1055 
1056  contours[position] = actor;
1057 
1058  // increase position
1059  position += spacing;
1060  }
1061 
1062  return contours;
1063 }
1064 //----------------------------------------------------------------------------
1065 
1066 //----------------------------------------------------------------------------
1067 void
1069 {
1070  if ( !this->GetInput() )
1071  {
1072  return;
1073  }
1074 // vtkCamera *cam = NULL;
1075 
1076  if ( !this->Renderer )
1077  {
1078 // cam = this->Renderer->GetActiveCamera();
1079 // }
1080 // else
1081 // {
1082 // return;
1083  }
1084  int *dimensions = this->GetInput()->GetDimensions();
1085 
1086  int indices[3] = { 0, 0, 0 };
1087  for ( unsigned int i = 0; i < 3; i++ )
1088  {
1089  indices[i] = (int)( (double)dimensions[i] / 2.0 );
1090  }
1091  indices[this->SliceOrientation] = this->GetSlice();
1092 
1093  double *center = this->GetWorldCoordinatesFromImageCoordinates (indices);
1094 
1095  for ( unsigned int i = 0; i < 3; i++ )
1096  {
1097  this->ViewCenter[i] = center[i];
1098  }
1099 
1100  delete[] center;
1101 }
1102 
1103 //----------------------------------------------------------------------------
1104 void
1106 {
1107  int axis = this->SetCameraToConvention();
1108 
1109  this->ViewOrientation = axis;
1110 
1111  this->SetAnnotationToConvention();
1112  this->SetSlicePlaneToConvention(axis);
1113  this->UpdateSlicePlane();
1114 }
1115 
1116 //----------------------------------------------------------------------------
1117 void
1119 {
1123 
1124  unsigned char vals[3] = { 0, 0, 0 };
1125 
1126  vals[this->ViewOrientation] = 255;
1127  vtkUnsignedCharArray *array = vtkUnsignedCharArray::SafeDownCast ( this->SlicePlane->GetPointData()->GetScalars() );
1128  if ( !array ) { return; }
1129  array->SetTupleValue (0, vals);
1130  array->SetTupleValue (1, vals);
1131  array->SetTupleValue (2, vals);
1132  array->SetTupleValue (3, vals);
1133 
1134  this->UpdateSlicePlane();
1135 }
1136 
1137 //----------------------------------------------------------------------------
1138 int
1140 {
1141  // The camera has already been set as if the image has no orientation.
1142  // So we just have to adjust its position and view up according
1143  // to the image orientation and conventions.
1144 
1145  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1146 
1147  if ( !cam ) { return -1; }
1148 
1149  double position[4], focalpoint[4], viewup[4];
1150  double conventionposition[4];
1151  double conventionview[4];
1152  double focaltoposition[3];
1153  std::vector< double * > viewupchoices;
1154  double first[3], second[3], third[3], fourth[3];
1155  bool inverseposition;
1156 
1157  // First recover information from the camera.
1158  // Recover also information from the convention matrix
1159  for ( unsigned int i = 0; i < 3; i++ )
1160  {
1161  position[i] = cam->GetPosition()[i];
1162  focalpoint[i] = cam->GetFocalPoint()[i];
1163  conventionposition[i] = this->ConventionMatrix->GetElement (i, 3);
1164  conventionview[i] = this->ConventionMatrix->GetElement (i, this->SliceOrientation);
1165  }
1166 
1167  position[3] = 1;
1168  focalpoint[3] = 1;
1169  conventionview[3] = 0;
1170  viewup[3] = 0;
1171 
1172  // Apply the orientation matrix to all this information
1173  if ( this->GetOrientationMatrix() )
1174  {
1175  this->GetOrientationMatrix()->MultiplyPoint (position, position);
1176  this->GetOrientationMatrix()->MultiplyPoint (focalpoint, focalpoint);
1177  this->GetOrientationMatrix()->MultiplyPoint (conventionview, conventionview);
1178  this->GetOrientationMatrix()->MultiplyPoint (conventionposition, conventionposition);
1179  }
1180 
1181  // Compute the vector perpendicular to the view
1182  for ( unsigned int i = 0; i < 3; i++ )
1183  {
1184  focaltoposition[i] = position[i] - focalpoint[i];
1185  }
1186 
1187  // Deal with the position :
1188  // invert it if necessary (symetry among the focal point)
1189  inverseposition = ( vtkMath::Dot (focaltoposition, conventionposition) < 0 );
1190  if ( inverseposition )
1191  {
1192  for ( unsigned int i = 0; i < 3; i++ )
1193  {
1194  position[i] -= 2 * focaltoposition[i];
1195  }
1196  }
1197 
1198  // Now we now we have 4 choices for the View-Up information
1199  for ( unsigned int i = 0; i < 3; i++ )
1200  {
1201  first[i] = conventionview[i];
1202  second[i] = -conventionview[i];
1203  }
1204 
1205  vtkMath::Cross (first, focaltoposition, third);
1206  vtkMath::Cross (second, focaltoposition, fourth);
1207  vtkMath::Normalize (third);
1208  vtkMath::Normalize (fourth);
1209 
1210  viewupchoices.push_back (first);
1211  viewupchoices.push_back (second);
1212  viewupchoices.push_back (third);
1213  viewupchoices.push_back (fourth);
1214 
1215  // To choose between these choices, first we find the axis
1216  // the closest to the focaltoposition vector
1217  unsigned int id = 0;
1218  double dot = 0;
1219  for ( unsigned int i = 0; i < 3; i++ )
1220  {
1221  if ( dot < std::abs (focaltoposition[i]) )
1222  {
1223  dot = std::abs (focaltoposition[i]);
1224  id = i;
1225  }
1226  }
1227 
1228  // Then we choose the convention matrix vector correspondant to the
1229  // one we just found
1230  for ( unsigned int i = 0; i < 3; i++ )
1231  {
1232  conventionview[i] = this->ConventionMatrix->GetElement (i, id);
1233  }
1234 
1235  // Then we pick from the 4 solutions the closest to the
1236  // vector just found
1237  unsigned int id2 = 0;
1238  double dot2 = 0;
1239  for ( unsigned int i = 0; i < viewupchoices.size(); i++ )
1240  {
1241  if ( dot2 < vtkMath::Dot (viewupchoices[i], conventionview) )
1242  {
1243  dot2 = vtkMath::Dot (viewupchoices[i], conventionview);
1244  id2 = i;
1245  }
1246  }
1247 
1248  // We found the solution
1249  for ( unsigned int i = 0; i < 3; i++ )
1250  {
1251  viewup[i] = viewupchoices[id2][i];
1252  }
1253 
1254  cam->SetPosition(position[0], position[1], position[2]);
1255  cam->SetFocalPoint(focalpoint[0], focalpoint[1], focalpoint[2]);
1256  cam->SetViewUp(viewup[0], viewup[1], viewup[2]);
1257 
1258  return id;
1259 }
1260 
1261 //----------------------------------------------------------------------------
1262 void
1264 {
1265  // This method has to be called after the camera
1266  // has been set according to orientation and convention.
1267  // We rely on the camera settings to compute the oriention
1268  // annotations.
1269 
1270  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1271 
1272  if ( !cam ) { return; }
1273 
1274  std::string matrix[3][2];
1275  matrix[0][0] = "R"; matrix[0][1] = "L";
1276  matrix[1][0] = "A"; matrix[1][1] = "P";
1277  matrix[2][0] = "I"; matrix[2][1] = "S";
1278 
1279  std::string solution[4];
1280 
1282 
1283  double *viewup = cam->GetViewUp();
1284  double *normal = cam->GetViewPlaneNormal();
1285  double rightvector[3];
1286  vtkMath::Cross (normal, viewup, rightvector);
1287 
1288  unsigned int id1 = 0;
1289  unsigned int id2 = 0;
1290 // unsigned int id3 = 0;
1291  double dot1 = 0;
1292  double dot2 = 0;
1293  double dot3 = 0;
1294 
1295  for ( unsigned int i = 0; i < 3; i++ )
1296  {
1297  if ( dot1 <= std::abs (viewup[i]) )
1298  {
1299  dot1 = std::abs (viewup[i]);
1300  id1 = i;
1301  }
1302  if ( dot2 <= std::abs (rightvector[i]) )
1303  {
1304  dot2 = std::abs (rightvector[i]);
1305  id2 = i;
1306  }
1307  if ( dot3 <= std::abs (normal[i]) )
1308  {
1309  dot3 = std::abs (normal[i]);
1310  //id3 = i;
1311  }
1312  }
1313 
1314  if ( viewup[id1] > 0 )
1315  {
1316  solution[3] = matrix[id1][0];
1317  solution[1] = matrix[id1][1];
1318  }
1319  else
1320  {
1321  solution[3] = matrix[id1][1];
1322  solution[1] = matrix[id1][0];
1323  }
1324  if ( rightvector[id2] > 0 )
1325  {
1326  solution[0] = matrix[id2][0];
1327  solution[2] = matrix[id2][1];
1328  }
1329  else
1330  {
1331  solution[0] = matrix[id2][1];
1332  solution[2] = matrix[id2][0];
1333  }
1334 
1335  for ( unsigned int i = 0; i < 4; i++ )
1336  {
1337  this->OrientationAnnotation->SetText ( i, solution[i].c_str() );
1338  }
1339 
1340  if ( this->GetInput() )
1341  {
1342  // naively the X and Y axes of the current view
1343  // correspond to the rightvector and the viewup respectively.
1344  // But in fact we have to put those vectors back in the image
1345  // coordinates and see to which xyz image axis they correspond.
1346 
1347  double Xaxis[4] = { 0, 0, 0, 0 };
1348  double Yaxis[4] = { 0, 0, 0, 0 };
1349  for ( unsigned int i = 0; i < 3; i++ )
1350  {
1351  Xaxis[i] = rightvector[i];
1352  Yaxis[i] = viewup[i];
1353  }
1354 
1355  vtkMatrix4x4 *inverse = vtkMatrix4x4::New();
1356  inverse->Identity();
1357  if ( this->GetOrientationMatrix() )
1358  {
1359  vtkMatrix4x4::Invert (this->GetOrientationMatrix(), inverse);
1360  }
1361 
1362  inverse->MultiplyPoint (Xaxis, Xaxis);
1363  inverse->MultiplyPoint (Yaxis, Yaxis);
1364  inverse->Delete();
1365 
1366  double dotX = 0;
1367  double dotY = 0;
1368  int idX, idY;
1369  idX = idY = 0;
1370 
1371  for ( unsigned int i = 0; i < 3; i++ )
1372  {
1373  if ( dotX <= std::abs (Xaxis[i]) )
1374  {
1375  dotX = std::abs (Xaxis[i]);
1376  idX = i;
1377  }
1378  if ( dotY <= std::abs (Yaxis[i]) )
1379  {
1380  dotY = std::abs (Yaxis[i]);
1381  idY = i;
1382  }
1383  }
1384 
1385  int * dimensions = this->GetInput()->GetDimensions();
1386  double *spacing = this->GetInput()->GetSpacing();
1387 
1388  sprintf(this->ImageInformation,
1389  "Image Size: %i x %i\nVoxel Size: %g x %g mm",
1390  dimensions[idX], dimensions[idY],
1391  spacing[idX], spacing[idY]);
1392  sprintf(this->SliceAndWindowInformation,
1393  "<slice_and_max>\n<window>\n<level>");
1394 
1395  this->CornerAnnotation->SetText(2, this->ImageInformation);
1396  this->CornerAnnotation->SetText(3, this->SliceAndWindowInformation);
1397  }
1398 }
1399 
1400 //----------------------------------------------------------------------------
1401 void
1403 {
1404  vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1405 
1406  if ( !cam ) { return; }
1407 
1408  double *position = cam->GetPosition();
1409  double *focalpoint = cam->GetFocalPoint();
1410 
1411  double focaltoposition[3];
1412 
1413  unsigned int i;
1414 
1415  // Compute the vector perpendicular to the view
1416  for ( i = 0; i < 3; i++ )
1417  {
1418  focaltoposition[i] = fabs(position[i] - focalpoint[i]);
1419  }
1420 
1421  this->SliceImplicitPlane->SetNormal (focaltoposition);
1422 }
1423 
1424 //----------------------------------------------------------------------------
1425 void
1427 {
1428  this->GetRenderer()->SetWorldPoint (this->CurrentPoint[0], this->CurrentPoint[1], this->CurrentPoint[2], 0);
1429  this->GetRenderer()->WorldToDisplay();
1430 
1431  double *xy = this->GetRenderer()->GetDisplayPoint();
1432  this->GetCursor()->SetDisplayPosition (xy);
1433 
1434  char os[128];
1435  sprintf(os,
1436  "%s\nXYZ: %4.2f, %4.2f, %4.2f mm\nValue: %g",
1437  this->ImageInformation,
1438  this->CurrentPoint[0], this->CurrentPoint[1], this->CurrentPoint[2],
1439  this->GetValueAtPosition (this->CurrentPoint)
1440  );
1441  this->CornerAnnotation->SetText(2, os);
1442 }
void SetCameraFocalAndPosition(double focal[3], double pos[3])
Set camera focal point and position.
vtkMatrix4x4 * ConventionMatrix
char SliceAndWindowInformation[64]
virtual double * GetWorldCoordinatesFromDisplayPosition(int xy[2])
Useful method that transform a display position into a world corrdinate point.
float IntersectionLineWidth
Definition: vtkViewImage.h:554
void SetViewer(vtkViewImage2D *viewer)
Set the 2d image related to this 2d event manager.
virtual double * GetWorldCoordinatesFromImageCoordinates(int indices[3])
Convert an indices coordinate point (image coordinates) into a world coordinate point.
vtkSmartPointer< vtkPlane > SliceImplicitPlane
virtual int GetSliceForWorldCoordinates(double pos[3])
Convert a world coordinate point into an image indices coordinate point.
virtual void ResetCamera(void)
Reset the camera in a nice way for the 2D view.
virtual void SetViewOrientation(int orientation)
vtkTextProperty * TextProperty
Definition: vtkViewImage.h:535
virtual void SetOrientationMatrix(vtkMatrix4x4 *matrix)
virtual int SetCameraToConvention(void)
static vtkInteractorStyleImage2D * New()
Convenient method to access the constructor.
virtual int SetCameraFromOrientation(void)
char ImageInformation[64]
virtual double GetValueAtPosition(double worldcoordinates[3], int component=0)
Get the pixel value at a given world coordinate point in space, return zero if out of bounds...
virtual double * GetWorldCoordinatesForSlice(int slice)
Convert an indices coordinate point (image coordinates) into a world coordinate point.
virtual void SetAnnotationsFromOrientation(void)
vtkViewImage2DCommand * Command
Access to the command of the viewer. This instance is in charge of observing the interactorstyle (Get...
void GetCameraFocalAndPosition(double focal[3], double pos[3])
Set camera focal point and position.
virtual void InitializeSlicePlane(void)
This method is called each time the orientation changes (SetViewOrientation()) and sets the appropria...
vtkPointHandleRepresentation2D * Cursor
Access to the actor corresponding to the cursor. It follows the mouse cursor everywhere it goes...
virtual void SetSlicePlaneFromOrientation(void)
virtual vtkActor * AddDataSet(vtkPolyData *polydata, vtkProperty *property=NULL, const bool &intersection=true, const bool &iDataVisibility=false)
Add a dataset to the view (has to be subclass of vtkPointSet). The dataset will be cut through the im...
virtual void SetShowAnnotations(const int &iShowAnnotations)
Set the annotation visibility.
virtual int * GetImageCoordinatesFromWorldCoordinates(double position[3])
Convert a world coordinate point into an image indices coordinate point.
virtual void SetWorldCoordinates(double pos[3])
The world is not always what we think it is ... Use this method to move the viewer slice such that th...
virtual void UpdateCenter(void)
static vtkOrientationAnnotation * New()
Convenient method to access the constructor. Instantiate object with a rectangle in normaled view coo...
std::string DirectionAnnotationMatrix[3][2]
Definition: vtkViewImage.h:552
virtual void UpdateOrientation()
virtual void PostUpdateOrientation(void)
vtkStandardNewMacro(vtkViewImage2D)
virtual void UpdateSlicePlane(void)
virtual void SetImplicitPlaneFromOrientation(void)
After the orientation has changed, it is crucial to adapt a couple of things according to new orienta...
virtual void Reset(void)
Reset position - zoom - window/level to default.
virtual void SetSlice(int s)
Set/Get the current slice to display (depending on the orientation this can be in X...
vtkOrientationAnnotation * OrientationAnnotation
Get the orientation annotation. This annotation describes the orientation of the slice plane...
virtual int GetInterpolate()
Get whether or not the interpolation between pixels should be activated. It is Off by default...
virtual void UpdateCursor(void)
Update the cursor position and the CornerAnnotation (top-left) according to current mouse position...
std::map< double, vtkActor * > ExtractActors(vtkPolyData *iDataSet, ORIENTATION iOrientation)
vtkMatrixToLinearTransform * OrientationTransform
Definition: vtkViewImage.h:550
virtual void InstallPipeline(void)
Overwrite of the Superclass InstallPipeline() method in order to set up the home made InteractorStyle...
vtkCornerAnnotation * CornerAnnotation
Definition: vtkViewImage.h:530
virtual void ResetPosition(void)
Reset the 3D position to center.
static vtkViewImage2DCommand * New()
Convenient method to access the constructor.
vtkCxxRevisionMacro(vtkViewImage2D,"$Revision: 541 $")
virtual void SetViewConvention(int convention)
double CurrentPoint[3]
Definition: vtkViewImage.h:566
vtkCursor2D * CursorGenerator
Access to the actor corresponding to the cursor. It follows the mouse cursor everywhere it goes...
virtual void SetInterpolate(const int &val)
Set whether or not the interpolation between pixels should be activated. It is Off by default...
virtual void SetAnnotationToConvention(void)
virtual void SetSlicePlaneToConvention(unsigned int axis)
vtkPolyData * SlicePlane
This polydata instance is a square colored (see InitializeSlicePlane()) according to the orientation ...
vtkInteractorStyle * InteractorStyleSwitcher
Basic class to handle 2D/3D items such as images and polydatas visualization in 2D.
double ViewCenter[3]