MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoView2D/View2DSliceList.h
Go to the documentation of this file.
00001 #ifndef __View2DSliceList_H
00002 #define __View2DSliceList_H
00003 //----------------------------------------------------------------------------------
00004 // **InsertLicense** code
00005 //----------------------------------------------------------------------------------
00007 
00013 //----------------------------------------------------------------------------------
00014 
00015 #ifndef __SoView2DSystem_H
00016 #include "SoView2DSystem.h"
00017 #endif
00018 #ifndef __SoSFMLImage_H
00019 #include "SoSFMLImage.h"
00020 #endif
00021 #ifndef __View2DSlice_H
00022 #include "View2DSlice.h"
00023 #endif
00024 
00025 class SoNodeList;
00026 class SoView2D;
00027 class View2DShader;
00028 
00029 //--------------------------------------------------------------------
00031 class SOVIEW2D_API View2DSliceList {
00032 
00033 public:
00035   View2DSliceList();
00037    ~View2DSliceList();
00038 
00040   void         setInputImage(SoSFMLImage *img);
00042   SoSFMLImage *getInputImage();
00043 
00045   void     setSliceRange(int  start, int num, int step =1);
00047   void     getSliceRange(int &start, int &num, int &step);
00048 
00050   void     setFilter(View2DTextureFilter filter = FILTER_LINEAR);
00052   View2DTextureFilter      getFilter();
00053 
00055   void setSliceAlignment(sliceAlignXMode x, sliceAlignYMode y);
00056 
00058   void setAspectRatio(float ratio) { _aspectRatio = ratio; }
00059 
00061   float getAspectRatio() { return _aspectRatio; }
00062 
00064   void setFixedInnerZoom(bool flag, float fixedZoom);
00065 
00067   void     setBlendMode(int blendMode = 0,  float *_blendColor=NULL);
00069   int      getBlendMode();
00070 
00072   float*   getBlendColor();
00073 
00075   void setDrawsData(bool flag);
00076 
00078   void setUseShaders(bool flag) { _useShaders = flag; }
00079 
00081   void initGL();
00082 
00084   void           setLut(ml::LUTData<MLuint8>* lut);
00086   ml::LUTData<MLuint8>*  getLut();
00087 
00089   void     setSliceSize(float  sizeX, float  sizeY);
00091   void     getSliceSize(float &sizeX, float &sizeY);
00092 
00094   void     setSliceSpacing(float  dx, float  dy);
00096   void     getSliceSpacing(float &dx, float &dy);
00097 
00099   void     setSliceOrigin(float  x, float  y);
00101   void     getSliceOrigin(float &x, float &y);
00102 
00104   void     setDrawOffset(float  x, float  y);
00106   void     getDrawOffset(float &x, float &y);
00107 
00109   void     setTimePoint(int timepoint);
00111   int      getTimePoint();
00112 
00114   void     setSliceZoom(float  zoom);
00116   float    getSliceZoom();
00117 
00119   void     setOwner(SoView2D* view) { _owner = view; };
00121   SoView2D* getOwner() { return _owner; };
00122 
00124   void setNumXSlices(int num);
00126   int  getNumXSlices();
00127 
00129   void setSlab(int slab);
00131   int  getSlab();
00132 
00134    void          setCachingMode(SLICE_CACHING_MODE mode);
00136   SLICE_CACHING_MODE getCachingMode();
00137 
00139   void setBackgroundColor(float* color);
00140 
00144    bool    drawSlices(int originX, int originY, int width, int height, bool updateLayoutOnly,
00145                       SoNodeList* extensions = NULL, int sharedCacheContext=-1, bool is3D = false, bool reverse = false);
00146 
00149   bool mapVoxelToDevice(float voxelX, float voxelY, float voxelZ,
00150                         float &rx, float &ry);
00151 
00154   bool mapWorldToDevice(float worldX, float worldY, float worldZ,
00155                         float &rx, float &ry);
00156 
00158   void mapWorldToVoxel(float   worldX, float   worldY, float   worldZ,
00159                        float &voxelX, float &voxelY, float &voxelZ);
00160 
00162   void mapVoxelToWorld(float   voxelX, float   voxelY, float   voxelZ,
00163                        float &worldX, float &worldY, float &worldZ);
00164 
00167   bool isSliceHit(int x, int y);
00168 
00170   int getSliceAtDevicePosition(int x, int y);
00171 
00173   bool  isVoxelInsideImage(float voxelX,float voxelY,float voxelZ);
00174 
00176   bool  is3D() { return _is3D; }
00177 
00179   void set3DPixelSize(float devicePixelMM) { _devicePixelMM = devicePixelMM; }
00180 
00182   SbVec3f  getSliceTranslation(int z);
00183 
00185   SbVec3f  getSliceNormal();
00186 
00193   bool castRayOnSlides(const SbVec3f& p1, const SbVec3f& p2, const SbVec3f& viewpoint,
00194     SbVec3f& worldHit, SbVec3f& voxelHit, int* sliceID = NULL);
00195 
00196   // SoVec3f convenience methods:
00197 
00200   bool mapVoxelToDevice(const SbVec3f& voxelCoord,
00201                         float &rx, float &ry);
00202 
00204   bool mapVoxelToDevice(const SbVec3f& voxelCoord, SbVec2f& r);
00205 
00208   bool mapWorldToDevice(const SbVec3f& worldCoord,
00209                         float &rx, float &ry);
00210 
00212   bool mapWorldToDevice(const SbVec3f& voxelCoord, SbVec2f& r);
00213 
00215   void mapWorldToVoxel(const SbVec3f& worldCoord,SbVec3f& voxelCoord);
00216 
00218   void mapVoxelToWorld(const SbVec3f& voxelCoord,SbVec3f& worldCoord);
00219 
00221   bool mapEventToWorld(View2DEvent* ec,
00222       float &worldX,
00223       float &worldY,
00224       float &worldZ);
00225 
00227   bool mapEventToWorld(View2DEvent* ec, SbVec3f &world);
00228 
00230   bool mapEventToVoxel(View2DEvent* ec,
00231       float &vx,
00232       float &vy,
00233       float &vz);
00234 
00236   bool mapEventToVoxel(View2DEvent* ec, SbVec3f &voxel);
00237 
00239   SbVec3f getWorldAxis(int a);
00240 
00242   void getImageSize(int &x, int &y, int &z);
00243 
00246   void             updateSliceList(int sharedContextId=-1, bool layoutOnly=false);
00247 
00249   View2DSlice*     getSlice(int z);
00250 
00252   void    getCurrentInnerZoom(float &x, float &y);
00253 
00255   int     getCurrentCacheContext() { return _currentCacheContext; }
00256 
00258   void getWindowSize(int& x, int& y) { x = _lastWindowX; y = _lastWindowY; }
00259 
00261   void             cleanup();
00262 
00264   bool shouldRenderReverse(const SbVec3f& viewdir);
00265 
00269   bool mapDeviceToWorld(int x, int y,
00270       SbVec3f& worldCoord);
00271 
00279   bool mapDeviceToVoxel(int x, int y,
00280       SbVec3f& voxelCoord,
00281       int* sliceID = NULL);
00282 
00286   bool mapDeviceToWorld(int x, int y,
00287       float &worldX,
00288       float &worldY,
00289       float &worldZ);
00290 
00298   bool mapDeviceToVoxel(int x, int y,
00299       float &voxelX,
00300       float &voxelY,
00301       float &voxelZ,
00302       int* sliceID = NULL);
00303 
00310   void grabSlice();
00311   void ungrabSlice();
00312 
00313 private:
00316   void drawSlice(int slice, int count, int originX, int originY, int width, int height,
00317                  int sharedContextId, bool updateLayoutOnly, bool is3D, SoNodeList* extensions);
00318 
00320   SoSFMLImage         *_inp;
00321 
00323   View2DSlice      **_sliceList;
00325   int              _slices;
00326 
00328   int              _sliceStart;
00329   int              _sliceNum;
00330   int              _sliceStep;
00331   int              _timePoint;
00332   int              _numXSlices;
00333   int              _slab;
00334 
00335   float            _sliceSizeX;
00336   float            _sliceSizeY;
00337   float            _spaceX;
00338   float            _spaceY;
00339   float            _offsetX;
00340   float            _offsetY;
00341 
00342   int              _lastWindowX;
00343   int              _lastWindowY;
00344 
00345   float            _sliceZoom;
00346   float            _sliceOriginX;
00347   float            _sliceOriginY;
00348 
00349   ml::LUTData<MLuint8>*    _lut;
00350 
00351   int              _blendMode;
00352   float            _blendColor[4];
00353   float            _bgColor[4];
00354   View2DTextureFilter _filter;
00355   bool             _drawData;
00356   bool             _is3D;
00357   float            _devicePixelMM;
00358   SbVec3f          _sliceNormal;
00359 
00361   sliceAlignXMode _sliceAlignX;
00363   sliceAlignYMode _sliceAlignY;
00364 
00365   float            _fixedInnerZoom;
00366   bool             _fixedInnerZoomOn;
00367   float            _aspectRatio;
00368 
00369   int              _grabSliceCounter; // flag realized as a counter, because it can be set/unset by various agents
00370   int              _grabbedLayoutIndex;
00371   static View2DSliceList* _grabbingSliceList; // only one slice list can grab the pointer
00373 
00375   SoView2D* _owner;
00376 
00378   View2DShader* _shader;
00380   View2DShader* _overlayShaders[VIEW2D_MAX_OVERLAY_TEXTURES];
00381 
00382   bool _useShaders;
00383 
00385   int _currentCacheContext;
00386 
00388   SLICE_CACHING_MODE    _caching;
00389 };
00390 
00391 #endif
00392 
00393 
00394