From a209081cf697bf58079010d29de1affa355811fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 12 Feb 2018 13:40:06 +0100 Subject: [PATCH] Begin hints integration -- WIP --- MarchingCubes.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++---- MarchingCubes.hpp | 6 +++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp index 22cd064..bc76de0 100644 --- a/MarchingCubes.cpp +++ b/MarchingCubes.cpp @@ -18,7 +18,12 @@ void MarchingCubes::add_hint(const Cuboid& hint) { Mesh MarchingCubes::operator()() { Mesh output; - without_hints(output); + if(hints.empty()) { + without_hints(output); + } + else { + with_hints(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 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, 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( 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; for(int dx=0; dx <= 1; dx++) { for(int dy=0; dy <= 1; dy++) { for(int dz=0; dz <= 1; dz++) { - double cx = bx + side_len * dx; - double cy = by + side_len * dy; - double cz = bz + side_len * dz; + double cx = bx + x_len * dx; + double cy = by + y_len * dy; + double cz = bz + z_len * dz; intersections.set_corner(dx, dy, dz, surface(cx, cy, cz) > 0); } @@ -120,6 +165,12 @@ MarchingCubes::Intersections MarchingCubes::mk_intersection_cube( Point MarchingCubes::intersect_location(const CubeEdge& edge, 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 compute = [&](double low_prop, double high_prop) diff --git a/MarchingCubes.hpp b/MarchingCubes.hpp index cd4fb28..2d61ecb 100644 --- a/MarchingCubes.hpp +++ b/MarchingCubes.hpp @@ -120,12 +120,18 @@ class MarchingCubes { /// triangle was added. void without_hints(Mesh& output); + void with_hints(Mesh& output); Intersections mk_intersection_cube(double bx, double by, double bz, 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, double bx, double by, double bz) const; + Point intersect_location(const CubeEdge& edge, + double bx, double by, double bz, + double resolution) const; private: static const std::vector edges_of_intersection[256];