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 =========================================================================*/
114 #ifndef vtkImagePlaneWidget_h
115 #define vtkImagePlaneWidget_h
116 
117 #include "vtkInteractionWidgetsModule.h" // For export macro
118 #include "vtkPolyDataSourceWidget.h"
119 
120 class vtkActor;
122 class vtkDataSetMapper;
123 class vtkImageData;
124 class vtkImageMapToColors;
125 class vtkImageReslice;
126 class vtkLookupTable;
127 class vtkMatrix4x4;
128 class vtkPlaneSource;
129 class vtkPoints;
130 class vtkPolyData;
131 class vtkProperty;
132 class vtkTextActor;
133 class vtkTextProperty;
134 class vtkTexture;
135 class vtkTransform;
136 
137 #define VTK_NEAREST_RESLICE 0
138 #define VTK_LINEAR_RESLICE 1
139 #define VTK_CUBIC_RESLICE 2
140 
141 // Private.
142 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
143 
144 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
145 {
146 public:
150  static vtkImagePlaneWidget* New();
151 
153  void PrintSelf(ostream& os, vtkIndent indent) override;
154 
156 
159  void SetEnabled(int) override;
160  void PlaceWidget(double bounds[6]) override;
161  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
163  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
164  {
165  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
166  }
168 
172  void SetInputConnection(vtkAlgorithmOutput* aout) override;
173 
175 
178  void SetOrigin(double x, double y, double z);
179  void SetOrigin(double xyz[3]);
180  double* GetOrigin() VTK_SIZEHINT(3);
181  void GetOrigin(double xyz[3]);
183 
185 
188  void SetPoint1(double x, double y, double z);
189  void SetPoint1(double xyz[3]);
190  double* GetPoint1() VTK_SIZEHINT(3);
191  void GetPoint1(double xyz[3]);
193 
195 
198  void SetPoint2(double x, double y, double z);
199  void SetPoint2(double xyz[3]);
200  double* GetPoint2() VTK_SIZEHINT(3);
201  void GetPoint2(double xyz[3]);
203 
205 
208  double* GetCenter() VTK_SIZEHINT(3);
209  void GetCenter(double xyz[3]);
211 
213 
216  double* GetNormal() VTK_SIZEHINT(3);
217  void GetNormal(double xyz[3]);
219 
223  void GetVector1(double v1[3]);
224 
228  void GetVector2(double v2[3]);
229 
233  int GetSliceIndex();
234 
238  void SetSliceIndex(int index);
239 
243  double GetSlicePosition();
244 
248  void SetSlicePosition(double position);
249 
251 
254  void SetResliceInterpolate(int);
255  vtkGetMacro(ResliceInterpolate, int);
256  void SetResliceInterpolateToNearestNeighbour()
257  {
258  this->SetResliceInterpolate(VTK_NEAREST_RESLICE);
259  }
260  void SetResliceInterpolateToLinear() { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
261  void SetResliceInterpolateToCubic() { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
263 
267  vtkImageData* GetResliceOutput();
268 
270 
274  vtkSetMacro(RestrictPlaneToVolume, vtkTypeBool);
275  vtkGetMacro(RestrictPlaneToVolume, vtkTypeBool);
276  vtkBooleanMacro(RestrictPlaneToVolume, vtkTypeBool);
278 
280 
285  vtkSetMacro(UserControlledLookupTable, vtkTypeBool);
286  vtkGetMacro(UserControlledLookupTable, vtkTypeBool);
287  vtkBooleanMacro(UserControlledLookupTable, vtkTypeBool);
289 
291 
297  vtkSetMacro(TextureInterpolate, vtkTypeBool);
298  vtkGetMacro(TextureInterpolate, vtkTypeBool);
299  vtkBooleanMacro(TextureInterpolate, vtkTypeBool);
301 
303 
307  virtual void SetTextureVisibility(vtkTypeBool);
308  vtkGetMacro(TextureVisibility, vtkTypeBool);
309  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
311 
320  void GetPolyData(vtkPolyData* pd);
321 
329 
334  void UpdatePlacement(void) override;
335 
340  vtkTexture* GetTexture();
341 
343 
349  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
350  virtual void SetColorMap(vtkImageMapToColors*);
352 
354 
358  virtual void SetPlaneProperty(vtkProperty*);
359  vtkGetObjectMacro(PlaneProperty, vtkProperty);
360  virtual void SetSelectedPlaneProperty(vtkProperty*);
361  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
363 
365 
369  void SetPlaneOrientation(int);
370  vtkGetMacro(PlaneOrientation, int);
371  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
372  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
373  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
375 
382  void SetPicker(vtkAbstractPropPicker*);
383 
385 
392  virtual void SetLookupTable(vtkLookupTable*);
393  vtkGetObjectMacro(LookupTable, vtkLookupTable);
395 
397 
401  vtkSetMacro(DisplayText, vtkTypeBool);
402  vtkGetMacro(DisplayText, vtkTypeBool);
403  vtkBooleanMacro(DisplayText, vtkTypeBool);
405 
407 
410  virtual void SetCursorProperty(vtkProperty*);
411  vtkGetObjectMacro(CursorProperty, vtkProperty);
413 
415 
418  virtual void SetMarginProperty(vtkProperty*);
419  vtkGetObjectMacro(MarginProperty, vtkProperty);
421 
423 
427  vtkSetClampMacro(MarginSizeX, double, 0.0, 0.5);
428  vtkGetMacro(MarginSizeX, double);
429  vtkSetClampMacro(MarginSizeY, double, 0.0, 0.5);
430  vtkGetMacro(MarginSizeY, double);
432 
434 
437  void SetTextProperty(vtkTextProperty* tprop);
438  vtkTextProperty* GetTextProperty();
440 
442 
445  virtual void SetTexturePlaneProperty(vtkProperty*);
446  vtkGetObjectMacro(TexturePlaneProperty, vtkProperty);
448 
450 
456  void SetWindowLevel(double window, double level, int copy = 0);
457  void GetWindowLevel(double wl[2]);
458  double GetWindow() { return this->CurrentWindow; }
459  double GetLevel() { return this->CurrentLevel; }
461 
466  int GetCursorData(double xyzv[4]);
467 
473  int GetCursorDataStatus();
474 
476 
480  vtkGetVectorMacro(CurrentCursorPosition, double, 3);
482 
484 
489  vtkGetMacro(CurrentImageValue, double);
491 
493 
496  vtkGetObjectMacro(ResliceAxes, vtkMatrix4x4);
497  vtkGetObjectMacro(Reslice, vtkImageReslice);
499 
501 
508  vtkSetMacro(UseContinuousCursor, vtkTypeBool);
509  vtkGetMacro(UseContinuousCursor, vtkTypeBool);
510  vtkBooleanMacro(UseContinuousCursor, vtkTypeBool);
512 
514 
517  void SetInteraction(vtkTypeBool interact);
518  vtkGetMacro(Interaction, vtkTypeBool);
519  vtkBooleanMacro(Interaction, vtkTypeBool);
521 
523 
526  enum
527  {
528  VTK_CURSOR_ACTION = 0,
529  VTK_SLICE_MOTION_ACTION = 1,
530  VTK_WINDOW_LEVEL_ACTION = 2
531  };
532  vtkSetClampMacro(LeftButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
533  vtkGetMacro(LeftButtonAction, int);
534  vtkSetClampMacro(MiddleButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
535  vtkGetMacro(MiddleButtonAction, int);
536  vtkSetClampMacro(RightButtonAction, int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
537  vtkGetMacro(RightButtonAction, int);
539 
541 
549  enum
550  {
551  VTK_NO_MODIFIER = 0,
552  VTK_SHIFT_MODIFIER = 1,
553  VTK_CONTROL_MODIFIER = 2
554  };
555  vtkSetClampMacro(LeftButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
556  vtkGetMacro(LeftButtonAutoModifier, int);
557  vtkSetClampMacro(MiddleButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
558  vtkGetMacro(MiddleButtonAutoModifier, int);
559  vtkSetClampMacro(RightButtonAutoModifier, int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
560  vtkGetMacro(RightButtonAutoModifier, int);
562 
563 protected:
565  ~vtkImagePlaneWidget() override;
566 
568 
572 
576 
577  enum
578  {
579  VTK_NO_BUTTON = 0,
580  VTK_LEFT_BUTTON = 1,
581  VTK_MIDDLE_BUTTON = 2,
582  VTK_RIGHT_BUTTON = 3
583  };
585 
586  // Manage the state of the widget
587  int State;
589  {
590  Start = 0,
598  Outside
599  };
600 
601  // Handles the events
602  static void ProcessEvents(
603  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
604 
605  // internal utility method that adds observers to the RenderWindowInteractor
606  // so that our ProcessEvents is eventually called. this method is called
607  // by SetEnabled as well as SetInteraction
608  void AddObservers();
609 
610  // ProcessEvents() dispatches to these methods.
611  virtual void OnMouseMove();
612  virtual void OnLeftButtonDown();
613  virtual void OnLeftButtonUp();
614  virtual void OnMiddleButtonDown();
615  virtual void OnMiddleButtonUp();
616  virtual void OnRightButtonDown();
617  virtual void OnRightButtonUp();
618  void OnChar() override;
619 
620  virtual void StartCursor();
621  virtual void StopCursor();
622  virtual void StartSliceMotion();
623  virtual void StopSliceMotion();
624  virtual void StartWindowLevel();
625  virtual void StopWindowLevel();
626 
627  // controlling ivars
628  vtkTypeBool Interaction; // Is the widget responsive to mouse events
634  double CurrentLevel;
636  double InitialLevel;
643 
644  // The geometric representation of the plane and it's outline
648  void HighlightPlane(int highlight);
649  void GeneratePlaneOutline();
650 
651  // Re-builds the plane outline based on the plane source
652  void BuildRepresentation();
653 
654  // Do the picking
656 
657  // Register internal Pickers within PickingManager
658  void RegisterPickers() override;
659 
660  // for negative window values.
661  void InvertTable();
662 
663  // Methods to manipulate the plane
664  void WindowLevel(int X, int Y);
665  void Push(double* p1, double* p2);
666  void Spin(double* p1, double* p2);
667  void Rotate(double* p1, double* p2, double* vpn);
668  void Scale(double* p1, double* p2, int X, int Y);
669  void Translate(double* p1, double* p2);
670 
679  vtkLookupTable* CreateDefaultLookupTable();
680 
681  // Properties used to control the appearance of selected objects and
682  // the manipulator in general. The plane property is actually that for
683  // the outline. The TexturePlaneProperty can be used to control the
684  // lighting etc. of the resliced image data.
690  void CreateDefaultProperties();
691 
692  // Reslice and texture management
693  void UpdatePlane();
694  void GenerateTexturePlane();
695 
696  // The cross-hair cursor
699  double CurrentCursorPosition[3];
700  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
701  void GenerateCursor();
702  void UpdateCursor(int, int);
703  void ActivateCursor(int);
704  int UpdateContinuousCursor(double* q);
705  int UpdateDiscreteCursor(double* q);
707 
708  // The text to display W/L, image data
711  void GenerateText();
712  void ManageTextDisplay();
713  void ActivateText(int);
714 
715  // Oblique reslice control
716  double RotateAxis[3];
717  double RadiusVector[3];
718  void AdjustState();
719 
720  // Visible margins to assist user interaction
724  void GenerateMargins();
725  void UpdateMargins();
726  void ActivateMargins(int);
727  double MarginSizeX;
728  double MarginSizeY;
729 
730 private:
731  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
732  void operator=(const vtkImagePlaneWidget&) = delete;
733 };
734 
735 #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:51
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:41
double GetLevel()
Set/Get the current window and level values.
represent surface properties of a geometric object
Definition: vtkProperty.h:67
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:60
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:90
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:56
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:39
#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:53
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:68
#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:39
vtkTypeBool UserControlledLookupTable