-
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.
- Loading branch information
fangy14
committed
Apr 6, 2017
1 parent
1d8c85b
commit e151d37
Showing
4 changed files
with
108 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
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) { | ||
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); | ||
return Vector2(gx, gy); | ||
} | ||
|
||
real DynamicLevelSet2D::get_temporal_gradient(const Vector2 &pos, real t) { | ||
real l1 = levelset0->get(pos); | ||
real l2 = levelset1->get(pos); | ||
return (l2 - l1) / (t1 - t0); | ||
} | ||
|
||
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,35 @@ | ||
/******************************************************************************* | ||
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); | ||
|
||
real get_temporal_gradient(const Vector2 &pos, real t); | ||
|
||
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
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