diff --git a/include/vacancy/voxel_carver.h b/include/vacancy/voxel_carver.h index 8e582a3..5e721f2 100644 --- a/include/vacancy/voxel_carver.h +++ b/include/vacancy/voxel_carver.h @@ -14,8 +14,8 @@ namespace vacancy { // Voxel update type enum class VoxelUpdate { - kMax = 0, // take max - kWeightedAverage = 1 // Weighted Average like KinectFusion. truncation is + kMax = 0, // take max. naive voxel carving + kWeightedAverage = 1 // weighted Average like KinectFusion. truncation is // necessary to get good result }; @@ -38,7 +38,7 @@ struct VoxelCarverOption { }; struct Voxel { - Eigen::Vector3i index{-1, -1, -1}; // voxel index + Eigen::Vector3i index{-1, -1, -1}; // voxel index int id{-1}; Eigen::Vector3f pos{0.0f, 0.0f, 0.0f}; // center of voxel float sdf{0.0f}; // Signed Distance Function (SDF) value diff --git a/src/vacancy/voxel_carver.cc b/src/vacancy/voxel_carver.cc index 17dbcd6..e43cb16 100644 --- a/src/vacancy/voxel_carver.cc +++ b/src/vacancy/voxel_carver.cc @@ -170,7 +170,7 @@ void SignedDistance2Color(const Image1f& sdf, Image3b* vis_sdf, } } -Voxel::Voxel(){} +Voxel::Voxel() {} Voxel::~Voxel() {} VoxelGrid::VoxelGrid() {} @@ -281,6 +281,20 @@ VoxelCarver::VoxelCarver(VoxelCarverOption option) { set_option(option); } void VoxelCarver::set_option(VoxelCarverOption option) { option_ = option; } bool VoxelCarver::Init() { + if (option_.update_option.voxel_max_update_num < 1) { + LOGE("voxel_max_update_num must be positive"); + return false; + } + if (option_.update_option.voxel_update_weight < + std::numeric_limits::min()) { + LOGE("voxel_update_weight must be positive"); + return false; + } + if (option_.update_option.truncation_band < + std::numeric_limits::min()) { + LOGE("truncation_band must be positive"); + return false; + } voxel_grid_ = std::make_unique(); return voxel_grid_->Init(option_.bb_max, option_.bb_min, option_.resolution); } @@ -352,8 +366,8 @@ bool VoxelCarver::Carve(const Camera& camera, const Image1b& silhouette, if (voxel->update_num < 1) { voxel->sdf = dist; } else { - float w = option_.update_option.voxel_update_weight; - float inv_denom = 1.0f / (w * (voxel->update_num + 1)); + const float& w = option_.update_option.voxel_update_weight; + const float inv_denom = 1.0f / (w * (voxel->update_num + 1)); voxel->sdf = (w * voxel->update_num * voxel->sdf + w * dist) * inv_denom; }