Skip to content

Commit e322789

Browse files
committed
cleaned up -slice implementation
Signed-off-by: Ken Museth <ken.museth@gmail.com>
1 parent f80fcb2 commit e322789

File tree

1 file changed

+23
-41
lines changed
  • openvdb_cmd/vdb_tool/include

1 file changed

+23
-41
lines changed

openvdb_cmd/vdb_tool/include/Tool.h

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,57 +2624,39 @@ void Tool::slice()
26242624
}
26252625

26262626
tools::Film film(image[0], image[1]);
2627-
const float s = 1.0f/255.0f;
2628-
26292627
const tbb::blocked_range2d<int> range(0, image[0], 0 , image[1]);
2630-
for (float x : X) {
2631-
tbb::parallel_for(range, [&](const auto &r){
2632-
Vec3R ijk(x*(dim[0]+1) + bbox.min()[0], 0, 0);
2633-
auto acc = grid->getAccessor();
2634-
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
2635-
ijk[1] = i/float(image[0])*(dim[1]+1) + bbox.min()[1];
2636-
for (int j=r.cols().begin(); j<r.cols().end(); ++j) {
2637-
ijk[2] = j/float(image[1])*(dim[2]+1) + bbox.min()[2];
2638-
const float v = tools::BoxSampler::sample(acc, ijk);
2639-
const uint8_t n = uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()));
2640-
film.pixel(i,j) = tools::Film::RGBA(s*LUT[n][0], s*LUT[n][1], s*LUT[n][2]);
2641-
}
2628+
Vec3R xyz;
2629+
2630+
auto mySample = [&](const auto &r, int a, int b) {
2631+
const float s = 1.0f/255.0f;
2632+
Vec3R ijk = xyz;// thread local copy
2633+
auto acc = grid->getAccessor();// thread local copy
2634+
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
2635+
ijk[a] = i/float(image[0])*(dim[a]+1) + bbox.min()[a];
2636+
for (int j=r.cols().begin(); j<r.cols().end(); ++j) {
2637+
ijk[b] = j/float(image[1])*(dim[b]+1) + bbox.min()[b];
2638+
const float v = tools::BoxSampler::sample(acc, ijk);
2639+
const uint8_t n = uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()));
2640+
film.pixel(i,j) = tools::Film::RGBA(s*LUT[n][0], s*LUT[n][1], s*LUT[n][2]);
26422641
}
2643-
});
2642+
}
2643+
};// mySample
2644+
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);});
26442648
film.savePPM(file + "_X_" + std::to_string(x)+ ".ppm");
26452649
}
26462650

26472651
for (float y : Y) {
2648-
tbb::parallel_for(range, [&](const auto &r){
2649-
Vec3R ijk(0, y*(dim[1]+1) + bbox.min()[1], 0);
2650-
auto acc = grid->getAccessor();
2651-
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
2652-
ijk[0] = i/float(image[0])*(dim[0]+1) + bbox.min()[0];
2653-
for (int j=r.cols().begin(); j<r.cols().end(); ++j) {
2654-
ijk[2] = j/float(image[1])*(dim[2]+1) + bbox.min()[2];
2655-
const float v = tools::BoxSampler::sample(acc, ijk);
2656-
const uint8_t n = uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()));
2657-
film.pixel(i,j) = tools::Film::RGBA(s*LUT[n][0], s*LUT[n][1], s*LUT[n][2]);
2658-
}
2659-
}
2660-
});
2652+
xyz[1] = y*(dim[1]+1) + bbox.min()[1];
2653+
tbb::parallel_for(range, [&](const auto &r){mySample(r, 0, 2);});
26612654
film.savePPM(file + "_Y_" + std::to_string(y)+ ".ppm");
26622655
}
26632656

26642657
for (float z : Z) {
2665-
tbb::parallel_for(range, [&](const auto &r){
2666-
Vec3R ijk(0, 0, z*(dim[2]+1) + bbox.min()[2]);
2667-
auto acc = grid->getAccessor();
2668-
for (auto i=r.rows().begin(); i!=r.rows().end(); ++i) {
2669-
ijk[0] = i/float(image[0])*(dim[0]+1) + bbox.min()[0];
2670-
for (int j=r.cols().begin(); j<r.cols().end(); ++j) {
2671-
ijk[1] = j/float(image[1])*(dim[1]+1) + bbox.min()[1];
2672-
const float v = tools::BoxSampler::sample(acc, ijk);
2673-
const uint8_t n = uint8_t(255.0f*(v - ex.min())/(ex.max() - ex.min()));
2674-
film.pixel(i,j) = tools::Film::RGBA(s*LUT[n][0], s*LUT[n][1], s*LUT[n][2]);
2675-
}
2676-
}
2677-
});
2658+
xyz[2] = z*(dim[2]+1) + bbox.min()[2];
2659+
tbb::parallel_for(range, [&](const auto &r){mySample(r, 0, 1);});
26782660
film.savePPM(file + "_Z_" + std::to_string(z)+ ".ppm");
26792661
}
26802662

0 commit comments

Comments
 (0)