Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace imstk;
- ///
- /// \brief imstk hello world example
- /// Creates and visualizes a simple elastic object constrained at certain points
- ///
- int main()
- {
- // Create the simulation manager
- auto sdk = std::make_shared<SimulationManager>();
- // Create imstk scene
- auto scene = sdk->createNewScene("HelloWorld");
- // Load a sample volumetric mesh
- auto volTetMesh = std::dynamic_pointer_cast<TetrahedralMesh>
- (MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg"));
- // Create a surface mesh for display purposes that is extracted from loaded volume mesh
- auto surfMesh = std::make_shared<SurfaceMesh>();
- volTetMesh->extractSurfaceMesh(surfMesh, true);
- // Create a visual model
- auto surfMeshModel = std::make_shared<VisualModel>(surfMesh);
- // Construct a map that relates volumetric and surface mesh
- // Construct one to one nodal map based on the above meshes
- auto oneToOneNodalMap = std::make_shared<OneToOneMap>();
- oneToOneNodalMap->setMaster(volTetMesh);
- oneToOneNodalMap->setSlave(surfMesh);
- oneToOneNodalMap->compute();
- // Create a deformable object
- auto deformableObj = std::make_shared<PbdObject>("PBDobject");
- auto pbdModel = std::make_shared<PbdModel>();
- pbdModel->setModelGeometry(volTetMesh);
- // configure the physics model
- pbdModel->configure(/*Number of Constraints*/ 1,
- /*Constraint configuration*/ "FEM StVk 100.0 0.3",
- /*Mass*/ 1.0,
- /*Gravity*/ "0 -9.8 0",
- /*TimeStep*/ 0.01,
- /*FixedPoint*/ "51 127 178",
- /*NumberOfIterationInConstraintSolver*/ 5);
- // Configure the deformable body
- deformableObj->setDynamicalModel(pbdModel); // set the physics model
- deformableObj->addVisualModel(surfMeshModel); // set the geometry to be used for rendering
- deformableObj->setPhysicsGeometry(volTetMesh); // set the geometry to be used for physics
- deformableObj->setPhysicsToVisualMap(oneToOneNodalMap); // assign the computed map
- deformableObj->setPbdModel(pbdModel);
- auto pbdSolver = std::make_shared<PbdSolver>();
- pbdSolver->setPbdObject(deformableObj);
- scene->addNonlinearSolver(pbdSolver);
- scene->addSceneObject(deformableObj);
- // Light
- scene->addLight(std::make_shared<DirectionalLight>("light"));
- // Run the scene
- sdk->setActiveScene(scene);
- sdk->startSimulation();
- return 0;
- }
Add Comment
Please, Sign In to add comment