Skip to content

Commit cb3969d

Browse files
committed
cleanup
Signed-off-by: Ken Museth <ken.museth@gmail.com>
1 parent e322789 commit cb3969d

File tree

1 file changed

+14
-21
lines changed
  • openvdb_cmd/vdb_tool/include

1 file changed

+14
-21
lines changed

openvdb_cmd/vdb_tool/include/Tool.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,12 @@ void Tool::scatter()
25892589

25902590
void Tool::slice()
25912591
{
2592+
struct Slices {
2593+
const std::string label;
2594+
const VecF frac;
2595+
const Vec3I axis;
2596+
Slices(const Parser &p, std::string s, int i, int j, int k) : label(s), frac(p.getVec<float>(s)), axis(i,j,k) {}
2597+
};
25922598
const std::string &name = mParser.getAction().names[0];
25932599
OPENVDB_ASSERT(name == "slice");
25942600
try {
@@ -2597,10 +2603,7 @@ void Tool::slice()
25972603
const bool keep = mParser.get<bool>("keep");
25982604
const std::string file = mParser.get<std::string>("file");
25992605
const VecI image = mParser.getVec<int>("image", "x");
2600-
const VecF X = mParser.getVec<float>("X");
2601-
const VecF Y = mParser.getVec<float>("Y");
2602-
const VecF Z = mParser.getVec<float>("Z");
2603-
2606+
std::vector<Slices> slices = {{mParser, "X", 0, 1, 2}, {mParser, "Y", 1, 0, 2}, {mParser, "Z", 2, 0, 1}};
26042607
auto it = this->getGrid(age);
26052608
GridT::Ptr grid = gridPtrCast<GridT>(*it);
26062609
if (!grid) throw std::invalid_argument("slice: no float grid with age "+std::to_string(age));
@@ -2628,7 +2631,7 @@ void Tool::slice()
26282631
Vec3R xyz;
26292632

26302633
auto mySample = [&](const auto &r, int a, int b) {
2631-
const float s = 1.0f/255.0f;
2634+
constexpr float s = 1.0f/255.0f;
26322635
Vec3R ijk = xyz;// thread local copy
26332636
auto acc = grid->getAccessor();// thread local copy
26342637
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
@@ -2642,22 +2645,12 @@ void Tool::slice()
26422645
}
26432646
};// mySample
26442647

2645-
for (float x : X) {
2646-
xyz[0] = x*(dim[0]+1) + bbox.min()[0];
2647-
tbb::parallel_for(range, [&](const auto &r){mySample(r, 1, 2);});
2648-
film.savePPM(file + "_X_" + std::to_string(x)+ ".ppm");
2649-
}
2650-
2651-
for (float y : Y) {
2652-
xyz[1] = y*(dim[1]+1) + bbox.min()[1];
2653-
tbb::parallel_for(range, [&](const auto &r){mySample(r, 0, 2);});
2654-
film.savePPM(file + "_Y_" + std::to_string(y)+ ".ppm");
2655-
}
2656-
2657-
for (float z : Z) {
2658-
xyz[2] = z*(dim[2]+1) + bbox.min()[2];
2659-
tbb::parallel_for(range, [&](const auto &r){mySample(r, 0, 1);});
2660-
film.savePPM(file + "_Z_" + std::to_string(z)+ ".ppm");
2648+
for (const Slices &s : slices) {
2649+
for (float d : s.frac) {
2650+
xyz[s.axis[0]] = d*(dim[s.axis[0]]+1) + bbox.min()[s.axis[0]];
2651+
tbb::parallel_for(range, [&](const auto &r){mySample(r, s.axis[1], s.axis[2]);});
2652+
film.savePPM(file + s.label + std::to_string(d)+ ".ppm");
2653+
}
26612654
}
26622655

26632656
if (!keep) mGrid.erase(std::next(it).base());

0 commit comments

Comments
 (0)