Public Types | Public Member Functions

_iil4mitkTexture Class Reference

#include <texture.h>

List of all members.

Public Types

enum  {
  INTENSITY = 0, INTENSITY_ALPHA, COLOR, COLOR_ALPHA,
  RGB, RGBA
}
 

The color models of the image.

More...

Public Member Functions

 _iil4mitkTexture (iil4mitkWidget *parent)
 The constructor.
virtual ~_iil4mitkTexture ()
 The destructor.
void bind ()
 Binds the texture to the OpenGL context of the widget.
void setSize (const unsigned int width, const unsigned int height)
 Sets the size of the texture.
unsigned int width () const
 Gets the width of the texture.
unsigned int height () const
 Gets the height of the texture.
void setModel (int model)
 Sets the color model of the data. If the color is different from white, the RGBA color model is used.
void setData (const unsigned char *data)
 Sets the image data for the texture. If some of the above parameters have been changed, the method brings the texture to a valid state.
void setInterpolation (const bool on=true)
 Turns the bilinear interpolation of the texture on/off.
void invalidate ()
 Makes the texture invalid.
bool isValid ()
 Checks if the texture is still valid. For example, the texture gets invalid if its parameters are changed without setting new data.

Detailed Description

Definition at line 13 of file texture.h.


Member Enumeration Documentation

anonymous enum

The color models of the image.

Enumerator:
INTENSITY 
INTENSITY_ALPHA 
COLOR 
COLOR_ALPHA 
RGB 
RGBA 

Definition at line 56 of file texture.h.


Constructor & Destructor Documentation

_iil4mitkTexture::_iil4mitkTexture ( iil4mitkWidget parent )

The constructor.

Note:
Make sure that the desired OpenGL context is selected.

Definition at line 4 of file texture.cpp.

References GL_CLAMP, GL_NEAREST, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_UNPACK_ALIGNMENT, glBindTexture(), glGenTextures(), glPixelStorei(), glTexParameterf(), and glTexParameteri().

  :  _width (0), _height (0), _model (0), _internal (0), _valid (false), _interpolation (false), _red (1.0), _green (1.0), _blue (1.0), _alpha (1.0),parent(aParent)
{       
        assert (parent);

        parent->MakeCurrent ();
        glGenTextures (1, &_name);
        glBindTexture (GL_TEXTURE_2D, _name);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}       
_iil4mitkTexture::~_iil4mitkTexture (  ) [virtual]

The destructor.

Frees the texture in the OpenGL context, if it is still

Note:
Make sure that the desired OpenGL context is selected. existing.

Definition at line 23 of file texture.cpp.

References glDeleteTextures().

                                     {
        if(parent!=NULL)
        parent->MakeCurrent ();
        glDeleteTextures (1, &_name);

        // Are the textures deleted automatically?

}

Member Function Documentation

void _iil4mitkTexture::bind (  )

Binds the texture to the OpenGL context of the widget.

Note:
Make sure that the OpenGL context is made current.

Definition at line 33 of file texture.cpp.

References GL_TEXTURE_2D, and glBindTexture().

Referenced by iil4mitkImage::drawTextures().

unsigned int _iil4mitkTexture::height (  ) const

Gets the height of the texture.

Definition at line 59 of file texture.cpp.

Referenced by setSize(), and iil4mitkImage::updateTexture().

{
        return _height;
}
void _iil4mitkTexture::invalidate (  )

Makes the texture invalid.

Definition at line 113 of file texture.cpp.

{

        _valid = false;
}
bool _iil4mitkTexture::isValid (  )

Checks if the texture is still valid. For example, the texture gets invalid if its parameters are changed without setting new data.

Definition at line 120 of file texture.cpp.

Referenced by iil4mitkImage::drawTextures().

{
        return _valid;
}
void _iil4mitkTexture::setData ( const unsigned char *  data )

Sets the image data for the texture. If some of the above parameters have been changed, the method brings the texture to a valid state.

Note:
Make sure that the OpenGL context is made current and the texture has been bound.
See also:
valid()

Definition at line 94 of file texture.cpp.

References GL_TEXTURE_2D, GL_UNSIGNED_BYTE, and glTexImage2D().

Referenced by iil4mitkImage::updateTexture().

{
        glTexImage2D (GL_TEXTURE_2D, 0, _internal, _width, _height, 0, _model, GL_UNSIGNED_BYTE, data);
        _valid = true;
}
void _iil4mitkTexture::setInterpolation ( const bool  on = true )

Turns the bilinear interpolation of the texture on/off.

Note:
Make sure that the OpenGL context is made current and the texture has been bound.

Definition at line 101 of file texture.cpp.

References GL_LINEAR, GL_NEAREST, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, and glTexParameterf().

Referenced by iil4mitkImage::drawTextures().

void _iil4mitkTexture::setModel ( int  model )

Sets the color model of the data. If the color is different from white, the RGBA color model is used.

Parameters:
modelthe color model which is requested

Definition at line 65 of file texture.cpp.

References COLOR, COLOR_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA, INTENSITY, INTENSITY_ALPHA, RGB, and RGBA.

Referenced by iil4mitkImage::drawTextures().

{
        switch (model) {
        case INTENSITY:
                _model = GL_LUMINANCE;
                break;
        case INTENSITY_ALPHA:
                _model = GL_LUMINANCE_ALPHA;
                break;
        case COLOR:
                _model = GL_RGB;
                break;
        case COLOR_ALPHA:
                _model = GL_RGBA;
                break;
        case RGB:
                _model = GL_RGB;
                break;
        case RGBA:
                _model = GL_RGBA;
                break;
        }
                if (_internal != _model) {
                        _internal = _model;
                        _valid = false;
                }       
}
void _iil4mitkTexture::setSize ( const unsigned int  width,
const unsigned int  height 
)

Sets the size of the texture.

Definition at line 40 of file texture.cpp.

References height(), and width().

Referenced by iil4mitkImage::drawTextures().

{
        assert (width > 0);
        assert (height > 0);

        if ((width != _width) || (height != _height)) {
                _valid = false;
        }
        _width = width;
        _height = height;
}
unsigned int _iil4mitkTexture::width (  ) const

Gets the width of the texture.

Definition at line 53 of file texture.cpp.

Referenced by setSize(), and iil4mitkImage::updateTexture().

{
        return _width;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines