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 
22 class SoNodeList;
23 class SoView2D;
24 class View2DShader;
25 
26 //--------------------------------------------------------------------
29 {
30 public:
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);
66  int getBlendMode();
67 
69  float* getBlendColor();
70 
72  void setDrawsData(bool flag);
73 
75  void setUseShaders(bool flag) { _useShaders = flag; }
76 
78  void initGL();
79 
83 
85  void setLut(View2DLut* lut);
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 setSliceZoom(float zoom);
117  float getSliceZoom();
118 
120  void setOwner(SoView2D* view) { _owner = view; };
122  SoView2D* getOwner() { return _owner; };
123 
125  void setNumXSlices(int num);
128 
130  void setSlab(int slab);
132  int getSlab();
133 
138 
140  void setBackgroundColor(float* color);
141 
143  void setClipBackgroundToImage( bool value );
144 
148  bool drawSlices(int originX, int originY, int width, int height, bool updateLayoutOnly,
149  SoNodeList* extensions = nullptr, int sharedCacheContext=-1, bool is3D = false, bool reverse = false);
150 
153  bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ,
154  float &rx, float &ry);
155 
158  bool mapWorldToDevice(float worldX, float worldY, float worldZ,
159  float &rx, float &ry);
160 
162  void mapWorldToVoxel(float worldX, float worldY, float worldZ,
163  float &voxelX, float &voxelY, float &voxelZ);
164 
166  void mapWorldToVoxel(double worldX, double worldY, double worldZ,
167  double &voxelX, double &voxelY, double &voxelZ);
168 
170  void mapVoxelToWorld(float voxelX, float voxelY, float voxelZ,
171  float &worldX, float &worldY, float &worldZ);
172 
174  void mapVoxelToWorld(double voxelX, double voxelY, double voxelZ,
175  double &worldX, double &worldY, double &worldZ);
176 
179  bool isSliceHit(int x, int y);
180 
182  int getSliceAtDevicePosition(int x, int y) const;
183 
185  bool isVoxelInsideImage(float voxelX,float voxelY,float voxelZ);
186 
188  bool is3D() { return _is3D; }
189 
191  void set3DPixelSize(float devicePixelMM) { _devicePixelMM = devicePixelMM; }
192 
194  SbVec3f getSliceTranslation(int z);
195 
203  SbVec3f getSliceNormal();
204 
211  bool castRayOnSlides(const SbVec3f& p1, const SbVec3f& p2, const SbVec3f& viewpoint,
212  SbVec3f& worldHit, SbVec3f& voxelHit, int* sliceID = nullptr);
213 
214  // SoVec3f convenience methods:
215 
218  bool mapVoxelToDevice(const SbVec3f& voxelCoord,
219  float &rx, float &ry);
220 
222  bool mapVoxelToDevice(const SbVec3f& voxelCoord, SbVec2f& r);
223 
226  bool mapWorldToDevice(const SbVec3f& worldCoord,
227  float &rx, float &ry);
228 
230  bool mapWorldToDevice(const SbVec3f& worldCoord, SbVec2f& r);
231 
233  void mapWorldToVoxel(const SbVec3f& worldCoord,SbVec3f& voxelCoord);
235  void mapWorldToVoxel(const SbVec3d& worldCoord,SbVec3d& voxelCoord);
236 
238  void mapVoxelToWorld(const SbVec3f& voxelCoord,SbVec3f& worldCoord);
240  void mapVoxelToWorld(const SbVec3d& voxelCoord,SbVec3d& worldCoord);
241 
244  float &worldX,
245  float &worldY,
246  float &worldZ);
247 
249  bool mapEventToWorld(View2DEvent* ec, SbVec3f &world);
250 
253  float &vx,
254  float &vy,
255  float &vz);
256 
258  bool mapEventToVoxel(View2DEvent* ec, SbVec3f &voxel);
259 
262  bool mapDeviceToNormalizedCoordinateSystem(int x, int y, SbVec2f &normalizedCoordinate) const;
263 
265  SbVec3f getWorldAxis(int a);
266 
268  SbVec3d getWorldAxisDouble(int a);
269 
271  void getImageSize(int &x, int &y, int &z);
272 
275  void updateSliceList(int sharedContextId=-1, bool layoutOnly=false);
276 
278  View2DSlice* getSlice(int z) const;
279 
281  void getCurrentInnerZoom(float &x, float &y);
282 
284  int getCurrentCacheContext() { return _currentCacheContext; }
285 
287  void getWindowSize(int& x, int& y) { x = _lastWindowX; y = _lastWindowY; }
288 
290  void cleanup();
291 
293  bool shouldRenderReverse(const SbVec3f& viewdir);
294 
298  bool mapDeviceToWorld(int x, int y,
299  SbVec3f& worldCoord);
300 
308  bool mapDeviceToVoxel(int x, int y,
309  SbVec3f& voxelCoord,
310  int* sliceID = nullptr);
311 
315  bool mapDeviceToWorld(int x, int y,
316  float &worldX,
317  float &worldY,
318  float &worldZ);
319 
327  bool mapDeviceToVoxel(int x, int y,
328  float &voxelX,
329  float &voxelY,
330  float &voxelZ,
331  int* sliceID = nullptr);
332 
339  void grabSlice();
340  void ungrabSlice();
341 
342 private:
345  void drawSlice(int slice, int count, int originX, int originY, int width, int height,
346  int sharedContextId, bool updateLayoutOnly, bool is3D, SoNodeList* extensions);
347 
349  SoSFMLImage *_inp;
350 
352  View2DSlice **_sliceList;
354  int _slices;
355 
357  int _sliceStart;
358  int _sliceNum;
359  int _sliceStep;
360  int _timePoint;
361  int _numXSlices;
362  int _slab;
363 
364  float _sliceSizeX;
365  float _sliceSizeY;
366  float _spaceX;
367  float _spaceY;
368  float _offsetX;
369  float _offsetY;
370 
371  int _lastWindowX;
372  int _lastWindowY;
373 
374  float _sliceZoom;
375  float _sliceOriginX;
376  float _sliceOriginY;
377 
378  View2DLut* _lut;
379 
380  int _blendMode;
381  float _blendColor[4];
382  float _bgColor[4];
383  bool _clipBackgroundToImage;
384  View2DTextureFilter _filter;
385  bool _drawData;
386  bool _is3D;
387  float _devicePixelMM;
388  SbVec3f _sliceNormal;
389 
391  View2DAlignXMode _sliceAlignX;
393  View2DAlignYMode _sliceAlignY;
394 
395  float _fixedInnerZoom;
396  bool _fixedInnerZoomOn;
397  float _aspectRatio;
398 
399  int _grabSliceCounter; // flag realized as a counter, because it can be set/unset by various agents
400  int _grabbedLayoutIndex;
401  static View2DSliceList* _grabbingSliceList; // only one slice list can grab the pointer
403 
405  SoView2D* _owner;
406 
408  View2DShader* _shader;
410  View2DShader* _overlayShaders[VIEW2D_MAX_OVERLAY_TEXTURES];
411 
412  bool _useShaders;
413 
415  int _currentCacheContext;
416 
418  View2DSliceCachingMode _caching;
419 };
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
Definition: View2DShader.h:34
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)
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...
View2DSlice * getSlice(int z) const
get slice with slice pos z
void setSliceAlignment(View2DAlignXMode x, View2DAlignYMode y)
set slice alignment
void getDrawOffset(float &x, float &y)
Get slice list draw offset.
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
View2DLut * getLut()
get lut
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
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
SoSFMLImage * getInputImage()
get the input image.
bool shouldRenderReverse(const SbVec3f &viewdir)
returns if the 3d rendering should be done in reverse order dependent on view direction (in world coo...
float * getBlendColor()
get the color for blending (4 floats)
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)
SoView2D * getOwner()
Get the owning SoView2D.
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
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
View2DShader * createShader()
returns a new shader, owned by the caller.
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)
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.
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