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 More...
 
virtual ~View2DTexture ()
 
void setLut (View2DLut *newLut)
 sets the lut currently used (NEEDS VALID CURRENT GL CONTEXT!) More...
 
View2DLutgetLut ()
 gets the lut More...
 
void setFilter (View2DTextureFilter filter)
 sets the filters that are currently used More...
 
View2DTextureFilter getFilter ()
 get the used filter mode More...
 
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 More...
 
void allocateData (MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype=MLuint8Type, MLssize_t channels=1)
 allocates a new data area, frees the old data More...
 
void * getData ()
 returns the data pointer (or NULL if empty), free write access is granted More...
 
bool hasData ()
 returns TRUE if there is data stored, else it returns false More...
 
void freeData ()
 frees the stored data More...
 
void forgetData ()
 forget the data, without freeing it. More...
 
void setDataChanged ()
 sets a flag that the current data needs to be reload as a texture because it was changed More...
 
bool isValidUserID (void *user, MLssize_t id)
 returns true if user and id are correct More...
 
bool isValidUser (void *user)
 returns true if user is correct More...
 
void setUserID (void *user, MLssize_t id)
 sets current user and id More...
 
MLssize_t getChannels () const
 Get the number of color channels. More...
 
bool isNPOT ()
 Get if the texture is a non-power of two texture. More...
 
double getDataShift ()
 
double getDataScale ()
 
void getSize (MLssize_t &x, MLssize_t &y)
 gets the current size of image More...
 
void loadSliceToTexture (SoSFMLImage *image, MLssize_t slice, MLssize_t timepoint, bool useNPOT=false)
 loads image slice to texture (depending on lut it uses a different data type) (LUT MUST be set before!!!) More...
 
void loadSliceToTexture (ml::PagedImage *image, MLssize_t slice, MLssize_t timepoint, 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 More...
 
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!) More...
 
void drawTexture (float dx1, float dy1, float dx2, float dy2)
 draws the texture in the given 2d rectangle (NEEDS VALID CURRENT GL CONTEXT!) More...
 
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!) More...
 
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. More...
 
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". More...
 
void restoreState ()
 restores the GL state (NEEDS VALID CURRENT GL CONTEXT!) More...
 
void freeTexture ()
 frees the allocated texture id More...
 
bool needsImageData ()
 check if texture needs image data (NEEDS VALID CURRENT GL CONTEXT!) More...
 
void setShader (View2DShader *shader)
 sets the shader that should be used for rendering More...
 
void setForceShaderUsage (bool flag)
 forces the usage of the shader, regardless of the format, this also clears the internal image data reloading mechanism More...
 
View2DShadergetShader ()
 get the shader (might be NULL); More...
 
void setCheckerInterval (size_t interval)
 Set the checkerInterval variable to value interval. More...
 
size_t getCheckerInterval () const
 Get the checkerInterval variable value. More...
 
void setCheckerTilesInverted (bool inverted)
 Invert the checkerboard, if inverted = TRUE. More...
 
bool areCheckerTilesInverted () const
 Get the _areCheckersInverted variable value. More...
 
void internalBindFirstTexture ()
 Just binds the first texture. Only for internal use! More...
 
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. More...
 

Static Public Member Functions

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

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 ( void  )
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.

◆ 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,
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,
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: