Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkImagePlaneWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkImagePlaneWidget.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00110 #ifndef __vtkImagePlaneWidget_h
00111 #define __vtkImagePlaneWidget_h
00112 
00113 #include "vtkPolyDataSourceWidget.h"
00114 
00115 class vtkActor;
00116 class vtkCellPicker;
00117 class vtkDataSetMapper;
00118 class vtkImageData;
00119 class vtkImageMapToColors;
00120 class vtkImageReslice;
00121 class vtkLookupTable;
00122 class vtkMatrix4x4;
00123 class vtkPlaneSource;
00124 class vtkPoints;
00125 class vtkPolyData;
00126 class vtkPolyDataMapper;
00127 class vtkProperty;
00128 class vtkTextActor;
00129 class vtkTextProperty;
00130 class vtkTexture;
00131 class vtkTextureMapToPlane;
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_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget
00139 {
00140 public:
00142   static vtkImagePlaneWidget *New();
00143 
00144   vtkTypeRevisionMacro(vtkImagePlaneWidget,vtkPolyDataSourceWidget);
00145   void PrintSelf(ostream& os, vtkIndent indent);
00146 
00148 
00149   virtual void SetEnabled(int);
00150   virtual void PlaceWidget(float bounds[6]);
00151   void PlaceWidget()
00152     {this->Superclass::PlaceWidget();}
00153   void PlaceWidget(float xmin, float xmax, float ymin, float ymax,
00154                    float zmin, float zmax)
00155     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00157 
00159   void SetInput(vtkDataSet* input);
00160 
00162 
00163   void SetOrigin(float x, float y, float z);
00164   void SetOrigin(float xyz[3]);
00165   float* GetOrigin();
00166   void GetOrigin(float xyz[3]);
00168 
00170 
00172   void SetPoint1(float x, float y, float z);
00173   void SetPoint1(float xyz[3]);
00174   float* GetPoint1();
00175   void GetPoint1(float xyz[3]);
00177 
00179 
00181   void SetPoint2(float x, float y, float z);
00182   void SetPoint2(float xyz[3]);
00183   float* GetPoint2();
00184   void GetPoint2(float xyz[3]);
00186 
00188 
00189   float* GetCenter();
00190   void GetCenter(float xyz[3]);
00192 
00194 
00195   float* GetNormal();
00196   void GetNormal(float xyz[3]);
00198 
00200   void GetVector1(float v1[3]);
00201 
00203   void GetVector2(float v2[3]);
00204 
00206   int GetSliceIndex();
00207 
00209   void SetSliceIndex(int index);
00210 
00212   float GetSlicePosition();
00213 
00215   void SetSlicePosition(float 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 
00264   void GetPolyData(vtkPolyData *pd);
00265 
00271   vtkPolyDataSource* GetPolyDataSource();
00272 
00275   void UpdatePlacement(void);
00276 
00279   vtkTexture *GetTexture();
00280 
00285   vtkImageMapToColors* GetImageMapToColors();
00286 
00288 
00290   virtual void SetPlaneProperty(vtkProperty*);
00291   vtkGetObjectMacro(PlaneProperty,vtkProperty);
00292   virtual void SetSelectedPlaneProperty(vtkProperty*);
00293   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
00295 
00297 
00299   void SetPlaneOrientation(int);
00300   vtkGetMacro(PlaneOrientation,int);
00301   void SetPlaneOrientationToXAxes()
00302     { this->SetPlaneOrientation(0); }
00303   void SetPlaneOrientationToYAxes()
00304     { this->SetPlaneOrientation(1); }
00305   void SetPlaneOrientationToZAxes()
00306     { this->SetPlaneOrientation(2); }
00308 
00313   void SetPicker(vtkCellPicker*);
00314 
00316 
00321   virtual void SetLookupTable(vtkLookupTable*);
00322   vtkGetObjectMacro(LookupTable,vtkLookupTable);
00324 
00326 
00328   vtkSetMacro(DisplayText,int);
00329   vtkGetMacro(DisplayText,int);
00330   vtkBooleanMacro(DisplayText,int);
00332 
00334 
00335   virtual void SetCursorProperty(vtkProperty*);
00336   vtkGetObjectMacro(CursorProperty,vtkProperty);
00338 
00340 
00341   virtual void SetMarginProperty(vtkProperty*);
00342   vtkGetObjectMacro(MarginProperty,vtkProperty);
00344 
00346 
00348   void SetTextProperty(vtkTextProperty* tprop);
00349   vtkTextProperty* GetTextProperty();
00351 
00353 
00354   virtual void SetTexturePlaneProperty(vtkProperty*);
00355   vtkGetObjectMacro(TexturePlaneProperty,vtkProperty);
00357 
00359   void GetWindowLevel(float wl[2]);
00360 
00363   int GetCursorData(float xyzv[4]);
00364 
00366 
00367   void SetInteraction(int interact);
00368   vtkGetMacro(Interaction,int);
00369   vtkBooleanMacro(Interaction,int);
00371 
00372 protected:
00373   vtkImagePlaneWidget();
00374   ~vtkImagePlaneWidget();
00375 
00376 //BTX - manage the state of the widget
00377   int State;
00378   enum WidgetState
00379   {
00380     Start=0,
00381     Cursoring,
00382     WindowLevelling,
00383     Pushing,
00384     Spinning,
00385     Rotating,
00386     Moving,
00387     Scaling,
00388     Outside
00389   };
00390 //ETX
00391 
00392   // Handles the events
00393   static void ProcessEvents(vtkObject* object,
00394                             unsigned long event,
00395                             void* clientdata,
00396                             void* calldata);
00397 
00398   // ProcessEvents() dispatches to these methods.
00399   void OnMouseMove();
00400   void OnLeftButtonDown();
00401   void OnLeftButtonUp();
00402   void OnMiddleButtonDown();
00403   void OnMiddleButtonUp();
00404   void OnRightButtonDown();
00405   void OnRightButtonUp();
00406 
00407   // controlling ivars
00408   int   Interaction; // Is the widget responsive to mouse events  
00409   int   PlaneOrientation;
00410   int   RestrictPlaneToVolume;
00411   float OriginalWindow;
00412   float OriginalLevel;
00413   float CurrentWindow;
00414   float CurrentLevel;
00415   int   ResliceInterpolate;
00416   int   TextureInterpolate;
00417   int   UserControlledLookupTable;
00418   int   DisplayText;
00419 
00420   // The geometric represenation of the plane and it's outline
00421   vtkPlaneSource    *PlaneSource;
00422   float              Normal[3]; // plane normal normalized
00423   vtkPolyData       *PlaneOutlinePolyData;
00424   vtkActor          *PlaneOutlineActor;
00425   vtkPolyDataMapper *PlaneOutlineMapper;
00426   void               HighlightPlane(int highlight);
00427   void               GeneratePlaneOutline();
00428 
00429   // Re-builds the plane outline based on the plane source
00430   void BuildRepresentation();
00431 
00432   // Do the picking
00433   vtkCellPicker *PlanePicker;
00434 
00435   // Methods to manipulate the plane
00436   void WindowLevel(int X, int Y);
00437   void Push(double *p1, double *p2);
00438   void Spin(double *p1, double *p2);
00439   void Rotate(double *p1, double *p2, double *vpn);
00440   void Scale(double *p1, double *p2, int X, int Y);
00441   void Translate(double *p1, double *p2);
00442 
00443   vtkImageData         *ImageData;
00444   vtkImageReslice      *Reslice;
00445   vtkMatrix4x4         *ResliceAxes;
00446   vtkTransform         *Transform;
00447   vtkTextureMapToPlane *TexturePlaneCoords;
00448   vtkDataSetMapper     *TexturePlaneMapper;
00449   vtkActor             *TexturePlaneActor;
00450   vtkImageMapToColors  *ColorMap;
00451   vtkTexture           *Texture;
00452   vtkLookupTable       *LookupTable;
00453   vtkLookupTable       *CreateDefaultLookupTable();
00454 
00455   // Properties used to control the appearance of selected objects and
00456   // the manipulator in general.  The plane property is actually that for
00457   // the outline.  The TexturePlaneProperty can be used to control the
00458   // lighting etc. of the resliced image data.
00459   vtkProperty   *PlaneProperty;
00460   vtkProperty   *SelectedPlaneProperty;
00461   vtkProperty   *CursorProperty;
00462   vtkProperty   *MarginProperty;
00463   vtkProperty   *TexturePlaneProperty;
00464   void           CreateDefaultProperties();
00465 
00466   // Reslice and texture management
00467   void UpdateNormal();
00468   void UpdateOrigin();
00469   void GenerateTexturePlane();
00470 
00471   // The cross-hair cursor
00472   vtkPolyData       *CursorPolyData;
00473   vtkPolyDataMapper *CursorMapper;
00474   vtkActor          *CursorActor;
00475   int                CurrentCursorPosition[3];
00476   float              CurrentImageValue; // Set to VTK_FLOAT_MAX when invalid
00477   void               GenerateCursor();
00478   void               UpdateCursor(int,int);
00479   void               ActivateCursor(int);
00480 
00481   // The text to display W/L, image data
00482   vtkTextActor *TextActor;
00483   char          TextBuff[128];
00484   void          GenerateText();
00485   void          ManageTextDisplay();
00486   void          ActivateText(int);
00487 
00488   // Oblique reslice control
00489   float RotateAxis[3];
00490   float RadiusVector[3];
00491   void  AdjustState();
00492 
00493   // Visible margins to assist user interaction
00494   vtkPolyData       *MarginPolyData;
00495   vtkPolyDataMapper *MarginMapper;
00496   vtkActor          *MarginActor;
00497   int                MarginSelectMode;
00498   void               GenerateMargins();
00499   void               UpdateMargins();
00500   void               ActivateMargins(int);
00501 
00502 private:
00503   vtkImagePlaneWidget(const vtkImagePlaneWidget&);  //Not implemented
00504   void operator=(const vtkImagePlaneWidget&);  //Not implemented
00505 };
00506 
00507 #endif