-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from squarefk/ampm
2D/3D level set/dynamic level set for MPM
- Loading branch information
Showing
17 changed files
with
479 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/******************************************************************************* | ||
Taichi - Physically based Computer Graphics Library | ||
Copyright (c) 2017 Yu Fang <squarefk@gmail.com> | ||
All rights reserved. Use of this source code is governed by | ||
the MIT license as written in the LICENSE file. | ||
*******************************************************************************/ | ||
|
||
#include "dynamic_levelset_2d.h" | ||
|
||
TC_NAMESPACE_BEGIN | ||
|
||
void DynamicLevelSet2D::initialize(real _t0, real _t1, const LevelSet2D &_ls0, const LevelSet2D &_ls1) { | ||
t0 = _t0; | ||
t1 = _t1; | ||
levelset0 = std::make_shared<LevelSet2D>(_ls0); | ||
levelset1 = std::make_shared<LevelSet2D>(_ls1); | ||
} | ||
|
||
Vector2 DynamicLevelSet2D::get_spatial_gradient(const Vector2 &pos, real t) const { | ||
Vector2 gxy0 = levelset0->get_gradient(pos); | ||
Vector2 gxy1 = levelset1->get_gradient(pos); | ||
real gx = lerp((t - t0) / (t1 - t0), gxy0.x, gxy1.x); | ||
real gy = lerp((t - t0) / (t1 - t0), gxy0.y, gxy1.y); | ||
Vector2 gradient = Vector2(gx, gy); | ||
if (length(gradient) < 1e-10f) | ||
return Vector2(1, 0); | ||
else | ||
return normalize(gradient); | ||
} | ||
|
||
real DynamicLevelSet2D::get_temporal_derivative(const Vector2 &pos, real t) const { | ||
real l1 = levelset0->get(pos); | ||
real l0 = levelset1->get(pos); | ||
return (l1 - l0) / (t1 - t0); | ||
} | ||
|
||
real DynamicLevelSet2D::sample(const Vector2 &pos, real t) const { | ||
real l1 = levelset0->sample(pos); | ||
real l2 = levelset1->sample(pos); | ||
return lerp((t - t0) / (t1 - t0), l1, l2); | ||
} | ||
|
||
Array2D<real> DynamicLevelSet2D::rasterize(int width, int height, real t) { | ||
Array2D<real> r0 = levelset0->rasterize(width, height); | ||
Array2D<real> r1 = levelset1->rasterize(width, height); | ||
Array2D<real> out(width, height); | ||
for (auto &ind : Region2D(0, width, 0, height, Vector2(0.5f, 0.5f))) { | ||
out[ind] = lerp((t - t0) / (t1 - t0), r0[ind], r1[ind]); | ||
if (std::isnan(out[ind])) { | ||
out[ind] = std::numeric_limits<real>::infinity(); | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
|
||
TC_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
Taichi - Physically based Computer Graphics Library | ||
Copyright (c) 2017 Yu Fang <squarefk@gmail.com> | ||
All rights reserved. Use of this source code is governed by | ||
the MIT license as written in the LICENSE file. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
|
||
#include <limits> | ||
#include <memory> | ||
#include <taichi/math/levelset_2d.h> | ||
|
||
|
||
TC_NAMESPACE_BEGIN | ||
|
||
class DynamicLevelSet2D { | ||
public: | ||
real t0, t1; | ||
std::shared_ptr<LevelSet2D> levelset0, levelset1; | ||
|
||
void initialize(real _t0, real _t1, const LevelSet2D &_ls0, const LevelSet2D &_ls1); | ||
|
||
Vector2 get_spatial_gradient(const Vector2 &pos, real t) const; | ||
|
||
real get_temporal_derivative(const Vector2 &pos, real t) const; | ||
|
||
real sample(const Vector2 &pos, real t) const; | ||
|
||
Array2D<real> rasterize(int width, int height, real t); | ||
}; | ||
|
||
TC_NAMESPACE_END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
Taichi - Physically based Computer Graphics Library | ||
Copyright (c) 2017 Yu Fang <squarefk@gmail.com> | ||
All rights reserved. Use of this source code is governed by | ||
the MIT license as written in the LICENSE file. | ||
*******************************************************************************/ | ||
|
||
#include "dynamic_levelset_3d.h" | ||
|
||
TC_NAMESPACE_BEGIN | ||
|
||
void DynamicLevelSet3D::initialize(real _t0, real _t1, const LevelSet3D &_ls0, const LevelSet3D &_ls1) { | ||
t0 = _t0; | ||
t1 = _t1; | ||
levelset0 = std::make_shared<LevelSet3D>(_ls0); | ||
levelset1 = std::make_shared<LevelSet3D>(_ls1); | ||
} | ||
|
||
Vector3 DynamicLevelSet3D::get_spatial_gradient(const Vector3 &pos, real t) const { | ||
Vector3 gxyz0 = levelset0->get_gradient(pos); | ||
Vector3 gxyz1 = levelset1->get_gradient(pos); | ||
real gx = lerp((t - t0) / (t1 - t0), gxyz0.x, gxyz1.x); | ||
real gy = lerp((t - t0) / (t1 - t0), gxyz0.y, gxyz1.y); | ||
real gz = lerp((t - t0) / (t1 - t0), gxyz0.z, gxyz1.z); | ||
Vector3 gradient = Vector3(gx, gy, gz); | ||
if (length(gradient) < 1e-10f) | ||
return Vector3(1, 0, 0); | ||
else | ||
return normalize(gradient); | ||
} | ||
|
||
real DynamicLevelSet3D::get_temporal_derivative(const Vector3 &pos, real t) const { | ||
real l0 = levelset0->get(pos); | ||
real l1 = levelset1->get(pos); | ||
return (l1 - l0) / (t1 - t0); | ||
} | ||
|
||
real DynamicLevelSet3D::sample(const Vector3 &pos, real t) const { | ||
real l1 = levelset0->get(pos); | ||
real l2 = levelset1->get(pos); | ||
return lerp((t - t0) / (t1 - t0), l1, l2); | ||
} | ||
|
||
Array3D<real> DynamicLevelSet3D::rasterize(int width, int height, int depth, real t) { | ||
Array3D<real> r0 = levelset0->rasterize(width, height, depth); | ||
Array3D<real> r1 = levelset1->rasterize(width, height, depth); | ||
Array3D<real> out(width, height, width); | ||
for (auto &ind : Region3D(0, width, 0, height, 0, depth, Vector3(0.5f, 0.5f, 0.5f))) { | ||
out[ind] = lerp((t - t0) / (t1 - t0), r0[ind], r1[ind]); | ||
if (std::isnan(out[ind])) { | ||
out[ind] = std::numeric_limits<real>::infinity(); | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
|
||
TC_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
Taichi - Physically based Computer Graphics Library | ||
Copyright (c) 2017 Yu Fang <squarefk@gmail.com> | ||
All rights reserved. Use of this source code is governed by | ||
the MIT license as written in the LICENSE file. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
|
||
#include <limits> | ||
#include <memory> | ||
#include <taichi/math/levelset_3d.h> | ||
|
||
|
||
TC_NAMESPACE_BEGIN | ||
|
||
class DynamicLevelSet3D { | ||
public: | ||
real t0, t1; | ||
std::shared_ptr<LevelSet3D> levelset0, levelset1; | ||
|
||
void initialize(real _t0, real _t1, const LevelSet3D &_ls0, const LevelSet3D &_ls1); | ||
|
||
Vector3 get_spatial_gradient(const Vector3 &pos, real t) const; | ||
|
||
real get_temporal_derivative(const Vector3 &pos, real t) const; | ||
|
||
real sample(const Vector3 &pos, real t) const; | ||
|
||
Array3D<real> rasterize(int width, int height, int depth, real t); | ||
}; | ||
|
||
TC_NAMESPACE_END | ||
|
Oops, something went wrong.