TEST(Mesh,CompareRealSpace) { alps::gf::real_space_index_mesh::container_type points1(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points2(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points3(boost::extents[20][3]); alps::gf::real_space_index_mesh::container_type points4(boost::extents[3][20]); for (int i=0; i<points1.num_elements(); ++i) { *(points1.origin()+i)=i; *(points2.origin()+i)=i; *(points3.origin()+i)=i+1; *(points4.origin()+i)=i; } alps::gf::real_space_index_mesh mesh1(points1); alps::gf::real_space_index_mesh mesh2(points2); alps::gf::real_space_index_mesh mesh3(points3); alps::gf::real_space_index_mesh mesh4(points4); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_TRUE(mesh1!=mesh4); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); EXPECT_FALSE(mesh1==mesh4); }
void KNDdeTorusCollocation::importTangent(KNVector& out, KNVector& Re, KNVector& Im, double alpha) { // alpha /= 2.0; for (size_t i2 = 0; i2 < nint2; i2++) { for (size_t i1 = 0; i1 < nint1; i1++) { for (size_t j2 = 0; j2 < ndeg2; j2++) { for (size_t j1 = 0; j1 < ndeg1; j1++) { const size_t idx1 = idxmap(j1, j2, i1, i2); const double t1 = (mesh1(j1) + i1) / ((double)nint1); const double t2 = (mesh2(j2) + i2) / ((double)nint2); for (size_t p = 0; p < NDIM; p++) { out(p + NDIM*idx1) = cos(-alpha * t1 + 2 * M_PI * t2) * Re(p + NDIM * (j1 + i1 * ndeg1)) + sin(-alpha * t1 + 2 * M_PI * t2) * Im(p + NDIM * (j1 + i1 * ndeg1)); } } } } } double norm = sqrt(integrate(out, out)); out /= norm; }
void Project::computeCrownIntersections() { for(int i=0; i<get_sizeTreeCV()-1; i++) { if(get_TreeCloud(i).isCrownExist()==true && get_TreeCloud(i).get_TreeCrown().isConvexhull3DExist()==true) { pcl::PolygonMesh mesh1(get_TreeCloud(i).get_TreeCrown().get3DConvexhull().getMesh()); QString name1 = get_TreeCloud(i).get_name(); for(int j=i+1; j<get_sizeTreeCV(); j++) { if(get_TreeCloud(j).isCrownExist()==true && get_TreeCloud(j).get_TreeCrown().isConvexhull3DExist()==true) { pcl::PointXYZI c1 = get_TreeCloud(i).get_TreeCrown().getCrownPosition(); pcl::PointXYZI c2 = get_TreeCloud(j).get_TreeCrown().getCrownPosition(); float l1 = get_TreeCloud(i).get_TreeCrown().getCrownLenghtXY(); float l2 = get_TreeCloud(j).get_TreeCrown().getCrownLenghtXY(); if(isIntersectionPossible(c1,l1,c2,l2) == true ) { pcl::PolygonMesh mesh2(get_TreeCloud(j).get_TreeCrown().get3DConvexhull().getMesh()); QString name2 = get_TreeCloud(j).get_name(); PolyhedronIntersections3D p(mesh1,mesh2,name1,name2); if(p.getSurface() > 0 && p.getVolume()>0) { m_intersections3D.push_back(p); } } } } } } }
void move(void) { if (N > 2.1 || N < 1.5) dir = -dir; N += incr*dir; mesh1(-1.5,1.5,-1.5,1.5,0.0,1.0,0.0,1.0,0.0,64,64); glutPostRedisplay(); }
TEST(Mesh,PrintIndexMeshHeader) { int n=2; std::stringstream header_line; header_line << "# INDEX mesh: N: "<<n<<std::endl; alps::gf::index_mesh mesh1(2); std::stringstream header_line_from_mesh; header_line_from_mesh << mesh1; EXPECT_EQ(header_line.str(), header_line_from_mesh.str()); }
TEST(Mesh,PrintImagTimeMeshHeader) { double beta=5.; int ntau=200; std::stringstream header_line; header_line << "# IMAGINARY_TIME mesh: N: "<<ntau<<" beta: "<<beta<<" statistics: "<<"FERMIONIC"<<std::endl; alps::gf::itime_mesh mesh1(beta, ntau); std::stringstream header_line_from_mesh; header_line_from_mesh << mesh1; EXPECT_EQ(header_line.str(), header_line_from_mesh.str()); }
TEST(Mesh,CompareITime) { alps::gf::itime_mesh mesh1(5.0, 20); alps::gf::itime_mesh mesh2(5.0, 20); alps::gf::itime_mesh mesh3(4.0, 20); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
TEST(Mesh,CompareIndex) { alps::gf::index_mesh mesh1(20); alps::gf::index_mesh mesh2(20); alps::gf::index_mesh mesh3(19); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
TEST(Mesh,CompareMatsubara) { alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh1(5.0, 20); alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh2(5.0, 20); alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh3(4.0, 20); EXPECT_TRUE(mesh1==mesh2); EXPECT_TRUE(mesh1!=mesh3); EXPECT_FALSE(mesh1==mesh3); EXPECT_FALSE(mesh1!=mesh2); }
TEST(Mesh,PrintMatsubaraMeshHeader) { double beta=5.; int n=20; { std::stringstream header_line; header_line << "# MATSUBARA mesh: N: "<<n<<" beta: "<<beta<<" statistics: "<<"FERMIONIC"<<" POSITIVE_ONLY"<<std::endl; alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_ONLY> mesh1(beta, n); std::stringstream header_line_from_mesh; header_line_from_mesh << mesh1; EXPECT_EQ(header_line.str(), header_line_from_mesh.str()); } { std::stringstream header_line; header_line << "# MATSUBARA mesh: N: "<<n<<" beta: "<<beta<<" statistics: "<<"FERMIONIC"<<" POSITIVE_NEGATIVE"<<std::endl; alps::gf::matsubara_mesh<alps::gf::mesh::POSITIVE_NEGATIVE> mesh1(beta, n); std::stringstream header_line_from_mesh; header_line_from_mesh << mesh1; EXPECT_EQ(header_line.str(), header_line_from_mesh.str()); } }
TEST(Mesh,PrintRealSpaceMeshHeader) { alps::gf::real_space_index_mesh::container_type data=get_data_for_real_space_mesh(); std::stringstream header_line; header_line << "# REAL_SPACE_INDEX mesh: N: "<<data.shape()[0]<<" dimension: "<<data.shape()[1]<<" points: "; for(int i=0;i<data.shape()[0];++i){ header_line<<"("; for(int d=0;d<data.shape()[1]-1;++d){ header_line<<data[i][d]<<","; } header_line<<data[i][data.shape()[1]-1]<<") "; } header_line<<std::endl; alps::gf::real_space_index_mesh mesh1(data); std::stringstream header_line_from_mesh; header_line_from_mesh << mesh1; EXPECT_EQ(header_line.str(), header_line_from_mesh.str()); }
void KNDdeTorusCollocation::Save(const char* dat, const char* idx, const KNVector& in) { // writing to file for plotting std::ofstream ff(dat); for (size_t i2 = 0; i2 < nint2; i2++) { for (size_t j2 = 0; j2 < ndeg2; j2++) { for (size_t i1 = 0; i1 < nint1; i1++) { for (size_t j1 = 0; j1 < ndeg1; j1++) { const size_t idx1 = idxmap(j1, j2, i1, i2); for (size_t p = 0; p < NDIM; p++) { ff << in(p + NDIM*idx1) << "\t"; } } } ff << "\n"; } } std::ofstream gg(idx); for (size_t i1 = 0; i1 < nint1; i1++) { for (size_t j1 = 0; j1 < ndeg1; j1++) { const double t1 = (mesh1(j1) + i1) / ((double)nint1); gg << t1 << "\t"; } } gg << "\n"; for (size_t i2 = 0; i2 < nint2; i2++) { for (size_t j2 = 0; j2 < ndeg2; j2++) { const double t2 = (mesh2(j2) + i2) / ((double)nint2); gg << t2 << "\t"; } } gg << "\n"; }
void test(Pooma::Tester &tester) { // Create a mesh using a DomainLayout. DomainLayout<2> layout1(physicalVertexDomain, gl); tester.out() << layout1 << std::endl; Mesh mesh1(layout1, origin, spacings); // Set up some centerings. Centering<2> cell = canonicalCentering<2>(CellType, Continuous); // Initialize a field. Field<Mesh> f1(cell, layout1, mesh1); // Do the tests. testPositions(tester, f1); testNormals(tester, f1); testCellVolumes(tester, f1); testFaceAreas(tester, f1); testEdgeLengths(tester, f1); }
void NGLScene::initializeGL() { // we must call this first before any other GL commands to load and link the // gl commands from the lib, if this is not done program will crash ngl::NGLInit::instance(); glClearColor(0.4f, 0.4f, 0.4f, 1.0f); // Grey Background // enable depth testing for drawing glEnable(GL_DEPTH_TEST); // enable multisampling for smoother drawing glEnable(GL_MULTISAMPLE); // Now we will create a basic Camera from the graphics library // This is a static camera so it only needs to be set once // First create Values for the camera position ngl::Vec3 from(0,10,40); ngl::Vec3 to(0,10,0); ngl::Vec3 up(0,1,0); // first we create a mesh from an obj passing in the obj file and texture std::unique_ptr<ngl::Obj>mesh1( new ngl::Obj("models/BrucePose1.obj")); m_meshes.push_back(std::move(mesh1)); std::unique_ptr<ngl::Obj> mesh2( new ngl::Obj("models/BrucePose2.obj")); m_meshes.push_back(std::move(mesh2)); std::unique_ptr<ngl::Obj>mesh3( new ngl::Obj("models/BrucePose3.obj")); m_meshes.push_back(std::move(mesh3)); createMorphMesh(); m_view=ngl::lookAt(from,to,up); // set the shape using FOV 45 Aspect Ratio based on Width and Height // The final two are near and far clipping planes of 0.5 and 10 m_project=ngl::perspective(45,(float)720.0/576.0,0.05,350); // now to load the shader and set the values // grab an instance of shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); // we are creating a shader called PerFragADS shader->createShaderProgram("PerFragADS"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("PerFragADSVertex",ngl::ShaderType::VERTEX); shader->attachShader("PerFragADSFragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("PerFragADSVertex","shaders/PerFragASDVert.glsl"); shader->loadShaderSource("PerFragADSFragment","shaders/PerFragASDFrag.glsl"); // compile the shaders shader->compileShader("PerFragADSVertex"); shader->compileShader("PerFragADSFragment"); // add them to the program shader->attachShaderToProgram("PerFragADS","PerFragADSVertex"); shader->attachShaderToProgram("PerFragADS","PerFragADSFragment"); // now we have associated this data we can link the shader shader->linkProgramObject("PerFragADS"); // and make it active ready to load values (*shader)["PerFragADS"]->use(); // now we need to set the material and light values /* *struct MaterialInfo { // Ambient reflectivity vec3 Ka; // Diffuse reflectivity vec3 Kd; // Specular reflectivity vec3 Ks; // Specular shininess factor float shininess; };*/ shader->setUniform("material.Ka",0.1f,0.1f,0.1f); // red diffuse shader->setUniform("material.Kd",0.8f,0.8f,0.8f); // white spec shader->setUniform("material.Ks",1.0f,1.0f,1.0f); shader->setUniform("material.shininess",1000.0f); // now for the lights values (all set to white) /*struct LightInfo { // Light position in eye coords. vec4 position; // Ambient light intensity vec3 La; // Diffuse light intensity vec3 Ld; // Specular light intensity vec3 Ls; };*/ shader->setUniform("light.position",ngl::Vec3(2,20,2)); shader->setUniform("light.La",0.1f,0.1f,0.1f); shader->setUniform("light.Ld",1.0f,1.0f,1.0f); shader->setUniform("light.Ls",0.9f,0.9f,0.9f); glEnable(GL_DEPTH_TEST); // for removal of hidden surfaces // as re-size is not explicitly called we need to do this. glViewport(0,0,width(),height()); m_text.reset( new ngl::Text(QFont("Arial",16))); m_text->setScreenSize(width(),height()); }
int main(int argc, char* argv[]) { // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh1(new Mesh); if (USE_XML_FORMAT == true) { MeshReaderH2DXML mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); mloader.load("square.xml", mesh); } else { MeshReaderH2D mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); mloader.load("square.mesh", mesh); } // Perform uniform mesh refinement. int refinement_type = 0; for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(refinement_type); // Show mesh. MeshView mv("Mesh", new WinGeom(0, 0, 580, 400)); mv.show(mesh); // Exact lambda MeshFunctionSharedPtr<double> exact_lambda(new ExactSolutionLambda(mesh,E,nu)); ScalarView viewLam("lambda [Pa]", new WinGeom(0, 460, 530, 350)); viewLam.show_mesh(false); viewLam.show(exact_lambda); // Exact lambda MeshFunctionSharedPtr<double> exact_mu(new ExactSolutionMu(mesh,E,nu)); ScalarView viewMu("mu [Pa]", new WinGeom(550, 460, 530, 350)); viewMu.show_mesh(false); viewMu.show(exact_mu); // Initialize boundary conditions. DefaultEssentialBCConst<double> disp_bot_top_x(Hermes::vector<std::string>("Bottom","Top"), 0.0); DefaultEssentialBCConst<double> disp_bot_y("Bottom", 0.0); DefaultEssentialBCConst<double> disp_top_y("Top", 0.1); EssentialBCs<double> bcs_x(&disp_bot_top_x); EssentialBCs<double> bcs_y(Hermes::vector<EssentialBoundaryCondition<double> *>(&disp_bot_y, &disp_top_y)); // Create x- and y- displacement space using the default H1 shapeset. SpaceSharedPtr<double> u1_space(new H1Space<double>(mesh, &bcs_x, P_INIT)); SpaceSharedPtr<double> u2_space(new H1Space<double>(mesh, &bcs_y, P_INIT)); Hermes::vector<SpaceSharedPtr<double> > spaces(u1_space, u2_space); int ndof = Space<double>::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormLinearElasticity wf(E, nu, &lambdaFun, &muFun, rho*g1, "Top", f0, f1); // Initialize Newton solver. NewtonSolver<double> newton(&wf, spaces); newton.set_verbose_output(true); // Perform Newton's iteration. try { newton.solve(); } catch(std::exception& e) { std::cout << e.what(); Hermes::Mixins::Loggable::Static::info("Newton's iteration failed."); } // Translate the resulting coefficient vector into the Solution sln. MeshFunctionSharedPtr<double> u1_sln(new Solution<double>), u2_sln(new Solution<double>); Hermes::vector<MeshFunctionSharedPtr<double> > solutions(u1_sln, u2_sln); Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, solutions); // Visualize the solution. ScalarView view("Von Mises stress [Pa]", new WinGeom(590, 0, 700, 400)); // First Lame constant. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); // Second Lame constant. double mu = E / (2*(1 + nu)); MeshFunctionSharedPtr<double> stress(new VonMisesFilter(solutions, lambda, mu)); MeshFunctionSharedPtr<double> S11(new CustomFilterS11(solutions, &muFun, &lambdaFun)); MeshFunctionSharedPtr<double> S12(new CustomFilterS12(solutions, mu)); MeshFunctionSharedPtr<double> S22(new CustomFilterS22(solutions, mu, lambda)); view.show_mesh(false); view.show(stress, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS11("S11 [Pa]", new WinGeom(0, 260, 530, 350)); viewS11.show_mesh(false); viewS11.show(S11, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS12("S12 [Pa]", new WinGeom(540, 260, 530, 350)); viewS12.show_mesh(false); viewS12.show(S12, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS22("S22 [Pa]", new WinGeom(1080, 260, 530, 350)); viewS22.show_mesh(false); viewS22.show(S22, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); // Wait for the view to be closed. View::wait(); 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; }
int main(int argc, char **argv) { TCLAP::ValueArg<int> rotation1("","rotation1", "The rotation of mesh 1", false, 0, "int"); TCLAP::ValueArg<int> rotation2("","rotation2", "The rotation of mesh 2", false, 0, "int"); TCLAP::SwitchArg dual1("","dual1", "The rotation of mesh 1", false); TCLAP::SwitchArg dual2("","dual2", "The rotation of mesh 2", false); TCLAP::UnlabeledValueArg<std::string> solution1_filename("solution1", "File name of first solution", true, "", "string"); TCLAP::UnlabeledValueArg<std::string> solution2_filename("solution2", "File name of first solution", true, "", "string"); try { TCLAP::CmdLine cmd("Compare solutions", ' ', "1.0"); cmd.add( rotation1 ); cmd.add( rotation2 ); cmd.add( dual1 ); cmd.add( dual2 ); cmd.add( solution1_filename ); cmd.add( solution2_filename ); cmd.parse( argc, argv ); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; return false; } viennagrid_numeric rotation_angle1 = 2*M_PI / 5 * rotation1.getValue(); viennagrid_numeric rotation_angle2 = 2*M_PI / 5 * rotation2.getValue(); viennagrid_mesh cmesh1; viennagrid_quantity_field solution1; viennagrid_mesh_io reader1; viennagrid_mesh_io_create(&reader1); viennagrid_error err1 = viennagrid_mesh_io_read_pvd(reader1, solution1_filename.getValue().c_str()); viennagrid_mesh_io_mesh_get(reader1, &cmesh1); viennagrid_mesh_io_quantity_field_get_by_index(reader1, 0, &solution1); viennagrid_mesh cmesh2; viennagrid_quantity_field solution2; viennagrid_mesh_io reader2; viennagrid_mesh_io_create(&reader2); viennagrid_error err2 = viennagrid_mesh_io_read_pvd(reader2, solution2_filename.getValue().c_str()); viennagrid_mesh_io_mesh_get(reader2, &cmesh2); viennagrid_mesh_io_quantity_field_get_by_index(reader2, 0, &solution2); viennagrid::mesh mesh1(cmesh1); viennagrid::mesh mesh2(cmesh2); // viennagrid_numeric matrix[4]; Transformation transformation = Transformation::make_rotation_2(- (rotation_angle1-rotation_angle2)); // Transformation rotation = if (dual1.getValue() != dual2.getValue()) { viennagrid_numeric angle = rotation_angle2 - 2*2*M_PI/5; viennagrid_numeric back_angle = rotation_angle2 - 3*2*M_PI/5; Transformation de_mirror = composition( Transformation::make_rotation_2(2*M_PI/5), Transformation::make_reflection_x(2) ); // composition( // Transformation::make_rotation_2(-back_angle), // composition( // Transformation::make_reflection_x(2), // Transformation::make_rotation_2(angle) // ) // ); transformation = composition( transformation, composition( Transformation::make_rotation_2(M_PI), Transformation::make_reflection_2(rotation_angle2 - M_PI/5) ) ); } // // if (dual.isSet()) // { // // } // else // { // matrix[0] = std::cos(rotation_angle); // matrix[1] = - std::sin(rotation_angle); // matrix[2] = std::sin(rotation_angle); // matrix[3] = std::cos(rotation_angle); // } viennagrid_mesh_affine_transform(mesh2.internal(), 2, &transformation.matrix.values[0], 0); viennagrid_mesh_io_write(reader1, "mesh1.vtu"); viennagrid_mesh_io_write(reader2, "mesh2.vtu"); int max_element_per_node = 10; int max_depth = 1000; NTreeNode * ntree1 = new NTreeNode(viennagrid::make_point(-1.1, -1.1), viennagrid::make_point( 1.1, 1.1)); { ElementRangeType cells(mesh1, 2); for (ElementRangeIterator cit = cells.begin(); cit != cells.end(); ++cit) ntree1->add(*cit, max_element_per_node, max_depth); } NTreeNode * ntree2 = new NTreeNode(viennagrid::make_point(-1.1, -1.1), viennagrid::make_point( 1.1, 1.1)); { ElementRangeType cells(mesh2, 2); for (ElementRangeIterator cit = cells.begin(); cit != cells.end(); ++cit) ntree2->add(*cit, max_element_per_node, max_depth); } std::cout << compare(mesh1, ntree1, viennagrid::quantity_field(solution1), mesh2, ntree2, viennagrid::quantity_field(solution2), 1e-6, 1e-6) << std::endl;; viennagrid_mesh_io_release(reader1); viennagrid_mesh_io_release(reader2); return 0; }
int main(int argc, char* argv[]) { // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh1(new Mesh); if (USE_XML_FORMAT == true) { MeshReaderH2DXML mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); mloader.load("domain.xml", mesh); } else { MeshReaderH2D mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); mloader.load("domain.mesh", mesh); } // Perform uniform mesh refinement. mesh->refine_all_elements(); // Show mesh. MeshView mv("Mesh", new WinGeom(0, 0, 580, 400)); mv.show(mesh); // Initialize boundary conditions. DefaultEssentialBCConst<double> zero_disp("Bottom", 0.0); EssentialBCs<double> bcs(&zero_disp); // Create x- and y- displacement space using the default H1 shapeset. SpaceSharedPtr<double> u1_space(new H1Space<double>(mesh, &bcs, P_INIT)); SpaceSharedPtr<double> u2_space(new H1Space<double>(mesh, &bcs, P_INIT)); Hermes::vector<SpaceSharedPtr<double> > spaces(u1_space, u2_space); int ndof = Space<double>::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "Top", f0, f1); // Initialize the FE problem. DiscreteProblem<double> dp(&wf, spaces); // Initialize Newton solver. NewtonSolver<double> newton(&dp); newton.set_verbose_output(true); // Perform Newton's iteration. try { newton.solve(); } catch(std::exception& e) { std::cout << e.what(); } // Translate the resulting coefficient vector into the Solution sln. MeshFunctionSharedPtr<double> u1_sln(new Solution<double>), u2_sln(new Solution<double>); Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, Hermes::vector<MeshFunctionSharedPtr<double> >(u1_sln, u2_sln)); // Visualize the solution. ScalarView view("Von Mises stress [Pa]", new WinGeom(590, 0, 700, 400)); // First Lame constant. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); // Second Lame constant. double mu = E / (2*(1 + nu)); MeshFunctionSharedPtr<double> stress(new VonMisesFilter(Hermes::vector<MeshFunctionSharedPtr<double> >(u1_sln, u2_sln), lambda, mu)); view.show_mesh(false); view.show(stress, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.5e5); // Wait for the view to be closed. View::wait(); return 0; }