Version: 6.3.1

src/PIPELINE/VISU_PlanesWidget.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00024 //  File   : VISU_PlanesWidget.h
00025 //  Author : Peter KURNEV
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/VISU/VISU_SRC/src/PIPELINE/VISU_PlanesWidget.hxx,v 1.6.2.1.6.1.8.1 2011-06-02 06:00:18 vsr Exp $
00028 //
00029 #ifndef __VISU_PlanesWidget_h
00030 #define __VISU_PlanesWidget_h
00031 
00032 #include "VISUPipeline.hxx"
00033 #include "VISU_ImplicitFunctionWidget.hxx"
00034 class vtkActor;
00035 class vtkPolyDataMapper;
00036 class vtkCellPicker;
00037 class vtkConeSource;
00038 class vtkLineSource;
00039 class vtkSphereSource;
00040 class vtkPlane;
00041 class vtkCutter;
00042 class vtkProperty;
00043 class vtkImageData;
00044 class vtkOutlineFilter;
00045 class vtkFeatureEdges;
00046 class vtkPolyData;
00047 class vtkTransform;
00048 class vtkImplicitBoolean;
00049 class vtkImplicitFunction;
00050 class VISU_UnScaledActor;
00051 class vtkDataSet;
00052 
00053 class VISU_PIPELINE_EXPORT VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
00054 {
00055 public:
00056   // Description:
00057   // Instantiate the object.
00058   static VISU_PlanesWidget *New();
00059 
00060   vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
00061   void PrintSelf(ostream& os, vtkIndent indent);
00062 
00063   void 
00064   SetDistance(const vtkFloatingPointType theDistance);
00065 
00066   vtkFloatingPointType
00067   Distance() const;
00068 
00069   vtkGetMacro(InitialLength,vtkFloatingPointType);
00070 
00071   virtual 
00072   vtkImplicitFunction* 
00073   ImplicitFunction();
00074 
00075   // Description:
00076   // Methods that satisfy the superclass' API.
00077   virtual
00078   void
00079   SetEnabled(int);
00080 
00081   virtual
00082   void
00083   PlaceWidget(vtkFloatingPointType bounds[6]);
00084 
00085   // Description:
00086   // Get the origin of the plane.
00087   void
00088   SetOrigin(vtkFloatingPointType x, 
00089             vtkFloatingPointType y, 
00090             vtkFloatingPointType z);
00091 
00092   void
00093   SetOrigin(vtkFloatingPointType x[3]);
00094 
00095   vtkFloatingPointType* 
00096   GetOrigin();
00097 
00098   void
00099   GetOrigin(vtkFloatingPointType xyz[3]);
00100 
00101   // Description:
00102   // Get the normal to the plane.
00103   void 
00104   SetNormal(vtkFloatingPointType x, 
00105             vtkFloatingPointType y, 
00106             vtkFloatingPointType z);
00107 
00108   void 
00109   SetNormal(vtkFloatingPointType x[3]);
00110 
00111   vtkFloatingPointType* 
00112   GetNormal();
00113 
00114   void
00115   GetNormal(vtkFloatingPointType xyz[3]);
00116   
00117   // Description:
00118   // Force the plane widget to be aligned with one of the x-y-z axes.
00119   // If one axis is set on, the other two will be set off.
00120   // Remember that when the state changes, a ModifiedEvent is invoked.
00121   // This can be used to snap the plane to the axes if it is orginally
00122   // not aligned.
00123   void
00124   SetNormalToXAxis(int);
00125 
00126   vtkGetMacro(NormalToXAxis,int);
00127   vtkBooleanMacro(NormalToXAxis,int);
00128 
00129   void
00130   SetNormalToYAxis(int);
00131 
00132   vtkGetMacro(NormalToYAxis,int);
00133   vtkBooleanMacro(NormalToYAxis,int);
00134 
00135   void
00136   SetNormalToZAxis(int);
00137   vtkGetMacro(NormalToZAxis,int);
00138   vtkBooleanMacro(NormalToZAxis,int);
00139 
00140   // Description:
00141   // Turn on/off tubing of the wire outline of the plane. The tube thickens
00142   // the line by wrapping with a vtkTubeFilter.
00143   //vtkSetMacro(Tubing,int);
00144   //vtkGetMacro(Tubing,int);
00145   //vtkBooleanMacro(Tubing,int);
00146 
00147   // Description:
00148   // Enable/disable the drawing of the plane. In some cases the plane
00149   // interferes with the object that it is operating on (i.e., the
00150   // plane interferes with the cut surface it produces producing
00151   // z-buffer artifacts.)
00152   void
00153   SetDrawPlane(int plane);
00154 
00155   int
00156   GetDrawPlane()
00157   {
00158     return myDrawPlane;
00159   }
00160 
00161   // Description:
00162   // Turn on/off the ability to translate the bounding box by grabbing it
00163   // with the left mouse button.
00164   vtkSetMacro(OutlineTranslation,int);
00165   vtkGetMacro(OutlineTranslation,int);
00166   vtkBooleanMacro(OutlineTranslation,int);
00167 
00168   // Description:
00169   // Grab the polydata that defines the plane. The polydata contains a single
00170   // polygon that is clipped by the bounding box.
00171   void
00172   GetPolyData(vtkPolyData *pd);
00173 
00174   // Description:
00175   // Satisfies superclass API.  This returns a pointer to the underlying
00176   // PolyData (which represents the plane).
00177   //vtkPolyDataSource* GetPolyDataSource();
00178    
00179   // Description:
00180   // Get the implicit function for the plane. The user must provide the
00181   // instance of the class vtkPlane. Note that vtkPlane is a subclass of
00182   // vtkImplicitFunction, meaning that it can be used by a variety of filters
00183   // to perform clipping, cutting, and selection of data.
00184   void
00185   GetPlane(vtkPlane *plane);
00186 
00187   // Description:
00188   // Satisfies the superclass API.  This will change the state of the widget
00189   // to match changes that have been made to the underlying PolyDataSource
00190   void
00191   UpdatePlacement(void);
00192 
00193   // Description:
00194   // Get the properties on the normal (line and cone).
00195   vtkGetObjectMacro(NormalProperty,vtkProperty);
00196   vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
00197   
00198   // Description:
00199   // Get the plane properties. The properties of the plane when selected 
00200   // and unselected can be manipulated.
00201   vtkGetObjectMacro(PlaneProperty,vtkProperty);
00202   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
00203 
00204   // Description:
00205   // Get the property of the outline.
00206   vtkGetObjectMacro(OutlineProperty,vtkProperty);
00207   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
00208 
00209   // Description:
00210   // Get the property of the intersection edges. (This property also
00211   // applies to the edges when tubed.)
00212   vtkGetObjectMacro(EdgesProperty,vtkProperty);
00213 
00214   void
00215   InitialPlaceWidget(vtkFloatingPointType bds[6]);
00216 
00217 protected:
00218   VISU_PlanesWidget();
00219   ~VISU_PlanesWidget();
00220 
00221 //BTX - manage the state of the widget
00222   int State;
00223   enum WidgetState
00224   {
00225     Start=0,
00226     MovingPlane,
00227     MovingOutline,
00228     MovingOrigin,
00229     Scaling,
00230     Pushing,
00231     Rotating,
00232     Outside,
00233     ChangeDistance
00234   };
00235 //ETX
00236     
00237   //handles the events
00238   static
00239   void
00240   ProcessEvents(vtkObject* object, unsigned long event,
00241                 void* clientdata, void* calldata);
00242 
00243   // ProcessEvents() dispatches to these methods.
00244   void OnLeftButtonDown();
00245   void OnLeftButtonUp();
00246   void OnMiddleButtonDown();
00247   void OnMiddleButtonUp();
00248   void OnRightButtonDown();
00249   void OnRightButtonUp();
00250   void OnMouseMove();
00251   //
00252   // Methods to manipulate the plane
00253   void ConstrainOrigin(vtkFloatingPointType x[3]);
00254   void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
00255   void TranslatePlane(double *p1, double *p2);
00256   void TranslateOutline(double *p1, double *p2);
00257   void TranslateOrigin(double *p1, double *p2);
00258   void Push(double *p1, double *p2);
00259   void Scale(double *p1, double *p2, int X, int Y);
00260   void PushDistance(double *p1, double *p2);
00261 
00262   void CreateDefaultProperties();
00263   
00264   void GeneratePlane();
00265   //virtual void SizeHandles();
00266   void HighlightPlane(int highlight);
00267   void HighlightNormal(int highlight);
00268   void HighlightOutline(int highlight);
00269   void UpdateRepresentation();
00270   void SetOriginInternal(vtkFloatingPointType x[3]);
00271 
00272   // Controlling ivars
00273   int NormalToXAxis;
00274   int NormalToYAxis;
00275   int NormalToZAxis;
00276   
00277 
00278   // Flags to handle mouse events
00279   bool HandleMoveEvent;
00280   bool HandleLeftButtonEvent;
00281   bool HandleMiddleButtonEvent;
00282   bool HandleRightButtonEvent;
00283   // The actual plane which is being manipulated
00284   vtkPlane *myPlane1;
00285   vtkPlane *myPlane2;
00286   
00287   vtkFloatingPointType myDistance; 
00288   vtkImplicitBoolean *myImplicitFunction;
00289 
00290   // The bounding box is represented by a single voxel image data
00291   vtkImageData      *myBox;
00292   vtkOutlineFilter  *myOutline;
00293   vtkPolyDataMapper *myOutlineMapper;
00294   vtkActor          *myOutlineActor;
00295   
00296   int OutlineTranslation; //whether the outline can be moved
00297   
00298   // The cut plane is produced with a vtkCutter
00299   vtkCutter         *myCutter1;
00300   vtkPolyDataMapper *myCutMapper1;
00301   vtkActor          *myCutActor1;
00302 
00303   vtkCutter         *myCutter2;
00304   vtkPolyDataMapper *myCutMapper2;
00305   vtkActor          *myCutActor2;
00306   
00307   vtkFeatureEdges   *myEdges2;
00308   vtkPolyDataMapper *myEdgesMapper2;
00309   vtkActor          *myEdgesActor2;
00310 
00311   int               myDrawPlane;
00312 
00313   vtkFeatureEdges   *myEdges1;
00314   vtkPolyDataMapper *myEdgesMapper1;
00315   vtkActor          *myEdgesActor1;
00316 
00317   // The + normal cone
00318   vtkConeSource      *ConeSource;
00319   vtkPolyDataMapper  *ConeMapper;
00320   VISU_UnScaledActor *ConeActor;
00321   // The + normal line
00322   vtkLineSource     *LineSource;
00323   vtkPolyDataMapper *LineMapper;
00324   vtkActor          *LineActor;
00325   // The - normal cone
00326   vtkConeSource      *ConeSource2;
00327   vtkPolyDataMapper  *ConeMapper2;
00328   VISU_UnScaledActor *ConeActor2;
00329   // The - normal line
00330   vtkLineSource     *LineSource2;
00331   vtkPolyDataMapper *LineMapper2;
00332   vtkActor          *LineActor2;
00333   // The origin positioning handle
00334   vtkSphereSource    *Sphere;
00335   vtkPolyDataMapper  *SphereMapper;
00336   VISU_UnScaledActor *SphereActor;
00337 
00338   // Do the picking
00339   vtkCellPicker *Picker;
00340   
00341   // Transform the normal (used for rotation)
00342   vtkTransform *Transform;
00343   // Properties used to control the appearance of selected objects and
00344   // the manipulator in general.
00345   vtkProperty *NormalProperty;
00346   vtkProperty *SelectedNormalProperty;
00347   vtkProperty *PlaneProperty;
00348   vtkProperty *SelectedPlaneProperty;
00349   vtkProperty *OutlineProperty;
00350   vtkProperty *SelectedOutlineProperty;
00351   vtkProperty *EdgesProperty;
00352   
00353 private:
00354   VISU_PlanesWidget(const VISU_PlanesWidget&);  //Not implemented
00355   void operator=(const VISU_ImplicitFunctionWidget&);  //Not implemented
00356 };
00357 
00358 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS