[Insight-users] Namespace problem with custom ImageIO class

David Christen davidchristen at gmail.com
Thu Oct 18 10:51:39 EDT 2007


Hi all.

I wrote an ImageIO-class for a proprietary image file format (AIM).
(see  itkAIMImageIO.h below) For the last few days I was trying to add
the possibility of reading/writing a log about the processing done on
the image (ProcessingLog). However, if I call the Set- or
GetProcessingLog functions, I get a compiler error:

AIMReadWrite.cxx:59: error: 'class itk::AIMImageIO' has no member
named 'SetProcessingLog'

The idea is to get the log from the reader-object, eventually modify
it and finally pass it to the writer-object.

I've been trying many things and I found out, that I can't declare any
additional public functions or members. Well, I can, and I can even
find it in the (shared) library, but if I include it in an application
and try to call the method or variable, I get the error above.
If I don't call any of the added functions, the application compiles
smoothly and the executable does exactly as expected.

If I make the member variable m_ProcessingLog public, I still can't
access it from outside the class. ("... has no member named
'm_ProcessingLog' ")

The output of nm is:
[dch at neuron itkUtilities]$ nm -C libvtkmyITKUtility.so | grep AIMImageIO
<..>
00000000000f15fa W itk::AIMImageIO::SetProcessingLog(char const*)
00000000000f15cc W
itk::AIMImageIO::SetProcessingLog(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)
<..>
00000000000f15dc W itk::AIMImageIO::GetProcessingLog() const
<..>

So the macro was correctly expanded (I even tested it in a member
function of the class).

I strongly suspect a namespace problem, but I can't figure out what I
have to change.

Any help is very much appreciated,
David


/**========================================================================
itkAIMImageIO.h
=========================================================================*/
#ifndef __itkAIMImageIO_h
#define __itkAIMImageIO_h

#include "itkImageIOBase.h"

#include "aimpack.h"

namespace itk
{
/** \class AIMImageIO
 *
 * \brief ImageIO object for reading and writing AIM Files
 *
 */
class ITK_EXPORT AIMImageIO : public ImageIOBase
{
public:
  /** Standard class typedefs. */
  typedef AIMImageIO            Self;
  typedef ImageIOBase  Superclass;
  typedef SmartPointer<Self>  Pointer;
  typedef SmartPointer<const Self>  ConstPointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(AIMImageIO, ImageIOBase);

  /** Any other get/set options that should be public */

  itkGetStringMacro(ProcessingLog);
  itkSetStringMacro(ProcessingLog);

  /*-------- This part of the interface deals with reading data. -----*/

  /** Determine the file type. Returns true if this ImageIO can read the
   * file specified. */
  virtual bool CanReadFile(const char*);

  /** Set the spacing and diemention information for the set filename.*/
  virtual void ReadImageInformation();

  /** Reads the data from disk into the memory buffer provided. */
  virtual void Read(void* buffer);


  /*-------- This part of the interfaces deals with writing data. ----*/

  /** Determine the file type. Returns true if this ImageIO can read the
   * file specified. */
  virtual bool CanWriteFile(const char*);

  /** Writes the spacing and dimentions of the image.
   * Assumes SetFileName has been called with a valid file name. */
  virtual void WriteImageInformation();

  /** Writes the data to disk from the memory buffer provided. Make sure
   * that the IORegion has been set properly. */
  virtual void Write(const void* buffer);

protected:
  AIMImageIO();
  ~AIMImageIO();
  void PrintSelf(std::ostream& os, Indent indent) const;

  D3AnyImage030 * m_AIMimage;
  std::string m_ProcessingLog;

private:
  AIMImageIO(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

};

} // end namespace itk

#endif // __itkAIMImageIO_h


/**========================================================================
AIMReadWrite.cxx
=========================================================================*/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkAIMImageIO.h"

//#include "itkImage.h"


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

  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::AIMImageIO                    ImageIOType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  ImageIOType::Pointer aimIOwrite = ImageIOType::New();
  ImageIOType::Pointer aimIOread = ImageIOType::New();

  const char * inputFilename  = argv[1];
  const char * outputFilename = argv[2];

  reader->SetFileName( inputFilename  );
  writer->SetFileName( outputFilename );

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

  aimIOread->CanReadFile(inputFilename);

  reader->SetImageIO( aimIOread );
  writer->SetImageIO( aimIOwrite );

  try
    {
    reader->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
    }

  aimIOwrite->SetProcessingLog( aimIOread->GetProcessingLog() );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}


More information about the Insight-users mailing list