MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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:
32 View2DSliceList() = default;
35
40
42 void setSliceRange(int start, int num, int step = 1);
44 void getSliceRange(int& start, int& num, int& step) const;
45
50
53
55 void setAspectRatio(float ratio)
56 {
57 _aspectRatio = ratio;
58 }
59
61 float getAspectRatio() const
62 {
63 return _aspectRatio;
64 }
65
67 void setFixedInnerZoom(bool flag, float fixedZoom);
68
70 void setBlendMode(int blendMode = 0, float* _blendColor = nullptr);
72 int getBlendMode() const;
73
75 float* getBlendColor();
76
78 void setDrawsData(bool flag);
79
82 {
83 _useShaders = flag;
84 }
85
87 void initGL();
88
92
96 View2DLut* getLut() const;
97
99 void setSliceSize(float sizeX, float sizeY);
101 void getSliceSize(float& sizeX, float& sizeY) const;
102
104 void setSliceSpacing(float dx, float dy);
106 void getSliceSpacing(float& dx, float& dy) const;
107
109 void setSliceOrigin(float x, float y);
111 void getSliceOrigin(float& x, float& y) const;
112
114 void setDrawOffset(float x, float y);
116 void getDrawOffset(float& x, float& y) const;
117
119 void setTimePoint(int timepoint);
121 int getTimePoint() const;
122
124 void setUserIndex(int userIndex);
126 int getUserIndex() const;
127
129 void setSliceZoom(float zoom);
131 float getSliceZoom() const;
132
135 {
136 _owner = view;
137 }
140 {
141 return _owner;
142 }
143
145 void setNumXSlices(int num);
147 int getNumXSlices() const;
148
150 void setSlab(int slab);
152 int getSlab() const;
153
158
160 void setBackgroundColor(float* color);
161
163 void setClipBackgroundToImage(bool value);
164
168 bool drawSlices(int originX, int originY, int width, int height, bool updateLayoutOnly,
169 SoNodeList* extensions = nullptr, int sharedCacheContext = -1, bool is3D = false,
170 bool reverse = false);
171
174 bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float& rx, float& ry) const;
175
178 bool mapWorldToDevice(float worldX, float worldY, float worldZ, float& rx, float& ry) const;
179
181 bool mapWorldToVoxel(float worldX, float worldY, float worldZ, float& voxelX, float& voxelY, float& voxelZ) const;
182
184 bool mapWorldToVoxel(double worldX, double worldY, double worldZ, double& voxelX, double& voxelY,
185 double& voxelZ) const;
186
188 bool mapVoxelToWorld(float voxelX, float voxelY, float voxelZ, float& worldX, float& worldY, float& worldZ) const;
189
191 bool mapVoxelToWorld(double voxelX, double voxelY, double voxelZ, double& worldX, double& worldY,
192 double& worldZ) const;
193
196 bool isSliceHit(int x, int y) const;
197
199 int getStartSlice() const;
200
202 int getSliceAtDevicePosition(int x, int y) const;
203
205 bool isVoxelInsideImage(float voxelX, float voxelY, float voxelZ) const;
206
208 bool is3D() const
209 {
210 return _is3D;
211 }
212
215 {
216 _devicePixelMM = devicePixelMM;
217 }
218
221
230
238 SbVec3f& voxelHit, int* sliceID = nullptr);
239
240 // SoVec3f convenience methods:
241
244 bool mapVoxelToDevice(const SbVec3f& voxelCoord, float& rx, float& ry) const;
245
248
251 bool mapWorldToDevice(const SbVec3f& worldCoord, float& rx, float& ry) const;
252
255
260
265
267 bool mapEventToWorld(View2DEvent* ec, float& worldX, float& worldY, float& worldZ) const;
268
271
273 static bool mapEventToVoxel(View2DEvent* ec, float& vx, float& vy, float& vz);
274
277
281
284
287
289 void getImageSize(int& x, int& y, int& z) const;
290
293 void updateSliceList(int sharedContextId = -1, bool layoutOnly = false);
294
296 View2DSlice* getSlice(int z) const;
297
299 void getCurrentInnerZoom(float& x, float& y) const;
300
303 {
304 return _currentCacheContext;
305 }
306
308 void getWindowSize(int& x, int& y) const
309 {
310 x = _lastWindowX;
311 y = _lastWindowY;
312 }
313
315 void cleanup();
316
319
322 bool mapDeviceToWorld(int x, int y, SbVec3f& worldCoord);
323
330 bool mapDeviceToVoxel(int x, int y, SbVec3f& voxelCoord, int* sliceID = nullptr);
331
334 bool mapDeviceToWorld(int x, int y, float& worldX, float& worldY, float& worldZ);
335
342 bool mapDeviceToVoxel(int x, int y, float& voxelX, float& voxelY, float& voxelZ, int* sliceID = nullptr);
343
350 void grabSlice();
352
353private:
356 void drawSlice(int slice, int count, int originX, int originY, int width, int height, int sharedContextId,
357 bool updateLayoutOnly, bool is3D, SoNodeList* extensions);
358
359 enum {
361 // (if the type for slice indices is changed to a bigger type
362 // than int, change this constant, too!)
363 INVALID_LAYOUT_INDEX = static_cast<int>(0x80000000)
364 };
365
367 SoSFMLImage* _inp{};
368
370 View2DSlice** _sliceList{};
372 int _slices{};
373
375 int _sliceStart{};
376 int _sliceNum{};
377 int _sliceStep{1};
378 int _timePoint{};
379 int _userIndex{};
380 int _numXSlices{1};
381 int _slab{1};
382
383 float _sliceSizeX{SLICE_ALIGNX_CENTER};
384 float _sliceSizeY{SLICE_ALIGNY_CENTER};
385 float _spaceX{1};
386 float _spaceY{1};
387 float _offsetX{};
388 float _offsetY{};
389
390 int _lastWindowX{-1};
391 int _lastWindowY{-1};
392
393 float _sliceZoom{1};
394 float _sliceOriginX{};
395 float _sliceOriginY{};
396
397 View2DLut* _lut{};
398
399 int _blendMode{BLEND_REPLACE};
400 float _blendColor[4]{1, 1, 1, 1};
401 float _bgColor[4]{0, 0, 0, 1};
402 bool _clipBackgroundToImage{};
404 bool _drawData{true};
405 bool _is3D{};
406 float _devicePixelMM{1};
407 SbVec3f _sliceNormal;
408
410 View2DAlignXMode _sliceAlignX{};
412 View2DAlignYMode _sliceAlignY{};
413
414 float _fixedInnerZoom{1};
415 bool _fixedInnerZoomOn{};
416 float _aspectRatio{1};
417
418 int _grabSliceCounter{}; // flag realized as a counter, because it can be set/unset by various agents
419 int _grabbedLayoutIndex{INVALID_LAYOUT_INDEX};
420 static View2DSliceList* _grabbingSliceList; // only one slice list can grab the pointer
422
424 SoView2D* _owner{};
425
427 View2DShader* _shader{};
429 View2DShader* _overlayShaders[VIEW2D_MAX_OVERLAY_TEXTURES]{};
430
431 bool _useShaders{};
432
434 int _currentCacheContext{-1};
435
438};
View2DAlignYMode
slice align mode y
@ SLICE_ALIGNY_CENTER
View2DTextureFilter
Filter mode.
@ FILTER_LINEAR
Bilinear filtering (after classification/LUT)
@ BLEND_REPLACE
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
The SoSFMLImage field is the interface used by Inventor Nodes to access image data (in the current im...
Definition SoSFMLImage.h:84
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
View2DSlice * getSlice(int z) const
get slice with slice pos z
View2DLut * getLut() const
get lut
void setSlab(int slab)
set number of slab slices (1 means no slab, one slice)
int getSlab() const
get number of slab slices
static View2DShader * createShader()
returns a new shader, owned by the caller.
void getSliceSpacing(float &dx, float &dy) const
Get the spacing between slices.
View2DSliceList()=default
create empty list
bool mapEventToWorld(View2DEvent *ec, float &worldX, float &worldY, float &worldZ) const
maps the given device event to world coords and returns if a slice was hit
void setSliceAlignment(View2DAlignXMode x, View2DAlignYMode y)
set slice alignment
int getNumXSlices() const
get number of slices in a row.
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.
void initGL()
initialize internals that require a valid GL state
bool mapDeviceToNormalizedCoordinateSystem(int x, int y, SbVec2f &normalizedCoordinate) const
Maps the given device coordinates to normalized View2D coordinates (as used by sliceOrigin and zoomCe...
float getSliceZoom() const
Get the inner slice zoom.
void getImageSize(int &x, int &y, int &z) const
returns the image size in pixels
bool mapWorldToDevice(const SbVec3f &worldCoord, float &rx, float &ry) const
Determine a device pixel coordinate from the world coordinate in any slice.
View2DTextureFilter getFilter() const
get filter
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...
bool mapEventToWorld(View2DEvent *ec, SbVec3f &world) const
maps the given device event to world coords and returns if a slice was hit
void setSliceZoom(float zoom)
Set the inner slice zoom.
bool mapVoxelToWorld(float voxelX, float voxelY, float voxelZ, float &worldX, float &worldY, float &worldZ) const
maps the voxel coordinate to world coordinates
void setSliceRange(int start, int num, int step=1)
set the slice range.
void setCachingMode(View2DSliceCachingMode mode)
set data caching mode.
bool mapVoxelToDevice(const SbVec3f &voxelCoord, SbVec2f &r) const
same as above
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.
View2DSliceCachingMode getCachingMode() const
get data caching mode.
SbVec3f getWorldAxis(int a)
returns the indicated axis (0/1/2) of the slices in world space
bool isSliceHit(int x, int y) const
Returns if a slice's visible rect is hit at the given device coordinate, if a device rect of a slice ...
void set3DPixelSize(float devicePixelMM)
set the device coordinate scale when slices are rendered in 3d
SoSFMLImage * getInputImage()
get the input image.
int getUserIndex() const
Get the user index.
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
bool is3D() const
is current rendering in 3D?
int getCurrentCacheContext() const
get current cache context (-1 if none, can only be called while drawing)
bool mapVoxelToWorld(const SbVec3d &voxelCoord, SbVec3d &worldCoord) const
maps the voxel coordinate to world coordinates (double version)
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.
int getBlendMode() const
get blendmode
bool mapWorldToVoxel(double worldX, double worldY, double worldZ, double &voxelX, double &voxelY, double &voxelZ) const
maps the world coordinate to local voxel coordinates (double version)
int getSliceAtDevicePosition(int x, int y) const
Returns z index of slice whose visible rect is hit, return -1 if no slice is hit.
int getTimePoint() const
Get the time point.
bool mapVoxelToWorld(double voxelX, double voxelY, double voxelZ, double &worldX, double &worldY, double &worldZ) const
maps the voxel coordinate to world coordinates (double version)
SbVec3f getSliceNormal() const
get normal of slices in world coordinates (all slices have the same normal) The slice normal is ortho...
SoView2D * getOwner() const
Get the owning SoView2D.
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.
static 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
void getWindowSize(int &x, int &y) const
get the window size that is currently rendered on
void setDrawOffset(float x, float y)
Set slice list draw offset.
SbVec3f getSliceTranslation(int z) const
get translation vector of the slice in world coordinates (to voxel 0,0,z+0.5)
bool mapWorldToVoxel(float worldX, float worldY, float worldZ, float &voxelX, float &voxelY, float &voxelZ) const
maps the world coordinate to local voxel coordinates
void setNumXSlices(int num)
set number of slices in a row.
bool isVoxelInsideImage(float voxelX, float voxelY, float voxelZ) const
Returns if the given voxel is inside the image extends.
bool mapWorldToDevice(float worldX, float worldY, float worldZ, float &rx, float &ry) const
Determine a device pixel coordinate from the world coordinate in any slice.
bool mapWorldToVoxel(const SbVec3f &worldCoord, SbVec3f &voxelCoord) const
maps the world coordinate to local voxel coordinates (float version)
void setSliceOrigin(float x, float y)
Set the inner slice origin.
void getSliceSize(float &sizeX, float &sizeY) const
Get the size of the slice to be drawn.
void setBackgroundColor(float *color)
set the background color (rgba)
bool mapWorldToDevice(const SbVec3f &worldCoord, SbVec2f &r) const
same as above
float * getBlendColor()
get the color for blending (4 floats)
void getCurrentInnerZoom(float &x, float &y) const
get the inner x/y zoom
bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ, float &rx, float &ry) const
Determine a device pixel coordinate from the voxel coordinate in any slice.
SbVec3d getWorldAxisDouble(int a)
returns the indicated axis (0/1/2) of the slices in world space
bool mapVoxelToWorld(const SbVec3f &voxelCoord, SbVec3f &worldCoord) const
maps the voxel coordinate to world coordinates (float version)
~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
static bool mapEventToVoxel(View2DEvent *ec, SbVec3f &voxel)
maps the given device event to voxel coords and returns if a slice was hit
bool mapWorldToVoxel(const SbVec3d &worldCoord, SbVec3d &voxelCoord) const
maps the world coordinate to local voxel coordinates (double version)
void updateSliceList(int sharedContextId=-1, bool layoutOnly=false)
Make the slice list up to date to the current settings.
bool shouldRenderReverse(const SbVec3f &viewdir) const
returns if the 3d rendering should be done in reverse order dependent on view direction (in world coo...
float getAspectRatio() const
get the aspect ratio
void getSliceRange(int &start, int &num, int &step) const
get the slice range.
void setTimePoint(int timepoint)
Set the time point.
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 setLut(View2DLut *lut)
set lut
void getDrawOffset(float &x, float &y) const
Get slice list draw offset.
bool mapVoxelToDevice(const SbVec3f &voxelCoord, float &rx, float &ry) const
Determine a device pixel coordinate from the voxel coordinate in any slice.
void getSliceOrigin(float &x, float &y) const
Get the inner slice origin.
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.