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

Lars Friedrich Lars lars-friedrich at gmx.net
Mon Mar 22 09:33:47 EDT 2010


Edoardo,

did you compile ITK with BUILD_EXAMPLES=ON?
If yes, could you try to run some of the examples and look whether or not they throw the same segfault?
You could try DicomImageReadWrite.cxx or DicomSeriesReadPrintTags.cxx or so on.

lars


-------- Original-Nachricht --------
> Datum: Mon, 22 Mar 2010 12:17:11 +0100
> Von: edoardo.belletti at alice.it
> An: "Lars Friedrich Lars" <lars-friedrich at gmx.net>
> Betreff: R: [Insight-users] Fwd: Re:  Problem ITK and GDCM in the same script

> Thank you very much for your interest
> My ITK_USE_SYSTEM_GDCM is ON and my GDCM_DIR =  /usr/local/lib/gdcm-2.0 
> (I have also tried to change it with /usr/local/gdcm/bin that is the
> directory where I bilt gdcm but with this directory the output of the command make
> return me a lot of error).
> When I use a CMakeLists.txt with only the things that you told me the
> errors are:
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:12:24:
> error: gdcmReader.h: Nessun file o directory
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:13:30:
> error: gdcmMediaStorage.h: Nessun file o directory
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:14:27:
> error: gdcmAttribute.h: Nessun file o directory
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:15:35:
> error: gdcmApplicationEntity.h: Nessun file o directory
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:16:25:
> error: gdcmElement.h: Nessun file o directory
> /home/edoardo/ITK/Tesi/AC_con_dicom/src/ReadAndDumpDICOMDIR.cxx:17:33:
> error: gdcmSequenceOfItems.h: Nessun file o directory
> (...)
> 
> Instead to put the pure GDCM-capabilities into a sub-library that
> explicitly links against GDCM2.0, and link against this sub-library in my main
> code; for this I have no idea how I can do it
> 
> This is the code that run, but when I remove the following comment:
> /*	ImageIOType::Pointer dicomIO = ImageIOType::New();
> 	ReaderType::Pointer reader = ReaderType::New();
> 	reader->SetFileName( argv[1] );
> 	reader->SetImageIO( dicomIO );
> 	reader->Update();
> */ 
> the outputi is always: Segmentation fault
> 
> Best regards,
> Edoardo Belletti
> 
> 
> // 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"
> 
> // 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;
> typedef itk::Image< float, Dimension > OutputImageType;
> typedef itk::SobelEdgeDetectionImageFilter< OutputImageType,
> OutputImageType > SobelFilterType;
> typedef itk::RegionOfInterestImageFilter< ImageType, ImageType >
> RegionFilterType;
> typedef itk::CastImageFilter< ImageType, OutputImageType>
> CastToRealFilterType;
> typedef itk::RescaleIntensityImageFilter< OutputImageType, ImageType >
> RescaleFilter;
> 
> 
> 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 < 2 )
> 	{
> 		std::cerr << "Usage: " << std::endl;
> 		std::cerr << argv[0] << " inputImageFile  outputImageFile " <<
> std::endl;
> 		return EXIT_FAILURE;
> 	}
> 
> 	
> /*	ImageIOType::Pointer dicomIO = ImageIOType::New();
> 	ReaderType::Pointer reader = ReaderType::New();
> 	reader->SetFileName( argv[1] );
> 	reader->SetImageIO( dicomIO );
> 	reader->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 << "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;
> 	}
> 		
> 
> 	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.GetValueAsSQ();
> 	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;
> }
> 
> 
> -----Messaggio originale-----
> Da: Lars Friedrich Lars [mailto:lars-friedrich at gmx.net]
> Inviato: lun 22/03/2010 9.26
> A: edoardo.belletti at alice.it
> Cc: insight-users at itk.org
> Oggetto: Re: R: [Insight-users] Fwd: Re:  Problem ITK and GDCM in the same
> script
>  
> Eduardo,
> 
> I just had a look at a small project where I use ITK3.16 and GDCM2.0
> together. It is compilable, linkable and runnable on both Linux (GCC) and
> Windows (MinGW). I will try to explain what I did:
> 
> I built ITK3.16 with ITK_USE_SYSTEM_GDCM=ON and
> GDCM_DIR=<dir-of-externally-built-gdcm2.0>.
> In the project's CMakeLists.txt I solely added:
> FIND_PACKAGE(ITK)
> IF(NOT ITK_DIR)
>   MESSAGE(FATAL_ERROR "Please set ITK_DIR.")
> ENDIF(NOT ITK_DIR) 
> INCLUDE(${ITK_USE_FILE})
> 
> For my project this is obviously enough.
> 
> In the main source code I use some gdcm-headers:
> #include <gdcmReader.h>
> #include <gdcmWriter.h>
> #include <gdcmFile.h>
> #include <gdcmDataSet.h>
> #include <gdcmByteValue.h>
> GDCM-path is not in the system's PATH-variable.
> 
> Maybe you could try to put the pure GDCM-capabilities (the source that
> needs GDCM) into a sub-library that explicitly links against GDCM2.0. And then
> link against this sub-library in your main code that also uses ITK.
> 
> regards,
> 
> lars
> 
> 
> 
> 

-- 
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