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 // Private.
128 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
129 
130 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
131 {
132 public:
136  static vtkImagePlaneWidget *New();
137 
139  void PrintSelf(ostream& os, vtkIndent indent) override;
140 
142 
145  void SetEnabled(int) override;
146  void PlaceWidget(double bounds[6]) override;
147  void PlaceWidget() override
148  {this->Superclass::PlaceWidget();}
149  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
150  double zmin, double zmax) override
151  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
153 
157  void SetInputConnection(vtkAlgorithmOutput* aout) override;
158 
160 
163  void SetOrigin(double x, double y, double z);
164  void SetOrigin(double xyz[3]);
165  double* GetOrigin() VTK_SIZEHINT(3);
166  void GetOrigin(double xyz[3]);
168 
170 
173  void SetPoint1(double x, double y, double z);
174  void SetPoint1(double xyz[3]);
175  double* GetPoint1() VTK_SIZEHINT(3);
176  void GetPoint1(double xyz[3]);
178 
180 
183  void SetPoint2(double x, double y, double z);
184  void SetPoint2(double xyz[3]);
185  double* GetPoint2() VTK_SIZEHINT(3);
186  void GetPoint2(double xyz[3]);
188 
190 
193  double* GetCenter() VTK_SIZEHINT(3);
194  void GetCenter(double xyz[3]);
196 
198 
201  double* GetNormal() VTK_SIZEHINT(3);
202  void GetNormal(double xyz[3]);
204 
208  void GetVector1(double v1[3]);
209 
213  void GetVector2(double v2[3]);
214 
218  int GetSliceIndex();
219 
223  void SetSliceIndex(int index);
224 
228  double GetSlicePosition();
229 
233  void SetSlicePosition(double position);
234 
236 
239  void SetResliceInterpolate(int);
240  vtkGetMacro(ResliceInterpolate,int);
241  void SetResliceInterpolateToNearestNeighbour()
242  { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); }
244  { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
246  { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
248 
252  vtkImageData* GetResliceOutput();
253 
255 
259  vtkSetMacro(RestrictPlaneToVolume,vtkTypeBool);
260  vtkGetMacro(RestrictPlaneToVolume,vtkTypeBool);
261  vtkBooleanMacro(RestrictPlaneToVolume,vtkTypeBool);
263 
265 
270  vtkSetMacro(UserControlledLookupTable,vtkTypeBool);
271  vtkGetMacro(UserControlledLookupTable,vtkTypeBool);
272  vtkBooleanMacro(UserControlledLookupTable,vtkTypeBool);
274 
276 
282  vtkSetMacro(TextureInterpolate,vtkTypeBool);
283  vtkGetMacro(TextureInterpolate,vtkTypeBool);
284  vtkBooleanMacro(TextureInterpolate,vtkTypeBool);
286 
288 
292  virtual void SetTextureVisibility(vtkTypeBool);
293  vtkGetMacro(TextureVisibility,vtkTypeBool);
294  vtkBooleanMacro(TextureVisibility,vtkTypeBool);
296 
305  void GetPolyData(vtkPolyData *pd);
306 
314 
319  void UpdatePlacement(void) override;
320 
325  vtkTexture *GetTexture();
326 
328 
334  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
335  virtual void SetColorMap(vtkImageMapToColors *);
337 
339 
343  virtual void SetPlaneProperty(vtkProperty*);
344  vtkGetObjectMacro(PlaneProperty,vtkProperty);
345  virtual void SetSelectedPlaneProperty(vtkProperty*);
346  vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
348 
350 
354  void SetPlaneOrientation(int);
355  vtkGetMacro(PlaneOrientation,int);
357  { this->SetPlaneOrientation(0); }
359  { this->SetPlaneOrientation(1); }
361  { this->SetPlaneOrientation(2); }
363 
370  void SetPicker(vtkAbstractPropPicker*);
371 
373 
380  virtual void SetLookupTable(vtkLookupTable*);
381  vtkGetObjectMacro(LookupTable,vtkLookupTable);
383 
385 
389  vtkSetMacro(DisplayText,vtkTypeBool);
390  vtkGetMacro(DisplayText,vtkTypeBool);
391  vtkBooleanMacro(DisplayText,vtkTypeBool);
393 
395 
398  virtual void SetCursorProperty(vtkProperty*);
399  vtkGetObjectMacro(CursorProperty,vtkProperty);
401 
403 
406  virtual void SetMarginProperty(vtkProperty*);
407  vtkGetObjectMacro(MarginProperty,vtkProperty);
409 
411 
415  vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5);
416  vtkGetMacro(MarginSizeX, double);
417  vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5);
418  vtkGetMacro(MarginSizeY, double);
420 
422 
425  void SetTextProperty(vtkTextProperty* tprop);
426  vtkTextProperty* GetTextProperty();
428 
430 
433  virtual void SetTexturePlaneProperty(vtkProperty*);
434  vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
436 
438 
444  void SetWindowLevel(double window, double level, int copy = 0);
445  void GetWindowLevel(double wl[2]);
446  double GetWindow(){return this->CurrentWindow;}
447  double GetLevel(){return this->CurrentLevel;}
449 
454  int GetCursorData(double xyzv[4]);
455 
461  int GetCursorDataStatus();
462 
464 
468  vtkGetVectorMacro(CurrentCursorPosition,double,3);
470 
472 
477  vtkGetMacro(CurrentImageValue,double);
479 
481 
484  vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 );
485  vtkGetObjectMacro( Reslice, vtkImageReslice );
487 
489 
496  vtkSetMacro(UseContinuousCursor,vtkTypeBool);
497  vtkGetMacro(UseContinuousCursor,vtkTypeBool);
498  vtkBooleanMacro(UseContinuousCursor,vtkTypeBool);
500 
502 
505  void SetInteraction(vtkTypeBool interact);
506  vtkGetMacro(Interaction,vtkTypeBool);
507  vtkBooleanMacro(Interaction,vtkTypeBool);
509 
511 
514  enum
515  {
516  VTK_CURSOR_ACTION = 0,
517  VTK_SLICE_MOTION_ACTION = 1,
518  VTK_WINDOW_LEVEL_ACTION = 2
519  };
520  vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
521  vtkGetMacro(LeftButtonAction, int);
522  vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
523  vtkGetMacro(MiddleButtonAction, int);
524  vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
525  vtkGetMacro(RightButtonAction, int);
527 
529 
537  enum
538  {
539  VTK_NO_MODIFIER = 0,
540  VTK_SHIFT_MODIFIER = 1,
541  VTK_CONTROL_MODIFIER = 2
542  };
543  vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
544  vtkGetMacro(LeftButtonAutoModifier, int);
545  vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
546  vtkGetMacro(MiddleButtonAutoModifier, int);
547  vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
548  vtkGetMacro(RightButtonAutoModifier, int);
550 
551 protected:
553  ~vtkImagePlaneWidget() override;
554 
556 
560 
564 
565  enum
566  {
567  VTK_NO_BUTTON = 0,
568  VTK_LEFT_BUTTON = 1,
569  VTK_MIDDLE_BUTTON = 2,
570  VTK_RIGHT_BUTTON = 3
571  };
573 
574  // Manage the state of the widget
575  int State;
577  {
578  Start=0,
586  Outside
587  };
588 
589  // Handles the events
590  static void ProcessEvents(vtkObject* object,
591  unsigned long event,
592  void* clientdata,
593  void* calldata);
594 
595  // internal utility method that adds observers to the RenderWindowInteractor
596  // so that our ProcessEvents is eventually called. this method is called
597  // by SetEnabled as well as SetInteraction
598  void AddObservers();
599 
600  // ProcessEvents() dispatches to these methods.
601  virtual void OnMouseMove();
602  virtual void OnLeftButtonDown();
603  virtual void OnLeftButtonUp();
604  virtual void OnMiddleButtonDown();
605  virtual void OnMiddleButtonUp();
606  virtual void OnRightButtonDown();
607  virtual void OnRightButtonUp();
608  void OnChar() override;
609 
610  virtual void StartCursor();
611  virtual void StopCursor();
612  virtual void StartSliceMotion();
613  virtual void StopSliceMotion();
614  virtual void StartWindowLevel();
615  virtual void StopWindowLevel();
616 
617  // controlling ivars
618  vtkTypeBool Interaction; // Is the widget responsive to mouse events
624  double CurrentLevel;
626  double InitialLevel;
633 
634  // The geometric representation of the plane and it's outline
638  void HighlightPlane(int highlight);
639  void GeneratePlaneOutline();
640 
641  // Re-builds the plane outline based on the plane source
642  void BuildRepresentation();
643 
644  // Do the picking
646 
647  // Register internal Pickers within PickingManager
648  void RegisterPickers() override;
649 
650  // for negative window values.
651  void InvertTable();
652 
653  // Methods to manipulate the plane
654  void WindowLevel(int X, int Y);
655  void Push(double *p1, double *p2);
656  void Spin(double *p1, double *p2);
657  void Rotate(double *p1, double *p2, double *vpn);
658  void Scale(double *p1, double *p2, int X, int Y);
659  void Translate(double *p1, double *p2);
660 
669  vtkLookupTable *CreateDefaultLookupTable();
670 
671  // Properties used to control the appearance of selected objects and
672  // the manipulator in general. The plane property is actually that for
673  // the outline. The TexturePlaneProperty can be used to control the
674  // lighting etc. of the resliced image data.
680  void CreateDefaultProperties();
681 
682  // Reslice and texture management
683  void UpdatePlane();
684  void GenerateTexturePlane();
685 
686  // The cross-hair cursor
689  double CurrentCursorPosition[3];
690  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
691  void GenerateCursor();
692  void UpdateCursor(int,int);
693  void ActivateCursor(int);
694  int UpdateContinuousCursor(double *q);
695  int UpdateDiscreteCursor(double *q);
697 
698  // The text to display W/L, image data
701  void GenerateText();
702  void ManageTextDisplay();
703  void ActivateText(int);
704 
705  // Oblique reslice control
706  double RotateAxis[3];
707  double RadiusVector[3];
708  void AdjustState();
709 
710  // Visible margins to assist user interaction
714  void GenerateMargins();
715  void UpdateMargins();
716  void ActivateMargins(int);
717  double MarginSizeX;
718  double MarginSizeY;
719 
720 private:
721  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
722  void operator=(const vtkImagePlaneWidget&) = delete;
723 };
724 
725 #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:60
vtkPolyData * PlaneOutlinePolyData
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
vtkPlaneSource * PlaneSource
vtkProperty * MarginProperty
void PlaceWidget() override
Methods that satisfy the superclass' API.
vtkLookupTable * LookupTable
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.
vtkProperty * CursorProperty
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
virtual void SetInputConnection(vtkAlgorithmOutput *)
Specify the input dataset.
vtkProperty * SelectedPlaneProperty
virtual void UpdatePlacement()=0
If you've made changes to the underlying vtkPolyDataSource AFTER your initial call to PlaceWidget(),...
Proxy object to connect input/output ports.
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkImageMapToColors * ColorMap
int vtkTypeBool
Definition: vtkABI.h:69
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.
void SetPlaneOrientationToXAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
#define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF
map the input image through a lookup table
vtkProperty * TexturePlaneProperty
handles properties associated with a texture map
Definition: vtkTexture.h:65
#define VTK_SIZEHINT(...)
vtkTypeBool RestrictPlaneToVolume
represent text properties.
Reslices a volume along a new set of axes.
create an array of quadrilaterals located in a plane
vtkImageReslice * Reslice
vtkAbstractPropPicker * PlanePicker
abstract API for pickers that can pick an instance of vtkProp
3D widget for reslicing image data
vtkPolyData * MarginPolyData
double GetWindow()
Set/Get the current window and level values.
vtkMatrix4x4 * ResliceAxes
vtkPolyData * CursorPolyData
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
vtkTypeBool UserControlledLookupTable