VTK
dox/Widgets/vtkImagePlaneWidget.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkImagePlaneWidget.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00112 #ifndef __vtkImagePlaneWidget_h
00113 #define __vtkImagePlaneWidget_h
00114 
00115 #include "vtkPolyDataSourceWidget.h"
00116 
00117 class vtkActor;
00118 class vtkAbstractPropPicker;
00119 class vtkDataSetMapper;
00120 class vtkImageData;
00121 class vtkImageMapToColors;
00122 class vtkImageReslice;
00123 class vtkLookupTable;
00124 class vtkMatrix4x4;
00125 class vtkPlaneSource;
00126 class vtkPoints;
00127 class vtkPolyData;
00128 class vtkProperty;
00129 class vtkTextActor;
00130 class vtkTextProperty;
00131 class vtkTexture;
00132 class vtkTransform;
00133 
00134 #define VTK_NEAREST_RESLICE 0
00135 #define VTK_LINEAR_RESLICE  1
00136 #define VTK_CUBIC_RESLICE   2
00137 
00138 class VTK_WIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
00139 {
00140 public:
00142   static vtkImagePlaneWidget *New();
00143 
00144   vtkTypeMacro(vtkImagePlaneWidget,vtkPolyDataSourceWidget);
00145   void PrintSelf(ostream& os, vtkIndent indent);
00146 
00148 
00149   virtual void SetEnabled(int);
00150   virtual void PlaceWidget(double bounds[6]);
00151   void PlaceWidget()
00152     {this->Superclass::PlaceWidget();}
00153   void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
00154                    double zmin, double zmax)
00155     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00157 
00159   void SetInput(vtkDataSet* input);
00160 
00162 
00163   void SetOrigin(double x, double y, double z);
00164   void SetOrigin(double xyz[3]);
00165   double* GetOrigin();
00166   void GetOrigin(double xyz[3]);
00168 
00170 
00172   void SetPoint1(double x, double y, double z);
00173   void SetPoint1(double xyz[3]);
00174   double* GetPoint1();
00175   void GetPoint1(double xyz[3]);
00177 
00179 
00181   void SetPoint2(double x, double y, double z);
00182   void SetPoint2(double xyz[3]);
00183   double* GetPoint2();
00184   void GetPoint2(double xyz[3]);
00186 
00188 
00189   double* GetCenter();
00190   void GetCenter(double xyz[3]);
00192 
00194 
00195   double* GetNormal();
00196   void GetNormal(double xyz[3]);
00198 
00200   void GetVector1(double v1[3]);
00201 
00203   void GetVector2(double v2[3]);
00204 
00206   int GetSliceIndex();
00207 
00209   void SetSliceIndex(int index);
00210 
00212   double GetSlicePosition();
00213 
00215   void SetSlicePosition(double position);
00216 
00218 
00219   void SetResliceInterpolate(int);
00220   vtkGetMacro(ResliceInterpolate,int);
00221   void SetResliceInterpolateToNearestNeighbour()
00222     { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); }
00223   void SetResliceInterpolateToLinear()
00224     { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); }
00225   void SetResliceInterpolateToCubic()
00226     { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); }
00228 
00230   vtkImageData* GetResliceOutput();
00231 
00233 
00234   vtkSetMacro(RestrictPlaneToVolume,int);
00235   vtkGetMacro(RestrictPlaneToVolume,int);
00236   vtkBooleanMacro(RestrictPlaneToVolume,int);
00238 
00240 
00242   vtkSetMacro(UserControlledLookupTable,int);
00243   vtkGetMacro(UserControlledLookupTable,int);
00244   vtkBooleanMacro(UserControlledLookupTable,int);
00246 
00248 
00252   vtkSetMacro(TextureInterpolate,int);
00253   vtkGetMacro(TextureInterpolate,int);
00254   vtkBooleanMacro(TextureInterpolate,int);
00256 
00258 
00260   virtual void SetTextureVisibility(int);
00261   vtkGetMacro(TextureVisibility,int);
00262   vtkBooleanMacro(TextureVisibility,int);
00264   
00271   void GetPolyData(vtkPolyData *pd);
00272 
00278   vtkPolyDataAlgorithm* GetPolyDataAlgorithm();
00279 
00283   void UpdatePlacement(void);
00284 
00287   vtkTexture *GetTexture();
00288 
00290 
00294   vtkGetObjectMacro(ColorMap, vtkImageMapToColors);
00295   virtual void SetColorMap(vtkImageMapToColors *);
00297 
00299 
00301   virtual void SetPlaneProperty(vtkProperty*);
00302   vtkGetObjectMacro(PlaneProperty,vtkProperty);
00303   virtual void SetSelectedPlaneProperty(vtkProperty*);
00304   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
00306 
00308 
00310   void SetPlaneOrientation(int);
00311   vtkGetMacro(PlaneOrientation,int);
00312   void SetPlaneOrientationToXAxes()
00313     { this->SetPlaneOrientation(0); }
00314   void SetPlaneOrientationToYAxes()
00315     { this->SetPlaneOrientation(1); }
00316   void SetPlaneOrientationToZAxes()
00317     { this->SetPlaneOrientation(2); }
00319 
00324   void SetPicker(vtkAbstractPropPicker*);
00325 
00327 
00332   virtual void SetLookupTable(vtkLookupTable*);
00333   vtkGetObjectMacro(LookupTable,vtkLookupTable);
00335 
00337 
00339   vtkSetMacro(DisplayText,int);
00340   vtkGetMacro(DisplayText,int);
00341   vtkBooleanMacro(DisplayText,int);
00343 
00345 
00346   virtual void SetCursorProperty(vtkProperty*);
00347   vtkGetObjectMacro(CursorProperty,vtkProperty);
00349 
00351 
00352   virtual void SetMarginProperty(vtkProperty*);
00353   vtkGetObjectMacro(MarginProperty,vtkProperty);
00355 
00357 
00359   vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5);
00360   vtkGetMacro(MarginSizeX, double);
00361   vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5);
00362   vtkGetMacro(MarginSizeY, double);
00364 
00366 
00368   void SetTextProperty(vtkTextProperty* tprop);
00369   vtkTextProperty* GetTextProperty();
00371 
00373 
00374   virtual void SetTexturePlaneProperty(vtkProperty*);
00375   vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
00377 
00379 
00383   void SetWindowLevel(double window, double level, int copy = 0);
00384   void GetWindowLevel(double wl[2]);
00385   double GetWindow(){return this->CurrentWindow;}
00386   double GetLevel(){return this->CurrentLevel;}
00388 
00391   int GetCursorData(double xyzv[4]);
00392 
00396   int GetCursorDataStatus();
00397 
00399 
00401   vtkGetVectorMacro(CurrentCursorPosition,double,3);
00403 
00405 
00408   vtkGetMacro(CurrentImageValue,double);
00410 
00412 
00418   vtkSetMacro(UseContinuousCursor,int);
00419   vtkGetMacro(UseContinuousCursor,int);
00420   vtkBooleanMacro(UseContinuousCursor,int);
00422 
00424 
00425   void SetInteraction(int interact);
00426   vtkGetMacro(Interaction,int);
00427   vtkBooleanMacro(Interaction,int);
00429 
00431 
00432   enum
00433   {
00434     VTK_CURSOR_ACTION       = 0,
00435     VTK_SLICE_MOTION_ACTION = 1,
00436     VTK_WINDOW_LEVEL_ACTION = 2
00437   };
00438   //ETX
00439   vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00440   vtkGetMacro(LeftButtonAction, int);
00441   vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00442   vtkGetMacro(MiddleButtonAction, int);
00443   vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00444   vtkGetMacro(RightButtonAction, int);
00446 
00448 
00454   enum
00455   {
00456     VTK_NO_MODIFIER         = 0,
00457     VTK_SHIFT_MODIFIER      = 1,
00458     VTK_CONTROL_MODIFIER    = 2
00459   };
00460   //ETX
00461   vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00462   vtkGetMacro(LeftButtonAutoModifier, int);
00463   vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00464   vtkGetMacro(MiddleButtonAutoModifier, int);
00465   vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00466   vtkGetMacro(RightButtonAutoModifier, int);
00468 
00469 protected:
00470   vtkImagePlaneWidget();
00471   ~vtkImagePlaneWidget();
00472 
00473   int TextureVisibility;
00474   
00475   int LeftButtonAction;
00476   int MiddleButtonAction;
00477   int RightButtonAction;
00478 
00479   int LeftButtonAutoModifier;
00480   int MiddleButtonAutoModifier;
00481   int RightButtonAutoModifier;
00482 
00483   //BTX
00484   enum
00485   {
00486     VTK_NO_BUTTON     = 0,
00487     VTK_LEFT_BUTTON   = 1,
00488     VTK_MIDDLE_BUTTON = 2,
00489     VTK_RIGHT_BUTTON  = 3
00490   };
00491   //ETX
00492   int LastButtonPressed;
00493 
00494   //BTX - manage the state of the widget
00495   int State;
00496   enum WidgetState
00497   {
00498     Start=0,
00499     Cursoring,
00500     WindowLevelling,
00501     Pushing,
00502     Spinning,
00503     Rotating,
00504     Moving,
00505     Scaling,
00506     Outside
00507   };
00508   //ETX
00509 
00510   // Handles the events
00511   static void ProcessEvents(vtkObject* object,
00512                             unsigned long event,
00513                             void* clientdata,
00514                             void* calldata);
00515 
00516   // internal utility method that adds observers to the RenderWindowInteractor
00517   // so that our ProcessEvents is eventually called.  this method is called
00518   // by SetEnabled as well as SetInteraction
00519   void AddObservers();
00520 
00521   // ProcessEvents() dispatches to these methods.
00522   virtual void OnMouseMove();
00523   virtual void OnLeftButtonDown();
00524   virtual void OnLeftButtonUp();
00525   virtual void OnMiddleButtonDown();
00526   virtual void OnMiddleButtonUp();
00527   virtual void OnRightButtonDown();
00528   virtual void OnRightButtonUp();
00529   virtual void OnChar();
00530 
00531   virtual void StartCursor();
00532   virtual void StopCursor();
00533   virtual void StartSliceMotion();
00534   virtual void StopSliceMotion();
00535   virtual void StartWindowLevel();
00536   virtual void StopWindowLevel();
00537 
00538   // controlling ivars
00539   int    Interaction; // Is the widget responsive to mouse events
00540   int    PlaneOrientation;
00541   int    RestrictPlaneToVolume;
00542   double OriginalWindow;
00543   double OriginalLevel;
00544   double CurrentWindow;
00545   double CurrentLevel;
00546   double InitialWindow;
00547   double InitialLevel;
00548   int    StartWindowLevelPositionX;
00549   int    StartWindowLevelPositionY;
00550   int    ResliceInterpolate;
00551   int    TextureInterpolate;
00552   int    UserControlledLookupTable;
00553   int    DisplayText;
00554 
00555   // The geometric represenation of the plane and it's outline
00556   vtkPlaneSource    *PlaneSource;
00557   vtkPolyData       *PlaneOutlinePolyData;
00558   vtkActor          *PlaneOutlineActor;
00559   void               HighlightPlane(int highlight);
00560   void               GeneratePlaneOutline();
00561 
00562   // Re-builds the plane outline based on the plane source
00563   void BuildRepresentation();
00564 
00565   // Do the picking
00566   vtkAbstractPropPicker *PlanePicker;
00567 
00568   // for negative window values.
00569   void InvertTable();
00570 
00571   // Methods to manipulate the plane
00572   void WindowLevel(int X, int Y);
00573   void Push(double *p1, double *p2);
00574   void Spin(double *p1, double *p2);
00575   void Rotate(double *p1, double *p2, double *vpn);
00576   void Scale(double *p1, double *p2, int X, int Y);
00577   void Translate(double *p1, double *p2);
00578 
00579   vtkImageData         *ImageData;
00580   vtkImageReslice      *Reslice;
00581   vtkMatrix4x4         *ResliceAxes;
00582   vtkTransform         *Transform;
00583   vtkActor             *TexturePlaneActor;
00584   vtkImageMapToColors  *ColorMap;
00585   vtkTexture           *Texture;
00586   vtkLookupTable       *LookupTable;
00587   vtkLookupTable       *CreateDefaultLookupTable();
00588 
00589   // Properties used to control the appearance of selected objects and
00590   // the manipulator in general.  The plane property is actually that for
00591   // the outline.  The TexturePlaneProperty can be used to control the
00592   // lighting etc. of the resliced image data.
00593   vtkProperty   *PlaneProperty;
00594   vtkProperty   *SelectedPlaneProperty;
00595   vtkProperty   *CursorProperty;
00596   vtkProperty   *MarginProperty;
00597   vtkProperty   *TexturePlaneProperty;
00598   void           CreateDefaultProperties();
00599 
00600   // Reslice and texture management
00601   void UpdatePlane();
00602   void GenerateTexturePlane();
00603 
00604   // The cross-hair cursor
00605   vtkPolyData       *CursorPolyData;
00606   vtkActor          *CursorActor;
00607   double             CurrentCursorPosition[3];
00608   double             CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
00609   void               GenerateCursor();
00610   void               UpdateCursor(int,int);
00611   void               ActivateCursor(int);
00612   int                UpdateContinuousCursor(double *q);
00613   int                UpdateDiscreteCursor(double *q);
00614   int                UseContinuousCursor;
00615 
00616   // The text to display W/L, image data
00617   vtkTextActor *TextActor;
00618   char          TextBuff[128];
00619   void          GenerateText();
00620   void          ManageTextDisplay();
00621   void          ActivateText(int);
00622 
00623   // Oblique reslice control
00624   double RotateAxis[3];
00625   double RadiusVector[3];
00626   void  AdjustState();
00627 
00628   // Visible margins to assist user interaction
00629   vtkPolyData       *MarginPolyData;
00630   vtkActor          *MarginActor;
00631   int                MarginSelectMode;
00632   void               GenerateMargins();
00633   void               UpdateMargins();
00634   void               ActivateMargins(int);
00635   double             MarginSizeX;
00636   double             MarginSizeY;
00637 
00638 private:
00639   vtkImagePlaneWidget(const vtkImagePlaneWidget&);  //Not implemented
00640   void operator=(const vtkImagePlaneWidget&);  //Not implemented
00641 };
00642 
00643 #endif