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

src/aclvis/poomastub.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // 
00027 // create iso-surface of the Lorenz attractor
00028 //
00029 
00030 #ifdef IPPL_USE_STANDARD_HEADERS
00031 #include <iostream>
00032 using namespace std;
00033 #else
00034 #include <iostream.h>
00035 #endif
00036 
00037 #include <vtk.h>
00038 #include "Profile/Profiler.h"
00039 
00040 float   Pr = 10.0;      // The Lorenz parameters
00041 float   b = 2.667;
00042 float   r = 28.0;
00043 float   x, y, z;        // starting (and current) x, y, z 
00044 float   h = 0.01;       // integration step size 
00045 int     resolution=200; // slice resolution 
00046 //int     iter = 10000000;        // number of iterations 
00047 int     iter = 100;        // number of iterations 
00048 float   xmin = -30.0;   // x, y, z range for voxels 
00049 float   xmax = 30.0;
00050 float   ymin = -30.0;
00051 float   ymax = 30.0;
00052 float   zmin = -10.0;
00053 float   zmax = 60.0;
00054 
00055 int randomMode = 1;
00056 float xIncr, yIncr, zIncr;
00057 short   *slice;
00058 
00059 void Lorenz(vtkStructuredPoints *vizdata, float Pr) {
00060   TAU_PROFILE("Lorenz()", "void (vtkStructuredPoints *, float)", TAU_VIZ);
00061 
00062   vtkShortScalars *scalars;
00063 
00064   int   i, j;        
00065   float xx, yy, zz;
00066   short xxx, yyy, zzz;
00067   int   sliceSize;
00068 
00069   short *s;
00070   void options(int, char**);
00071   int numPts, index;
00072   vtkMath math;
00073 
00074   // take a stab at an integration step size
00075   xIncr = resolution / (xmax - xmin);
00076   yIncr = resolution / (ymax - ymin);
00077   zIncr = resolution / (zmax - zmin);
00078 
00079   // printf ("The Lorenz Attractor\n");
00080   // printf ("     Pr = %f\n", Pr);
00081   // printf ("     b = %f\n", b);
00082   // printf ("     r = %f\n", r);
00083   // printf ("     integration step size = %f\n", h);
00084   // printf ("     slice resolution = %d\n", resolution);
00085   // printf ("     # of iterations = %d\n", iter);
00086   // printf ("     specified range:\n");
00087   // printf ("             x: %f, %f\n", xmin, xmax);
00088   // printf ("             y: %f, %f\n", ymin, ymax);
00089   // printf ("             z: %f, %f\n", zmin, zmax);
00090 
00091   x = math.Random(xmin,xmax);
00092   y = math.Random(ymin,ymax);
00093   z = math.Random(zmin,zmax);
00094   // printf ("     starting at %f, %f, %f\n", x, y, z);
00095 
00096   // allocate memory for the slices
00097   sliceSize = resolution * resolution;
00098   numPts = sliceSize * resolution;
00099   scalars = new vtkShortScalars(numPts);
00100   //scalars = (vtkShortScalars *)vizdata->GetPointData()->GetScalars();
00101   s = scalars->WritePtr(0,numPts);
00102   for (i=0; i < numPts; i++) s[i] = 0;
00103 
00104   // printf ("     integrating...\n");
00105   for (j = 0; j < iter; j++) 
00106     {
00107     // integrate to next time step
00108     xx = x + h * Pr * (y - x);
00109     yy = y + h * (x * (r - z) - y);
00110     zz = z + h * (x * y - (b * z));
00111 
00112     x = xx; y = yy; z = zz;
00113 
00114     // calculate voxel index
00115     if (x < xmax && x > xmin && y < ymax && y > ymin && z < zmax && z > zmin) 
00116       {
00117       xxx = (short) ((float)(xx - xmin) * xIncr);
00118       yyy = (short) ((float)(yy - ymin) * yIncr);
00119       zzz = (short) ((float)(zz - zmin) * zIncr);
00120       index = xxx + yyy*resolution + zzz*sliceSize;
00121       s[index] += 1;
00122       }
00123     }
00124   scalars->WrotePtr();
00125   vizdata->GetPointData()->SetScalars(scalars);
00126   vizdata->SetDimensions(resolution,resolution,resolution);
00127   vizdata->SetOrigin(xmin,ymin,zmin);
00128   vizdata->SetAspectRatio((xmax-xmin)/resolution, (ymax-ymin)/resolution, (zmax-zmin)/resolution);
00129   scalars->Delete();
00130 }
00131 
00132 
00133 #include "aclvis/ipplstub.h"
00134 
00135 ConnectStub::ConnectStub(int type_param) {
00136   TAU_PROFILE("ConnectStub::ConnectStub()", "void (int)", TAU_VIZ);
00137   type = type_param;
00138   if (type == ACLVIS) {
00139     connection = new VizTool();
00140   }
00141 }
00142 
00143 int ConnectStub::GetType(){
00144   TAU_PROFILE("ConnectStub::GetType()", "int ()", TAU_VIZ);
00145   return type;
00146 }
00147 
00148 void ConnectStub::SetType(int type_param){
00149   TAU_PROFILE("ConnectStub::SetType()", "void (int)", TAU_VIZ);
00150   type = type_param;
00151 }
00152  
00153 void *ConnectStub::GetConnection(){
00154   TAU_PROFILE("ConnectStub::GetConnection()", "void ()", TAU_VIZ);
00155   return connection;
00156 }
00157 
00158 void ConnectStub::SetConnection(void *connection_param) {
00159   TAU_PROFILE("ConnectStub::SetConnection()", "void (void *)", TAU_VIZ);
00160   connection = connection_param;
00161 }
00162 
00163 void FieldStub::connect(ConnectStub *connect_stub_param,
00164                         char *name, ConnectDataType ctype){
00165   TAU_PROFILE("FieldStub::connect()", "void (ConnectStub *, char *, ConnectDataType)", 
00166     TAU_VIZ);
00167   VizTool *viztool;
00168 
00169   connectDataType = ctype;
00170   if (ctype == FieldDataType) {
00171     readtool = new ReadFieldTool;
00172   } else {
00173     readtool = new ReadParticleTool;
00174   }
00175 
00176   connect_stub = connect_stub_param;
00177   if (connect_stub->GetType() == ACLVIS) {
00178     viztool = (VizTool *)connect_stub->GetConnection();
00179     viztool->connect(this, name, readtool, ctype);
00180   }
00181 }
00182 
00183 void FieldStub::update(float Pr){
00184   TAU_PROFILE("FieldStub::update()", "void (float)", TAU_VIZ);
00185   VizTool *viztool;
00186 
00187   if (connectDataType == FieldDataType) {
00188     ReadFieldTool *readFieldTool;
00189     readFieldTool = (ReadFieldTool *)readtool;
00190     Lorenz(readFieldTool->GetOutput(),Pr);
00191   }
00192     
00193   //cerr << "ippl-stub: \n";
00194   if (connect_stub->GetType() == ACLVIS) {
00195     viztool = (VizTool *)connect_stub->GetConnection();
00196     viztool->update(this);
00197   }
00198 }
00199 
00200 void FieldStub::interact(int flag){
00201   TAU_PROFILE("FieldStub::interact()", "void (int)", TAU_VIZ);
00202   VizTool *viztool;
00203 
00204   if (connect_stub->GetType() == ACLVIS) {
00205 
00206     viztool = (VizTool *)connect_stub->GetConnection();
00207     viztool->Interact(flag);
00208   }
00209 }
00210 
00211 void FieldStub::disconnect(){
00212   TAU_PROFILE("FieldStub::disconnect()", "void ()", TAU_VIZ);
00213   VizTool *viztool;
00214 
00215   if (connect_stub->GetType() == ACLVIS) {
00216     viztool = (VizTool *)connect_stub->GetConnection();
00217     viztool->disconnect(this);
00218   }
00219 }
00220 
00221 
00222 /***************************************************************************
00223  * $RCSfile: ipplstub.cpp,v $   $Author: adelmann $
00224  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:34 $
00225  * IPPL_VERSION_ID: $Id: ipplstub.cpp,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 
00226  ***************************************************************************/

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