diff --git a/Implicit.hpp b/Implicit.hpp index 721f963..9e1ea0d 100644 --- a/Implicit.hpp +++ b/Implicit.hpp @@ -8,11 +8,16 @@ class ImplicitSurface { double operator()(const Point& pt) const; Point getCenter() const { return center;} + const Color& get_color() const { return color; } + void set_color(const Color& _color) { color = _color; } + virtual Point location_hint() const = 0; /// Compute the normal vector to the isosurface at `pt` Point normal_at(const Point& pt) const; protected: Point center; + Color color; + ImplicitSurface(Point _center) : center(_center) {} }; diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp index 90d93a0..f890fcc 100644 --- a/MarchingCubes.cpp +++ b/MarchingCubes.cpp @@ -24,6 +24,8 @@ MarchingCubes& MarchingCubes::add_hint(const Point& hint) { Mesh MarchingCubes::operator()() { Mesh output; + output.set_color(surface.get_color()); + perf_counter = 0; if(hints.empty()) @@ -31,7 +33,9 @@ Mesh MarchingCubes::operator()() { else with_hints(output); - printf("Explored cubes: %ld\n", perf_counter); +#ifdef MC_SHOW_PERF + fprintf(stderr, "Explored cubes: %ld\n", perf_counter); +#endif // MC_SHOW_PERF output.translate(surface.getCenter()); diff --git a/Mesh.hpp b/Mesh.hpp index fe06831..00514a0 100644 --- a/Mesh.hpp +++ b/Mesh.hpp @@ -41,6 +41,9 @@ class Mesh { /// Gets the various faces const std::vector& get_faces() const; + const Color& get_color() const { return color; } + void set_color(const Color& _color) { color = _color; } + private: //struct struct NormalVect { NormalVect(const Point& vect, bool manual=false) @@ -63,4 +66,5 @@ class Mesh { std::vector > faces_with_vert; Point center; + Color color; }; diff --git a/common_structures.hpp b/common_structures.hpp index 014aa7c..66240f9 100644 --- a/common_structures.hpp +++ b/common_structures.hpp @@ -152,6 +152,20 @@ class Cuboid { Point lowBound, highBound; }; +struct Color { + Color() : r(0), g(0), b(0) {} + Color(double r, double g, double b) : r(r), g(g), b(b) {} + double r, g, b; + double operator[](int i) const { + switch(i % 3) { + case 0: return r; + case 1: return g; + case 2: return b; + } + return 0; // won't happen + } +}; + namespace std { template<> struct hash { diff --git a/render/GlutRender.cpp b/render/GlutRender.cpp index 0bdf988..7a791e5 100644 --- a/render/GlutRender.cpp +++ b/render/GlutRender.cpp @@ -149,8 +149,15 @@ void GlutRender::display_mesh(Mesh& mesh) const { #endif // DEBUG_DISPLAY_WIREFRAME + const Color& color = mesh.get_color(); + GLfloat material_specular[] = { + (float)color[0], + (float)color[1], + (float)color[2], + 1.}; glBegin(GL_TRIANGLES); - glColor3f(1., 1., 1.); + glColor3f(color[0], color[1], color[2]); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular); for(const Face& face: mesh.get_faces()) { Point p0 = face.pt(0, points) + mesh_center, p1 = face.pt(1, points) + mesh_center,