Structural deformable models
Public Member Functions | Protected Attributes | List of all members
GLImage Class Reference

#include <glImage.h>

Public Member Functions

 GLImage ()
 
 GLImage (const std::vector< Image< byte > > &image)
 
 GLImage (const Image< byte > &image)
 
 ~GLImage ()
 
void setImage (const Image< byte > &image)
 
void setImage (const std::vector< Image< byte > > &image)
 
void unsetImage ()
 
bool bindTexture () const
 
void draw (float x, float y, float sx=1.f, float sy=1.f) const
 
 operator bool () const
 
float getSizeX () const
 
float getSizeY () const
 

Protected Attributes

GLuint m_gltexture
 
int m_sx
 
int m_sy
 
float m_tx
 
float m_ty
 
bool m_Initialized
 

Detailed Description

Definition at line 9 of file glImage.h.

Constructor & Destructor Documentation

GLImage::GLImage ( )
inline

Definition at line 11 of file glImage.h.

11 : m_Initialized(false) {}
bool m_Initialized
Definition: glImage.h:106
GLImage::GLImage ( const std::vector< Image< byte > > &  image)
inline

Definition at line 12 of file glImage.h.

References setImage().

12  : m_Initialized(false)
13  {
14  setImage(image);
15  }
void setImage(const Image< byte > &image)
Definition: glImage.h:27
bool m_Initialized
Definition: glImage.h:106
GLImage::GLImage ( const Image< byte > &  image)
inline

Definition at line 17 of file glImage.h.

References setImage().

17  : m_Initialized(false)
18  {
19  setImage(image);
20  }
void setImage(const Image< byte > &image)
Definition: glImage.h:27
bool m_Initialized
Definition: glImage.h:106
GLImage::~GLImage ( )
inline

Definition at line 22 of file glImage.h.

References unsetImage().

23  {
24  unsetImage();
25  }
void unsetImage()
Definition: glImage.h:72

Member Function Documentation

bool GLImage::bindTexture ( ) const
inline

Definition at line 79 of file glImage.h.

References m_gltexture, and m_Initialized.

Referenced by draw().

80  {
81  if(m_Initialized) glBindTexture(GL_TEXTURE_2D, m_gltexture);
82  return m_Initialized;
83  }
bool m_Initialized
Definition: glImage.h:106
GLuint m_gltexture
Definition: glImage.h:103
void GLImage::draw ( float  x,
float  y,
float  sx = 1.f,
float  sy = 1.f 
) const
inline

Definition at line 85 of file glImage.h.

References bindTexture(), m_sx, m_sy, m_tx, and m_ty.

Referenced by Dataset::draw().

86  {
87  if(!bindTexture()) return;
88  float bx = x + sx*m_sx;
89  float by = y + sy*m_sy;
90  glBegin(GL_QUADS);// Begin Drawing The Textured Quad
91  glTexCoord2f(0.0f, 0.0f); glVertex2f( x, y);
92  glTexCoord2f(m_tx, 0.0f); glVertex2f( bx, y);
93  glTexCoord2f(m_tx, m_ty); glVertex2f( bx, by);
94  glTexCoord2f(0.0f, m_ty); glVertex2f( x, by);
95  glEnd();
96  }
bool bindTexture() const
Definition: glImage.h:79
float m_tx
Definition: glImage.h:105
int m_sy
Definition: glImage.h:104
int m_sx
Definition: glImage.h:104
float m_ty
Definition: glImage.h:105
float GLImage::getSizeX ( ) const
inline

Definition at line 99 of file glImage.h.

References m_sx.

99 { return m_sx; }
int m_sx
Definition: glImage.h:104
float GLImage::getSizeY ( ) const
inline

Definition at line 100 of file glImage.h.

References m_sy.

100 { return m_sy; }
int m_sy
Definition: glImage.h:104
GLImage::operator bool ( ) const
inline

Definition at line 98 of file glImage.h.

References m_Initialized.

98 { return m_Initialized; }
bool m_Initialized
Definition: glImage.h:106
void GLImage::setImage ( const Image< byte > &  image)
inline

Definition at line 27 of file glImage.h.

References Image< T >::getData(), Image< T >::getSizeX(), Image< T >::getSizeY(), Image< T >::insert(), m_gltexture, m_Initialized, m_sx, m_sy, m_tx, m_ty, power2(), and unsetImage().

Referenced by Dataset::draw(), and GLImage().

28  {
29  unsetImage();
30  m_sx = image.getSizeX();
31  m_sy = image.getSizeY();
32  dword p2x = power2(m_sx);
33  dword p2y = power2(m_sy);
34  m_tx = float(m_sx)/p2x;
35  m_ty = float(m_sy)/p2y;
36  Image<byte> p2i(p2x, p2y);
37  p2i.insert(image);
38  glGenTextures(1, &m_gltexture);// Create One Texture
39 // Create Linear Filtered Texture
40  glBindTexture(GL_TEXTURE_2D, m_gltexture);
41  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
42  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
43  glTexImage2D(GL_TEXTURE_2D, 0, 3, p2x, p2y, 0,
44  GL_LUMINANCE, GL_UNSIGNED_BYTE, p2i.getData());
45  m_Initialized = true;
46  }
int getSizeX() const
Definition: Image.h:42
void unsetImage()
Definition: glImage.h:72
float m_tx
Definition: glImage.h:105
int m_sy
Definition: glImage.h:104
int m_sx
Definition: glImage.h:104
unsigned long dword
Definition: simpletypes.h:6
dword power2(dword x)
Definition: mathutil.h:117
bool m_Initialized
Definition: glImage.h:106
float m_ty
Definition: glImage.h:105
GLuint m_gltexture
Definition: glImage.h:103
int getSizeY() const
Definition: Image.h:43
void GLImage::setImage ( const std::vector< Image< byte > > &  image)
inline

Definition at line 48 of file glImage.h.

References Image< T >::getData(), Image< T >::getSizeX(), Image< T >::getSizeY(), Image< T >::insert(), Image< T >::interleave(), m_gltexture, m_Initialized, m_sx, m_sy, m_tx, m_ty, power2(), and unsetImage().

49  {
50  unsetImage();
51  if(image.empty()) return;
52  Image<byte> combimg;
53  combimg.interleave(image, 3);
54  m_sx = combimg.getSizeX()/3; //image[0].getSizeX();
55  m_sy = combimg.getSizeY(); //image[0].getSizeY();
56  dword p2x = power2(m_sx);
57  dword p2y = power2(m_sy);
58  m_tx = float(m_sx)/float(p2x);
59  m_ty = float(m_sy)/float(p2y);
60  Image<byte> p2i(p2x*3, p2y);
61  p2i.insert(combimg);
62  glGenTextures(1, &m_gltexture);// Create One Texture
63 // Create Linear Filtered Texture
64  glBindTexture(GL_TEXTURE_2D, m_gltexture);
65  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
66  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
67  glTexImage2D(GL_TEXTURE_2D, 0, 3, p2x, p2y, 0, GL_RGB,
68  GL_UNSIGNED_BYTE, p2i.getData());
69  m_Initialized = true;
70  }
Image< T > & interleave(const std::vector< Image< T > > &img, dword ncomp=0)
Definition: Image.h:150
int getSizeX() const
Definition: Image.h:42
void unsetImage()
Definition: glImage.h:72
float m_tx
Definition: glImage.h:105
int m_sy
Definition: glImage.h:104
int m_sx
Definition: glImage.h:104
unsigned long dword
Definition: simpletypes.h:6
dword power2(dword x)
Definition: mathutil.h:117
bool m_Initialized
Definition: glImage.h:106
float m_ty
Definition: glImage.h:105
GLuint m_gltexture
Definition: glImage.h:103
int getSizeY() const
Definition: Image.h:43
void GLImage::unsetImage ( )
inline

Definition at line 72 of file glImage.h.

References m_gltexture, and m_Initialized.

Referenced by Dataset::draw(), setImage(), and ~GLImage().

73  {
74  if(!m_Initialized) return;
75  glDeleteTextures(1, &m_gltexture);
76  m_Initialized = false;
77  }
bool m_Initialized
Definition: glImage.h:106
GLuint m_gltexture
Definition: glImage.h:103

Member Data Documentation

GLuint GLImage::m_gltexture
protected

Definition at line 103 of file glImage.h.

Referenced by bindTexture(), setImage(), and unsetImage().

bool GLImage::m_Initialized
protected

Definition at line 106 of file glImage.h.

Referenced by bindTexture(), operator bool(), setImage(), and unsetImage().

int GLImage::m_sx
protected

Definition at line 104 of file glImage.h.

Referenced by draw(), getSizeX(), and setImage().

int GLImage::m_sy
protected

Definition at line 104 of file glImage.h.

Referenced by draw(), getSizeY(), and setImage().

float GLImage::m_tx
protected

Definition at line 105 of file glImage.h.

Referenced by draw(), and setImage().

float GLImage::m_ty
protected

Definition at line 105 of file glImage.h.

Referenced by draw(), and setImage().


The documentation for this class was generated from the following file: