Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_VOLUME_RENDERING_VOLUME_RENDERING_PREINTEGRATED_COLOR_TABLE_H
00002 #define OPENTISSUE_UTILITY_VOLUME_RENDERING_VOLUME_RENDERING_PREINTEGRATED_COLOR_TABLE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/texture/texture_texture2D.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace volume_rendering
00017 {
00018
00026 template<typename image_type>
00027 OpenTissue::texture::texture2D_pointer compute_1D_preintegration_color_table( image_type const & color_table )
00028 {
00029 typedef typename image_type::value_type value_type;
00030 typedef float real_type;
00031
00032 unsigned int entries = color_table.width();
00033 unsigned int rows = color_table.height();
00034 unsigned int channels = color_table.channels();
00035
00036 assert(rows==1 || !"compute_1D_preintegration_color_table(): Color table image must have exactly one row");
00037 assert(entries>0 || !"compute_1D_preintegration_color_table(): Color table image must positive number of entries");
00038 assert(channels==4 || !"compute_1D_preintegration_color_table(): Color table image must have four color components");
00039
00040 image_type preintegration;
00041 preintegration.create(entries, 1, channels);
00042
00043 real_type tauc = 0;
00044 real_type r = 0;
00045 real_type g = 0;
00046 real_type b = 0;
00047 real_type a = 0;
00048
00049 preintegration(0,0,0) = r;
00050 preintegration(0,0,1) = g;
00051 preintegration(0,0,2) = b;
00052 preintegration(0,0,3) = a;
00053 for ( unsigned int i = 1; i < entries; ++i )
00054 {
00055 real_type alpha = color_table( i,0,3);
00056 real_type alpha_m1 = color_table(i-1,0,3);
00057 real_type red = color_table( i,0,0);
00058 real_type red_m1 = color_table(i-1,0,0);
00059 real_type green = color_table( i,0,1);
00060 real_type green_m1 = color_table(i-1,0,1);
00061 real_type blue = color_table( i,0,2);
00062 real_type blue_m1 = color_table(i-1,0,2);
00063
00064 tauc = ( alpha_m1 + alpha ) / 2.0;
00065 r = r + ( red_m1 + red ) / 2.0 * tauc;
00066 g = g + ( green_m1 + green ) / 2.0 * tauc;
00067 b = b + ( blue_m1 + blue ) / 2.0 * tauc;
00068 a = a + tauc;
00069
00070 preintegration(i,0,0) = r;
00071 preintegration(i,0,1) = g;
00072 preintegration(i,0,2) = b;
00073 preintegration(i,0,3) = a;
00074 }
00075 return preintegration.create_texture(GL_RGBA);
00076 }
00077
00078 }
00079 }
00080
00081
00082 #endif