+ * \brief Loader
+ * @param fileName 'Document' (File or DicomDir) to be open for parsing
+ * @return false if file cannot be open or no swap info was found,
+ * or no tag was found.
+ */
+bool Document::Load( std::string const &fileName )
+{
+ // We should clean out anything that already exists.
+ // Check IsDocumentAlreadyLoaded to be sure.
+ if( IsDocumentAlreadyLoaded )
+ {
+ gdcmWarningMacro( "A file was already parsed inside this "
+ << "gdcm::Document (previous name was: "
+ << Filename.c_str() << ". New name is :"
+ << fileName );
+ // todo : clean out the 'Document'
+ // Should we call ClearEntry() on the parent object ?!?
+ }
+
+ Filename = fileName;
+
+ Fp = 0;
+ if ( !OpenFile() )
+ {
+ // warning already performed in OpenFile()
+ //gdcmWarningMacro( "Unable to open as an ACR/DICOM file: "
+ // << Filename.c_str() );
+ Filetype = Unknown;
+ return false;
+ }
+
+ Group0002Parsed = false;
+
+ gdcmWarningMacro( "Starting parsing of file: " << Filename.c_str());
+
+ Fp->seekg(0, std::ios::end);
+ long lgt = Fp->tellg(); // total length of the file
+
+ Fp->seekg(0, std::ios::beg);
+
+ // CheckSwap returns a boolean
+ // (false if no swap info of any kind was found)
+ if (! CheckSwap() )
+ {
+ gdcmWarningMacro( "Neither a DICOM V3 nor an ACR-NEMA file: "
+ << Filename.c_str());
+ CloseFile();
+ return false;
+ }
+
+ long beg = Fp->tellg(); // just after DICOM preamble (if any)
+
+ lgt -= beg; // remaining length to parse
+
+ ParseDES( this, beg, lgt, false); // Loading is done during parsing
+
+ if ( IsEmpty() )
+ {
+ gdcmWarningMacro( "No tag in internal hash table for: "
+ << Filename.c_str());
+ CloseFile();
+ return false;
+ }
+ IsDocumentAlreadyLoaded = true;
+
+ Fp->seekg( 0, std::ios::beg);
+
+ // Load 'non string' values
+
+ std::string PhotometricInterpretation = GetEntryValue(0x0028,0x0004);
+ if( PhotometricInterpretation == "PALETTE COLOR " )
+ {
+ // FIXME
+ // Probabely this line should be outside the 'if'
+ // Try to find an image sample holding a 'gray LUT'
+ LoadEntryBinArea(0x0028,0x1200); // gray LUT
+
+ /// FIXME
+ /// The tags refered by the three following lines used to be CORRECTLY
+ /// defined as having an US Value Representation in the public
+ /// dictionary. BUT the semantics implied by the three following
+ /// lines state that the corresponding tag contents are in fact
+ /// the ones of a BinEntry.
+ /// In order to fix things "Quick and Dirty" the dictionary was
+ /// altered on PURPOSE but now contains a WRONG value.
+ /// In order to fix things and restore the dictionary to its
+ /// correct value, one needs to decided of the semantics by deciding
+ /// whether the following tags are either:
+ /// - multivaluated US, and hence loaded as ValEntry, but afterwards
+ /// also used as BinEntry, which requires the proper conversion,
+ /// - OW, and hence loaded as BinEntry, but afterwards also used
+ /// as ValEntry, which requires the proper conversion.
+ LoadEntryBinArea(0x0028,0x1201); // R LUT
+ LoadEntryBinArea(0x0028,0x1202); // G LUT
+ LoadEntryBinArea(0x0028,0x1203); // B LUT
+
+ // Segmented Red Palette Color LUT Data
+ LoadEntryBinArea(0x0028,0x1221);
+ // Segmented Green Palette Color LUT Data
+ LoadEntryBinArea(0x0028,0x1222);
+ // Segmented Blue Palette Color LUT Data
+ LoadEntryBinArea(0x0028,0x1223);
+ }