7 #include "FemurObject.h" 8 #include "imstkLevelSetModel.h" 9 #include "imstkLocalMarchingCubes.h" 10 #include "imstkMeshIO.h" 11 #include "imstkRenderMaterial.h" 12 #include "imstkSurfaceMesh.h" 13 #include "imstkTaskGraph.h" 14 #include "imstkVisualModel.h" 19 std::shared_ptr<ImageData> initLvlSetImage = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/legs/femurBoneSolid_SDF.nii")->cast(IMSTK_DOUBLE);
23 initLvlSetImage->setOrigin(Vec3d(0.0, 0.8, 1.5));
26 auto lvlSetConfig = std::make_shared<LevelSetModelConfig>();
27 lvlSetConfig->m_sparseUpdate =
true;
28 lvlSetConfig->m_substeps = 15;
33 m_isoExtract->setInputImage(initLvlSetImage);
34 m_isoExtract->setIsoValue(0.0);
35 m_isoExtract->setNumberOfChunks(Vec3i(32, 9, 9));
36 m_isoExtract->update();
38 if (m_useRandomChunkColors)
40 srand(static_cast<unsigned int>(time(NULL)));
44 auto sdf = std::make_shared<SignedDistanceField>(initLvlSetImage);
47 auto model = std::make_shared<LevelSetModel>();
48 model->setModelGeometry(sdf);
49 model->configure(lvlSetConfig);
51 setPhysicsGeometry(sdf);
52 setCollidingGeometry(sdf);
53 setDynamicalModel(model);
57 m_forwardModifiedVoxels = std::make_shared<TaskNode>(
59 m_taskGraph->addNode(m_forwardModifiedVoxels);
73 m_isoExtract->update();
83 const Vec3i& numChunks = m_isoExtract->getNumberOfChunks();
84 for (
int i = 0; i < numChunks[0] * numChunks[1] * numChunks[2]; i++)
86 auto surfMesh = std::dynamic_pointer_cast<
SurfaceMesh>(m_isoExtract->getOutput(i));
87 if (surfMesh->getNumVertices() > 0 && m_chunksGenerated.count(i) == 0)
89 auto surfMeshModel = std::make_shared<VisualModel>();
90 surfMeshModel->setGeometry(m_isoExtract->getOutput(i));
91 auto material = std::make_shared<RenderMaterial>();
92 material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
93 material->setLineWidth(4.0);
94 if (m_useRandomChunkColors)
96 const double r = (rand() % 10000) / 10000.0;
97 const double g = (rand() % 10000) / 10000.0;
98 const double b = (rand() % 10000) / 10000.0;
99 material->setColor(
Color(r, g, b));
103 material->setColor(Color::Bone);
106 surfMeshModel->setRenderMaterial(material);
107 addVisualModel(surfMeshModel);
108 m_chunksGenerated.insert(i);
117 for (
auto i : getLevelSetModel()->getNodesToUpdate())
119 m_isoExtract->setModified(std::get<0>(i.second));
127 m_taskGraph->addEdge(source, getUpdateNode());
129 m_dynamicalModel->initGraphEdges();
130 m_taskGraph->nestGraph(m_dynamicalModel->getTaskGraph(), getUpdateNode(), getUpdateGeometryNode());
134 m_taskGraph->addEdge(getLevelSetModel()->getGenerateVelocitiesEndNode(), m_forwardModifiedVoxels);
135 m_taskGraph->addEdge(m_forwardModifiedVoxels, getLevelSetModel()->getQuantityEvolveNode(0));
137 m_taskGraph->addEdge(getUpdateGeometryNode(), sink);
bool initialize() override
Initialize the scene object.
Base class for scene objects that move and/or deform under position based dynamics formulation...
This filter extracts a contour SurfaceMesh from an image given an isovalue. Users should prefer imstk...
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
void updateModifiedVoxels()
Forwards/copies the levelsets list of modified voxels to the isosurface extraction filters list of mo...
void createVisualModels()
Creates visual models for any chunk that has non-zero vertices and is not already generated...
void visualUpdate() override
Update the isosurface before rendering, the isosurface is not used for simulation so we can afford to...
void initGraphEdges()
Initializes the edges of the SceneObject's computational graph.