VTK  9.0.3
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:
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 { this->Superclass::PlaceWidget(); }
149  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
150  {
151  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
152  }
154 
159 
161 
164  void SetOrigin(double x, double y, double z);
165  void SetOrigin(double xyz[3]);
166  double* GetOrigin() VTK_SIZEHINT(3);
167  void GetOrigin(double xyz[3]);
169 
171 
174  void SetPoint1(double x, double y, double z);
175  void SetPoint1(double xyz[3]);
176  double* GetPoint1() VTK_SIZEHINT(3);
177  void GetPoint1(double xyz[3]);
179 
181 
184  void SetPoint2(double x, double y, double z);
185  void SetPoint2(double xyz[3]);
186  double* GetPoint2() VTK_SIZEHINT(3);
187  void GetPoint2(double xyz[3]);
189 
191 
194  double* GetCenter() VTK_SIZEHINT(3);
195  void GetCenter(double xyz[3]);
197 
199 
202  double* GetNormal() VTK_SIZEHINT(3);
203  void GetNormal(double xyz[3]);
205 
209  void GetVector1(double v1[3]);
210 
214  void GetVector2(double v2[3]);
215 
219  int GetSliceIndex();
220 
224  void SetSliceIndex(int index);
225 
229  double GetSlicePosition();
230 
234  void SetSlicePosition(double position);
235 
237 
240  void SetResliceInterpolate(int);
241  vtkGetMacro(ResliceInterpolate, int);
242  void SetResliceInterpolateToNearestNeighbour()
243  {
244  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
245  }
246  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
247  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
249 
254 
256 
260  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
261  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
262  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
264 
266 
271  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
272  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
273  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
275 
277 
283  vtkSetMacro(TextureInterpolate, vtkTypeBool);
284  vtkGetMacro(TextureInterpolate, vtkTypeBool);
285  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
287 
289 
294  vtkGetMacro(TextureVisibility, vtkTypeBool);
295  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
297 
307 
315 
320  void UpdatePlacement(void) override;
321 
327 
329 
335  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
338 
340 
345  vtkGetObjectMacro(PlaneProperty, vtkProperty);
347  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
349 
351 
356  vtkGetMacro(PlaneOrientation, int);
357  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
358  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
359  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
361 
369 
371 
379  vtkGetObjectMacro(LookupTable, vtkLookupTable);
381 
383 
387  vtkSetMacro(DisplayText, vtkTypeBool);
388  vtkGetMacro(DisplayText, vtkTypeBool);
389  vtkBooleanMacro(DisplayText, vtkTypeBool);
391 
393 
397  vtkGetObjectMacro(CursorProperty, vtkProperty);
399 
401 
405  vtkGetObjectMacro(MarginProperty, vtkProperty);
407 
409 
413  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
414  vtkGetMacro(MarginSizeX, double);
415  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
416  vtkGetMacro(MarginSizeY, double);
418 
420 
426 
428 
432  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
434 
436 
442  void SetWindowLevel(double window, double level, int copy = 0);
443  void GetWindowLevel(double wl[2]);
444  double GetWindow() { return this->CurrentWindow; }
445  double GetLevel() { return this->CurrentLevel; }
447 
452  int GetCursorData(double xyzv[4]);
453 
460 
462 
466  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
468 
470 
475  vtkGetMacro(CurrentImageValue, double);
477 
479 
482  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
483  vtkGetObjectMacro(Reslice, vtkImageReslice);
485 
487 
494  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
495  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
496  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
498 
500 
503  void SetInteraction(vtkTypeBool interact);
504  vtkGetMacro(Interaction, vtkTypeBool);
505  vtkBooleanMacro(Interaction, vtkTypeBool);
507 
509 
512  enum
513  {
514  VTK_CURSOR_ACTION = 0,
515  VTK_SLICE_MOTION_ACTION = 1,
516  VTK_WINDOW_LEVEL_ACTION = 2
517  };
518  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
519  vtkGetMacro(LeftButtonAction, int);
520  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
521  vtkGetMacro(MiddleButtonAction, int);
522  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
523  vtkGetMacro(RightButtonAction, int);
525 
527 
535  enum
536  {
537  VTK_NO_MODIFIER = 0,
538  VTK_SHIFT_MODIFIER = 1,
539  VTK_CONTROL_MODIFIER = 2
540  };
541  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
542  vtkGetMacro(LeftButtonAutoModifier, int);
543  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
544  vtkGetMacro(MiddleButtonAutoModifier, int);
545  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
546  vtkGetMacro(RightButtonAutoModifier, int);
548 
549 protected:
552 
554 
558 
562 
563  enum
564  {
565  VTK_NO_BUTTON = 0,
566  VTK_LEFT_BUTTON = 1,
567  VTK_MIDDLE_BUTTON = 2,
568  VTK_RIGHT_BUTTON = 3
569  };
571 
572  // Manage the state of the widget
573  int State;
575  {
576  Start = 0,
584  Outside
585  };
586 
587  // Handles the events
588  static void ProcessEvents(
589  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
590 
591  // internal utility method that adds observers to the RenderWindowInteractor
592  // so that our ProcessEvents is eventually called. this method is called
593  // by SetEnabled as well as SetInteraction
594  void AddObservers();
595 
596  // ProcessEvents() dispatches to these methods.
597  virtual void OnMouseMove();
598  virtual void OnLeftButtonDown();
599  virtual void OnLeftButtonUp();
600  virtual void OnMiddleButtonDown();
601  virtual void OnMiddleButtonUp();
602  virtual void OnRightButtonDown();
603  virtual void OnRightButtonUp();
604  void OnChar() override;
605 
606  virtual void StartCursor();
607  virtual void StopCursor();
608  virtual void StartSliceMotion();
609  virtual void StopSliceMotion();
610  virtual void StartWindowLevel();
611  virtual void StopWindowLevel();
612 
613  // controlling ivars
614  vtkTypeBool Interaction; // Is the widget responsive to mouse events
620  double CurrentLevel;
622  double InitialLevel;
629 
630  // The geometric representation of the plane and it's outline
634  void HighlightPlane(int highlight);
636 
637  // Re-builds the plane outline based on the plane source
639 
640  // Do the picking
642 
643  // Register internal Pickers within PickingManager
644  void RegisterPickers() override;
645 
646  // for negative window values.
647  void InvertTable();
648 
649  // Methods to manipulate the plane
650  void WindowLevel(int X, int Y);
651  void Push(double* p1, double* p2);
652  void Spin(double* p1, double* p2);
653  void Rotate(double* p1, double* p2, double* vpn);
654  void Scale(double* p1, double* p2, int X, int Y);
655  void Translate(double* p1, double* p2);
656 
666 
667  // Properties used to control the appearance of selected objects and
668  // the manipulator in general. The plane property is actually that for
669  // the outline. The TexturePlaneProperty can be used to control the
670  // lighting etc. of the resliced image data.
677 
678  // Reslice and texture management
679  void UpdatePlane();
681 
682  // The cross-hair cursor
685  double CurrentCursorPosition[3];
686  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
688  void UpdateCursor(int, int);
689  void ActivateCursor(int);
690  int UpdateContinuousCursor(double* q);
691  int UpdateDiscreteCursor(double* q);
693 
694  // The text to display W/L, image data
697  void GenerateText();
699  void ActivateText(int);
700 
701  // Oblique reslice control
702  double RotateAxis[3];
703  double RadiusVector[3];
704  void AdjustState();
705 
706  // Visible margins to assist user interaction
712  void ActivateMargins(int);
713  double MarginSizeX;
714  double MarginSizeY;
715 
716 private:
717  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
718  void operator=(const vtkImagePlaneWidget&) = delete;
719 };
720 
721 #endif
virtual void PlaceWidget()
abstract API for pickers that can pick an instance of vtkProp
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:46
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:42
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 PlaceWidget() override
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 *)
vtkLookupTable * LookupTable
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()
vtkPolyDataAlgorithm * GetPolyDataAlgorithm() override
Satisfies superclass API.
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
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)
virtual void OnMouseMove()
void CreateDefaultProperties()
void HighlightPlane(int highlight)
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()
void SetEnabled(int) override
Methods that satisfy the superclass' API.
vtkTypeBool UserControlledLookupTable
void SetOrigin(double xyz[3])
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])
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
We have to redeclare this abstract, PlaceWidget() requires it.
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 *)
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()
vtkPolyData * PlaneOutlinePolyData
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:34
map scalar values into colors via a lookup table
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
abstract base class for most VTK objects
Definition: vtkObject.h:54
create an array of quadrilaterals located in a plane
represent and manipulate 3D points
Definition: vtkPoints.h:34
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:85
represent surface properties of a geometric object
Definition: vtkProperty.h:62
An actor that displays text.
Definition: vtkTextActor.h:51
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:66
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:55
@ 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(...)