1 /*=========================================================================
4 Module: $RCSfile: TestFromScratch.cxx,v $
6 Date: $Date: 2005/02/02 10:06:32 $
7 Version: $Revision: 1.17 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmDictEntry.h"
21 #include "gdcmDocEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmValEntry.h"
24 #include "gdcmDebug.h"
26 // The whole purpose of this example is to create a DICOM from scratch
27 // well almost the only thing we allow use is to copy the string entry
28 // From the previous image read.
30 int main(int argc, char *argv[])
34 std::cerr << "Usage: " << argv[0] << " Image.dcm" << std::endl;
39 // Doesn't seem to do anything:
40 gdcm::Debug::DebugOn();
42 // Doesn't link properly:
43 //gdcm::Debug::GetReference().SetDebug(1);
45 std::string filename = argv[1];
46 gdcm::FileHelper *f1 = new gdcm::FileHelper( filename );
47 gdcm::File *h1 = f1->GetFile();
49 int dataSize = f1->GetImageDataSize();
50 std::cout << "DataSize: " << dataSize << std::endl;
51 // Since we know the image is 16bits:
52 uint8_t *imageData = f1->GetImageData();
54 // Hopefully default to something
55 gdcm::File *h2 = new gdcm::File();
57 // Copy of the header content
58 gdcm::DocEntry *d = h1->GetFirstEntry();
61 if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
63 // Do not bother with field from private dict
64 if( v->GetName() != "gdcm::Unknown" )
66 h2->InsertValEntry( v->GetValue(),
67 v->GetGroup(),v->GetElement(),
72 // We skip pb of SQ recursive exploration
73 // We skip bin entries
75 d = h1->GetNextEntry();
77 h2->Print( std::cout );
79 gdcm::FileHelper *f2 = new gdcm::FileHelper( h2 );
80 f2->SetImageData(imageData, dataSize);
82 f2->SetWriteTypeToDcmExplVR();
83 f2->Write( "output.dcm" );