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

Hybrid/vtkLineWidget.h

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