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   virtual void SetDistanceAnnotationScale( double scale[3] );
00220   virtual double * GetDistanceAnnotationScale();
00222 
00224   double GetDistance();
00225   
00226 
00229   void SetLineColor(double r, double g, double b);
00230 
00232   virtual vtkProperty *GetDistanceAnnotationProperty();
00233 
00235 
00236   vtkGetObjectMacro(TextActor, vtkFollower);
00238 
00239 protected:
00240   vtkLineRepresentation();
00241   ~vtkLineRepresentation();
00242 
00243   // The handle and the rep used to close the handles
00244   vtkPointHandleRepresentation3D *HandleRepresentation;
00245   vtkPointHandleRepresentation3D *Point1Representation;
00246   vtkPointHandleRepresentation3D *Point2Representation;
00247   vtkPointHandleRepresentation3D *LineHandleRepresentation;
00248 
00249   // Manage how the representation appears
00250   int RepresentationState;
00251 
00252   // the line
00253   vtkActor          *LineActor;
00254   vtkPolyDataMapper *LineMapper;
00255   vtkLineSource     *LineSource;
00256 
00257   // glyphs representing hot spots (e.g., handles)
00258   vtkActor          **Handle;
00259   vtkPolyDataMapper **HandleMapper;
00260   vtkSphereSource   **HandleGeometry;
00261 
00262   // Properties used to control the appearance of selected objects and
00263   // the manipulator in general.
00264   vtkProperty *EndPointProperty;
00265   vtkProperty *SelectedEndPointProperty;
00266   vtkProperty *EndPoint2Property;
00267   vtkProperty *SelectedEndPoint2Property;
00268   vtkProperty *LineProperty;
00269   vtkProperty *SelectedLineProperty;
00270   void         CreateDefaultProperties();
00271 
00272   // Selection tolerance for the handles and the line
00273   int Tolerance;
00274 
00275   // Helper members
00276   int  ClampToBounds;
00277   void ClampPosition(double x[3]);
00278   void HighlightPoint(int ptId, int highlight);
00279   void HighlightLine(int highlight);
00280   int  InBounds(double x[3]);
00281   void SizeHandles();
00282 
00283   // Ivars used during widget interaction to hold initial positions
00284   double StartP1[3];
00285   double StartP2[3];
00286   double StartLineHandle[3];
00287   double Length;
00288   double LastEventPosition[3];
00289 
00290   // Support GetBounds() method
00291   vtkBox *BoundingBox;
00292   
00293   // Need to keep track if we have successfully initialized the display position. 
00294   // The widget tends to do stuff in world coordinates, put if the renderer has
00295   // not been assigned, then certain operations do not properly update the display
00296   // position.
00297   int InitializedDisplayPosition;
00298 
00299   // Format for the label
00300   int DistanceAnnotationVisibility;
00301   char *DistanceAnnotationFormat;
00302 
00303   vtkFollower       *TextActor;
00304   vtkPolyDataMapper *TextMapper;
00305   vtkVectorText     *TextInput;  
00306   double             Distance;
00307   bool               AnnotationTextScaleInitialized;
00308 
00309   vtkCellPicker     *LinePicker;
00310 
00311 private:
00312   vtkLineRepresentation(const vtkLineRepresentation&);  //Not implemented
00313   void operator=(const vtkLineRepresentation&);  //Not implemented
00314 };
00315 
00316 #endif