00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __EXTENTFILE_H
00021 #define __EXTENTFILE_H
00022
00023 #include "ExtentFileDescriptor.h"
00024 #include "File.h"
00025
00027 namespace extfile
00028 {
00029 UInt32 defaultStripe(UInt32 in, UInt32 sc);
00030
00031
00033
00038 struct LabelDescription
00039 {
00041 char name[64];
00043 char side[2];
00045 char system[32];
00047 char location[32];
00049 bool use;
00051 bool display;
00052 };
00053
00055
00062 class ExtentFile
00063 {
00064 public:
00066 ExtentFileDescriptor efd;
00067
00068 public:
00070 Int32 diskCount;
00072 FileWrapper data[MAXSTRIPES];
00073
00075 UInt32 *address;
00076
00078 UInt8 *tempBuffer;
00079
00080
00081 public:
00083 Int32 zoomLevels;
00085 UInt32 extOff[MAXZOOM];
00086 Int32 extX[MAXZOOM], extY[MAXZOOM], extZ[MAXZOOM];
00087 Int32 sizeX[MAXZOOM], sizeY[MAXZOOM], sizeZ[MAXZOOM];
00089 Int32 extSizeX, extSizeY, extSizeZ;
00091 Int32 realExtSizeX, realExtSizeY, realExtSizeZ;
00093 Int32 imgSizeX, imgSizeY, imgSizeZ;
00095 Int32 extCount;
00097 Int32 extSize;
00098
00100 double voxelSizeX, voxelSizeY, voxelSizeZ;
00101
00103 LabelDescription *labels;
00105 Int32 labelCount;
00106
00108 bool active;
00109
00111 StripeFunc stripefunc;
00112
00113 private:
00115 bool loadLabels(const char *fname);
00116
00117 public:
00119 ExtentFile() { active = false; stripefunc=defaultStripe; labels=NULL; labelCount=0; }
00121 ~ExtentFile() { if(active) close(); }
00122
00124 bool open(const char *configFileName);
00126 bool close();
00127
00129
00136 void loadExtent(int en, void *target);
00137
00139
00150 bool getCube(int r, int x0, int y0, int z0, int x1, int y1, int z1, int c, void *target);
00151 };
00152
00153
00155 class LoadedExtent
00156 {
00157 public:
00159 Int32 slot;
00161 Int32 extent;
00163 UInt32 *address;
00165 UInt32 *finalAddress;
00167 LoadedExtent *prev;
00169 LoadedExtent *next;
00170 };
00171
00173
00179 class CachedExtentFile : public ExtentFile
00180 {
00182 UInt32 cacheSize;
00184 LoadedExtent *lruListItem;
00186 UInt8 *cacheBase;
00188 UInt8 *bottom;
00190 LoadedExtent *cacheHead, *cacheTail;
00192 int unusedCacheSlots;
00193
00195 bool active;
00196
00198 UInt32 *zeroBuffer;
00200 Int32 baseSize[MAXCHANNELS];
00201
00202 private:
00204 bool loadExtent(int en);
00205
00207
00211 void *getExtent(int en, int c)
00212 {
00213 if(en<0 || en>=extCount || c<0 || c>=efd.channels)
00214 return zeroBuffer;
00215 if(!lruListItem[en].finalAddress)
00216 loadExtent(en);
00217 return ((UInt8*)lruListItem[en].finalAddress)+baseSize[c];
00218 }
00219
00220 public:
00222 CachedExtentFile() { active=false; }
00224 ~CachedExtentFile() { if(active) close(); }
00225
00227
00231 bool open(const char *configFileName, const UInt32 cacheSize);
00233 bool close();
00234
00236
00243 void *getExtent(int rf, int x, int y, int z, int c)
00244 {
00245 if(rf<0 || rf>=zoomLevels || x<0 || y<0 || z<0 || x>=extX[rf] || y>=extY[rf] || z>=extZ[rf] || c<0 || c>=efd.channels)
00246 return zeroBuffer;
00247 return ((UInt8*)getExtent(x+(y*extX[rf])+(z*extX[rf]*extY[rf])+extOff[rf],c));
00248 }
00249
00251
00258 UInt32 getVoxel(int rf, int x, int y, int z, int c)
00259 {
00260 if(rf<0 || rf>=zoomLevels || x<0 || y<0 || z<0 || x>=sizeX[rf] || y>=sizeY[rf] || z>=sizeZ[rf] || c<0 || c>=efd.channels)
00261 return 0;
00262 UInt8 *off=((UInt8*)getExtent(rf,x/realExtSizeX,y/realExtSizeY,z/realExtSizeZ,c))+((x%realExtSizeX)+((y%realExtSizeY)*realExtSizeX)+((z%realExtSizeZ)*realExtSizeX*realExtSizeY))*efd.channelSize(efd.channelFormat[c]);
00263 UInt32 rv=0;
00264 for(int i=0;i<efd.channelSize(efd.channelFormat[c]);i++)
00265 rv|=off[i]<<(i<<3);
00266 return rv;
00267 }
00268
00270
00289 void getSlice(float xp, float yp, float zp, float ux, float uy, float uz, float vx, float vy, float vz, float zoom, int w, int h, void *data, int c);
00290
00291 };
00292
00293 }
00294
00295 #endif