MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
31template <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:
51 View2DSlice() = default;
54
56 void destroy();
57
62
65
68 {
69 return _shader;
70 }
71
73 void setSliceZ(int z);
75 int getSliceZ() const;
76
78 void setDrawsData(bool flag);
79
81 void setAspectRatio(float ratio)
82 {
83 _aspectRatio = ratio;
84 }
85
87 float getAspectRatio() const
88 {
89 return _aspectRatio;
90 }
91
96
99
102
104 void setDrawSize(float sx, float sy);
106 void getDrawSize(float& sx, float& sy) const;
107
109 void setDrawPosition(float x, float y);
111 void getDrawPosition(float& x, float& y) const;
112
114 void setSliceOrigin(float x, float y);
116 void getSliceOrigin(float& x, float& y) const;
117
119 void setSliceZoom(float zoom);
121 float getSliceZoom() const;
122
127
129 void getVoxelSize(float& vx, float& vy, float& vz) const;
130
132 void getVoxelSize(double& vx, double& vy, double& vz) const;
133
136
139
141 void setBlendMode(int blendMode, float* blendColor = nullptr);
142
144 void setBackgroundColor(float* color);
145
147 void setTimePoint(int timepoint);
149 int getTimePoint() const;
150
154 int getUserIndex() const;
155
156
158 void drawBackground(bool clipBackgroundToImage = false);
159
162 void drawSlice(View2DSliceList* dsl, int originX, int originY, int width, int height, SoNodeList* extensions,
164
166
168 void drawTexture(View2DTexture* texture, int blendMode);
170 void drawTexture(View2DTexture* texture, int blendMode, float* blendColor);
172 void drawTexture(View2DTexture* texture, int blendMode, float* blendColor, View2DTextureFilter filter);
173
175 void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3], int blendMode, float* blendColor);
176
178 void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3], int blendMode, float* blendColor,
179 View2DTextureFilter filter);
180
182 void getImageDeviceRect(float& dx1, float& dy1, float& dx2, float& dy2) const;
183
185 static void enableBlending(int blendMode);
186
193 bool select(float x, float y, float& voxelX, float& voxelY, float& voxelZ) const;
194
196 bool select(float x, float y, SbVec3f& voxel) const;
197
199 bool select(const SbVec2f& d, SbVec3f& voxel) const;
200
203 bool isSliceHit(float x, float y) const;
204
210
212 bool isValidVoxel(float voxelX, float voxelY, float voxelZ) const;
213
215 bool isValidVoxel(const SbVec3f& voxel) const;
216
219
223
227 void mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float& rx, float& ry) const;
228
230 void mapVoxelToDevice(const SbVec3f& voxelCoord, float& rx, float& ry) const;
231
234
237
240 bool mapWorldToDevice(float worldX, float worldY, float worldZ, float& rx, float& ry) const;
241
243 bool mapWorldToDevice(const SbVec3f& worldCoord, float& rx, float& ry) const;
244
247
249 void getVisibleDeviceRect(float& dx1, float& dy1, float& dx2, float& dy2) const;
250
252 View2DTexture* getOverlayTexture(void* user = nullptr, int id = 0);
253
256
258 float getInnerZoom() const;
259
261 void setDraw3D(bool flag, float devicePixelSize = 1);
262
264 bool is3D() const
265 {
266 return _is3D;
267 }
268
270 bool containsVoxel(const SbVec3f& voxelPos) const;
271
272private:
275 int _sliceZ{};
277 int _timePoint{};
279 int _userIndex{};
281 float _drawPosX{};
283 float _drawPosY{};
285 float _drawWidth{};
287 float _drawHeight{};
288
290 int _blendMode{};
291 float _blendColor[4]{1, 1, 1, 1};
292 float _bgColor[4]{0, 0, 0, 1};
293 float _zoom{1};
294 float _sliceZoom{1};
295 float _sliceOriginX{};
296 float _sliceOriginY{};
297
298 float _fixedInnerZoom{1};
299 bool _fixedInnerZoomOn{};
300
302
304 SoSFMLImage* _inp{};
305
307 float _centerX{};
309 float _centerY{};
310
312 int _imageWidth{};
314 int _imageHeight{};
315
317 float _vxFlt{}, _vyFlt{}, _vzFlt{};
318 double _vxDbl{}, _vyDbl{}, _vzDbl{};
320
322 float _aspectRatio{1};
323
325 bool _drawData{true};
327 bool _is3D{};
328
333
336
338 View2DTexture _sliceTexture;
340 View2DTexture* _overlayTextures[VIEW2D_MAX_OVERLAY_TEXTURES]{};
341
343 View2DShader* _shader{};
344 View2DShader** _overlayShaders{};
345};
View2DAlignYMode
slice align mode y
@ SLICE_ALIGNY_CENTER
View2DTextureFilter
Filter mode.
@ FILTER_LINEAR
Bilinear filtering (after classification/LUT)
View2DAlignXMode
slice align mode x
@ SLICE_ALIGNX_CENTER
View2DSliceCachingMode
Caching mode.
@ SLICE_CACHING_PARTIAL
#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: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 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)
float getInnerZoom() const
get the inner zoom
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.
int getUserIndex() const
get the user index
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 mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float &rx, float &ry) const
maps the local voxel coordinate to a device pixel coordinate which may be used in OpenGL (for drawing...
void setInputImage(SoSFMLImage *img)
set the input image.
bool select(float x, float y, float &voxelX, float &voxelY, float &voxelZ) const
Determine whether the slice can be selected, returned position is in voxel coordinates (typically thi...
View2DSlice()=default
constructor
void drawTexture(View2DTexture *texture, int blendMode)
draw a View2DTexture (used for Slice drawing and for overlays also)
void mapVoxelToDevice(const SbVec3f &voxelCoord, SbVec2f &r) const
same as above
View2DShader * getShader() const
get the main shader (might be NULL);
Definition View2DSlice.h:67
void getDrawPosition(float &x, float &y) const
get the slice position for drawing
void setAspectRatio(float ratio)
set the aspect ratio
Definition View2DSlice.h:81
void getImageDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2) const
Returns the device rect for the base image.
void getSliceOrigin(float &x, float &y) const
get the inner slice origin
void setDraw3D(bool flag, float devicePixelSize=1)
enable drawing in 3d
bool select(float x, float y, SbVec3f &voxel) const
same as above
void destroy()
destroy the slice textures
bool select(const SbVec2f &d, SbVec3f &voxel) const
same as above
void setSliceAlignment(View2DAlignXMode x, View2DAlignYMode y)
set the alignment of the slice
void drawBackground(bool clipBackgroundToImage=false)
draw background of the slice
void setDrawPosition(float x, float y)
set the slice position for drawing
bool mapWorldToDevice(const SbVec3f &worldCoord, SbVec2f &r) const
same as above
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...
void getVoxelSize(float &vx, float &vy, float &vz) const
return voxel size
bool mapWorldToDevice(float worldX, float worldY, float worldZ, float &rx, float &ry) const
maps the world coordinate to a device pixel coordinate which may be used in OpenGL (for drawing on th...
void getVisibleDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2) const
returns the visible device rect of the slice (the region the sliceOrigin and sliceZoom shows of the s...
bool containsVoxel(const SbVec3f &voxelPos) const
returns if the slice contains the given voxel pos
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
int getTimePoint() const
get the time point
void setSliceOrigin(float x, float y)
set the inner slice origin
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 getDrawSize(float &sx, float &sy) const
get the slice size for drawing
void setSliceZ(int z)
set the slice z position.
SbMatrix getWorldToDeviceMatrix() const
Returns the world to device matrix.
void setFixedInnerZoom(bool flag, float fixedZoom)
set the fixed inner zoom
float millimeterToPixel(float lengthMillimeter) const
calculates the pixel offset (in device coordinates) that corresponds to a certain distance (in mm,...
void getVoxelSize(double &vx, double &vy, double &vz) const
return voxel size in doubles
bool mapWorldToDevice(const SbVec3f &worldCoord, float &rx, float &ry) const
same as above
void setDrawsData(bool flag)
enable/disable data loading
bool isValidVoxel(const SbVec3f &voxel) const
same as above
void drawTexture(View2DTexture *texture, int blendMode, float *blendColor, View2DTextureFilter filter)
draw a View2DTexture (used for Slice drawing and for overlays also)
void mapVoxelToDevice(const SbVec3f &voxelCoord, float &rx, float &ry) const
same as above
View2DTextureFilter getFilter() const
get the filter
int getSliceZ() const
get the slice z position.
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 ...
float getSliceZoom() const
get the inner slice zoom
void setTimePoint(int timepoint)
set the time point
~View2DSlice()
destructor.
void setCachingMode(View2DSliceCachingMode mode)
set data caching mode.
View2DSliceCachingMode getCachingMode() const
get data caching mode.
void invalidate()
Invalidate the current slice data.
void updateLayout()
update internal layout
float getAspectRatio() const
get the aspect ratio
Definition View2DSlice.h:87
bool isValidVoxel(float voxelX, float voxelY, float voxelZ) const
Returns if the given voxel coordinate is inside the image (z is currently ignored)
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)
bool is3D() const
check if current rendering is in 3d
A class to render images as OpenGL Textures.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.