#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; };