MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
27class SoSFMLImage;
28class View2DShader;
29
30namespace ml
31{
32 class PagedImage;
33}
34
36
48{
49public:
52 virtual ~View2DTexture();
53
56
59
62
65 {
66 return _filter;
67 }
68
80 bool ownsData = true);
81
84 {
85 return _type;
86 }
87
90
92 void* getData()
93 {
94 return _data;
95 };
96
98 bool hasData()
99 {
100 return _data != nullptr;
101 };
102
104 void freeData();
105
108
111 {
112 _dataChanged = true;
113 };
114
116 bool isValidUserID(void* user, MLssize_t id);
117
119 bool isValidUser(void* user)
120 {
121 return user == _user;
122 };
123
125 void setUserID(void* user, MLssize_t id);
126
129 {
130 return _channels;
131 }
132
134 bool isNPOT()
135 {
136 return _useNPOT;
137 }
138
140 {
141 return _dataShift;
142 }
144 {
145 return _dataScale;
146 }
147
150 {
151 x = _sizeX;
152 y = _sizeY;
153 };
154
157 void loadSliceToTexture(SoSFMLImage* image, MLssize_t slice, MLssize_t timepoint, MLssize_t userIndex,
158 bool useNPOT = false);
159 void loadSliceToTexture(ml::PagedImage* image, MLssize_t slice, MLssize_t timepoint, MLssize_t userIndex,
160 bool useNPOT = false);
161
165
168
170 void drawTexture(float dx1, float dy1, float dx2, float dy2);
172 void drawTexture(float vp1[3], float vp2[3], float vp3[3]);
173
176 void drawTextureRegion(float vp1[3], float vp2[3], float vp3[3], int startX, int startY, int endX, int endY);
177
185 void drawTextureAsBorderImage(float dx1, float dy1, float dx2, float dy2, float borderWidth, float borderHeight);
186
189
192
195
198
202
205 {
206 return _shader;
207 }
208
211
214
218
220 size_t getCheckerInterval() const;
221
224
227
230
232
233 void createRenderToTextureTarget(int width, int height, int channels, GLenum format, GLenum internalFormat);
234
237
238private:
240 void createTextureIds();
241
244 static MLuint32* convertToRGBA(void* data, MLssize_t size, MLssize_t channels, size_t dataTypeSize, View2DLut* lut);
245
247 void transferTextureData(void* data, GLuint format, GLuint internalFormat, GLuint transferDataType);
248
251 MLssize_t calcNumTextures(MLssize_t size);
252
254 MLssize_t _sizeX;
256 MLssize_t _sizeY;
257
259 MLDataType _type;
261 ml::GLTextures _textures;
263 MLssize_t _numTexturesX;
265 MLssize_t _numTexturesY;
266
268 View2DLut* _lut;
269
271 MLssize_t _channels;
272
274 void* _data;
276 bool _dataChanged;
278 bool _ownsData;
279
281 View2DTextureFilter _filter;
282
284 void* _user;
286 MLssize_t _id;
287
289 ml::LUTDataId _lastLutChangeID;
291 MLssize_t _lastLutSize;
292
294 View2DShader* _shader;
296 bool _shaderChanged;
298 bool _forceShaderUsage;
300 bool _useNPOT;
301
303 double _dataScale;
304 double _dataShift;
305
307 static MLssize_t _maxTextureSize;
308
312 size_t _checkerInterval;
313
315 bool _areCheckersInverted;
316};
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:84
A small wrapper class for the LUT data.
Definition View2DLut.h:23
base class for hardware shaders that can be used on a View2DTexture
A class to render images as OpenGL Textures.
void freeData()
frees the stored data
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 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(ml::PagedImage *image, MLssize_t slice, MLssize_t timepoint, MLssize_t userIndex, bool useNPOT=false)
View2DTextureFilter getFilter()
get the used filter mode
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!
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
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()
View2DLut * getLut()
gets the lut
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
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)
View2DShader * getShader()
get the shader (might be NULL);
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 * getData()
returns the data pointer (or NULL if empty), free write access is granted
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
void forgetData()
forget the data, without freeing it.
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.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
@ MLuint8Type
Enumerator for the unsigned 8-bit ML integer type.
Definition mlTypeDefs.h:617
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
unsigned int MLuint32
Definition mlTypeDefs.h:185
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition mlTypeDefs.h:563
Main documentation file for ML users and developers.
Definition SoSFMLImage.h:64