7 #include "imstkCamera.h" 8 #include "imstkDirectionalLight.h" 9 #include "imstkKeyboardDeviceClient.h" 10 #include "imstkKeyboardSceneControl.h" 11 #include "imstkMeshIO.h" 12 #include "imstkMouseDeviceClient.h" 13 #include "imstkMouseSceneControl.h" 15 #include "imstkRenderMaterial.h" 16 #include "imstkScene.h" 17 #include "imstkSceneManager.h" 18 #include "imstkSignedDistanceField.h" 19 #include "imstkSimulationManager.h" 20 #include "imstkSimulationUtils.h" 21 #include "imstkSphModel.h" 22 #include "imstkSphObject.h" 23 #include "imstkSphObjectCollision.h" 24 #include "imstkSurfaceMesh.h" 25 #include "imstkSurfaceMeshDistanceTransform.h" 26 #include "imstkViewer.h" 27 #include "imstkVisualModel.h" 28 #include "imstkVTKViewer.h" 30 using namespace imstk;
35 std::shared_ptr<VecDataArray<double, 3>>
36 generateBoxShapeFluid(
const double particleRadius,
const Vec3d& boxCenter,
const Vec3d& boxSize)
40 boxCenter.x() - boxSize.x() * 0.5,
41 boxCenter.x() + boxSize.x() * 0.5,
42 boxCenter.y() - boxSize.y() * 0.5,
43 boxCenter.y() + boxSize.y() * 0.5,
44 boxCenter.z() - boxSize.z() * 0.5,
45 boxCenter.z() + boxSize.z() * 0.5
48 const double spacing = 2.0 * particleRadius;
50 static_cast<int>(boxSize.x() / spacing),
51 static_cast<int>(boxSize.y() / spacing),
52 static_cast<int>(boxSize.z() / spacing)
56 particles->reserve(dim[0] * dim[1] * dim[2]);
58 for (
double z = bounds[4]; z < bounds[5]; z += spacing)
60 for (
double y = bounds[2]; y < bounds[3]; y += spacing)
62 for (
double x = bounds[0]; x < bounds[1]; x += spacing)
64 particles->push_back(Vec3d(x, y, z));
72 std::shared_ptr<SphObject>
73 makeSPHBoxObject(
const std::string& name,
const double particleRadius,
const Vec3d& boxShift,
const Vec3d& boxSize)
79 std::shared_ptr<VecDataArray<double, 3>> particles = generateBoxShapeFluid(particleRadius, boxShift, boxSize);
80 LOG(INFO) <<
"Number of particles: " << particles->size();
86 sphParams->m_bNormalizeDensity =
true;
87 sphParams->m_kernelOverParticleRadiusRatio = 6.0;
89 sphParams->m_surfaceTensionStiffness = 5.0;
90 sphParams->m_gravity = Vec3d(0.0, -70.0, 0.0);
100 fluidVisualModel->setGeometry(fluidGeometry);
103 fluidMaterial->setVertexColor(Color::Orange);
104 fluidMaterial->setPointSize(particleRadius);
108 fluidObj->addVisualModel(fluidVisualModel);
109 fluidObj->setCollidingGeometry(fluidGeometry);
110 fluidObj->setDynamicalModel(sphModel);
111 fluidObj->setPhysicsGeometry(fluidGeometry);
116 static std::shared_ptr<CollidingObject>
117 makeDragonCollidingObject(
const std::string& name,
const Vec3d& position)
123 auto dragonSurfMesh = MeshIO::read<SurfaceMesh>(iMSTK_DATA_ROOT
"/asianDragon/asianDragon.obj");
124 dragonSurfMesh->translate(position, Geometry::TransformType::ApplyToData);
128 computeSdf->setDimensions(100, 100, 100);
133 material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
135 surfMeshModel->setGeometry(dragonSurfMesh);
139 collidingObj->addVisualModel(surfMeshModel);
140 collidingObj->setCollidingGeometry(std::make_shared<SignedDistanceField>(computeSdf->getOutputImage()));
159 scene->getActiveCamera()->setPosition(0, 2.0, 15.0);
162 std::shared_ptr<CollidingObject> dragonObj = makeDragonCollidingObject(
"Dragon", Vec3d(0.0, 0.0, 0.0));
163 scene->addSceneObject(dragonObj);
166 std::shared_ptr<SphObject> sphFluidBox = makeSPHBoxObject(
"Box", 0.1, Vec3d(0.0, 7.0, 0.0), Vec3d(3.0, 7.0, 3.0));
167 scene->addSceneObject(sphFluidBox);
170 scene->addInteraction(
171 std::make_shared<SphObjectCollision>(sphFluidBox, dragonObj));
177 scene->addLight(
"light", light);
189 sceneManager->setActiveScene(scene);
190 sceneManager->pause();
198 std::shared_ptr<Entity> mouseAndKeyControls =
199 SimulationUtils::createDefaultSceneControl(driver);
200 scene->addSceneObject(mouseAndKeyControls);
void initialize(std::shared_ptr< VecDataArray< double, 3 >> positions)
Initializes the data structure given vertex positions.
void setDesiredDt(const double dt)
Sets the target fixed timestep (may violate), seconds This ultimately effects the number of iteration...
void setActiveScene(std::shared_ptr< Scene > scene) override
Set scene to be rendered.
void configure(const std::shared_ptr< SphModelConfig > ¶ms)
Set simulation parameters.
Renders a set of points using a screen-space fluid renderer.
virtual void setTimeStepSizeType(const TimeSteppingType type)
Get/Set the type of approach used to update the time step size after every frame. ...
void addModule(std::shared_ptr< Module > module) override
Add a module to run.
virtual void setBackgroundColors(const Color color1, const Color color2=Color(0.0, 0.0, 0.0), const bool gradientBackground=false) override
Set the coloring of the screen background If 'gradientBackground' is false or not supplied color1 wil...
void setIntensity(const double intensity)
Set the light intensity. This value is unbounded.
std::shared_ptr<T> obj = std::make_shared<T>(); equivalent, convenience class for STL shared allocati...
void update()
Do the actual algorithm.
void setModelGeometry(std::shared_ptr< Geometry > geometry)
Sets the model geometry.
void setRenderMaterial(std::shared_ptr< RenderMaterial > renderMaterial)
Set/Get render material.
void setDirection(const Vec3d &dir)
Set the direction of the light.
static LoggerG3 & startLogger()
Starts logger with default sinks, use getInstance to create a logger with no sinks.
void setInputMesh(std::shared_ptr< SurfaceMesh > surfMesh)
Required input, port 0.