MeVisLab Toolbox Reference
View2DSlice.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
16
17#pragma once
18
19#include "SoView2DSystem.h"
20#include "SoSFMLImage.h"
21#include "SoView2DExtension.h"
22#include "View2DTexture.h"
23
24class View2DSliceList;
25class View2DShader;
26class SoNodeList;
27
28// declare the LUTData
30
31 template <typename T> class LUTData;
32
34
36#define VIEW2D_MAX_OVERLAY_TEXTURES 32
37
38enum {
40 // (if the type for slice indices is changed to a bigger type
41 // than int, change this constant, too!)
42 NO_SLICE_ID = 0x80000000
43};
44
45//-------------------------------------------------------------
48{
49public:
54
56 void destroy();
57
62
65
67 View2DShader* getShader() { return _shader; }
68
70 void setSliceZ(int z);
72 int getSliceZ();
73
75 void setDrawsData(bool flag);
76
78 void setAspectRatio(float ratio) { _aspectRatio = ratio; }
79
81 float getAspectRatio() { return _aspectRatio; }
82
87
90
92 void setFixedInnerZoom(bool flag, float fixedZoom);
93
95 void setDrawSize(float sx, float sy);
97 void getDrawSize(float &sx, float &sy);
98
100 void setDrawPosition(float x, float y);
102 void getDrawPosition(float &x, float &y);
103
105 void setSliceOrigin(float x, float y);
107 void getSliceOrigin(float &x, float &y);
108
110 void setSliceZoom(float zoom);
113
118
120 void getVoxelSize(float &vx,float &vy, float &vz);
121
123 void getVoxelSize(double &vx, double &vy, double &vz);
124
127
130
132 void setBlendMode(int blendMode, float* blendColor=nullptr);
133
135 void setBackgroundColor(float* color);
136
138 void setTimePoint(int timepoint);
141
146
147
149 void drawBackground(bool clipBackgroundToImage = false);
150
153 void drawSlice(View2DSliceList *dsl, int originX, int originY, int width, int height,
155
157
159 void drawTexture(View2DTexture* texture, int blendMode);
161 void drawTexture(View2DTexture* texture, int blendMode, float* blendColor);
163 void drawTexture(View2DTexture* texture, int blendMode, float* blendColor,View2DTextureFilter filter);
164
166 void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3],
167 int blendMode, float* blendColor);
168
170 void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3],
171 int blendMode, float* blendColor, View2DTextureFilter filter);
172
174 void getImageDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2);
175
177 static void enableBlending(int blendMode);
178
185 bool select(float x, float y, float &voxelX, float &voxelY, float &voxelZ);
186
188 bool select(float x, float y, SbVec3f &voxel);
189
191 bool select(const SbVec2f& d, SbVec3f &voxel);
192
195 bool isSliceHit(float x, float y) const;
196
202
204 bool isValidVoxel(float voxelX, float voxelY, float voxelZ);
205
208
211
215
219
223 void mapVoxelToDevice(float voxelX, float voxelY, float voxelZ,
224 float &rx, float &ry);
225
228 float &rx, float &ry);
229
232 SbVec2f& r);
233
236
239 void mapWorldToDevice(float worldX, float worldY, float worldZ,
240 float &rx, float &ry);
241
244 float &rx, float &ry);
245
248 SbVec2f& r);
249
251 void getVisibleDeviceRect(float &dx1,float &dy1, float &dx2, float &dy2);
252
254 View2DTexture* getOverlayTexture(void* user = nullptr, int id = 0);
255
258
261
263 void setDraw3D(bool flag, float devicePixelSize = 1);
264
266 bool is3D() { return _is3D; }
267
269 bool containsVoxel(const SbVec3f& voxelPos);
270
271private:
273 void* getImageSlice(int slice);
274
277 int _sliceZ;
279 int _timePoint;
281 int _userIndex;
283 float _drawPosX;
285 float _drawPosY;
287 float _drawWidth;
289 float _drawHeight;
290
291 View2DTextureFilter _filter;
292 int _blendMode;
293 float _blendColor[4];
294 float _bgColor[4];
295 float _zoom;
296 float _sliceZoom;
297 float _sliceOriginX;
298 float _sliceOriginY;
299
300 float _fixedInnerZoom;
301 bool _fixedInnerZoomOn;
302
304
306 SoSFMLImage *_inp;
307
309 float _centerX;
311 float _centerY;
312
314 int _imageWidth;
316 int _imageHeight;
317
319 float _vxFlt,_vyFlt,_vzFlt;
320 double _vxDbl,_vyDbl,_vzDbl;
322
324 float _aspectRatio;
325
327 bool _drawData;
329 bool _is3D;
330
332 View2DAlignXMode _sliceAlignX;
334 View2DAlignYMode _sliceAlignY;
335
337 View2DSliceCachingMode _caching;
338
340 View2DTexture _sliceTexture;
343
345 View2DShader* _shader;
346 View2DShader** _overlayShaders;
347};
View2DAlignYMode
slice align mode y
View2DTextureFilter
Filter mode.
@ FILTER_LINEAR
Bilinear filtering (after classification/LUT)
View2DAlignXMode
slice align mode x
View2DSliceCachingMode
Caching mode.
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
#define VIEW2D_MAX_OVERLAY_TEXTURES
number of overlay textures that can be cached
Definition View2DSlice.h:36
@ NO_SLICE_ID
define a number as meaning "no slice selected"
Definition View2DSlice.h:42
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
a list that holds all View2DSlice objects (lazily created) of a SoView2D
a single slice that is stored in a View2DSliceList, typically created by a View2DSliceList
Definition View2DSlice.h:48
static void enableBlending(int blendMode)
enable the given blend mode in GL state.
void setDrawSize(float sx, float sy)
set the slice size for drawing
int getLutSize()
get size of lut
void drawTexture(View2DTexture *texture, float vp1[3], float vp2[3], float vp3[3], int blendMode, float *blendColor, View2DTextureFilter filter)
draw a View2DTexture in specified device coordinates (may be 3D coordinates also)
void drawTexture(View2DTexture *texture, int blendMode, float *blendColor)
draw a View2DTexture (used for Slice drawing and for overlays also)
void setLut(View2DLut *lut)
set the lut
SoSFMLImage * getInputImage()
get the input image.
float getAspectRatio()
get the aspect ratio
Definition View2DSlice.h:81
bool select(const SbVec2f &d, SbVec3f &voxel)
same as above
void drawTexture(View2DTexture *texture, float vp1[3], float vp2[3], float vp3[3], int blendMode, float *blendColor)
draw a View2DTexture in specified device coordinates (may be 3D coordinates also)
void setBackgroundColor(float *color)
set the background color (rgba)
void mapWorldToDevice(const SbVec3f &worldCoord, float &rx, float &ry)
same as above
void setInputImage(SoSFMLImage *img)
set the input image.
void drawTexture(View2DTexture *texture, int blendMode)
draw a View2DTexture (used for Slice drawing and for overlays also)
void getDrawPosition(float &x, float &y)
get the slice position for drawing
int getUserIndex()
get the user index
void invalidateView()
Sets a flag that the current state of the instance does not correspond to the data on the display.
float millimeterToPixel(float lengthMillimeter)
calculates the pixel offset (in device coordinates) that corresponds to a certain distance (in mm,...
void mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float &rx, float &ry)
maps the local voxel coordinate to a device pixel coordinate which may be used in OpenGL (for drawing...
bool containsVoxel(const SbVec3f &voxelPos)
returns if the slice contains the given voxel pos
int getSliceZ()
get the slice z position.
void getImageDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2)
Returns the device rect for the base image.
void setAspectRatio(float ratio)
set the aspect ratio
Definition View2DSlice.h:78
void getVoxelSize(double &vx, double &vy, double &vz)
return voxel size in doubles
void setDraw3D(bool flag, float devicePixelSize=1)
enable drawing in 3d
void destroy()
destroy the slice textures
void mapVoxelToDevice(const SbVec3f &voxelCoord, float &rx, float &ry)
same as above
void setSliceAlignment(View2DAlignXMode x, View2DAlignYMode y)
set the alignment of the slice
bool select(float x, float y, float &voxelX, float &voxelY, float &voxelZ)
Determine whether the slice can be selected, returned position is in voxel coordinates (typically thi...
void drawBackground(bool clipBackgroundToImage=false)
draw background of the slice
void mapWorldToDevice(const SbVec3f &worldCoord, SbVec2f &r)
same as above
void setDrawPosition(float x, float y)
set the slice position for drawing
void mapVoxelToDevice(const SbVec3f &voxelCoord, SbVec2f &r)
same as above
bool isValidVoxel(const SbVec3f &voxel)
same as above
void getDrawSize(float &sx, float &sy)
get the slice size for drawing
void setFilter(View2DTextureFilter filter=FILTER_LINEAR)
set the filter
void mapDeviceToNormalizedCoordinateSystem(int x, int y, SbVec2f &normalizedCoordinate) const
Maps the given device coordinates to normalized View2D coordinates (as used by sliceOrigin and zoomCe...
View2DSlice()
constructor
void getSliceOrigin(float &x, float &y)
get the inner slice origin
void drawSliceIn3D(View2DSliceList *dsl, bool extensionsOnly, SoNodeList *extensions, bool reverseDrawingOrder)
void setShaders(View2DShader *shader, View2DShader **overlayShaders)
sets the shader that should be used for rendering
void setSliceZoom(float zoom)
set the inner slice zoom
View2DSliceCachingMode getCachingMode()
get data caching mode.
bool select(float x, float y, SbVec3f &voxel)
same as above
void setSliceOrigin(float x, float y)
set the inner slice origin
float getSliceZoom()
get the inner slice zoom
void drawSlice(View2DSliceList *dsl, int originX, int originY, int width, int height, SoNodeList *extensions, bool extensionsOnly, bool isSlabRendering)
draw the slice (originX, originY, width and height are the current viewport position/size)
void getVisibleDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2)
returns the visible device rect of the slice (the region the sliceOrigin and sliceZoom shows of the s...
void setSliceZ(int z)
set the slice z position.
void setFixedInnerZoom(bool flag, float fixedZoom)
set the fixed innerzoom
void setDrawsData(bool flag)
enable/disable data loading
float getInnerZoom()
get the inner zoom
void drawTexture(View2DTexture *texture, int blendMode, float *blendColor, View2DTextureFilter filter)
draw a View2DTexture (used for Slice drawing and for overlays also)
bool isValidVoxel(float voxelX, float voxelY, float voxelZ)
Returns if the given voxel coordinate is inside the image (z is currently ignored)
View2DShader * getShader()
get the main shader (might be NULL);
Definition View2DSlice.h:67
bool is3D()
check if current rendering is in 3d
void setBlendMode(int blendMode, float *blendColor=nullptr)
set blend mode
bool isSliceHit(float x, float y) const
Returns if slice is hit at the given device coordinate if the visible device rect of a slice was hit ...
void getVoxelSize(float &vx, float &vy, float &vz)
return voxel size
void setTimePoint(int timepoint)
set the time point
~View2DSlice()
destructor.
void setCachingMode(View2DSliceCachingMode mode)
set data caching mode.
void invalidate()
Invalidate the current slice data.
int getTimePoint()
get the time point
void updateLayout()
update internal layout
SbMatrix getWorldToDeviceMatrix()
Returns the world to device matrix.
View2DTextureFilter getFilter()
get the filter
void mapWorldToDevice(float worldX, float worldY, float worldZ, float &rx, float &ry)
maps the world coordinate to a device pixel coordinate which may be used in OpenGL (for drawing on th...
void setUserIndex(int useIndex)
set the user index
View2DTexture * getOverlayTexture(void *user=nullptr, int id=0)
get the overlay texture (is only created on first call and cached afterwards)
A class to render images as OpenGL Textures.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.