VTK  9.0.1
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 =========================================================================*/
109 #ifndef vtkImagePlaneWidget_h
110 #define vtkImagePlaneWidget_h
111 
112 #include "vtkInteractionWidgetsModule.h" // For export macro
113 #include "vtkPolyDataSourceWidget.h"
114 
115 class vtkActor;
117 class vtkDataSetMapper;
118 class vtkImageData;
119 class vtkImageMapToColors;
120 class vtkImageReslice;
121 class vtkLookupTable;
122 class vtkMatrix4x4;
123 class vtkPlaneSource;
124 class vtkPoints;
125 class vtkPolyData;
126 class vtkProperty;
127 class vtkTextActor;
128 class vtkTextProperty;
129 class vtkTexture;
130 class vtkTransform;
131 
132 #define VTK_NEAREST_RESLICE 0
133 #define VTK_LINEAR_RESLICE 1
134 #define VTK_CUBIC_RESLICE 2
135 
136 // Private.
137 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
138 
139 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
140 {
141 public:
145  static vtkImagePlaneWidget* New();
146 
148  void PrintSelf(ostream& os, vtkIndent indent) override;
149 
151 
154  void SetEnabled(int) override;
155  void PlaceWidget(double bounds[6]) override;
156  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
158  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
159  {
160  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
161  }
163 
167  void SetInputConnection(vtkAlgorithmOutput* aout) override;
168 
170 
173  void SetOrigin(double x, double y, double z);
174  void SetOrigin(double xyz[3]);
175  double* GetOrigin() VTK_SIZEHINT(3);
176  void GetOrigin(double xyz[3]);
178 
180 
183  void SetPoint1(double x, double y, double z);
184  void SetPoint1(double xyz[3]);
185  double* GetPoint1() VTK_SIZEHINT(3);
186  void GetPoint1(double xyz[3]);
188 
190 
193  void SetPoint2(double x, double y, double z);
194  void SetPoint2(double xyz[3]);
195  double* GetPoint2() VTK_SIZEHINT(3);
196  void GetPoint2(double xyz[3]);
198 
200 
203  double* GetCenter() VTK_SIZEHINT(3);
204  void GetCenter(double xyz[3]);
206 
208 
211  double* GetNormal() VTK_SIZEHINT(3);
212  void GetNormal(double xyz[3]);
214 
218  void GetVector1(double v1[3]);
219 
223  void GetVector2(double v2[3]);
224 
228  int GetSliceIndex();
229 
233  void SetSliceIndex(int index);
234 
238  double GetSlicePosition();
239 
243  void SetSlicePosition(double position);
244 
246 
249  void SetResliceInterpolate(int);
250  vtkGetMacro(ResliceInterpolate, int);
251  void SetResliceInterpolateToNearestNeighbour()
252  {
253  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
254  }
255  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
256  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
258 
262  vtkImageData* GetResliceOutput();
263 
265 
269  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
270  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
271  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
273 
275 
280  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
281  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
282  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
284 
286 
292  vtkSetMacro(TextureInterpolate, vtkTypeBool);
293  vtkGetMacro(TextureInterpolate, vtkTypeBool);
294  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
296 
298 
302  virtual void SetTextureVisibility(vtkTypeBool);
303  vtkGetMacro(TextureVisibility, vtkTypeBool);
304  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
306 
315  void GetPolyData(vtkPolyData* pd);
316 
324 
329  void UpdatePlacement(void) override;
330 
335  vtkTexture* GetTexture();
336 
338 
344  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
345  virtual void SetColorMap(vtkImageMapToColors*);
347 
349 
353  virtual void SetPlaneProperty(vtkProperty*);
354  vtkGetObjectMacro(PlaneProperty, vtkProperty);
355  virtual void SetSelectedPlaneProperty(vtkProperty*);
356  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
358 
360 
364  void SetPlaneOrientation(int);
365  vtkGetMacro(PlaneOrientation, int);
366  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
367  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
368  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
370 
377  void SetPicker(vtkAbstractPropPicker*);
378 
380 
387  virtual void SetLookupTable(vtkLookupTable*);
388  vtkGetObjectMacro(LookupTable, vtkLookupTable);
390 
392 
396  vtkSetMacro(DisplayText, vtkTypeBool);
397  vtkGetMacro(DisplayText, vtkTypeBool);
398  vtkBooleanMacro(DisplayText, vtkTypeBool);
400 
402 
405  virtual void SetCursorProperty(vtkProperty*);
406  vtkGetObjectMacro(CursorProperty, vtkProperty);
408 
410 
413  virtual void SetMarginProperty(vtkProperty*);
414  vtkGetObjectMacro(MarginProperty, vtkProperty);
416 
418 
422  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
423  vtkGetMacro(MarginSizeX, double);
424  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
425  vtkGetMacro(MarginSizeY, double);
427 
429 
432  void SetTextProperty(vtkTextProperty* tprop);
433  vtkTextProperty* GetTextProperty();
435 
437 
440  virtual void SetTexturePlaneProperty(vtkProperty*);
441  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
443 
445 
451  void SetWindowLevel(double window, double level, int copy = 0);
452  void GetWindowLevel(double wl[2]);
453  double GetWindow() { return this->CurrentWindow; }
454  double GetLevel() { return this->CurrentLevel; }
456 
461  int GetCursorData(double xyzv[4]);
462 
468  int GetCursorDataStatus();
469 
471 
475  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
477 
479 
484  vtkGetMacro(CurrentImageValue, double);
486 
488 
491  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
492  vtkGetObjectMacro(Reslice, vtkImageReslice);
494 
496 
503  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
504  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
505  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
507 
509 
512  void SetInteraction(vtkTypeBool interact);
513  vtkGetMacro(Interaction, vtkTypeBool);
514  vtkBooleanMacro(Interaction, vtkTypeBool);
516 
518 
521  enum
522  {
523  VTK_CURSOR_ACTION = 0,
524  VTK_SLICE_MOTION_ACTION = 1,
525  VTK_WINDOW_LEVEL_ACTION = 2
526  };
527  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
528  vtkGetMacro(LeftButtonAction, int);
529  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
530  vtkGetMacro(MiddleButtonAction, int);
531  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
532  vtkGetMacro(RightButtonAction, int);
534 
536 
544  enum
545  {
546  VTK_NO_MODIFIER = 0,
547  VTK_SHIFT_MODIFIER = 1,
548  VTK_CONTROL_MODIFIER = 2
549  };
550  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
551  vtkGetMacro(LeftButtonAutoModifier, int);
552  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
553  vtkGetMacro(MiddleButtonAutoModifier, int);
554  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
555  vtkGetMacro(RightButtonAutoModifier, int);
557 
558 protected:
560  ~vtkImagePlaneWidget() override;
561 
563 
567 
571 
572  enum
573  {
574  VTK_NO_BUTTON = 0,
575  VTK_LEFT_BUTTON = 1,
576  VTK_MIDDLE_BUTTON = 2,
577  VTK_RIGHT_BUTTON = 3
578  };
580 
581  // Manage the state of the widget
582  int State;
584  {
585  Start = 0,
593  Outside
594  };
595 
596  // Handles the events
597  static void ProcessEvents(
598  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
599 
600  // internal utility method that adds observers to the RenderWindowInteractor
601  // so that our ProcessEvents is eventually called. this method is called
602  // by SetEnabled as well as SetInteraction
603  void AddObservers();
604 
605  // ProcessEvents() dispatches to these methods.
606  virtual void OnMouseMove();
607  virtual void OnLeftButtonDown();
608  virtual void OnLeftButtonUp();
609  virtual void OnMiddleButtonDown();
610  virtual void OnMiddleButtonUp();
611  virtual void OnRightButtonDown();
612  virtual void OnRightButtonUp();
613  void OnChar() override;
614 
615  virtual void StartCursor();
616  virtual void StopCursor();
617  virtual void StartSliceMotion();
618  virtual void StopSliceMotion();
619  virtual void StartWindowLevel();
620  virtual void StopWindowLevel();
621 
622  // controlling ivars
623  vtkTypeBool Interaction; // Is the widget responsive to mouse events
629  double CurrentLevel;
631  double InitialLevel;
638 
639  // The geometric representation of the plane and it's outline
643  void HighlightPlane(int highlight);
644  void GeneratePlaneOutline();
645 
646  // Re-builds the plane outline based on the plane source
647  void BuildRepresentation();
648 
649  // Do the picking
651 
652  // Register internal Pickers within PickingManager
653  void RegisterPickers() override;
654 
655  // for negative window values.
656  void InvertTable();
657 
658  // Methods to manipulate the plane
659  void WindowLevel(int X, int Y);
660  void Push(double* p1, double* p2);
661  void Spin(double* p1, double* p2);
662  void Rotate(double* p1, double* p2, double* vpn);
663  void Scale(double* p1, double* p2, int X, int Y);
664  void Translate(double* p1, double* p2);
665 
674  vtkLookupTable* CreateDefaultLookupTable();
675 
676  // Properties used to control the appearance of selected objects and
677  // the manipulator in general. The plane property is actually that for
678  // the outline. The TexturePlaneProperty can be used to control the
679  // lighting etc. of the resliced image data.
685  void CreateDefaultProperties();
686 
687  // Reslice and texture management
688  void UpdatePlane();
689  void GenerateTexturePlane();
690 
691  // The cross-hair cursor
694  double CurrentCursorPosition[3];
695  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
696  void GenerateCursor();
697  void UpdateCursor(int, int);
698  void ActivateCursor(int);
699  int UpdateContinuousCursor(double* q);
700  int UpdateDiscreteCursor(double* q);
702 
703  // The text to display W/L, image data
706  void GenerateText();
707  void ManageTextDisplay();
708  void ActivateText(int);
709 
710  // Oblique reslice control
711  double RotateAxis[3];
712  double RadiusVector[3];
713  void AdjustState();
714 
715  // Visible margins to assist user interaction
719  void GenerateMargins();
720  void UpdateMargins();
721  void ActivateMargins(int);
722  double MarginSizeX;
723  double MarginSizeY;
724 
725 private:
726  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
727  void operator=(const vtkImagePlaneWidget&) = delete;
728 };
729 
730 #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:62
#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:61
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:84
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:41
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