VTK
dox/Interaction/Widgets/vtkLineWidget.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkLineWidget.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 =========================================================================*/
00075 #ifndef __vtkLineWidget_h
00076 #define __vtkLineWidget_h
00077 
00078 #include "vtkInteractionWidgetsModule.h" // For export macro
00079 #include "vtk3DWidget.h"
00080 #include "vtkLineSource.h" // For passing calls to it
00081 
00082 class vtkActor;
00083 class vtkPolyDataMapper;
00084 class vtkPoints;
00085 class vtkPolyData;
00086 class vtkProp;
00087 class vtkProperty;
00088 class vtkSphereSource;
00089 class vtkCellPicker;
00090 class vtkPointWidget;
00091 class vtkPWCallback;
00092 class vtkPW1Callback;
00093 class vtkPW2Callback;
00094 
00095 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
00096 {
00097 public:
00099   static vtkLineWidget *New();
00100 
00101   vtkTypeMacro(vtkLineWidget,vtk3DWidget);
00102   void PrintSelf(ostream& os, vtkIndent indent);
00103 
00105 
00106   virtual void SetEnabled(int);
00107   virtual void PlaceWidget(double bounds[6]);
00108   void PlaceWidget()
00109     {this->Superclass::PlaceWidget();}
00110   void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
00111                    double zmin, double zmax)
00112     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00114 
00116 
00117   void SetResolution(int r)
00118     { this->LineSource->SetResolution(r); }
00119   int GetResolution()
00120     { return this->LineSource->GetResolution(); }
00122 
00124 
00125   void SetPoint1(double x, double y, double z);
00126   void SetPoint1(double x[3])
00127     {this->SetPoint1(x[0], x[1], x[2]); }
00128   double* GetPoint1()
00129     {return this->LineSource->GetPoint1();}
00130   void GetPoint1(double xyz[3])
00131     {this->LineSource->GetPoint1(xyz);}
00133 
00135 
00136   void SetPoint2(double x, double y, double z);
00137   void SetPoint2(double x[3])
00138     {this->SetPoint2(x[0], x[1], x[2]);}
00139   double* GetPoint2()
00140     {return this->LineSource->GetPoint2();}
00141   void GetPoint2(double xyz[3])
00142     {this->LineSource->GetPoint2(xyz);}
00144 
00146 
00150   vtkSetClampMacro(Align, int, XAxis, None);
00151   vtkGetMacro(Align, int);
00152   void SetAlignToXAxis() { this->SetAlign(XAxis); }
00153   void SetAlignToYAxis() { this->SetAlign(YAxis); }
00154   void SetAlignToZAxis() { this->SetAlign(ZAxis); }
00155   void SetAlignToNone()  { this->SetAlign(None); }
00157 
00159 
00163   vtkSetMacro(ClampToBounds,int);
00164   vtkGetMacro(ClampToBounds,int);
00165   vtkBooleanMacro(ClampToBounds,int);
00167 
00173   void GetPolyData(vtkPolyData *pd);
00174 
00176 
00179   vtkGetObjectMacro(HandleProperty,vtkProperty);
00180   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00182 
00184 
00186   vtkGetObjectMacro(LineProperty,vtkProperty);
00187   vtkGetObjectMacro(SelectedLineProperty,vtkProperty);
00189 
00190 protected:
00191   vtkLineWidget();
00192   ~vtkLineWidget();
00193 
00194 //BTX - manage the state of the widget
00195   friend class vtkPWCallback;
00196 
00197   int State;
00198   enum WidgetState
00199   {
00200     Start=0,
00201     MovingHandle,
00202     MovingLine,
00203     Scaling,
00204     Outside
00205   };
00206 //ETX
00207 
00208   //handles the events
00209   static void ProcessEvents(vtkObject* object,
00210                             unsigned long event,
00211                             void* clientdata,
00212                             void* calldata);
00213 
00214   // ProcessEvents() dispatches to these methods.
00215   void OnLeftButtonDown();
00216   void OnLeftButtonUp();
00217   void OnMiddleButtonDown();
00218   void OnMiddleButtonUp();
00219   void OnRightButtonDown();
00220   void OnRightButtonUp();
00221   virtual void OnMouseMove();
00222 
00223   // controlling ivars
00224   int Align;
00225 
00226 //BTX
00227   enum AlignmentState {
00228     XAxis,
00229     YAxis,
00230     ZAxis,
00231     None
00232   };
00233 //ETX
00234 
00235   // the line
00236   vtkActor          *LineActor;
00237   vtkPolyDataMapper *LineMapper;
00238   vtkLineSource     *LineSource;
00239   void HighlightLine(int highlight);
00240 
00241   // glyphs representing hot spots (e.g., handles)
00242   vtkActor          **Handle;
00243   vtkPolyDataMapper **HandleMapper;
00244   vtkSphereSource   **HandleGeometry;
00245 
00246   void BuildRepresentation();
00247   virtual void SizeHandles();
00248   void HandlesOn(double length);
00249   void HandlesOff();
00250   int HighlightHandle(vtkProp *prop); //returns cell id
00251   void HighlightHandles(int highlight);
00252 
00253   // Do the picking
00254   vtkCellPicker *HandlePicker;
00255   vtkCellPicker *LinePicker;
00256   vtkActor *CurrentHandle;
00257   double LastPosition[3];
00258   void  SetLinePosition(double x[3]);
00259 
00260   // Register internal Pickers within PickingManager
00261   virtual void RegisterPickers();
00262 
00263   // Methods to manipulate the hexahedron.
00264   void Scale(double *p1, double *p2, int X, int Y);
00265 
00266   // Initial bounds
00267   int   ClampToBounds;
00268   void  ClampPosition(double x[3]);
00269   int   InBounds(double x[3]);
00270 
00271   // Properties used to control the appearance of selected objects and
00272   // the manipulator in general.
00273   vtkProperty *HandleProperty;
00274   vtkProperty *SelectedHandleProperty;
00275   vtkProperty *LineProperty;
00276   vtkProperty *SelectedLineProperty;
00277   void CreateDefaultProperties();
00278 
00279   void GenerateLine();
00280 
00281   // Methods for managing the point widgets used to control the endpoints
00282   vtkPointWidget *PointWidget;
00283   vtkPointWidget *PointWidget1;
00284   vtkPointWidget *PointWidget2;
00285   vtkPWCallback  *PWCallback;
00286   vtkPW1Callback *PW1Callback;
00287   vtkPW2Callback *PW2Callback;
00288   vtkPointWidget *CurrentPointWidget;
00289   void EnablePointWidget();
00290   void DisablePointWidget();
00291   int ForwardEvent(unsigned long event);
00292 
00293 private:
00294   vtkLineWidget(const vtkLineWidget&);  //Not implemented
00295   void operator=(const vtkLineWidget&);  //Not implemented
00296 };
00297 
00298 #endif