00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SO_VR_RASTER_STACK_READER_
00024 #define _SO_VR_RASTER_STACK_READER_
00025
00026 #ifdef _WIN32
00027 #pragma warning( push )
00028 #pragma warning(disable:4251)
00029 #endif
00030
00031 #include <LDM/readers/SoVolumeReader.h>
00032 #include <Inventor/helpers/SbFileHelper.h>
00033 #include <Inventor/image/SoRasterImageFile.h>
00034 #include <Inventor/image/SoRasterReaderSet.h>
00035 #include <Inventor/image/SoRasterImageRW.h>
00036 #include <Inventor/image/SbRasterImage.h>
00037 #include <Inventor/STL/vector>
00038 #include <Inventor/STL/string>
00039 #include <VolumeViz/nodes/SoVolumeData.h>
00040
00114 class SoVRRasterStackReader : public SoVolumeReader
00115 {
00116 SO_FIELDCONTAINER_HEADER(SoVRRasterStackReader);
00117
00118 public:
00119
00121 enum ChannelSelection {
00125 MAX_CHANNEL = 0,
00129 LUMINANCE = 1,
00133 RED_CHANNEL = 2,
00137 GREEN_CHANNEL = 3,
00141 BLUE_CHANNEL = 4,
00145 ALPHA_CHANNEL = 5,
00149 ALL_CHANNELS = 11
00150 };
00151
00153 SoVRRasterStackReader();
00154
00159 virtual int setFilename(const SbString& filename);
00160
00168 SbBool setFilenameList(const SbStringList& filenameList);
00169
00186 SbBool setDirectory(const SbString& directory);
00187
00194 virtual ReadError getDataChar(SbBox3f& size, SoDataSet::DataType& type, SbVec3i32& dim);
00195
00202 virtual void getSubSlice(const SbBox2i32& subSlice, int sliceNumber, void* data);
00203
00207 void setSize(SbBox3f& size) {m_size = size;};
00208
00212 void setChannelSelection(ChannelSelection cs) {m_channelSelection = cs;};
00213
00217 virtual SoVolumeReader::ReaderType getReaderType () {return RASTERSTACK;};
00218
00222 virtual SbBool isRGBA() const;
00223
00227 virtual SbBool isThreadSafe() const;
00228
00229 private:
00230
00231 int extractFileList(const SbString& headFile);
00232 SbBool extractParameters(const char* lineStr);
00233
00234 SoDataSet::DataType findOutDestType(const SbRasterImage::Components nc, const unsigned int numComponent);
00235
00236 void RGBA2HLS(SbVec3f& hls, float* rgba);
00237
00238 float convertFloat(float value);
00239 short convertShort(short value);
00240 int32_t convertInt32(int32_t value);
00241 unsigned short convertUShort(unsigned short value);
00242 uint32_t convertUInt32(uint32_t value);
00243 SbBool needEndianConversion();
00244
00245 int getChannelId(const char* channel);
00246
00247 template <typename T>
00248 void getSubSliceInternal(const SbBox2i32 &subSlice, int sliceNumber, void* data);
00249
00250 template <typename TSRC, typename T>
00251 void convertSubSliceInternal(TSRC* srcData, const SbVec2i32 srcSize, const unsigned int srcNumComponent, std::vector<T>& dstVector);
00252
00260 SbBool readImage(int numImage, SbRasterImage& rasterImage, const SbBox2i32& region, SbBool infoOnly);
00261
00262 template <typename T>
00263 void getSingleChannelData(std::vector<T> srcVector, SbVec2i32& size2s,
00264 unsigned int xMin, unsigned int xMax,
00265 unsigned int yMin, unsigned int yMax,
00266 void* data);
00267
00268 template <typename T>
00269 T endianConverter(const T value);
00270
00271 SbString m_listDirectory;
00272 SbBox3f m_size;
00273 SbVec3i32 m_dim;
00274 SbBool m_isRawData;
00275 unsigned int m_nc;
00276 SoDataSet::DataType m_srcType;
00277 SoDataSet::DataType m_destType;
00278 ChannelSelection m_channelSelection;
00279 std::vector< SbString > m_fileList;
00280 unsigned int m_rawHeaderSize;
00281 SbBool m_rawIsBigEndian;
00282 SbBool m_rawIsBinary;
00283
00284 private:
00285
00286 bool m_isInitialized;
00287
00288
00289
00290
00291
00292 template <typename T>
00293 SbBool readRawBuffer(FILE* fp, SbRasterImage& rasterImage, const SbBox2i32& region);
00294 };
00295
00296 #ifdef _WIN32
00297 #pragma warning( pop )
00298 #endif
00299
00300 #endif
00301
00302