volmetrics

changeset 35:df4a277adb82

port to macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 06 Feb 2015 21:15:23 +0200
parents eb87d4a12bd3
children 1df14c5ffa71
files .hgignore Makefile src/main.cc src/mesh.cc src/opengl.h src/sdr.cc src/volume.cc
diffstat 7 files changed, 34 insertions(+), 44 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Fri Feb 06 21:15:23 2015 +0200
     1.3 @@ -0,0 +1,5 @@
     1.4 +\.o$
     1.5 +\.d$
     1.6 +\.swp$
     1.7 +^data/
     1.8 +^test1$
     2.1 --- a/Makefile	Mon Aug 18 10:44:11 2014 +0300
     2.2 +++ b/Makefile	Fri Feb 06 21:15:23 2015 +0200
     2.3 @@ -3,13 +3,21 @@
     2.4  dep = $(obj:.o=.d)
     2.5  bin = test1
     2.6  
     2.7 +warn = -pedantic -Wall
     2.8  dbg = -g
     2.9  opt = -O0
    2.10  inc = -Isrc -I/usr/local/include -I/usr/local/lib
    2.11  
    2.12  CXX = g++
    2.13 -CXXFLAGS = -std=c++11 -pedantic -Wall $(dbg) $(opt) $(inc)
    2.14 -LDFLAGS = -lGL -lGLU -lGLEW -lglut -limago -lm -lmetasurf -lglui
    2.15 +CXXFLAGS = -std=c++11 $(warn) $(dbg) $(opt) $(inc)
    2.16 +LDFLAGS = $(libgl) -limago -lm
    2.17 +
    2.18 +ifeq ($(shell uname -s), Darwin)
    2.19 +	libgl = -framework OpenGL -framework GLUT -lGLEW -lglui
    2.20 +	warn += -Wno-deprecated-declarations
    2.21 +else
    2.22 +	libgl = -lGL -lGLU -lglut -lGLEW -lglui
    2.23 +endif
    2.24  
    2.25  $(bin): $(obj)
    2.26  	$(CXX) -o $@ $(obj) $(LDFLAGS)
     3.1 --- a/src/main.cc	Mon Aug 18 10:44:11 2014 +0300
     3.2 +++ b/src/main.cc	Fri Feb 06 21:15:23 2015 +0200
     3.3 @@ -1,6 +1,4 @@
     3.4 -#include <GL/glew.h>
     3.5 -#include <GL/glut.h>
     3.6 -#include <GL/glui.h>
     3.7 +#include "opengl.h"
     3.8  
     3.9  #include <math.h>
    3.10  #include <stdio.h>
     4.1 --- a/src/mesh.cc	Mon Aug 18 10:44:11 2014 +0300
     4.2 +++ b/src/mesh.cc	Fri Feb 06 21:15:23 2015 +0200
     4.3 @@ -1,4 +1,4 @@
     4.4 -#include <GL/gl.h>
     4.5 +#include "opengl.h"
     4.6  #include "mesh.h"
     4.7  
     4.8  Mesh::Mesh()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/opengl.h	Fri Feb 06 21:15:23 2015 +0200
     5.3 @@ -0,0 +1,15 @@
     5.4 +#ifndef OPENGL_H_
     5.5 +#define OPENGL_H_
     5.6 +
     5.7 +#include <GL/glew.h>
     5.8 +
     5.9 +#ifndef __APPLE__
    5.10 +#include <GL/glut.h>
    5.11 +#else
    5.12 +#include <GLUT/glut.h>
    5.13 +#endif
    5.14 +
    5.15 +#include <GL/glui.h>
    5.16 +
    5.17 +
    5.18 +#endif	// OPENGL_H_
     6.1 --- a/src/sdr.cc	Mon Aug 18 10:44:11 2014 +0300
     6.2 +++ b/src/sdr.cc	Fri Feb 06 21:15:23 2015 +0200
     6.3 @@ -1,5 +1,4 @@
     6.4 -#include <GL/glew.h>
     6.5 -#include <GL/gl.h>
     6.6 +#include "opengl.h"
     6.7  
     6.8  #include <errno.h>
     6.9  #include <stdio.h>
     7.1 --- a/src/volume.cc	Mon Aug 18 10:44:11 2014 +0300
     7.2 +++ b/src/volume.cc	Fri Feb 06 21:15:23 2015 +0200
     7.3 @@ -1,4 +1,4 @@
     7.4 -#include <GL/glew.h>
     7.5 +#include "opengl.h"
     7.6  
     7.7  #include <assert.h>
     7.8  
     7.9 @@ -11,8 +11,6 @@
    7.10  #include <string>
    7.11  #include <vector>
    7.12  
    7.13 -#include <metasurf.h>
    7.14 -
    7.15  #include "mesh.h"
    7.16  #include "volume.h"
    7.17  
    7.18 @@ -228,31 +226,6 @@
    7.19  		(1 - smoothstep(x, high_thres - dt, high_thres + dt));
    7.20  }
    7.21  
    7.22 -static float cb_eval(float x, float y, float z)
    7.23 -{
    7.24 -	const Image *img = cur_vol->get_slice_by_z((z + 1) / 2.0);
    7.25 -	const float *pixels = img->get_pixels();
    7.26 -
    7.27 -	int px = (x + 1) / 2.0 * img->get_width();
    7.28 -	int py = (y + 1) / 2.0 * img->get_height();
    7.29 -
    7.30 -	float val = pixels[px + img->get_width() * py];
    7.31 -	return transfer_function(val, low_thres, high_thres);
    7.32 -}
    7.33 -
    7.34 -static void cb_vertex(float x, float y, float z)
    7.35 -{
    7.36 -	float dx = 1.0 / cur_vol->get_slice(0)->get_width();
    7.37 -	float dy = 1.0 / cur_vol->get_slice(0)->get_height();
    7.38 -	float dz = 1.0 / cur_vol->get_slice_count();
    7.39 -	float dfdx = cb_eval(x - dx, y, z) - cb_eval(x + dx, y, z);
    7.40 -	float dfdy = cb_eval(x, y - dy, z) - cb_eval(x, y + dy, z);
    7.41 -	float dfdz = cb_eval(x, y, z - dz) - cb_eval(x, y, z + dz);
    7.42 -
    7.43 -	cur_mesh->add_normal(Vector3(dfdx, dfdy, dfdz));
    7.44 -	cur_mesh->add_vertex(Vector3(x, y, z));
    7.45 -}
    7.46 -
    7.47  void Volume::create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres)
    7.48  {
    7.49  	if (tmin > tmax) {
    7.50 @@ -271,14 +244,6 @@
    7.51  
    7.52  	cur_mesh = mesh;
    7.53  	cur_vol = this;
    7.54 -
    7.55 -	metasurface *ms = msurf_create();
    7.56 -	msurf_threshold(ms, 0.5);
    7.57 -	msurf_resolution(ms, xres, yres, zres);
    7.58 -	msurf_vertex_func(ms, cb_vertex);
    7.59 -	msurf_eval_func(ms, cb_eval);
    7.60 -	msurf_polygonize(ms);
    7.61 -	msurf_free(ms);
    7.62  }
    7.63  
    7.64  void Volume::draw() const