int main(int argc, char** argv) { double ri = 0.0; double rf = 1.0; std::vector<int> npts(3); npts[0]=51;npts[1]=51;npts[2]=51; double xcut=0.23; double ycut=0.67; const int nk0=1; const int nk1=1; const int nk2=1; //Create one-dimensional grids for three orthogonal directions typedef LinearGrid<double> GridType; GridType gridX, gridY, gridZ; gridX.set(ri,rf,npts[0]); gridY.set(ri,rf,npts[1]); gridZ.set(ri,rf,npts[2]); //Create an analytic function for assignment ComboFunc infunc; infunc.push_back(0.5,new TestFunc(1,1,1)); //infunc.push_back(0.3,new TestFunc(1,1,2)); //infunc.push_back(0.1,new TestFunc(1,2,1)); //infunc.push_back(0.01,new TestFunc(2,1,1)); //infunc.push_back(0.01,new TestFunc(2,2,1)); //infunc.push_back(0.001,new TestFunc(2,1,2)); //infunc.push_back(0.001,new TestFunc(2,2,2)); //infunc.push_back(0.001,new TestFunc(5,5,5)); //infunc.push_back(-0.3,new TestFunc(7,2,3)); //infunc.push_back(0.01,new TestFunc(7,7,7)); //infunc.push_back(0.001,new TestFunc(5,5,5)); //Write to an array std::vector<double> inData(npts[0]*npts[1]*npts[2]); std::vector<double>::iterator it(inData.begin()); Pooma::Clock timer; timer.start(); //Assign the values for(int ix=0; ix<npts[0]; ix++) { double x(gridX(ix)); for(int iy=0; iy<npts[1]; iy++) { double y(gridY(iy)); for(int iz=0; iz<npts[2]; iz++) { (*it)=infunc.f(x,y,gridZ(iz));++it; } } } timer.stop(); cout << "Time to evaluate " << timer.cpu_time() << endl; //Test TriCubicSplineT function //Create XYZCubicGrid XYZCubicGrid<double> grid3(&gridX,&gridY,&gridZ); //Create a TriCubicSpline with PBC: have to think more about fixed-boundary conditions TriCubicSplineT<double> aorb(&grid3); //Reset the coefficients aorb.reset(inData.begin(), inData.end()); double lap,val; TinyVector<double,3> grad; //aorb.reset(); //Write for vtk ImageData string fname("spline3d.vti"); std::ofstream dfile(fname.c_str()); dfile.setf(ios::scientific, ios::floatfield); dfile.setf(ios::left,ios::adjustfield); dfile.precision(10); dfile << "<?xml version=\"1.0\"?>" << endl; dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl; dfile << " <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl; dfile << " <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl; dfile << " <PointData Scalars=\"wfs\">" << endl; dfile << " <DataArray type=\"Float32\" Name=\"wfs\">" << endl; timer.start(); int ng=0; for(int ix=0; ix<npts[0]-1; ix++) { double x(gridX(ix)); for(int iy=0; iy<npts[1]-1; iy++) { double y(gridY(iy)); for(int iz=0; iz<npts[2]-1; iz++, ng++) { TinyVector<double,3> p(x,y,gridZ(iz)); //aorb.setgrid(p); //Timing with the ofstream is not correct. //Uncomment the line below and comment out the next two line. //double t=aorb.evaluate(p,grad,lap); dfile << setw(20) << aorb.evaluate(p,grad,lap); if(ng%5 == 4) dfile << endl; } } } timer.stop(); cout << "Time to evaluate with spline " << timer.cpu_time() << endl; dfile << " </DataArray>" << endl; dfile << " </PointData>" << endl; dfile << " </Piece>" << endl; dfile << " </ImageData>" << endl; dfile << "</VTKFile>" << endl; hid_t h_file = H5Fcreate("spline3d.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); HDFAttribIO<std::vector<double> > dump(inData,npts); dump.write(h_file,"orb0000"); HDFAttribIO<TriCubicSplineT<double> > dump1(aorb); dump1.write(h_file,"spline0000"); H5Fclose(h_file); //double lap; //TinyVector<double,3> grad; //for(int k=0; k<nptY-1; k++) { // //TinyVector<double,3> p(xcut,ycut,gridZ(k)+0.11*gridZ.dr(k)); // TinyVector<double,3> p(xcut,gridY(k)+0.11*gridY.dr(k),ycut); // aorb.setgrid(p); // double y=aorb.evaluate(p,grad,lap); // dfile << setw(30) << p[1] << setw(30) << infunc.f(p) << setw(30) << y << setw(30) << infunc.d2f(p) << setw(30) << lap << endl; //} return 0; }
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice) { // Setup some materials - we'll use these for // making the same mesh appear in multiple // colors D3DMATERIAL9 colors[8]; D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f ); // white D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f ); // cyan D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f ); // red D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f ); // green D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f ); // blue D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f ); // 40% grey D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f ); // 25% grey D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f ); // 65% grey // The identity matrix is always useful D3DXMATRIX ident; D3DXMatrixIdentity(&ident); // We'll use these rotations for some teapots and grid objects D3DXMATRIX rotateX, rotateY, rotateZ; // Create the root, and the camera. // Remeber how to use smart pointers?? I hope so! boost::shared_ptr<TransformNode> root(new TransformNode(&ident)); boost::shared_ptr<CameraNode> camera(new CameraNode(&ident)); root->m_children.push_back(camera); // We'll put the camera in the scene at (20,20,20) looking back at the Origin D3DXMATRIX rotOnly, result, inverse; float cameraYaw = - (3.0f * D3DX_PI) / 4.0f; float cameraPitch = D3DX_PI / 4.0f; D3DXQUATERNION q; D3DXQuaternionIdentity(&q); D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0); D3DXMatrixRotationQuaternion(&rotOnly, &q); D3DXMATRIX trans; D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f); D3DXMatrixMultiply(&result, &rotOnly, &trans); D3DXMatrixInverse(&inverse, NULL, &result); camera->VSetTransform(&result, &inverse); D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f); D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f); D3DXVECTOR3 target(30, 2, 15); // ID3DXMesh *teapot; if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) ) { // Teapot #1 - a white one at (x=6,y=2,z=4) D3DXMatrixTranslation(&trans,6,2,4); boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2])); root->m_children.push_back(mesh1); // Teapot #2 - a cyan one at (x=3,y=2,z=1) // with a D3DXMatrixTranslation(&trans, 3,2,1); D3DXMATRIX result; D3DXMatrixMultiply(&result, &rotateZ, &trans); boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1])); root->m_children.push_back(mesh2); // Teapot #3 - another white one at (x=30, y=2, z=15) D3DXMATRIX rotateY90; D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f); D3DXMatrixTranslation(&trans, target.x, target.y, target.z); D3DXMatrixMultiply(&result, &rotateY90, &trans); boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0])); root->m_children.push_back(mesh3); // We can release the teapot now, mesh1 and mesh2 AddRef'd it. SAFE_RELEASE(teapot); } ID3DXMesh *sphere; if ( SUCCEEDED( D3DXCreateSphere( d3dDevice, .25, 16, 16, &sphere, NULL) ) ) { // We're going to create a spiral of spheres... // starting at (x=3, y=0, z=3), and spiraling // upward about a local Y axis. D3DXMatrixTranslation(&trans, 3,0,3); boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) ); root->m_children.push_back(sphere1); // Here's the local rotation and translation. // We'll rotate about Y, and then translate // up (along Y) and forward (along Z). D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f); D3DXMATRIX trans2; D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5); D3DXMatrixMultiply(&result, &trans2, &rotateY); for (int i=0; i<25; i++) { // If you didn't think smart pointers were cool - // watch this! No leaked memory.... // Notice this is a heirarchy.... boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) ); sphere1->m_children.push_back(sphere2); sphere1 = sphere2; } // We can release the sphere now, all the cylinders AddRef'd it. SAFE_RELEASE(sphere); } // D3DXMatrixTranslation(&trans,-25,20,20); //D3DXMatrixScaling(&trans, -10, -10, -10); ScaleMtrl scale; scale.x = -50.0f; scale.y = -50.0f; scale.z = -50.0f; boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh1); root->m_children.push_back(xmesh1); /*D3DXMatrixTranslation(&trans,-45,20,20); boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh11);*/ XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale); D3DXMatrixTranslation(&trans,10,10,10); //D3DXMatrixScaling(&trans, -10, -10, -10); //ScaleMtrl scale; scale.x = 100.0f; scale.y = 100.0f; scale.z = 100.0f; boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh2); /*D3DXMatrixTranslation(&trans,20,20,20); boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmesh3);*/ int col = 10; int row= 10; int zoom = 10; const int COUNT = 13; for(int i = 0; i < COUNT; i++) { for (int j = 0; j< COUNT; j++) { for(int z = 0; z< COUNT; z++) { D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z); boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmeshNew); } } } //D3DXMatrixScaling(&trans, 10, 10, 10); // Here are the grids...they make it easy for us to // see where the coordinates are in 3D space. boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident)); root->m_children.push_back(grid1); boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX)); root->m_children.push_back(grid2); boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ)); root->m_children.push_back(grid3); // Here's the sky node that never worked!!!! boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera)); root->m_children.push_back(sky); D3DXMatrixTranslation(&trans,15,2,15); D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow1); D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice)); root->m_children.push_back(arrow2); D3DXMatrixMultiply(&result, &rotateX, &trans); boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow3); // Everything has been attached to the root. Now // we attach the root to the scene. Scene *scene = new Scene(d3dDevice, root); scene->Restore(); // A movement controller is going to control the camera, // but it could be constructed with any of the objects you see in this // function. You can have your very own remote controlled sphere. What fun... boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch)); scene->m_pMovementController = m_pMovementController; return scene; }
/* BEGIN Module Compute Routine */ int module_compute( AVSfield *data, AVSfield *coords, AVSfield *weights, AVSfield *table, AVSfield **out, float *radiusFOVproduct, int width_in, float *OverSampFact, float *windowLength, float *taper_start, float *taper_length, int num_threads, int veclen, /* if data is not present */ int compute) { /* check to see if the body should run or not */ if(!compute) { /* don't signal downstream modules */ AVSmark_output_unchanged("spectrum"); return(1); } /* grid size */ int width = (float)width_in * (*OverSampFact); /* allocate kernel table */ unsigned long dim[1]; dim[0] = DEFAULT_KERNEL_TABLE_SIZE; dataArray_double *kern = (dataArray_double*) new_dataArray_double(1,dim); for(long i=0;i<kern->num_elem;i++) kern->data[i]=0.; loadGrid3Kernel(kern); /* make dataArray_double copies of input data */ dataArray_double *data_tmp = AVSfield_2_dataArray( (AVSfield_double*)data ); dataArray_double *crds_tmp = AVSfield_2_dataArray( (AVSfield_double*)coords ); dataArray_double *wght_tmp = NULL; if (weights != NULL) wght_tmp = AVSfield_2_dataArray( (AVSfield_double*)weights ); unsigned long dims[4]; dims[0] = 2; /* complex */ dims[1] = width; dims[2] = width; dims[3] = width; dataArray_double *out_tmp = new_dataArray_double(4,dims); /* choose either octant split gridding or single thread */ if(num_threads == 8) { /* GRID3_threaded */ /* 1) map threads */ dataArray_double *threadMask = NULL; dataArray_double *centerPts = NULL; int partsize = -1; double rfp_d = *radiusFOVproduct; partitionGrid_octants(crds_tmp, rfp_d, width, &threadMask, ¢erPts, &partsize); /* 2) grid it */ grid3_threaded(data_tmp, crds_tmp, wght_tmp, out_tmp, kern, *radiusFOVproduct, *windowLength, num_threads, threadMask, centerPts, partsize); /* free tmp data */ free_dataArray_double(threadMask); free_dataArray_double(centerPts); } else { /* GRID3 non-threaded */ int nt = 1; int ct = 0; double rfp_d = *radiusFOVproduct; double win_d = *windowLength; grid3 ( &nt, &ct, data_tmp, crds_tmp, wght_tmp, &out_tmp, kern, NULL, NULL, &width, &rfp_d, &win_d ); } /* allocate output array */ if(*out != NULL) AVSfield_free((AVSfield*)*out); *out = (AVSfield *)dataArray_2_AVSfield(out_tmp); /* free kernel table */ free_dataArray_double(kern); free_dataArray_double(out_tmp); return 1; }