X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestCopyDicom.cxx;h=698828b8cf20a010ca6abaf501af361d52f8e0a5;hb=bd7bec4c367d671a9da358584e98a8ec29bb641e;hp=f74e39d2ba95f5e01a845b6a8435e096e7181608;hpb=96cc99e8e141ceaf026104699c3273ad5fc88a1f;p=gdcm.git diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index f74e39d2..698828b8 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/02/03 10:00:06 $ - Version: $Revision: 1.39 $ + Date: $Date: 2007/10/30 09:13:45 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,44 +17,14 @@ =========================================================================*/ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" //Generated file: #include "gdcmDataImages.h" -#ifndef _WIN32 -#include //for access, unlink -#else -#include //for _access on Win32 -#endif - // return true if the file exists -bool FileExists(const char *filename) -{ -#ifdef _MSC_VER -# define access _access -#endif -#ifndef R_OK -# define R_OK 04 -#endif - if ( access(filename, R_OK) != 0 ) - { - return false; - } - else - { - return true; - } -} - -bool RemoveFile(const char *source) -{ -#ifdef _MSC_VER -#define _unlink unlink -#endif - return unlink(source) != 0 ? false : true; -} +bool FileExists(const char *filename); +bool RemoveFile(const char *source); int CopyDicom(std::string const &filename, std::string const &output ) @@ -71,27 +41,24 @@ int CopyDicom(std::string const &filename, //////////////// Step 1: std::cout << " 1..."; - gdcm::File *originalH = new gdcm::File( filename ); - gdcm::File *copyH = new gdcm::File( ); + GDCM_NAME_SPACE::File *originalH = GDCM_NAME_SPACE::File::New(); + GDCM_NAME_SPACE::File *copyH = GDCM_NAME_SPACE::File::New(); + + originalH->SetFileName( filename ); + originalH->Load( ); //First of all copy the file, field by field //////////////// Step 2: std::cout << "2..."; - gdcm::DocEntry *d=originalH->GetFirstEntry(); + GDCM_NAME_SPACE::DocEntry *d=originalH->GetFirstEntry(); while(d) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) - { - copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copyH->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + if ( GDCM_NAME_SPACE::DataEntry *de = dynamic_cast(d) ) + { + copyH->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { @@ -100,15 +67,17 @@ int CopyDicom(std::string const &filename, d=originalH->GetNextEntry(); } - - gdcm::FileHelper *original = new gdcm::FileHelper( originalH ); - gdcm::FileHelper *copy = new gdcm::FileHelper( copyH ); + GDCM_NAME_SPACE::FileHelper *original = GDCM_NAME_SPACE::FileHelper::New(originalH); + GDCM_NAME_SPACE::FileHelper *copy = GDCM_NAME_SPACE::FileHelper::New(copyH); size_t dataSize = original->GetImageDataSize(); uint8_t *imageData = original->GetImageData(); // Useless to set the image data, because it's already made when - // copying the corresponding BinEntry that contains the pixel data + // copying the corresponding DataEntry that contains the pixel data + + // --> FIXME : Why do we let the following line? + // to avoid compile time warnings? copy->SetImageData(imageData, dataSize); //////////////// Step 3: @@ -119,29 +88,29 @@ int CopyDicom(std::string const &filename, std::cout << " Failed" << std::endl << " " << output << " not written" << std::endl; - delete original; - delete copy; - delete originalH; - delete copyH; + original->Delete(); + copy->Delete(); + originalH->Delete(); + copyH->Delete(); return 1; } - delete copy; - delete copyH; + copy->Delete(); + copyH->Delete(); //////////////// Step 4: std::cout << "4..."; - copy = new gdcm::FileHelper( output ); - +// copy = new GDCM_NAME_SPACE::FileHelper( output ); + copy = GDCM_NAME_SPACE::FileHelper::New(output); // ??? //Is the file written still gdcm parsable ? if ( !copy->GetFile()->IsReadable() ) { std::cout << " Failed" << std::endl << " " << output << " not readable" << std::endl; - delete original; - delete originalH; + original->Delete(); + originalH->Delete(); return 1; } @@ -157,9 +126,9 @@ int CopyDicom(std::string const &filename, << " Pixel areas lengths differ: " << dataSize << " # " << dataSizeWritten << std::endl; - delete original; - delete copy; - delete originalH; + original->Delete(); + copy->Delete(); + originalH->Delete(); return 1; } @@ -170,17 +139,17 @@ int CopyDicom(std::string const &filename, std::cout << " Failed" << std::endl << " Pixel differ (as expanded in memory)." << std::endl; - delete original; - delete copy; - delete originalH; + original->Delete(); + copy->Delete(); + originalH->Delete(); return 1; } std::cout << "OK." << std::endl ; - delete original; - delete copy; - delete originalH; + original->Delete(); + copy->Delete(); + originalH->Delete(); return 0; }