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
00115 class SoVRRasterStackReader : public SoVolumeReader
00116 {
00117 SO_FIELDCONTAINER_HEADER(SoVRRasterStackReader);
00118
00119 public:
00120
00122 enum ChannelSelection {
00126 MAX_CHANNEL = 0,
00130 LUMINANCE = 1,
00134 RED_CHANNEL = 2,
00138 GREEN_CHANNEL = 3,
00142 BLUE_CHANNEL = 4,
00146 ALPHA_CHANNEL = 5,
00150 ALL_CHANNELS = 11
00151 };
00152
00154 SoVRRasterStackReader();
00155
00160 virtual int setFilename(const SbString& filename);
00161
00169 SbBool setFilenameList(const SbStringList& filenameList);
00170
00187 SbBool setDirectory(const SbString& directory);
00188
00195 virtual ReadError getDataChar(SbBox3f& size, SoDataSet::DataType& type, SbVec3i32& dim);
00196
00203 virtual void getSubSlice(const SbBox2i32& subSlice, int sliceNumber, void* data);
00204
00208 void setSize(SbBox3f& size) {m_size = size;};
00209
00213 void setChannelSelection(ChannelSelection cs) {m_channelSelection = cs;};
00214
00218 virtual ReaderType getReaderType () {return RASTERSTACK;};
00219
00223 virtual SbBool isRGBA() const;
00224
00228 virtual SbBool isThreadSafe() const;
00229
00230 private:
00231
00232 int extractFileList(const SbString& headFile);
00233 SbBool extractParameters(const char* lineStr);
00234
00235 SoDataSet::DataType findOutDestType(const SbRasterImage::Components nc, const unsigned int numComponent);
00236
00237 void RGBA2HLS(SbVec3f& hls, float* rgba);
00238
00239 float convertFloat(float value);
00240 short convertShort(short value);
00241 int32_t convertInt32(int32_t value);
00242 unsigned short convertUShort(unsigned short value);
00243 uint32_t convertUInt32(uint32_t value);
00244 SbBool needEndianConversion();
00245
00246 int getChannelId(const char* channel);
00247
00248 template <typename T>
00249 void getSubSliceInternal(const SbBox2i32 &subSlice, int sliceNumber, void* data);
00250
00251 template <typename TSRC, typename T>
00252 void convertSubSliceInternal(TSRC* srcData, const SbVec2i32 srcSize, const unsigned int srcNumComponent, std::vector<T>& dstVector);
00253
00261 SbBool readImage(int numImage, SbRasterImage& rasterImage, const SbBox2i32& region, SbBool infoOnly);
00262
00263 template <typename T>
00264 void getSingleChannelData(std::vector<T> srcVector, SbVec2i32& size2s,
00265 unsigned int xMin, unsigned int xMax,
00266 unsigned int yMin, unsigned int yMax,
00267 void* data);
00268
00269 template <typename T>
00270 T endianConverter(const T value);
00271
00272 SbString m_listDirectory;
00273 SbBox3f m_size;
00274 SbVec3i32 m_dim;
00275 SbBool m_isRawData;
00276 unsigned int m_nc;
00277 SoDataSet::DataType m_srcType;
00278 SoDataSet::DataType m_destType;
00279 ChannelSelection m_channelSelection;
00280 std::vector< SbString > m_fileList;
00281 unsigned int m_rawHeaderSize;
00282 SbBool m_rawIsBigEndian;
00283 SbBool m_rawIsBinary;
00284
00285 private:
00286
00287 bool m_isInitialized;
00288
00289
00290
00291
00292
00293 template <typename T>
00294 SbBool readRawBuffer(FILE* fp, SbRasterImage& rasterImage, const SbBox2i32& region);
00295 };
00296
00297 #ifdef _WIN32
00298 #pragma warning( pop )
00299 #endif
00300
00301 #endif
00302
00303