VTK
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 =========================================================================*/
106 #ifndef vtkImagePlaneWidget_h
107 #define vtkImagePlaneWidget_h
108 
109 #include "vtkInteractionWidgetsModule.h" // For export macro
110 #include "vtkPolyDataSourceWidget.h"
111 
112 class vtkActor;
114 class vtkDataSetMapper;
115 class vtkImageData;
116 class vtkImageMapToColors;
117 class vtkImageReslice;
118 class vtkLookupTable;
119 class vtkMatrix4x4;
120 class vtkPlaneSource;
121 class vtkPoints;
122 class vtkPolyData;
123 class vtkProperty;
124 class vtkTextActor;
125 class vtkTextProperty;
126 class vtkTexture;
127 class vtkTransform;
128 
129 #define VTK_NEAREST_RESLICE 0
130 #define VTK_LINEAR_RESLICE 1
131 #define VTK_CUBIC_RESLICE 2
132 
133 // Private.
134 #define VTK_IMAGE_PLANE_WIDGET_MAX_TEXTBUFF 128
135 
136 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
137 {
138 public:
142  static vtkImagePlaneWidget *New();
143 
145  void PrintSelf(ostream& os, vtkIndent indent) override;
146 
148 
151  void SetEnabled(int) override;
152  void PlaceWidget(double bounds[6]) override;
153  void PlaceWidget() override
154  {this->Superclass::PlaceWidget();}
155  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
156  double zmin, double zmax) override
157  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
159 
163  void SetInputConnection(vtkAlgorithmOutput* aout) override;
164 
166 
169  void SetOrigin(double x, double y, double z);
170  void SetOrigin(double xyz[3]);
171  double* GetOrigin() VTK_SIZEHINT(3);
172  void GetOrigin(double xyz[3]);
174 
176 
179  void SetPoint1(double x, double y, double z);
180  void SetPoint1(double xyz[3]);
181  double* GetPoint1() VTK_SIZEHINT(3);
182  void GetPoint1(double xyz[3]);
184 
186 
189  void SetPoint2(double x, double y, double z);
190  void SetPoint2(double xyz[3]);
191  double* GetPoint2() VTK_SIZEHINT(3);
192  void GetPoint2(double xyz[3]);
194 
196 
199  double* GetCenter() VTK_SIZEHINT(3);
200  void GetCenter(double xyz[3]);
202 
204 
207  double* GetNormal() VTK_SIZEHINT(3);
208  void GetNormal(double xyz[3]);
210 
214  void GetVector1(double v1[3]);
215 
219  void GetVector2(double v2[3]);
220 
224  int GetSliceIndex();
225 
229  void SetSliceIndex(int index);
230 
234  double GetSlicePosition();
235 
239  void SetSlicePosition(double position);
240 
242 
245  void SetResliceInterpolate(int);
246  vtkGetMacro(ResliceInterpolate,int);
248  { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); }
250  { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
252  { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
254 
258  vtkImageData* GetResliceOutput();
259 
261 
265  vtkSetMacro(RestrictPlaneToVolume,vtkTypeBool);
266  vtkGetMacro(RestrictPlaneToVolume,vtkTypeBool);
267  vtkBooleanMacro(RestrictPlaneToVolume,vtkTypeBool);
269 
271 
276  vtkSetMacro(UserControlledLookupTable,vtkTypeBool);
277  vtkGetMacro(UserControlledLookupTable,vtkTypeBool);
278  vtkBooleanMacro(UserControlledLookupTable,vtkTypeBool);
280 
282 
288  vtkSetMacro(TextureInterpolate,vtkTypeBool);
289  vtkGetMacro(TextureInterpolate,vtkTypeBool);
290  vtkBooleanMacro(TextureInterpolate,vtkTypeBool);
292 
294 
298  virtual void SetTextureVisibility(vtkTypeBool);
299  vtkGetMacro(TextureVisibility,vtkTypeBool);
300  vtkBooleanMacro(TextureVisibility,vtkTypeBool);
302 
311  void GetPolyData(vtkPolyData *pd);
312 
320 
325  void UpdatePlacement(void) override;
326 
331  vtkTexture *GetTexture();
332 
334 
340  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
341  virtual void SetColorMap(vtkImageMapToColors *);
343 
345 
349  virtual void SetPlaneProperty(vtkProperty*);
350  vtkGetObjectMacro(PlaneProperty,vtkProperty);
351  virtual void SetSelectedPlaneProperty(vtkProperty*);
352  vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
354 
356 
360  void SetPlaneOrientation(int);
361  vtkGetMacro(PlaneOrientation,int);
363  { this->SetPlaneOrientation(0); }
365  { this->SetPlaneOrientation(1); }
367  { this->SetPlaneOrientation(2); }
369 
376  void SetPicker(vtkAbstractPropPicker*);
377 
379 
386  virtual void SetLookupTable(vtkLookupTable*);
387  vtkGetObjectMacro(LookupTable,vtkLookupTable);
389 
391 
395  vtkSetMacro(DisplayText,vtkTypeBool);
396  vtkGetMacro(DisplayText,vtkTypeBool);
397  vtkBooleanMacro(DisplayText,vtkTypeBool);
399 
401 
404  virtual void SetCursorProperty(vtkProperty*);
405  vtkGetObjectMacro(CursorProperty,vtkProperty);
407 
409 
412  virtual void SetMarginProperty(vtkProperty*);
413  vtkGetObjectMacro(MarginProperty,vtkProperty);
415 
417 
421  vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5);
422  vtkGetMacro(MarginSizeX, double);
423  vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5);
424  vtkGetMacro(MarginSizeY, double);
426 
428 
431  void SetTextProperty(vtkTextProperty* tprop);
432  vtkTextProperty* GetTextProperty();
434 
436 
439  virtual void SetTexturePlaneProperty(vtkProperty*);
440  vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
442 
444 
450  void SetWindowLevel(double window, double level, int copy = 0);
451  void GetWindowLevel(double wl[2]);
452  double GetWindow(){return this->CurrentWindow;}
453  double GetLevel(){return this->CurrentLevel;}
455 
460  int GetCursorData(double xyzv[4]);
461 
467  int GetCursorDataStatus();
468 
470 
474  vtkGetVectorMacro(CurrentCursorPosition,double,3);
476 
478 
483  vtkGetMacro(CurrentImageValue,double);
485 
487 
490  vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 );
491  vtkGetObjectMacro( Reslice, vtkImageReslice );
493 
495 
502  vtkSetMacro(UseContinuousCursor,vtkTypeBool);
503  vtkGetMacro(UseContinuousCursor,vtkTypeBool);
504  vtkBooleanMacro(UseContinuousCursor,vtkTypeBool);
506 
508 
511  void SetInteraction(vtkTypeBool interact);
512  vtkGetMacro(Interaction,vtkTypeBool);
513  vtkBooleanMacro(Interaction,vtkTypeBool);
515 
517 
520  enum
521  {
522  VTK_CURSOR_ACTION = 0,
523  VTK_SLICE_MOTION_ACTION = 1,
524  VTK_WINDOW_LEVEL_ACTION = 2
525  };
526  vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
527  vtkGetMacro(LeftButtonAction, int);
528  vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
529  vtkGetMacro(MiddleButtonAction, int);
530  vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
531  vtkGetMacro(RightButtonAction, int);
533 
535 
543  enum
544  {
545  VTK_NO_MODIFIER = 0,
546  VTK_SHIFT_MODIFIER = 1,
547  VTK_CONTROL_MODIFIER = 2
548  };
549  vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
550  vtkGetMacro(LeftButtonAutoModifier, int);
551  vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
552  vtkGetMacro(MiddleButtonAutoModifier, int);
553  vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
554  vtkGetMacro(RightButtonAutoModifier, int);
556 
557 protected:
559  ~vtkImagePlaneWidget() override;
560 
562 
566 
570 
571  enum
572  {
573  VTK_NO_BUTTON = 0,
574  VTK_LEFT_BUTTON = 1,
575  VTK_MIDDLE_BUTTON = 2,
576  VTK_RIGHT_BUTTON = 3
577  };
579 
580  // Manage the state of the widget
581  int State;
583  {
584  Start=0,
592  Outside
593  };
594 
595  // Handles the events
596  static void ProcessEvents(vtkObject* object,
597  unsigned long event,
598  void* clientdata,
599  void* calldata);
600 
601  // internal utility method that adds observers to the RenderWindowInteractor
602  // so that our ProcessEvents is eventually called. this method is called
603  // by SetEnabled as well as SetInteraction
604  void AddObservers();
605 
606  // ProcessEvents() dispatches to these methods.
607  virtual void OnMouseMove();
608  virtual void OnLeftButtonDown();
609  virtual void OnLeftButtonUp();
610  virtual void OnMiddleButtonDown();
611  virtual void OnMiddleButtonUp();
612  virtual void OnRightButtonDown();
613  virtual void OnRightButtonUp();
614  void OnChar() override;
615 
616  virtual void StartCursor();
617  virtual void StopCursor();
618  virtual void StartSliceMotion();
619  virtual void StopSliceMotion();
620  virtual void StartWindowLevel();
621  virtual void StopWindowLevel();
622 
623  // controlling ivars
624  vtkTypeBool Interaction; // Is the widget responsive to mouse events
630  double CurrentLevel;
632  double InitialLevel;
639 
640  // The geometric representation of the plane and it's outline
644  void HighlightPlane(int highlight);
645  void GeneratePlaneOutline();
646 
647  // Re-builds the plane outline based on the plane source
648  void BuildRepresentation();
649 
650  // Do the picking
652 
653  // Register internal Pickers within PickingManager
654  void RegisterPickers() override;
655 
656  // for negative window values.
657  void InvertTable();
658 
659  // Methods to manipulate the plane
660  void WindowLevel(int X, int Y);
661  void Push(double *p1, double *p2);
662  void Spin(double *p1, double *p2);
663  void Rotate(double *p1, double *p2, double *vpn);
664  void Scale(double *p1, double *p2, int X, int Y);
665  void Translate(double *p1, double *p2);
666 
675  vtkLookupTable *CreateDefaultLookupTable();
676 
677  // Properties used to control the appearance of selected objects and
678  // the manipulator in general. The plane property is actually that for
679  // the outline. The TexturePlaneProperty can be used to control the
680  // lighting etc. of the resliced image data.
686  void CreateDefaultProperties();
687 
688  // Reslice and texture management
689  void UpdatePlane();
690  void GenerateTexturePlane();
691 
692  // The cross-hair cursor
695  double CurrentCursorPosition[3];
696  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
697  void GenerateCursor();
698  void UpdateCursor(int,int);
699  void ActivateCursor(int);
700  int UpdateContinuousCursor(double *q);
701  int UpdateDiscreteCursor(double *q);
703 
704  // The text to display W/L, image data
707  void GenerateText();
708  void ManageTextDisplay();
709  void ActivateText(int);
710 
711  // Oblique reslice control
712  double RotateAxis[3];
713  double RadiusVector[3];
714  void AdjustState();
715 
716  // Visible margins to assist user interaction
720  void GenerateMargins();
721  void UpdateMargins();
722  void ActivateMargins(int);
723  double MarginSizeX;
724  double MarginSizeY;
725 
726 private:
727  vtkImagePlaneWidget(const vtkImagePlaneWidget&) = delete;
728  void operator=(const vtkImagePlaneWidget&) = delete;
729 };
730 
731 #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:59
#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:66
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:85
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: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:45
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:71
#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