Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/aclvis/Tool.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef ACLVIS_TOOL_H
00012 #define ACLVIS_TOOL_H
00013 
00014 #ifdef IPPL_USE_STANDARD_HEADERS
00015 #include <iostream>
00016 using namespace std;
00017 #else
00018 #include <iostream.h>
00019 #endif
00020 
00021 #include <vtk.h>
00022 #include <vtkXRenderWindow.h>
00023 
00024 #define NUM_OF_TOOL_TYPES 10
00025 enum ToolType {ReadField, ReadParticle, Slice, Iso, MIso, Point, Sphere, Render, \
00026 VectorField, VectorParticle, Axes, LineTrace, Empty};
00027 
00028 #define XY 2
00029 #define YZ 0
00030 #define XZ 1
00031 
00033 class vizStructuredFieldDataType;
00034 class vizParticleDataType;
00035 
00037 #define NUM_OF_UPDATE_POLICY_TYPES 4
00038 enum UpdatePolicyType {Zero, Once, Al, UpdateEmpty};
00039 
00040 class Tool {
00041 public:
00042            Tool();
00043   virtual ~Tool();
00044 
00045   void SetUpdatePolicy(UpdatePolicyType);
00046   UpdatePolicyType GetUpdatePolicy();
00047   int UpdateTestAndSet();
00048 
00049   void SetLocalDimensions(int *);
00050   void SetLocalOrigin(float *);
00051   void SetLocalAspectRatio(float *);
00052   void SetRange(float *);
00053   void SetAllValues(int *, float *, float *, float *);
00054 
00055   void GetLocalDimensions(int *);
00056   void GetLocalOrigin(float *);
00057   void GetLocalAspectRatio(float *);
00058   void GetRange(float *);
00059   void GetAllValues(int *, float *, float *, float *);
00060 
00061 
00062 private:
00063   UpdatePolicyType updatePolicy;
00064   int              updateCount;
00065 
00066   int              dims[3];
00067   float            origin[3];
00068   float            aspect[3];
00069   float            range[2];
00070 };
00071 
00072 
00074 class ReadParticleTool : public vtkPolySource, public Tool {
00075 public:
00076            ReadParticleTool();
00077   virtual ~ReadParticleTool();
00078 
00079   vizParticleDataType *GetVizData();
00080   int PrepareFinishedData(); // Place data into the polyData structure
00081                              // of the read tool
00082   void UpdateRange();
00083 
00084 private:
00085   vizParticleDataType *vizData;
00086   void                 Execute();
00087 };
00088 
00089 
00091 class ReadFieldTool : public vtkStructuredPointsSource, public Tool {
00092 public:
00093            ReadFieldTool();
00094   virtual ~ReadFieldTool();
00095 
00096   void UpdateAllValues();
00097   void UpdateDimensions();
00098   void UpdateOrigin();
00099   void UpdateAspect();
00100   void UpdateRange();
00101 
00102   void SetDimensions(int    dims[3]); 
00103   void SetAspectRatio(float aspr[3]);
00104   void SetOrigin(float      orig[3]);
00105 
00106   vizStructuredFieldDataType *GetVizData();
00107   int PrepareFinishedData(); // Place data into the data structure
00108                              // of the read tool
00109 private:
00110   vizStructuredFieldDataType *vizData;   
00111   void         Execute();
00112 };
00113 
00114 
00116 class RenderTool : public Tool {
00117 public:
00118   RenderTool();
00119   void              SetRenderer(vtkRenderer *);
00120   void              SetRenderWindow(vtkXRenderWindow *);
00121 
00122   vtkRenderer*      GetRenderer();
00123   vtkRenderWindow*  GetRenderWindow();
00124 
00125   void              ResetCamera();
00126   void              AddActors(vtkActor *);
00127   void              RemoveActors(vtkActor *);
00128   void              Render();
00129 
00130 private:
00131   int number_of_actors;
00132 
00133   //new stuff
00134   vtkRenderWindowInteractor *iren;
00135   vtkRenderMaster           *render_master;
00136   vtkRenderWindow           *render_window;
00137 
00138   vtkRenderer               *renderer;
00139 };
00140 
00141 
00143 class FilterTool : public Tool {
00144 public:
00145   FilterTool();
00146   ~FilterTool();
00147   void FilterToolInit(void *, RenderTool *);
00148 
00149   void           SetReadTool(void *);
00150   void           SetRenderTool(RenderTool *);
00151 
00152   void*          GetReadTool();
00153   RenderTool*    GetRenderTool();
00154   vtkActor*      GetActor(); 
00155   vtkPolyMapper* GetPolyMapper();
00156 
00157 private:
00158   void          *readtool;
00159   RenderTool    *rendertool;
00160   ToolType       readtool_type;
00161   vtkActor      *actor;
00162   vtkPolyMapper *polyMapper;
00163 };
00164 
00165 
00167 class SliceTool : public FilterTool {
00168 public:
00169   SliceTool(void *, RenderTool *);
00170   ~SliceTool();
00171 
00172   void   SetSliceType(int param_sliceType);
00173   void   SetSliceValue(float param_sliceValue);
00174   void   SetExtent();
00175 
00176   int    GetSliceType();
00177   float  GetSliceValue();
00178   float  GetLowerBound();
00179   float  GetUpperBound();
00180   float  GetValueRange();
00181 
00182   vtkStructuredPointsGeometryFilter* GetStructuredPointsGeometryFilter();
00183 
00184 
00185 private:
00186   vtkStructuredPointsGeometryFilter *p1;
00187 
00188   int sliceType;
00189   int sliceValue;
00190 };
00191 
00192 
00194 class IsoSurfaceTool : public FilterTool {
00195 public:
00196   IsoSurfaceTool(void *, RenderTool *);
00197   ~IsoSurfaceTool();
00198 
00199   void  SetNumContours(int param_numContours);
00200   void  SetContourSubRange(float *param_srange);
00201 
00202   int   GetNumContours();
00203   void  GetContourSubRange(float *param_srange);
00204 
00205   vtkContourFilter*  GetContourFilter();
00206 
00207 private:
00208   vtkContourFilter *isoF;
00209   int numContours;
00210   float srange[2];
00211 };
00212 
00213 
00215 class PointTool : public FilterTool {
00216 public:
00217   PointTool(void *, RenderTool *);
00218   ~PointTool();
00219 };
00220 
00221 
00223 class vizTraceTool : public FilterTool {
00224 public:
00225   vizTraceTool();
00226   vizTraceTool(void *, RenderTool *);
00227   virtual ~vizTraceTool();
00228 
00229   int                SetTraceNumber(int num); // see traceNumber
00230   int                SetTraceIter(int iter);  //  see traceIter
00231 
00232   int                GetTraceNumber()   const;
00233   int                GetTraceIter()     const;
00234   vtkCollection*     GetTraceCollection();   // see traceCollection
00235   vtkAppendPolyData* Getapd();               // see apd
00236                      
00237                      // This function will add the new vtkPolyData to a
00238                      // vtkAppendPolyData object to allow for a particle trace
00239                      // if the traceNumber of the vizTraceTool is greater than 1
00240                      // To use the trace fuctionality, place this function in
00241                      // the MainWindow::UpdateTools method for your subclass 
00242   int                AppendPolyData(vtkPolyData *newPolyData);
00243 
00244                      // Used by AppendPolyData to control the mumber of
00245                      // vtkPolyData saved in the trace
00246   int                CullStalePolyData(int fromSetFlag=0);
00247 
00248                      // Used by AppendPolyData to control traceIter 
00249   int                IterateTraceIter(int amt = 1);               
00250 
00251 protected:
00252   vtkAppendPolyData *apd;         //The data saved for the particle trace
00253   vtkCollection     *traceCollection; // Saves pointers to vtkDataSets in apd
00254   int                traceNumber; // # of time steps of data to keep
00255   int                traceIter;   // current # of saved updates on data 
00256 };
00257 
00258 
00260 class SphereTool : public vizTraceTool {
00261 public:
00262   SphereTool(void *, RenderTool *);
00263   virtual ~SphereTool();
00264 
00265   vtkSphereSource*   GetSphereSource();
00266 
00267 private:
00268   vtkGlyph3D        *glyph;
00269   vtkSphereSource   *sphere;
00270 };
00271 
00272 
00274 class vizVectorTool : public vizTraceTool {
00275 public:
00276   vizVectorTool();
00277   virtual ~vizVectorTool();
00278 
00279   void        SetScaleFactor(float scaleFact);  // Added scaling of vector length
00280   void        SetScaleByValue(int togle);       // Scale by Vector (1) or Scalar (0)
00281   void        FlipTubeArrowFlag();              // If flag = 1, make tube arrows,
00282                                                 // if flag = 0, make line arrows
00283   void        SetArrowTubeRadius(float rad);
00284   void        SetNumberOfTubeFacets(int numFacets);
00285 
00286   float       GetScaleFactor()         const;
00287   int         GetScaleByValue()        const; 
00288   int         GetTubeArrowFlag()       const;
00289   float       GetArrowTubeRadius()     const;
00290   int         GetNumberOfTubeFacets()  const;
00291   
00292 
00293   void  MakeUnitArrowPolyData(vtkPolyData *&arrowPolyData); 
00294                                             // Make a unit tube to
00295                                             // to represent the vectors.
00296                                             // it is scaled to the 
00297                                             // vector length
00298   
00299 protected:
00300   vtkPolyData  *vectorRepPolyData;
00301   vtkGlyph3D   *vectGlyph;
00302   float         scaleFactor;
00303   int           scaleByValue; // if 0 scale by scalar, 
00304                               //if 1 scale by vector (not implemented)
00305   
00306   int           tubeArrow; // flag that determine wheather the arrow is made of lines or tubes
00307   float         arrowTubeRadius;
00308   int           numTubeFacets;
00309 };
00310 
00311 
00313 class vizVectorFieldTool : public vizVectorTool {
00314 public:
00315   vizVectorFieldTool();
00316   vizVectorFieldTool(void *, RenderTool *);
00317   virtual ~vizVectorFieldTool();
00318 };
00319 
00320 
00322 class vizVectorParticleTool : public vizVectorTool {
00323 public:
00324   vizVectorParticleTool();
00325   vizVectorParticleTool(void *, RenderTool *);
00326   virtual ~vizVectorParticleTool();
00327 };
00328 
00329 
00331 class vizAxesTool : public FilterTool {
00332 public:
00333             vizAxesTool();
00334             vizAxesTool(void *param_readtool, RenderTool *param_rendertool);
00335   virtual  ~vizAxesTool();
00336 
00337   int       SetScaleFactor(float scaleFact);
00338   
00339   float     GetScaleFactor() const;
00340   int       GetMaxSideLenOfGlobalBoundingBox(RenderTool *ren, float& maxSide);
00341   int       GetGlobalBoundingBox(RenderTool *ren, float allBounds[6]);
00342 
00343 private:
00344   vtkAxes  *axes;
00345   float     scaleFactor;
00346 };
00347 
00348 
00350 class vizParticleLineTraceTool : public vizTraceTool {
00351 public:
00352   vizParticleLineTraceTool();
00353   vizParticleLineTraceTool(void *param_readtool, RenderTool *param_rendertool);
00354   ~vizParticleLineTraceTool();
00355 
00356   void     MakeAndAppendNewLines(vtkPolyData *newPD);
00357   void     TubeIt(vtkPolyData* polyLines);
00358   void     FlipTubeLinesFlag();
00359 private:
00360   vtkPolyData    *currentPolyData;
00361   vtkPolyData    *newPolyData;
00362   vtkTubeFilter  *tubeFilter;
00363   int             tubeLines;
00364 };
00365 
00366 
00368 class vizPointData : public vtkUserDefined 
00369 {
00370 public:
00371            vizPointData();
00372   virtual ~vizPointData();
00373 
00374   vtkIntScalars *GetIds();
00375 
00376 private:
00377   vtkIntScalars *ids;
00378 };
00379 
00381 
00382 class vizStructuredFieldDataType {
00383 public:
00384   // possible different data structures for the vtk storage
00385   enum {ACLVIS_UNKNOWN, ACLVIS_SCALAR, ACLVIS_VECTOR, ACLVIS_TENSOR};
00386 
00387   vizStructuredFieldDataType();
00388   vizStructuredFieldDataType(unsigned numPts, int ptDataType = ACLVIS_UNKNOWN);
00389   virtual ~vizStructuredFieldDataType();
00390 
00391   int InitData(unsigned numPts, int ptDataType = ACLVIS_UNKNOWN);
00392                                   // Initialize with the number of 
00393                                   // points to be stored and the 
00394                                   // type of data stored at each point
00395                                   // using the above enum values.
00396    
00397   int InitPointDataType(int pdType); // To set the value of "type"
00398                                      // to one of the enum vals
00399   
00400   int AddScalar(float sc);                  // adds a scalar to "scalars"
00401   int AddScalar(int index, float sc);       // adds a scalar to "scalars"
00402   int AddVector(float vect[3]);             // adds a vector to "vectors"
00403   int AddVector(int index, float vect[3]);  // adds a vector to "vectors"
00404 
00405   int InsertFieldData(vtkDataSet *dataSet);
00406                               // Add place data into the polyData structure
00407                              // of the read tool
00408 
00409   int SetPointData(vtkDataSet *dataSet); //add the data structure to 
00410                                          //the given vtk data set
00411 
00412   int GetPointDataType() const; // To set the value of "type"
00413 
00414   void* GetPointData(); // return pointer to point data
00415 
00416 protected:
00417   // data associated with each point "pointData"
00418   int type;
00419   union {
00420     vtkFloatScalars *scalars;
00421     vtkFloatVectors *vectors;
00422     vtkFloatTensors *tensors;
00423   };
00424 
00425   int             isPointData; // 0 no 1 yes
00426   int numPoints; // number of points in structure (particle or field)
00427                  // should be the same as the number of 
00428                  // pointData values 
00429 };
00430 
00431 
00433 class vizParticleDataType : public vizStructuredFieldDataType
00434 {
00435 public:
00436   vizParticleDataType();
00437   vizParticleDataType(unsigned numPts, int ptDataType = ACLVIS_UNKNOWN, 
00438                       int isIds = 1);
00439   virtual ~vizParticleDataType();
00440 
00441   int InitData(unsigned numPts, int ptDataType = ACLVIS_UNKNOWN, 
00442                int isIds = 1);
00443                                   // Initialize with the number of 
00444                                   // points to be stored and the 
00445                                   // type of data stored at each point
00446                                   // using the above enum values.
00447                                   // If particle id information will
00448                                   // be provide, set isIdInfo 1 to
00449                                   // initialize memory for storing the info.
00450    
00451   int InitIdInfo();  // initialize the IdInfo data.
00452   
00453   int AddPoint(float pt[3]);              // adds a point  to "points"
00454   int AddPoint(int index, float pt[3]);   // adds a point  to "points"
00455   int AddIdInfoVal(int idInf);            // adds a idinf  to "idInfo"
00456   int AddIdInfoVal(int index, int idInf); // adds a idinf  to "idInfo"
00457 
00458 
00459   int InsertParticleData(vtkPolyData *polyData);
00460 
00461 
00462   int SetPoints(vtkPolyData *polyData); // add the vtkPoints data structure 
00463                                         // to the given vtkPolyData
00464 
00465   int SetIdInfo(vtkDataSet *dataSet);
00466 
00467   int GetIsIdInfoFlag() const;
00468 private:
00469   vtkFloatPoints *points;
00470   vtkCellArray   *cellArray;
00471 
00472   vizPointData   *idInfo; // To hold index into vtkFloatPoint array
00473                          // where the corresponding particle point
00474                          // (position) was stored during prev time
00475                          // step
00476   int             isIdInfo;  // 0 no 1 yes
00477 };
00478 
00479 #endif // ACLVIS_TOOL_H
00480 
00481 /***************************************************************************
00482  * $RCSfile: Tool.h,v $   $Author: adelmann $
00483  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:34 $
00484  * IPPL_VERSION_ID: $Id: Tool.h,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 
00485  ***************************************************************************/

Generated on Fri Nov 2 01:25:54 2007 for IPPL by doxygen 1.3.5