Browse Source
stored formatted implicit arrangements data, and it is tested to be read correctly.blobtree
18 changed files with 188761 additions and 83 deletions
@ -0,0 +1,6 @@ |
|||||
|
#include <implicit_functions.hpp> |
||||
|
#include <implicit_surface_network_processor.hpp> |
||||
|
|
||||
|
int main(){ |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
target("implicit_surface_integrator") |
||||
|
set_kind("binary") |
||||
|
add_rules("config.indirect_predicates.flags") |
||||
|
add_deps("implicit_surface_network_process", "implicit_functions", "shared_module") |
||||
|
add_files("main.cpp") |
||||
|
target_end() |
File diff suppressed because it is too large
@ -0,0 +1,258 @@ |
|||||
|
257 |
||||
|
0 |
||||
|
1 |
||||
|
2 |
||||
|
3 |
||||
|
11 |
||||
|
12 |
||||
|
13 |
||||
|
15 |
||||
|
19 |
||||
|
20 |
||||
|
22 |
||||
|
23 |
||||
|
27 |
||||
|
35 |
||||
|
39 |
||||
|
43 |
||||
|
57 |
||||
|
58 |
||||
|
59 |
||||
|
61 |
||||
|
65 |
||||
|
66 |
||||
|
67 |
||||
|
71 |
||||
|
73 |
||||
|
75 |
||||
|
79 |
||||
|
83 |
||||
|
87 |
||||
|
91 |
||||
|
93 |
||||
|
97 |
||||
|
101 |
||||
|
102 |
||||
|
104 |
||||
|
105 |
||||
|
109 |
||||
|
111 |
||||
|
115 |
||||
|
119 |
||||
|
123 |
||||
|
124 |
||||
|
128 |
||||
|
129 |
||||
|
131 |
||||
|
135 |
||||
|
139 |
||||
|
141 |
||||
|
145 |
||||
|
153 |
||||
|
157 |
||||
|
161 |
||||
|
175 |
||||
|
179 |
||||
|
181 |
||||
|
185 |
||||
|
189 |
||||
|
193 |
||||
|
197 |
||||
|
199 |
||||
|
203 |
||||
|
217 |
||||
|
221 |
||||
|
225 |
||||
|
233 |
||||
|
234 |
||||
|
235 |
||||
|
237 |
||||
|
241 |
||||
|
242 |
||||
|
243 |
||||
|
247 |
||||
|
249 |
||||
|
251 |
||||
|
255 |
||||
|
259 |
||||
|
263 |
||||
|
267 |
||||
|
269 |
||||
|
273 |
||||
|
277 |
||||
|
278 |
||||
|
279 |
||||
|
283 |
||||
|
285 |
||||
|
286 |
||||
|
287 |
||||
|
295 |
||||
|
296 |
||||
|
300 |
||||
|
308 |
||||
|
322 |
||||
|
326 |
||||
|
328 |
||||
|
329 |
||||
|
333 |
||||
|
334 |
||||
|
336 |
||||
|
340 |
||||
|
344 |
||||
|
348 |
||||
|
352 |
||||
|
360 |
||||
|
374 |
||||
|
378 |
||||
|
382 |
||||
|
396 |
||||
|
404 |
||||
|
408 |
||||
|
412 |
||||
|
416 |
||||
|
420 |
||||
|
422 |
||||
|
426 |
||||
|
428 |
||||
|
432 |
||||
|
436 |
||||
|
438 |
||||
|
439 |
||||
|
443 |
||||
|
444 |
||||
|
448 |
||||
|
452 |
||||
|
456 |
||||
|
458 |
||||
|
462 |
||||
|
463 |
||||
|
465 |
||||
|
466 |
||||
|
467 |
||||
|
469 |
||||
|
470 |
||||
|
474 |
||||
|
476 |
||||
|
480 |
||||
|
484 |
||||
|
488 |
||||
|
489 |
||||
|
493 |
||||
|
494 |
||||
|
496 |
||||
|
500 |
||||
|
504 |
||||
|
506 |
||||
|
510 |
||||
|
512 |
||||
|
516 |
||||
|
520 |
||||
|
524 |
||||
|
528 |
||||
|
536 |
||||
|
550 |
||||
|
554 |
||||
|
558 |
||||
|
572 |
||||
|
580 |
||||
|
584 |
||||
|
588 |
||||
|
592 |
||||
|
596 |
||||
|
598 |
||||
|
599 |
||||
|
603 |
||||
|
604 |
||||
|
606 |
||||
|
610 |
||||
|
624 |
||||
|
632 |
||||
|
636 |
||||
|
637 |
||||
|
645 |
||||
|
646 |
||||
|
647 |
||||
|
649 |
||||
|
653 |
||||
|
654 |
||||
|
655 |
||||
|
659 |
||||
|
663 |
||||
|
665 |
||||
|
669 |
||||
|
673 |
||||
|
677 |
||||
|
681 |
||||
|
683 |
||||
|
685 |
||||
|
689 |
||||
|
690 |
||||
|
691 |
||||
|
695 |
||||
|
697 |
||||
|
698 |
||||
|
699 |
||||
|
707 |
||||
|
711 |
||||
|
715 |
||||
|
729 |
||||
|
733 |
||||
|
735 |
||||
|
739 |
||||
|
743 |
||||
|
747 |
||||
|
751 |
||||
|
753 |
||||
|
757 |
||||
|
771 |
||||
|
775 |
||||
|
779 |
||||
|
787 |
||||
|
791 |
||||
|
793 |
||||
|
797 |
||||
|
801 |
||||
|
803 |
||||
|
804 |
||||
|
808 |
||||
|
809 |
||||
|
813 |
||||
|
817 |
||||
|
821 |
||||
|
823 |
||||
|
827 |
||||
|
828 |
||||
|
830 |
||||
|
831 |
||||
|
835 |
||||
|
839 |
||||
|
841 |
||||
|
845 |
||||
|
849 |
||||
|
853 |
||||
|
857 |
||||
|
859 |
||||
|
861 |
||||
|
865 |
||||
|
866 |
||||
|
867 |
||||
|
871 |
||||
|
873 |
||||
|
874 |
||||
|
875 |
||||
|
889 |
||||
|
893 |
||||
|
897 |
||||
|
905 |
||||
|
909 |
||||
|
910 |
||||
|
912 |
||||
|
913 |
||||
|
917 |
||||
|
919 |
||||
|
920 |
||||
|
921 |
||||
|
929 |
||||
|
930 |
||||
|
931 |
||||
|
932 |
@ -0,0 +1,9 @@ |
|||||
|
#include <implicit_arrangement.h> |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
load_lut(); |
||||
|
lut_print_test(); |
||||
|
|
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "utils/eigen_alias.hpp" |
||||
|
|
||||
|
class ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
template <size_t Dim> |
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector<double, Dim>>& pos) const; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
Eigen::Vector<double, Dim> evaluate_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>>& pos) const; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
Eigen::Vector<double, Dim + 1> evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>>& pos) const; |
||||
|
}; |
@ -0,0 +1,14 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <string_view> |
||||
|
|
||||
|
#include <container/small_vector.hpp> |
||||
|
|
||||
|
#include "implicit_function.hpp" |
||||
|
|
||||
|
struct load_functions_result_t { |
||||
|
small_vector_mp<std::unique_ptr<ImplicitFunction>> functions{}; |
||||
|
bool success{}; |
||||
|
}; |
||||
|
|
||||
|
load_functions_result_t load_functions(const std::string_view& filename); |
@ -0,0 +1,215 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "implicit_function.hpp" |
||||
|
|
||||
|
static constexpr double kEpsilon = 1e-6; |
||||
|
|
||||
|
class ConstantFunction : public ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
explicit ConstantFunction(double value) : value_(value) {} |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
return value_; |
||||
|
} |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
Eigen::Vector<double, Dim> evaluate_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
return Eigen::Vector<double, Dim>::Zero(); |
||||
|
} |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
Eigen::Vector<double, Dim + 1> evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
auto res = Eigen::Vector<double, Dim + 1>::Zero(); |
||||
|
res[0] = value_; |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
double value_{}; |
||||
|
}; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
class PlaneDistanceFunction : public ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
PlaneDistanceFunction(const Eigen::Ref<const Eigen::Vector<double, Dim>> &point, |
||||
|
const Eigen::Ref<const Eigen::Vector<double, Dim>> &normal) |
||||
|
: point_(point), normal_(normal) |
||||
|
{ |
||||
|
normal_.normalize(); |
||||
|
} |
||||
|
|
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const { return normal_.dot(pos - point_); } |
||||
|
|
||||
|
Eigen::Vector<double, Dim> evaluate_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
return normal_; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector<double, Dim + 1> evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
Eigen::Vector<double, Dim + 1> res{}; |
||||
|
res.template head<Dim>().array() = normal_.array(); |
||||
|
res[Dim] = evaluate_scalar(pos); |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Eigen::Vector<double, Dim> point_{}; |
||||
|
Eigen::Vector<double, Dim> normal_{}; |
||||
|
}; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
class SphereDistanceFunction : public ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
SphereDistanceFunction(const Eigen::Ref<const Eigen::Vector<double, Dim>> ¢er, double radius) |
||||
|
: center_(center), radius_(radius) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
return (pos - center_).norm() - radius_; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector<double, Dim> evaluate_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
auto vec = pos - center_; |
||||
|
double norm = vec.norm(); |
||||
|
if (norm <= kEpsilon) return Eigen::Vector<double, Dim>::Zero(); |
||||
|
return vec / norm; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector<double, Dim + 1> evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector<double, Dim>> &pos) const |
||||
|
{ |
||||
|
Eigen::Vector<double, Dim + 1> res{}; |
||||
|
|
||||
|
auto vec = pos - center_; |
||||
|
double norm = vec.norm(); |
||||
|
if (norm <= kEpsilon) { |
||||
|
res[Dim] = -radius_; |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
res.template head<Dim>().array() = vec.array() / norm; |
||||
|
res[Dim] = norm - radius_; |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Eigen::Vector<double, Dim> center_{}; |
||||
|
double radius_{}; |
||||
|
}; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
class CylinderDistanceFunction; |
||||
|
|
||||
|
template <> |
||||
|
class CylinderDistanceFunction<3> : public ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
CylinderDistanceFunction(const Eigen::Ref<const Eigen::Vector3d> &axis_point, |
||||
|
const Eigen::Ref<const Eigen::Vector3d> &axis_dir, |
||||
|
double radius) |
||||
|
: axis_point_(axis_point), axis_dir_(axis_dir), radius_(radius) |
||||
|
{ |
||||
|
axis_dir_.normalize(); |
||||
|
} |
||||
|
|
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
auto vec = pos - axis_point_; |
||||
|
auto dist = vec.dot(axis_dir_); |
||||
|
return (vec - dist * axis_dir_).norm() - radius_; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector3d evaluate_gradient(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
auto vec = pos - axis_point_; |
||||
|
auto dist = vec.dot(axis_dir_); |
||||
|
auto vec_para = dist * axis_dir_; |
||||
|
Eigen::Vector3d vec_perp = vec - vec_para; |
||||
|
double norm = vec_perp.norm(); |
||||
|
if (norm <= kEpsilon) return Eigen::Vector3d::Zero(); |
||||
|
return vec_perp / norm; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector4d evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
Eigen::Vector4d res{}; |
||||
|
|
||||
|
auto vec = pos - axis_point_; |
||||
|
auto dist = vec.dot(axis_dir_); |
||||
|
auto vec_para = dist * axis_dir_; |
||||
|
Eigen::Vector3d vec_perp = vec - vec_para; |
||||
|
double norm = vec_perp.norm(); |
||||
|
if (norm <= kEpsilon) { |
||||
|
res[3] = -radius_; |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
res.template head<3>().array() = vec_perp.array() / norm; |
||||
|
res[3] = norm - radius_; |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Eigen::Vector3d axis_point_{}; |
||||
|
Eigen::Vector3d axis_dir_{}; |
||||
|
double radius_{}; |
||||
|
}; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
class ConeDistanceFunction; |
||||
|
|
||||
|
template <> |
||||
|
class ConeDistanceFunction<3> : public ImplicitFunction |
||||
|
{ |
||||
|
public: |
||||
|
ConeDistanceFunction(const Eigen::Ref<const Eigen::Vector3d> &apex_point, |
||||
|
const Eigen::Ref<const Eigen::Vector3d> &axis_dir, |
||||
|
double apex_angle) |
||||
|
: apex_point_(apex_point), axis_dir_(axis_dir), apex_angle_cosine_(std::cos(apex_angle)) |
||||
|
{ |
||||
|
axis_dir_.normalize(); |
||||
|
} |
||||
|
|
||||
|
double evaluate_scalar(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
return apex_angle_cosine_ * (pos - apex_point_).norm() - (pos - apex_point_).dot(axis_dir_); |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector3d evaluate_gradient(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
auto vec_apex = pos - apex_point_; |
||||
|
auto vec_norm = vec_apex.norm(); |
||||
|
if (vec_norm <= kEpsilon) return Eigen::Vector3d::Zero(); |
||||
|
return vec_apex * apex_angle_cosine_ / vec_norm - axis_dir_; |
||||
|
} |
||||
|
|
||||
|
Eigen::Vector4d evaluate_scalar_gradient(const Eigen::Ref<const Eigen::Vector3d> &pos) const |
||||
|
{ |
||||
|
auto vec_apex = pos - apex_point_; |
||||
|
auto vec_norm = vec_apex.norm(); |
||||
|
if (vec_norm <= kEpsilon) return Eigen::Vector4d::Zero(); |
||||
|
|
||||
|
Eigen::Vector4d res{}; |
||||
|
res.template head<3>().array() = vec_apex.array() * apex_angle_cosine_ / vec_norm - axis_dir_.array(); |
||||
|
res[3] = apex_angle_cosine_ * vec_norm - vec_apex.dot(axis_dir_); |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Eigen::Vector3d apex_point_{}; |
||||
|
Eigen::Vector3d axis_dir_{}; |
||||
|
double apex_angle_cosine_{}; |
||||
|
}; |
||||
|
|
||||
|
template <size_t Dim> |
||||
|
class TorusDistanceFunction; |
@ -0,0 +1,27 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <tbb/tbbmalloc_proxy.h> |
||||
|
|
||||
|
#define EIGEN_NO_CUDA 1 |
||||
|
#define EIGEN_USE_MKL 1 |
||||
|
#define EIGEN_USE_MKL_ALL 1 |
||||
|
#define EIGEN_USE_THREADS 1 |
||||
|
// just an experiment, since it seems OKay to mix oneTBB and OpenMP, see
|
||||
|
// https://oneapi-src.github.io/oneTBB/main/tbb_userguide/appendix_B.html
|
||||
|
// #define EIGEN_DONT_PARALLELIZE \ |
||||
|
// 1 // use this macro to disable multi-threading in Eigen, since Eigen's multi-threading is
|
||||
|
// // restricted to use OpenMP
|
||||
|
#define EIGEN_INITIALIZE_MATRICES_BY_ZERO 1 |
||||
|
#define EIGEN_NO_AUTOMATIC_RESIZING 1 |
||||
|
// #define EIGEN_MAX_CPP_VER 17
|
||||
|
#include <Eigen/Dense> |
||||
|
|
||||
|
// namespace BlobtreeIntegral::IMath
|
||||
|
// {
|
||||
|
// using namespace Eigen;
|
||||
|
|
||||
|
// static aligned_allocator<double> g_aligned_allocator{};
|
||||
|
|
||||
|
// static ThreadPool g_thread_pool(nbThreads());
|
||||
|
// static ThreadPoolDevice g_tensor_thread_pool_handle(&g_thread_pool, nbThreads());
|
||||
|
// } // namespace BlobtreeIntegral::IMath
|
@ -0,0 +1,4 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <primitive_functions.hpp> |
||||
|
#include <load_functions.hpp> |
@ -0,0 +1,82 @@ |
|||||
|
#include <iostream> |
||||
|
#include <fstream> |
||||
|
|
||||
|
#include <nlohmann/json.hpp> |
||||
|
|
||||
|
#include <implicit_functions.hpp> |
||||
|
#include "primitive_functions.hpp" |
||||
|
|
||||
|
load_functions_result_t load_functions(const std::string_view& filename) |
||||
|
{ |
||||
|
using json = nlohmann::json; |
||||
|
|
||||
|
std::ifstream file(filename.data()); |
||||
|
if (!file) { |
||||
|
std::cout << "Failed to open function file: " << filename << std::endl; |
||||
|
return {}; |
||||
|
} |
||||
|
|
||||
|
json data; |
||||
|
file >> data; |
||||
|
file.close(); |
||||
|
|
||||
|
load_functions_result_t result{}; |
||||
|
const auto num_functions = data.size(); |
||||
|
result.functions.reserve(num_functions); |
||||
|
for (size_t j = 0; j < num_functions; ++j) { |
||||
|
const auto type = data[j]["type"].get<std::string>(); |
||||
|
if (type == "plane") { |
||||
|
Eigen::Vector3d point, normal; |
||||
|
for (auto i = 0; i < 3; ++i) { |
||||
|
point[i] = data[j]["point"][i].get<double>(); |
||||
|
normal[i] = data[j]["normal"][i].get<double>(); |
||||
|
} |
||||
|
result.functions.emplace_back(std::make_unique<PlaneDistanceFunction<3>>(point, normal)); |
||||
|
} else if (type == "line") { |
||||
|
Eigen::Vector3d point, direction; |
||||
|
for (auto i = 0; i < 3; ++i) { |
||||
|
point[i] = data[j]["point"][i].get<double>(); |
||||
|
direction[i] = data[j]["direction"][i].get<double>(); |
||||
|
} |
||||
|
result.functions.emplace_back(std::make_unique<CylinderDistanceFunction<3>>(point, direction, 0)); |
||||
|
} else if (type == "cylinder") { |
||||
|
Eigen::Vector3d axis_point, axis_direction; |
||||
|
if (data[j].contains("axis_point1") && data[j].contains("axis_point2")) { |
||||
|
Eigen::Vector3d axis_point_; |
||||
|
for (auto i = 0; i < 3; ++i) { |
||||
|
axis_point[i] = data[j]["axis_point1"][i].get<double>(); |
||||
|
axis_point_[i] = data[j]["axis_point2"][i].get<double>(); |
||||
|
} |
||||
|
axis_direction = axis_point_ - axis_point; |
||||
|
} else { |
||||
|
for (auto i = 0; i < 3; ++i) { |
||||
|
axis_point[i] = data[j]["axis_point"][i].get<double>(); |
||||
|
axis_direction[i] = data[j]["axis_direction"][i].get<double>(); |
||||
|
} |
||||
|
} |
||||
|
double radius = data[j]["radius"].get<double>(); |
||||
|
result.functions.emplace_back(std::make_unique<CylinderDistanceFunction<3>>(axis_point, axis_direction, radius)); |
||||
|
} else if (type == "sphere") { |
||||
|
Eigen::Vector3d center; |
||||
|
for (auto i = 0; i < 3; ++i) { center[i] = data[j]["center"][i].get<double>(); } |
||||
|
double radius = data[j]["radius"].get<double>(); |
||||
|
result.functions.emplace_back(std::make_unique<SphereDistanceFunction<3>>(center, radius)); |
||||
|
} else if (type == "cone") { |
||||
|
Eigen::Vector3d apex_point, axis_direction; |
||||
|
for (auto i = 0; i < 3; ++i) { |
||||
|
apex_point[i] = data[j]["apex_point"][i].get<double>(); |
||||
|
axis_direction[i] = data[j]["axis_direction"][i].get<double>(); |
||||
|
} |
||||
|
double apex_angle = data[j]["apex_angle"].get<double>(); |
||||
|
result.functions.emplace_back(std::make_unique<ConeDistanceFunction<3>>(apex_point, axis_direction, apex_angle)); |
||||
|
} else if (type == "constant") { |
||||
|
double value = data[j]["value"].get<double>(); |
||||
|
result.functions.emplace_back(std::make_unique<ConstantFunction>(value)); |
||||
|
} else { |
||||
|
std::cout << "Unsupported function type: " << type << std::endl; |
||||
|
return {}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
Loading…
Reference in new issue