volmetrics

diff src/volume.cc @ 11:c5af275b6a60

fixed normals
author Eleni Maria Stea <elene.mst@gmail.com>
date Mon, 27 Jan 2014 01:22:02 +0200
parents 40febfed6cff
children 1272e3335608
line diff
     1.1 --- a/src/volume.cc	Sun Jan 26 23:18:13 2014 +0200
     1.2 +++ b/src/volume.cc	Mon Jan 27 01:22:02 2014 +0200
     1.3 @@ -180,6 +180,19 @@
     1.4  	return pixels[px + img->get_width() * py];
     1.5  }
     1.6  
     1.7 +static void cb_vertex(float x, float y, float z)
     1.8 +{
     1.9 +	float dx = 1.0 / cur_vol->get_slice(0)->get_width();
    1.10 +	float dy = 1.0 / cur_vol->get_slice(0)->get_height();
    1.11 +	float dz = 1.0 / cur_vol->get_slice_count();
    1.12 +	float dfdx = cb_eval(x - dx, y, z) - cb_eval(x + dx, y, z);
    1.13 +	float dfdy = cb_eval(x, y - dy, z) - cb_eval(x, y + dy, z);
    1.14 +	float dfdz = cb_eval(x, y, z - dz) - cb_eval(x, y, z + dz);
    1.15 +
    1.16 +	cur_mesh->add_normal(Vector3(dfdx, dfdy, dfdz));
    1.17 +	cur_mesh->add_vertex(Vector3(x, y, z));
    1.18 +}
    1.19 +
    1.20  void Volume::create_mesh(Mesh *mesh, float threshold)
    1.21  {
    1.22  	cur_mesh = mesh;
    1.23 @@ -188,11 +201,7 @@
    1.24  	metasurface *ms = msurf_create();
    1.25  	msurf_threshold(ms, threshold);
    1.26  	msurf_resolution(ms, width, height, slices.size());
    1.27 -	msurf_vertex_func(ms,
    1.28 -			[](float x, float y, float z){cur_mesh->add_vertex(Vector3(x, y, z));});
    1.29 -	msurf_normal_func(ms,
    1.30 -			[](float x, float y, float z){cur_mesh->add_normal(Vector3(x, y, z));});
    1.31 -
    1.32 +	msurf_vertex_func(ms, cb_vertex);
    1.33  	msurf_eval_func(ms, cb_eval);
    1.34  	msurf_polygonize(ms);
    1.35  	msurf_free(ms);