VTK  9.2.6
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 =========================================================================*/
133 #ifndef vtkImagePlaneWidget_h
134 #define vtkImagePlaneWidget_h
135 
136 #include "vtkInteractionWidgetsModule.h" // For export macro
137 #include "vtkPolyDataSourceWidget.h"
138 
139 class vtkActor;
141 class vtkDataSetMapper;
142 class vtkImageData;
143 class vtkImageMapToColors;
144 class vtkImageReslice;
145 class vtkLookupTable;
146 class vtkMatrix4x4;
147 class vtkPlaneSource;
148 class vtkPoints;
149 class vtkPolyData;
150 class vtkProperty;
151 class vtkTextActor;
152 class vtkTextProperty;
153 class vtkTexture;
154 class vtkTransform;
155 
156 #define VTK_NEAREST_RESLICE 0
157 #define VTK_LINEAR_RESLICE 1
158 #define VTK_CUBIC_RESLICE 2
159 
160 // Private.
161 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
162 
163 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
164 {
165 public:
170 
172  void PrintSelf(ostream& os, vtkIndent indent) override;
173 
175 
178  void SetEnabled(int) override;
179  void PlaceWidget(double bounds[6]) override;
180  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
182  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
183  {
184  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
185  }
187 
192 
194 
197  void SetOrigin(double x, double y, double z);
198  void SetOrigin(double xyz[3]);
199  double* GetOrigin() VTK_SIZEHINT(3);
200  void GetOrigin(double xyz[3]);
202 
204 
207  void SetPoint1(double x, double y, double z);
208  void SetPoint1(double xyz[3]);
209  double* GetPoint1() VTK_SIZEHINT(3);
210  void GetPoint1(double xyz[3]);
212 
214 
217  void SetPoint2(double x, double y, double z);
218  void SetPoint2(double xyz[3]);
219  double* GetPoint2() VTK_SIZEHINT(3);
220  void GetPoint2(double xyz[3]);
222 
224 
227  double* GetCenter() VTK_SIZEHINT(3);
228  void GetCenter(double xyz[3]);
230 
232 
235  double* GetNormal() VTK_SIZEHINT(3);
236  void GetNormal(double xyz[3]);
238 
242  void GetVector1(double v1[3]);
243 
247  void GetVector2(double v2[3]);
248 
252  int GetSliceIndex();
253 
257  void SetSliceIndex(int index);
258 
262  double GetSlicePosition();
263 
267  void SetSlicePosition(double position);
268 
270 
273  void SetResliceInterpolate(int);
274  vtkGetMacro(ResliceInterpolate, int);
275  void SetResliceInterpolateToNearestNeighbour()
276  {
277  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
278  }
279  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
280  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
282 
287 
289 
293  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
294  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
295  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
297 
299 
304  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
305  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
306  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
308 
310 
316  vtkSetMacro(TextureInterpolate, vtkTypeBool);
317  vtkGetMacro(TextureInterpolate, vtkTypeBool);
318  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
320 
322 
327  vtkGetMacro(TextureVisibility, vtkTypeBool);
328  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
330 
340 
348 
353  void UpdatePlacement(void) override;
354 
360 
362 
368  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
371 
373 
378  vtkGetObjectMacro(PlaneProperty, vtkProperty);
380  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
382 
384 
389  vtkGetMacro(PlaneOrientation, int);
390  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
391  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
392  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
394 
402 
404 
412  vtkGetObjectMacro(LookupTable, vtkLookupTable);
414 
416 
420  vtkSetMacro(DisplayText, vtkTypeBool);
421  vtkGetMacro(DisplayText, vtkTypeBool);
422  vtkBooleanMacro(DisplayText, vtkTypeBool);
424 
426 
430  vtkGetObjectMacro(CursorProperty, vtkProperty);
432 
434 
438  vtkGetObjectMacro(MarginProperty, vtkProperty);
440 
442 
446  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
447  vtkGetMacro(MarginSizeX, double);
448  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
449  vtkGetMacro(MarginSizeY, double);
451 
453 
459 
461 
465  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
467 
469 
475  void SetWindowLevel(double window, double level, int copy = 0);
476  void GetWindowLevel(double wl[2]);
477  double GetWindow() { return this->CurrentWindow; }
478  double GetLevel() { return this->CurrentLevel; }
480 
485  int GetCursorData(double xyzv[4]);
486 
493 
495 
499  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
501 
503 
508  vtkGetMacro(CurrentImageValue, double);
510 
512 
515  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
516  vtkGetObjectMacro(Reslice, vtkImageReslice);
518 
520 
527  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
528  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
529  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
531 
533 
536  void SetInteraction(vtkTypeBool interact);
537  vtkGetMacro(Interaction, vtkTypeBool);
538  vtkBooleanMacro(Interaction, vtkTypeBool);
540 
542 
545  enum
546  {
547  VTK_CURSOR_ACTION = 0,
548  VTK_SLICE_MOTION_ACTION = 1,
549  VTK_WINDOW_LEVEL_ACTION = 2
550  };
551  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
552  vtkGetMacro(LeftButtonAction, int);
553  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
554  vtkGetMacro(MiddleButtonAction, int);
555  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
556  vtkGetMacro(RightButtonAction, int);
558 
560 
568  enum
569  {
570  VTK_NO_MODIFIER = 0,
571  VTK_SHIFT_MODIFIER = 1,
572  VTK_CONTROL_MODIFIER = 2
573  };
574  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
575  vtkGetMacro(LeftButtonAutoModifier, int);
576  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
577  vtkGetMacro(MiddleButtonAutoModifier, int);
578  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
579  vtkGetMacro(RightButtonAutoModifier, int);
581 
582 protected:
585 
587 
591 
595 
596  enum
597  {
598  VTK_NO_BUTTON = 0,
599  VTK_LEFT_BUTTON = 1,
600  VTK_MIDDLE_BUTTON = 2,
601  VTK_RIGHT_BUTTON = 3
602  };
604 
605  // Manage the state of the widget
606  int State;
608  {
609  Start = 0,
617  Outside
618  };
619 
620  // Handles the events
621  static void ProcessEvents(
622  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
623 
624  // internal utility method that adds observers to the RenderWindowInteractor
625  // so that our ProcessEvents is eventually called. this method is called
626  // by SetEnabled as well as SetInteraction
627  void AddObservers();
628 
629  // ProcessEvents() dispatches to these methods.
630  virtual void OnMouseMove();
631  virtual void OnLeftButtonDown();
632  virtual void OnLeftButtonUp();
633  virtual void OnMiddleButtonDown();
634  virtual void OnMiddleButtonUp();
635  virtual void OnRightButtonDown();
636  virtual void OnRightButtonUp();
637  void OnChar() override;
638 
639  virtual void StartCursor();
640  virtual void StopCursor();
641  virtual void StartSliceMotion();
642  virtual void StopSliceMotion();
643  virtual void StartWindowLevel();
644  virtual void StopWindowLevel();
645 
646  // controlling ivars
647  vtkTypeBool Interaction; // Is the widget responsive to mouse events
653  double CurrentLevel;
655  double InitialLevel;
662 
663  // The geometric representation of the plane and it's outline
667  void HighlightPlane(int highlight);
669 
670  // Re-builds the plane outline based on the plane source
672 
673  // Do the picking
675 
676  // Register internal Pickers within PickingManager
677  void RegisterPickers() override;
678 
679  // for negative window values.
680  void InvertTable();
681 
682  // Methods to manipulate the plane
683  void WindowLevel(int X, int Y);
684  void Push(double* p1, double* p2);
685  void Spin(double* p1, double* p2);
686  void Rotate(double* p1, double* p2, double* vpn);
687  void Scale(double* p1, double* p2, int X, int Y);
688  void Translate(double* p1, double* p2);
689 
699 
700  // Properties used to control the appearance of selected objects and
701  // the manipulator in general. The plane property is actually that for
702  // the outline. The TexturePlaneProperty can be used to control the
703  // lighting etc. of the resliced image data.
710 
711  // Reslice and texture management
712  void UpdatePlane();
714 
715  // The cross-hair cursor
718  double CurrentCursorPosition[3];
719  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
721  void UpdateCursor(int, int);
722  void ActivateCursor(int);
723  int UpdateContinuousCursor(double* q);
724  int UpdateDiscreteCursor(double* q);
726 
727  // The text to display W/L, image data
730  void GenerateText();
732  void ActivateText(int);
733 
734  // Oblique reslice control
735  double RotateAxis[3];
736  double RadiusVector[3];
737  void AdjustState();
738 
739  // Visible margins to assist user interaction
745  void ActivateMargins(int);
746  double MarginSizeX;
747  double MarginSizeY;
748 
749 private:
750  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
751  void operator=(const vtkImagePlaneWidget&) = delete;
752 };
753 
754 #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:161
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:163
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)
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 UpdatePlacement(void) override
Satisfies superclass API.
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:119
map scalar values into colors via a lookup table
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
abstract base class for most VTK objects
Definition: vtkObject.h:82
create an array of quadrilaterals located in a plane
represent and manipulate 3D points
Definition: vtkPoints.h:149
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:200
represent surface properties of a geometric object
Definition: vtkProperty.h:177
An actor that displays text.
Definition: vtkTextActor.h:166
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:178
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:170
@ level
Definition: vtkX3D.h:401
@ position
Definition: vtkX3D.h:267
@ index
Definition: vtkX3D.h:252
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_LINEAR_RESLICE
#define VTK_CUBIC_RESLICE
#define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF
#define VTK_NEAREST_RESLICE
#define VTK_SIZEHINT(...)