bool SofaCarving_test::doCarvingWithPenetration() { bool res = createScene("-0.02"); if (!res) return false; // init scene m_simu->init(m_root.get()); // get node of the mesh sofa::simulation::Node* cylinder = m_root->getChild("cylinder"); EXPECT_NE(cylinder, nullptr); // getting topology sofa::core::topology::BaseMeshTopology* topo = cylinder->getMeshTopology(); EXPECT_NE(topo, nullptr); // perform some steps for (unsigned int i = 0; i < 100; ++i) { m_simu->animate(m_root.get()); } // checking topo after carving EXPECT_LT(topo->getNbPoints(), 510); EXPECT_LT(topo->getNbEdges(), 3119); EXPECT_LT(topo->getNbTriangles(), 5040); EXPECT_LT(topo->getNbTetrahedra(), 2430); return true; }
bool SofaCarving_test::ManagerInit() { bool res = createScene("0.0"); if (!res) return false; // init scene m_simu->init(m_root.get()); // get node of the mesh sofa::simulation::Node* cylinder = m_root->getChild("cylinder"); EXPECT_NE(cylinder, nullptr); // getting topology sofa::core::topology::BaseMeshTopology* topo = cylinder->getMeshTopology(); EXPECT_NE(topo, nullptr); // checking topo at start EXPECT_EQ(topo->getNbPoints(), 510); EXPECT_EQ(topo->getNbEdges(), 3119); EXPECT_EQ(topo->getNbTriangles(), 5040); EXPECT_EQ(topo->getNbTetrahedra(), 2430); return res; }
void BaseGUI::configureGUI(sofa::simulation::Node::SPtr groot) { sofa::component::configurationsetting::SofaDefaultPathSetting *defaultPath; groot->get(defaultPath, sofa::core::objectmodel::BaseContext::SearchRoot); if (defaultPath) { if (!defaultPath->recordPath.getValue().empty()) { setRecordPath(defaultPath->recordPath.getValue()); } if (!defaultPath->gnuplotPath.getValue().empty()) setGnuplotPath(defaultPath->gnuplotPath.getValue()); } //Background sofa::component::configurationsetting::BackgroundSetting *background; groot->get(background, sofa::core::objectmodel::BaseContext::SearchRoot); if (background) { if (background->image.getValue().empty()) setBackgroundColor(background->color.getValue()); else setBackgroundImage(background->image.getFullPath()); } //Stats sofa::component::configurationsetting::StatsSetting *stats; groot->get(stats, sofa::core::objectmodel::BaseContext::SearchRoot); if (stats) { setDumpState(stats->dumpState.getValue()); setLogTime(stats->logTime.getValue()); setExportState(stats->exportState.getValue()); #ifdef SOFA_DUMP_VISITOR_INFO setTraceVisitors(stats->traceVisitors.getValue()); #endif } //Viewer Dimension TODO in viewer ! sofa::component::configurationsetting::ViewerSetting *viewerConf; groot->get(viewerConf, sofa::core::objectmodel::BaseContext::SearchRoot); if (viewerConf) setViewerConfiguration(viewerConf); //TODO: Video Recorder Configuration //Mouse Manager using ConfigurationSetting component... sofa::helper::vector< sofa::component::configurationsetting::MouseButtonSetting*> mouseConfiguration; groot->get<sofa::component::configurationsetting::MouseButtonSetting>(&mouseConfiguration, sofa::core::objectmodel::BaseContext::SearchRoot); for (unsigned int i=0; i<mouseConfiguration.size(); ++i) setMouseButtonConfiguration(mouseConfiguration[i]); }
void SetUp() { std::string scene = "<Node name='root' gravity='0 -9.81 0'>" "<DefaultAnimationLoop/>" "<Node name='node'>" "<EulerImplicit rayleighStiffness='0' printLog='false' rayleighMass='0.1'/>" "<CGLinearSolver iterations='100' threshold='0.00000001' " "tolerance='1e-5'/>" "<MeshGmshLoader name='loader' filename='mesh/smCube27.msh' " "createSubelements='true' />" "<MechanicalObject template='Rigid3d' src='@loader' name='MO' />" "<Monitor template='Rigid3d' name='monitor' listening='1' indices='0' " "ExportPositions='true' ExportVelocities='true' ExportForces='true' />" "<UniformMass totalmass='1' />" "</Node>" "</Node>"; root = SceneLoaderXML::loadFromMemory("MonitorTest", scene.c_str(), scene.size()); root->init(sofa::core::ExecParams::defaultInstance()); std::string s = "/node/monitor"; Monitor<Rigid3Types>* ptr = NULL; ptr = root->get<Monitor<Rigid3Types> >(s); EXPECT_FALSE(ptr == NULL); monitor = reinterpret_cast<MonitorTest*>(ptr); EXPECT_FALSE(monitor == 0); root->get<MechanicalObject<Rigid3Types> >(mo, "/node/MO"); EXPECT_FALSE(mo == 0); }
void testModif() { std::string str_x = "# Gnuplot File : positions of 1 particle(s) Monitored\n# 1st Column : " "time, others : particle(s) number 0 \n1 -3.5 -12.4182 -3.5 0 0 " "0 1 \n2 -3.5 -29.4438 -3.5 0 0 0 1 \n3 -3.5 -53.8398 " "-3.5 0 0 0 1 \n4 -3.5 -84.9362 -3.5 0 0 0 1 \n5 -3.5 " "-122.124 -3.5 0 0 0 1 \n6 -3.5 -164.849 -3.5 0 0 0 1 " "\n7 " "-3.5 -212.608 -3.5 0 0 0 1 \n8 -3.5 -264.944 -3.5 0 0 0 " "1 " "\n9 -3.5 -321.44 -3.5 0 0 0 1 \n10 -3.5 -381.718 -3.5 0 0 " "0 1 \n"; std::string str_f = "# Gnuplot File : forces of 1 particle(s) Monitored\n# 1st Column : " "time, others : particle(s) number 0 \n1 0 -0.363333 0 0 0 " "0 " "\n2 0 -0.363333 0 0 0 0 \n3 0 -0.363333 0 0 0 0 " "\n4 " "0 -0.363333 0 0 0 0 \n5 0 -0.363333 0 0 0 0 \n6 0 " "-0.363333 0 0 0 0 \n7 0 -0.363333 0 0 0 0 \n8 0 " "-0.363333 0 0 0 0 \n9 0 -0.363333 0 0 0 0 \n10 0 " "-0.363333 0 0 0 0 \n"; std::string str_v = "# Gnuplot File : velocities of 1 particle(s) Monitored\n# 1st Column " ": time, others : particle(s) number 0 \n1 0 -8.91818 0 0 0 " "0 " "\n2 0 -17.0256 0 0 0 0 \n3 0 -24.396 0 0 0 0 " "\n4 " "0 -31.0964 0 0 0 0 \n5 0 -37.1876 0 0 0 0 \n6 0 " "-42.7251 0 0 0 0 \n7 0 -47.7592 0 0 0 0 \n8 0 " "-52.3356 0 0 0 0 \n9 0 -56.496 0 0 0 0 \n10 0 " "-60.2782 0 0 0 0 \n"; // make a few steps before checkinf if values are correctly updated in // Monitor for (int i = 0; i < 10; ++i) simulation::getSimulation()->animate(root.get(), 1.0); monitor->testModif(mo.get()); std::string s_x = readWholeFile(monitor->d_fileName.getFullPath() + "_x.txt"); std::string s_f = readWholeFile(monitor->d_fileName.getFullPath() + "_f.txt"); std::string s_v = readWholeFile(monitor->d_fileName.getFullPath() + "_v.txt"); EXPECT_EQ(s_x, str_x); EXPECT_EQ(s_f, str_f); EXPECT_EQ(s_v, str_v); std::remove(std::string(monitor->d_fileName.getFullPath() + "_x.txt").c_str()); std::remove(std::string(monitor->d_fileName.getFullPath() + "_f.txt").c_str()); std::remove(std::string(monitor->d_fileName.getFullPath() + "_v.txt").c_str()); }
bool SofaCarving_test::createScene(const std::string& carvingDistance) { sofa::component::initComponentBase(); sofa::component::initComponentCommon(); sofa::component::initComponentGeneral(); sofa::component::initComponentAdvanced(); sofa::component::initComponentMisc(); m_simu = createSimulation("DAG"); m_root = createRootNode(m_simu, "root"); // set scene variables m_root->setGravity(sofa::defaulttype::Vector3(0.0, 0.0, -0.9)); m_root->setDt(0.01); // create collision pipeline createObject(m_root, "CollisionPipeline", { { "name","Collision Pipeline" } }); createObject(m_root, "BruteForceDetection", { { "name","Detection" } }); createObject(m_root, "CollisionResponse", { { "name", "Contact Manager" }, { "response", "default" } }); createObject(m_root, "MinProximityIntersection", { { "name","Proximity" }, { "alarmDistance", "0.5" }, { "contactDistance", "0.05" } }); // create solver createObject(m_root, "EulerImplicitSolver", { { "name","Euler Implicit" }, { "rayleighStiffness","0.1" }, { "rayleighMass", "0.1" } }); createObject(m_root, "CGLinearSolver", { { "name","Conjugate Gradient" }, { "iterations","25" }, { "threshold", "0.000000001" }, { "tolerance", "0.000000001" } }); // create carving createObject(m_root, "CarvingManager", { { "name","Carving Manager" }, { "active","1" }, { "carvingDistance", carvingDistance } } ); // create cylinder object Node::SPtr nodeVolume = createChild(m_root, "cylinder"); createObject(nodeVolume, "MeshGmshLoader", { { "name","loader" }, { "filename", sofa::helper::system::DataRepository.getFile("mesh/cylinder.msh") } }); createObject(nodeVolume, "MechanicalObject", { { "name","Volume" }, { "template","Vec3" }, { "src", "@loader" } }); createObject(nodeVolume, "TetrahedronSetTopologyContainer", { { "name","Container" }, { "src", "@loader" } }); createObject(nodeVolume, "TetrahedronSetTopologyModifier", { { "name","Modifier" } }); createObject(nodeVolume, "TetrahedronSetTopologyAlgorithms", { { "name","TopoAlgo" }, { "template", "Vec3" } }); createObject(nodeVolume, "TetrahedronSetGeometryAlgorithms", { { "name","GeomAlgo" }, { "template", "Vec3" } }); createObject(nodeVolume, "DiagonalMass", { { "name", "mass" }, { "massDensity", "0.01" } }); createObject(nodeVolume, "BoxROI", { { "name", "ROI1" }, { "template", "Vec3" }, { "box", "-1 -1 -1 1 1 0.01" } }); createObject(nodeVolume, "FixedConstraint", { { "name", "FIX1" }, { "indices", "@ROI1.indices" } }); createObject(nodeVolume, "TetrahedralCorotationalFEMForceField", { { "name", "CFEM" }, { "poissonRatio", "0.3" }, { "method", "large" }, { "youngModulus", "300" } }); // create cylinder surface Node::SPtr nodeSurface = createChild(nodeVolume, "Surface"); createObject(nodeSurface, "TriangleSetTopologyContainer", { { "name","Container" } }); createObject(nodeSurface, "TriangleSetTopologyModifier", { { "name","Modifier" } }); createObject(nodeSurface, "TriangleSetTopologyAlgorithms", { { "name","TopoAlgo" }, { "template", "Vec3" } }); createObject(nodeSurface, "TriangleSetGeometryAlgorithms", { { "name","GeomAlgo" }, { "template", "Vec3" } }); createObject(nodeSurface, "Tetra2TriangleTopologicalMapping", { { "name","topoMap" }, { "input", "@../Container" }, { "output", "@Container" } }); createObject(nodeSurface, "TriangleSet", { { "name", "Triangle Model" }, { "tags", "CarvingSurface" }, { "group", "0" } }); createObject(nodeSurface, "PointSet", { { "name", "Point Model" }, { "tags", "CarvingSurface" }, { "group", "0" } }); // create carving Node Node::SPtr nodeCarv = createChild(m_root, "carvingElement"); createObject(nodeCarv, "MechanicalObject", { { "name","Particles" }, { "template","Vec3" }, { "position", "0 0 1.0" }, { "velocity", "0 0 0" } }); createObject(nodeCarv, "UniformMass", { { "name","Mass" }, { "totalMass", "1.0" } }); createObject(nodeCarv, "SphereModel", { { "name", "Sphere Model" }, { "radius", "0.02" }, { "tags", "CarvingTool" }, { "group", "1" } }); return true; }