volmetrics
diff src/volume.cc @ 34:eb87d4a12bd3
histogram
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Mon, 18 Aug 2014 10:44:11 +0300 |
parents | e548d95e0667 |
children | df4a277adb82 |
line diff
1.1 --- a/src/volume.cc Sun Aug 17 02:25:01 2014 +0300 1.2 +++ b/src/volume.cc Mon Aug 18 10:44:11 2014 +0300 1.3 @@ -4,6 +4,7 @@ 1.4 1.5 #include <ctype.h> 1.6 #include <errno.h> 1.7 +#include <float.h> 1.8 #include <stdio.h> 1.9 #include <string.h> 1.10 1.11 @@ -24,6 +25,9 @@ 1.12 x_rot = 0; 1.13 vol_tex_valid = false; 1.14 1.15 + memset(histogram, 0, HIST_SIZE * sizeof(int)); 1.16 + max_histogram_value = 0; 1.17 + 1.18 glGenTextures(1, &vol_tex); 1.19 } 1.20 1.21 @@ -55,6 +59,31 @@ 1.22 } 1.23 } 1.24 1.25 +void Volume::create_histogram() 1.26 +{ 1.27 + if (slices.empty()) 1.28 + return; 1.29 + 1.30 + for (size_t i=0; i<slices.size(); i++) 1.31 + { 1.32 + float *slice_pixels = (float*)slices[i].get_pixels(); 1.33 + for (int j=0; j < width * height; j++) 1.34 + { 1.35 + float val = slice_pixels[j]; 1.36 + 1.37 + int ival = (int)(val * 256); 1.38 + histogram[ival]++; 1.39 + } 1.40 + } 1.41 + 1.42 + max_histogram_value = 0; 1.43 + for (int i=0; i<HIST_SIZE; i++) { 1.44 + if (i < 10) 1.45 + continue; 1.46 + max_histogram_value = std::max(max_histogram_value, histogram[i]); 1.47 + } 1.48 +} 1.49 + 1.50 bool Volume::load(const char *fname) 1.51 { 1.52 char up = 'y'; 1.53 @@ -110,6 +139,7 @@ 1.54 if (up == 'z') 1.55 x_rot = 90; 1.56 1.57 + create_histogram(); 1.58 return true; 1.59 } 1.60