VTK
dox/Interaction/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 "vtkInteractionWidgetsModule.h" // For export macro
00044 #include "vtkWidgetRepresentation.h"
00045 
00046 class vtkActor;
00047 class vtkPolyDataMapper;
00048 class vtkLineSource;
00049 class vtkSphereSource;
00050 class vtkProperty;
00051 class vtkPolyData;
00052 class vtkPolyDataAlgorithm;
00053 class vtkPointHandleRepresentation3D;
00054 class vtkBox;
00055 class vtkFollower;
00056 class vtkVectorText;
00057 class vtkPolyDataMapper;
00058 class vtkCellPicker;
00059 
00060 class VTKINTERACTIONWIDGETS_EXPORT vtkLineRepresentation : public vtkWidgetRepresentation
00061 {
00062 public:
00064   static vtkLineRepresentation *New();
00065 
00067 
00068   vtkTypeMacro(vtkLineRepresentation,vtkWidgetRepresentation);
00069   void PrintSelf(ostream& os, vtkIndent indent);
00071 
00073 
00076   void GetPoint1WorldPosition(double pos[3]);
00077   double* GetPoint1WorldPosition();
00078   void GetPoint1DisplayPosition(double pos[3]);
00079   double* GetPoint1DisplayPosition();
00080   void SetPoint1WorldPosition(double pos[3]);
00081   void SetPoint1DisplayPosition(double pos[3]);
00082   void GetPoint2DisplayPosition(double pos[3]);
00083   double* GetPoint2DisplayPosition();
00084   void GetPoint2WorldPosition(double pos[3]);
00085   double* GetPoint2WorldPosition();
00086   void SetPoint2WorldPosition(double pos[3]);
00087   void SetPoint2DisplayPosition(double pos[3]);
00089 
00091 
00099   void SetHandleRepresentation(vtkPointHandleRepresentation3D *handle);
00100   void InstantiateHandleRepresentation();
00102 
00104 
00105   vtkGetObjectMacro(Point1Representation,vtkPointHandleRepresentation3D);
00106   vtkGetObjectMacro(Point2Representation,vtkPointHandleRepresentation3D);
00107   vtkGetObjectMacro(LineHandleRepresentation,vtkPointHandleRepresentation3D);
00109 
00111 
00113   vtkGetObjectMacro(EndPointProperty,vtkProperty);
00114   vtkGetObjectMacro(SelectedEndPointProperty,vtkProperty);
00116 
00118 
00120   vtkGetObjectMacro(EndPoint2Property,vtkProperty);
00121   vtkGetObjectMacro(SelectedEndPoint2Property,vtkProperty);
00123 
00125 
00127   vtkGetObjectMacro(LineProperty,vtkProperty);
00128   vtkGetObjectMacro(SelectedLineProperty,vtkProperty);
00130 
00132 
00135   vtkSetClampMacro(Tolerance,int,1,100);
00136   vtkGetMacro(Tolerance,int);
00138 
00140 
00143   void SetResolution(int res);
00144   int GetResolution();
00146 
00153   void GetPolyData(vtkPolyData *pd);
00154 
00156 
00157   virtual void PlaceWidget(double bounds[6]);
00158   virtual void BuildRepresentation();
00159   virtual int ComputeInteractionState(int X, int Y, int modify=0);
00160   virtual void StartWidgetInteraction(double e[2]);
00161   virtual void WidgetInteraction(double e[2]);
00162   virtual double *GetBounds();
00164 
00166 
00167   virtual void GetActors(vtkPropCollection *pc);
00168   virtual void ReleaseGraphicsResources(vtkWindow*);
00169   virtual int RenderOpaqueGeometry(vtkViewport*);
00170   virtual int RenderTranslucentPolygonalGeometry(vtkViewport*);
00171   virtual int HasTranslucentPolygonalGeometry();
00173 
00174 //BTX - manage the state of the widget
00175   enum {Outside=0,OnP1,OnP2,TranslatingP1,TranslatingP2,OnLine,Scaling};
00176 //ETX
00177 
00179 
00186   vtkSetClampMacro(InteractionState,int,Outside,Scaling);
00188 
00190 
00192   virtual void SetRepresentationState(int);
00193   vtkGetMacro(RepresentationState, int);
00195 
00198   virtual unsigned long GetMTime();
00199 
00201   virtual void SetRenderer(vtkRenderer *ren);
00202 
00204 
00205   vtkSetMacro( DistanceAnnotationVisibility, int );
00206   vtkGetMacro( DistanceAnnotationVisibility, int );
00207   vtkBooleanMacro( DistanceAnnotationVisibility, int );
00209 
00211 
00214   vtkSetStringMacro(DistanceAnnotationFormat);
00215   vtkGetStringMacro(DistanceAnnotationFormat);
00217 
00219 
00220   void SetDistanceAnnotationScale(double x, double y, double z)
00221   {
00222     double scale[3];
00223     scale[0] = x;
00224     scale[1] = y;
00225     scale[2] = z;
00226     this->SetDistanceAnnotationScale(scale);
00227   }
00228   virtual void SetDistanceAnnotationScale( double scale[3] );
00229   virtual double * GetDistanceAnnotationScale();
00231 
00233   double GetDistance();
00234 
00235 
00238   void SetLineColor(double r, double g, double b);
00239 
00241   virtual vtkProperty *GetDistanceAnnotationProperty();
00242 
00244 
00245   vtkGetObjectMacro(TextActor, vtkFollower);
00247 
00248 protected:
00249   vtkLineRepresentation();
00250   ~vtkLineRepresentation();
00251 
00252   // The handle and the rep used to close the handles
00253   vtkPointHandleRepresentation3D *HandleRepresentation;
00254   vtkPointHandleRepresentation3D *Point1Representation;
00255   vtkPointHandleRepresentation3D *Point2Representation;
00256   vtkPointHandleRepresentation3D *LineHandleRepresentation;
00257 
00258   // Manage how the representation appears
00259   int RepresentationState;
00260 
00261   // the line
00262   vtkActor          *LineActor;
00263   vtkPolyDataMapper *LineMapper;
00264   vtkLineSource     *LineSource;
00265 
00266   // glyphs representing hot spots (e.g., handles)
00267   vtkActor          **Handle;
00268   vtkPolyDataMapper **HandleMapper;
00269   vtkSphereSource   **HandleGeometry;
00270 
00271   // Properties used to control the appearance of selected objects and
00272   // the manipulator in general.
00273   vtkProperty *EndPointProperty;
00274   vtkProperty *SelectedEndPointProperty;
00275   vtkProperty *EndPoint2Property;
00276   vtkProperty *SelectedEndPoint2Property;
00277   vtkProperty *LineProperty;
00278   vtkProperty *SelectedLineProperty;
00279   void         CreateDefaultProperties();
00280 
00281   // Selection tolerance for the handles and the line
00282   int Tolerance;
00283 
00284   // Helper members
00285   int  ClampToBounds;
00286   void ClampPosition(double x[3]);
00287   void HighlightPoint(int ptId, int highlight);
00288   void HighlightLine(int highlight);
00289   int  InBounds(double x[3]);
00290   void SizeHandles();
00291 
00292   // Ivars used during widget interaction to hold initial positions
00293   double StartP1[3];
00294   double StartP2[3];
00295   double StartLineHandle[3];
00296   double Length;
00297   double LastEventPosition[3];
00298 
00299   // Support GetBounds() method
00300   vtkBox *BoundingBox;
00301 
00302   // Need to keep track if we have successfully initialized the display position.
00303   // The widget tends to do stuff in world coordinates, put if the renderer has
00304   // not been assigned, then certain operations do not properly update the display
00305   // position.
00306   int InitializedDisplayPosition;
00307 
00308   // Format for the label
00309   int DistanceAnnotationVisibility;
00310   char *DistanceAnnotationFormat;
00311 
00312   vtkFollower       *TextActor;
00313   vtkPolyDataMapper *TextMapper;
00314   vtkVectorText     *TextInput;
00315   double             Distance;
00316   bool               AnnotationTextScaleInitialized;
00317 
00318   vtkCellPicker     *LinePicker;
00319 
00320 private:
00321   vtkLineRepresentation(const vtkLineRepresentation&);  //Not implemented
00322   void operator=(const vtkLineRepresentation&);  //Not implemented
00323 };
00324 
00325 #endif