VTK
vtkImagePlaneWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkImagePlaneWidget.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
100 #ifndef vtkImagePlaneWidget_h
101 #define vtkImagePlaneWidget_h
102 
103 #include "vtkInteractionWidgetsModule.h" // For export macro
104 #include "vtkPolyDataSourceWidget.h"
105 
106 class vtkActor;
108 class vtkDataSetMapper;
109 class vtkImageData;
110 class vtkImageMapToColors;
111 class vtkImageReslice;
112 class vtkLookupTable;
113 class vtkMatrix4x4;
114 class vtkPlaneSource;
115 class vtkPoints;
116 class vtkPolyData;
117 class vtkProperty;
118 class vtkTextActor;
119 class vtkTextProperty;
120 class vtkTexture;
121 class vtkTransform;
122 
123 #define VTK_NEAREST_RESLICE 0
124 #define VTK_LINEAR_RESLICE 1
125 #define VTK_CUBIC_RESLICE 2
126 
127 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
128 {
129 public:
133  static vtkImagePlaneWidget *New();
134 
136  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
137 
139 
142  void SetEnabled(int) VTK_OVERRIDE;
143  void PlaceWidget(double bounds[6]) VTK_OVERRIDE;
144  void PlaceWidget() VTK_OVERRIDE
145  {this->Superclass::PlaceWidget();}
146  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
147  double zmin, double zmax) VTK_OVERRIDE
148  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
150 
154  void SetInputConnection(vtkAlgorithmOutput* aout) VTK_OVERRIDE;
155 
157 
160  void SetOrigin(double x, double y, double z);
161  void SetOrigin(double xyz[3]);
162  double* GetOrigin();
163  void GetOrigin(double xyz[3]);
165 
167 
170  void SetPoint1(double x, double y, double z);
171  void SetPoint1(double xyz[3]);
172  double* GetPoint1();
173  void GetPoint1(double xyz[3]);
175 
177 
180  void SetPoint2(double x, double y, double z);
181  void SetPoint2(double xyz[3]);
182  double* GetPoint2();
183  void GetPoint2(double xyz[3]);
185 
187 
190  double* GetCenter();
191  void GetCenter(double xyz[3]);
193 
195 
198  double* GetNormal();
199  void GetNormal(double xyz[3]);
201 
205  void GetVector1(double v1[3]);
206 
210  void GetVector2(double v2[3]);
211 
215  int GetSliceIndex();
216 
220  void SetSliceIndex(int index);
221 
225  double GetSlicePosition();
226 
230  void SetSlicePosition(double position);
231 
233 
236  void SetResliceInterpolate(int);
237  vtkGetMacro(ResliceInterpolate,int);
239  { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); }
241  { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
243  { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
245 
249  vtkImageData* GetResliceOutput();
250 
252 
256  vtkSetMacro(RestrictPlaneToVolume,int);
257  vtkGetMacro(RestrictPlaneToVolume,int);
258  vtkBooleanMacro(RestrictPlaneToVolume,int);
260 
262 
267  vtkSetMacro(UserControlledLookupTable,int);
268  vtkGetMacro(UserControlledLookupTable,int);
269  vtkBooleanMacro(UserControlledLookupTable,int);
271 
273 
279  vtkSetMacro(TextureInterpolate,int);
280  vtkGetMacro(TextureInterpolate,int);
281  vtkBooleanMacro(TextureInterpolate,int);
283 
285 
289  virtual void SetTextureVisibility(int);
290  vtkGetMacro(TextureVisibility,int);
291  vtkBooleanMacro(TextureVisibility,int);
293 
302  void GetPolyData(vtkPolyData *pd);
303 
311 
316  void UpdatePlacement(void) VTK_OVERRIDE;
317 
322  vtkTexture *GetTexture();
323 
325 
331  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
332  virtual void SetColorMap(vtkImageMapToColors *);
334 
336 
340  virtual void SetPlaneProperty(vtkProperty*);
341  vtkGetObjectMacro(PlaneProperty,vtkProperty);
342  virtual void SetSelectedPlaneProperty(vtkProperty*);
343  vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
345 
347 
351  void SetPlaneOrientation(int);
352  vtkGetMacro(PlaneOrientation,int);
353  void SetPlaneOrientationToXAxes()
354  { this->SetPlaneOrientation(0); }
356  { this->SetPlaneOrientation(1); }
358  { this->SetPlaneOrientation(2); }
360 
367  void SetPicker(vtkAbstractPropPicker*);
368 
370 
377  virtual void SetLookupTable(vtkLookupTable*);
378  vtkGetObjectMacro(LookupTable,vtkLookupTable);
380 
382 
386  vtkSetMacro(DisplayText,int);
387  vtkGetMacro(DisplayText,int);
388  vtkBooleanMacro(DisplayText,int);
390 
392 
395  virtual void SetCursorProperty(vtkProperty*);
396  vtkGetObjectMacro(CursorProperty,vtkProperty);
398 
400 
403  virtual void SetMarginProperty(vtkProperty*);
404  vtkGetObjectMacro(MarginProperty,vtkProperty);
406 
408 
412  vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5);
413  vtkGetMacro(MarginSizeX, double);
414  vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5);
415  vtkGetMacro(MarginSizeY, double);
417 
419 
422  void SetTextProperty(vtkTextProperty* tprop);
423  vtkTextProperty* GetTextProperty();
425 
427 
430  virtual void SetTexturePlaneProperty(vtkProperty*);
431  vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
433 
435 
441  void SetWindowLevel(double window, double level, int copy = 0);
442  void GetWindowLevel(double wl[2]);
443  double GetWindow(){return this->CurrentWindow;}
444  double GetLevel(){return this->CurrentLevel;}
446 
451  int GetCursorData(double xyzv[4]);
452 
458  int GetCursorDataStatus();
459 
461 
465  vtkGetVectorMacro(CurrentCursorPosition,double,3);
467 
469 
474  vtkGetMacro(CurrentImageValue,double);
476 
478 
481  vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 );
482  vtkGetObjectMacro( Reslice, vtkImageReslice );
484 
486 
493  vtkSetMacro(UseContinuousCursor,int);
494  vtkGetMacro(UseContinuousCursor,int);
495  vtkBooleanMacro(UseContinuousCursor,int);
497 
499 
502  void SetInteraction(int interact);
503  vtkGetMacro(Interaction,int);
504  vtkBooleanMacro(Interaction,int);
506 
508 
511  enum
512  {
513  VTK_CURSOR_ACTION = 0,
514  VTK_SLICE_MOTION_ACTION = 1,
515  VTK_WINDOW_LEVEL_ACTION = 2
516  };
517  vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
518  vtkGetMacro(LeftButtonAction, int);
519  vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
520  vtkGetMacro(MiddleButtonAction, int);
521  vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
522  vtkGetMacro(RightButtonAction, int);
524 
526 
534  enum
535  {
536  VTK_NO_MODIFIER = 0,
537  VTK_SHIFT_MODIFIER = 1,
538  VTK_CONTROL_MODIFIER = 2
539  };
540  vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
541  vtkGetMacro(LeftButtonAutoModifier, int);
542  vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
543  vtkGetMacro(MiddleButtonAutoModifier, int);
544  vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
545  vtkGetMacro(RightButtonAutoModifier, int);
547 
548 protected:
550  ~vtkImagePlaneWidget() VTK_OVERRIDE;
551 
552  int TextureVisibility;
553 
554  int LeftButtonAction;
555  int MiddleButtonAction;
556  int RightButtonAction;
557 
558  int LeftButtonAutoModifier;
559  int MiddleButtonAutoModifier;
560  int RightButtonAutoModifier;
561 
562  enum
563  {
564  VTK_NO_BUTTON = 0,
565  VTK_LEFT_BUTTON = 1,
566  VTK_MIDDLE_BUTTON = 2,
567  VTK_RIGHT_BUTTON = 3
568  };
570 
571  // Manage the state of the widget
572  int State;
574  {
575  Start=0,
583  Outside
584  };
585 
586  // Handles the events
587  static void ProcessEvents(vtkObject* object,
588  unsigned long event,
589  void* clientdata,
590  void* calldata);
591 
592  // internal utility method that adds observers to the RenderWindowInteractor
593  // so that our ProcessEvents is eventually called. this method is called
594  // by SetEnabled as well as SetInteraction
595  void AddObservers();
596 
597  // ProcessEvents() dispatches to these methods.
598  virtual void OnMouseMove();
599  virtual void OnLeftButtonDown();
600  virtual void OnLeftButtonUp();
601  virtual void OnMiddleButtonDown();
602  virtual void OnMiddleButtonUp();
603  virtual void OnRightButtonDown();
604  virtual void OnRightButtonUp();
605  void OnChar() VTK_OVERRIDE;
606 
607  virtual void StartCursor();
608  virtual void StopCursor();
609  virtual void StartSliceMotion();
610  virtual void StopSliceMotion();
611  virtual void StartWindowLevel();
612  virtual void StopWindowLevel();
613 
614  // controlling ivars
615  int Interaction; // Is the widget responsive to mouse events
616  int PlaneOrientation;
617  int RestrictPlaneToVolume;
618  double OriginalWindow;
619  double OriginalLevel;
620  double CurrentWindow;
621  double CurrentLevel;
622  double InitialWindow;
623  double InitialLevel;
624  int StartWindowLevelPositionX;
625  int StartWindowLevelPositionY;
626  int ResliceInterpolate;
627  int TextureInterpolate;
628  int UserControlledLookupTable;
629  int DisplayText;
630 
631  // The geometric represenation of the plane and it's outline
632  vtkPlaneSource *PlaneSource;
633  vtkPolyData *PlaneOutlinePolyData;
634  vtkActor *PlaneOutlineActor;
635  void HighlightPlane(int highlight);
636  void GeneratePlaneOutline();
637 
638  // Re-builds the plane outline based on the plane source
639  void BuildRepresentation();
640 
641  // Do the picking
642  vtkAbstractPropPicker *PlanePicker;
643 
644  // Register internal Pickers within PickingManager
645  void RegisterPickers() VTK_OVERRIDE;
646 
647  // for negative window values.
648  void InvertTable();
649 
650  // Methods to manipulate the plane
651  void WindowLevel(int X, int Y);
652  void Push(double *p1, double *p2);
653  void Spin(double *p1, double *p2);
654  void Rotate(double *p1, double *p2, double *vpn);
655  void Scale(double *p1, double *p2, int X, int Y);
656  void Translate(double *p1, double *p2);
657 
658  vtkImageData *ImageData;
659  vtkImageReslice *Reslice;
660  vtkMatrix4x4 *ResliceAxes;
662  vtkActor *TexturePlaneActor;
664  vtkTexture *Texture;
665  vtkLookupTable *LookupTable;
666  vtkLookupTable *CreateDefaultLookupTable();
667 
668  // Properties used to control the appearance of selected objects and
669  // the manipulator in general. The plane property is actually that for
670  // the outline. The TexturePlaneProperty can be used to control the
671  // lighting etc. of the resliced image data.
672  vtkProperty *PlaneProperty;
673  vtkProperty *SelectedPlaneProperty;
674  vtkProperty *CursorProperty;
675  vtkProperty *MarginProperty;
676  vtkProperty *TexturePlaneProperty;
677  void CreateDefaultProperties();
678 
679  // Reslice and texture management
680  void UpdatePlane();
681  void GenerateTexturePlane();
682 
683  // The cross-hair cursor
684  vtkPolyData *CursorPolyData;
685  vtkActor *CursorActor;
686  double CurrentCursorPosition[3];
687  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
688  void GenerateCursor();
689  void UpdateCursor(int,int);
690  void ActivateCursor(int);
691  int UpdateContinuousCursor(double *q);
692  int UpdateDiscreteCursor(double *q);
693  int UseContinuousCursor;
694 
695  // The text to display W/L, image data
696  vtkTextActor *TextActor;
697  char TextBuff[128];
698  void GenerateText();
699  void ManageTextDisplay();
700  void ActivateText(int);
701 
702  // Oblique reslice control
703  double RotateAxis[3];
704  double RadiusVector[3];
705  void AdjustState();
706 
707  // Visible margins to assist user interaction
708  vtkPolyData *MarginPolyData;
709  vtkActor *MarginActor;
710  int MarginSelectMode;
711  void GenerateMargins();
712  void UpdateMargins();
713  void ActivateMargins(int);
714  double MarginSizeX;
715  double MarginSizeY;
716 
717 private:
718  vtkImagePlaneWidget(const vtkImagePlaneWidget&) VTK_DELETE_FUNCTION;
719  void operator=(const vtkImagePlaneWidget&) VTK_DELETE_FUNCTION;
720 };
721 
722 #endif
#define VTK_CUBIC_RESLICE
void SetPlaneOrientationToZAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
virtual vtkPolyDataAlgorithm * GetPolyDataAlgorithm()=0
Returns underlying vtkPolyDataAlgorithm that determines geometry.
void SetResliceInterpolateToCubic()
Set the interpolation to use when texturing the plane.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
abstract base class for most VTK objects
Definition: vtkObject.h:53
#define VTK_LINEAR_RESLICE
abstract PolyDataSource-based 3D widget
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
double GetLevel()
Set/Get the current window and level values.
represent surface properties of a geometric object
Definition: vtkProperty.h:58
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
Handles the char widget activation event.
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
map scalar values into colors via a lookup table
void PlaceWidget() override
Methods that satisfy the superclass' API.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:54
void PlaceWidget() override
Overrides vtk3DWidget PlaceWidget() so that it doesn't complain if there's no Input and no Prop3D...
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
virtual void SetInputConnection(vtkAlgorithmOutput *)
Specify the input dataset.
void SetResliceInterpolateToNearestNeighbour()
Set the interpolation to use when texturing the plane.
Proxy object to connect input/output ports.
An actor that displays text.
Definition: vtkTextActor.h:50
map vtkDataSet and derived classes to graphics primitives
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:33
#define VTK_NEAREST_RESLICE
void SetPlaneOrientationToYAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
map the input image through a lookup table
handles properties associated with a texture map
Definition: vtkTexture.h:64
represent text properties.
Reslices a volume along a new set of axes.
create an array of quadrilaterals located in a plane
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstract API for pickers that can pick an instance of vtkProp
3D widget for reslicing image data
double GetWindow()
Set/Get the current window and level values.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual void OnChar()
Sets up the keypress-i event.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void PlaceWidget()
This method is used to initially place the widget.
void SetResliceInterpolateToLinear()
Set the interpolation to use when texturing the plane.
represent and manipulate 3D points
Definition: vtkPoints.h:33
Transform
Definition: ADIOSDefs.h:39