]> Creatis software - gdcm.git/blobdiff - Example/TestFromScratch.cxx
Typo, comments
[gdcm.git] / Example / TestFromScratch.cxx
index 27fd2627474ddaba7bd1c81b3f73de4b2fb8c5ff..7bb6884737737cc38608783b20c1fca7734d31b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestFromScratch.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/10 15:50:04 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/02/02 10:06:32 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmHeader.h"
 #include "gdcmFile.h"
+#include "gdcmFileHelper.h"
 #include "gdcmDictEntry.h"
 #include "gdcmDocEntry.h"
+#include "gdcmBinEntry.h"
 #include "gdcmValEntry.h"
 #include "gdcmDebug.h"
 
@@ -34,57 +35,52 @@ int main(int argc, char *argv[])
       return 1;
    }
 
-   // Doesn't seems to do anything:
-   dbg.SetDebug(-1);
+
+   // Doesn't seem to do anything:
+   gdcm::Debug::DebugOn();
+
    // Doesn't link properly:
    //gdcm::Debug::GetReference().SetDebug(1);
 
    std::string filename = argv[1];
-   //gdcm::File *f1 = new gdcm::File( "/home/malaterre/Creatis/gdcmData/012345.002.050.dcm" );
-   gdcm::File *f1 = new gdcm::File( filename );
-   gdcm::Header *h1 = f1->GetHeader();
+   gdcm::FileHelper *f1 = new gdcm::FileHelper( filename );
+   gdcm::File *h1 = f1->GetFile();
 
    int dataSize = f1->GetImageDataSize();
    std::cout << "DataSize:      " << dataSize << std::endl;
    // Since we know the image is 16bits:
-   uint8_timageData = f1->GetImageData();
+   uint8_t *imageData = f1->GetImageData();
  
    // Hopefully default to something
-   gdcm::Header *h2 = new gdcm::Header();
+   gdcm::File *h2 = new gdcm::File();
 
-   const gdcm::TagDocEntryHT &nameHt = h1->GetTagHT();
-   //const gdcm::TagDocEntryHT &nameHt = h2->GetTagHT(); seems to be empty ??
-   for (gdcm::TagDocEntryHT::const_iterator tag = nameHt.begin(); tag != nameHt.end(); ++tag)
+   // Copy of the header content
+   gdcm::DocEntry *d = h1->GetFirstEntry();
+   while(d)
    {
-      //Copy string only:
-      if (tag->second->GetVR().find("SQ") == 0)
-      {
-         // skip DICOM SeQuence, otherwise following cast will crash
-         continue;
-      }
-      const std::string &name = tag->second->GetName();
-      const std::string &value = ((gdcm::ValEntry*)(tag->second))->GetValue();
-      if( name != "unkn"
-       && value.find( "gdcm::NotLoaded" ) != 0
-       && value.find( "gdcm::Binary" )    != 0
-       && value.find( "gdcm::Loaded" )    != 0 )
-      {
-        //std::cout << name << "," << value << std::endl;
-        gdcm::DictEntry *dictEntry = h2->GetPubDict()->GetDictEntryByName(name);
-        h2->ReplaceOrCreateByNumber( value, dictEntry->GetGroup(), dictEntry->GetElement());
+      if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
+      {   
+         // Do not bother with field from private dict
+         if( v->GetName() != "gdcm::Unknown" )
+         {  
+            h2->InsertValEntry( v->GetValue(),
+                                v->GetGroup(),v->GetElement(),
+                                v->GetVR() ); 
+         }
       }
-   }
+      //else
+         // We skip pb of SQ recursive exploration
+         // We skip bin entries
 
-   h2->ReplaceOrCreateByNumber( imageData, dataSize, 0x7fe0, 0x0010, "PXL" );
+      d = h1->GetNextEntry();
+   }
    h2->Print( std::cout );
 
-   gdcm::File *f2 = new gdcm::File( h2 );
-   // SetImageData does not work because you need to have called
-   // somwhow ReplaceOrCreateByNumber before with the proper group/element
+   gdcm::FileHelper *f2 = new gdcm::FileHelper( h2 );
    f2->SetImageData(imageData, dataSize);
 
-   f2->WriteDcmExplVR( "output.dcm" );
+   f2->SetWriteTypeToDcmExplVR();
+   f2->Write( "output.dcm" );
 
    delete f1;
    delete f2;