VTK  9.3.20240418
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
121 #ifndef vtkImagePlaneWidget_h
122 #define vtkImagePlaneWidget_h
123 
124 #include "vtkInteractionWidgetsModule.h" // For export macro
125 #include "vtkPolyDataSourceWidget.h"
126 
127 VTK_ABI_NAMESPACE_BEGIN
128 class vtkActor;
130 class vtkDataSetMapper;
131 class vtkImageData;
132 class vtkImageMapToColors;
133 class vtkImageReslice;
134 class vtkLookupTable;
135 class vtkMatrix4x4;
136 class vtkPlaneSource;
137 class vtkPoints;
138 class vtkPolyData;
139 class vtkProperty;
140 class vtkTextActor;
141 class vtkTextProperty;
142 class vtkTexture;
143 class vtkTransform;
144 
145 #define VTK_NEAREST_RESLICE 0
146 #define VTK_LINEAR_RESLICE 1
147 #define VTK_CUBIC_RESLICE 2
148 
149 // Private.
150 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
151 
152 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
153 {
154 public:
159 
161  void PrintSelf(ostream& os, vtkIndent indent) override;
162 
164 
167  void SetEnabled(int) override;
168  void PlaceWidget(double bounds[6]) override;
169  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
171  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
172  {
173  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
174  }
176 
181 
183 
186  void SetOrigin(double x, double y, double z);
187  void SetOrigin(double xyz[3]);
188  double* GetOrigin() VTK_SIZEHINT(3);
189  void GetOrigin(double xyz[3]);
191 
193 
196  void SetPoint1(double x, double y, double z);
197  void SetPoint1(double xyz[3]);
198  double* GetPoint1() VTK_SIZEHINT(3);
199  void GetPoint1(double xyz[3]);
201 
203 
206  void SetPoint2(double x, double y, double z);
207  void SetPoint2(double xyz[3]);
208  double* GetPoint2() VTK_SIZEHINT(3);
209  void GetPoint2(double xyz[3]);
211 
213 
216  double* GetCenter() VTK_SIZEHINT(3);
217  void GetCenter(double xyz[3]);
219 
221 
224  double* GetNormal() VTK_SIZEHINT(3);
225  void GetNormal(double xyz[3]);
227 
231  void GetVector1(double v1[3]);
232 
236  void GetVector2(double v2[3]);
237 
241  int GetSliceIndex();
242 
246  void SetSliceIndex(int index);
247 
251  double GetSlicePosition();
252 
256  void SetSlicePosition(double position);
257 
259 
262  void SetResliceInterpolate(int);
263  vtkGetMacro(ResliceInterpolate, int);
264  void SetResliceInterpolateToNearestNeighbour()
265  {
266  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
267  }
268  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
269  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
271 
276 
278 
282  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
283  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
284  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
286 
288 
293  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
294  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
295  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
297 
299 
305  vtkSetMacro(TextureInterpolate, vtkTypeBool);
306  vtkGetMacro(TextureInterpolate, vtkTypeBool);
307  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
309 
311 
316  vtkGetMacro(TextureVisibility, vtkTypeBool);
317  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
319 
329 
337 
342  void UpdatePlacement() override;
343 
349 
351 
357  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
360 
362 
367  vtkGetObjectMacro(PlaneProperty, vtkProperty);
369  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
371 
373 
378  vtkGetMacro(PlaneOrientation, int);
379  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
380  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
381  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
383 
391 
393 
401  vtkGetObjectMacro(LookupTable, vtkLookupTable);
403 
405 
409  vtkSetMacro(DisplayText, vtkTypeBool);
410  vtkGetMacro(DisplayText, vtkTypeBool);
411  vtkBooleanMacro(DisplayText, vtkTypeBool);
413 
415 
419  vtkGetObjectMacro(CursorProperty, vtkProperty);
421 
423 
427  vtkGetObjectMacro(MarginProperty, vtkProperty);
429 
431 
435  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
436  vtkGetMacro(MarginSizeX, double);
437  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
438  vtkGetMacro(MarginSizeY, double);
440 
442 
448 
450 
454  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
456 
458 
464  void SetWindowLevel(double window, double level, int copy = 0);
465  void GetWindowLevel(double wl[2]);
466  double GetWindow() { return this->CurrentWindow; }
467  double GetLevel() { return this->CurrentLevel; }
469 
474  int GetCursorData(double xyzv[4]);
475 
482 
484 
488  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
490 
492 
497  vtkGetMacro(CurrentImageValue, double);
499 
501 
504  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
505  vtkGetObjectMacro(Reslice, vtkImageReslice);
507 
509 
516  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
517  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
518  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
520 
522 
525  void SetInteraction(vtkTypeBool interact);
526  vtkGetMacro(Interaction, vtkTypeBool);
527  vtkBooleanMacro(Interaction, vtkTypeBool);
529 
531 
534  enum
535  {
536  VTK_CURSOR_ACTION = 0,
537  VTK_SLICE_MOTION_ACTION = 1,
538  VTK_WINDOW_LEVEL_ACTION = 2
539  };
540  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
541  vtkGetMacro(LeftButtonAction, int);
542  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
543  vtkGetMacro(MiddleButtonAction, int);
544  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
545  vtkGetMacro(RightButtonAction, int);
547 
549 
557  enum
558  {
559  VTK_NO_MODIFIER = 0,
560  VTK_SHIFT_MODIFIER = 1,
561  VTK_CONTROL_MODIFIER = 2
562  };
563  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
564  vtkGetMacro(LeftButtonAutoModifier, int);
565  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
566  vtkGetMacro(MiddleButtonAutoModifier, int);
567  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
568  vtkGetMacro(RightButtonAutoModifier, int);
570 
571 protected:
574 
576 
580 
584 
585  enum
586  {
587  VTK_NO_BUTTON = 0,
588  VTK_LEFT_BUTTON = 1,
589  VTK_MIDDLE_BUTTON = 2,
590  VTK_RIGHT_BUTTON = 3
591  };
593 
594  // Manage the state of the widget
595  int State;
597  {
598  Start = 0,
606  Outside
607  };
608 
609  // Handles the events
610  static void ProcessEvents(
611  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
612 
613  // internal utility method that adds observers to the RenderWindowInteractor
614  // so that our ProcessEvents is eventually called. this method is called
615  // by SetEnabled as well as SetInteraction
616  void AddObservers();
617 
618  // ProcessEvents() dispatches to these methods.
619  virtual void OnMouseMove();
620  virtual void OnLeftButtonDown();
621  virtual void OnLeftButtonUp();
622  virtual void OnMiddleButtonDown();
623  virtual void OnMiddleButtonUp();
624  virtual void OnRightButtonDown();
625  virtual void OnRightButtonUp();
626  void OnChar() override;
627 
628  virtual void StartCursor();
629  virtual void StopCursor();
630  virtual void StartSliceMotion();
631  virtual void StopSliceMotion();
632  virtual void StartWindowLevel();
633  virtual void StopWindowLevel();
634 
635  // controlling ivars
636  vtkTypeBool Interaction; // Is the widget responsive to mouse events
642  double CurrentLevel;
644  double InitialLevel;
651 
652  // The geometric representation of the plane and it's outline
656  void HighlightPlane(int highlight);
658 
659  // Re-builds the plane outline based on the plane source
661 
662  // Do the picking
664 
665  // Register internal Pickers within PickingManager
666  void RegisterPickers() override;
667 
668  // for negative window values.
669  void InvertTable();
670 
671  // Methods to manipulate the plane
672  void WindowLevel(int X, int Y);
673  void Push(double* p1, double* p2);
674  void Spin(double* p1, double* p2);
675  void Rotate(double* p1, double* p2, double* vpn);
676  void Scale(double* p1, double* p2, int X, int Y);
677  void Translate(double* p1, double* p2);
678 
688 
689  // Properties used to control the appearance of selected objects and
690  // the manipulator in general. The plane property is actually that for
691  // the outline. The TexturePlaneProperty can be used to control the
692  // lighting etc. of the resliced image data.
699 
700  // Reslice and texture management
701  void UpdatePlane();
703 
704  // The cross-hair cursor
707  double CurrentCursorPosition[3];
708  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
710  void UpdateCursor(int, int);
711  void ActivateCursor(int);
712  int UpdateContinuousCursor(double* q);
713  int UpdateDiscreteCursor(double* q);
715 
716  // The text to display W/L, image data
719  void GenerateText();
721  void ActivateText(int);
722 
723  // Oblique reslice control
724  double RotateAxis[3];
725  double RadiusVector[3];
726  void AdjustState();
727 
728  // Visible margins to assist user interaction
734  void ActivateMargins(int);
735  double MarginSizeX;
736  double MarginSizeY;
737 
738 private:
739  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
740  void operator=(const vtkImagePlaneWidget&) = delete;
741 };
742 
743 VTK_ABI_NAMESPACE_END
744 #endif
virtual void PlaceWidget()
This method is used to initially place the widget.
abstract API for pickers that can pick an instance of vtkProp
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:151
Proxy object to connect input/output ports.
map vtkDataSet and derived classes to graphics primitives
topologically and geometrically regular array of data
Definition: vtkImageData.h:156
map the input image through a lookup table
3D widget for reslicing image data
void SetPicker(vtkAbstractPropPicker *)
Set the internal picker to one defined by the user.
virtual void StartSliceMotion()
vtkPolyData * MarginPolyData
virtual void StartWindowLevel()
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that defines the plane.
vtkProperty * SelectedPlaneProperty
void SetPlaneOrientationToZAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
void PlaceWidget() override
Methods that satisfy the superclass' API.
void WindowLevel(int X, int Y)
vtkAbstractPropPicker * PlanePicker
vtkProperty * TexturePlaneProperty
void SetPlaneOrientation(int)
Convenience method sets the plane orientation normal to the x, y, or z axes.
vtkPlaneSource * PlaneSource
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeBool RestrictPlaneToVolume
void Rotate(double *p1, double *p2, double *vpn)
void Push(double *p1, double *p2)
virtual void SetSelectedPlaneProperty(vtkProperty *)
Set/Get the plane's outline properties.
vtkLookupTable * LookupTable
double GetWindow()
Set/Get the current window and level values.
void ActivateCursor(int)
virtual void SetCursorProperty(vtkProperty *)
Set the properties of the cross-hair cursor.
virtual void StopWindowLevel()
virtual void StartCursor()
virtual void OnMiddleButtonUp()
static vtkImagePlaneWidget * New()
Instantiate the object.
virtual void SetMarginProperty(vtkProperty *)
Set the properties of the margins.
~vtkImagePlaneWidget() override
void SetOrigin(double x, double y, double z)
Set/Get the origin of the plane.
virtual void StopSliceMotion()
double GetLevel()
Set/Get the current window and level values.
vtkPolyDataAlgorithm * GetPolyDataAlgorithm() override
Satisfies superclass API.
void SetPlaneOrientationToYAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
vtkProperty * MarginProperty
virtual void SetTextureVisibility(vtkTypeBool)
Control the visibility of the actual texture mapped reformatted plane.
virtual void SetTexturePlaneProperty(vtkProperty *)
Set/Get the property for the resliced image.
void Translate(double *p1, double *p2)
void SetResliceInterpolateToCubic()
Set the interpolation to use when texturing the plane.
virtual void OnMouseMove()
void CreateDefaultProperties()
void HighlightPlane(int highlight)
void SetResliceInterpolateToLinear()
Set the interpolation to use when texturing the plane.
void SetInputConnection(vtkAlgorithmOutput *aout) override
Set the vtkImageData* input for the vtkImageReslice.
int UpdateContinuousCursor(double *q)
void SetWindowLevel(double window, double level, int copy=0)
Set/Get the current window and level values.
int GetCursorData(double xyzv[4])
Get the image coordinate position and voxel value.
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
void UpdatePlacement() override
Satisfies superclass API.
virtual void SetLookupTable(vtkLookupTable *)
Set/Get the internal lookuptable (lut) to one defined by the user, or, alternatively,...
vtkTextProperty * GetTextProperty()
Set/Get the text property for the image data and window-level annotation.
void SetEnabled(int) override
Methods that satisfy the superclass' API.
vtkTypeBool UserControlledLookupTable
void SetOrigin(double xyz[3])
Set/Get the origin of the plane.
vtkMatrix4x4 * ResliceAxes
vtkTexture * GetTexture()
Convenience method to get the texture used by this widget.
void Spin(double *p1, double *p2)
void ActivateMargins(int)
vtkProperty * CursorProperty
int UpdateDiscreteCursor(double *q)
vtkLookupTable * CreateDefaultLookupTable()
virtual void OnMiddleButtonDown()
void GetWindowLevel(double wl[2])
Set/Get the current window and level values.
void SetTextProperty(vtkTextProperty *tprop)
Set/Get the text property for the image data and window-level annotation.
virtual void OnRightButtonUp()
virtual void SetPlaneProperty(vtkProperty *)
Set/Get the plane's outline properties.
int GetCursorDataStatus()
Get the status of the cursor data.
void PlaceWidget(double bounds[6]) override
Methods that satisfy the superclass' API.
virtual void StopCursor()
virtual void OnLeftButtonUp()
vtkImageMapToColors * ColorMap
vtkImageReslice * Reslice
vtkPolyData * CursorPolyData
void UpdateCursor(int, int)
void SetInteraction(vtkTypeBool interact)
Enable/disable mouse interaction so the widget remains on display.
virtual void SetColorMap(vtkImageMapToColors *)
Convenience method to get the vtkImageMapToColors filter used by this widget.
virtual void OnLeftButtonDown()
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
virtual void OnRightButtonDown()
double * GetOrigin()
Set/Get the origin of the plane.
vtkPolyData * PlaneOutlinePolyData
void SetPlaneOrientationToXAxes()
Convenience method sets the plane orientation normal to the x, y, or z axes.
void OnChar() override
Sets up the keypress-i event.
void ActivateText(int)
void Scale(double *p1, double *p2, int X, int Y)
vtkImageData * GetResliceOutput()
Convenience method to get the vtkImageReslice output.
Reslices a volume along a new set of axes.
a simple class to control print indentation
Definition: vtkIndent.h:108
map scalar values into colors via a lookup table
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:141
abstract base class for most VTK objects
Definition: vtkObject.h:162
create an array of quadrilaterals located in a plane
represent and manipulate 3D points
Definition: vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
abstract PolyDataSource-based 3D widget
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:181
represent surface properties of a geometric object
Definition: vtkProperty.h:167
An actor that displays text.
Definition: vtkTextActor.h:155
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:167
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:160
@ level
Definition: vtkX3D.h:395
@ position
Definition: vtkX3D.h:261
@ index
Definition: vtkX3D.h:246
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_LINEAR_RESLICE
#define VTK_CUBIC_RESLICE
#define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF
#define VTK_NEAREST_RESLICE
#define VTK_SIZEHINT(...)