diff --git a/src/dwi/bootstrap.h b/src/dwi/bootstrap.h index a6b0a09e7f..16099ab3ec 100644 --- a/src/dwi/bootstrap.h +++ b/src/dwi/bootstrap.h @@ -46,8 +46,10 @@ class Bootstrap : public Adapter::Base(NUM_VOX_PER_CHUNK * size(3))); + clear(); } value_type value() { return get_voxel()[index(3)]; } @@ -65,8 +67,6 @@ class Bootstrap : public Adapter::Base(NUM_VOX_PER_CHUNK * size(3))); next_voxel = &voxel_buffer[0][0]; last_voxel = next_voxel + NUM_VOX_PER_CHUNK * size(3); current_chunk = 0; @@ -82,11 +82,10 @@ class Bootstrap : public Adapter::Base= voxel_buffer.size()) + if (++current_chunk >= voxel_buffer.size()) voxel_buffer.push_back(std::vector(NUM_VOX_PER_CHUNK * size(3))); assert(current_chunk < voxel_buffer.size()); - next_voxel = &voxel_buffer.back()[0]; + next_voxel = &voxel_buffer[current_chunk][0]; last_voxel = next_voxel + NUM_VOX_PER_CHUNK * size(3); } value_type *retval = next_voxel; @@ -95,16 +94,17 @@ class Bootstrap : public Adapter::Basesecond); - if (!data) { - data = allocate_voxel(); - ssize_t pos = index(3); - for (auto l = Loop(3)(*this); l; ++l) - data[index(3)] = base_type::value(); - index(3) = pos; - func(data); - } + const Eigen::Vector3i voxel(index(0), index(1), index(2)); + const typename std::map::const_iterator existing = voxels.find(voxel); + if (existing != voxels.end()) + return existing->second; + value_type *const data = allocate_voxel(); + ssize_t pos = index(3); + for (auto l = Loop(3)(*this); l; ++l) + data[index(3)] = base_type::value(); + index(3) = pos; + func(data); + voxels.insert({voxel, data}); return data; } };