<!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 with ITK and GDCM in the same program</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi everyone, I have a problem: I have created this programthat use both ITK and GDCM libraries:<BR>
// GDCM Libraries<BR>
#include "gdcmReader.h"<BR>
(...)<BR>
// ITK Libraries<BR>
#include "itkImage.h"<BR>
(...)<BR>
// Standard Libraries<BR>
#include <string><BR>
(...)<BR>
// Type definitions<BR>
const unsigned int Dimension = 2;<BR>
typedef unsigned char PixelType;<BR>
typedef itk::Image< PixelType, Dimension > ImageType;<BR>
typedef itk::ImageFileReader< ImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< ImageType > WriterType;<BR>
typedef itk::GDCMImageIO ImageIOType;<BR>
typedef itk::Image< float, Dimension > OutputImageType;<BR>
typedef itk::SobelEdgeDetectionImageFilter< OutputImageType, OutputImageType > SobelFilterType;<BR>
typedef itk::RegionOfInterestImageFilter< ImageType, ImageType > RegionFilterType;<BR>
typedef itk::CastImageFilter< ImageType, OutputImageType> CastToRealFilterType;<BR>
typedef itk::RescaleIntensityImageFilter< OutputImageType, ImageType > RescaleFilter; <BR>
// Functions<BR>
template <typename TPrinter> bool Region(const std::string & filename, unsigned int* X_min, unsigned int* Y_min, unsigned int* X_max, unsigned int* Y_max );<BR>
int main (int argc, char *argv[])<BR>
{<BR>
if( argc < 2 )<BR>
{<BR>
std::cerr << "Usage: " << std::endl;<BR>
std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;<BR>
return EXIT_FAILURE;<BR>
}<BR>
std::string filename = argv[1];<BR>
<BR>
// ImageIOType::Pointer dicomIO = ImageIOType::New();<BR>
// ReaderType::Pointer reader = ReaderType::New();<BR>
// reader->SetFileName( argv[1] );<BR>
// reader->SetImageIO( dicomIO );<BR>
// reader->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>
if( Region<gdcm::Printer>( filename, &x_min, &y_min, &x_max, &y_max ) )<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>
else<BR>
{<BR>
std::cout << "no\n";<BR>
}<BR>
<BR>
//Return<BR>
return EXIT_SUCCESS;<BR>
}<BR>
<BR>
template <typename TPrinter> bool Region(const std::string & filename, unsigned int* X_min, unsigned int* Y_min, unsigned int* X_max, unsigned int* Y_max )<BR>
{<BR>
gdcm::Reader reader;<BR>
reader.SetFileName( filename.c_str() );<BR>
bool success = reader.Read();<BR>
if( !success )<BR>
{<BR>
std::cerr << "Failed to read: " << filename << std::endl;<BR>
return false;<BR>
}<BR>
<BR>
// Replace the stream buffer used by 'std::cout' with a suitable other<BR>
// stream buffer.<BR>
// Direct 'std::cout' to not print to the screen but also write to a file.<BR>
std::streambuf* cout_sbuf = std::cout.rdbuf(); // save original sbuf<BR>
std::ofstream fout( "header_dicom.txt" );<BR>
std::cout.rdbuf( fout.rdbuf() ); // redirect 'cout' to a 'fout' <BR>
<BR>
TPrinter printer;<BR>
printer.SetFile ( reader.GetFile() );<BR>
printer.Print( std::cout );<BR>
<BR>
// Restoring the original stream buffer is necessary because the stream<BR>
// buffer to which 'std::cout' was redirected is destroyed at the end of<BR>
// 'main()'.<BR>
std::cout.rdbuf( cout_sbuf ); // restore the original stream buffer<BR>
<BR>
std::string str, str_prec;<BR>
std::fstream f_input;<BR>
bool findX0 = false;<BR>
bool findX1 = false;<BR>
bool findY0 = false;<BR>
bool findY1 = false;<BR>
f_input.open ( "header_dicom.txt", std::ios::in );<BR>
if ( f_input.fail() )<BR>
{<BR>
std::cerr << "ERROR: can not open file!\n";<BR>
remove ( "header_dicom.txt" );<BR>
return false;<BR>
}<BR>
<BR>
while ( f_input >> str )<BR>
{<BR>
if ( str.compare("(0018,6018)") == 0 )<BR>
{<BR>
do {<BR>
str_prec = str;<BR>
f_input >> str;<BR>
} while ( str.compare("#") != 0 );<BR>
*X_min = atoi(str_prec.c_str());<BR>
findX0 = true;<BR>
//std::cout << *X_min << std::endl;<BR>
}<BR>
if ( str.compare("(0018,601a)") == 0 )<BR>
{<BR>
do {<BR>
str_prec = str;<BR>
f_input >> str;<BR>
} while ( str.compare("#") != 0 );<BR>
*Y_min = atoi(str_prec.c_str());<BR>
findY0 = true;<BR>
//std::cout << *Y_min << std::endl;<BR>
}<BR>
if ( str.compare("(0018,601c)") == 0 )<BR>
{<BR>
do {<BR>
str_prec = str;<BR>
f_input >> str;<BR>
} while ( str.compare("#") != 0 );<BR>
*X_max = atoi(str_prec.c_str());<BR>
findX1 = true;<BR>
//std::cout << *X_max << std::endl;<BR>
}<BR>
if ( str.compare("(0018,601e)") == 0 )<BR>
{<BR>
do {<BR>
str_prec = str;<BR>
f_input >> str;<BR>
} while ( str.compare("#") != 0 );<BR>
*Y_max = atoi(str_prec.c_str());<BR>
findY1 = true;<BR>
//std::cout << *Y_max << std::endl;<BR>
}<BR>
<BR>
//std::cout << str << std::endl;<BR>
}<BR>
<BR>
if ( ( !findX0 ) || ( !findY0 ) || ( !findX1 ) || ( !findY1 ) )<BR>
{<BR>
remove ( "header_dicom.txt" );<BR>
return false;<BR>
}<BR>
f_input.close();<BR>
<BR>
remove ( "header_dicom.txt" );<BR>
return true;<BR>
}<BR>
<BR>
when i run it without the comments on this lines (49-53):<BR>
ImageIOType::Pointer dicomIO = ImageIOType::New();<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
reader->SetFileName( argv[1] );<BR>
reader->SetImageIO( dicomIO );<BR>
reader->Update();<BR>
<BR>
the output is:<BR>
<BR>
edoardo@edoardo-laptop:~/ITK/Tesi/01_Autocrop/crop/bin$ make<BR>
Scanning dependencies of target cropping<BR>
[100%] Building CXX object CMakeFiles/cropping.dir/cropping.cxx.o<BR>
Linking CXX executable cropping<BR>
/usr/local/lib/InsightToolkit/libitkgdcm.a(gdcmGlobal.o): In function `gdcm::Global::Global()':<BR>
gdcmGlobal.cxx:(.text+0x0): multiple definition of `gdcm::Global::Global()'<BR>
/usr/local/lib/libgdcmDICT.a(gdcmGlobal.cxx.o):gdcmGlobal.cxx:(.text+0x0): first defined here<BR>
/usr/local/lib/InsightToolkit/libitkgdcm.a(gdcmGlobal.o): In function `gdcm::Global::Global()':<BR>
gdcmGlobal.cxx:(.text+0x300): multiple definition of `gdcm::Global::Global()'<BR>
/usr/local/lib/libgdcmDICT.a(gdcmGlobal.cxx.o):gdcmGlobal.cxx:(.text+0x80): first defined here<BR>
/usr/local/lib/InsightToolkit/libitkgdcm.a(gdcmGlobal.o): In function `gdcm::Global::~Global()':<BR>
gdcmGlobal.cxx:(.text+0x600): multiple definition of `gdcm::Global::~Global()'<BR>
/usr/local/lib/libgdcmDICT.a(gdcmGlobal.cxx.o):gdcmGlobal.cxx:(.text+0x100): first defined here<BR>
/usr/local/lib/InsightToolkit/libitkgdcm.a(gdcmGlobal.o): In function `gdcm::Global::~Global()':<BR>
gdcmGlobal.cxx:(.text+0x694): multiple definition of `gdcm::Global::~Global()'<BR>
/usr/local/lib/libgdcmDICT.a(gdcmGlobal.cxx.o):gdcmGlobal.cxx:(.text+0x14c): first defined here<BR>
collect2: ld returned 1 exit status<BR>
make[2]: *** [cropping] Errore 1<BR>
make[1]: *** [CMakeFiles/cropping.dir/all] Errore 2<BR>
make: *** [all] Errore 2<BR>
<BR>
instead of if these lines are commented I don't have any error; but my problem is that I want to use also ITK libraries into my project.<BR>
<BR>
my CMakeList.txt:<BR>
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)<BR>
<BR>
PROJECT(ImageIO)<BR>
<BR>
# Find ITK.<BR>
FIND_PACKAGE(ITK)<BR>
IF(NOT ITK_DIR)<BR>
MESSAGE(FATAL_ERROR "Please set ITK_DIR.")<BR>
ENDIF(NOT ITK_DIR)<BR>
INCLUDE(${ITK_USE_FILE})<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>
ADD_EXECUTABLE(cropping cropping.cxx )<BR>
TARGET_LINK_LIBRARIES(cropping gdcmMSFF ITKCommon ITKIO)<BR>
<BR>
and my ITK_USE_SYSTEM_GDCM is ON<BR>
and my GDCM_USE_ITK is OFF<BR>
<BR>
Please I need help, I very don't know which is the problem.<BR>
<BR>
Thank you very much for your interest<BR>
Best regards<BR>
Edoardo<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>