<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7655.8">
<TITLE>Problem ITK and GDCM in the same script</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi<BR>
I have a problem with configuring ITK with GDCM 2.0<BR>
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)<BR>
I don't know if it is a problem of CMakeLists and so I have put in this email also my CMakeLists.txt.<BR>
<BR>
Thank you very much<BR>
<BR>
Edoardo Belletti<BR>
<BR>
CMakeLists.txt:<BR>
<BR>
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)<BR>
<BR>
PROJECT(ImageIO)<BR>
<BR>
# Find ITK.<BR>
FIND_PACKAGE(ITK REQUIRED)<BR>
IF(ITK_FOUND)<BR>
INCLUDE(${ITK_USE_FILE})<BR>
ENDIF(ITK_FOUND)<BR>
<BR>
# Find GDCM<BR>
FIND_PACKAGE(GDCM)<BR>
IF(GDCM_FOUND)<BR>
INCLUDE(${GDCM_USE_FILE})<BR>
IF( "${GDCM_MAJOR_VERSION}" LESS 2.0 )<BR>
SET(MITK_GDCM_LIBRARIES gdcm)<BR>
ELSE( "${GDCM_MAJOR_VERSION}" LESS 2.0 )<BR>
SET(MITK_GDCM_LIBRARIES gdcmMSFF)<BR>
ENDIF( "${GDCM_MAJOR_VERSION}" LESS 2.0 )<BR>
ELSE(GDCM_FOUND)<BR>
MESSAGE(FATAL_ERROR "Must set GDCM_DIR for MITK_USE_SYSTEM_GDCM.")<BR>
ENDIF(GDCM_FOUND)<BR>
<BR>
<BR>
<BR>
ADD_EXECUTABLE(ReadAndDumpDICOMDIR ReadAndDumpDICOMDIR.cxx )<BR>
TARGET_LINK_LIBRARIES(ReadAndDumpDICOMDIR ITKCommon ITKIO gdcmMSFF)<BR>
<BR>
<BR>
//==========================================================<BR>
<BR>
<BR>
// Librerie ITK<BR>
#include "itkImage.h"<BR>
#include "itkImageFileReader.h"<BR>
#include "itkImageFileWriter.h"<BR>
#include "itkSobelEdgeDetectionImageFilter.h"<BR>
#include "itkCastImageFilter.h"<BR>
#include "itkRescaleIntensityImageFilter.h"<BR>
#include "itkGDCMImageIO.h"<BR>
#include "itkRegionOfInterestImageFilter.h"<BR>
// Librerie GDCM<BR>
#include "gdcmReader.h"<BR>
#include "gdcmMediaStorage.h"<BR>
#include "gdcmAttribute.h"<BR>
#include "gdcmApplicationEntity.h"<BR>
#include "gdcmElement.h"<BR>
#include "gdcmSequenceOfItems.h"<BR>
<BR>
bool Region ( char* nomefile, unsigned int X_min, unsigned int Y_min, unsigned int X_max, unsigned int Y_max );<BR>
<BR>
<BR>
int main(int argc, char* argv[] )<BR>
{<BR>
// Controllo del numero di argomenti introdotti da riga di comando<BR>
if( argc < 3 )<BR>
{<BR>
std::cerr << "Usage: " << std::endl;<BR>
std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;<BR>
return EXIT_FAILURE;<BR>
}<BR>
// Settaggio delle variabili in input<BR>
const char * InputImageFilename = argv[1];<BR>
const char * OutputImageFilename = argv[2];<BR>
<BR>
// Dichiarazione dei tipi<BR>
const unsigned int Dimension = 2;<BR>
typedef unsigned char PixelType;<BR>
typedef itk::Image< PixelType, Dimension > ImageType;<BR>
<BR>
typedef itk::ImageFileReader< ImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< ImageType > WriterType;<BR>
<BR>
typedef itk::GDCMImageIO ImageIOType;<BR>
ImageIOType::Pointer dicomIO = ImageIOType::New();<BR>
<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
reader->SetFileName( InputImageFilename );<BR>
reader->SetImageIO( dicomIO );<BR>
<BR>
WriterType::Pointer writer = WriterType::New();<BR>
writer->SetFileName( OutputImageFilename );<BR>
writer->SetInput( reader->GetOutput() );<BR>
writer->Update();<BR>
<BR>
unsigned int x_min = 1;<BR>
unsigned int y_min = 1;<BR>
unsigned int x_max = 1;<BR>
unsigned int y_max = 1;<BR>
<BR>
if( Region ( argv[1], x_min, y_min, x_max, y_max ) )<BR>
std::cout << "ok\n";<BR>
<BR>
else<BR>
{<BR>
std::cout << "no\n";<BR>
<BR>
}<BR>
<BR>
<BR>
}<BR>
<BR>
bool Region ( char* nomefile, unsigned int X_min, unsigned int Y_min, unsigned int X_max, unsigned int Y_max )<BR>
{<BR>
gdcm::Reader reader;<BR>
reader.SetFileName( nomefile );<BR>
if( !reader.Read() )<BR>
{<BR>
std::cerr << "Could not read: " << nomefile << std::endl;<BR>
return false;<BR>
}<BR>
<BR>
gdcm::File &file = reader.GetFile();<BR>
gdcm::DataSet &ds = file.GetDataSet();<BR>
<BR>
gdcm::Tag tsqur(0x0018,0x6011);<BR>
if( !ds.FindDataElement( tsqur ) )<BR>
{<BR>
return false;<BR>
}<BR>
<BR>
const gdcm::DataElement &squr= ds.GetDataElement( tsqur );<BR>
//std::cout << squr << std::endl;<BR>
const gdcm::SequenceOfItems *sqi = squr.GetSequenceOfItems();<BR>
if( !sqi || !sqi->GetNumberOfItems() )<BR>
{<BR>
return false;<BR>
}<BR>
//std::cout << sqi << std::endl;<BR>
<BR>
const gdcm::Item & item = sqi->GetItem(1);<BR>
//std::cout << item << std::endl;<BR>
const gdcm::DataSet& nestedds = item.GetNestedDataSet();<BR>
//std::cout << nestedds << std::endl; <BR>
<BR>
gdcm::Tag tX0(0x0018,0x6018);<BR>
gdcm::Tag tY0(0x0018,0x601a);<BR>
gdcm::Tag tX1(0x0018,0x601c);<BR>
gdcm::Tag tY1(0x0018,0x601e);<BR>
<BR>
if( (!nestedds.FindDataElement( tX0 ))||(!nestedds.FindDataElement( tY0 ))||(!nestedds.FindDataElement( tX1 ))||(!nestedds.FindDataElement( tY1 )) )<BR>
{<BR>
return false;<BR>
}<BR>
<BR>
const gdcm::DataElement& deX0 = nestedds.GetDataElement( tX0 );<BR>
const gdcm::DataElement& deY0 = nestedds.GetDataElement( tY0 );<BR>
const gdcm::DataElement& deX1 = nestedds.GetDataElement( tX1 );<BR>
const gdcm::DataElement& deY1 = nestedds.GetDataElement( tY1 );<BR>
//std::cout << deX0 << std::endl << deY0 << std::endl << << deX1 << std::endl << deY1 << std::endl;<BR>
<BR>
//const gdcm::ByteValue *bvX0 = deX0.GetByteValue();<BR>
//const gdcm::ByteValue *bvY0 = deY0.GetByteValue();<BR>
//const gdcm::ByteValue *bvX1 = deX1.GetByteValue();<BR>
//const gdcm::ByteValue *bvY1 = deY1.GetByteValue();<BR>
//std::cout << bvX0 << std::endl << bvY0 << std::endl << bvX1 << std::endl << bvY1 << std::endl; <BR>
<BR>
gdcm::Attribute<0x0018,0x6018> atX0;<BR>
gdcm::Attribute<0x0018,0x601a> atY0;<BR>
gdcm::Attribute<0x0018,0x601c> atX1;<BR>
gdcm::Attribute<0x0018,0x601e> atY1;<BR>
atX0.SetFromDataElement( deX0 );<BR>
atY0.SetFromDataElement( deY0 );<BR>
atX1.SetFromDataElement( deX1 );<BR>
atY1.SetFromDataElement( deY1 );<BR>
const uint32_t* X0 = atX0.GetValues();<BR>
const uint32_t* Y0 = atY0.GetValues();<BR>
const uint32_t* X1 = atX1.GetValues();<BR>
const uint32_t* Y1 = atY1.GetValues();<BR>
//std::cout << X0 << std::endl << Y0 << std::endl << X1 << std::endl << Y1 << std::endl;<BR>
<BR>
X_min = static_cast<unsigned int>(X0[0]);<BR>
Y_min = static_cast<unsigned int>(Y0[0]);<BR>
X_max = static_cast<unsigned int>(X1[0]);<BR>
Y_max = static_cast<unsigned int>(Y1[0]);<BR>
<BR>
std::cout << "X_min = " << X_min << std::endl; <BR>
std::cout << "Y_min = " << Y_min << std::endl;<BR>
std::cout << "X_max = " << X_max << std::endl;<BR>
std::cout << "Y_max = " << Y_max << std::endl;<BR>
<BR>
return true;<BR>
}<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>