VTK
dox/Widgets/vtkParallelopipedRepresentation.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkParallelopipedRepresentation.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 =========================================================================*/
00033 #ifndef __vtkParallelopipedRepresentation_h
00034 #define __vtkParallelopipedRepresentation_h
00035 
00036 #include "vtkWidgetRepresentation.h"
00037 
00038 class vtkActor;
00039 class vtkPlane;
00040 class vtkPoints;
00041 class vtkPolyData;
00042 class vtkPolyDataMapper;
00043 class vtkProperty;
00044 class vtkCellArray;
00045 class vtkTransform;
00046 class vtkHandleRepresentation;
00047 class vtkClosedSurfacePointPlacer;
00048 class vtkPlaneCollection;
00049 class vtkParallelopipedTopology;
00050 
00051 class VTK_WIDGETS_EXPORT vtkParallelopipedRepresentation 
00052                               : public vtkWidgetRepresentation
00053 {
00054 public:
00056   static vtkParallelopipedRepresentation *New();
00057 
00059 
00060   vtkTypeMacro(vtkParallelopipedRepresentation,vtkWidgetRepresentation);
00061   void PrintSelf(ostream& os, vtkIndent indent);
00063 
00065   virtual void GetActors(vtkPropCollection *pc);
00066 
00068 
00076   virtual void PlaceWidget(double corners[8][3]);
00077   virtual void PlaceWidget(double bounds[6]);
00079   
00081 
00084   vtkSetMacro(InteractionState,int);
00086 
00092   void GetBoundingPlanes( vtkPlaneCollection *pc );
00093 
00095   void GetPolyData(vtkPolyData *pd);
00096 
00098   virtual double *GetBounds();
00099 
00101 
00102   virtual void SetHandleProperty           (vtkProperty *);
00103   virtual void SetHoveredHandleProperty    (vtkProperty *);
00104   virtual void SetSelectedHandleProperty   (vtkProperty *);
00105   vtkGetObjectMacro(HandleProperty,         vtkProperty  );
00106   vtkGetObjectMacro(HoveredHandleProperty,  vtkProperty  );
00107   vtkGetObjectMacro(SelectedHandleProperty, vtkProperty  );
00109   
00110   void SetHandleRepresentation(vtkHandleRepresentation *handle);
00111   vtkHandleRepresentation* GetHandleRepresentation(int index);
00112 
00114 
00116   void HandlesOn();
00117   void HandlesOff();
00119   
00121 
00123   vtkGetObjectMacro(FaceProperty,vtkProperty);
00124   vtkGetObjectMacro(SelectedFaceProperty,vtkProperty);
00126   
00128 
00130   vtkGetObjectMacro(OutlineProperty,vtkProperty);
00131   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
00133   
00136   virtual void BuildRepresentation();
00137  
00139 
00140   virtual void ReleaseGraphicsResources(vtkWindow *w);
00141   virtual int  RenderOverlay(vtkViewport *viewport);
00142   virtual int  RenderOpaqueGeometry(vtkViewport *viewport);
00144 
00147   virtual int ComputeInteractionState(int X, int Y, int modify=0);
00148 
00149   //BTX - manage the state of the widget
00150   enum _InteractionState
00151   {
00152     Outside = 0,
00153     Inside,
00154     RequestResizeParallelopiped,
00155     RequestResizeParallelopipedAlongAnAxis,
00156     RequestChairMode,
00157     RequestTranslateParallelopiped,
00158     RequestScaleParallelopiped,
00159     RequestRotateParallelopiped,
00160     ResizingParallelopiped,
00161     ResizingParallelopipedAlongAnAxis,
00162     ChairMode,
00163     TranslatingParallelopiped,
00164     ScalingParallelopiped,
00165     RotatingParallelopiped
00166   };
00167   //ETX
00168 
00169   // Methods to manipulate the piped.
00170   virtual void Translate( double translation[3] );
00171   virtual void Translate( int X, int Y );
00172   virtual void Scale( int X, int Y );
00173   
00176   virtual void PositionHandles();
00177   
00179 
00183   vtkSetMacro( MinimumThickness, double );
00184   vtkGetMacro( MinimumThickness, double );
00186   
00187 protected:
00188   vtkParallelopipedRepresentation();
00189   ~vtkParallelopipedRepresentation();
00190 
00192   void TranslatePoint( int n, const double motionVector[3] );
00193   
00196   void SetHandleHighlight( int handleIdx, vtkProperty *property );
00197 
00199 
00201   void SetFaceHighlight( vtkCellArray * face, vtkProperty * );
00202   void HighlightAllFaces();
00203   void UnHighlightAllFaces();
00205   
00206   // Node can be a value within [0,7]. This will create a chair one one of
00207   // the handle corners. '0 < InitialChairDepth < 1' value dicates the starting
00208   // depth of the cavity.
00209   void UpdateChairAtNode( int node );
00210   
00211   // Removes any existing chairs.
00212   void RemoveExistingChairs();
00213 
00214   // Convenience method to get just the planes that define the parallelopiped.
00215   // If we aren't in chair mode, this will be the same as GetBoundingPlanes().
00216   // If we are in chair mode, this will be the first 6 planes from amongst 
00217   // those returned by "GetBoundingPlanes". 
00218   // All planes have their normals pointing inwards. 
00219   void GetParallelopipedBoundingPlanes( vtkPlaneCollection * pc );
00220 
00221   // Convenience method to edefine a plane passing through 3 points.
00222   void DefinePlane( vtkPlane *, double p[3][3]);
00223 
00224   // Convenience method to edefine a plane passing through 3 pointIds of the 
00225   // parallelopiped. The point Ids must like in the range [0,15], ie the
00226   // 15 points comprising the parallelopiped and the chair (also modelled
00227   // as a parallelopiped)
00228   void DefinePlane( vtkPlane *, vtkIdType, vtkIdType, vtkIdType);
00229 
00230   vtkActor                          * HexActor;
00231   vtkPolyDataMapper                 * HexMapper;
00232   vtkPolyData                       * HexPolyData;
00233   vtkPoints                         * Points;
00234   vtkActor                          * HexFaceActor;
00235   vtkPolyDataMapper                 * HexFaceMapper;
00236   vtkPolyData                       * HexFacePolyData;
00237   
00238   double                              LastEventPosition[2];
00239   
00240   // Cache the axis index used for face aligned resize.
00241   int                                 LastResizeAxisIdx;
00242 
00243   vtkHandleRepresentation           * HandleRepresentation;
00244   vtkHandleRepresentation          ** HandleRepresentations;
00245   int                                 CurrentHandleIdx;
00246   int                                 ChairHandleIdx;
00247   
00248   
00249   // When a chair is carved out for the first time, this is the initial 
00250   // depth of the chair
00251   double                              InitialChairDepth;
00252   
00253   vtkProperty                       * HandleProperty;
00254   vtkProperty                       * HoveredHandleProperty;
00255   vtkProperty                       * FaceProperty;
00256   vtkProperty                       * OutlineProperty;
00257   vtkProperty                       * SelectedHandleProperty;
00258   vtkProperty                       * SelectedFaceProperty;
00259   vtkProperty                       * SelectedOutlineProperty;
00260   vtkClosedSurfacePointPlacer       * ChairPointPlacer;
00261   vtkParallelopipedTopology         * Topology;
00262   double                              MinimumThickness;
00263   double                              AbsoluteMinimumThickness;
00264 
00265 private:
00266   vtkParallelopipedRepresentation(const vtkParallelopipedRepresentation&);  //Not implemented
00267   void operator=(const vtkParallelopipedRepresentation&);  //Not implemented
00268 };
00269 
00270 #endif