MeVisLab Toolbox Reference
View2DSliceList.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 "SoView2DSystem.h"
19#include "SoSFMLImage.h"
20#include "View2DSlice.h"
21
22class SoNodeList;
23class SoView2D;
24class View2DShader;
25
26//--------------------------------------------------------------------
29{
30public:
35
40
42 void setSliceRange(int start, int num, int step =1);
44 void getSliceRange(int &start, int &num, int &step);
45
50
53
55 void setAspectRatio(float ratio) { _aspectRatio = ratio; }
56
58 float getAspectRatio() { return _aspectRatio; }
59
61 void setFixedInnerZoom(bool flag, float fixedZoom);
62
64 void setBlendMode(int blendMode = 0, float *_blendColor=nullptr);
67
69 float* getBlendColor();
70
72 void setDrawsData(bool flag);
73
75 void setUseShaders(bool flag) { _useShaders = flag; }
76
78 void initGL();
79
83
88
90 void setSliceSize(float sizeX, float sizeY);
92 void getSliceSize(float &sizeX, float &sizeY);
93
95 void setSliceSpacing(float dx, float dy);
97 void getSliceSpacing(float &dx, float &dy);
98
100 void setSliceOrigin(float x, float y);
102 void getSliceOrigin(float &x, float &y);
103
105 void setDrawOffset(float x, float y);
107 void getDrawOffset(float &x, float &y);
108
110 void setTimePoint(int timepoint);
113
115 void setUserIndex(int userIndex);
118
120 void setSliceZoom(float zoom);
123
125 void setOwner(SoView2D* view) { _owner = view; };
127 SoView2D* getOwner() { return _owner; };
128
130 void setNumXSlices(int num);
133
135 void setSlab(int slab);
137 int getSlab();
138
143
145 void setBackgroundColor(float* color);
146
148 void setClipBackgroundToImage( bool value );
149
153 bool drawSlices(int originX, int originY, int width, int height, bool updateLayoutOnly,
154 SoNodeList* extensions = nullptr, int sharedCacheContext=-1, bool is3D = false, bool reverse = false);
155
158 bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ,
159 float &rx, float &ry);
160
163 bool mapWorldToDevice(float worldX, float worldY, float worldZ,
164 float &rx, float &ry);
165
167 void mapWorldToVoxel(float worldX, float worldY, float worldZ,
168 float &voxelX, float &voxelY, float &voxelZ);
169
171 void mapWorldToVoxel(double worldX, double worldY, double worldZ,
172 double &voxelX, double &voxelY, double &voxelZ);
173
175 void mapVoxelToWorld(float voxelX, float voxelY, float voxelZ,
176 float &worldX, float &worldY, float &worldZ);
177
179 void mapVoxelToWorld(double voxelX, double voxelY, double voxelZ,
180 double &worldX, double &worldY, double &worldZ);
181
184 bool isSliceHit(int x, int y);
185
187 int getStartSlice() const;
188
190 int getSliceAtDevicePosition(int x, int y) const;
191
193 bool isVoxelInsideImage(float voxelX,float voxelY,float voxelZ);
194
196 bool is3D() { return _is3D; }
197
199 void set3DPixelSize(float devicePixelMM) { _devicePixelMM = devicePixelMM; }
200
203
212
219 bool castRayOnSlides(const SbVec3f& p1, const SbVec3f& p2, const SbVec3f& viewpoint,
220 SbVec3f& worldHit, SbVec3f& voxelHit, int* sliceID = nullptr);
221
222 // SoVec3f convenience methods:
223
227 float &rx, float &ry);
228
231
235 float &rx, float &ry);
236
239
244
249
252 float &worldX,
253 float &worldY,
254 float &worldZ);
255
258
261 float &vx,
262 float &vy,
263 float &vz);
264
267
271
274
277
279 void getImageSize(int &x, int &y, int &z);
280
284
286 View2DSlice* getSlice(int z) const;
287
289 void getCurrentInnerZoom(float &x, float &y);
290
292 int getCurrentCacheContext() { return _currentCacheContext; }
293
295 void getWindowSize(int& x, int& y) { x = _lastWindowX; y = _lastWindowY; }
296
298 void cleanup();
299
302
306 bool mapDeviceToWorld(int x, int y,
308
316 bool mapDeviceToVoxel(int x, int y,
318 int* sliceID = nullptr);
319
323 bool mapDeviceToWorld(int x, int y,
324 float &worldX,
325 float &worldY,
326 float &worldZ);
327
335 bool mapDeviceToVoxel(int x, int y,
336 float &voxelX,
337 float &voxelY,
338 float &voxelZ,
339 int* sliceID = nullptr);
340
347 void grabSlice();
349
350private:
353 void drawSlice(int slice, int count, int originX, int originY, int width, int height,
355
357 SoSFMLImage *_inp;
358
360 View2DSlice **_sliceList;
362 int _slices;
363
365 int _sliceStart;
366 int _sliceNum;
367 int _sliceStep;
368 int _timePoint;
369 int _userIndex;
370 int _numXSlices;
371 int _slab;
372
373 float _sliceSizeX;
374 float _sliceSizeY;
375 float _spaceX;
376 float _spaceY;
377 float _offsetX;
378 float _offsetY;
379
380 int _lastWindowX;
381 int _lastWindowY;
382
383 float _sliceZoom;
384 float _sliceOriginX;
385 float _sliceOriginY;
386
387 View2DLut* _lut;
388
389 int _blendMode;
390 float _blendColor[4];
391 float _bgColor[4];
392 bool _clipBackgroundToImage;
393 View2DTextureFilter _filter;
394 bool _drawData;
395 bool _is3D;
396 float _devicePixelMM;
397 SbVec3f _sliceNormal;
398
400 View2DAlignXMode _sliceAlignX;
402 View2DAlignYMode _sliceAlignY;
403
404 float _fixedInnerZoom;
405 bool _fixedInnerZoomOn;
406 float _aspectRatio;
407
408 int _grabSliceCounter; // flag realized as a counter, because it can be set/unset by various agents
409 int _grabbedLayoutIndex;
410 static View2DSliceList* _grabbingSliceList; // only one slice list can grab the pointer
412
414 SoView2D* _owner;
415
417 View2DShader* _shader;
420
421 bool _useShaders;
422
424 int _currentCacheContext;
425
427 View2DSliceCachingMode _caching;
428};
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
The SoSFMLImage field is the interface used by Inventor Nodes to access image data (in the current im...
Definition SoSFMLImage.h:70
SoView2D is a 2D viewer for image data.
Definition SoView2D.h:62
View2DEvent stores all information on an event on a SoView2D.
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
void mapWorldToVoxel(double worldX, double worldY, double worldZ, double &voxelX, double &voxelY, double &voxelZ)
maps the world coordinate to local voxel coordinates (double version)
View2DSlice * getSlice(int z) const
get slice with slice pos z
void mapWorldToVoxel(const SbVec3d &worldCoord, SbVec3d &voxelCoord)
maps the world coordinate to local voxel coordinates (double version)
void setSlab(int slab)
set number of slab slices (1 means no slab, one slice)
View2DSliceCachingMode getCachingMode()
get data caching mode.
int getTimePoint()
Get the time point.
int getSlab()
get number of slab slices
SbVec3f getSliceNormal()
get normal of slices in world coordinates (all slices have the same normal) The slice normal is ortho...
void setSliceAlignment(View2DAlignXMode x, View2DAlignYMode y)
set slice alignment
void getDrawOffset(float &x, float &y)
Get slice list draw offset.
void setUserIndex(int userIndex)
Set the user index.
int getStartSlice() const
Returns z index of the current start slice or -1 if not set.
void grabSlice()
Switch on or off slice grabbing, i.e.
bool is3D()
is current rendering in 3D?
void initGL()
initialize internals that require a valid GL state
View2DTextureFilter getFilter()
get filter
void mapVoxelToWorld(const SbVec3f &voxelCoord, SbVec3f &worldCoord)
maps the voxel coordinate to world coordinates (float version)
bool mapDeviceToNormalizedCoordinateSystem(int x, int y, SbVec2f &normalizedCoordinate) const
Maps the given device coordinates to normalized View2D coordinates (as used by sliceOrigin and zoomCe...
void getImageSize(int &x, int &y, int &z)
returns the image size in pixels
void getWindowSize(int &x, int &y)
get the window size that is currently rendered on
int getCurrentCacheContext()
get current cache context (-1 if none, can only be called while drawing)
void setClipBackgroundToImage(bool value)
set if background should be clipped to image rect
bool castRayOnSlides(const SbVec3f &p1, const SbVec3f &p2, const SbVec3f &viewpoint, SbVec3f &worldHit, SbVec3f &voxelHit, int *sliceID=nullptr)
Do a 3d collision with the slices, returns first hit of given line with the first slice plane from gi...
void setSliceZoom(float zoom)
Set the inner slice zoom.
void mapVoxelToWorld(float voxelX, float voxelY, float voxelZ, float &worldX, float &worldY, float &worldZ)
maps the voxel coordinate to world coordinates
void getSliceSpacing(float &dx, float &dy)
Get the spacing between slices.
void setSliceRange(int start, int num, int step=1)
set the slice range.
void setCachingMode(View2DSliceCachingMode mode)
set data caching mode.
bool isSliceHit(int x, int y)
Returns if a slice's visible rect is hit at the given device coordinate, if a device rect of a slice ...
void setBlendMode(int blendMode=0, float *_blendColor=nullptr)
set blendmode
void setFilter(View2DTextureFilter filter=FILTER_LINEAR)
set filter
void setAspectRatio(float ratio)
set the aspect ratio
void cleanup()
Remove all current slice objects.
SbVec3f getWorldAxis(int a)
returns the indicated axis (0/1/2) of the slices in world space
void getSliceSize(float &sizeX, float &sizeY)
Get the size of the slice to be drawn.
void getSliceRange(int &start, int &num, int &step)
get the slice range.
float getAspectRatio()
get the aspect ratio
void set3DPixelSize(float devicePixelMM)
set the device coordinate scale when slices are rendered in 3d
void getCurrentInnerZoom(float &x, float &y)
get the inner x/y zoom
View2DShader * createShader()
returns a new shader, owned by the caller.
View2DLut * getLut()
get lut
bool mapEventToWorld(View2DEvent *ec, float &worldX, float &worldY, float &worldZ)
maps the given device event to world coords and returns if a slice was hit
bool shouldRenderReverse(const SbVec3f &viewdir)
returns if the 3d rendering should be done in reverse order dependent on view direction (in world coo...
SoSFMLImage * getInputImage()
get the input image.
bool mapVoxelToDevice(const SbVec3f &voxelCoord, SbVec2f &r)
same as above
bool mapVoxelToDevice(const SbVec3f &voxelCoord, float &rx, float &ry)
Determine a device pixel coordinate from the voxel coordinate in any slice.
void setSliceSpacing(float dx, float dy)
Set the spacing between slices.
bool mapDeviceToVoxel(int x, int y, SbVec3f &voxelCoord, int *sliceID=nullptr)
Maps device coordinates to local voxel coordinates, returns TRUE if successful, otherwise return FALS...
void setUseShaders(bool flag)
sets if the tries to use shaders for hardware lut
void mapWorldToVoxel(const SbVec3f &worldCoord, SbVec3f &voxelCoord)
maps the world coordinate to local voxel coordinates (float version)
bool mapEventToVoxel(View2DEvent *ec, float &vx, float &vy, float &vz)
maps the given device event to voxel coords and returns if a slice was hit
bool mapDeviceToWorld(int x, int y, SbVec3f &worldCoord)
Maps device coordinates to world coordinates, returns TRUE if successful, otherwise return FALSE.
void setInputImage(SoSFMLImage *img)
set the input image.
bool mapWorldToDevice(float worldX, float worldY, float worldZ, float &rx, float &ry)
Determine a device pixel coordinate from the world coordinate in any slice.
int getSliceAtDevicePosition(int x, int y) const
Returns z index of slice whose visible rect is hit, return -1 if no slice is hit.
View2DSliceList()
create empty list
SoView2D * getOwner()
Get the owning SoView2D.
bool mapEventToVoxel(View2DEvent *ec, SbVec3f &voxel)
maps the given device event to voxel coords and returns if a slice was hit
bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float &rx, float &ry)
Determine a device pixel coordinate from the voxel coordinate in any slice.
bool mapDeviceToWorld(int x, int y, float &worldX, float &worldY, float &worldZ)
Maps device coordinates to world coordinates, returns TRUE if successful, otherwise return FALSE.
void setSliceSize(float sizeX, float sizeY)
Set the size of the slice to be drawn.
bool mapWorldToDevice(const SbVec3f &worldCoord, SbVec2f &r)
same as above
void setDrawOffset(float x, float y)
Set slice list draw offset.
void mapVoxelToWorld(const SbVec3d &voxelCoord, SbVec3d &worldCoord)
maps the voxel coordinate to world coordinates (double version)
void setNumXSlices(int num)
set number of slices in a row.
int getNumXSlices()
get number of slices in a row.
void getSliceOrigin(float &x, float &y)
Get the inner slice origin.
bool mapWorldToDevice(const SbVec3f &worldCoord, float &rx, float &ry)
Determine a device pixel coordinate from the world coordinate in any slice.
void setSliceOrigin(float x, float y)
Set the inner slice origin.
void setBackgroundColor(float *color)
set the background color (rgba)
int getUserIndex()
Get the user index.
bool mapEventToWorld(View2DEvent *ec, SbVec3f &world)
maps the given device event to world coords and returns if a slice was hit
bool isVoxelInsideImage(float voxelX, float voxelY, float voxelZ)
Returns if the given voxel is inside the image extends.
float * getBlendColor()
get the color for blending (4 floats)
SbVec3d getWorldAxisDouble(int a)
returns the indicated axis (0/1/2) of the slices in world space
float getSliceZoom()
Get the inner slice zoom.
~View2DSliceList()
destructor
bool drawSlices(int originX, int originY, int width, int height, bool updateLayoutOnly, SoNodeList *extensions=nullptr, int sharedCacheContext=-1, bool is3D=false, bool reverse=false)
Draw the slices (originX, originY, width and height are the current viewport position/size) Returns F...
void setOwner(SoView2D *view)
Set the owning SoView2D.
void setFixedInnerZoom(bool flag, float fixedZoom)
set the fixed innerzoom
void updateSliceList(int sharedContextId=-1, bool layoutOnly=false)
Make the slice list up to date to the current settings.
void mapWorldToVoxel(float worldX, float worldY, float worldZ, float &voxelX, float &voxelY, float &voxelZ)
maps the world coordinate to local voxel coordinates
void setTimePoint(int timepoint)
Set the time point.
int getBlendMode()
get blendmode
void setDrawsData(bool flag)
enable/disable data loading
bool mapDeviceToVoxel(int x, int y, float &voxelX, float &voxelY, float &voxelZ, int *sliceID=nullptr)
Maps device coordinates to local voxel coordinates, returns TRUE if successful, otherwise return FALS...
void mapVoxelToWorld(double voxelX, double voxelY, double voxelZ, double &worldX, double &worldY, double &worldZ)
maps the voxel coordinate to world coordinates (double version)
SbVec3f getSliceTranslation(int z)
get translation vector of the slice in world coordinates (to voxel 0,0,z+0.5)
void setLut(View2DLut *lut)
set lut
a single slice that is stored in a View2DSliceList, typically created by a View2DSliceList
Definition View2DSlice.h:48
Target mlrange_cast(Source arg)
Generic version of checked ML casts.