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

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