diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp index b6e6222..bccdb6c 100644 --- a/MarchingCubes.cpp +++ b/MarchingCubes.cpp @@ -54,7 +54,27 @@ Mesh MarchingCubes::operator()() { const std::vector& cur_triangles = edges_of_intersection[intersections.value()]; - // TODO + for(const CubeTri& cube_tri: cur_triangles) { + Point verts[3] = { + intersect_location(cube_tri.edge[0], + x, y, z), + intersect_location(cube_tri.edge[1], + x, y, z), + intersect_location(cube_tri.edge[2], + x, y, z), + }; + + size_t vert_ids[3]; + for(int i=0; i < 3; ++i) + vert_ids[i] = output.add_vertice(verts[i]); + + for(int i=0; i < 3; ++i) { + output.add_face( + vert_ids[i], + vert_ids[(i+1) % 3], + vert_ids[(i+2) % 3]); + } + } } } } diff --git a/MarchingCubes.hpp b/MarchingCubes.hpp index 0e0c155..97d1855 100644 --- a/MarchingCubes.hpp +++ b/MarchingCubes.hpp @@ -86,6 +86,12 @@ class MarchingCubes { } bool x[2], y[2], z[2]; + const bool operator==(const CubeEdge& oth) const { + return x[0] == oth.x[0] && x[1] == oth.x[1] + && y[0] == oth.y[0] && y[1] == oth.y[1] + && z[0] == oth.z[0] && z[1] == oth.z[1]; + } + /** Get the space point at a given position of [0,1] along the edge * when the base of the cube (ie. (0, 0, 0)) is given. */ Point at(double pos,