GDCM  2.0.18
gdcmReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004 
00005   Copyright (c) 2006-2011 Mathieu Malaterre
00006   All rights reserved.
00007   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 
00015 #ifndef GDCMREADER_H
00016 #define GDCMREADER_H
00017 
00018 #include "gdcmFile.h"
00019 
00020 
00021 #include <fstream>
00022 
00023 namespace gdcm
00024 {
00025   class StreamImageReader;
00055 class GDCM_EXPORT Reader
00056 {
00057 public:
00058   Reader():F(new File){
00059     Stream = NULL;
00060     Ifstream = NULL;
00061   }
00062   virtual ~Reader();
00063 
00065   virtual bool Read(); // Execute()
00066 
00069   void SetFileName(const char *filename) {
00070     if(Ifstream) delete Ifstream;
00071     Ifstream = new std::ifstream();
00072     Ifstream->open(filename, std::ios::binary);
00073     Stream = Ifstream;
00074   }
00075 
00077   void SetStream(std::istream &input_stream) {
00078     Stream = &input_stream;
00079   }
00080 
00082   const File &GetFile() const { return *F; }
00083 
00085   File &GetFile() { return *F; }
00086 
00088   void SetFile(File& file) { F = &file; }
00089 
00092   bool ReadUpToTag(const Tag & tag, std::set<Tag> const & skiptags = std::set<Tag>() );
00093 
00095   bool ReadSelectedTags(std::set<Tag> const & tags);
00096 
00099   bool CanRead() const;
00100 
00101 protected:
00102   bool ReadPreamble();
00103   bool ReadMetaInformation();
00104   bool ReadDataSet();
00105 
00106   SmartPointer<File> F;
00107 
00108   friend class StreamImageReader; //need to be friended to be able to grab the GetStreamPtr
00109 
00110   //this function is added for the StreamImageReader, which needs to read
00111   //up to the pixel data and then stops right before reading the pixel data.
00112   //it's used to get that position, so that reading can continue
00113   //apace once the read function is called.
00114   //so, this function gets the stream directly, and then allows for position information
00115   //from the tellg function, and allows for stream/pointer manip in order
00116   //to read the pixel data.  Note, of course, that reading pixel elements
00117   //will still have to be subject to endianness swaps, if necessary.
00118   std::istream* GetStreamPtr() const { return Stream; }
00119 
00120 private:
00121   template <typename T_Caller>
00122   bool InternalReadCommon(const T_Caller &caller);
00123   TransferSyntax GuessTransferSyntax();
00124   std::istream *Stream;
00125   std::ifstream *Ifstream;
00126 };
00127 
00134 } // end namespace gdcm
00135 
00136 
00137 #endif //GDCMREADER_H

Generated on Tue Dec 6 2011 07:25:31 for GDCM by doxygen 1.7.5.1
SourceForge.net Logo