Marching: add test implicit surface and main

The test surface is the sphere TestImplicitSphere
This commit is contained in:
Théophile Bastian 2018-02-11 20:23:07 +01:00
parent 4a3a1b9d76
commit 52ca47cde6
4 changed files with 57 additions and 0 deletions

View file

@ -12,6 +12,7 @@ OBJS=Implicit.o \
util/ObjParser.o \
MarchingCubes.o \
_gen/marching_cubes_data.o \
tests/TestImplicitSphere.o \
render/GlutRender.o
all: $(TARGETS:=.bin)

33
main_test_sphere.cpp Normal file
View file

@ -0,0 +1,33 @@
/** An entry-point file using render/GlutRender as a renderer, displaying a
* simple sphere.
**/
#include "render/GlutRender.hpp"
#include "util/ObjParser.hpp"
#include "tests/TestImplicitSphere.hpp"
#include "Mesh.hpp"
#include "MarchingCubes.hpp"
int main(int argc, char** argv) {
GlutRender& render = GlutRender::get_instance();
render.init(&argc, argv, 640, 480, "Bouncing stuff");
TestImplicitSphere sph1(Point(2.5, -1, 0), 1);
TestImplicitSphere sph2(Point(-4, 0.5, 0), 1.4);
Mesh m_sph1 = MarchingCubes(sph1,
Cuboid(Point(1, -2, -2), Point(3, 0, 2)))();
Mesh m_sph2 = MarchingCubes(sph2,
Cuboid(Point(-6, -2, -2), Point(2, 3, 2)))();
render.add_mesh(&m_sph1);
render.add_mesh(&m_sph2);
puts("=== All set! ===");
printf("Sph1 has %ld vertices, %ld faces.\n",
m_sph1.get_vertices().size(),
m_sph1.get_faces().size());
render.run();
return 0;
}

View file

@ -0,0 +1,9 @@
#include "TestImplicitSphere.hpp"
double TestImplicitSphere::operator()(double x, double y, double z) const {
auto sq = [](double x) { return x*x; };
return - (sq(center.x - x)
+ sq(center.y - y)
+ sq(center.z - z))
+ sq(radius);
}

View file

@ -0,0 +1,14 @@
#pragma once
#include "../Implicit.hpp"
class TestImplicitSphere: public ImplicitSurface {
public:
TestImplicitSphere(const Point& center, double r):
center(center), radius(r) {}
virtual double operator()(double x, double y, double z) const;
private:
Point center;
double radius;
};