diff --git a/Makefile b/Makefile index 51ce6f3..e19eac1 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,10 @@ CXXLIBS=-lGL -lGLU -lglut TARGETS=glut OBJS=Implicit.o \ + common_structures.o \ Mesh.o \ util/ObjParser.o \ + MarchingCubes.o \ render/GlutRender.o all: $(TARGETS:=.bin) diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp new file mode 100644 index 0000000..6988d10 --- /dev/null +++ b/MarchingCubes.cpp @@ -0,0 +1,33 @@ +#include "MarchingCubes.hpp" + +MarchingCubes::MarchingCubes( + const ImplicitSurface& surface, + const Cuboid& box, + double resolution): + surface(surface), + box(box), + resolution(resolution) +{} + +void MarchingCubes::add_hint(const Cuboid& hint) { + hints.push_back(hint); +} + +Mesh MarchingCubes::operator()() { + Mesh output; + + for(double x = box.low(0); x < box.high(0) + resolution; x += resolution) + { + for(double y = box.low(1); y < box.high(1) + resolution; + y += resolution) + { + for(double z = box.low(2); z < box.high(2) + resolution; + z += resolution) + { + //TODO apply marching cube indeed + } + } + } + + return output; +} diff --git a/MarchingCubes.hpp b/MarchingCubes.hpp new file mode 100644 index 0000000..95db829 --- /dev/null +++ b/MarchingCubes.hpp @@ -0,0 +1,48 @@ +#pragma once + +/** Implement the Marching Cubes algorithm + * + * Marching cubes: + * W. E. Lorensen, H. E. Cline, 1987 + * ``Marching cubes: a high resulution 3D surface construction algorithm'' + * + */ + +#include +#include "Mesh.hpp" +#include "Implicit.hpp" +#include "common_structures.hpp" + +class MarchingCubes { + private: + typedef unsigned char intersect_t; + + public: + MarchingCubes( + const ImplicitSurface& surface, + const Cuboid& box=Cuboid( + Point(-20, -20, -20), + Point(20, 20, 20)), + double resolution=.25); + + /** Add a starting point hint + * + * A hint is a cuboid that should intersect at least once the surface, + * such that the marching cube will find the surface there and will be + * able to follow it. + * If at least a hint is given, the algorithm will expect that at least + * a hint per disjoint surface is given, ie. that it is safe to only + * follow the surface starting from the hints, and ignoring the parts + * of the grid that are "far" from the hints. + */ + void add_hint(const Cuboid& hint); + + Mesh operator()(); + + private: + const ImplicitSurface& surface; + Cuboid box; + double resolution; + + std::vector hints; +};