From 8fca7bc2830904113dbb5521c009775d964c5c98 Mon Sep 17 00:00:00 2001 From: frog Date: Thu, 1 Jul 2004 13:03:01 +0000 Subject: [PATCH] * Test/*.cxx and Example/*.cxx: moved some examples away from the test suite to the Example directory. Are concerned: - PrintHeader.cxx - TestDcm2Acr.cxx - TestFindTags.cxx - TestWrite.cxx was - TestWriteSimple.cxx * Test/CMakeLists.txt: added some comments on reasons for black listing image gdcmData/oldACR00001.ima --- ChangeLog | 11 ++ Example/CMakeLists.txt | 18 ++- Example/FindTags.cxx | 93 +++++++++++++++ Example/PrintHeader.cxx | 67 +++++++++++ Example/TestDcm2Acr.cxx | 50 ++++++++ Example/TestWrite.cxx | 140 +++++++++++++++++++++++ {Testing => Example}/TestWriteSimple.cxx | 7 +- Testing/CMakeLists.txt | 24 ++-- 8 files changed, 395 insertions(+), 15 deletions(-) create mode 100644 Example/FindTags.cxx create mode 100644 Example/PrintHeader.cxx create mode 100644 Example/TestDcm2Acr.cxx create mode 100644 Example/TestWrite.cxx rename {Testing => Example}/TestWriteSimple.cxx (89%) diff --git a/ChangeLog b/ChangeLog index fb69366c..b22b77c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-07-01 Eric Boix + * Test/*.cxx and Example/*.cxx: moved some examples away from the + test suite to the Example directory. Are concerned: + - PrintHeader.cxx + - TestDcm2Acr.cxx + - TestFindTags.cxx + - TestWrite.cxx was + - TestWriteSimple.cxx + * Test/CMakeLists.txt: added some comments on reasons for black listing + image gdcmData/oldACR00001.ima + 2004-06-30 Eric Boix * Test/CmakeList.txt: removed the following from black list (to be coherent with removal from gdcmData): diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 1d6156c8..8709bad5 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -8,6 +8,17 @@ INCLUDE_DIRECTORIES( ${GDCM_BINARY_DIR}/ ) +ADD_EXECUTABLE(FindTags FindTags.cxx) +TARGET_LINK_LIBRARIES(FindTags gdcm) + +ADD_EXECUTABLE(TestDcm2Acr TestDcm2Acr.cxx) +TARGET_LINK_LIBRARIES(TestDcm2Acr gdcm) + +ADD_EXECUTABLE(TestWrite TestWrite.cxx) +TARGET_LINK_LIBRARIES(TestWrite gdcm) + +ADD_EXECUTABLE(TestWriteSimple TestWriteSimple.cxx) +TARGET_LINK_LIBRARIES(TestWriteSimple gdcm) ADD_EXECUTABLE(PrintDocument PrintDocument.cxx) TARGET_LINK_LIBRARIES(PrintDocument gdcm) @@ -15,11 +26,14 @@ TARGET_LINK_LIBRARIES(PrintDocument gdcm) ADD_EXECUTABLE(PrintFile PrintFile.cxx) TARGET_LINK_LIBRARIES(PrintFile gdcm) -ADD_EXECUTABLE(Write Write.cxx) -TARGET_LINK_LIBRARIES(Write gdcm) +ADD_EXECUTABLE(PrintHeader PrintHeader.cxx) +TARGET_LINK_LIBRARIES(PrintHeader gdcm) ADD_EXECUTABLE(WriteDicom WriteDicom.cxx) TARGET_LINK_LIBRARIES(WriteDicom gdcm) +ADD_EXECUTABLE(Write Write.cxx) +TARGET_LINK_LIBRARIES(Write gdcm) + ADD_EXECUTABLE(WriteRead WriteRead.cxx) TARGET_LINK_LIBRARIES(WriteRead gdcm) diff --git a/Example/FindTags.cxx b/Example/FindTags.cxx new file mode 100644 index 00000000..46aea14b --- /dev/null +++ b/Example/FindTags.cxx @@ -0,0 +1,93 @@ +#include +//#include +#include "gdcm.h" +#include "math.h" + +int main(int argc, char* argv[]) { + + std::string toto, titi; + + gdcmFile * f1; + + if(argc > 1 ) + f1 = new gdcmFile(argv[1]); + else { + toto = GDCM_DATA_ROOT; + toto += "/test.acr"; + f1 = new gdcmFile(toto); + } + + std::string ManufacturerName="SIEMENS "; + std::string RecCode="ACR-NEMA 2.0"; + std::string ImagePositionPatient, Location, ImageLocation; + char zozo[100], zizi[50]; + char c; + + float x, y, z, l; + + int dataSize = f1->GetImageDataSize(); + printf ("---> pourFindTaggs : dataSize %d\n",dataSize); + + f1->SetEntryByNumber(RecCode ,0x0008,0x0010); + f1->SetEntryByNumber(ManufacturerName ,0x0008,0x0070); + +// ImagePositionPatient + ImagePositionPatient = f1->GetHeader()->GetEntryByNumber(0x0020,0x0032); + +// Image Position (RET) + f1->SetEntryByNumber(ImagePositionPatient, 0x0020,0x0030); + + sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z); + +// ceci est probablement une mauvaise idée ! +// (peut casser l'ordre des images si la pile d'images +// traverse l'axe des X, ou des Y, ou des Z) +//l=sqrt(x*x + y*y + z*z); + +// ceci ne marchera pas si on se déplace à Z constant :-( + l=z; +// existerait-il qq chose qui marche à tout coup? + +// Location + sprintf(zizi,"%f\n",l); + Location = zizi; + f1->SetEntryByNumber(Location, 0x0020,0x0050); + +// sinon, la longueur du champ est erronée (?!?) +// Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length() +// a eclaircir ! + +// SetEntryLengthByNumber is private now. +//TO DO : see is the pb goes on... + +//f1->GetHeader()->SetEntryLengthByNumber(strlen(Location.c_str())-1, 0x0020,0x0050); + +// Image Location + + sprintf(zizi,"%d\n",0x7FE0); + ImageLocation = zizi; +//f1->SetEntryByNumber(Location, 0x0028,0x0200); +//f1->GetHeader()->SetEntryLengthByNumber(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence ! + +// void* imageData= f1->GetImageData(); + +// ecriture d'un fichier ACR à partir d'un dcmHeader correct. + + printf ("----------------avant PrintEntry---------------------\n"); + f1->GetHeader()->Print(); + printf ("----------------avant WriteDcm---------------------\n"); + + +// ecriture d'un fichier ACR à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.acr", toto.c_str()); + printf ("WriteACR\n"); + f1->WriteAcr(zozo); + + printf ("----------------apres Write---------------------\n"); + + return 0; +} + + + diff --git a/Example/PrintHeader.cxx b/Example/PrintHeader.cxx new file mode 100644 index 00000000..49cd54e7 --- /dev/null +++ b/Example/PrintHeader.cxx @@ -0,0 +1,67 @@ +#include +#include "gdcm.h" + +int main(int argc, char* argv[]) +{ + bool dropPriv = false; + bool showSeq = true; + std::string fileName; + + if (argc == 1) { + std::cout << argv[0] << + " fileName" << std::endl << + " [nopriv] if you don't want to print Shadow groups" << std::endl << + " [noseq] if you don't want to 'go inside' the SQ's" << std::endl; + } + + if (argc > 1) { + fileName=argv[1]; + } else { + fileName += GDCM_DATA_ROOT; + fileName += "/test.acr"; + } + + for (int j=0;jGetHeader(); + + if (argc > 2) { + int level = atoi(argv[2]); + e1->SetPrintLevel(level); + } + + e1->Print(); + + std::cout << "\n\n" << std::endl; + std::string transferSyntaxName = e1->GetTransfertSyntaxName(); + std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; + + if ( transferSyntaxName != "Implicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Little Endian" + && transferSyntaxName != "Deflated Explicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Big Endian" + && transferSyntaxName != "Uncompressed ACR-NEMA" ) + { + std::cout << std::endl << "===========================================" + << std::endl; + e2->ParsePixelData(); + std::cout << std::endl << "===========================================" + << std::endl; + } + + if(e1->IsReadable()) + std::cout < +#include "gdcm.h" + +int main(int argc, char* argv[]) +{ + std::string toto; + char zozo[100]; + + gdcmFile * f1; + + printf (" Before gdcmFile() \n"); + printf ("\n\n---------------------------------------\n\n"); + + if (argc > 1) { + toto = argv[1]; + f1 = new gdcmFile(toto); + } else { + std::string filename = GDCM_DATA_ROOT; + filename += "/test.acr"; + f1 = new gdcmFile(filename.c_str()); + } + printf (" Sortie gdcmFile() \n"); + + //e1.PrintPubDict(std::cout); + f1->GetHeader()->Print(); + + //cle = gdcmDictEntry::TranslateToKey(0x0028,0x0008); + + int dataSize = f1->GetImageDataSize(); + printf ("dataSize %d\n",dataSize); + + // void* imageData= f1->GetHeader()->GetImageData(); + + // Ecriture d'un Raw File, a afficher avec affim filein= dim= nbit= signe= + //f1->WriteRawData("image.raw"); + + // ecriture d'un fichier DICOM à partir d'un dcmHeader correct. + + //f1->WriteDcmImplVR("image.dcm"); + + // ecriture d'un fichier ACR à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.nema", toto.c_str()); + f1->WriteAcr(zozo); + printf ("\n\n---------------------------------------\n\n"); + + f1->GetHeader()->Print(); + + return 0; +} diff --git a/Example/TestWrite.cxx b/Example/TestWrite.cxx new file mode 100644 index 00000000..9673abf0 --- /dev/null +++ b/Example/TestWrite.cxx @@ -0,0 +1,140 @@ +#include +#include "gdcm.h" +#include "gdcmHeader.h" +#include "gdcmDocument.h" + +#include + +int main(int argc, char* argv[]) +{ + std::string toto; + char zozo[200]; + + + gdcmHeader* e1; + gdcmFile * f1; + + //gdcmDocument * d; //not used + void* imageData; + int dataSize; + + if (argc < 3) { + std::cerr << "usage: " << std::endl + << argv[0] << " fileName writtingMode " + << std::endl + << "(a : ACR, d : DICOM Implicit VR," + << " x : DICOM Explicit VR r : RAW)" + << std::endl; + return 0; + } +/* + if (0) { // Just to keep the code for further use + std::cout <GetHeader()->IsReadable()) { + std::cout << "Sorry, not a DICOM / ACR File" < after new gdcmHeader" + << std::endl; + e1->PrintEntry(); + std::cout <IsReadable()) { + std::cerr << "Sorry, not a Readable DICOM / ACR File" <Print(); + + f1 = new gdcmFile(e1); +// --- + + dataSize = f1->GetImageDataSize(); + std::cout <GetXSize(); + nY=e1->GetYSize(); + nZ=e1->GetZSize(); + std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl; + + pixelType = e1->GetPixelType(); + sPP = e1->GetSamplesPerPixel(); + planarConfig = e1->GetPlanarConfiguration(); + + std::cout << " pixelType=" << pixelType + << " SampleserPixel=" << sPP + << " PlanarConfiguration=" << planarConfig + << " PhotometricInterpretation=" + << e1->GetEntryByNumber(0x0028,0x0004) + << std::endl; + + int numberOfScalarComponents=e1->GetNumberOfScalarComponents(); + std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <GetTransfertSyntaxName(); + std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; + + if ( transferSyntaxName != "Implicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Little Endian" + && transferSyntaxName != "Deflated Explicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Big Endian" + && transferSyntaxName != "Uncompressed ACR-NEMA" ) { + std::cout << std::endl << "===========================================" + << std::endl; + f1->ParsePixelData(); + std::cout << std::endl << "===========================================" + << std::endl; + } + imageData= f1->GetImageData(); + + switch (argv[2][0]) { + case 'a' : + // ecriture d'un fichier ACR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.ACR", toto.c_str()); + printf ("WriteACR\n"); + f1->WriteAcr(zozo); + break; + + case 'd' : + // ecriture d'un fichier DICOM Implicit VR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.DCM", toto.c_str()); + printf ("WriteDCM Implicit VR\n"); + f1->WriteDcmImplVR(zozo); + break; + + case 'x' : + // ecriture d'un fichier DICOM Explicit VR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.XDCM", toto.c_str()); + std::cout << "WriteDCM Explicit VR" << std::endl; + f1->WriteDcmExplVR(zozo); + break; + + case 'r' : + // Ecriture d'un Raw File, a afficher avec + // affim filein= dimx= dimy= nbit= signe= + + sprintf(zozo, "%s.RAW", toto.c_str()); + std::cout << "WriteRaw" << std::endl; + f1->WriteRawData(zozo); + break; + + } + return 0; +} + diff --git a/Testing/TestWriteSimple.cxx b/Example/TestWriteSimple.cxx similarity index 89% rename from Testing/TestWriteSimple.cxx rename to Example/TestWriteSimple.cxx index 51b3f4d9..df717bf4 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Example/TestWriteSimple.cxx @@ -1,9 +1,6 @@ -#include "gdcmHeader.h" -#include "gdcmFile.h" -#include "gdcmDebug.h" +#include "gdcm.h" - -int TestWriteSimple(int argc, char* argv[]) +int main(int argc, char* argv[]) { if (argc < 3) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 676500aa..2ba2bca1 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -9,20 +9,15 @@ SET(GDCM_TESTS ${CXX_TEST_PATH}/gdcmTests) # They usally return if no argument is given SET(TEST_SOURCES TestBug.cxx - TestDcm2Acr.cxx TestHash.cxx - TestWrite.cxx - TestReadWriteReadCompare.cxx - TestWriteSimple.cxx ) # add tests that require data IF (GDCM_DATA_ROOT) SET(TEST_SOURCES ${TEST_SOURCES} - #PrintHeader.cxx #require test.acr - PrintAllDocument.cxx #require test.acr + TestReadWriteReadCompare.cxx # includes generated gdcmDataImages.h + PrintAllDocument.cxx # includes generated gdcmDataImages.h PrintDicomDir.cxx - TestFindTags.cxx TestChangeHeader.cxx TestDicomDir.cxx #require DICOMDIR BuildUpDicomDir.cxx @@ -112,7 +107,20 @@ SET(BLACK_LIST "irmPhlipsNew1.dcm" #png looks ugly "mriThruVPRO.dcm" #png looks ugly "gdcm-MR-SIEMENS-16-1.acr" #segfaults TestReadWriteReadCompare - "oldACR00001.ima" #segfaults TestReadWriteReadCompare + #segfaults TestReadWriteReadCompare: this image looks corrupted: + # - it's pixel data is 132096 bytes long + # - it has a size of 256x256 with 16 bytes per pixel, i.e. a size + # of 256*256*2 = 131072 bytes. + # Since there is a missmatch, when we have the following call stack: + # gdcmFile::GetImageData() + # PixelData = new uint8_t[ImageDataSize]; + # \--->::GetImageDataIntoVector(destination, ImageDataSize) + # \---> ::ReadPixelData(destination) + # \---> fread(destination, Header->GetPixelAreaLength(), 1, fp); + # we get a segfault because : + # - destination is ImageDataSize i.e. 131072 bytes long + # - Header->GetPixelAreaLength() = 132096 bytes long + "oldACR00001.ima" ) # gdcm-ACR-LibIDO seems to be cut -- 2.45.1