Browse Source

aabb special judgment

gjj
Dtouch 2 months ago
parent
commit
295176e3dc
  1. 60
      application/main.cpp
  2. 28
      primitive_process/src/extrude_polyline.cpp

60
application/main.cpp

@ -165,10 +165,68 @@ void testPolylineSDF()
}
}
void testHex()
{
std::vector<raw_vector3d_t> points;
std::vector<double> bulges;
points.push_back({-10800.000000000031, -7479.9999999988240, 0.0000000000000000});
points.push_back({-7200.0000000000291, -7479.9999999988240, 0.0000000000000000});
points.push_back({-7200.0000000000291, -7719.9999999988240, 0.0000000000000000});
points.push_back({-10800.000000000031, -7719.9999999988240, 0.0000000000000000});
bulges.push_back(0.0000000000000000);
bulges.push_back(0.0000000000000000);
bulges.push_back(0.0000000000000000);
bulges.push_back(0.0000000000000000);
polyline_descriptor_t profile{
4,
points.data(),
4,
bulges.data(),
raw_vector3d_t{0., 0., 1.},
true
};
auto axisEnd = points[0];
axisEnd.z = 78.000000000471118;
auto axisPoints = std::array{points[0], axisEnd};
auto axisBulges = std::array{0.0};
polyline_descriptor_t axis{
2,
axisPoints.data(),
1,
axisBulges.data(),
raw_vector3d_t{0., 1., 0.},
false
};
extrude_polyline_descriptor_t extrude{1, &profile, axis};
aabb_t<> aabb{};
internal::extrude_polyline extrude_polyline{extrude, aabb};
std::vector<Eigen::Vector3d> queryPoints = {
{0., 0., 0. },
{-8000, 0, 10 },
{-8000, 0, -10},
{-8000, -7500, 10 },
{-8000, -7481, 10 },
{-7202, -7500, 10 }
};
for (const auto &queryPoint : queryPoints) {
double res = extrude_polyline.evaluate_sdf(queryPoint);
Eigen::Vector3d closest_point = extrude_polyline.evaluate_cpm(queryPoint);
printf("SDF at (%f, %f, %f) is %f, closest point: (%f, %f, %f)\n",
queryPoint.x(),
queryPoint.y(),
queryPoint.z(),
res,
closest_point.x(),
closest_point.y(),
closest_point.z());
}
}
int main()
{
// testExtrudeSDFZoX();
testExtrudeSDFXoY();
testHex();
// testPolylineSDF();
// std::cout << "Setting scene..." << std::endl;

28
primitive_process/src/extrude_polyline.cpp

@ -1,5 +1,6 @@
#include "Eigen/Core"
#include "internal_primitive_desc.hpp"
#include <cassert>
#include <cmath>
#include <iostream>
@ -20,9 +21,36 @@ extrude_polyline::extrude_polyline(const extrude_polyline_descriptor_t &desc, aa
matrix_handle.col(3),
profile_aabb);
const auto profile_max_extent = profile_aabb.max().cwiseMax(profile_aabb.min().cwiseAbs()).maxCoeff();
//////////////special judge////////////////
const auto eqs = [](double a, double b) { return std::abs(a - b) < EPSILON; };
int aabb_parallel_coord_axis = -1;
if (eqs(aabb.min().x(), aabb.max().x()) && eqs(aabb.min().y(), aabb.max().y())) {
aabb_parallel_coord_axis = 2;
assert(aabb.min().z() != aabb.max().z());
aabb.min().x() -= profile_max_extent;
aabb.max().x() += profile_max_extent;
aabb.min().y() -= profile_max_extent;
aabb.max().y() += profile_max_extent;
} else if (eqs(aabb.min().x(), aabb.max().x()) && eqs(aabb.min().z(), aabb.max().z())) {
aabb_parallel_coord_axis = 1;
assert(aabb.min().y() != aabb.max().y());
aabb.min().x() -= profile_max_extent;
aabb.max().x() += profile_max_extent;
aabb.min().z() -= profile_max_extent;
aabb.max().z() += profile_max_extent;
} else if (eqs(aabb.min().y(), aabb.max().y()) && eqs(aabb.min().z(), aabb.max().z())) {
aabb_parallel_coord_axis = 0;
aabb.min().y() -= profile_max_extent;
aabb.max().y() += profile_max_extent;
aabb.min().z() -= profile_max_extent;
aabb.max().z() += profile_max_extent;
}
//////////////EO special judge////////////////
else {
aabb.min().array() -= profile_max_extent;
aabb.max().array() += profile_max_extent;
}
}
extrude_polyline::extrude_polyline(extrude_polyline_descriptor_t &&desc, aabb_t<> &aabb)
{

Loading…
Cancel
Save