MeVisLab Toolbox Reference
View2DTexture Class Reference

A class to render images as OpenGL Textures. More...

#include <View2DTexture.h>

Public Member Functions

 View2DTexture ()
 create empty texture
 
virtual ~View2DTexture ()
 
void setLut (View2DLut *newLut)
 sets the lut currently used (NEEDS VALID CURRENT GL CONTEXT!)
 
View2DLutgetLut ()
 gets the lut
 
void setFilter (View2DTextureFilter filter)
 sets the filters that are currently used
 
View2DTextureFilter getFilter ()
 get the used filter mode
 
void setData (void *data, MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype=MLuint8Type, MLssize_t channels=1, bool ownsData=true)
 
MLDataType getImageDataType ()
 get the data type of the stored image
 
void allocateData (MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype=MLuint8Type, MLssize_t channels=1)
 allocates a new data area, frees the old data
 
voidgetData ()
 returns the data pointer (or NULL if empty), free write access is granted
 
bool hasData ()
 returns TRUE if there is data stored, else it returns false
 
void freeData ()
 frees the stored data
 
void forgetData ()
 forget the data, without freeing it.
 
void setDataChanged ()
 sets a flag that the current data needs to be reload as a texture because it was changed
 
bool isValidUserID (void *user, MLssize_t id)
 returns true if user and id are correct
 
bool isValidUser (void *user)
 returns true if user is correct
 
void setUserID (void *user, MLssize_t id)
 sets current user and id
 
MLssize_t getChannels () const
 Get the number of color channels.
 
bool isNPOT ()
 Get if the texture is a non-power of two texture.
 
double getDataShift ()
 
double getDataScale ()
 
void getSize (MLssize_t &x, MLssize_t &y)
 gets the current size of image
 
void loadSliceToTexture (SoSFMLImage *image, MLssize_t slice, MLssize_t timepoint, MLssize_t userIndex, bool useNPOT=false)
 loads image slice to texture (depending on lut it uses a different data type) (LUT MUST be set before!!!)
 
void loadSliceToTexture (ml::PagedImage *image, MLssize_t slice, MLssize_t timepoint, MLssize_t userIndex, bool useNPOT=false)
 
void loadSliceToTexture (SoSFMLImage *image, const ml::SubImageBox &section, bool useNPOT=false)
 loads part of a slice to texture, z, t, and u should have size 1
 
void loadSliceToTexture (ml::PagedImage *image, const ml::SubImageBox &section, bool useNPOT=false)
 
void bindTexture ()
 binds the texture, needs to be done before drawTexture (NEEDS VALID CURRENT GL CONTEXT!)
 
void drawTexture (float dx1, float dy1, float dx2, float dy2)
 draws the texture in the given 2d rectangle (NEEDS VALID CURRENT GL CONTEXT!)
 
void drawTexture (float vp1[3], float vp2[3], float vp3[3])
 draws the texture in the given 3d slice (vp1, vp2, vp3 (4. point is calculated)) (NEEDS VALID CURRENT GL CONTEXT!)
 
void drawTextureRegion (float vp1[3], float vp2[3], float vp3[3], int startX, int startY, int endX, int endY)
 draws the texture region in the given 3d slice (vp1, vp2, vp3 (4.
 
void drawTextureAsBorderImage (float dx1, float dy1, float dx2, float dy2, float borderWidth, float borderHeight)
 draws the image texture from dx1,dy1 to dx2,dy2 using 3x3 quads (the corners/border regions defined by borderWidth and borderHeight (in texels) are not stretched while the rest of the image is stretched to fill the box) For example usages, google for "css border-image".
 
void restoreState ()
 restores the GL state (NEEDS VALID CURRENT GL CONTEXT!)
 
void freeTexture ()
 frees the allocated texture id
 
bool needsImageData ()
 check if texture needs image data (NEEDS VALID CURRENT GL CONTEXT!)
 
void setShader (View2DShader *shader)
 sets the shader that should be used for rendering
 
void setForceShaderUsage (bool flag)
 forces the usage of the shader, regardless of the format, this also clears the internal image data reloading mechanism
 
View2DShadergetShader ()
 get the shader (might be NULL);
 
void setCheckerInterval (size_t interval)
 Set the checkerInterval variable to value interval.
 
size_t getCheckerInterval () const
 Get the checkerInterval variable value.
 
void setCheckerTilesInverted (bool inverted)
 Invert the checkerboard, if inverted = TRUE.
 
bool areCheckerTilesInverted () const
 Get the _areCheckersInverted variable value.
 
void internalBindFirstTexture ()
 Just binds the first texture. Only for internal use!
 
GLint internalGetFirstTexture ()
 
void createRenderToTextureTarget (int width, int height, int channels, GLenum format, GLenum internalFormat)
 
MLuint64 getSizeInBytesOnGPU () const
 Returns the number of bytes used on the GPU.
 

Static Public Member Functions

static MLssize_t getPowerOfTwo (MLssize_t size, bool &subflag)
 returns next power of two and if size is only subpart
 
static MLssize_t getPowerOfTwo (MLssize_t size)
 returns next power of two
 

Detailed Description

A class to render images as OpenGL Textures.

This class internally uses OpenGL Textures to render an image of arbitrary size, using multiple textures if the image is bigger than the texture limit of the hardware. Lookuptables are supported for all datatypes. The maximum color channels supported are 4, which is an RGBA image. Setting channels >4 results in undefined behaviour.

  • 1 channel = Luminance
  • 2 channels = Luminance+Alpha
  • 3 channels = RGB
  • 4 channels = RGBA

Definition at line 46 of file View2DTexture.h.

Constructor & Destructor Documentation

◆ View2DTexture()

View2DTexture::View2DTexture ( )

create empty texture

◆ ~View2DTexture()

virtual View2DTexture::~View2DTexture ( )
virtual

Member Function Documentation

◆ allocateData()

void View2DTexture::allocateData ( MLssize_t sizeX,
MLssize_t sizeY,
MLDataType dtype = MLuint8Type,
MLssize_t channels = 1 )

allocates a new data area, frees the old data

◆ areCheckerTilesInverted()

bool View2DTexture::areCheckerTilesInverted ( ) const

Get the _areCheckersInverted variable value.

◆ bindTexture()

void View2DTexture::bindTexture ( )

binds the texture, needs to be done before drawTexture (NEEDS VALID CURRENT GL CONTEXT!)

◆ createRenderToTextureTarget()

void View2DTexture::createRenderToTextureTarget ( int width,
int height,
int channels,
GLenum format,
GLenum internalFormat )

◆ drawTexture() [1/2]

void View2DTexture::drawTexture ( float dx1,
float dy1,
float dx2,
float dy2 )

draws the texture in the given 2d rectangle (NEEDS VALID CURRENT GL CONTEXT!)

◆ drawTexture() [2/2]

void View2DTexture::drawTexture ( float vp1[3],
float vp2[3],
float vp3[3] )

draws the texture in the given 3d slice (vp1, vp2, vp3 (4. point is calculated)) (NEEDS VALID CURRENT GL CONTEXT!)

◆ drawTextureAsBorderImage()

void View2DTexture::drawTextureAsBorderImage ( float dx1,
float dy1,
float dx2,
float dy2,
float borderWidth,
float borderHeight )

draws the image texture from dx1,dy1 to dx2,dy2 using 3x3 quads (the corners/border regions defined by borderWidth and borderHeight (in texels) are not stretched while the rest of the image is stretched to fill the box) For example usages, google for "css border-image".

In contrast to drawTexture(), this method calls bindTexture() and restoreState(), so it does not require further setup calls before drawing. NOTE: This method only supports textures that are smaller than the maximum GL texture size.

◆ drawTextureRegion()

void View2DTexture::drawTextureRegion ( float vp1[3],
float vp2[3],
float vp3[3],
int startX,
int startY,
int endX,
int endY )

draws the texture region in the given 3d slice (vp1, vp2, vp3 (4.

point is calculated)) (NEEDS VALID CURRENT GL CONTEXT!) The region is given in pixel coordinates. This only works on textures that fit in a single GL texture.

◆ forgetData()

void View2DTexture::forgetData ( )

forget the data, without freeing it.

◆ freeData()

void View2DTexture::freeData ( )

frees the stored data

◆ freeTexture()

void View2DTexture::freeTexture ( )

frees the allocated texture id

◆ getChannels()

MLssize_t View2DTexture::getChannels ( ) const
inline

Get the number of color channels.

Definition at line 108 of file View2DTexture.h.

◆ getCheckerInterval()

size_t View2DTexture::getCheckerInterval ( ) const

Get the checkerInterval variable value.

◆ getData()

void * View2DTexture::getData ( )
inline

returns the data pointer (or NULL if empty), free write access is granted

Definition at line 84 of file View2DTexture.h.

◆ getDataScale()

double View2DTexture::getDataScale ( )
inline

Definition at line 114 of file View2DTexture.h.

◆ getDataShift()

double View2DTexture::getDataShift ( )
inline

Definition at line 113 of file View2DTexture.h.

◆ getFilter()

View2DTextureFilter View2DTexture::getFilter ( )
inline

get the used filter mode

Definition at line 63 of file View2DTexture.h.

◆ getImageDataType()

MLDataType View2DTexture::getImageDataType ( )
inline

get the data type of the stored image

Definition at line 78 of file View2DTexture.h.

◆ getLut()

View2DLut * View2DTexture::getLut ( )

gets the lut

◆ getPowerOfTwo() [1/2]

static MLssize_t View2DTexture::getPowerOfTwo ( MLssize_t size)
static

returns next power of two

◆ getPowerOfTwo() [2/2]

static MLssize_t View2DTexture::getPowerOfTwo ( MLssize_t size,
bool & subflag )
static

returns next power of two and if size is only subpart

◆ getShader()

View2DShader * View2DTexture::getShader ( )
inline

get the shader (might be NULL);

Definition at line 166 of file View2DTexture.h.

◆ getSize()

void View2DTexture::getSize ( MLssize_t & x,
MLssize_t & y )
inline

gets the current size of image

Definition at line 117 of file View2DTexture.h.

◆ getSizeInBytesOnGPU()

MLuint64 View2DTexture::getSizeInBytesOnGPU ( ) const

Returns the number of bytes used on the GPU.

◆ hasData()

bool View2DTexture::hasData ( )
inline

returns TRUE if there is data stored, else it returns false

Definition at line 87 of file View2DTexture.h.

◆ internalBindFirstTexture()

void View2DTexture::internalBindFirstTexture ( )

Just binds the first texture. Only for internal use!

◆ internalGetFirstTexture()

GLint View2DTexture::internalGetFirstTexture ( )

◆ isNPOT()

bool View2DTexture::isNPOT ( )
inline

Get if the texture is a non-power of two texture.

Definition at line 111 of file View2DTexture.h.

◆ isValidUser()

bool View2DTexture::isValidUser ( void * user)
inline

returns true if user is correct

Definition at line 102 of file View2DTexture.h.

References mlrange_cast().

◆ isValidUserID()

bool View2DTexture::isValidUserID ( void * user,
MLssize_t id )

returns true if user and id are correct

◆ loadSliceToTexture() [1/4]

void View2DTexture::loadSliceToTexture ( ml::PagedImage * image,
const ml::SubImageBox & section,
bool useNPOT = false )

◆ loadSliceToTexture() [2/4]

void View2DTexture::loadSliceToTexture ( ml::PagedImage * image,
MLssize_t slice,
MLssize_t timepoint,
MLssize_t userIndex,
bool useNPOT = false )

◆ loadSliceToTexture() [3/4]

void View2DTexture::loadSliceToTexture ( SoSFMLImage * image,
const ml::SubImageBox & section,
bool useNPOT = false )

loads part of a slice to texture, z, t, and u should have size 1

◆ loadSliceToTexture() [4/4]

void View2DTexture::loadSliceToTexture ( SoSFMLImage * image,
MLssize_t slice,
MLssize_t timepoint,
MLssize_t userIndex,
bool useNPOT = false )

loads image slice to texture (depending on lut it uses a different data type) (LUT MUST be set before!!!)

◆ needsImageData()

bool View2DTexture::needsImageData ( )

check if texture needs image data (NEEDS VALID CURRENT GL CONTEXT!)

◆ restoreState()

void View2DTexture::restoreState ( )

restores the GL state (NEEDS VALID CURRENT GL CONTEXT!)

◆ setCheckerInterval()

void View2DTexture::setCheckerInterval ( size_t interval)

Set the checkerInterval variable to value interval.

Results in every interval-th voxel drawn.

◆ setCheckerTilesInverted()

void View2DTexture::setCheckerTilesInverted ( bool inverted)

Invert the checkerboard, if inverted = TRUE.

◆ setData()

void View2DTexture::setData ( void * data,
MLssize_t sizeX,
MLssize_t sizeY,
MLDataType dtype = MLuint8Type,
MLssize_t channels = 1,
bool ownsData = true )

sets the current data and its size default is uint8 index data, the size in pixels is given as sizeX and sizeY. For color data, you can pass in a value of channels==3 for RGB and channels==4 for RGBA. The data is expected as RGB interleaved data, as in OpenGL. The size can be bigger than the maximum size of a single texture in OpenGL and it is allowed to be a non-power of two. NOTE: the right to free the data is moved to the View2DTexture object, you dont own the data anymore, the data needs to be allocated with malloc! If ownsData == false, the ownership stays with the caller.

◆ setDataChanged()

void View2DTexture::setDataChanged ( )
inline

sets a flag that the current data needs to be reload as a texture because it was changed

Definition at line 96 of file View2DTexture.h.

◆ setFilter()

void View2DTexture::setFilter ( View2DTextureFilter filter)

sets the filters that are currently used

◆ setForceShaderUsage()

void View2DTexture::setForceShaderUsage ( bool flag)

forces the usage of the shader, regardless of the format, this also clears the internal image data reloading mechanism

◆ setLut()

void View2DTexture::setLut ( View2DLut * newLut)

sets the lut currently used (NEEDS VALID CURRENT GL CONTEXT!)

◆ setShader()

void View2DTexture::setShader ( View2DShader * shader)

sets the shader that should be used for rendering

◆ setUserID()

void View2DTexture::setUserID ( void * user,
MLssize_t id )

sets current user and id


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