Add a context to implement marching cubes

This commit is contained in:
Théophile Bastian 2018-02-07 18:00:01 +01:00
parent 4e41e88462
commit 8b98f373bc
3 changed files with 83 additions and 0 deletions

View file

@ -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)

33
MarchingCubes.cpp Normal file
View file

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

48
MarchingCubes.hpp Normal file
View file

@ -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''
* <http://fab.cba.mit.edu/classes/S62.12/docs/Lorensen_marching_cubes.pdf>
*/
#include <vector>
#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<Cuboid> hints;
};