]> Creatis software - gdcm.git/commitdiff
* Test/ : rename VTK tests to have a best name for the tests
authorregrain <regrain>
Wed, 19 Jan 2005 10:43:00 +0000 (10:43 +0000)
committerregrain <regrain>
Wed, 19 Jan 2005 10:43:00 +0000 (10:43 +0000)
   * gdcmPython/demo/*.py.in : Change the InitTraversal/GetNextEntry use to
     GetFirstEntry/GetNextEntry use
   -- BeNours

ChangeLog
Testing/CMakeLists.txt
Testing/VTKTestRead.cxx [new file with mode: 0644]
Testing/VTKTestReadSeq.cxx [new file with mode: 0644]
Testing/VTKTestWrite.cxx [new file with mode: 0644]
gdcmPython/demo/PrintDict.py.in
gdcmPython/demo/PrintHeader.py.in

index 78a1bffebd75e8286ef8f2e77ad28357aeba5966..c14b7b48d9cdb381088a215223b740f7c8fe3144 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-01-19 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * Test/ : rename VTK tests to have a best name for the tests
+   * gdcmPython/demo/*.py.in : Change the InitTraversal/GetNextEntry use to
+     GetFirstEntry/GetNextEntry use
+
 2005-01-18 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * Test/ShowDicom.cxx, ShowDicomSeq.cxx, TestWriteWithVTK.cxx : change the
      test. Now it's on image content and not on the resulting visualisation...
index 60b1e913443f399a90eb768f085f8be48ebbc363..f18303c52bb38acd834e486d5594ac7d06085532 100644 (file)
@@ -15,6 +15,7 @@ SET(TEST_SOURCES
   TestUtil.cxx
   TestDicomString.cxx
   TestDict.cxx
+  TestWriteSimple.cxx
 )
 
 # add tests that require data
@@ -25,9 +26,8 @@ IF (GDCM_DATA_ROOT)
     TestAllReadCompareDicom.cxx      # includes generated gdcmDataImages.h
     TestAllEntryVerify.cxx           # includes generated gdcmDataImages.h
     #TestChangeHeader.cxx
-    TestCopyDicom.cxx
-    TestCopyRescaleDicom.cxx
-    TestWriteSimple.cxx
+    TestCopyDicom.cxx                # includes generated gdcmDataImages.h 
+    TestCopyRescaleDicom.cxx         # includes generated gdcmDataImages.h 
     TestDicomDir.cxx                 # require DICOMDIR
     BuildUpDicomDir.cxx              # writes a file named "NewDICOMDIR"
     makeDicomDir.cxx                 # writes a file named "NewDICOMDIR"
@@ -42,9 +42,9 @@ IF (GDCM_DATA_ROOT)
       ${GDCM_SOURCE_DIR}/vtk/
       )
     SET(TEST_SOURCES ${TEST_SOURCES}
-      ShowDicom.cxx
-      ShowDicomSeq.cxx
-      TestWriteWithVTK.cxx
+      VTKTestRead.cxx
+      VTKTestReadSeq.cxx
+      VTKTestWrite.cxx
       )
   ENDIF(GDCM_VTK)
 ENDIF (GDCM_DATA_ROOT)
diff --git a/Testing/VTKTestRead.cxx b/Testing/VTKTestRead.cxx
new file mode 100644 (file)
index 0000000..4a6dc5d
--- /dev/null
@@ -0,0 +1,242 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: VTKTestRead.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/19 10:43:01 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "vtkGdcmReader.h"
+#include "vtkImageViewer.h"
+#include "vtkImageData.h"
+#include "vtkRegressionTestImage.h"
+#include "vtkImageClip.h"
+#include "vtkImageTranslateExtent.h"
+#include "vtkImageAppendComponents.h"
+#include "vtkImageShiftScale.h"
+
+#include <iostream>
+
+//Generated file:
+#include "gdcmDataImages.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+int VTKReadTest(vtkTesting *t,vtkImageViewer *viewer,
+                std::string const & filename, 
+                std::string const & referenceFileName,
+                bool show )
+{
+   int retVal = 0;  //by default this is an error
+
+   t->CleanArguments();
+   t->AddArgument("-D");
+   t->AddArgument( GDCM_DATA_ROOT );
+   t->AddArgument("-V");
+   t->AddArgument( referenceFileName.c_str() );
+   t->AddArgument("-T");
+   t->AddArgument( "." );
+   
+   // Instead of directly reading the dicom let's write it down to another file
+   // do a scope to be sure everything gets cleanup
+   {
+      gdcm::File file( filename );
+      file.GetImageData();
+      file.SetWriteModeToRaw();
+      file.WriteDcmExplVR( "TestWrite.dcm" );
+   }
+   // Ok for now still use the original image, 
+   vtkGdcmReader *reader = vtkGdcmReader::New();
+   //reader->SetFileName( filename.c_str() );
+   reader->SetFileName( "TestWrite.dcm" );
+   reader->Update();
+
+   int dim[3];
+   reader->GetOutput()->GetDimensions( dim );
+
+   // Show
+   if(viewer)
+   {
+      viewer->SetInput ( reader->GetOutput() );
+
+      vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
+      viewer->SetColorWindow (range[1] - range[0]);
+      viewer->SetColorLevel (0.5 * (range[1] + range[0]));
+
+      viewer->SetSize(dim[0], dim[1]);
+      if(dim[2] != 1)
+      {
+         //For multifame dicom, take a snapshot of the center slice (+/- 1)
+         viewer->SetZSlice( dim[2] / 2 );
+      }
+      else
+      {
+         viewer->SetZSlice( 0 );
+      }
+
+      viewer->OffScreenRenderingOff();
+      viewer->Render();
+      viewer->SetInput(NULL);
+   }
+
+   //----------------------------------------------------------------------
+   // Transform the image to be RGB unsigned char, due to the requests in
+   // vtkTesting processing
+   // The pipeline is broken after each process to keep maximum of memory
+   vtkImageData *image=reader->GetOutput();
+   image->Update();
+   image->Register(NULL);
+   reader->Delete();
+
+   // Get the middle slice in the image
+   if(dim[2] != 1)
+   {
+      int *ext=image->GetExtent();
+      vtkImageClip *clip=vtkImageClip::New();
+      clip->SetInput(image);
+      clip->SetOutputWholeExtent(ext[0],ext[1],ext[2],ext[3],
+                                 ext[4]+dim[2] / 2,ext[4]+dim[2] / 2);
+      vtkImageTranslateExtent *translat=vtkImageTranslateExtent::New();
+      translat->SetInput(clip->GetOutput());
+      translat->SetTranslation(0,0,-ext[4]-dim[2] / 2);
+
+      image->UnRegister(NULL);
+      image=translat->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      translat->SetOutput(NULL);
+      clip->Delete();
+      translat->Delete();
+   }
+
+   // Set an unsigned char image
+   // Shift/Scale the image 
+   image->Update();
+   double *rng=image->GetScalarRange();
+   vtkImageShiftScale *iss=vtkImageShiftScale::New();
+   iss->SetInput(image);
+   iss->SetOutputScalarTypeToUnsignedChar();
+   iss->SetShift(-rng[0]);
+   iss->SetScale(255.0/(rng[1]-rng[0]));
+   iss->ClampOverflowOn();
+
+   image->UnRegister(NULL);
+   image=iss->GetOutput();
+   image->Update();
+   image->Register(NULL);
+   iss->Delete();
+
+   // Set 3 components to the image
+   if(image->GetNumberOfScalarComponents()==1)
+   {
+      vtkImageAppendComponents *x3=vtkImageAppendComponents::New();
+      x3->AddInput(image);
+      x3->AddInput(image);
+      x3->AddInput(image);
+
+      image->UnRegister(NULL);
+      image=x3->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      x3->SetOutput(NULL);
+      x3->Delete();
+   }
+   // End of transform
+   //----------------------------------------------------------------------
+
+   // make test
+   ostrstream str;
+   retVal = t->RegressionTest(image,0.0,str);
+   image->UnRegister(NULL);
+
+   if( retVal != vtkTesting::PASSED )
+   {
+      std::cerr << str.str();
+   }
+   str.rdbuf()->freeze(1);
+
+   if( retVal == vtkTesting::PASSED )
+   {
+      std::cerr << "       ... OK" << std::endl;
+      return 0;
+   }
+   else
+   {
+      std::cerr << "       ... Failed" << std::endl;
+      return 1;
+   }
+
+}
+
+int VTKTestRead(int argc, char *argv[])
+{
+   bool show = false;
+   if( argc >= 2 )
+   {
+      if( std::string(argv[1]) == "-V" )
+      {
+         show = true;
+      }
+   }
+
+   int ret = 0;
+   vtkTesting* t = vtkTesting::New();
+   vtkImageViewer *viewer;
+   if( show )
+      viewer = vtkImageViewer::New();
+   else
+      viewer = NULL;
+
+   if( argc < 3+show )
+   {
+      std::cerr << "Usage: " << argv[0] << " [-V] image.dcm ref.png\n";
+      std::cerr << "   -V : to view images to the screen... \n"
+                << "        this mode can generate errors in the test\n\n";
+   }
+   else
+   {
+      ret = VTKReadTest(t,viewer,argv[1+show],argv[2+show],show);
+      t->Delete();
+      viewer->Delete();
+
+      return ret;
+   }
+
+   // Test for all images
+   int i = 0;
+   while( gdcmDataImages[i] != 0 )
+   {
+      std::string filename = GDCM_DATA_ROOT;
+      filename += "/";  //doh!
+      filename += gdcmDataImages[i];
+      std::cerr << "Filename: " << filename << std::endl;
+
+      //Extract name to find the png file matching:
+      std::string pngfile = gdcmDataImages[i++];
+      //pngfile.replace(pngfile.size()-3, 3, "png");
+      //More robust approach:
+      std::string::size_type dot_pos = pngfile.rfind( "." );
+      pngfile = pngfile.substr(0, dot_pos).append( ".png" );
+      pngfile.insert( 0, "Baseline/");
+      //std::cerr << "PNG file: " << pngfile << std::endl;
+
+      ret += VTKReadTest(t,viewer,filename,pngfile,show);
+   }
+   t->Delete();
+   viewer->Delete();
+
+   return ret;
+}
diff --git a/Testing/VTKTestReadSeq.cxx b/Testing/VTKTestReadSeq.cxx
new file mode 100644 (file)
index 0000000..7339eb8
--- /dev/null
@@ -0,0 +1,244 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: VTKTestReadSeq.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/19 10:43:01 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "vtkGdcmReader.h"
+#include "vtkImageViewer.h"
+#include "vtkImageData.h"
+#include "vtkRegressionTestImage.h"
+#include "vtkImageClip.h"
+#include "vtkImageTranslateExtent.h"
+#include "vtkImageAppendComponents.h"
+#include "vtkImageShiftScale.h"
+
+#include <iostream>
+
+//Generated file:
+#include "gdcmDataSeqImages.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+int VTKReadSeqTest(vtkTesting *t,vtkImageViewer *viewer,
+                   std::string const & filename, 
+                   std::string const & referenceFileName,
+                   bool show )
+{
+   int retVal = 0;  //by default this is an error
+
+   // Set the reader   
+   vtkGdcmReader *reader = vtkGdcmReader::New();
+
+   char *newFileDcm = new char[filename.size()+1];
+   int fileCount = 0;
+   for(int i=0;i<9;i++)
+   {
+      fileCount = i;
+      sprintf(newFileDcm,filename.c_str(),i);
+
+      // Test the existance of the file
+      ifstream opened(newFileDcm,std::ios::in | std::ios::binary);
+      if(opened)
+      {
+         reader->AddFileName(newFileDcm);
+         opened.close();
+      }
+      else
+         break;
+   }
+   delete[] newFileDcm;
+   reader->Update();
+
+   if( show )
+   {
+      viewer->SetInput ( reader->GetOutput() );
+      viewer->OffScreenRenderingOff();
+
+      vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
+      viewer->SetColorWindow (range[1] - range[0]);
+      viewer->SetColorLevel (0.5 * (range[1] + range[0]));
+
+      int dim[3];
+      reader->GetOutput()->GetDimensions( dim );
+      viewer->SetSize(dim[0], dim[1]);
+      viewer->SetZSlice( 0 );
+      viewer->Render();
+      viewer->SetInput(NULL);
+   }
+
+   // make test
+   int ret = 0;
+   ostrstream str;
+   char *newFilePng = new char[referenceFileName.size()+1];
+   for(int j=0;j<fileCount;j++)
+   {
+      sprintf(newFilePng,referenceFileName.c_str(),j);
+
+      t->CleanArguments();
+      t->AddArgument("-D");
+      t->AddArgument( GDCM_DATA_ROOT );
+      t->AddArgument("-V");
+      t->AddArgument( newFilePng );
+      t->AddArgument("-T");
+      t->AddArgument( "." );
+
+      //----------------------------------------------------------------------
+      // Transform the image to be RGB unsigned char, due to the requests in
+      // vtkTesting processing
+      // The pipeline is broken after each process to keep maximum of memory
+      vtkImageData *image=reader->GetOutput();
+      image->Update();
+      image->Register(NULL);
+
+      // Get the middle slice in the image
+      int *ext=image->GetExtent();
+      vtkImageClip *clip=vtkImageClip::New();
+      clip->SetInput(image);
+      clip->SetOutputWholeExtent(ext[0],ext[1],ext[2],ext[3],j,j);
+      vtkImageTranslateExtent *translat=vtkImageTranslateExtent::New();
+      translat->SetInput(clip->GetOutput());
+      translat->SetTranslation(0,0,-j);
+
+      image->UnRegister(NULL);
+      image=translat->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      translat->SetOutput(NULL);
+      clip->Delete();
+      translat->Delete();
+
+      // Set an unsigned char image
+      // Shift/Scale the image 
+      image->Update();
+      double *rng=image->GetScalarRange();
+      vtkImageShiftScale *iss=vtkImageShiftScale::New();
+      iss->SetInput(image);
+      iss->SetOutputScalarTypeToUnsignedChar();
+      iss->SetShift(-rng[0]);
+      iss->SetScale(255.0/(rng[1]-rng[0]));
+      iss->ClampOverflowOn();
+
+      image->UnRegister(NULL);
+      image=iss->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      iss->Delete();
+
+      // Set 3 components to the image
+      if(image->GetNumberOfScalarComponents()==1)
+      {
+         vtkImageAppendComponents *x3=vtkImageAppendComponents::New();
+         x3->AddInput(image);
+         x3->AddInput(image);
+         x3->AddInput(image);
+
+         image->UnRegister(NULL);
+         image=x3->GetOutput();
+         image->Update();
+         image->Register(NULL);
+         x3->SetOutput(NULL);
+         x3->Delete();
+      }
+      // End of transform
+      //----------------------------------------------------------------------
+
+      // make test
+      retVal = t->RegressionTest(image,2.0,str);
+      image->UnRegister(NULL);
+
+      if( retVal != vtkTesting::PASSED )
+      {
+         std::cerr << str.str();
+      }
+      str.rdbuf()->freeze(1);
+
+      if( retVal == vtkTesting::PASSED )
+      {
+         std::cerr << "       ...Slice " << j << ": OK" << std::endl;
+      }
+      else
+      {
+         std::cerr << "       ...Slice " << j << ": Failed" << std::endl;
+         ret++;
+      }
+   }
+
+   delete[] newFilePng;
+   reader->Delete();
+
+   return ret;
+}
+
+int VTKTestReadSeq(int argc, char *argv[])
+{
+   bool show = false;
+   if( argc >= 2 )
+   {
+      if( std::string(argv[1]) == "-V" )
+      {
+         show = true;
+      }
+   }
+
+   int ret = 0;
+   vtkTesting* t = vtkTesting::New();
+   vtkImageViewer *viewer;
+   if( show )
+      viewer = vtkImageViewer::New();
+   else
+      viewer = NULL;
+
+   if( argc < 3+show )
+   {
+      std::cerr << "Usage: " << argv[0] << " [-V] image%d.dcm ref%d.png\n";
+      std::cerr << "   -V : to view images to the screen... \n"
+                << "        this mode can generate errors in the test\n";
+      std::cerr << "   %d : this will be replaced by a number at execution.\n"
+                << "        It will be from 0 to 9 only with a step of 1\n\n";
+   }
+   else
+   {
+      ret = VTKReadSeqTest(t,viewer,argv[1+show],argv[2+show],show);
+      t->Delete();
+      viewer->Delete();
+
+      return ret;
+   }
+
+   // Test for all images
+   int i = 0;
+   while( gdcmDataSeqImages[i] != 0 )
+   {
+      std::string filename = GDCM_DATA_ROOT;
+      filename += "/";  //doh!
+      filename += gdcmDataSeqImages[i];
+      std::cerr << "Filename: " << filename << std::endl;
+
+      //Extract name to find the png file matching:
+      std::string pngfile = gdcmDataSeqImages[i++];
+      std::string::size_type dot_pos = pngfile.rfind( "." );
+      pngfile = pngfile.substr(0, dot_pos).append( ".png" );
+      pngfile.insert( 0, "Baseline/");
+      
+      ret += VTKReadSeqTest(t,viewer,filename,pngfile,show);
+   }
+   t->Delete();
+   viewer->Delete();
+
+   return ret;
+}
diff --git a/Testing/VTKTestWrite.cxx b/Testing/VTKTestWrite.cxx
new file mode 100644 (file)
index 0000000..e782dd7
--- /dev/null
@@ -0,0 +1,246 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: VTKTestWrite.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/19 10:43:01 $
+  Version:   $Revision: 1.1 $
+
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "vtkGdcmReader.h"
+#include "vtkGdcmWriter.h"
+#include "vtkImageViewer.h"
+#include "vtkImageData.h"
+#include "vtkRegressionTestImage.h"
+#include "vtkImageClip.h"
+#include "vtkImageTranslateExtent.h"
+#include "vtkImageAppendComponents.h"
+#include "vtkImageShiftScale.h"
+
+#include <iostream>
+
+//Generated file:
+#include "gdcmDataImages.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+int VTKWriteTest(vtkTesting *t,vtkImageViewer *viewer,
+                 std::string const & filename, 
+                 std::string const & referenceFileName,
+                 bool show )
+{
+   int retVal = 0;  //by default this is an error
+
+   t->CleanArguments();
+   t->AddArgument("-D");
+   t->AddArgument( GDCM_DATA_ROOT );
+   t->AddArgument("-V");
+   t->AddArgument( referenceFileName.c_str() );
+   t->AddArgument("-T");
+   t->AddArgument( "." );
+
+   // Read the image   
+   vtkGdcmReader *origin = vtkGdcmReader::New();
+   origin->SetFileName( filename.c_str() );
+   origin->Update();
+
+   // Write the image
+   vtkGdcmWriter *writer = vtkGdcmWriter::New();
+   writer->SetFileName( "TestWrite.dcm" );
+   writer->SetInput(origin->GetOutput());
+   writer->Write();
+
+   origin->Delete();
+   writer->Delete();
+
+   // Read the written image   
+   vtkGdcmReader *reader = vtkGdcmReader::New();
+   reader->SetFileName( "TestWrite.dcm" );
+   reader->Update();
+
+   int dim[3];
+   reader->GetOutput()->GetDimensions( dim );
+
+   // Show
+   if( show )
+   {
+      viewer->SetInput ( reader->GetOutput() );
+
+      vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
+      viewer->SetColorWindow (range[1] - range[0]);
+      viewer->SetColorLevel (0.5 * (range[1] + range[0]));
+
+      viewer->SetSize(dim[0], dim[1]);
+      if(dim[2] != 1)
+      {
+         //For multifame dicom, take a snapshot of the center slice (+/- 1)
+         viewer->SetZSlice( dim[2] / 2 );
+      }
+      else
+      {
+         viewer->SetZSlice( 0 );
+      }
+
+      viewer->OffScreenRenderingOff();
+      viewer->Render();
+      viewer->SetInput(NULL);
+   }
+
+   //----------------------------------------------------------------------
+   // Transform the image to be RGB unsigned char, due to the requests in
+   // vtkTesting processing
+   // The pipeline is broken after each process to keep maximum of memory
+   vtkImageData *image=reader->GetOutput();
+   image->Update();
+   image->Register(NULL);
+   reader->Delete();
+
+   // Get the middle slice in the image
+   if(dim[2] != 1)
+   {
+      int *ext=image->GetExtent();
+      vtkImageClip *clip=vtkImageClip::New();
+      clip->SetInput(image);
+      clip->SetOutputWholeExtent(ext[0],ext[1],ext[2],ext[3],
+                                 ext[4]+dim[2] / 2,ext[4]+dim[2] / 2);
+      vtkImageTranslateExtent *translat=vtkImageTranslateExtent::New();
+      translat->SetInput(clip->GetOutput());
+      translat->SetTranslation(0,0,-ext[4]-dim[2] / 2);
+
+      image->UnRegister(NULL);
+      image=translat->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      translat->SetOutput(NULL);
+      clip->Delete();
+      translat->Delete();
+   }
+
+   // Set an unsigned char image
+   // Shift/Scale the image 
+   image->Update();
+   double *rng=image->GetScalarRange();
+   vtkImageShiftScale *iss=vtkImageShiftScale::New();
+   iss->SetInput(image);
+   iss->SetOutputScalarTypeToUnsignedChar();
+   iss->SetShift(-rng[0]);
+   iss->SetScale(255.0/(rng[1]-rng[0]));
+   iss->ClampOverflowOn();
+
+   image->UnRegister(NULL);
+   image=iss->GetOutput();
+   image->Update();
+   image->Register(NULL);
+   iss->Delete();
+
+   // Set 3 components to the image
+   if(image->GetNumberOfScalarComponents()==1)
+   {
+      vtkImageAppendComponents *x3=vtkImageAppendComponents::New();
+      x3->AddInput(image);
+      x3->AddInput(image);
+      x3->AddInput(image);
+
+      image->UnRegister(NULL);
+      image=x3->GetOutput();
+      image->Update();
+      image->Register(NULL);
+      x3->SetOutput(NULL);
+      x3->Delete();
+   }
+   // End of transform
+   //----------------------------------------------------------------------
+
+   // make test
+   ostrstream str;
+   retVal = t->RegressionTest(image,0.0,str);
+   image->UnRegister(NULL);
+
+   if( retVal != vtkTesting::PASSED )
+   {
+      std::cerr << str.str();
+   }
+   str.rdbuf()->freeze(1);
+
+   if( retVal == vtkTesting::PASSED )
+   {
+      std::cerr << "       ... OK" << std::endl;
+      return 0;
+   }
+   else
+   {
+      std::cerr << "       ... Failed" << std::endl;
+      return 1;
+   }
+}
+
+int VTKTestWrite(int argc, char *argv[])
+{
+   bool show = false;
+   if( argc >= 2 )
+   {
+      if( std::string(argv[1]) == "-V" )
+      {
+         show = true;
+      }
+   }
+
+   int ret = 0;
+   vtkTesting* t = vtkTesting::New();
+   vtkImageViewer *viewer;
+   if( show )
+      viewer = vtkImageViewer::New();
+   else
+      viewer = NULL;
+
+   if( argc < 3+show )
+   {
+      std::cerr << "Usage: " << argv[0] << " [-V] image.dcm ref.png\n";
+      std::cerr << "   -V : to view images to the screen... \n"
+                << "        this mode can generate errors in the test\n\n";
+   }
+   else
+   {
+      ret = VTKWriteTest(t,viewer,argv[1+show],argv[2+show],show);
+      t->Delete();
+      viewer->Delete();
+
+      return ret;
+   }
+
+   // Test for all images
+   int i = 0;
+   while( gdcmDataImages[i] != 0 )
+   {
+      std::string filename = GDCM_DATA_ROOT;
+      filename += "/";  //doh!
+      filename += gdcmDataImages[i];
+      std::cerr << "Filename: " << filename << std::endl;
+
+      //Extract name to find the png file matching:
+      std::string pngfile = gdcmDataImages[i++];
+      //pngfile.replace(pngfile.size()-3, 3, "png");
+      //More robust approach:
+      std::string::size_type dot_pos = pngfile.rfind( "." );
+      pngfile = pngfile.substr(0, dot_pos).append( ".png" );
+      pngfile.insert( 0, "Baseline/");
+      //std::cerr << "PNG file: " << pngfile << std::endl;
+
+      ret += VTKWriteTest(t,viewer,filename,pngfile,show);
+   }
+   t->Delete();
+   viewer->Delete();
+
+   return ret;
+}
index 8adbdd9d1ca1689b555706142f33742215a7492a..03ac74973d9fc41496d7da9fcd5dc8cd087e04cd 100644 (file)
@@ -40,8 +40,7 @@ entry.Print()
 print "#####################################################################"
 # Print the public Dict content
 print "dict content :"
-pubDict.InitTraversal()
-entry=pubDict.GetNextEntry()
+entry=pubDict.GetFirstEntry()
 while(entry):
        entry.Print()
        entry=pubDict.GetNextEntry()
index eb11bce6b42f2e2be53769366d205f20473012f1..6b7ca53052ac251f83907d3753a0d43a36d8750c 100644 (file)
@@ -32,8 +32,7 @@ print "### Display all the elements and their respective values"
 print "## found in the ", fileName, " file."
 print "##############################################################"
 
-header.InitTraversal()
-val=header.GetNextEntry()
+val=header.GetFirstEntry()
 while(val):
        val.Print()
        print ""