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 
24 class View2DSliceList;
25 class View2DShader;
26 class SoNodeList;
27 
28 // declare the LUTData
29 ML_START_NAMESPACE
30 
31  template <typename T> class LUTData;
32 
33 ML_END_NAMESPACE
34 
36 #define VIEW2D_MAX_OVERLAY_TEXTURES 32
37 
38 enum {
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 {
49 public:
54 
56  void destroy();
57 
62 
64  void setShaders(View2DShader* shader, View2DShader** overlayShaders);
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);
112  float getSliceZoom();
113 
118 
120  void getVoxelSize(float &vx,float &vy, float &vz);
121 
123  void getVoxelSize(double &vx, double &vy, double &vz);
124 
126  void updateLayout();
127 
129  void setLut(View2DLut* lut);
130 
132  void setBlendMode(int blendMode, float* blendColor=nullptr);
133 
135  void setBackgroundColor(float* color);
136 
138  void setTimePoint(int timepoint);
141 
143  void drawBackground(bool clipBackgroundToImage = false);
144 
147  void drawSlice(View2DSliceList *dsl, int originX, int originY, int width, int height,
148  SoNodeList* extensions, bool extensionsOnly, bool isSlabRendering);
149 
150  void drawSliceIn3D(View2DSliceList * dsl, bool extensionsOnly, SoNodeList* extensions, bool reverseDrawingOrder);
151 
153  void drawTexture(View2DTexture* texture, int blendMode);
155  void drawTexture(View2DTexture* texture, int blendMode, float* blendColor);
157  void drawTexture(View2DTexture* texture, int blendMode, float* blendColor,View2DTextureFilter filter);
158 
160  void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3],
161  int blendMode, float* blendColor);
162 
164  void drawTexture(View2DTexture* texture, float vp1[3], float vp2[3], float vp3[3],
165  int blendMode, float* blendColor, View2DTextureFilter filter);
166 
168  void getImageDeviceRect(float &dx1, float &dy1, float &dx2, float &dy2);
169 
171  static void enableBlending(int blendMode);
172 
179  bool select(float x, float y, float &voxelX, float &voxelY, float &voxelZ);
180 
182  bool select(float x, float y, SbVec3f &voxel);
183 
185  bool select(const SbVec2f& d, SbVec3f &voxel);
186 
189  bool isSliceHit(float x, float y) const;
190 
195  void mapDeviceToNormalizedCoordinateSystem(int x, int y, SbVec2f &normalizedCoordinate) const;
196 
198  bool isValidVoxel(float voxelX, float voxelY, float voxelZ);
199 
201  bool isValidVoxel(const SbVec3f& voxel);
202 
204  void invalidate();
205 
209 
212  float millimeterToPixel(float lengthMillimeter);
213 
217  void mapVoxelToDevice(float voxelX, float voxelY, float voxelZ,
218  float &rx, float &ry);
219 
221  void mapVoxelToDevice(const SbVec3f &voxelCoord,
222  float &rx, float &ry);
223 
225  void mapVoxelToDevice(const SbVec3f &voxelCoord,
226  SbVec2f& r);
227 
230 
233  void mapWorldToDevice(float worldX, float worldY, float worldZ,
234  float &rx, float &ry);
235 
237  void mapWorldToDevice(const SbVec3f &worldCoord,
238  float &rx, float &ry);
239 
241  void mapWorldToDevice(const SbVec3f &worldCoord,
242  SbVec2f& r);
243 
245  void getVisibleDeviceRect(float &dx1,float &dy1, float &dx2, float &dy2);
246 
248  View2DTexture* getOverlayTexture(void* user = nullptr, int id = 0);
249 
251  int getLutSize();
252 
254  float getInnerZoom();
255 
257  void setDraw3D(bool flag, float devicePixelSize = 1);
258 
260  bool is3D() { return _is3D; }
261 
263  bool containsVoxel(const SbVec3f& voxelPos);
264 
265 private:
267  void* getImageSlice(int slice);
268 
271  int _sliceZ;
273  int _timePoint;
275  float _drawPosX;
277  float _drawPosY;
279  float _drawWidth;
281  float _drawHeight;
282 
283  View2DTextureFilter _filter;
284  int _blendMode;
285  float _blendColor[4];
286  float _bgColor[4];
287  float _zoom;
288  float _sliceZoom;
289  float _sliceOriginX;
290  float _sliceOriginY;
291 
292  float _fixedInnerZoom;
293  bool _fixedInnerZoomOn;
294 
296 
298  SoSFMLImage *_inp;
299 
301  float _centerX;
303  float _centerY;
304 
306  int _imageWidth;
308  int _imageHeight;
309 
311  float _vxFlt,_vyFlt,_vzFlt;
312  double _vxDbl,_vyDbl,_vzDbl;
314 
316  float _aspectRatio;
317 
319  bool _drawData;
321  bool _is3D;
322 
324  View2DAlignXMode _sliceAlignX;
326  View2DAlignYMode _sliceAlignY;
327 
329  View2DSliceCachingMode _caching;
330 
332  View2DTexture _sliceTexture;
334  View2DTexture *_overlayTextures[VIEW2D_MAX_OVERLAY_TEXTURES];
335 
337  View2DShader* _shader;
338  View2DShader** _overlayShaders;
339 };
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
Definition: View2DShader.h:34
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
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
View2DTexture * getOverlayTexture(void *user=nullptr, int id=0)
get the overlay texture (is only created on first call and cached afterwards)
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...
SoSFMLImage * getInputImage()
get the input image.
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)
bool is3D()
check if current rendering is in 3d
Definition: View2DSlice.h:260
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
View2DShader * getShader()
get the main shader (might be NULL);
Definition: View2DSlice.h:67
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...
A class to render images as OpenGL Textures.
Definition: View2DTexture.h:47