VTK  9.0.1
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:
136  static vtkImagePlaneWidget* New();
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 
158  void SetInputConnection(vtkAlgorithmOutput* aout) override;
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);
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 
253  vtkImageData* GetResliceOutput();
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 
293  virtual void SetTextureVisibility(vtkTypeBool);
294  vtkGetMacro(TextureVisibility, vtkTypeBool);
295  vtkBooleanMacro(TextureVisibility, vtkTypeBool);
297 
306  void GetPolyData(vtkPolyData* pd);
307 
315 
320  void UpdatePlacement(void) override;
321 
326  vtkTexture* GetTexture();
327 
329 
335  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
336  virtual void SetColorMap(vtkImageMapToColors*);
338 
340 
344  virtual void SetPlaneProperty(vtkProperty*);
345  vtkGetObjectMacro(PlaneProperty, vtkProperty);
346  virtual void SetSelectedPlaneProperty(vtkProperty*);
347  vtkGetObjectMacro(SelectedPlaneProperty, vtkProperty);
349 
351 
355  void SetPlaneOrientation(int);
356  vtkGetMacro(PlaneOrientation, int);
357  void SetPlaneOrientationToXAxes() { this->SetPlaneOrientation(0); }
358  void SetPlaneOrientationToYAxes() { this->SetPlaneOrientation(1); }
359  void SetPlaneOrientationToZAxes() { this->SetPlaneOrientation(2); }
361 
368  void SetPicker(vtkAbstractPropPicker*);
369 
371 
378  virtual void SetLookupTable(vtkLookupTable*);
379  vtkGetObjectMacro(LookupTable, vtkLookupTable);
381 
383 
387  vtkSetMacro(DisplayText, vtkTypeBool);
388  vtkGetMacro(DisplayText, vtkTypeBool);
389  vtkBooleanMacro(DisplayText, vtkTypeBool);
391 
393 
396  virtual void SetCursorProperty(vtkProperty*);
397  vtkGetObjectMacro(CursorProperty, vtkProperty);
399 
401 
404  virtual void SetMarginProperty(vtkProperty*);
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 
423  void SetTextProperty(vtkTextProperty* tprop);
424  vtkTextProperty* GetTextProperty();
426 
428 
431  virtual void SetTexturePlaneProperty(vtkProperty*);
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 
459  int GetCursorDataStatus();
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:
551  ~vtkImagePlaneWidget() override;
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);
635  void GeneratePlaneOutline();
636 
637  // Re-builds the plane outline based on the plane source
638  void BuildRepresentation();
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 
665  vtkLookupTable* CreateDefaultLookupTable();
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.
676  void CreateDefaultProperties();
677 
678  // Reslice and texture management
679  void UpdatePlane();
680  void GenerateTexturePlane();
681 
682  // The cross-hair cursor
685  double CurrentCursorPosition[3];
686  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
687  void GenerateCursor();
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();
698  void ManageTextDisplay();
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
710  void GenerateMargins();
711  void UpdateMargins();
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
#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:45
abstract base class for most VTK objects
Definition: vtkObject.h:53
#define VTK_LINEAR_RESLICE
abstract PolyDataSource-based 3D widget
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
double GetLevel()
Set/Get the current window and level values.
represent surface properties of a geometric object
Definition: vtkProperty.h:61
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:54
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:84
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()...
void SetResliceInterpolateToNearestNeighbour()
Set the interpolation to use when texturing the plane.
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:50
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:33
#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:41
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:65
#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:33
vtkTypeBool UserControlledLookupTable