mpri-graphics-project/MarchingCubes.cpp

49 lines
1.4 KiB
C++

#include "MarchingCubes.hpp"
const std::vector<MarchingCubes::CubeTri>
MarchingCubes::edges_of_intersection[256] = {
};
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)
{
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 = x + resolution * dx;
double cy = y + resolution * dy;
double cz = z + resolution * dz;
intersections.set_corner(cx, cy, cz,
surface(cx, cy, cz));
}
}
}
}
}
}
return output;
}