VTK  9.3.1
vtkImagePlaneWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
102 #ifndef vtkImagePlaneWidget_h
103 #define vtkImagePlaneWidget_h
104 
105 #include "vtkInteractionWidgetsModule.h" // For export macro
106 #include "vtkPolyDataSourceWidget.h"
107 
108 VTK_ABI_NAMESPACE_BEGIN
109 class vtkActor;
111 class vtkDataSetMapper;
112 class vtkImageData;
113 class vtkImageMapToColors;
114 class vtkImageReslice;
115 class vtkLookupTable;
116 class vtkMatrix4x4;
117 class vtkPlaneSource;
118 class vtkPoints;
119 class vtkPolyData;
120 class vtkProperty;
121 class vtkTextActor;
122 class vtkTextProperty;
123 class vtkTexture;
124 class vtkTransform;
125 
126 #define VTK_NEAREST_RESLICE 0
127 #define VTK_LINEAR_RESLICE 1
128 #define VTK_CUBIC_RESLICE 2
129 
130 // Private.
131 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
132 
133 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
134 {
135 public:
139  static vtkImagePlaneWidget* New();
140 
142  void PrintSelf(ostream& os, vtkIndent indent) override;
143 
145 
148  void SetEnabled(int) override;
149  void PlaceWidget(double bounds[6]) override;
150  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
152  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
153  {
154  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
155  }
157 
161  void SetInputConnection(vtkAlgorithmOutput* aout) override;
162 
164 
167  void SetOrigin(double x, double y, double z);
168  void SetOrigin(double xyz[3]);
169  double* GetOrigin() VTK_SIZEHINT(3);
170  void GetOrigin(double xyz[3]);
172 
174 
177  void SetPoint1(double x, double y, double z);
178  void SetPoint1(double xyz[3]);
179  double* GetPoint1() VTK_SIZEHINT(3);
180  void GetPoint1(double xyz[3]);
182 
184 
187  void SetPoint2(double x, double y, double z);
188  void SetPoint2(double xyz[3]);
189  double* GetPoint2() VTK_SIZEHINT(3);
190  void GetPoint2(double xyz[3]);
192 
194 
197  double* GetCenter() VTK_SIZEHINT(3);
198  void GetCenter(double xyz[3]);
200 
202 
205  double* GetNormal() VTK_SIZEHINT(3);
206  void GetNormal(double xyz[3]);
208 
212  void GetVector1(double v1[3]);
213 
217  void GetVector2(double v2[3]);
218 
222  int GetSliceIndex();
223 
227  void SetSliceIndex(int index);
228 
232  double GetSlicePosition();
233 
237  void SetSlicePosition(double position);
238 
240 
243  void SetResliceInterpolate(int);
244  vtkGetMacro(ResliceInterpolate, int);
245  void SetResliceInterpolateToNearestNeighbour()
246  {
247  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
248  }
249  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
250  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
252 
256  vtkImageData* GetResliceOutput();
257 
259 
263  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
264  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
265  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
267 
269 
274  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
275  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
276  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
278 
280 
286  vtkSetMacro(TextureInterpolate, vtkTypeBool);
287  vtkGetMacro(TextureInterpolate, vtkTypeBool);
288  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
290 
292 
296  virtual void SetTextureVisibility(vtkTypeBool);
297  vtkGetMacro(TextureVisibility, vtkTypeBool);
298  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
300 
309  void GetPolyData(vtkPolyData* pd);
310 
318 
323  void UpdatePlacement() override;
324 
329  vtkTexture* GetTexture();
330 
332 
338  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
339  virtual void SetColorMap(vtkImageMapToColors*);
341 
343 
347  virtual void SetPlaneProperty(vtkProperty*);
348  vtkGetObjectMacro(PlaneProperty, vtkProperty);
349  virtual void SetSelectedPlaneProperty(vtkProperty*);
350  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
352 
354 
358  void SetPlaneOrientation(int);
359  vtkGetMacro(PlaneOrientation, int);
360  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
361  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
362  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
364 
371  void SetPicker(vtkAbstractPropPicker*);
372 
374 
381  virtual void SetLookupTable(vtkLookupTable*);
382  vtkGetObjectMacro(LookupTable, vtkLookupTable);
384 
386 
390  vtkSetMacro(DisplayText, vtkTypeBool);
391  vtkGetMacro(DisplayText, vtkTypeBool);
392  vtkBooleanMacro(DisplayText, vtkTypeBool);
394 
396 
399  virtual void SetCursorProperty(vtkProperty*);
400  vtkGetObjectMacro(CursorProperty, vtkProperty);
402 
404 
407  virtual void SetMarginProperty(vtkProperty*);
408  vtkGetObjectMacro(MarginProperty, vtkProperty);
410 
412 
416  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
417  vtkGetMacro(MarginSizeX, double);
418  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
419  vtkGetMacro(MarginSizeY, double);
421 
423 
426  void SetTextProperty(vtkTextProperty* tprop);
427  vtkTextProperty* GetTextProperty();
429 
431 
434  virtual void SetTexturePlaneProperty(vtkProperty*);
435  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
437 
439 
445  void SetWindowLevel(double window, double level, int copy = 0);
446  void GetWindowLevel(double wl[2]);
447  double GetWindow() { return this->CurrentWindow; }
448  double GetLevel() { return this->CurrentLevel; }
450 
455  int GetCursorData(double xyzv[4]);
456 
462  int GetCursorDataStatus();
463 
465 
469  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
471 
473 
478  vtkGetMacro(CurrentImageValue, double);
480 
482 
485  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
486  vtkGetObjectMacro(Reslice, vtkImageReslice);
488 
490 
497  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
498  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
499  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
501 
503 
506  void SetInteraction(vtkTypeBool interact);
507  vtkGetMacro(Interaction, vtkTypeBool);
508  vtkBooleanMacro(Interaction, vtkTypeBool);
510 
512 
515  enum
516  {
517  VTK_CURSOR_ACTION = 0,
518  VTK_SLICE_MOTION_ACTION = 1,
519  VTK_WINDOW_LEVEL_ACTION = 2
520  };
521  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
522  vtkGetMacro(LeftButtonAction, int);
523  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
524  vtkGetMacro(MiddleButtonAction, int);
525  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
526  vtkGetMacro(RightButtonAction, int);
528 
530 
538  enum
539  {
540  VTK_NO_MODIFIER = 0,
541  VTK_SHIFT_MODIFIER = 1,
542  VTK_CONTROL_MODIFIER = 2
543  };
544  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
545  vtkGetMacro(LeftButtonAutoModifier, int);
546  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
547  vtkGetMacro(MiddleButtonAutoModifier, int);
548  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
549  vtkGetMacro(RightButtonAutoModifier, int);
551 
552 protected:
554  ~vtkImagePlaneWidget() override;
555 
557 
561 
565 
566  enum
567  {
568  VTK_NO_BUTTON = 0,
569  VTK_LEFT_BUTTON = 1,
570  VTK_MIDDLE_BUTTON = 2,
571  VTK_RIGHT_BUTTON = 3
572  };
574 
575  // Manage the state of the widget
576  int State;
578  {
579  Start = 0,
587  Outside
588  };
589 
590  // Handles the events
591  static void ProcessEvents(
592  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
593 
594  // internal utility method that adds observers to the RenderWindowInteractor
595  // so that our ProcessEvents is eventually called. this method is called
596  // by SetEnabled as well as SetInteraction
597  void AddObservers();
598 
599  // ProcessEvents() dispatches to these methods.
600  virtual void OnMouseMove();
601  virtual void OnLeftButtonDown();
602  virtual void OnLeftButtonUp();
603  virtual void OnMiddleButtonDown();
604  virtual void OnMiddleButtonUp();
605  virtual void OnRightButtonDown();
606  virtual void OnRightButtonUp();
607  void OnChar() override;
608 
609  virtual void StartCursor();
610  virtual void StopCursor();
611  virtual void StartSliceMotion();
612  virtual void StopSliceMotion();
613  virtual void StartWindowLevel();
614  virtual void StopWindowLevel();
615 
616  // controlling ivars
617  vtkTypeBool Interaction; // Is the widget responsive to mouse events
623  double CurrentLevel;
625  double InitialLevel;
632 
633  // The geometric representation of the plane and it's outline
637  void HighlightPlane(int highlight);
638  void GeneratePlaneOutline();
639 
640  // Re-builds the plane outline based on the plane source
641  void BuildRepresentation();
642 
643  // Do the picking
645 
646  // Register internal Pickers within PickingManager
647  void RegisterPickers() override;
648 
649  // for negative window values.
650  void InvertTable();
651 
652  // Methods to manipulate the plane
653  void WindowLevel(int X, int Y);
654  void Push(double* p1, double* p2);
655  void Spin(double* p1, double* p2);
656  void Rotate(double* p1, double* p2, double* vpn);
657  void Scale(double* p1, double* p2, int X, int Y);
658  void Translate(double* p1, double* p2);
659 
668  vtkLookupTable* CreateDefaultLookupTable();
669 
670  // Properties used to control the appearance of selected objects and
671  // the manipulator in general. The plane property is actually that for
672  // the outline. The TexturePlaneProperty can be used to control the
673  // lighting etc. of the resliced image data.
679  void CreateDefaultProperties();
680 
681  // Reslice and texture management
682  void UpdatePlane();
683  void GenerateTexturePlane();
684 
685  // The cross-hair cursor
688  double CurrentCursorPosition[3];
689  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
690  void GenerateCursor();
691  void UpdateCursor(int, int);
692  void ActivateCursor(int);
693  int UpdateContinuousCursor(double* q);
694  int UpdateDiscreteCursor(double* q);
696 
697  // The text to display W/L, image data
700  void GenerateText();
701  void ManageTextDisplay();
702  void ActivateText(int);
703 
704  // Oblique reslice control
705  double RotateAxis[3];
706  double RadiusVector[3];
707  void AdjustState();
708 
709  // Visible margins to assist user interaction
713  void GenerateMargins();
714  void UpdateMargins();
715  void ActivateMargins(int);
716  double MarginSizeX;
717  double MarginSizeY;
718 
719 private:
720  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
721  void operator=(const vtkImagePlaneWidget&) = delete;
722 };
723 
724 VTK_ABI_NAMESPACE_END
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:40
abstract base class for most VTK objects
Definition: vtkObject.h:51
#define VTK_LINEAR_RESLICE
abstract PolyDataSource-based 3D widget
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
double GetLevel()
Set/Get the current window and level values.
represent surface properties of a geometric object
Definition: vtkProperty.h:56
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:49
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:64
An actor that displays text.
Definition: vtkTextActor.h:45
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:28
#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:42
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:57
#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:28
vtkTypeBool UserControlledLookupTable