Program: gdcm
Module: $RCSfile: TestAllReadCompareDicom.cxx,v $
Language: C++
- Date: $Date: 2004/11/17 10:20:06 $
- Version: $Revision: 1.16 $
+ Date: $Date: 2005/01/31 03:36:59 $
+ Version: $Revision: 1.26 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
-#include "gdcmHeader.h"
#include "gdcmFile.h"
-#include <stdio.h>
+#include "gdcmFileHelper.h"
+
+#include <iostream>
+#include <fstream>
//Generated file:
#include "gdcmDataImages.h"
{
std::cout << " Testing: " << filename << std::endl;
- gdcm::File* tested = new gdcm::File( filename );
- if( !tested->GetHeader()->IsReadable() )
+ ////// Step 1:
+ std::cout << " 1...";
+ gdcm::FileHelper* tested = new gdcm::FileHelper( filename );
+ if( !tested->GetFile()->IsReadable() )
{
- std::cout << " Image not gdcm compatible:"
+ std::cout << " Failed" << std::endl
+ << " Image not gdcm compatible:"
<< filename << std::endl;
delete tested;
return 1;
}
////// Step 2:
-
////// Check for existence of reference baseline dicom file:
+ std::cout << "2...";
- FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
+ std::ifstream testFILE( referenceFileName.c_str() );
if (! testFILE )
{
- ////// Step 3a:
uint8_t* testedImageData = tested->GetImageData(); // Kludge
(void)testedImageData;
+ tested->SetWriteModeToRGB();
tested->WriteDcmExplVR( referenceFileName );
- std::cerr << " Creating reference baseline file :" << std::endl
- << " " << referenceFileName
- << std::endl;
- delete tested;
- //delete (char*)testedImageData;
- return 0;
- }
- else
- {
- fclose( testFILE );
}
+ testFILE.close();
+ ////// Step 3a:
////// When reference file is not gdcm readable test is failed:
-
- gdcm::File* reference = new gdcm::File( referenceFileName );
- if( !reference->GetHeader()->IsReadable() )
+ std::cout << "3a...";
+
+ gdcm::FileHelper* reference = new gdcm::FileHelper( referenceFileName );
+ if( !reference->GetFile()->IsReadable() )
{
- std::cout << " Failed: reference image " << std::endl
- << " " << referenceFileName <<std::endl
- << " is not gdcm compatible." << std::endl;
+ std::cout << " Failed" << std::endl
+ << " reference image "
+ << referenceFileName
+ << " is not gdcm compatible." << std::endl;
delete tested;
delete reference;
return 1;
}
- ////// Step 3b:
+ std::string PixelType = reference->GetFile()->GetPixelType();
+ ////// Step 3b:
+ std::cout << "3b...";
int testedDataSize = tested->GetImageDataSize();
uint8_t* testedImageData = tested->GetImageData();
int referenceDataSize = reference->GetImageDataSize();
uint8_t* referenceImageData = reference->GetImageData();
+ // Test the image size
+ if (tested->GetFile()->GetXSize() != reference->GetFile()->GetXSize() ||
+ tested->GetFile()->GetYSize() != reference->GetFile()->GetYSize() ||
+ tested->GetFile()->GetZSize() != reference->GetFile()->GetZSize())
+ {
+ std::cout << "Failed" << std::endl
+ << " Size differs: "
+ << "X: " << tested->GetFile()->GetXSize() << " # "
+ << reference->GetFile()->GetXSize() << " | "
+ << "Y: " << tested->GetFile()->GetYSize() << " # "
+ << reference->GetFile()->GetYSize() << " | "
+ << "Z: " << tested->GetFile()->GetZSize() << " # "
+ << reference->GetFile()->GetZSize() << std::endl;
+ delete reference;
+ delete tested;
+ return 1;
+ }
+
+ // Test the data size
if (testedDataSize != referenceDataSize)
{
- std::cout << " Failed: pixel areas lengths differ: "
+ std::cout << " Failed" << std::endl
+ << " pixel ("
+ << PixelType
+ <<") areas lengths differ: "
<< testedDataSize << " # " << referenceDataSize
<< std::endl;
delete tested;
return 1;
}
+ // Test the data content
if (int res = memcmp(testedImageData, referenceImageData,
testedDataSize) != 0 )
{
(void)res;
- std::cout << " Failed: pixel differ (as expanded in memory)."
+ std::cout << " Failed" << std::endl
+ << " pixel ("
+ << PixelType
+ << ") differ (as expanded in memory)."
<< std::endl;
delete tested;
delete reference;
delete tested;
delete reference;
- std::cout << " Passed..." << std::endl;
+ std::cout << "OK." << std::endl;
return 0;
}
<< std::endl;
std::cout << " apply the following to each filename.xxx: "
<< std::endl;
- std::cout << " step 1: parse the image (as gdcmHeader) and call"
+ std::cout << " step 1: parse the image (as gdcmFile) and call"
<< " IsReadable(). "
<< std::endl;
std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
std::string baseLineDir = GDCM_DATA_ROOT;
baseLineDir += "/BaselineDicom/";
- std::ifstream* testDIR = new std::ifstream(baseLineDir.c_str(), std::ios::in | std::ios::binary);
+ std::ifstream testDIR(baseLineDir.c_str(), std::ios::in | std::ios::binary);
if (!testDIR )
{
std::cerr << " The reference baseline directory " << std::endl
<< std::endl;
return 1;
}
- else
- {
- testDIR->close();
- }
+ testDIR.close();
////// Step 1 (see above description):
std::string filename = GDCM_DATA_ROOT;