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 
00413   vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 );
00414   vtkGetObjectMacro( Reslice, vtkImageReslice );
00416 
00418 
00424   vtkSetMacro(UseContinuousCursor,int);
00425   vtkGetMacro(UseContinuousCursor,int);
00426   vtkBooleanMacro(UseContinuousCursor,int);
00428 
00430 
00431   void SetInteraction(int interact);
00432   vtkGetMacro(Interaction,int);
00433   vtkBooleanMacro(Interaction,int);
00435 
00436   //BTX
00438 
00439   enum
00440   {
00441     VTK_CURSOR_ACTION       = 0,
00442     VTK_SLICE_MOTION_ACTION = 1,
00443     VTK_WINDOW_LEVEL_ACTION = 2
00444   };
00445   //ETX
00446   vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00447   vtkGetMacro(LeftButtonAction, int);
00448   vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00449   vtkGetMacro(MiddleButtonAction, int);
00450   vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION);
00451   vtkGetMacro(RightButtonAction, int);
00453 
00454   //BTX
00456 
00462   enum
00463   {
00464     VTK_NO_MODIFIER         = 0,
00465     VTK_SHIFT_MODIFIER      = 1,
00466     VTK_CONTROL_MODIFIER    = 2
00467   };
00468   //ETX
00469   vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00470   vtkGetMacro(LeftButtonAutoModifier, int);
00471   vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00472   vtkGetMacro(MiddleButtonAutoModifier, int);
00473   vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER);
00474   vtkGetMacro(RightButtonAutoModifier, int);
00476 
00477 protected:
00478   vtkImagePlaneWidget();
00479   ~vtkImagePlaneWidget();
00480 
00481   int TextureVisibility;
00482   
00483   int LeftButtonAction;
00484   int MiddleButtonAction;
00485   int RightButtonAction;
00486 
00487   int LeftButtonAutoModifier;
00488   int MiddleButtonAutoModifier;
00489   int RightButtonAutoModifier;
00490 
00491   //BTX
00492   enum
00493   {
00494     VTK_NO_BUTTON     = 0,
00495     VTK_LEFT_BUTTON   = 1,
00496     VTK_MIDDLE_BUTTON = 2,
00497     VTK_RIGHT_BUTTON  = 3
00498   };
00499   //ETX
00500   int LastButtonPressed;
00501 
00502   //BTX - manage the state of the widget
00503   int State;
00504   enum WidgetState
00505   {
00506     Start=0,
00507     Cursoring,
00508     WindowLevelling,
00509     Pushing,
00510     Spinning,
00511     Rotating,
00512     Moving,
00513     Scaling,
00514     Outside
00515   };
00516   //ETX
00517 
00518   // Handles the events
00519   static void ProcessEvents(vtkObject* object,
00520                             unsigned long event,
00521                             void* clientdata,
00522                             void* calldata);
00523 
00524   // internal utility method that adds observers to the RenderWindowInteractor
00525   // so that our ProcessEvents is eventually called.  this method is called
00526   // by SetEnabled as well as SetInteraction
00527   void AddObservers();
00528 
00529   // ProcessEvents() dispatches to these methods.
00530   virtual void OnMouseMove();
00531   virtual void OnLeftButtonDown();
00532   virtual void OnLeftButtonUp();
00533   virtual void OnMiddleButtonDown();
00534   virtual void OnMiddleButtonUp();
00535   virtual void OnRightButtonDown();
00536   virtual void OnRightButtonUp();
00537   virtual void OnChar();
00538 
00539   virtual void StartCursor();
00540   virtual void StopCursor();
00541   virtual void StartSliceMotion();
00542   virtual void StopSliceMotion();
00543   virtual void StartWindowLevel();
00544   virtual void StopWindowLevel();
00545 
00546   // controlling ivars
00547   int    Interaction; // Is the widget responsive to mouse events
00548   int    PlaneOrientation;
00549   int    RestrictPlaneToVolume;
00550   double OriginalWindow;
00551   double OriginalLevel;
00552   double CurrentWindow;
00553   double CurrentLevel;
00554   double InitialWindow;
00555   double InitialLevel;
00556   int    StartWindowLevelPositionX;
00557   int    StartWindowLevelPositionY;
00558   int    ResliceInterpolate;
00559   int    TextureInterpolate;
00560   int    UserControlledLookupTable;
00561   int    DisplayText;
00562 
00563   // The geometric represenation of the plane and it's outline
00564   vtkPlaneSource    *PlaneSource;
00565   vtkPolyData       *PlaneOutlinePolyData;
00566   vtkActor          *PlaneOutlineActor;
00567   void               HighlightPlane(int highlight);
00568   void               GeneratePlaneOutline();
00569 
00570   // Re-builds the plane outline based on the plane source
00571   void BuildRepresentation();
00572 
00573   // Do the picking
00574   vtkAbstractPropPicker *PlanePicker;
00575 
00576   // for negative window values.
00577   void InvertTable();
00578 
00579   // Methods to manipulate the plane
00580   void WindowLevel(int X, int Y);
00581   void Push(double *p1, double *p2);
00582   void Spin(double *p1, double *p2);
00583   void Rotate(double *p1, double *p2, double *vpn);
00584   void Scale(double *p1, double *p2, int X, int Y);
00585   void Translate(double *p1, double *p2);
00586 
00587   vtkImageData         *ImageData;
00588   vtkImageReslice      *Reslice;
00589   vtkMatrix4x4         *ResliceAxes;
00590   vtkTransform         *Transform;
00591   vtkActor             *TexturePlaneActor;
00592   vtkImageMapToColors  *ColorMap;
00593   vtkTexture           *Texture;
00594   vtkLookupTable       *LookupTable;
00595   vtkLookupTable       *CreateDefaultLookupTable();
00596 
00597   // Properties used to control the appearance of selected objects and
00598   // the manipulator in general.  The plane property is actually that for
00599   // the outline.  The TexturePlaneProperty can be used to control the
00600   // lighting etc. of the resliced image data.
00601   vtkProperty   *PlaneProperty;
00602   vtkProperty   *SelectedPlaneProperty;
00603   vtkProperty   *CursorProperty;
00604   vtkProperty   *MarginProperty;
00605   vtkProperty   *TexturePlaneProperty;
00606   void           CreateDefaultProperties();
00607 
00608   // Reslice and texture management
00609   void UpdatePlane();
00610   void GenerateTexturePlane();
00611 
00612   // The cross-hair cursor
00613   vtkPolyData       *CursorPolyData;
00614   vtkActor          *CursorActor;
00615   double             CurrentCursorPosition[3];
00616   double             CurrentImageValue; // Set to VTK_DOUBLE_MAX when invalid
00617   void               GenerateCursor();
00618   void               UpdateCursor(int,int);
00619   void               ActivateCursor(int);
00620   int                UpdateContinuousCursor(double *q);
00621   int                UpdateDiscreteCursor(double *q);
00622   int                UseContinuousCursor;
00623 
00624   // The text to display W/L, image data
00625   vtkTextActor *TextActor;
00626   char          TextBuff[128];
00627   void          GenerateText();
00628   void          ManageTextDisplay();
00629   void          ActivateText(int);
00630 
00631   // Oblique reslice control
00632   double RotateAxis[3];
00633   double RadiusVector[3];
00634   void  AdjustState();
00635 
00636   // Visible margins to assist user interaction
00637   vtkPolyData       *MarginPolyData;
00638   vtkActor          *MarginActor;
00639   int                MarginSelectMode;
00640   void               GenerateMargins();
00641   void               UpdateMargins();
00642   void               ActivateMargins(int);
00643   double             MarginSizeX;
00644   double             MarginSizeY;
00645 
00646 private:
00647   vtkImagePlaneWidget(const vtkImagePlaneWidget&);  //Not implemented
00648   void operator=(const vtkImagePlaneWidget&);  //Not implemented
00649 };
00650 
00651 #endif