Skip to content

Commit 132a032

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

File tree

1 file changed

+27
-30
lines changed
  • openvdb_cmd/vdb_tool/include

1 file changed

+27
-30
lines changed

openvdb_cmd/vdb_tool/include/Tool.h

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,11 +2589,12 @@ void Tool::scatter()
25892589

25902590
void Tool::slice()
25912591
{
2592-
struct Slices {
2592+
using RangeT = tbb::blocked_range2d<int>;
2593+
struct Axis {
25932594
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) {}
2595+
const VecF slices;
2596+
const Vec3I abc;// indics of the three axis
2597+
Axis(const Parser &p, std::string s, int i, int j, int k) : label(s), slices(p.getVec<float>(s)), abc(i,j,k) {}
25972598
};
25982599
const std::string &name = mParser.getAction().names[0];
25992600
OPENVDB_ASSERT(name == "slice");
@@ -2603,7 +2604,8 @@ void Tool::slice()
26032604
const bool keep = mParser.get<bool>("keep");
26042605
const std::string file = mParser.get<std::string>("file");
26052606
const VecI image = mParser.getVec<int>("image", "x");
2606-
std::vector<Slices> slices = {{mParser, "X", 0, 1, 2}, {mParser, "Y", 1, 0, 2}, {mParser, "Z", 2, 0, 1}};
2607+
std::vector<Axis> axes = {{mParser, "X", 0, 1, 2}, {mParser, "Y", 1, 0, 2}, {mParser, "Z", 2, 0, 1}};
2608+
26072609
auto it = this->getGrid(age);
26082610
GridT::Ptr grid = gridPtrCast<GridT>(*it);
26092611
if (!grid) throw std::invalid_argument("slice: no float grid with age "+std::to_string(age));
@@ -2627,31 +2629,26 @@ void Tool::slice()
26272629
}
26282630

26292631
tools::Film film(image[0], image[1]);
2630-
const tbb::blocked_range2d<int> range(0, image[0], 0 , image[1]);
2631-
Vec3R xyz;
2632-
2633-
auto mySample = [&](const auto &r, int a, int b) {
2634-
constexpr float s = 1.0f/255.0f;
2635-
Vec3R ijk = xyz;// thread local copy
2636-
auto acc = grid->getAccessor();// thread local copy
2637-
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
2638-
ijk[a] = i/float(image[0])*(dim[a]+1) + bbox.min()[a];
2639-
for (int j=r.cols().begin(); j<r.cols().end(); ++j) {
2640-
ijk[b] = j/float(image[1])*(dim[b]+1) + bbox.min()[b];
2641-
const float v = tools::BoxSampler::sample(acc, ijk);
2642-
const uint8_t n = uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()));
2643-
film.pixel(i,j) = tools::Film::RGBA(s*LUT[n][0], s*LUT[n][1], s*LUT[n][2]);
2644-
}
2645-
}
2646-
};// mySample
2647-
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-
}
2654-
}
2632+
for (const Axis &axis : axes) {
2633+
for (const float slice : axis.slices) {
2634+
tbb::parallel_for(RangeT(0, image[0], 0, image[1]), [&](const auto &range){
2635+
const int a = axis.abc[0], b = axis.abc[1], c = axis.abc[2];
2636+
Vec3R xyz;
2637+
xyz[a] = slice * (dim[a]+1) + bbox.min()[a];
2638+
auto acc = grid->getAccessor();// thread local copy
2639+
for (auto row=range.rows().begin(); row!=range.rows().end(); ++row) {
2640+
xyz[b] = row/float(image[0])*(dim[b]+1) + bbox.min()[b];
2641+
for (int col=range.cols().begin(); col<range.cols().end(); ++col) {
2642+
xyz[c] = col/float(image[1])*(dim[c]+1) + bbox.min()[c];
2643+
const float v = tools::BoxSampler::sample(acc, xyz);
2644+
const unsigned char *p = LUT[uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()))];
2645+
film.pixel(row,col) = tools::Film::RGBA(p[0]/255.0f, p[1]/255.0f, p[2]/255.0f);
2646+
}// loop over colums in image
2647+
}// loop over rows in image
2648+
});// end parallel_for
2649+
film.savePPM(file + axis.label + std::to_string(slice)+ ".ppm");
2650+
}// loop over slices withing an axis (singular)
2651+
}// loop over axes (plural)
26552652

26562653
if (!keep) mGrid.erase(std::next(it).base());
26572654
if (mParser.verbose) mTimer.stop();

0 commit comments

Comments
 (0)