glviewvol

diff src/xfer_view.cc @ 14:0d2447b9c512

did the histogram... doesn't seem to work right
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 01 Jan 2015 06:36:45 +0200
parents 773f89037a35
children
line diff
     1.1 --- a/src/xfer_view.cc	Wed Dec 31 07:57:42 2014 +0200
     1.2 +++ b/src/xfer_view.cc	Thu Jan 01 06:36:45 2015 +0200
     1.3 @@ -20,8 +20,12 @@
     1.4  #include "opengl.h"
     1.5  #include "xfer_view.h"
     1.6  #include "viewer.h"
     1.7 +#include "volume.h"
     1.8 +
     1.9 +static void draw_histogram();
    1.10  
    1.11  static TransferFunc *xfer;
    1.12 +static Volume *vol;
    1.13  
    1.14  static int act_color = -1;
    1.15  static int grabbed_handle = -1;
    1.16 @@ -37,6 +41,11 @@
    1.17  {
    1.18  }
    1.19  
    1.20 +void xfview_set_volume(Volume *volarg)
    1.21 +{
    1.22 +	vol = volarg;
    1.23 +}
    1.24 +
    1.25  void xfview_draw()
    1.26  {
    1.27  	float line_color[][3] = {
    1.28 @@ -64,6 +73,8 @@
    1.29  	glVertex2f(-1, 1);
    1.30  	glEnd();
    1.31  
    1.32 +	draw_histogram();
    1.33 +
    1.34  	glEnable(GL_LINE_SMOOTH);
    1.35  
    1.36  	glEnable(GL_BLEND);
    1.37 @@ -191,6 +202,40 @@
    1.38  	glDisable(GL_BLEND);
    1.39  }
    1.40  
    1.41 +#define HIST_SAMPLES	256
    1.42 +
    1.43 +static void draw_histogram()
    1.44 +{
    1.45 +	VoxelVolume *voxvol = dynamic_cast<VoxelVolume*>(vol);
    1.46 +	if(!voxvol) return;
    1.47 +
    1.48 +	float *hist = voxvol->calc_histogram(HIST_SAMPLES);
    1.49 +	if(!hist) return;
    1.50 +
    1.51 +	float max_y = 0.0f;
    1.52 +	for(int i=0; i<HIST_SAMPLES; i++) {
    1.53 +		if(hist[i] > max_y) {
    1.54 +			max_y = hist[i];
    1.55 +		}
    1.56 +	}
    1.57 +
    1.58 +	float dx = 1.0 / (float)HIST_SAMPLES;
    1.59 +	glBegin(GL_QUADS);
    1.60 +	glColor3f(0.6, 0.6, 0.6);
    1.61 +	for(int i=0; i<HIST_SAMPLES; i++) {
    1.62 +		float x0 = (float)i / (float)HIST_SAMPLES;
    1.63 +		float x1 = x0 + dx;
    1.64 +
    1.65 +		float y = hist[i] / max_y;
    1.66 +
    1.67 +		glVertex2f(x0, 0);
    1.68 +		glVertex2f(x1, 0);
    1.69 +		glVertex2f(x1, y);
    1.70 +		glVertex2f(x0, y);
    1.71 +	}
    1.72 +	glEnd();
    1.73 +}
    1.74 +
    1.75  static int prev_x, prev_y;
    1.76  
    1.77  void xfview_button(int bn, int press, int x, int y)