MeVisLab Toolbox Reference
View2DTexture.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
15 
16 #pragma once
17 
18 #include "mlDataTypes.h"
19 #include "SoView2DSystem.h"
20 #include <mlPagedImage.h>
21 
22 #include "mlOpenGL.h"
23 #include "mlGLResources.h"
24 
25 #include "View2DLut.h"
26 
27 class SoSFMLImage;
28 class View2DShader;
29 
30 namespace ml {
31  class PagedImage;
32 }
33 
35 
47 {
48 public:
51  virtual ~View2DTexture();
52 
54  void setLut(View2DLut* newLut);
55 
58 
61 
63  View2DTextureFilter getFilter() { return _filter; }
64 
75  void setData(void* data, MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype = MLuint8Type, MLssize_t channels = 1, bool ownsData = true);
76 
78  MLDataType getImageDataType() { return _type; }
79 
81  void allocateData(MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype = MLuint8Type, MLssize_t channels = 1);
82 
84  void* getData() { return _data; };
85 
87  bool hasData() { return _data!=nullptr; };
88 
90  void freeData();
91 
93  void forgetData();
94 
96  void setDataChanged() { _dataChanged = true; };
97 
99  bool isValidUserID(void* user, MLssize_t id);
100 
102  bool isValidUser(void* user) { return user==_user; };
103 
105  void setUserID(void* user, MLssize_t id);
106 
108  MLssize_t getChannels() const { return _channels; }
109 
111  bool isNPOT() { return _useNPOT; }
112 
113  double getDataShift() { return _dataShift; }
114  double getDataScale() { return _dataScale; }
115 
117  void getSize(MLssize_t &x, MLssize_t &y) { x = _sizeX; y = _sizeY; };
118 
121  void loadSliceToTexture(SoSFMLImage* image, MLssize_t slice, MLssize_t timepoint, bool useNPOT = false);
122  void loadSliceToTexture(ml::PagedImage* image, MLssize_t slice, MLssize_t timepoint, bool useNPOT = false);
123 
125  void loadSliceToTexture(SoSFMLImage* image, const ml::SubImageBox& section, bool useNPOT = false);
126  void loadSliceToTexture(ml::PagedImage* image, const ml::SubImageBox& section, bool useNPOT = false);
127 
129  void bindTexture();
130 
132  void drawTexture(float dx1,float dy1, float dx2, float dy2);
134  void drawTexture(float vp1[3],float vp2[3],float vp3[3]);
135 
138  void drawTextureRegion(float vp1[3], float vp2[3], float vp3[3], int startX, int startY, int endX, int endY);
139 
147  void drawTextureAsBorderImage(float dx1, float dy1, float dx2, float dy2, float borderWidth, float borderHeight);
148 
150  void restoreState();
151 
153  void freeTexture();
154 
157 
159  void setShader(View2DShader* shader);
160 
163  void setForceShaderUsage(bool flag);
164 
166  View2DShader* getShader() { return _shader; }
167 
169  static MLssize_t getPowerOfTwo(MLssize_t size, bool& subflag);
170 
173 
176  void setCheckerInterval(size_t interval);
177 
179  size_t getCheckerInterval() const;
180 
182  void setCheckerTilesInverted(bool inverted);
183 
186 
189 
191 
192  void createRenderToTextureTarget(int width, int height, int channels, GLenum format, GLenum internalFormat);
193 
196 
197 private:
199  void createTextureIds();
200 
203  static MLuint32* convertToRGBA(void* data, MLssize_t size, MLssize_t channels, size_t dataTypeSize, View2DLut* lut);
204 
206  void transferTextureData(void* data, GLuint format, GLuint internalFormat, GLuint transferDataType);
207 
209  MLssize_t calcNumTextures(MLssize_t size);
210 
212  MLssize_t _sizeX;
214  MLssize_t _sizeY;
215 
217  MLDataType _type;
219  ml::GLTextures _textures;
221  MLssize_t _numTexturesX;
223  MLssize_t _numTexturesY;
224 
226  View2DLut* _lut;
227 
229  MLssize_t _channels;
230 
232  void* _data;
234  bool _dataChanged;
236  bool _ownsData;
237 
239  View2DTextureFilter _filter;
240 
242  void* _user;
244  MLssize_t _id;
245 
247  ml::LUTDataId _lastLutChangeID;
249  MLssize_t _lastLutSize;
250 
252  View2DShader* _shader;
254  bool _shaderChanged;
256  bool _forceShaderUsage;
258  bool _useNPOT;
259 
261  double _dataScale;
262  double _dataShift;
263 
265  static MLssize_t _maxTextureSize;
266 
270  size_t _checkerInterval;
271 
273  bool _areCheckersInverted;
274 };
View2DTextureFilter
Filter mode.
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
The SoSFMLImage field is the interface used by Inventor Nodes to access image data (in the current im...
Definition: SoSFMLImage.h:70
A small wrapper class for the LUT data.
Definition: View2DLut.h:23
base class for hardware shaders that can be used on a View2DTexture
Definition: View2DShader.h:34
A class to render images as OpenGL Textures.
Definition: View2DTexture.h:47
void freeData()
frees the stored data
void bindTexture()
binds the texture, needs to be done before drawTexture (NEEDS VALID CURRENT GL CONTEXT!...
void getSize(MLssize_t &x, MLssize_t &y)
gets the current size of image
void setCheckerTilesInverted(bool inverted)
Invert the checkerboard, if inverted = TRUE.
void setCheckerInterval(size_t interval)
Set the checkerInterval variable to value interval.
void setLut(View2DLut *newLut)
sets the lut currently used (NEEDS VALID CURRENT GL CONTEXT!)
void restoreState()
restores the GL state (NEEDS VALID CURRENT GL CONTEXT!)
void allocateData(MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype=MLuint8Type, MLssize_t channels=1)
allocates a new data area, frees the old data
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...
View2DTextureFilter getFilter()
get the used filter mode
Definition: View2DTexture.h:63
GLint internalGetFirstTexture()
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 setData(void *data, MLssize_t sizeX, MLssize_t sizeY, MLDataType dtype=MLuint8Type, MLssize_t channels=1, bool ownsData=true)
void internalBindFirstTexture()
Just binds the first texture. Only for internal use!
View2DShader * getShader()
get the shader (might be NULL);
void loadSliceToTexture(ml::PagedImage *image, const ml::SubImageBox &section, bool useNPOT=false)
void setDataChanged()
sets a flag that the current data needs to be reload as a texture because it was changed
Definition: View2DTexture.h:96
View2DLut * getLut()
gets the lut
size_t getCheckerInterval() const
Get the checkerInterval variable value.
void setFilter(View2DTextureFilter filter)
sets the filters that are currently used
bool areCheckerTilesInverted() const
Get the _areCheckersInverted variable value.
double getDataScale()
MLssize_t getChannels() const
Get the number of color channels.
void drawTexture(float dx1, float dy1, float dx2, float dy2)
draws the texture in the given 2d rectangle (NEEDS VALID CURRENT GL CONTEXT!)
bool hasData()
returns TRUE if there is data stored, else it returns false
Definition: View2DTexture.h:87
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
void setShader(View2DShader *shader)
sets the shader that should be used for rendering
bool needsImageData()
check if texture needs image data (NEEDS VALID CURRENT GL CONTEXT!)
bool isNPOT()
Get if the texture is a non-power of two texture.
View2DTexture()
create empty texture
void setUserID(void *user, MLssize_t id)
sets current user and id
void createRenderToTextureTarget(int width, int height, int channels, GLenum format, GLenum internalFormat)
double getDataShift()
void freeTexture()
frees the allocated texture id
bool isValidUserID(void *user, MLssize_t id)
returns true if user and id are correct
void setForceShaderUsage(bool flag)
forces the usage of the shader, regardless of the format, this also clears the internal image data re...
void loadSliceToTexture(ml::PagedImage *image, MLssize_t slice, MLssize_t timepoint, bool useNPOT=false)
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 b...
MLDataType getImageDataType()
get the data type of the stored image
Definition: View2DTexture.h:78
void forgetData()
forget the data, without freeing it.
void * getData()
returns the data pointer (or NULL if empty), free write access is granted
Definition: View2DTexture.h:84
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...
virtual ~View2DTexture()
bool isValidUser(void *user)
returns true if user is correct
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.
MLuint64 getSizeInBytesOnGPU() const
Returns the number of bytes used on the GPU.
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
@ MLuint8Type
Enumerator for the unsigned 8 bit ML integer type.
Definition: mlTypeDefs.h:723
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
unsigned int MLuint32
Definition: mlTypeDefs.h:191
SSIZE_T MLssize_t
The signed ML size type which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
Definition: mlTypeDefs.h:654
Main documentation file for ML users and developers.
Definition: SoSFMLImage.h:51