[Insight-users] Fwd: Re: Problem ITK and GDCM in the same script

Lars Friedrich Lars lars-friedrich at gmx.net
Sun Mar 21 10:49:32 EDT 2010


-------- Original-Nachricht --------
Datum: Sun, 21 Mar 2010 15:46:53 +0100
Von: "Lars Friedrich Lars" <lars-friedrich at gmx.net>
An: edoardo.belletti at alice.it
Betreff: Re: [Insight-users] Problem ITK and GDCM in the same script

Hello Eduardo,

without exactly knowing what you expect your DICOM application to do ...

Did you compile the ITK with ITK_USE_SYSTEM_GDCM (CMake-option of ITK)? If you did not, you should. This causes the ITK to take the system-installed GDCM (usually 2.++) instead of the one shipped with the ITK. If you did that you do no longer have to enter the GDCM-specific CMakeLists-entries (FIND_PACKAGE(GDCM) and so on), it should normally be sufficient to do the FIND_PACKAGE(ITK) stuff.

I had similar problems with a mixed-up ITK/VTK/GDCM2.0 application at the very beginning (the error messages were partially funny and not really trackable).

HTH,

lars


-------- Original-Nachricht --------
> Datum: Sun, 21 Mar 2010 12:21:26 +0100
> Von: edoardo.belletti at alice.it
> An: "ITK_forum  " <insight-users at itk.org>
> Betreff: [Insight-users] Problem ITK and GDCM in the same script

> Hi 
> I have a problem with configuring ITK with GDCM 2.0
> I have wrote this script which use the gdcm library for extract some tag
> from the header dicom and it works, but when in the same script I try to use
> also the itk's library the output is: Segmentation Fault (wherever I call
> Update() or I create a new smartpointer with New)
> I don't know if it is a problem of CMakeLists and so I have put in this
> email also my CMakeLists.txt.
> 
> Thank you very much
> 
> Edoardo Belletti
> 
> CMakeLists.txt:
> 
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
> 
> PROJECT(ImageIO)
> 
> # Find ITK.
> FIND_PACKAGE(ITK REQUIRED)
> IF(ITK_FOUND)
>   INCLUDE(${ITK_USE_FILE})
> ENDIF(ITK_FOUND)
> 
> # Find GDCM
> FIND_PACKAGE(GDCM)
>   IF(GDCM_FOUND)
>     INCLUDE(${GDCM_USE_FILE})
>     IF( "${GDCM_MAJOR_VERSION}" LESS 2.0 )
>       SET(MITK_GDCM_LIBRARIES gdcm)
>     ELSE( "${GDCM_MAJOR_VERSION}" LESS 2.0 )
>       SET(MITK_GDCM_LIBRARIES gdcmMSFF)
>     ENDIF( "${GDCM_MAJOR_VERSION}" LESS 2.0 )
>   ELSE(GDCM_FOUND)
>     MESSAGE(FATAL_ERROR "Must set GDCM_DIR for MITK_USE_SYSTEM_GDCM.")
>   ENDIF(GDCM_FOUND)
> 
> 
> 
> ADD_EXECUTABLE(ReadAndDumpDICOMDIR ReadAndDumpDICOMDIR.cxx )
> TARGET_LINK_LIBRARIES(ReadAndDumpDICOMDIR ITKCommon ITKIO gdcmMSFF)
> 
> 
> //==========================================================
> 
> 
> // Librerie ITK
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkSobelEdgeDetectionImageFilter.h"
> #include "itkCastImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkGDCMImageIO.h"
> #include "itkRegionOfInterestImageFilter.h"
> // Librerie GDCM
> #include "gdcmReader.h"
> #include "gdcmMediaStorage.h"
> #include "gdcmAttribute.h"
> #include "gdcmApplicationEntity.h"
> #include "gdcmElement.h"
> #include "gdcmSequenceOfItems.h"
> 
> bool Region ( char* nomefile, unsigned int X_min, unsigned int Y_min,
> unsigned int X_max, unsigned int Y_max );
> 
> 
> int main(int argc, char* argv[] )
> {
> 	// Controllo del numero di argomenti introdotti da riga di comando
> 	if( argc < 3 )
> 	{
> 		std::cerr << "Usage: " << std::endl;
> 		std::cerr << argv[0] << " inputImageFile  outputImageFile " <<
> std::endl;
> 		return EXIT_FAILURE;
> 	}
> 	// Settaggio delle variabili in input
> 	const char * InputImageFilename  = argv[1];
> 	const char * OutputImageFilename = argv[2];
> 
> 	// Dichiarazione dei tipi
> 	const unsigned int Dimension = 2;
> 	typedef unsigned char PixelType;
> 	typedef itk::Image< PixelType, Dimension > ImageType;
> 
> 	typedef itk::ImageFileReader< ImageType > ReaderType;
> 	typedef itk::ImageFileWriter< ImageType > WriterType;
> 	
> 	typedef itk::GDCMImageIO ImageIOType;
> 	ImageIOType::Pointer dicomIO = ImageIOType::New();
> 	
> 	ReaderType::Pointer reader = ReaderType::New();
>         reader->SetFileName( InputImageFilename );
> 	reader->SetImageIO( dicomIO );
>        
> 	WriterType::Pointer writer = WriterType::New();
>         writer->SetFileName( OutputImageFilename );
>         writer->SetInput( reader->GetOutput() );
>         writer->Update();
> 
> 	unsigned int x_min = 1;
> 	unsigned int y_min = 1;
> 	unsigned int x_max = 1;
> 	unsigned int y_max = 1;
> 
> 	if( Region ( argv[1], x_min, y_min, x_max, y_max ) )
> 			std::cout << "ok\n";
> 
> 	else
> 	{
> 		std::cout << "no\n";
> 
> 	}
> 
> 
> }
> 
> bool Region ( char* nomefile, unsigned int X_min, unsigned int Y_min,
> unsigned int X_max, unsigned int Y_max )
> {
> 	gdcm::Reader reader;
>         reader.SetFileName( nomefile );
>         if( !reader.Read() )
>         {
>                 std::cerr << "Could not read: " << nomefile << std::endl;
>                 return false;
>         }
> 
> 	gdcm::File &file = reader.GetFile();
>         gdcm::DataSet &ds = file.GetDataSet();
> 
> 	gdcm::Tag tsqur(0x0018,0x6011);
> 	if( !ds.FindDataElement( tsqur ) )
> 	{
> 		return false;
> 	}
> 
> 	const gdcm::DataElement &squr= ds.GetDataElement( tsqur );
> 	//std::cout << squr << std::endl;
> 	const gdcm::SequenceOfItems *sqi = squr.GetSequenceOfItems();
> 	if( !sqi || !sqi->GetNumberOfItems() )
> 	{
> 		return false;
> 	}
> 	//std::cout << sqi << std::endl;
> 
> 	const gdcm::Item & item = sqi->GetItem(1);
> 	//std::cout << item << std::endl;
> 	const gdcm::DataSet& nestedds = item.GetNestedDataSet();
> 	//std::cout << nestedds << std::endl;	
> 
> 	gdcm::Tag tX0(0x0018,0x6018);
> 	gdcm::Tag tY0(0x0018,0x601a);
> 	gdcm::Tag tX1(0x0018,0x601c);
> 	gdcm::Tag tY1(0x0018,0x601e);
> 
> 	if( (!nestedds.FindDataElement( tX0 ))||(!nestedds.FindDataElement( tY0
> ))||(!nestedds.FindDataElement( tX1 ))||(!nestedds.FindDataElement( tY1 )) )
> 	{
> 		return false;
> 	}
> 
> 	const gdcm::DataElement& deX0 = nestedds.GetDataElement( tX0 );
> 	const gdcm::DataElement& deY0 = nestedds.GetDataElement( tY0 );
> 	const gdcm::DataElement& deX1 = nestedds.GetDataElement( tX1 );
> 	const gdcm::DataElement& deY1 = nestedds.GetDataElement( tY1 );
> 	//std::cout << deX0 << std::endl << deY0 << std::endl << << deX1 <<
> std::endl << deY1 << std::endl;
> 
> 	//const gdcm::ByteValue *bvX0 = deX0.GetByteValue();
> 	//const gdcm::ByteValue *bvY0 = deY0.GetByteValue();
> 	//const gdcm::ByteValue *bvX1 = deX1.GetByteValue();
> 	//const gdcm::ByteValue *bvY1 = deY1.GetByteValue();
>     	//std::cout << bvX0 << std::endl << bvY0 << std::endl << bvX1 <<
> std::endl << bvY1 << std::endl;    
> 
> 	gdcm::Attribute<0x0018,0x6018> atX0;
> 	gdcm::Attribute<0x0018,0x601a> atY0;
> 	gdcm::Attribute<0x0018,0x601c> atX1;
> 	gdcm::Attribute<0x0018,0x601e> atY1;
>     	atX0.SetFromDataElement( deX0 );
> 	atY0.SetFromDataElement( deY0 );
> 	atX1.SetFromDataElement( deX1 );
> 	atY1.SetFromDataElement( deY1 );
> 	const uint32_t* X0 = atX0.GetValues();
> 	const uint32_t* Y0 = atY0.GetValues();
> 	const uint32_t* X1 = atX1.GetValues();
> 	const uint32_t* Y1 = atY1.GetValues();
> 	//std::cout << X0 << std::endl << Y0 << std::endl << X1 << std::endl <<
> Y1 << std::endl;
> 
> 	X_min = static_cast<unsigned int>(X0[0]);
> 	Y_min = static_cast<unsigned int>(Y0[0]);
> 	X_max = static_cast<unsigned int>(X1[0]);
> 	Y_max = static_cast<unsigned int>(Y1[0]);
> 
> 	std::cout << "X_min = " << X_min << std::endl;	
> 	std::cout << "Y_min = " << Y_min << std::endl;
> 	std::cout << "X_max = " << X_max << std::endl;
> 	std::cout << "Y_max = " << Y_max << std::endl;
> 
>         return true;
> }
> 
> 
> 

-- 
GMX.at - Österreichs FreeMail-Dienst mit über 2 Mio Mitgliedern
E-Mail, SMS & mehr! Kostenlos: http://portal.gmx.net/de/go/atfreemail

-- 
GMX.at - Österreichs FreeMail-Dienst mit über 2 Mio Mitgliedern
E-Mail, SMS & mehr! Kostenlos: http://portal.gmx.net/de/go/atfreemail


More information about the Insight-users mailing list