Logo Search packages:      
Sourcecode: gdcm version File versions  Download package

bool gdcm::MediaStorage::SetFromFile ( File const &  file  ) 

Attempt to set the MediaStorage from a file: WARNING: When no MediaStorage & Modality are found BUT a PixelData element is found then MediaStorage is set to the default SecondaryCaptureImageStorage (return value is false in this case)

Definition at line 435 of file gdcmMediaStorage.cxx.

References gdcm::File::GetDataSet(), gdcm::File::GetHeader(), IsImage(), SetFromDataSet(), and SetFromSourceImageSequence().

Referenced by gdcm::ImageHelper::GetDirectionCosinesValue(), gdcm::ImageHelper::GetOriginValue(), gdcm::ImageHelper::GetRescaleInterceptSlopeValue(), gdcm::ImageHelper::GetSpacingValue(), gdcm::PixmapReader::Read(), gdcm::SplitMosaicFilter::Split(), and gdcm::ImageWriter::Write().

{
  /*
   * DICOMDIR usually have group 0002 present, but no 0008,0016 (doh!)
   * So we first check in header, if found, assumed it is ok (we should
   * check that consistant with 0008,0016 ...)
   * A lot of DICOM image file are still missing the group header
   * this is why we check 0008,0016, and to preserve compat with ACR-NEMA
   * we also check Modality element to guess a fake Media Storage UID
   * file such as:
   * gdcmData/SIEMENS-MR-RGB-16Bits.dcm
   * are a pain to handle ...
   */
  const FileMetaInformation &header = file.GetHeader();
  const char* header_ms_ptr = GetFromHeader(header);
  std::string copy1;
  const char *header_ms_str = 0;
  if( header_ms_ptr )
    {
    copy1 = header_ms_ptr;
    header_ms_str = copy1.c_str();
    }
  const DataSet &ds = file.GetDataSet();
  const char* ds_ms_ptr = GetFromDataSet(ds);
  std::string copy2;
  const char *ds_ms_str = 0;
  if( ds_ms_ptr )
    {
    copy2 = ds_ms_ptr;
    ds_ms_str = copy2.c_str();
    }

  // Easy case:
  if( header_ms_str && ds_ms_str && strcmp(header_ms_str, ds_ms_str) == 0 )
    {
    return SetFromHeader( header );
    }

  if( ds_ms_str )
    {
    // means either no header ms or different, take from dataset just in case
    return SetFromDataSet( ds );
    }

  // Looks suspicious or DICOMDIR...
  if( header_ms_str )
    {
    return SetFromHeader( header );
    }

  // old fall back
  if( !SetFromHeader( header ) )
    {
    // try again but from dataset this time:
    gdcmDebugMacro( "No MediaStorage found in Header, looking up in DataSet" );
    if( !SetFromDataSet( ds ) )
      {
      // ACR-NEMA compat:
      gdcmDebugMacro( "No MediaStorage found neither in DataSet nor in FileMetaInformation, trying from Modality" );
      // Attempt to read what's in Modality:
      if( !SetFromModality( ds ) )
        {
        return false;
        }
      }
    }
// BEGIN SPECIAL HANDLING FOR GDCM 1.2.x 'ReWrite'n files
#if 0
  else if( MSField == MediaStorage::SecondaryCaptureImageStorage )
    {
    /*
     * BEGIN HACK:
     * Technically it should be enough to know that the image is a SecondaryCaptureImageStorage ... BUT GDCM 1.x
     * used to rewrite everything by default as SecondaryCaptureImageStorage so when you would look carefully
     * this DataSet would in fact contains *everything* from the MR Image Storage, therefore, we prefer to use 
     * the Source Image Sequence to detect the *real* IOD...I am pretty sure this will bite us one day...
     */
    MediaStorage ms2;
    ms2.SetFromSourceImageSequence(ds);
    if( MSField != ms2 && ms2 != MediaStorage::MS_END )
      {
      assert( MediaStorage::IsImage( ms2 ) );
      gdcmWarningMacro( "Object is declared as SecondaryCaptureImageStorage but according"
        " to Source Image Sequence it was derived from " << ms2 << ". Using it instead" );
      MSField = ms2;
      }
    }
#endif
  return true;
}


Generated by  Doxygen 1.6.0   Back to index