1 #include "gdcmHeader.h"
4 // return true if the file exists
5 bool FileExists(const char* filename)
8 # define access _access
13 if ( access(filename, R_OK) != 0 )
23 bool RemoveFile(const char* source)
26 #define _unlink unlink
28 return unlink(source) != 0 ? false : true;
31 // Here we load a gdcmFile and then try to create from scratch a copy of it,
32 // copying field by field the dicom image
34 int TestCopyDicom(int argc, char* argv[])
38 std::cerr << "Usage :" << std::endl <<
39 argv[0] << " input_dicom output_dicom" << std::endl;
43 if( FileExists( argv[2] ) )
45 std::cerr << "Don't try to cheat, I am removing the file anyway" << std::endl;
46 if( !RemoveFile( argv[2] ) )
48 std::cerr << "Ouch, the file exist, but I cannot remove it" << std::endl;
52 gdcmFile *original = new gdcmFile( argv[1] );
53 gdcmFile *copy = new gdcmFile( argv[2] );
55 //First of all copy the header field by field
56 TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName();
57 for (TagNameHT::iterator tag = nameHt.begin(); tag != nameHt.end(); ++tag)
59 std::cerr << "Reading: " << tag->second->GetVR() << std::endl;
61 copy->GetHeader()->ReplaceOrCreateByNumber( tag->second->GetVR(),
62 tag->second->GetGroup(), tag->second->GetElement() );
65 size_t dataSize = original->GetImageDataSize();
66 void *imageData = original->GetImageData();
68 copy->SetImageData(imageData, dataSize);
69 //original->GetHeader()->SetImageDataSize(dataSize);
71 //copy->GetHeader()->PrintEntry();
73 copy->WriteDcmExplVR( argv[2] );