volmetrics

diff src/volume.cc @ 9:40febfed6cff

rendering isosurfaces / added simple gui
author Eleni Maria Stea <elene.mst@gmail.com>
date Sun, 26 Jan 2014 23:13:37 +0200
parents 928954bfefd7
children c5af275b6a60
line diff
     1.1 --- a/src/volume.cc	Sat Jan 25 19:25:32 2014 +0200
     1.2 +++ b/src/volume.cc	Sun Jan 26 23:13:37 2014 +0200
     1.3 @@ -10,6 +10,9 @@
     1.4  #include <string>
     1.5  #include <vector>
     1.6  
     1.7 +#include <metasurf.h>
     1.8 +
     1.9 +#include "mesh.h"
    1.10  #include "volume.h"
    1.11  
    1.12  static char *strip_whitespaces(char *buf);
    1.13 @@ -163,6 +166,38 @@
    1.14  	return vol_tex;
    1.15  }
    1.16  
    1.17 +static Mesh *cur_mesh;
    1.18 +static Volume *cur_vol;
    1.19 +
    1.20 +static float cb_eval(float x, float y, float z)
    1.21 +{
    1.22 +	const Image *img = cur_vol->get_slice_by_z((z + 1) / 2.0);
    1.23 +	const float *pixels = img->get_pixels();
    1.24 +
    1.25 +	int px = (x + 1) / 2.0 * img->get_width();
    1.26 +	int py = (y + 1) / 2.0 * img->get_height();
    1.27 +
    1.28 +	return pixels[px + img->get_width() * py];
    1.29 +}
    1.30 +
    1.31 +void Volume::create_mesh(Mesh *mesh, float threshold)
    1.32 +{
    1.33 +	cur_mesh = mesh;
    1.34 +	cur_vol = this;
    1.35 +
    1.36 +	metasurface *ms = msurf_create();
    1.37 +	msurf_threshold(ms, threshold);
    1.38 +	msurf_resolution(ms, width, height, slices.size());
    1.39 +	msurf_vertex_func(ms,
    1.40 +			[](float x, float y, float z){cur_mesh->add_vertex(Vector3(x, y, z));});
    1.41 +	msurf_normal_func(ms,
    1.42 +			[](float x, float y, float z){cur_mesh->add_normal(Vector3(x, y, z));});
    1.43 +
    1.44 +	msurf_eval_func(ms, cb_eval);
    1.45 +	msurf_polygonize(ms);
    1.46 +	msurf_free(ms);
    1.47 +}
    1.48 +
    1.49  void Volume::draw() const
    1.50  {
    1.51  }