VTK
dox/Widgets/vtkLineRepresentation.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkLineRepresentation.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 =========================================================================*/
00040 #ifndef __vtkLineRepresentation_h
00041 #define __vtkLineRepresentation_h
00042 
00043 #include "vtkWidgetRepresentation.h"
00044 
00045 class vtkActor;
00046 class vtkPolyDataMapper;
00047 class vtkLineSource;
00048 class vtkSphereSource;
00049 class vtkProperty;
00050 class vtkPolyData;
00051 class vtkPolyDataAlgorithm;
00052 class vtkPointHandleRepresentation3D;
00053 class vtkBox;
00054 class vtkFollower;
00055 class vtkVectorText;
00056 class vtkPolyDataMapper;
00057 class vtkCellPicker;
00058 
00059 class VTK_WIDGETS_EXPORT vtkLineRepresentation : public vtkWidgetRepresentation
00060 {
00061 public:
00063   static vtkLineRepresentation *New();
00064 
00066 
00067   vtkTypeMacro(vtkLineRepresentation,vtkWidgetRepresentation);
00068   void PrintSelf(ostream& os, vtkIndent indent);
00070 
00072 
00075   void GetPoint1WorldPosition(double pos[3]);
00076   double* GetPoint1WorldPosition();
00077   void GetPoint1DisplayPosition(double pos[3]);
00078   double* GetPoint1DisplayPosition();
00079   void SetPoint1WorldPosition(double pos[3]);
00080   void SetPoint1DisplayPosition(double pos[3]);
00081   void GetPoint2DisplayPosition(double pos[3]);
00082   double* GetPoint2DisplayPosition();
00083   void GetPoint2WorldPosition(double pos[3]);
00084   double* GetPoint2WorldPosition();
00085   void SetPoint2WorldPosition(double pos[3]);
00086   void SetPoint2DisplayPosition(double pos[3]);
00088 
00090 
00098   void SetHandleRepresentation(vtkPointHandleRepresentation3D *handle);
00099   void InstantiateHandleRepresentation();
00101 
00103 
00104   vtkGetObjectMacro(Point1Representation,vtkPointHandleRepresentation3D);
00105   vtkGetObjectMacro(Point2Representation,vtkPointHandleRepresentation3D);
00106   vtkGetObjectMacro(LineHandleRepresentation,vtkPointHandleRepresentation3D);
00108 
00110 
00112   vtkGetObjectMacro(EndPointProperty,vtkProperty);
00113   vtkGetObjectMacro(SelectedEndPointProperty,vtkProperty);
00115 
00117 
00119   vtkGetObjectMacro(EndPoint2Property,vtkProperty);
00120   vtkGetObjectMacro(SelectedEndPoint2Property,vtkProperty);
00122   
00124 
00126   vtkGetObjectMacro(LineProperty,vtkProperty);
00127   vtkGetObjectMacro(SelectedLineProperty,vtkProperty);
00129 
00131 
00134   vtkSetClampMacro(Tolerance,int,1,100);
00135   vtkGetMacro(Tolerance,int);
00137 
00139 
00142   void SetResolution(int res);
00143   int GetResolution();
00145 
00152   void GetPolyData(vtkPolyData *pd);
00153 
00155 
00156   virtual void PlaceWidget(double bounds[6]);
00157   virtual void BuildRepresentation();
00158   virtual int ComputeInteractionState(int X, int Y, int modify=0);
00159   virtual void StartWidgetInteraction(double e[2]);
00160   virtual void WidgetInteraction(double e[2]);
00161   virtual double *GetBounds();
00163   
00165 
00166   virtual void GetActors(vtkPropCollection *pc);
00167   virtual void ReleaseGraphicsResources(vtkWindow*);
00168   virtual int RenderOpaqueGeometry(vtkViewport*);
00169   virtual int RenderTranslucentPolygonalGeometry(vtkViewport*);
00170   virtual int HasTranslucentPolygonalGeometry();
00172   
00173 //BTX - manage the state of the widget
00174   enum {Outside=0,OnP1,OnP2,TranslatingP1,TranslatingP2,OnLine,Scaling};
00175 //ETX
00176 
00178 
00185   vtkSetClampMacro(InteractionState,int,Outside,Scaling);
00187 
00189 
00191   virtual void SetRepresentationState(int);
00192   vtkGetMacro(RepresentationState, int);
00194 
00197   virtual unsigned long GetMTime();
00198 
00200   virtual void SetRenderer(vtkRenderer *ren);
00201 
00203 
00204   vtkSetMacro( DistanceAnnotationVisibility, int );
00205   vtkGetMacro( DistanceAnnotationVisibility, int );
00206   vtkBooleanMacro( DistanceAnnotationVisibility, int );
00208 
00210 
00213   vtkSetStringMacro(DistanceAnnotationFormat);
00214   vtkGetStringMacro(DistanceAnnotationFormat);
00216   
00218 
00219   void SetDistanceAnnotationScale(double x, double y, double z)
00220   {
00221     double scale[3];
00222     scale[0] = x;
00223     scale[1] = y;
00224     scale[2] = z;
00225     this->SetDistanceAnnotationScale(scale);
00226   }
00227   virtual void SetDistanceAnnotationScale( double scale[3] );
00228   virtual double * GetDistanceAnnotationScale();
00230 
00232   double GetDistance();
00233   
00234 
00237   void SetLineColor(double r, double g, double b);
00238 
00240   virtual vtkProperty *GetDistanceAnnotationProperty();
00241 
00243 
00244   vtkGetObjectMacro(TextActor, vtkFollower);
00246 
00247 protected:
00248   vtkLineRepresentation();
00249   ~vtkLineRepresentation();
00250 
00251   // The handle and the rep used to close the handles
00252   vtkPointHandleRepresentation3D *HandleRepresentation;
00253   vtkPointHandleRepresentation3D *Point1Representation;
00254   vtkPointHandleRepresentation3D *Point2Representation;
00255   vtkPointHandleRepresentation3D *LineHandleRepresentation;
00256 
00257   // Manage how the representation appears
00258   int RepresentationState;
00259 
00260   // the line
00261   vtkActor          *LineActor;
00262   vtkPolyDataMapper *LineMapper;
00263   vtkLineSource     *LineSource;
00264 
00265   // glyphs representing hot spots (e.g., handles)
00266   vtkActor          **Handle;
00267   vtkPolyDataMapper **HandleMapper;
00268   vtkSphereSource   **HandleGeometry;
00269 
00270   // Properties used to control the appearance of selected objects and
00271   // the manipulator in general.
00272   vtkProperty *EndPointProperty;
00273   vtkProperty *SelectedEndPointProperty;
00274   vtkProperty *EndPoint2Property;
00275   vtkProperty *SelectedEndPoint2Property;
00276   vtkProperty *LineProperty;
00277   vtkProperty *SelectedLineProperty;
00278   void         CreateDefaultProperties();
00279 
00280   // Selection tolerance for the handles and the line
00281   int Tolerance;
00282 
00283   // Helper members
00284   int  ClampToBounds;
00285   void ClampPosition(double x[3]);
00286   void HighlightPoint(int ptId, int highlight);
00287   void HighlightLine(int highlight);
00288   int  InBounds(double x[3]);
00289   void SizeHandles();
00290 
00291   // Ivars used during widget interaction to hold initial positions
00292   double StartP1[3];
00293   double StartP2[3];
00294   double StartLineHandle[3];
00295   double Length;
00296   double LastEventPosition[3];
00297 
00298   // Support GetBounds() method
00299   vtkBox *BoundingBox;
00300   
00301   // Need to keep track if we have successfully initialized the display position. 
00302   // The widget tends to do stuff in world coordinates, put if the renderer has
00303   // not been assigned, then certain operations do not properly update the display
00304   // position.
00305   int InitializedDisplayPosition;
00306 
00307   // Format for the label
00308   int DistanceAnnotationVisibility;
00309   char *DistanceAnnotationFormat;
00310 
00311   vtkFollower       *TextActor;
00312   vtkPolyDataMapper *TextMapper;
00313   vtkVectorText     *TextInput;  
00314   double             Distance;
00315   bool               AnnotationTextScaleInitialized;
00316 
00317   vtkCellPicker     *LinePicker;
00318 
00319 private:
00320   vtkLineRepresentation(const vtkLineRepresentation&);  //Not implemented
00321   void operator=(const vtkLineRepresentation&);  //Not implemented
00322 };
00323 
00324 #endif