mirror of https://github.com/wpkong/Octree.git
25 changed files with 10129 additions and 209 deletions
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="VcsDirectoryMappings"> |
||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
||||
|
</component> |
||||
|
</project> |
File diff suppressed because it is too large
@ -0,0 +1,53 @@ |
|||||
|
/**
|
||||
|
* ------------------------------------ |
||||
|
* @author: Weipeng Kong |
||||
|
* @date: 2021/11/30 |
||||
|
* @email: yjxkwp@foxmail.com |
||||
|
* @site: https://donot.fit
|
||||
|
* @description: |
||||
|
* ------------------------------------ |
||||
|
**/ |
||||
|
|
||||
|
#ifndef OCTREE_VOXELDENSEDATA_H |
||||
|
#define OCTREE_VOXELDENSEDATA_H |
||||
|
|
||||
|
#include <vector> |
||||
|
#include <Eigen/Core> |
||||
|
#include <Eigen/Dense> |
||||
|
|
||||
|
namespace Octree { |
||||
|
/**
|
||||
|
* All Dense value will be sampled use coordinate [0, 1]^3 |
||||
|
*/ |
||||
|
class VoxelDenseData { |
||||
|
protected: |
||||
|
int _x, _y, _z; // 3D range [start with 0]
|
||||
|
std::vector<double> value; |
||||
|
|
||||
|
public: |
||||
|
VoxelDenseData(const std::vector<double> &value, int _x, int _y, int _z); |
||||
|
|
||||
|
public: |
||||
|
/**
|
||||
|
* Sample from value |
||||
|
* @param x [0,1] |
||||
|
* @param y [0,1] |
||||
|
* @param z [0,1] |
||||
|
* @return sampled value |
||||
|
*/ |
||||
|
double sample(double x, double y, double z) const; |
||||
|
|
||||
|
/**
|
||||
|
* Tool function: calc 1D index from 3D coordinate |
||||
|
* @param x |
||||
|
* @param y |
||||
|
* @param z |
||||
|
* @return |
||||
|
*/ |
||||
|
int get_array_index(int x, int y, int z) const; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif //OCTREE_VOXELDENSEDATA_H
|
@ -0,0 +1,104 @@ |
|||||
|
/**
|
||||
|
* ------------------------------------ |
||||
|
* @author: Weipeng Kong |
||||
|
* @date: 2021/11/30 |
||||
|
* @email: yjxkwp@foxmail.com |
||||
|
* @site: https://donot.fit
|
||||
|
* @description: |
||||
|
* ------------------------------------ |
||||
|
**/ |
||||
|
|
||||
|
#include "Octree/VoxelDenseData.h" |
||||
|
|
||||
|
|
||||
|
namespace LerpTools { |
||||
|
inline double interpolate1D(double v1, double v2, double x1, double x2, double x) { |
||||
|
double t = (x - x1) / (x2 - x1); |
||||
|
return v1 * (1 - t) + v2 * t; |
||||
|
} |
||||
|
|
||||
|
inline double interpolate2D(double v1, double v2, double v3, double v4, |
||||
|
double x1, double x2, double x, |
||||
|
double y1, double y2, double y) { |
||||
|
double s = interpolate1D(v1, v2, x1, x2, x); |
||||
|
double t = interpolate1D(v3, v4, x1, x2, x); |
||||
|
return interpolate1D(s, t, y1, y2, y); |
||||
|
} |
||||
|
|
||||
|
inline double interpolate3D(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, |
||||
|
double x1, double x2, double x, |
||||
|
double y1, double y2, double y, |
||||
|
double z1, double z2, double z) { |
||||
|
double s = interpolate2D(v1, v2, v3, v4, x1, x2, x, y1, y2, y); |
||||
|
double t = interpolate2D(v5, v6, v7, v8, x1, x2, x, y1, y2, y); |
||||
|
return interpolate1D(s, t, z1, z2, z); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Octree::VoxelDenseData::VoxelDenseData(const std::vector<double> &value, int _x, int _y, int _z) : value(value), |
||||
|
_x(_x), _y(_y), |
||||
|
_z(_z) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
double Octree::VoxelDenseData::sample(double x, double y, double z) const { |
||||
|
// std::cout << "x = " << x << std::endl;
|
||||
|
// std::cout << "_x = " << _x << std::endl;
|
||||
|
x = (_x - 1) * x; |
||||
|
y = (_y - 1) * y; |
||||
|
z = (_z - 1) * z; |
||||
|
|
||||
|
#define LerpOnSDF |
||||
|
#ifdef LerpOnSDF |
||||
|
int bound[6] = { |
||||
|
int(x), int(x) + 1, int(y), int(y) + 1, int(z), int(z) + 1 |
||||
|
}; |
||||
|
// if (bound[1] >= _x) bound[1] = bound[0];
|
||||
|
// if (bound[3] >= _y) bound[3] = bound[2];
|
||||
|
// if (bound[5] >= _z) bound[5] = bound[4];
|
||||
|
|
||||
|
// std::cout << bound[0] << ", "<< bound[1] << ", "<< bound[2] << ", "<< bound[3] << ", "<< bound[4] << ", "<< bound[5] << std::endl;
|
||||
|
// exit(0);
|
||||
|
|
||||
|
double v[8]; |
||||
|
v[0] = value[get_array_index(bound[0], bound[2], bound[4])]; |
||||
|
v[1] = value[get_array_index(bound[1], bound[2], bound[4])]; |
||||
|
v[2] = value[get_array_index(bound[0], bound[3], bound[4])]; |
||||
|
v[3] = value[get_array_index(bound[1], bound[3], bound[4])]; |
||||
|
v[4] = value[get_array_index(bound[0], bound[2], bound[5])]; |
||||
|
v[5] = value[get_array_index(bound[1], bound[2], bound[5])]; |
||||
|
v[6] = value[get_array_index(bound[0], bound[3], bound[5])]; |
||||
|
v[7] = value[get_array_index(bound[1], bound[3], bound[5])]; |
||||
|
|
||||
|
// v[0] = value[get_array_index(bound[0], bound[2], bound[4])];
|
||||
|
// v[1] = value[get_array_index(bound[0], bound[3], bound[4])];
|
||||
|
// v[2] = value[get_array_index(bound[1], bound[2], bound[4])];
|
||||
|
// v[3] = value[get_array_index(bound[1], bound[3], bound[4])];
|
||||
|
// v[4] = value[get_array_index(bound[0], bound[2], bound[5])];
|
||||
|
// v[5] = value[get_array_index(bound[0], bound[3], bound[5])];
|
||||
|
// v[6] = value[get_array_index(bound[1], bound[2], bound[5])];
|
||||
|
// v[7] = value[get_array_index(bound[1], bound[3], bound[5])];
|
||||
|
|
||||
|
// return v[2];
|
||||
|
// return v[7];
|
||||
|
// return (v[0]+ v[1]+v[2]+v[3]+ v[4]+ v[5]+ v[6]+v[7]) / 8;
|
||||
|
// return v[0];
|
||||
|
|
||||
|
return LerpTools::interpolate3D( |
||||
|
v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], |
||||
|
bound[0], bound[1], x, |
||||
|
bound[2], bound[3], y, |
||||
|
bound[4], bound[5], z |
||||
|
); |
||||
|
|
||||
|
#else |
||||
|
return value[get_array_index((int) x, (int) y, (int) z)]; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
int Octree::VoxelDenseData::get_array_index(int x, int y, int z) const { |
||||
|
// return (x * _x * _y) + (y * _y) + z;
|
||||
|
// return ((x * _y) + y) * _z + z;
|
||||
|
return ((z * _y) + y) * _x + x; |
||||
|
} |
@ -1,3 +1,3 @@ |
|||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
||||
add_executable(octree_test main.cpp) |
add_executable(octree_test main.cpp) |
||||
target_link_libraries(octree_test OctreeSDF pMesh) |
target_link_libraries(octree_test Octree pMesh) |
||||
|
@ -1,3 +1,3 @@ |
|||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
||||
add_executable(sdf_test main.cpp) |
add_executable(sdf_test main.cpp) |
||||
target_link_libraries(sdf_test OctreeSDF pMesh) |
target_link_libraries(sdf_test Octree pMesh) |
||||
|
Loading…
Reference in new issue