Begin hints integration -- WIP
This commit is contained in:
parent
cf0d7af712
commit
a209081cf6
2 changed files with 61 additions and 4 deletions
|
@ -18,7 +18,12 @@ void MarchingCubes::add_hint(const Cuboid& hint) {
|
||||||
Mesh MarchingCubes::operator()() {
|
Mesh MarchingCubes::operator()() {
|
||||||
Mesh output;
|
Mesh output;
|
||||||
|
|
||||||
|
if(hints.empty()) {
|
||||||
without_hints(output);
|
without_hints(output);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
with_hints(output);
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +41,39 @@ void MarchingCubes::without_hints(Mesh& output) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MarchingCubes::with_hints(Mesh& output) {
|
||||||
|
auto fmod = [](double x, double mod) {
|
||||||
|
return x - floor(x/mod) * mod;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocSet visited;
|
||||||
|
for(const Cuboid& hint: hints) {
|
||||||
|
Intersections inters = mk_intersection_cuboid(
|
||||||
|
hint.low(0), hint.low(1), hint.low(2),
|
||||||
|
hint.length(0), hint.length(1), hint.length(2));
|
||||||
|
|
||||||
|
const std::vector<CubeTri> triangles =
|
||||||
|
edges_of_intersection[inters.value()];
|
||||||
|
if(triangles.size() == 0)
|
||||||
|
continue; // this hint does not intersect anything.
|
||||||
|
const CubeEdge& edge = triangles[0].edge[0];
|
||||||
|
double edge_len = 0;
|
||||||
|
if(edge.x[0] != edge.x[1])
|
||||||
|
edge_len = hint.length(0);
|
||||||
|
else if(edge.y[0] != edge.y[1])
|
||||||
|
edge_len = hint.length(1);
|
||||||
|
else
|
||||||
|
edge_len = hint.length(2);
|
||||||
|
|
||||||
|
Point intersect_loc = intersect_location(
|
||||||
|
edge, hint.low(0), hint.low(1), hint.low(1), edge_len);
|
||||||
|
int cube_x = floor(intersect_loc.x / resolution),
|
||||||
|
cube_y = floor(intersect_loc.y / resolution),
|
||||||
|
cube_z = floor(intersect_loc.z / resolution);
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Point MarchingCubes::CubeEdge::at(double pos,
|
Point MarchingCubes::CubeEdge::at(double pos,
|
||||||
double bx, double by, double bz, double resolution) const
|
double bx, double by, double bz, double resolution) const
|
||||||
{
|
{
|
||||||
|
@ -102,14 +140,21 @@ bool MarchingCubes::march_at(double x, double y, double z, Mesh& output) {
|
||||||
|
|
||||||
MarchingCubes::Intersections MarchingCubes::mk_intersection_cube(
|
MarchingCubes::Intersections MarchingCubes::mk_intersection_cube(
|
||||||
double bx, double by, double bz, double side_len) const
|
double bx, double by, double bz, double side_len) const
|
||||||
|
{
|
||||||
|
return mk_intersection_cuboid(bx, by, bz, side_len, side_len, side_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
MarchingCubes::Intersections MarchingCubes::mk_intersection_cuboid(
|
||||||
|
double bx, double by, double bz,
|
||||||
|
double x_len, double y_len, double z_len) const
|
||||||
{
|
{
|
||||||
Intersections intersections;
|
Intersections intersections;
|
||||||
for(int dx=0; dx <= 1; dx++) {
|
for(int dx=0; dx <= 1; dx++) {
|
||||||
for(int dy=0; dy <= 1; dy++) {
|
for(int dy=0; dy <= 1; dy++) {
|
||||||
for(int dz=0; dz <= 1; dz++) {
|
for(int dz=0; dz <= 1; dz++) {
|
||||||
double cx = bx + side_len * dx;
|
double cx = bx + x_len * dx;
|
||||||
double cy = by + side_len * dy;
|
double cy = by + y_len * dy;
|
||||||
double cz = bz + side_len * dz;
|
double cz = bz + z_len * dz;
|
||||||
intersections.set_corner(dx, dy, dz,
|
intersections.set_corner(dx, dy, dz,
|
||||||
surface(cx, cy, cz) > 0);
|
surface(cx, cy, cz) > 0);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +165,12 @@ MarchingCubes::Intersections MarchingCubes::mk_intersection_cube(
|
||||||
|
|
||||||
Point MarchingCubes::intersect_location(const CubeEdge& edge,
|
Point MarchingCubes::intersect_location(const CubeEdge& edge,
|
||||||
double bx, double by, double bz) const
|
double bx, double by, double bz) const
|
||||||
|
{
|
||||||
|
return intersect_location(edge, bx, by, bz, this->resolution);
|
||||||
|
}
|
||||||
|
|
||||||
|
Point MarchingCubes::intersect_location(const CubeEdge& edge,
|
||||||
|
double bx, double by, double bz, double resolution) const
|
||||||
{
|
{
|
||||||
std::function<Point(double, double)> compute =
|
std::function<Point(double, double)> compute =
|
||||||
[&](double low_prop, double high_prop)
|
[&](double low_prop, double high_prop)
|
||||||
|
|
|
@ -120,12 +120,18 @@ class MarchingCubes {
|
||||||
/// triangle was added.
|
/// triangle was added.
|
||||||
|
|
||||||
void without_hints(Mesh& output);
|
void without_hints(Mesh& output);
|
||||||
|
void with_hints(Mesh& output);
|
||||||
|
|
||||||
Intersections mk_intersection_cube(double bx, double by, double bz,
|
Intersections mk_intersection_cube(double bx, double by, double bz,
|
||||||
double side_len) const;
|
double side_len) const;
|
||||||
|
Intersections mk_intersection_cuboid(double bx, double by, double bz,
|
||||||
|
double x_len, double y_len, double z_len) const;
|
||||||
|
|
||||||
Point intersect_location(const CubeEdge& edge,
|
Point intersect_location(const CubeEdge& edge,
|
||||||
double bx, double by, double bz) const;
|
double bx, double by, double bz) const;
|
||||||
|
Point intersect_location(const CubeEdge& edge,
|
||||||
|
double bx, double by, double bz,
|
||||||
|
double resolution) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::vector<CubeTri> edges_of_intersection[256];
|
static const std::vector<CubeTri> edges_of_intersection[256];
|
||||||
|
|
Loading…
Reference in a new issue