VTK
|
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 =========================================================================*/ 00108 #ifndef vtkImagePlaneWidget_h 00109 #define vtkImagePlaneWidget_h 00110 00111 #include "vtkInteractionWidgetsModule.h" // For export macro 00112 #include "vtkPolyDataSourceWidget.h" 00113 00114 class vtkActor; 00115 class vtkAbstractPropPicker; 00116 class vtkDataSetMapper; 00117 class vtkImageData; 00118 class vtkImageMapToColors; 00119 class vtkImageReslice; 00120 class vtkLookupTable; 00121 class vtkMatrix4x4; 00122 class vtkPlaneSource; 00123 class vtkPoints; 00124 class vtkPolyData; 00125 class vtkProperty; 00126 class vtkTextActor; 00127 class vtkTextProperty; 00128 class vtkTexture; 00129 class vtkTransform; 00130 00131 #define VTK_NEAREST_RESLICE 0 00132 #define VTK_LINEAR_RESLICE 1 00133 #define VTK_CUBIC_RESLICE 2 00134 00135 class VTKINTERACTIONWIDGETS_EXPORT vtkImagePlaneWidget : public vtkPolyDataSourceWidget 00136 { 00137 public: 00139 static vtkImagePlaneWidget *New(); 00140 00141 vtkTypeMacro(vtkImagePlaneWidget,vtkPolyDataSourceWidget); 00142 void PrintSelf(ostream& os, vtkIndent indent); 00143 00145 00146 virtual void SetEnabled(int); 00147 virtual void PlaceWidget(double bounds[6]); 00148 void PlaceWidget() 00149 {this->Superclass::PlaceWidget();} 00150 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00151 double zmin, double zmax) 00152 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00154 00156 void SetInputConnection(vtkAlgorithmOutput* aout); 00157 00159 00160 void SetOrigin(double x, double y, double z); 00161 void SetOrigin(double xyz[3]); 00162 double* GetOrigin(); 00163 void GetOrigin(double xyz[3]); 00165 00167 00169 void SetPoint1(double x, double y, double z); 00170 void SetPoint1(double xyz[3]); 00171 double* GetPoint1(); 00172 void GetPoint1(double xyz[3]); 00174 00176 00178 void SetPoint2(double x, double y, double z); 00179 void SetPoint2(double xyz[3]); 00180 double* GetPoint2(); 00181 void GetPoint2(double xyz[3]); 00183 00185 00186 double* GetCenter(); 00187 void GetCenter(double xyz[3]); 00189 00191 00192 double* GetNormal(); 00193 void GetNormal(double xyz[3]); 00195 00197 void GetVector1(double v1[3]); 00198 00200 void GetVector2(double v2[3]); 00201 00203 int GetSliceIndex(); 00204 00206 void SetSliceIndex(int index); 00207 00209 double GetSlicePosition(); 00210 00212 void SetSlicePosition(double position); 00213 00215 00216 void SetResliceInterpolate(int); 00217 vtkGetMacro(ResliceInterpolate,int); 00218 void SetResliceInterpolateToNearestNeighbour() 00219 { this->SetResliceInterpolate(VTK_NEAREST_RESLICE); } 00220 void SetResliceInterpolateToLinear() 00221 { this->SetResliceInterpolate(VTK_LINEAR_RESLICE); } 00222 void SetResliceInterpolateToCubic() 00223 { this->SetResliceInterpolate(VTK_CUBIC_RESLICE); } 00225 00227 vtkImageData* GetResliceOutput(); 00228 00230 00231 vtkSetMacro(RestrictPlaneToVolume,int); 00232 vtkGetMacro(RestrictPlaneToVolume,int); 00233 vtkBooleanMacro(RestrictPlaneToVolume,int); 00235 00237 00239 vtkSetMacro(UserControlledLookupTable,int); 00240 vtkGetMacro(UserControlledLookupTable,int); 00241 vtkBooleanMacro(UserControlledLookupTable,int); 00243 00245 00249 vtkSetMacro(TextureInterpolate,int); 00250 vtkGetMacro(TextureInterpolate,int); 00251 vtkBooleanMacro(TextureInterpolate,int); 00253 00255 00257 virtual void SetTextureVisibility(int); 00258 vtkGetMacro(TextureVisibility,int); 00259 vtkBooleanMacro(TextureVisibility,int); 00261 00268 void GetPolyData(vtkPolyData *pd); 00269 00275 vtkPolyDataAlgorithm* GetPolyDataAlgorithm(); 00276 00280 void UpdatePlacement(void); 00281 00284 vtkTexture *GetTexture(); 00285 00287 00291 vtkGetObjectMacro(ColorMap, vtkImageMapToColors); 00292 virtual void SetColorMap(vtkImageMapToColors *); 00294 00296 00298 virtual void SetPlaneProperty(vtkProperty*); 00299 vtkGetObjectMacro(PlaneProperty,vtkProperty); 00300 virtual void SetSelectedPlaneProperty(vtkProperty*); 00301 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); 00303 00305 00307 void SetPlaneOrientation(int); 00308 vtkGetMacro(PlaneOrientation,int); 00309 void SetPlaneOrientationToXAxes() 00310 { this->SetPlaneOrientation(0); } 00311 void SetPlaneOrientationToYAxes() 00312 { this->SetPlaneOrientation(1); } 00313 void SetPlaneOrientationToZAxes() 00314 { this->SetPlaneOrientation(2); } 00316 00321 void SetPicker(vtkAbstractPropPicker*); 00322 00324 00329 virtual void SetLookupTable(vtkLookupTable*); 00330 vtkGetObjectMacro(LookupTable,vtkLookupTable); 00332 00334 00336 vtkSetMacro(DisplayText,int); 00337 vtkGetMacro(DisplayText,int); 00338 vtkBooleanMacro(DisplayText,int); 00340 00342 00343 virtual void SetCursorProperty(vtkProperty*); 00344 vtkGetObjectMacro(CursorProperty,vtkProperty); 00346 00348 00349 virtual void SetMarginProperty(vtkProperty*); 00350 vtkGetObjectMacro(MarginProperty,vtkProperty); 00352 00354 00356 vtkSetClampMacro(MarginSizeX,double, 0.0, 0.5); 00357 vtkGetMacro(MarginSizeX, double); 00358 vtkSetClampMacro(MarginSizeY,double, 0.0, 0.5); 00359 vtkGetMacro(MarginSizeY, double); 00361 00363 00365 void SetTextProperty(vtkTextProperty* tprop); 00366 vtkTextProperty* GetTextProperty(); 00368 00370 00371 virtual void SetTexturePlaneProperty(vtkProperty*); 00372 vtkGetObjectMacro(TexturePlaneProperty,vtkProperty); 00374 00376 00380 void SetWindowLevel(double window, double level, int copy = 0); 00381 void GetWindowLevel(double wl[2]); 00382 double GetWindow(){return this->CurrentWindow;} 00383 double GetLevel(){return this->CurrentLevel;} 00385 00388 int GetCursorData(double xyzv[4]); 00389 00393 int GetCursorDataStatus(); 00394 00396 00398 vtkGetVectorMacro(CurrentCursorPosition,double,3); 00400 00402 00405 vtkGetMacro(CurrentImageValue,double); 00407 00409 00410 vtkGetObjectMacro( ResliceAxes, vtkMatrix4x4 ); 00411 vtkGetObjectMacro( Reslice, vtkImageReslice ); 00413 00415 00421 vtkSetMacro(UseContinuousCursor,int); 00422 vtkGetMacro(UseContinuousCursor,int); 00423 vtkBooleanMacro(UseContinuousCursor,int); 00425 00427 00428 void SetInteraction(int interact); 00429 vtkGetMacro(Interaction,int); 00430 vtkBooleanMacro(Interaction,int); 00432 00433 //BTX 00435 00436 enum 00437 { 00438 VTK_CURSOR_ACTION = 0, 00439 VTK_SLICE_MOTION_ACTION = 1, 00440 VTK_WINDOW_LEVEL_ACTION = 2 00441 }; 00442 //ETX 00443 vtkSetClampMacro(LeftButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION); 00444 vtkGetMacro(LeftButtonAction, int); 00445 vtkSetClampMacro(MiddleButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION); 00446 vtkGetMacro(MiddleButtonAction, int); 00447 vtkSetClampMacro(RightButtonAction,int, VTK_CURSOR_ACTION, VTK_WINDOW_LEVEL_ACTION); 00448 vtkGetMacro(RightButtonAction, int); 00450 00451 //BTX 00453 00459 enum 00460 { 00461 VTK_NO_MODIFIER = 0, 00462 VTK_SHIFT_MODIFIER = 1, 00463 VTK_CONTROL_MODIFIER = 2 00464 }; 00465 //ETX 00466 vtkSetClampMacro(LeftButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER); 00467 vtkGetMacro(LeftButtonAutoModifier, int); 00468 vtkSetClampMacro(MiddleButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER); 00469 vtkGetMacro(MiddleButtonAutoModifier, int); 00470 vtkSetClampMacro(RightButtonAutoModifier,int, VTK_NO_MODIFIER, VTK_CONTROL_MODIFIER); 00471 vtkGetMacro(RightButtonAutoModifier, int); 00473 00474 protected: 00475 vtkImagePlaneWidget(); 00476 ~vtkImagePlaneWidget(); 00477 00478 int TextureVisibility; 00479 00480 int LeftButtonAction; 00481 int MiddleButtonAction; 00482 int RightButtonAction; 00483 00484 int LeftButtonAutoModifier; 00485 int MiddleButtonAutoModifier; 00486 int RightButtonAutoModifier; 00487 00488 //BTX 00489 enum 00490 { 00491 VTK_NO_BUTTON = 0, 00492 VTK_LEFT_BUTTON = 1, 00493 VTK_MIDDLE_BUTTON = 2, 00494 VTK_RIGHT_BUTTON = 3 00495 }; 00496 //ETX 00497 int LastButtonPressed; 00498 00499 //BTX - manage the state of the widget 00500 int State; 00501 enum WidgetState 00502 { 00503 Start=0, 00504 Cursoring, 00505 WindowLevelling, 00506 Pushing, 00507 Spinning, 00508 Rotating, 00509 Moving, 00510 Scaling, 00511 Outside 00512 }; 00513 //ETX 00514 00515 // Handles the events 00516 static void ProcessEvents(vtkObject* object, 00517 unsigned long event, 00518 void* clientdata, 00519 void* calldata); 00520 00521 // internal utility method that adds observers to the RenderWindowInteractor 00522 // so that our ProcessEvents is eventually called. this method is called 00523 // by SetEnabled as well as SetInteraction 00524 void AddObservers(); 00525 00526 // ProcessEvents() dispatches to these methods. 00527 virtual void OnMouseMove(); 00528 virtual void OnLeftButtonDown(); 00529 virtual void OnLeftButtonUp(); 00530 virtual void OnMiddleButtonDown(); 00531 virtual void OnMiddleButtonUp(); 00532 virtual void OnRightButtonDown(); 00533 virtual void OnRightButtonUp(); 00534 virtual void OnChar(); 00535 00536 virtual void StartCursor(); 00537 virtual void StopCursor(); 00538 virtual void StartSliceMotion(); 00539 virtual void StopSliceMotion(); 00540 virtual void StartWindowLevel(); 00541 virtual void StopWindowLevel(); 00542 00543 // controlling ivars 00544 int Interaction; // Is the widget responsive to mouse events 00545 int PlaneOrientation; 00546 int RestrictPlaneToVolume; 00547 double OriginalWindow; 00548 double OriginalLevel; 00549 double CurrentWindow; 00550 double CurrentLevel; 00551 double InitialWindow; 00552 double InitialLevel; 00553 int StartWindowLevelPositionX; 00554 int StartWindowLevelPositionY; 00555 int ResliceInterpolate; 00556 int TextureInterpolate; 00557 int UserControlledLookupTable; 00558 int DisplayText; 00559 00560 // The geometric represenation of the plane and it's outline 00561 vtkPlaneSource *PlaneSource; 00562 vtkPolyData *PlaneOutlinePolyData; 00563 vtkActor *PlaneOutlineActor; 00564 void HighlightPlane(int highlight); 00565 void GeneratePlaneOutline(); 00566 00567 // Re-builds the plane outline based on the plane source 00568 void BuildRepresentation(); 00569 00570 // Do the picking 00571 vtkAbstractPropPicker *PlanePicker; 00572 00573 // Register internal Pickers within PickingManager 00574 virtual void RegisterPickers(); 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