]> Creatis software - gdcm.git/commitdiff
* Test/*.cxx and Example/*.cxx: moved some examples away from the
authorfrog <frog>
Thu, 1 Jul 2004 13:03:01 +0000 (13:03 +0000)
committerfrog <frog>
Thu, 1 Jul 2004 13:03:01 +0000 (13:03 +0000)
     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
Example/CMakeLists.txt
Example/FindTags.cxx [new file with mode: 0644]
Example/PrintHeader.cxx [new file with mode: 0644]
Example/TestDcm2Acr.cxx [new file with mode: 0644]
Example/TestWrite.cxx [new file with mode: 0644]
Example/TestWriteSimple.cxx [moved from Testing/TestWriteSimple.cxx with 89% similarity]
Testing/CMakeLists.txt

index fb69366c6070125a83cf129b05f5436d7a0b5366..b22b77c6bdd0153d568fa2188939e0d46d089078 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-07-01 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+   * 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 <Eric.Boix@creatis.insa-lyon.fr>
    * Test/CmakeList.txt: removed the following from black list (to be coherent
      with removal from gdcmData):
index 1d6156c8636a15c8d9a3ad757649ac87649df691..8709bad56ed074ccb93a4166116c1ece5abd083f 100644 (file)
@@ -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 (file)
index 0000000..46aea14
--- /dev/null
@@ -0,0 +1,93 @@
+#include <iostream>
+//#include <glib.h>
+#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 (file)
index 0000000..49cd54e
--- /dev/null
@@ -0,0 +1,67 @@
+#include <iostream>
+#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;j<argc;j++) {
+      if (strcmp(argv[j],"nopriv")==0)
+         dropPriv=true;
+      else if (strcmp(argv[j],"noseq")==0)
+         showSeq=false;
+   }
+   
+   gdcmFile *e2 = new gdcmFile(fileName.c_str(),false, showSeq, dropPriv);
+   gdcmHeader *e1 = e2->GetHeader();  
+        
+   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 <<std::endl<<fileName<<" is Readable"<<std::endl;
+   else
+      std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
+   std::cout<<std::flush;
+   delete e1;
+
+   return 0;
+   
+}
diff --git a/Example/TestDcm2Acr.cxx b/Example/TestDcm2Acr.cxx
new file mode 100644 (file)
index 0000000..8a2996b
--- /dev/null
@@ -0,0 +1,50 @@
+#include <iostream>
+#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 (file)
index 0000000..9673abf
--- /dev/null
@@ -0,0 +1,140 @@
+#include <iostream>
+#include "gdcm.h"
+#include "gdcmHeader.h"
+#include "gdcmDocument.h"
+
+#include <stdio.h>
+
+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 <<std::endl << "-------- Test gdcmHeader ------" <<std::endl;
+      e1 = new gdcmHeaderHelper(argv[1]);
+      if (!f1->GetHeader()->IsReadable()) {
+         std::cout << "Sorry, not a DICOM / ACR File"  <<std::endl;
+         exit(0);
+      }
+      std::cout << std::endl << "----------------------> after new gdcmHeader"
+                << std::endl;
+      e1->PrintEntry();
+      std::cout <<std::endl <<"---------------------------------------" 
+                <<std::endl;
+   }
+*/
+
+   std::cout << std::endl
+             << "--------------------- file :" << argv[1] 
+             << std::endl;
+     
+   toto = argv[1]; 
+
+   e1 = new gdcmHeader(toto.c_str(), false, true);
+   if (!e1->IsReadable()) {
+       std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
+       return 0;
+   }
+  // e1->Print(); 
+   
+   f1 = new gdcmFile(e1);
+// ---     
+
+   dataSize = f1->GetImageDataSize();
+   std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
+   int nX,nY,nZ,sPP,planarConfig;
+   std::string pixelType, transferSyntaxName;
+   nX=e1->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 <<std::endl;
+   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; 
+      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;
+}
+
similarity index 89%
rename from Testing/TestWriteSimple.cxx
rename to Example/TestWriteSimple.cxx
index 51b3f4d9bfb2eec72b6894a36d8c492c39fbb665..df717bf4299b69e10d65954d912cec968b9c9f0f 100644 (file)
@@ -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) 
index 676500aacae612a5cda9f867e300f326c51d57ef..2ba2bca1b4afea0c62813d2b76b84896259dbf60 100644 (file)
@@ -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