Guest User

Untitled

a guest
Dec 13th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using namespace imstk;
  2.  
  3. ///
  4. /// \brief imstk hello world example
  5. ///  Creates and visualizes a simple elastic object constrained at certain points
  6. ///
  7. int main()
  8. {
  9.    // Create the simulation manager
  10.    auto sdk = std::make_shared<SimulationManager>();
  11.  
  12.    // Create imstk scene
  13.    auto scene = sdk->createNewScene("HelloWorld");
  14.  
  15.    // Load a sample volumetric mesh
  16.    auto volTetMesh = std::dynamic_pointer_cast<TetrahedralMesh>
  17. (MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg"));
  18.  
  19.    // Create a surface mesh for display purposes that is extracted from loaded volume mesh
  20.    auto surfMesh = std::make_shared<SurfaceMesh>();
  21.    volTetMesh->extractSurfaceMesh(surfMesh, true);
  22.  
  23.    // Create a visual model
  24.    auto surfMeshModel = std::make_shared<VisualModel>(surfMesh);
  25.  
  26.    // Construct a map that relates volumetric and surface mesh
  27.  
  28.    // Construct one to one nodal map based on the above meshes
  29.    auto oneToOneNodalMap = std::make_shared<OneToOneMap>();
  30.    oneToOneNodalMap->setMaster(volTetMesh);
  31.    oneToOneNodalMap->setSlave(surfMesh);
  32.    oneToOneNodalMap->compute();
  33.  
  34.    // Create a deformable object
  35.    auto deformableObj = std::make_shared<PbdObject>("PBDobject");
  36.    auto pbdModel = std::make_shared<PbdModel>();
  37.    pbdModel->setModelGeometry(volTetMesh);
  38.   
  39.    // configure the physics model
  40.    pbdModel->configure(/*Number of Constraints*/ 1,
  41.                        /*Constraint configuration*/ "FEM StVk 100.0 0.3",
  42.                        /*Mass*/ 1.0,
  43.                        /*Gravity*/ "0 -9.8 0",
  44.                        /*TimeStep*/ 0.01,
  45.                        /*FixedPoint*/ "51 127 178",
  46.                        /*NumberOfIterationInConstraintSolver*/ 5);
  47.  
  48.    // Configure the deformable body
  49.    deformableObj->setDynamicalModel(pbdModel); // set the physics model
  50.    deformableObj->addVisualModel(surfMeshModel); // set the geometry to be used for rendering
  51.    deformableObj->setPhysicsGeometry(volTetMesh); // set the geometry to be used for physics
  52.    deformableObj->setPhysicsToVisualMap(oneToOneNodalMap); // assign the computed map
  53.    deformableObj->setPbdModel(pbdModel);
  54.  
  55.    auto pbdSolver = std::make_shared<PbdSolver>();
  56.    pbdSolver->setPbdObject(deformableObj);
  57.   
  58.    scene->addNonlinearSolver(pbdSolver);
  59.    scene->addSceneObject(deformableObj);
  60.  
  61.    // Light
  62.    scene->addLight(std::make_shared<DirectionalLight>("light"));
  63.  
  64.    // Run the scene
  65.    sdk->setActiveScene(scene);
  66.    sdk->startSimulation();
  67.  
  68.    return 0;
  69. }
Add Comment
Please, Sign In to add comment