7 #include "imstkPointSet.h" 8 #include "imstkRenderMaterial.h" 9 #include "imstkScene.h" 10 #include "imstkSphObject.h" 11 #include "imstkSphModel.h" 12 #include "imstkVisualModel.h" 14 using namespace imstk;
19 std::shared_ptr<VecDataArray<double, 3>>
20 generateSphereShapeFluid(
const double particleRadius)
22 const double sphereRadius = 2.0;
23 const Vec3d sphereCenter(0, 1, 0);
25 const double sphereRadiusSqr = sphereRadius * sphereRadius;
26 const double spacing = 2.0 * particleRadius;
27 const int N =
static_cast<int>(2.0 * sphereRadius / spacing);
28 const Vec3d lcorner = sphereCenter - Vec3d(sphereRadius, sphereRadius, sphereRadius);
30 std::shared_ptr<VecDataArray<double, 3>> particles = std::make_shared<VecDataArray<double, 3>>();
31 particles->reserve(N * N * N);
33 for (
int i = 0; i < N; ++i)
35 for (
int j = 0; j < N; ++j)
37 for (
int k = 0; k < N; ++k)
39 Vec3d ppos = lcorner + Vec3d(spacing * static_cast<double>(i), spacing * static_cast<double>(j), spacing * static_cast<double>(k));
40 Vec3d cx = ppos - sphereCenter;
41 if (cx.squaredNorm() < sphereRadiusSqr)
43 particles->push_back(ppos);
55 std::shared_ptr<VecDataArray<double, 3>>
56 generateBoxShapeFluid(
const double particleRadius)
58 const double boxWidth = 4.0;
59 const Vec3d boxLowerCorner(-2, -3, -2);
61 const double spacing = 2.0 * particleRadius;
62 const int N =
static_cast<int>(boxWidth / spacing);
64 std::shared_ptr<VecDataArray<double, 3>> particles = std::make_shared<VecDataArray<double, 3>>();
65 particles->reserve(N * N * N);
67 for (
int i = 0; i < N; ++i)
69 for (
int j = 0; j < N; ++j)
71 for (
int k = 0; k < N; ++k)
73 Vec3d ppos = boxLowerCorner + Vec3d(spacing * static_cast<double>(i), spacing * static_cast<double>(j), spacing * static_cast<double>(k));
74 particles->push_back(ppos);
83 std::shared_ptr<VecDataArray<double, 3>> getBunny();
85 std::shared_ptr<VecDataArray<double, 3>>
89 generateBunnyShapeFluid(
const double particleRadius)
91 LOG_IF(FATAL, (std::abs(particleRadius - 0.08) > 1e-6)) <<
"Particle radius for this scene must be 0.08";
92 std::shared_ptr<VecDataArray<double, 3>> particles = std::make_shared<VecDataArray<double, 3>>();
94 particles = getBunny();
102 std::shared_ptr<VecDataArray<double, 3>>
103 generatePipeFluid(
const double particleRadius)
105 const double pipeRadius = 1.0;
106 const double pipeLength = 5.0;
107 const Vec3d lcorner(-5.0, 5.0, 0.0);
108 const Vec3d pipeLeftCenter = lcorner + Vec3d(0.0, pipeRadius, pipeRadius);
110 const double spacing = 2.0 * particleRadius;
111 const int N_width =
static_cast<int>(2.0 * pipeRadius / spacing);
112 const int N_length =
static_cast<int>(pipeLength / spacing);
116 particles.
reserve(N_width * N_width * N_length);
118 for (
int i = 0; i < N_length; ++i)
120 for (
int j = 0; j < N_width; ++j)
122 for (
int k = 0; k < N_width; ++k)
124 Vec3d ppos = lcorner + Vec3d(spacing * static_cast<double>(i), spacing * static_cast<double>(j), spacing * static_cast<double>(k));
127 Vec3d cx = ppos - Vec3d(spacing * static_cast<double>(i), 0.0, 0.0) - pipeLeftCenter;
128 if (cx.squaredNorm() < pipeRadius)
139 std::shared_ptr<VecDataArray<double, 3>>
140 initializeNonZeroVelocities(
const int numParticles)
143 initVelocitiesPtr->fill(Vec3d(10.0, 0.0, 0.0));
144 return initVelocitiesPtr;
147 std::shared_ptr<SphObject>
148 generateFluid(
const double particleRadius)
150 std::shared_ptr<VecDataArray<double, 3>> particles = std::make_shared<VecDataArray<double, 3>>();
154 particles = generateSphereShapeFluid(particleRadius);
157 particles = generateBoxShapeFluid(particleRadius);
160 particles = generateBunnyShapeFluid(particleRadius);
163 LOG(FATAL) <<
"Invalid scene index";
166 LOG(INFO) <<
"Number of particles: " << particles->size();
177 visualModel->setGeometry(geometry);
183 material->setPointSize(0.1);
187 material->setPointSize(20.0);
188 material->setRenderPointsAsSpheres(
true);
189 material->setColor(Color::Orange);
199 sphParams->m_bNormalizeDensity =
true;
202 sphParams->m_kernelOverParticleRadiusRatio = 6.0;
203 sphParams->m_surfaceTensionStiffness = 5.0;
208 sphParams->m_frictionBoundary = 0.3;
215 fluidObj->addVisualModel(visualModel);
216 fluidObj->setCollidingGeometry(geometry);
217 fluidObj->setDynamicalModel(sphModel);
218 fluidObj->setPhysicsGeometry(geometry);
void initialize(std::shared_ptr< VecDataArray< double, 3 >> positions)
Initializes the data structure given vertex positions.
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 reserve(const int size) override
Allocates extra capacity, for the number of values, conservative reallocate.
void push_back(const ValueType &val)
Append the data array to hold the new value, resizes if neccesary.
const std::shared_ptr< T > & get() const
Returns const ref to STL smart pointer.
std::shared_ptr<T> obj = std::make_shared<T>(); equivalent, convenience class for STL shared allocati...
void setModelGeometry(std::shared_ptr< Geometry > geometry)
Sets the model geometry.
DisplayMode getDisplayMode() const
Get/Set display mode.
void setRenderMaterial(std::shared_ptr< RenderMaterial > renderMaterial)
Set/Get render material.