GDCM  2.2.0
gdcmStreamImageReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 
00019 #ifndef GDCMSTREAMIMAGEREADER_H
00020 #define GDCMSTREAMIMAGEREADER_H
00021 
00022 #include "gdcmPixmapReader.h"
00023 #include "gdcmImage.h"
00024 #include "gdcmReader.h"
00025 #include <iostream>
00026 #include "gdcmDataSet.h"
00027 
00028 namespace gdcm
00029 {
00030 
00031 class MediaStorage;
00043 class GDCM_EXPORT StreamImageReader
00044 {
00045 
00046 public:
00047   StreamImageReader();
00048   ~StreamImageReader();
00049 
00050 
00054   void SetFileName(const char* inFileName);
00055   void SetStream(std::istream& inStream);
00056 
00057   std::vector<unsigned int> GetDimensionsValueForResolution( unsigned int  );
00058 
00067   void DefinePixelExtent(uint16_t inXMin, uint16_t inXMax,
00068     uint16_t inYMin, uint16_t inYMax, uint16_t inZMin = 0, uint16_t inZMax = 1);
00069 
00074   uint32_t DefineProperBufferLength() const;
00075 
00083   bool Read(void* inReadBuffer, const std::size_t& inBufferLength);
00084   
00090   bool CanReadImage() const;
00091   
00092 
00096   virtual bool ReadImageInformation();
00097 
00101   File const & GetFile() const;
00102 
00103 protected:
00104 
00105   //contains a reader for being able to ReadUpToTag
00106   //however, we don't want the user to be able to call Read
00107   //either directly or via a parent class call, so we hide the reader in here.
00108   Reader mReader;
00109 
00110   std::streamoff mFileOffset; //the fileoffset for getting header information
00111   std::streamoff mFileOffset1;
00112   DataSet mHeaderInformation; //all the non-pixel information
00113 
00114   //for thread safety, these should not be stored here, but should be used
00115   //for every read subregion operation.
00116   uint16_t mXMin, mYMin, mXMax, mYMax, mZMin, mZMax;
00117 
00122   //virtual bool ReadImageSubregionRAW(std::ostream& os);
00123   virtual bool ReadImageSubregionRAW(char* inReadBuffer, const std::size_t& inBufferLength);
00124   
00127   bool ReadImageSubregionJpegLS(char* inReadBuffer, const std::size_t& inBufferLength);
00128 
00129 };
00130 //see http://stackoverflow.com/questions/1448467/initializing-a-c-stdistringstream-from-an-in-memory-buffer/1449527#1449527
00131 struct OneShotReadBuf : public std::streambuf
00132 {
00133   OneShotReadBuf(void* s, std::size_t n){
00134     char* cast = (char*)s;
00135     setg(cast, cast, cast+n);
00136   }
00137 };
00138 
00139 } // end namespace gdcm
00140 
00141 #endif //GDCMSTREAMIMAGEREADER_H
00142 

Generated on Fri Mar 30 2012 12:44:06 for GDCM by doxygen 1.8.0
SourceForge.net Logo