Skip to content

Commit

Permalink
1) Fix a bug of VoxelGrid::Clear() 2) Supress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
unclearness committed Oct 10, 2023
1 parent ec2c402 commit deed29d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/ugu/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ using Scalar_ = Vec_<TT, 4>;

using Scalar = Scalar_<double>;

#ifndef OPENCV_CORE_HAL_INTERFACE_H

#define CV_CN_MAX 512
#define CV_CN_SHIFT 3
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
Expand Down Expand Up @@ -292,6 +294,8 @@ using Scalar = Scalar_<double>;
#define CV_16FC4 CV_MAKETYPE(CV_16F, 4)
#define CV_16FC(n) CV_MAKETYPE(CV_16F, (n))

#endif

#define CV_GETCN(type) ((type >> CV_CN_SHIFT) + 1)

int GetBitsFromCvType(int cv_type);
Expand Down
6 changes: 3 additions & 3 deletions src/image_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ bool WriteJpg(const ImageBase& img, const std::string& path) {
}
#else
bool LoadByStb(ImageBase& img, const std::string& path) {
(void)path;
(void)img, path;
LOGE("can't load image with this configuration\n");
return false;
}

bool WritePng(const ImageBase& img, const std::string& path) {
(void)path;
(void)img, path;
LOGE("can't write image with this configuration\n");
return false;
}

bool WriteJpg(const ImageBase& img, const std::string& path) {
(void)path;
(void)img, path;
LOGE("can't write image with this configuration\n");
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/renderable_mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void RenderableMesh::SetupMesh(int geo_id) {
}

void RenderableMesh::Draw(const Shader &shader) const {
(void)shader;
LOGE("Not supported with this configuration\n");
}
} // namespace ugu
Expand Down
6 changes: 5 additions & 1 deletion src/util/image_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void eigen2cv(const Eigen::MatrixXd& mat, ugu::Image1d& img) {
mat_ = mat.transpose();
}

img = ugu::Image1d::zeros(mat_.rows(), mat_.cols());
img = ugu::Image1d::zeros(static_cast<int>(mat_.rows()),
static_cast<int>(mat_.cols()));
std::memcpy(img.data, mat.data(), sizeof(double) * img.cols * img.rows);
}

Expand Down Expand Up @@ -1126,6 +1127,9 @@ std::pair<std::vector<Image4b>, std::vector<int>> LoadGif(
std::memcpy(images[i].data, data.data() + i * bytes_per_image,
bytes_per_image);
}
#else
(void)path;
LOGE("can't load image with this configuration\n");
#endif
return {images, delays};
}
Expand Down
31 changes: 29 additions & 2 deletions src/voxel/voxel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include <array>

// #define ENSURE_UPDATE

#ifdef ENSURE_UPDATE
#include <unordered_set>
#endif

#include "ugu/timer.h"
#include "ugu/util/image_util.h"
#include "ugu/util/rgbd_util.h"
Expand Down Expand Up @@ -75,9 +81,25 @@ inline void FusePointBase(const Eigen::Vector3f& p, const Eigen::Vector3f& n,
} else {
float step = voxel_grid.resolution();
// Sample along with normal direction

#ifdef ENSURE_UPDATE
std::unordered_set<Eigen::Vector3i> updated_idxs;
const float step_scale = std::sqrt(2.f);
#endif
for (int k = -sample_num; k < sample_num + 1; k++) {
#ifdef ENSURE_UPDATE
Eigen::Vector3f offset = n * k * step;
auto voxel_idx_ = voxel_grid.get_index(p + offset);
if (updated_idxs.find(voxel_idx_) != updated_idxs.end()) {
offset = n * k * step * step_scale;
voxel_idx_ = voxel_grid.get_index(p + offset);
// std::cout << "try again..." << std::endl;
}
updated_idxs.insert(voxel_idx_);
#else
const Eigen::Vector3f offset = n * k * step;
const auto& voxel_idx_ = voxel_grid.get_index(p + offset);
#endif
if (voxel_idx_[0] < 0 || voxel_idx_[1] < 0 || voxel_idx_[2] < 0) {
return;
}
Expand Down Expand Up @@ -280,9 +302,11 @@ Eigen::Vector3i VoxelGrid::get_index(const Eigen::Vector3f& p) const {
}

void VoxelGrid::Clear() {
#pragma omp parallel for
#if defined(_OPENMP) && defined(UGU_USE_OPENMP)
#pragma omp parallel for schedule(dynamic, 1)
#endif
for (int64_t i = 0; i < static_cast<int64_t>(voxels_.size()); i++) {
voxels_[i].sdf = 0.f;
voxels_[i].sdf = InvalidSdf::kVal;
voxels_[i].update_num = 0;
}
}
Expand Down Expand Up @@ -394,6 +418,9 @@ bool FuseDepth(const Camera& camera, const Image1f& depth,
Eigen::Affine3f c2w = camera.c2w().cast<float>();
Eigen::Matrix3f c2w_R = c2w.rotation();

#if defined(_OPENMP) && defined(UGU_USE_OPENMP)
#pragma omp parallel for schedule(dynamic, 1)
#endif
for (int y = 0; y < camera.height(); y++) {
for (int x = 0; x < camera.width(); x++) {
const float& d = depth.at<float>(y, x);
Expand Down

0 comments on commit deed29d

Please sign in to comment.