Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_VOLUME_RENDERING_SLABBING_VOLUME_RENDERING_SHADER_SLABBING_SHADER_H
00002 #define OPENTISSUE_UTILITY_VOLUME_RENDERING_SLABBING_VOLUME_RENDERING_SHADER_SLABBING_SHADER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/cg/cg_program.h>
00013 #include <OpenTissue/core/geometry/geometry_obb_z_slicer.h>
00014 #include <OpenTissue/utility/volume_rendering/volume_rendering_volume_shader.h>
00015
00016 #include <string>
00017
00018 namespace OpenTissue
00019 {
00020 namespace volume_rendering
00021 {
00022
00026 template<typename math_types>
00027 class SlabbingShader
00028 : public VolumeShader< SlabbingShader<math_types> >
00029 {
00030 public:
00031
00032 typedef typename math_types::real_type real_type;
00033 typedef typename math_types::vector3_type vector3_type;
00034
00035 protected:
00036
00037 cg::Program m_vertex_program;
00038 cg::Program m_fragment_program;
00039 unsigned int m_slice_cnt;
00040 GLfloat m_eye2model_matrix[16];
00041
00042 public:
00043
00044 SlabbingShader()
00045 : m_vertex_program()
00046 , m_fragment_program()
00047 , m_slice_cnt(64)
00048 {
00049 }
00050
00051 public:
00052
00053 void init(){};
00054
00055 bool front2back()const{ return false; }
00056
00057 template<typename texture2d_pointer>
00058 void pre_render ( texture2d_pointer & color_table )
00059 {
00060 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT );
00061
00062
00063 glEnable( GL_BLEND );
00064 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
00065 glDisable( GL_LIGHTING );
00066 glDisable( GL_DEPTH_TEST );
00067 glEnable( GL_ALPHA_TEST );
00068 glAlphaFunc(GL_GREATER, 0.01 );
00069
00070 GLfloat model2eye_matrix[16];
00071 glGetFloatv( GL_MODELVIEW_MATRIX, model2eye_matrix );
00072 gl::invert( model2eye_matrix, m_eye2model_matrix );
00073
00074
00075 static std::string path = opentissue_path + "/OpenTissue/utility/volume_rendering/slabbing_shader/";
00076
00077 if(!m_vertex_program.is_program_loaded())
00078 m_vertex_program.load_from_file(cg::Program::vertex_program,path + "/vp.cg");
00079
00080 m_vertex_program.set_modelview_projection_matrix();
00081 m_vertex_program.set_modelview_inverse_matrix();
00082 m_vertex_program.enable();
00083
00084
00085 if(!m_fragment_program.is_program_loaded())
00086 m_fragment_program.load_from_file(cg::Program::fragment_program,path + "/fp.cg");
00087
00088 m_fragment_program.set_input_texture( "color_table" , color_table );
00089 m_fragment_program.enable();
00090 }
00091
00092 template<typename tile_type>
00093 void render(tile_type const & tile)
00094 {
00095 using std::fabs;
00096
00097 static vector3_type slice[8];
00098 real_type slab_width = fabs(tile.m_min_depth - tile.m_max_depth)/(m_slice_cnt-1);
00099 m_fragment_program.set_input_texture( "volume" , tile.m_volume_texture );
00100 for ( unsigned int s = 0; s < m_slice_cnt; ++s )
00101 {
00102 real_type t = (1.0 + s) / (1.0 + m_slice_cnt);
00103 real_type depth = (tile.m_max_depth-tile.m_min_depth)*t + tile.m_min_depth;
00104 unsigned int slice_size = OpenTissue::geometry::obb_z_slice(tile.m_eye_vertices,depth,slice);
00105 glBegin( GL_TRIANGLE_FAN );
00106 for ( unsigned int i = 0; i < slice_size; ++i )
00107 {
00108 slice[i] = gl::xform( m_eye2model_matrix, slice[i]);
00109 glMultiTexCoord1f(GL_TEXTURE0, slab_width );
00110 glMultiTexCoord3f(GL_TEXTURE1, tile.m_tile_min_x, tile.m_tile_min_y, tile.m_tile_min_z );
00111 glMultiTexCoord3f(GL_TEXTURE2, tile.m_tile_width, tile.m_tile_height, tile.m_tile_depth );
00112 glVertex3f( slice[ i ][ 0 ], slice[ i ][ 1 ], slice[ i ][ 2 ] );
00113 }
00114 glEnd();
00115 }
00116 }
00117
00118 void post_render()
00119 {
00120 m_fragment_program.disable();
00121 m_vertex_program.disable();
00122 glPopAttrib( );
00123 }
00124 };
00125
00126 }
00127 }
00128
00129
00130 #endif