-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecay.cpp
More file actions
61 lines (50 loc) · 1.89 KB
/
Copy pathDecay.cpp
File metadata and controls
61 lines (50 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Decay.hpp"
#include "VolumeNodeGridType.hpp"
#include "MeshNode.hpp"
#include <openvdb/openvdb.h>
#include <openvdb/tools/ValueTransformer.h>
#include <openvdb/tree/ValueAccessor.h>
using namespace std;
using namespace ci;
using namespace ci::gl;
using namespace openvdb::tools;
using namespace openvdb::tree;
class DecayOperation {
PreparedGrid& input;
VolumeNodeGridType::ConstAccessor accessor;
std::mt19937& generator;
std::uniform_real_distribution<double>& decayJitter;
public:
DecayOperation(PreparedGrid& input,
std::mt19937& generator,
std::uniform_real_distribution<double>& decayJitter) :
input(input),
accessor(input.grid.getConstAccessor()),
generator(generator),
decayJitter(decayJitter) { }
inline void operator()(const VolumeNodeGridType::ValueOnIter& iterator) const {
auto coord = iterator.getCoord();
// auto value = iterator.getValue();
auto value = accessor.getValue(coord);
const double boundY = input.params.volumeBounds.y * input.params.densityPerUnit;
auto decay = ((boundY - coord.y()) / boundY) * input.params.decayMultiplier *
decayJitter(generator);
value.life -= decay;
auto xScale = input.params.volumeBounds.x * input.params.densityPerUnit;
auto yScale = input.params.volumeBounds.y * input.params.densityPerUnit;
auto t = coord.y() / yScale;
value.color = Color(value.color.r, coord.x() / xScale, t);
if (value.life < input.params.gridBackgroundValue) {
iterator.setActiveState(false);
} else {
iterator.setValue(value);
}
}
};
PreparedGrid Decay::process(PreparedGrid& input) {
foreach(input.grid.beginValueOn(), DecayOperation(input, generator, decayJitter));
return PreparedGrid {
.grid = input.grid,
.params = input.params
};
}