Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
unlclearness committed Apr 9, 2019
1 parent e12c2d3 commit 88de6ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/vacancy/voxel_carver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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
Expand Down
20 changes: 17 additions & 3 deletions src/vacancy/voxel_carver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void SignedDistance2Color(const Image1f& sdf, Image3b* vis_sdf,
}
}

Voxel::Voxel(){}
Voxel::Voxel() {}
Voxel::~Voxel() {}

VoxelGrid::VoxelGrid() {}
Expand Down Expand Up @@ -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<float>::min()) {
LOGE("voxel_update_weight must be positive");
return false;
}
if (option_.update_option.truncation_band <
std::numeric_limits<float>::min()) {
LOGE("truncation_band must be positive");
return false;
}
voxel_grid_ = std::make_unique<VoxelGrid>();
return voxel_grid_->Init(option_.bb_max, option_.bb_min, option_.resolution);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 88de6ff

Please sign in to comment.