# HG changeset patch # User John Tsiombikas # Date 1420087005 -7200 # Node ID 0d2447b9c512b97a419c72a9c689fd6299962ce9 # Parent 64f874301b53764a871082364e5a5727b12ea60e did the histogram... doesn't seem to work right diff -r 64f874301b53 -r 0d2447b9c512 src/viewer.cc --- a/src/viewer.cc Wed Dec 31 07:57:42 2014 +0200 +++ b/src/viewer.cc Thu Jan 01 06:36:45 2015 +0200 @@ -71,6 +71,7 @@ if(!xfview_init(xfer)) { return -1; } + xfview_set_volume(vol); return 0; } diff -r 64f874301b53 -r 0d2447b9c512 src/volume.cc --- a/src/volume.cc Wed Dec 31 07:57:42 2014 +0200 +++ b/src/volume.cc Thu Jan 01 06:36:45 2015 +0200 @@ -94,6 +94,10 @@ VoxelVolume::VoxelVolume() { size[0] = size[1] = size[2] = 0; + + hist_valid = false; + hist = 0; + num_hist_samples = 0; } VoxelVolume::~VoxelVolume() @@ -151,6 +155,7 @@ } size[2] = slices.size(); + hist_valid = false; fclose(fp); return true; } @@ -223,6 +228,39 @@ return slices[z].pixels[y * size[0] + x]; } +float *VoxelVolume::calc_histogram(int hist_samples) +{ + if(hist && hist_samples == num_hist_samples && hist_valid) { + return hist; + } + + int num_pixels = size[0] * size[1] * size[2]; + if(!num_pixels) { + return 0; + } + + delete [] hist; + hist = new float[hist_samples]; + memset(hist, 0, hist_samples * sizeof *hist); + + for(int i=0; i slices; + float *hist; + int num_hist_samples; + bool hist_valid; + public: VoxelVolume(); ~VoxelVolume(); @@ -52,6 +56,8 @@ float valuef(float x, float y, float z) const; float valuei(int x, int y, int z) const; + + float *calc_histogram(int hist_samples); }; #endif // VOLUME_H_ diff -r 64f874301b53 -r 0d2447b9c512 src/xfer_view.cc --- a/src/xfer_view.cc Wed Dec 31 07:57:42 2014 +0200 +++ b/src/xfer_view.cc Thu Jan 01 06:36:45 2015 +0200 @@ -20,8 +20,12 @@ #include "opengl.h" #include "xfer_view.h" #include "viewer.h" +#include "volume.h" + +static void draw_histogram(); static TransferFunc *xfer; +static Volume *vol; static int act_color = -1; static int grabbed_handle = -1; @@ -37,6 +41,11 @@ { } +void xfview_set_volume(Volume *volarg) +{ + vol = volarg; +} + void xfview_draw() { float line_color[][3] = { @@ -64,6 +73,8 @@ glVertex2f(-1, 1); glEnd(); + draw_histogram(); + glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); @@ -191,6 +202,40 @@ glDisable(GL_BLEND); } +#define HIST_SAMPLES 256 + +static void draw_histogram() +{ + VoxelVolume *voxvol = dynamic_cast(vol); + if(!voxvol) return; + + float *hist = voxvol->calc_histogram(HIST_SAMPLES); + if(!hist) return; + + float max_y = 0.0f; + for(int i=0; i max_y) { + max_y = hist[i]; + } + } + + float dx = 1.0 / (float)HIST_SAMPLES; + glBegin(GL_QUADS); + glColor3f(0.6, 0.6, 0.6); + for(int i=0; i