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