[Insight-users] Building ITK Program Using MINC2 IO Review Code

Geoff Topping g_topping at hotmail.com
Tue Apr 21 13:20:35 EDT 2009


Hi all.

I've enabled the MINC2 IO review code and rebuilt ITK.  Now I'd like to actually test this functionality, but am having trouble setting up the code and CMakeLists.txt necessary to do so.

I started with the basic ImageReadWrite example code, and modified it based on the results of various web searches.  A seemingly helpful example is here:

http://en.wikibooks.org/wiki/MINC/Tutorials/part2

The result is this code:

My current code:



*****************************************************



#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "itkImage.h"



#include "itkImageIOFactory.h"

#include "itkMINC2ImageIOFactory.h"

#include "itkMINC2ImageIO.h"





namespace {

    typedef float                               PixelType;

    const   unsigned int                        Dimension = 3;

    typedef itk::Image<PixelType, Dimension>    ImageType;



    typedef itk::ImageFileReader<ImageType>     ReaderType;

    typedef itk::ImageFileWriter<ImageType>     WriterType;



    typedef itk::MINC2ImageIO                   ImageIOType;

}



int main(int argc, char ** argv) {

    // Verify the number of parameters in the command line

    if ( argc < 3 ) {

        std::cerr << "Usage: " << std::endl;

        std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;

        return EXIT_FAILURE;

    }



    ReaderType::Pointer reader = ReaderType::New();

    ImageIOType::Pointer minc2ImageIO = ImageIOType::New();

    reader->SetImageIO( minc2ImageIO );

    const char* inputFilename  = argv[1];

    reader->SetFileName(inputFilename);





    WriterType::Pointer writer = WriterType::New();

    const char* outputFilename = argv[2];

    writer->SetFileName(outputFilename);





    writer->SetInput(reader->GetOutput());





    try { 

        writer->Update(); 

    } catch(itk::ExceptionObject & err) { 

        std::cerr << "ExceptionObject caught !" << std::endl; 

        std::cerr << err << std::endl; 

        return EXIT_FAILURE;

    } 



    return EXIT_SUCCESS;

}



******************************************************


I tried building this using my existing CMakeLists.txt that works for the same code without the minc-related parts...

******************************************************

# This is the root ITK CMakeLists file.
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND CMAKE_POLICY)
  CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND CMAKE_POLICY)


# This project is designed to be built outside the Insight source tree.
PROJECT(IOExamples)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ImageReadWrite ImageReadWrite.cxx )
TARGET_LINK_LIBRARIES(ImageReadWrite  ITKIO)

*******************************************************

After re-running ccmake and running make, I got errors about missing headers:

*******************************************************

/work/geoff/itk/iotest > make
[100%] Building CXX object CMakeFiles/ImageReadWrite.dir/ImageReadWrite.o
In file included from /work/geoff/itk/iotest/ImageReadWrite.cxx:8:
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:37:19: minc2.h: No such file or directory
In file included from /work/geoff/itk/iotest/ImageReadWrite.cxx:8:
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:100: error: `midimhandle_t' has not been declared
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:100: error: ISO C++ forbids declaration of `hdims' with no type
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:145: error: `mihandle_t' has not been declared
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:145: error: ISO C++ forbids declaration of `volume' with no type
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:149: error: `mihandle_t' has not been declared
/work/geoff/InsightToolkit-3.12.0/Code/Review/itkMINC2ImageIO.h:149: error: ISO C++ forbids declaration of `volume' with no type
make[2]: *** [CMakeFiles/ImageReadWrite.dir/ImageReadWrite.o] Error 1
make[1]: *** [CMakeFiles/ImageReadWrite.dir/all] Error 2
make: *** [all] Error 2
/work/geoff/itk/iotest > ccmake .

****************************************************

So I hit net searched a bit more, and found some promising looking alterations to the previous CMakeLists.txt, starting after the INCLUDE(${ITK_USE_FILE}) line:

****************************************************

FIND_PACKAGE(MINC2)
INCLUDE_DIRECTORIES(${MINC2_INCLUDE_PATH} ${HDF5_INCLUDE_PATH} ${NETCDF_INCLUDE_PATH})

ADD_EXECUTABLE(ImageReadWrite ImageReadWrite.cxx )
TARGET_LINK_LIBRARIES(ImageReadWrite ITKIO ITKIOMINC2 ${MINC2_LIB} ${HDF5_LIB} ${NETCDF_LIB})

*****************************************************

After doing this, when I run ccmake, I have an extra line where I need to enter the location of MINC2_DIR.  I give it the same directory as I used to build ITK after turning on MINC and related options, but after pressing c to configure, I get an error message:

CMake Error: MINC2_DIR is set to "/opt/minc2", which is not a directory containing MINC2Config.cmake

I've searched for a file by that name in my ITK binary or code directories.

I also tried without the FIND_PACKAGE(MINC2) line, but just got the same missing headers error during compiling.

I don't know how else to point ccmake to the location of the minc2 headers.  Can someone suggest what modifications need to be made to CMakeLists.txt so the compiler can find the necessary headers to build a program using the MINC ITK IO classes, or whatever else I need to be doing?  Is this documented somewhere I haven't found?

Thanks,
Geoff Topping




_________________________________________________________________
Reinvent how you stay in touch with the new Windows Live Messenger.
http://go.microsoft.com/?linkid=9650731
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090421/6fc9bae2/attachment-0001.htm>


More information about the Insight-users mailing list