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 getSliceAtDevicePosition(int x, int y) const;
188
190 bool isVoxelInsideImage(float voxelX,float voxelY,float voxelZ);
191
193 bool is3D() { return _is3D; }
194
196 void set3DPixelSize(float devicePixelMM) { _devicePixelMM = devicePixelMM; }
197
200
209
216 bool castRayOnSlides(const SbVec3f& p1, const SbVec3f& p2, const SbVec3f& viewpoint,
217 SbVec3f& worldHit, SbVec3f& voxelHit, int* sliceID = nullptr);
218
219 // SoVec3f convenience methods:
220
224 float &rx, float &ry);
225
228
232 float &rx, float &ry);
233
236
241
246
249 float &worldX,
250 float &worldY,
251 float &worldZ);
252
255
258 float &vx,
259 float &vy,
260 float &vz);
261
264
268
271
274
276 void getImageSize(int &x, int &y, int &z);
277
281
283 View2DSlice* getSlice(int z) const;
284
286 void getCurrentInnerZoom(float &x, float &y);
287
289 int getCurrentCacheContext() { return _currentCacheContext; }
290
292 void getWindowSize(int& x, int& y) { x = _lastWindowX; y = _lastWindowY; }
293
295 void cleanup();
296
299
303 bool mapDeviceToWorld(int x, int y,
305
313 bool mapDeviceToVoxel(int x, int y,
315 int* sliceID = nullptr);
316
320 bool mapDeviceToWorld(int x, int y,
321 float &worldX,
322 float &worldY,
323 float &worldZ);
324
332 bool mapDeviceToVoxel(int x, int y,
333 float &voxelX,
334 float &voxelY,
335 float &voxelZ,
336 int* sliceID = nullptr);
337
344 void grabSlice();
346
347private:
350 void drawSlice(int slice, int count, int originX, int originY, int width, int height,
352
354 SoSFMLImage *_inp;
355
357 View2DSlice **_sliceList;
359 int _slices;
360
362 int _sliceStart;
363 int _sliceNum;
364 int _sliceStep;
365 int _timePoint;
366 int _userIndex;
367 int _numXSlices;
368 int _slab;
369
370 float _sliceSizeX;
371 float _sliceSizeY;
372 float _spaceX;
373 float _spaceY;
374 float _offsetX;
375 float _offsetY;
376
377 int _lastWindowX;
378 int _lastWindowY;
379
380 float _sliceZoom;
381 float _sliceOriginX;
382 float _sliceOriginY;
383
384 View2DLut* _lut;
385
386 int _blendMode;
387 float _blendColor[4];
388 float _bgColor[4];
389 bool _clipBackgroundToImage;
390 View2DTextureFilter _filter;
391 bool _drawData;
392 bool _is3D;
393 float _devicePixelMM;
394 SbVec3f _sliceNormal;
395
397 View2DAlignXMode _sliceAlignX;
399 View2DAlignYMode _sliceAlignY;
400
401 float _fixedInnerZoom;
402 bool _fixedInnerZoomOn;
403 float _aspectRatio;
404
405 int _grabSliceCounter; // flag realized as a counter, because it can be set/unset by various agents
406 int _grabbedLayoutIndex;
407 static View2DSliceList* _grabbingSliceList; // only one slice list can grab the pointer
409
411 SoView2D* _owner;
412
414 View2DShader* _shader;
417
418 bool _useShaders;
419
421 int _currentCacheContext;
422
424 View2DSliceCachingMode _caching;
425};
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.
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.