VTK
dox/Graphics/vtkStreamer.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkStreamer.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 =========================================================================*/
00052 #ifndef __vtkStreamer_h
00053 #define __vtkStreamer_h
00054 
00055 #include "vtkPolyDataAlgorithm.h"
00056 
00057 class vtkInitialValueProblemSolver;
00058 class vtkMultiThreader;
00059 
00060 #define VTK_INTEGRATE_FORWARD 0
00061 #define VTK_INTEGRATE_BACKWARD 1
00062 #define VTK_INTEGRATE_BOTH_DIRECTIONS 2
00063 
00064 class VTK_GRAPHICS_EXPORT vtkStreamer : public vtkPolyDataAlgorithm
00065 {
00066 public:
00067   vtkTypeMacro(vtkStreamer,vtkPolyDataAlgorithm);
00068   void PrintSelf(ostream& os, vtkIndent indent);
00069 
00073   void SetStartLocation(vtkIdType cellId, int subId, double pcoords[3]);
00074 
00076 
00079   void SetStartLocation(vtkIdType cellId, int subId, double r, double s,
00080                         double t);
00082 
00085   vtkIdType GetStartLocation(int& subId, double pcoords[3]);
00086 
00090   void SetStartPosition(double x[3]);
00091 
00095   void SetStartPosition(double x, double y, double z);
00096 
00098   double *GetStartPosition();
00099 
00101 
00102   void SetSource(vtkDataSet *source);
00103   vtkDataSet *GetSource();
00105 
00107 
00108   vtkSetClampMacro(MaximumPropagationTime,double,0.0,VTK_DOUBLE_MAX);
00109   vtkGetMacro(MaximumPropagationTime,double);
00111 
00113 
00114   vtkSetClampMacro(IntegrationDirection,int,
00115                    VTK_INTEGRATE_FORWARD,VTK_INTEGRATE_BOTH_DIRECTIONS);
00116   vtkGetMacro(IntegrationDirection,int);
00117   void SetIntegrationDirectionToForward()
00118     {this->SetIntegrationDirection(VTK_INTEGRATE_FORWARD);};
00119   void SetIntegrationDirectionToBackward()
00120     {this->SetIntegrationDirection(VTK_INTEGRATE_BACKWARD);};
00121   void SetIntegrationDirectionToIntegrateBothDirections()
00122     {this->SetIntegrationDirection(VTK_INTEGRATE_BOTH_DIRECTIONS);};
00123   const char *GetIntegrationDirectionAsString();
00125 
00127 
00129   vtkSetClampMacro(IntegrationStepLength,double,0.0000001,VTK_DOUBLE_MAX);
00130   vtkGetMacro(IntegrationStepLength,double);
00132 
00134 
00136   vtkSetMacro(SpeedScalars,int);
00137   vtkGetMacro(SpeedScalars,int);
00138   vtkBooleanMacro(SpeedScalars,int);
00140 
00142 
00147   vtkSetMacro(OrientationScalars, int);
00148   vtkGetMacro(OrientationScalars, int);
00149   vtkBooleanMacro(OrientationScalars, int);
00151 
00153 
00155   vtkSetClampMacro(TerminalSpeed,double,0.0,VTK_DOUBLE_MAX);
00156   vtkGetMacro(TerminalSpeed,double);
00158 
00160 
00165   vtkSetMacro(Vorticity,int);
00166   vtkGetMacro(Vorticity,int);
00167   vtkBooleanMacro(Vorticity,int);
00169 
00170   vtkSetMacro( NumberOfThreads, int );
00171   vtkGetMacro( NumberOfThreads, int );
00172 
00173   vtkSetMacro( SavePointInterval, double );
00174   vtkGetMacro( SavePointInterval, double );
00175 
00177 
00181   void SetIntegrator(vtkInitialValueProblemSolver *);
00182   vtkGetObjectMacro ( Integrator, vtkInitialValueProblemSolver );
00184 
00186 
00188   vtkSetMacro(Epsilon,double);
00189   vtkGetMacro(Epsilon,double);
00191   
00192 protected:
00194 
00197   vtkStreamer();
00198   ~vtkStreamer();
00200 
00201   // Integrate data
00202   void Integrate(vtkDataSet *input, vtkDataSet *source);
00203 
00204   // Controls where streamlines start from (either position or location).
00205   int StartFrom;
00206 
00207   // Starting from cell location
00208   vtkIdType StartCell;
00209   int StartSubId;
00210   double StartPCoords[3];
00211 
00212   // starting from global x-y-z position
00213   double StartPosition[3];
00214 
00215   //
00216   // Special classes for manipulating data
00217   //
00218   //BTX - begin tcl exclude
00219   //
00220   class StreamPoint {
00221   public:
00222     double    x[3];    // position 
00223     vtkIdType cellId;  // cell
00224     int       subId;   // cell sub id
00225     double    p[3];    // parametric coords in cell 
00226     double    v[3];    // velocity 
00227     double    speed;   // velocity norm 
00228     double    s;       // scalar value 
00229     double    t;       // time travelled so far 
00230     double    d;       // distance travelled so far 
00231     double    omega;   // stream vorticity, if computed
00232     double    theta;   // rotation angle, if vorticity is computed
00233   };
00234 
00235   class StreamArray;
00236   friend class StreamArray;
00237   class StreamArray { //;prevent man page generation
00238   public:
00239     StreamArray();
00240     ~StreamArray()
00241       {
00242         if (this->Array)
00243           {
00244           delete [] this->Array;
00245           }
00246       };
00247     vtkIdType GetNumberOfPoints() {return this->MaxId + 1;};
00248     StreamPoint *GetStreamPoint(vtkIdType i) {return this->Array + i;};
00249     vtkIdType InsertNextStreamPoint() 
00250       {
00251         if ( ++this->MaxId >= this->Size )
00252           {
00253           this->Resize(this->MaxId);
00254           }
00255         return this->MaxId; //return offset from array
00256       }
00257     StreamPoint *Resize(vtkIdType sz); //reallocates data
00258     void Reset() {this->MaxId = -1;};
00259 
00260     StreamPoint *Array;     // pointer to data
00261     vtkIdType MaxId;        // maximum index inserted thus far
00262     vtkIdType Size;         // allocated size of data
00263     vtkIdType Extend;       // grow array by this amount
00264     double Direction;       // integration direction
00265   };
00266   //ETX
00267   //
00268 
00269   //array of streamers
00270   StreamArray *Streamers;
00271   vtkIdType NumberOfStreamers;
00272 
00273   // length of Streamer is generated by time, or by MaximumSteps
00274   double MaximumPropagationTime;
00275 
00276   // integration direction
00277   int IntegrationDirection;
00278 
00279   // the length (fraction of cell size) of integration steps
00280   double IntegrationStepLength;
00281 
00282   // boolean controls whether vorticity is computed
00283   int Vorticity;
00284 
00285   // terminal propagation speed
00286   double TerminalSpeed;
00287 
00288   // boolean controls whether data scalars or velocity magnitude are used
00289   int SpeedScalars;
00290 
00291   // boolean controls whether data scalars or vorticity orientation are used
00292   int OrientationScalars;
00293 
00294   // Prototype showing the integrator type to be set by the user.
00295   vtkInitialValueProblemSolver* Integrator;
00296 
00297   // A positive value, as small as possible for numerical comparison.
00298   // The initial value is 1E-12.
00299   double Epsilon;
00300   
00301   // Interval with which the stream points will be stored.
00302   // Useful in reducing the memory footprint. Since the initial
00303   // value is small, by default, it will store all/most points.
00304   double SavePointInterval;
00305 
00306   static VTK_THREAD_RETURN_TYPE ThreadedIntegrate( void *arg );
00307 
00309 
00311   vtkGetMacro( NumberOfStreamers, vtkIdType );
00312   StreamArray *GetStreamers() { return this->Streamers; };
00314 
00315   void InitializeThreadedIntegrate();
00316   vtkMultiThreader           *Threader;
00317   int                        NumberOfThreads;
00318 
00319   virtual int FillInputPortInformation(int port, vtkInformation *info);
00320 
00321 private:
00322   vtkStreamer(const vtkStreamer&);  // Not implemented.
00323   void operator=(const vtkStreamer&);  // Not implemented.
00324 };
00325 
00327 
00328 inline const char *vtkStreamer::GetIntegrationDirectionAsString()
00329 {
00330   if ( this->IntegrationDirection == VTK_INTEGRATE_FORWARD ) 
00331     {
00332     return "IntegrateForward";
00333     }
00334   else if ( this->IntegrationDirection == VTK_INTEGRATE_BACKWARD ) 
00335     {
00336     return "IntegrateBackward";
00337     }
00338   else 
00339     {
00340     return "IntegrateBothDirections";
00341     }
00342 }
00344 
00345 #endif