Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_VOLUME_RENDERING_VOLUME_RENDERING_COLOR_TABLE_H
00002 #define OPENTISSUE_UTILITY_VOLUME_RENDERING_VOLUME_RENDERING_COLOR_TABLE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/image/image.h>
00013 #include <OpenTissue/gpu/image/image_make_noise.h>
00014 #include <OpenTissue/gpu/texture/texture_texture2D.h>
00015
00016 #include <OpenTissue/core/math/math_constants.h>
00017
00018
00019 namespace OpenTissue
00020 {
00021 namespace volume_rendering
00022 {
00023
00028 typedef OpenTissue::image::Image<unsigned char> color_table_type;
00029 typedef boost::shared_ptr<color_table_type> color_table_pointer;
00030
00038 template< typename histogram_type, typename image_type >
00039 void compute_histogram_color_table( unsigned int entries, histogram_type const & histogram, image_type & color_table )
00040 {
00041 using std::fabs;
00042
00043 typedef typename image_type::value_type value_type;
00044 typedef float real_type;
00045
00046 unsigned int N = histogram.size();
00047 std::vector<real_type> H,D;
00048 H.resize(N);
00049 D.resize(N);
00050 for(unsigned int idx=0;idx<N;++idx)
00051 H[idx] = histogram[idx];
00052
00053
00054 D[0] = H[1] - H[0];
00055 D[N-1] = H[N-2] - H[N-1];
00056 for(unsigned int i=1;i<N-1;++i)
00057 D[i] = (H[i+1] - H[i-1])*.5;
00058
00059
00060 assert(entries>0 || !"");
00061 std::vector<unsigned int> region_lut;
00062 region_lut.resize(entries);
00063 real_type nominator = static_cast<real_type>(entries);
00064
00065 real_type old_slope = D[0];
00066 unsigned int region = 0;
00067 region_lut[0] = region;
00068 for(unsigned int idx=1;idx<entries;++idx)
00069 {
00070 unsigned int i = static_cast<unsigned int>( ( idx /nominator) *N );
00071 real_type cur_slope = D[i];
00072
00073 if(cur_slope*old_slope<0.0)
00074 {
00075 ++region;
00076 }
00077 region_lut[idx] = region;
00078 old_slope = cur_slope;
00079 }
00080
00081 assert(entries>0 || !"");
00082 color_table.create(entries, 1, 4);
00083 value_type high = math::detail::highest<value_type>();
00084 value_type low = math::detail::lowest<value_type>();
00085 for(unsigned int i=0;i<entries;++i)
00086 {
00087 real_type t = (1.0*region_lut[i]) / (1.0*region);
00088 value_type I = static_cast<value_type>( t * (high-low) + low );
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 color_table(i,0,0) = I; color_table(i,0,1) = I; color_table(i,0,2) = I;
00118 color_table(i,0,3) = high;
00119 }
00120 }
00121
00135 template<typename image_type >
00136 void compute_linear_color_table( unsigned int entries, image_type & color_table, bool reverse = false, bool transparency = false)
00137 {
00138 typedef typename image_type::value_type value_type;
00139 typedef float real_type;
00140 assert(entries>0 || !"");
00141 color_table.create(entries, 1, 4);
00142
00143 value_type high = math::detail::highest<value_type>();
00144 value_type low = math::detail::lowest<value_type>();
00145
00146 real_type nominator = static_cast<real_type>(entries);
00147 for(unsigned int i=0;i<entries;++i)
00148 {
00149 real_type t = (i /nominator) ;
00150 value_type tmp = static_cast<value_type>( t * (high-low) + low );
00151 value_type I = reverse? high - tmp: tmp;
00152 color_table(i,0,0) = I;
00153 color_table(i,0,1) = I;
00154 color_table(i,0,2) = I;
00155 color_table(i,0,3) = transparency?I:high;
00156 }
00157 }
00158
00159
00160
00170 template<typename image_type >
00171 void compute_noise_color_table( unsigned int entries, image_type & color_table)
00172 {
00173 typedef typename image_type::value_type value_type;
00174 typedef float real_type;
00175 assert(entries>0 || !"");
00176 color_table.create(entries, 1, 4);
00177 make_noise(color_table);
00178 }
00179
00180
00181 }
00182 }
00183
00184
00185 #endif