Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_IMAGE_IMAGE_H
00002 #define OPENTISSUE_GPU_IMAGE_IMAGE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/texture/texture_texture2D.h>
00013 #include <OpenTissue/gpu/texture/texture_types.h>
00014
00015 #include <iostream>
00016 #include <vector>
00017 #include <algorithm>
00018 #include <cassert>
00019
00020 namespace OpenTissue
00021 {
00022 namespace image
00023 {
00024
00028 template<typename T>
00029 class Image
00030 {
00031 public:
00032
00033 typedef T value_type;
00034
00035 protected:
00036
00037 size_t m_width;
00038 size_t m_height;
00039 size_t m_channels;
00040 std::vector<T> m_data;
00041
00042 public:
00043
00044 size_t width() const { return m_width; }
00045 size_t height() const { return m_height; }
00046 size_t channels() const { return m_channels; }
00047
00048 T & operator()(size_t x,size_t y,size_t channel)
00049 {
00050 return m_data[(y*m_width + x)*m_channels + channel];
00051 }
00052
00053 T const & operator()(size_t x,size_t y,size_t channel) const
00054 {
00055 return m_data[(y*m_width + x)*m_channels + channel];
00056 }
00057
00058 void * get_data() { return &(m_data[0]); }
00059 void const * get_data() const { return &(m_data[0]); }
00060
00061 public:
00062
00063 Image()
00064 : m_width(0)
00065 , m_height(0)
00066 , m_channels(0)
00067 , m_data(0)
00068 {}
00069
00070 Image( size_t width, size_t height, size_t channels, T const * data)
00071 : m_width(width)
00072 , m_height(height)
00073 , m_channels(channels)
00074 , m_data( data, data+(width*height*channels) )
00075 {}
00076
00077 Image( size_t width, size_t height, size_t channels, std::vector<T> const & data )
00078 : m_width(width)
00079 , m_height(height)
00080 , m_channels(channels)
00081 , m_data(data)
00082 {}
00083
00084 Image( size_t width, size_t height, size_t channels )
00085 : m_width(width)
00086 , m_height(height)
00087 , m_channels(channels)
00088 , m_data(width*height*channels)
00089 {}
00090
00091 public:
00092
00093 void create( size_t width, size_t height, size_t channels )
00094 {
00095 m_width = width;
00096 m_height = height;
00097 m_channels = channels;
00098 m_data.resize(width*height*channels);
00099 std::fill(m_data.begin(),m_data.end(),static_cast<T>(0));
00100 }
00101
00108 OpenTissue::texture::texture2D_pointer create_texture(
00109 size_t internal_format
00110 , bool rectangular=false
00111 , int border=0
00112 ) const
00113 {
00114 size_t ext_format = OpenTissue::texture::external_format( m_channels );
00115 OpenTissue::texture::texture2D_pointer tex(
00116 new OpenTissue::texture::Texture2D(
00117 internal_format
00118 , m_width
00119 , m_height
00120 , ext_format
00121 , OpenTissue::texture::external_type<T>()
00122 , &m_data[0]
00123 , rectangular
00124 , border
00125 )
00126 );
00127 return tex;
00128 }
00129
00130 };
00131
00132 }
00133 }
00134
00135
00136 #endif