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 =========================================================================*/
112 #ifndef __vtkImagePlaneWidget_h
113 #define __vtkImagePlaneWidget_h
114 
115 #include "vtkPolyDataSourceWidget.h"
116 
117 class vtkActor;
119 class vtkDataSetMapper;
120 class vtkImageData;
121 class vtkImageMapToColors;
122 class vtkImageReslice;
123 class vtkLookupTable;
124 class vtkMatrix4x4;
125 class vtkPlaneSource;
126 class vtkPoints;
127 class vtkPolyData;
128 class vtkProperty;
129 class vtkTextActor;
130 class vtkTextProperty;
131 class vtkTexture;
132 class vtkTransform;
133 
134 #define VTK_NEAREST_RESLICE 0
135 #define VTK_LINEAR_RESLICE 1
136 #define VTK_CUBIC_RESLICE 2
137 
139 {
140 public:
142  static vtkImagePlaneWidget *New();
143 
145  void PrintSelf(ostream& os, vtkIndent indent);
146 
148 
149  virtual void SetEnabled(int);
150  virtual void PlaceWidget(double bounds[6]);
151  void PlaceWidget()
152  {this->Superclass::PlaceWidget();}
153  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
154  double zmin, double zmax)
155  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
157 
159  void SetInput(vtkDataSet* input);
160 
162 
163  void SetOrigin(double x, double y, double z);
164  void SetOrigin(double xyz[3]);
165  double* GetOrigin();
166  void GetOrigin(double xyz[3]);
168 
170 
172  void SetPoint1(double x, double y, double z);
173  void SetPoint1(double xyz[3]);
174  double* GetPoint1();
175  void GetPoint1(double xyz[3]);
177 
179 
181  void SetPoint2(double x, double y, double z);
182  void SetPoint2(double xyz[3]);
183  double* GetPoint2();
184  void GetPoint2(double xyz[3]);
186 
188 
189  double* GetCenter();
190  void GetCenter(double xyz[3]);
192 
194 
195  double* GetNormal();
196  void GetNormal(double xyz[3]);
198 
200  void GetVector1(double v1[3]);
201 
203  void GetVector2(double v2[3]);
204 
206  int GetSliceIndex();
207 
209  void SetSliceIndex(int index);
210 
212  double GetSlicePosition();
213 
215  void SetSlicePosition(double position);
216 
218 
219  void SetResliceInterpolate(int);
220  vtkGetMacro(ResliceInterpolate,int);
222  { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); }
224  { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
226  { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
228 
230  vtkImageData* GetResliceOutput();
231 
233 
234  vtkSetMacro(RestrictPlaneToVolume,int);
235  vtkGetMacro(RestrictPlaneToVolume,int);
236  vtkBooleanMacro(RestrictPlaneToVolume,int);
238 
240 
242  vtkSetMacro(UserControlledLookupTable,int);
243  vtkGetMacro(UserControlledLookupTable,int);
244  vtkBooleanMacro(UserControlledLookupTable,int);
246 
248 
252  vtkSetMacro(TextureInterpolate,int);
253  vtkGetMacro(TextureInterpolate,int);
254  vtkBooleanMacro(TextureInterpolate,int);
256 
258 
260  virtual void SetTextureVisibility(int);
261  vtkGetMacro(TextureVisibility,int);
262  vtkBooleanMacro(TextureVisibility,int);
264 
271  void GetPolyData(vtkPolyData *pd);
272 
279 
283  void UpdatePlacement(void);
284 
287  vtkTexture *GetTexture();
288 
290 
294  vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
295  virtual void SetColorMap(vtkImageMapToColors *);
297 
299 
301  virtual void SetPlaneProperty(vtkProperty*);
302  vtkGetObjectMacro(PlaneProperty,vtkProperty);
303  virtual void SetSelectedPlaneProperty(vtkProperty*);
304  vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
306 
308 
310  void SetPlaneOrientation(int);
311  vtkGetMacro(PlaneOrientation,int);
313  { this->SetPlaneOrientation(0); }
315  { this->SetPlaneOrientation(1); }
317  { this->SetPlaneOrientation(2); }
319 
324  void SetPicker(vtkAbstractPropPicker*);
325 
327 
332  virtual void SetLookupTable(vtkLookupTable*);
333  vtkGetObjectMacro(LookupTable,vtkLookupTable);
335 
337 
339  vtkSetMacro(DisplayText,int);
340  vtkGetMacro(DisplayText,int);
341  vtkBooleanMacro(DisplayText,int);
343 
345 
346  virtual void SetCursorProperty(vtkProperty*);
347  vtkGetObjectMacro(CursorProperty,vtkProperty);
349 
351 
352  virtual void SetMarginProperty(vtkProperty*);
353  vtkGetObjectMacro(MarginProperty,vtkProperty);
355 
357 
359  vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5);
360  vtkGetMacro(MarginSizeX, double);
361  vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5);
362  vtkGetMacro(MarginSizeY, double);
364 
366 
368  void SetTextProperty(vtkTextProperty* tprop);
369  vtkTextProperty* GetTextProperty();
371 
373 
374  virtual void SetTexturePlaneProperty(vtkProperty*);
375  vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
377 
379 
383  void SetWindowLevel(double window, double level, int copy = 0);
384  void GetWindowLevel(double wl[2]);
385  double GetWindow(){return this->CurrentWindow;}
386  double GetLevel(){return this->CurrentLevel;}
388 
391  int GetCursorData(double xyzv[4]);
392 
396  int GetCursorDataStatus();
397 
399 
401  vtkGetVectorMacro(CurrentCursorPosition,double,3);
403 
405 
408  vtkGetMacro(CurrentImageValue,double);
410 
412 
413  vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 );
414  vtkGetObjectMacro( Reslice, vtkImageReslice );
416 
418 
424  vtkSetMacro(UseContinuousCursor,int);
425  vtkGetMacro(UseContinuousCursor,int);
426  vtkBooleanMacro(UseContinuousCursor,int);
428 
430 
431  void SetInteraction(int interact);
432  vtkGetMacro(Interaction,int);
433  vtkBooleanMacro(Interaction,int);
435 
436  //BTX
438 
439  enum
440  {
441  VTK_CURSOR_ACTION = 0,
442  VTK_SLICE_MOTION_ACTION = 1,
443  VTK_WINDOW_LEVEL_ACTION = 2
444  };
445  //ETX
446  vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
447  vtkGetMacro(LeftButtonAction, int);
448  vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
449  vtkGetMacro(MiddleButtonAction, int);
450  vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
451  vtkGetMacro(RightButtonAction, int);
453 
454  //BTX
456 
462  enum
463  {
464  VTK_NO_MODIFIER = 0,
465  VTK_SHIFT_MODIFIER = 1,
466  VTK_CONTROL_MODIFIER = 2
467  };
468  //ETX
469  vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
470  vtkGetMacro(LeftButtonAutoModifier, int);
471  vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
472  vtkGetMacro(MiddleButtonAutoModifier, int);
473  vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
474  vtkGetMacro(RightButtonAutoModifier, int);
476 
477 protected:
480 
482 
486 
490 
491  //BTX
492  enum
493  {
494  VTK_NO_BUTTON = 0,
495  VTK_LEFT_BUTTON = 1,
496  VTK_MIDDLE_BUTTON = 2,
497  VTK_RIGHT_BUTTON = 3
498  };
499  //ETX
501 
502  //BTX - manage the state of the widget
503  int State;
505  {
506  Start=0,
514  Outside
515  };
516  //ETX
517 
518  // Handles the events
519  static void ProcessEvents(vtkObject* object,
520  unsigned long event,
521  void* clientdata,
522  void* calldata);
523 
524  // internal utility method that adds observers to the RenderWindowInteractor
525  // so that our ProcessEvents is eventually called. this method is called
526  // by SetEnabled as well as SetInteraction
527  void AddObservers();
528 
529  // ProcessEvents() dispatches to these methods.
530  virtual void OnMouseMove();
531  virtual void OnLeftButtonDown();
532  virtual void OnLeftButtonUp();
533  virtual void OnMiddleButtonDown();
534  virtual void OnMiddleButtonUp();
535  virtual void OnRightButtonDown();
536  virtual void OnRightButtonUp();
537  virtual void OnChar();
538 
539  virtual void StartCursor();
540  virtual void StopCursor();
541  virtual void StartSliceMotion();
542  virtual void StopSliceMotion();
543  virtual void StartWindowLevel();
544  virtual void StopWindowLevel();
545 
546  // controlling ivars
547  int Interaction; // Is the widget responsive to mouse events
553  double CurrentLevel;
555  double InitialLevel;
562 
563  // The geometric represenation of the plane and it's outline
567  void HighlightPlane(int highlight);
568  void GeneratePlaneOutline();
569 
570  // Re-builds the plane outline based on the plane source
571  void BuildRepresentation();
572 
573  // Do the picking
575 
576  // for negative window values.
577  void InvertTable();
578 
579  // Methods to manipulate the plane
580  void WindowLevel(int X, int Y);
581  void Push(double *p1, double *p2);
582  void Spin(double *p1, double *p2);
583  void Rotate(double *p1, double *p2, double *vpn);
584  void Scale(double *p1, double *p2, int X, int Y);
585  void Translate(double *p1, double *p2);
586 
595  vtkLookupTable *CreateDefaultLookupTable();
596 
597  // Properties used to control the appearance of selected objects and
598  // the manipulator in general. The plane property is actually that for
599  // the outline. The TexturePlaneProperty can be used to control the
600  // lighting etc. of the resliced image data.
606  void CreateDefaultProperties();
607 
608  // Reslice and texture management
609  void UpdatePlane();
610  void GenerateTexturePlane();
611 
612  // The cross-hair cursor
615  double CurrentCursorPosition[3];
616  double CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
617  void GenerateCursor();
618  void UpdateCursor(int,int);
619  void ActivateCursor(int);
620  int UpdateContinuousCursor(double *q);
621  int UpdateDiscreteCursor(double *q);
623 
624  // The text to display W/L, image data
626  char TextBuff[128];
627  void GenerateText();
628  void ManageTextDisplay();
629  void ActivateText(int);
630 
631  // Oblique reslice control
632  double RotateAxis[3];
633  double RadiusVector[3];
634  void AdjustState();
635 
636  // Visible margins to assist user interaction
640  void GenerateMargins();
641  void UpdateMargins();
642  void ActivateMargins(int);
643  double MarginSizeX;
644  double MarginSizeY;
645 
646 private:
647  vtkImagePlaneWidget(const vtkImagePlaneWidget&); //Not implemented
648  void operator=(const vtkImagePlaneWidget&); //Not implemented
649 };
650 
651 #endif