[Insight-users] Simple image program help

RJ Stevens rj.stevens at gmail.com
Mon Jan 10 16:16:58 EST 2005


Hi again, I am building a simple program to open an image based off
the example Image2.
I have included all the information this time, namely the program, the
CMakeLists.txt, and the error messages.

I am running SUSE linux 9.2 with Itk version 1.8. 
Thanks for any input.

Richard Stevens


Simple program based off of image2 example:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include <iostream>

int main(int , char ** argv)
{

//define variables for image def
typedef unsigned char		PixelType;
const unsigned int		Dimension = 2;

//set pixel type and dimension
typedef itk::Image< PixelType, Dimension > ImageType;

//instantiate the image reader class
typedef itk::ImageFileReader< ImageType > ReaderType;

//use reader class to create a reader object
ReaderType::Pointer reader = ReaderType::New();

//give reader oject filename of image to be loaded into memory
const char * filename = argv[1];
reader->SetFileName(filename);

//reader object is a pipeline source object and responds to pipeline
//update requests. Since this pipeline is of length 1, we must send the
//update reqest manually
reader->Update();

//put the image into an image object
ImageType::Pointer image = reader -> GetOutput();


return 0;
}

The CMakeLists.txt file this program that is mostly borrowed from
InsightApplications after my first attempt did not work:

CMAKE_MINIMUM_REQUIRED(VERSION 1.6)
PROJECT(Segment1)
INCLUDE_REGULAR_EXPRESSION("^.*$")

# Tell CMake's FIND_PACKAGE command where to look for our Find<pkg>
# modules.
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${InsightApplications_SOURCE_DIR})

IF(NOT WIN32)
  OPTION(BUILD_SHARED_LIBS "Build Insight-Applications with shared
libraries." OFF)
ENDIF(NOT WIN32)

# Don't build anything unless the version of CMake is high enough.
# The matching ELSE/ENDIF should be the last lines in the file.
IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)


FIND_PACKAGE(ITK)
IF(ITK_FOUND)
	INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
	MESSAGE(FATAL_ERROR
		"ITK not found. Set ITK_DIR.")
ENDIF(ITK_FOUND)

#added from CMakeLists.txt from InsightApplications
LINK_LIBRARIES (
ITKAlgorithms
ITKCommon
ITKBasicFilters 
)


ADD_EXECUTABLE( Segment1 Segment1.cxx)


# If the version of CMake was too old, complain and build nothing.
# These should be the last lines in this file.
ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)
  MESSAGE(SEND_ERROR
          "This version of CMake is too old to build InsightApplications.  "
          "Please upgrade to CMake 1.6.")
ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)


Errors Generated:

:/VTKITK/work/picture2 # make
Building dependencies. cmake.depends...
Building object file Segment1.o...
Building executable ./Segment1...
Segment1.o(.gnu.linkonce.t._ZN3itk15ImageFileReaderINS_5ImageIhLj2EEENS_25DefaultConvertPixelTraitsIhEEE25GenerateOutputInformationEv+0x28b):
In function `itk::ImageFileReader<itk::Image<unsigned char,
(unsigned)2>, itk::DefaultConvertPixelTraits<unsigned char>
>::GenerateOutputInformation()':
: undefined reference to `itk::ImageIOFactory::CreateImageIO(char
const*, itk::ImageIOFactory::FileModeType)'
Segment1.o(.gnu.linkonce.t._ZN3itk15ImageFileReaderINS_5ImageIhLj2EEENS_25DefaultConvertPixelTraitsIhEEE12GenerateDataEv+0x3ad):
In function `itk::ImageFileReader<itk::Image<unsigned char,
(unsigned)2>, itk::DefaultConvertPixelTraits<unsigned char>
>::GenerateData()':
: undefined reference to `itk::operator<<(std::basic_ostream<char,
std::char_traits<char> >&, itk::ImageIORegion const&)'
Segment1.o(.gnu.linkonce.t._ZN3itk15ImageFileReaderINS_5ImageIhLj2EEENS_25DefaultConvertPixelTraitsIhEEE12GenerateDataEv+0x932):
In function `itk::ImageFileReader<itk::Image<unsigned char,
(unsigned)2>, itk::DefaultConvertPixelTraits<unsigned char>
>::GenerateData()':
: undefined reference to `itk::ImageIOBase::GetImageSizeInBytes() const'
Segment1.o(.gnu.linkonce.t._ZN3itk15ImageFileReaderINS_5ImageIhLj2EEENS_25DefaultConvertPixelTraitsIhEEE15DoConvertBufferEPvm+0x66b):
In function `itk::ImageFileReader<itk::Image<unsigned char,
(unsigned)2>, itk::DefaultConvertPixelTraits<unsigned char>
>::DoConvertBuffer(void*, unsigned long)':
: undefined reference to
`itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)
const'
Segment1.o(.gnu.linkonce.t._ZN3itk13ImageIORegionC1Ej+0x1a): In
function `itk::ImageIORegion::ImageIORegion[in-charge](unsigned)':
: undefined reference to `vtable for itk::ImageIORegion'
Segment1.o(.gnu.linkonce.t._ZN3itk13ImageIORegionD1Ev+0xc): In
function `itk::ImageIORegion::~ImageIORegion [in-charge]()':
: undefined reference to `vtable for itk::ImageIORegion'
Segment1.o(.gnu.linkonce.t._ZN3itk13ImageIORegionC1ERKS0_+0x1a): In
function `itk::ImageIORegion::ImageIORegion[in-charge](itk::ImageIORegion
const&)':
: undefined reference to `vtable for itk::ImageIORegion'
collect2: ld returned 1 exit status
make[1]: *** [Segment1] Error 1
make: *** [default_target] Error 2


More information about the Insight-users mailing list