]> Creatis software - gdcm.git/commitdiff
* Test/VTKTestWriteSeq.cxx : add a VTK test to write sequences
authorregrain <regrain>
Wed, 9 Feb 2005 15:31:14 +0000 (15:31 +0000)
committerregrain <regrain>
Wed, 9 Feb 2005 15:31:14 +0000 (15:31 +0000)
   -- BeNours

ChangeLog
Example/exGC.cxx
Testing/CMakeLists.txt
Testing/TestCopyDicom.cxx
Testing/TestCopyRescaleDicom.cxx
Testing/VTKTestRead.cxx
Testing/VTKTestReadSeq.cxx
Testing/VTKTestWrite.cxx
Testing/VTKTestWriteSeq.cxx [new file with mode: 0644]

index 26c6f887f4552638a99908a9e238676424f3a952..9fccacd1011f54b3aba1a95d69df01eda325ad59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2005-02-09 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * Test/VTKTestWriteSeq.cxx : add a VTK test to write sequences
+
 2005-02-09 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * Test/ : accelerate tests (it's not very significant accelerations).
      Remove TestCopyDicom that is redundant with TestCopyRescaleDicom
index 25bb6454863e93dc48359d0e86afd6cb0097f2ee..56ec83cc7f87458dff2f7e38d4b321389f698c19 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exGC.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/09 14:39:48 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -149,8 +149,9 @@ int main(int argc, char *argv[])
 
    int imageSize = fh1->GetImageDataSize();
 // Black up all 'grey' pixels
+   int i;
    int n = 0;
-   for (int i = 0; i<imageSize/3; i++)
+   for (i = 0; i<imageSize/3; i++)
    {
       if ( ((rgb8_t *)imageData)[i].r == ((rgb8_t *)imageData)[i].g
          &&
@@ -167,7 +168,7 @@ int main(int argc, char *argv[])
               << imageSize/3 << ")" << std::endl;
 
    n = 0;
-   for (int i = 0; i<imageSize/3; i++)
+   for (i = 0; i<imageSize/3; i++)
    {
    if ( ((rgb8_t *)imageData)[i].r < threshold
      &&
index ee0639e92fe96939325ccd863425f2c569e858fe..3cafed40454b5fbe7f823b0ece154dfee83fb9be 100644 (file)
@@ -44,12 +44,13 @@ IF (GDCM_DATA_ROOT)
 
     INCLUDE_DIRECTORIES(
       ${GDCM_SOURCE_DIR}/vtk/
-      )
+    )
     SET(TEST_SOURCES ${TEST_SOURCES}
       VTKTestRead.cxx
       VTKTestReadSeq.cxx
       VTKTestWrite.cxx
-      )
+      VTKTestWriteSeq.cxx
+    )
   ENDIF(GDCM_VTK)
 ENDIF (GDCM_DATA_ROOT)
 
@@ -75,14 +76,7 @@ REMOVE (TestsToRun gdcmTests.cxx)
 # Loop over files and create executables
 FOREACH(file ${TEST_SOURCES})
   GET_FILENAME_COMPONENT(name ${file} NAME_WE)
-#  IF (GDCM_DATA_ROOT)
-#    ADD_TEST(${name} ${GDCM_TESTS} ${name}
-#        -D ${GDCM_DATA_ROOT}
-#        -T ${GDCM_BINARY_DIR}/Testing/Temporary
-#        -V Baseline/gdcm/${name}.png)
-#  ELSE (GDCM_DATA_ROOT)
-    ADD_TEST(${name} ${GDCM_TESTS} ${name})
-#  ENDIF (GDCM_DATA_ROOT)
+  ADD_TEST(${name} ${GDCM_TESTS} ${name})
 ENDFOREACH(file ${TEST_SOURCES})
 
 #-----------------------------------------------------------------------------
@@ -183,9 +177,9 @@ ENDFOREACH(filename)
 # Populate GDCM_DATA_IMAGES:
 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataImages.h"
   "const char * const gdcmDataImages[] = { ${GDCM_DATA_IMAGES}\n0 };\n" 
-  )
+)
 
 # Populate GDCM_DATA_SEQ_IMAGES:
 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataSeqImages.h"
   "const char * const gdcmDataSeqImages[] = { ${GDCM_DATA_SEQ_IMAGES}\n0 };\n" 
-  )
+)
index f74e39d2ba95f5e01a845b6a8435e096e7181608..9220962c4098437541ccb0531f9a88793e72c36e 100644 (file)
@@ -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: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.40 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 //Generated file:
 #include "gdcmDataImages.h"
 
-#ifndef _WIN32
-#include <unistd.h> //for access, unlink
-#else
-#include <io.h> //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 )
index 392e7c27dd3d7f406101111a9507b31913bf92d2..54f7d7b81a3fe8a530aec59afbc08bc2799f4a42 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestCopyRescaleDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/09 15:06:48 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 //Generated file:
 #include "gdcmDataImages.h"
 
-bool FileExists(const char *filename);
+#ifndef _WIN32
+#include <unistd.h> //for access, unlink
+#else
+#include <io.h> //for _access on Win32
+#endif
 
-bool RemoveFile(const char *source);
+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;
+}
 
 int CopyRescaleDicom(std::string const &filename, 
                      std::string const &output )
index 88a6157eeff8317a009bce752b0a571f8f3fd7a4..f17b7512e71605fa86e655b58349d3f10b3085fa 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: VTKTestRead.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/09 15:06:48 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -15,7 +15,6 @@
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmFileHelper.h"
 #include "vtkGdcmReader.h"
 #include "vtkImageViewer.h"
 #include "vtkImageData.h"
index 516927feb1528b34fa208264565c19666045986d..7cd5166ad8a6d5418d0a1b5fd5a149c0b9ebffbd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: VTKTestReadSeq.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/03 10:00:06 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -15,7 +15,6 @@
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmFileHelper.h"
 #include "vtkGdcmReader.h"
 #include "vtkImageViewer.h"
 #include "vtkImageData.h"
index ea204cf11e078f6978712527dd3de0030ef22981..c3d989ee6fd3db966ca604727f9b9d5b7131d275 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: VTKTestWrite.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/02 10:05:26 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2005/02/09 15:31:15 $
+  Version:   $Revision: 1.9 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -15,7 +15,6 @@
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmFileHelper.h"
 #include "vtkGdcmReader.h"
 #include "vtkGdcmWriter.h"
 #include "vtkImageViewer.h"
diff --git a/Testing/VTKTestWriteSeq.cxx b/Testing/VTKTestWriteSeq.cxx
new file mode 100644 (file)
index 0000000..4d3b41c
--- /dev/null
@@ -0,0 +1,268 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: VTKTestWriteSeq.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/02/09 15:31:15 $
+  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 "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 "gdcmDataSeqImages.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+int VTKWriteSeqTest(vtkTesting *t, vtkImageViewer *viewer,
+                   std::string const &filename, 
+                   std::string const &referenceFileName)
+{
+   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();
+
+   // Write the image
+   vtkGdcmWriter *writer = vtkGdcmWriter::New();
+   writer->SetFilePattern("%s%02d.dcm");
+   writer->SetFilePrefix("TestWrite");
+   writer->SetFileDimensionality(2);
+   writer->SetInput(reader->GetOutput());
+   writer->Write();
+
+   reader->Delete();
+   writer->Delete();
+
+   // Reread the image
+   reader = vtkGdcmReader::New();
+   reader->SetFilePattern("%s%02d.dcm");
+   reader->SetFilePrefix("TestWrite");
+   reader->SetFileNameSliceOffset(0);
+   reader->SetFileNameSliceSpacing(1);
+   reader->SetDataExtent(0,0,0,0,0,fileCount-1);
+   reader->Update();
+
+   double range[2];
+   reader->GetOutput()->GetScalarRange(range);
+
+   // Show
+   if( viewer )
+   {
+      viewer->SetInput ( reader->GetOutput() );
+      viewer->OffScreenRenderingOff();
+
+      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);
+      clip->ClipDataOn();
+      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();
+      vtkImageShiftScale *iss=vtkImageShiftScale::New();
+      iss->SetInput(image);
+      iss->SetOutputScalarTypeToUnsignedChar();
+      iss->SetShift(-range[0]);
+      iss->SetScale(255.0/(range[1]-range[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 VTKTestWriteSeq(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 = VTKWriteSeqTest(t,viewer,argv[1+show],argv[2+show]);
+      t->Delete();
+      if( viewer )
+         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 += VTKWriteSeqTest(t,viewer,filename,pngfile);
+   }
+   t->Delete();
+   if( viewer )
+      viewer->Delete();
+
+   return ret;
+}