[Insight-users] compilation error on linux

Reinhard Hameeteman reinhard.afstuderen at gmail.com
Tue Oct 11 06:36:07 EDT 2005


Hi,

I am making an application to do deformable liver registrations. The
program I made so far works fine on a windows machine using the VC++
6.0 compiler. But now I want to move the program to a linux machine
and refuses to compile using
gcc 3.3.5 and make 3.8. The error is in a templated class which I
wrote. In my program I perform a rigid registration which final
parameters (3 translation parameters) I use to initialize the non
rigid registration. My nonrigidregistration class has a member
m_RigidTransformParameters which stores these parameters.
The member function SetRigidTransform causes the following compilation error:

/home/rhameeteman/source/test2/NonRigidRegistration.txx:105: error: prototype
   for `void NonRigidRegistration<TFixedImage, TMovingImage,
   TOutputImage>::SetRigidTransform(typename
   itk::BSplineDeformableTransform<double, NonRigidRegistration<TFixedImage,
   TMovingImage, TOutputImage>::ImageDimension, 3>::ParametersType)' does not
   match any in class `NonRigidRegistration<TFixedImage, TMovingImage,
   TOutputImage>'
/home/rhameeteman/source/test2/NonRigidRegistration.h:209: error: candidate is:
   void NonRigidRegistration<TFixedImage, TMovingImage,
   TOutputImage>::SetRigidTransform(typename
   itk::BSplineDeformableTransform<double, NonRigidRegistration<TFixedImage,
   TMovingImage, TOutputImage>::ImageDimension, 3>::ParametersType)
/home/rhameeteman/source/test2/NonRigidRegistration.txx:105: error: template
   definition of non-template `void NonRigidRegistration<TFixedImage,
   TMovingImage, TOutputImage>::SetRigidTransform(typename
   itk::BSplineDeformableTransform<double, NonRigidRegistration<TFixedImage,
   TMovingImage, TOutputImage>::ImageDimension, 3>::ParametersType)'
make[1]: *** [LivReg.o] Error 1
make: *** [default_target] Error 2

What puzzles me is that the suggested candidate is exactly the same as
the one causing the error.
I included a sort of minimal example to demonstrate the problem. It
compiles fine in VC, but won't build on Linux.
I use itk 2.2.0

Reinhard
-------------- next part --------------
PROJECT(LivReg)

FIND_PACKAGE(ITK)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
  MESSAGE(FATAL_ERROR "ITK niet gevonden")
ENDIF(ITK_FOUND)


ADD_EXECUTABLE(
LivReg                          LivReg.cpp 
NonRigidRegistration.txx        NonRigidRegistration.h)


TARGET_LINK_LIBRARIES(LivReg ITKNumerics ITKIO ITKAlgorithms ITKBasicFilters ITKStatistics)
-------------- next part --------------
#include <stdio.h>
#include "NonRigidRegistration.h"

int main(int argc, char * argv[])
{
  std::cout << "startup: Image Registration Application" << std::endl;
 
  char *parameterFile;

  if (argc < 2 )
  {
    std::cout << "No filename provided, trying LiverRegistration.txt" << std::endl;
    parameterFile = "LiverRegistration.txt";
  }
  else
  {
    parameterFile = argv[1];
  }

  const unsigned int ImageDimension = 3 ;
  typedef unsigned char PixelType;

  typedef itk::Image<PixelType, ImageDimension>			   InputImageType;
  typedef itk::Image<PixelType, ImageDimension>			   OutputImageType;

  typedef      NonRigidRegistration< InputImageType,
                                     InputImageType,
                                     OutputImageType >  NonRigidRegistrationType;

  NonRigidRegistrationType::Pointer  m_NonRigidRegistration;

  m_NonRigidRegistration = NonRigidRegistrationType::New();


  return 0;
}

-------------- next part --------------
#ifndef _NONRIGIDREGISTRATION_H_
#define _NONRIGIDREGISTRATION_H_

#include "itkBSplineDeformableTransform.h"
#include "itkImageToImageFilter.h"



template <typename TFixedImage, typename TMovingImage, typename TOutputImage>
class NonRigidRegistration : public itk::ImageToImageFilter<TMovingImage, TOutputImage>
{
public:

  // Standard class typedefs. 
  typedef NonRigidRegistration  Self;
  typedef itk::ImageToImageFilter<TMovingImage, TOutputImage>  Superclass;
  typedef itk::SmartPointer<Self>   Pointer;
  typedef itk::SmartPointer<const Self>  ConstPointer;

  // Method for creation through the object factory.
  itkNewMacro(Self);
  
  // Run-time type information (and related methods).
  itkTypeMacro(NonRigidRegistrationMethod, ImageToImageFilter);

  // ImageDimension enumeration 
  itkStaticConstMacro(ImageDimension, unsigned int, TFixedImage::ImageDimension);

  // Image Types. 
  typedef          TFixedImage                    FixedImageType;
  typedef typename FixedImageType::ConstPointer   FixedImagePointer;
  
  typedef          TMovingImage                   MovingImageType;
  typedef typename MovingImageType::ConstPointer  MovingImagePointer;

  typedef          TOutputImage                   OutputImageType;
  typedef typename OutputImageType::Pointer       OutputImagePointer;


  typedef itk::BSplineDeformableTransform
               < double, 
                 ImageDimension, 3 >    TransformType;

  typedef typename TransformType::ParametersType	ParametersType;

  // Initialize the transform with rigid parameters
  void SetRigidTransform( ParametersType );
  //void SetRigidTransform( void * );
  
  // Get the final transformation parameters of the registration
  const ParametersType GetFinalTransformParameters( void );

  // Get the transform
  const TransformType * GetTransform( void );

  ParametersType                        m_LastTransformParameters;
  ParametersType                        m_RigidTransformParameters;
  typename TransformType::Pointer		    m_NonRigidTransform;
  
protected:
  NonRigidRegistration();
  virtual ~NonRigidRegistration() {};
  void GenerateData(void );

private:

  FixedImagePointer  m_FixedPtr;
  MovingImagePointer m_MovingPtr;
  
  void InitializeTransform();
};



#ifndef ITK_MANUAL_INSTANTIATION
#include "NonRigidRegistration.txx"
#endif

#endif //_NONRIGIDREGISTRATION_H_
-------------- next part --------------
#include "NonRigidRegistration.h"

template <typename Type>
inline Type max(Type const& a, Type const& b) { return b < a ? a : b; }



template < typename TFixedImage, typename TMovingImage, typename TOutputImage >
NonRigidRegistration< TFixedImage, TMovingImage, TOutputImage  >
::NonRigidRegistration()
{
  this->SetNumberOfRequiredInputs( 2 );
  m_NonRigidTransform      = TransformType::New();
  
}



template < typename TFixedImage, typename TMovingImage, typename TOutputImage >
void
NonRigidRegistration< TFixedImage, TMovingImage, TOutputImage  >
::SetRigidTransform( ParametersType rigidParameters)
//::SetRigidTransform( void * rigidParameters)
{
  m_RigidTransformParameters = rigidParameters; //reinterpret_cast<ParametersType *>(rigidParameters);
}



template < typename TFixedImage, typename TMovingImage, typename TOutputImage >
void
NonRigidRegistration< TFixedImage, TMovingImage, TOutputImage  >
::InitializeTransform()
{
  typedef typename TransformType::RegionType TransformRegionType;

  TransformRegionType                             transformGridRegion;
	typename TransformRegionType::SizeType          gridBorderSize;
	typename TransformRegionType::SizeType          totalGridSize;
	typename MovingImageType::RegionType::SizeType  gridSizeOnImage;
	
  typename FixedImageType:: SizeType fixedImageSize  = m_FixedPtr-> GetLargestPossibleRegion().GetSize();
  typename MovingImageType::SizeType movingImageSize = m_MovingPtr->GetLargestPossibleRegion().GetSize();

  // Set the number of spline nodes.
  // Each spline needs 3 nodes outside the image: 1 on lower and 2 on the upper border.
  // The number of splines are set in proportion to the image size.
  // At least 2 nodes are needed in each dimension.
  gridBorderSize.Fill(3); 
  unsigned int numberOfNodesPerDimension = 5; //Number of nodes in the image
  for (unsigned int ii = 0; ii < ImageDimension; ii++)
  {
    gridSizeOnImage[ii] = max( (int)( numberOfNodesPerDimension * 
                                      movingImageSize[ii] / 
                                      movingImageSize[0]  ), 2);
  }
   

  totalGridSize = gridSizeOnImage + gridBorderSize;
 	transformGridRegion.SetSize( totalGridSize );

 	typename TransformType::SpacingType spacing = m_FixedPtr->GetSpacing();
 	typename TransformType::OriginType  origin  = m_FixedPtr->GetOrigin();
	

	for(unsigned int r=0; r<ImageDimension; r++) 
  {
	    spacing[r] *= floor( static_cast<double>( fixedImageSize[r]  - 1) / 
                           static_cast<double>( gridSizeOnImage[r] - 1) );
    	origin[r]  -=  spacing[r]; 
  }

	m_NonRigidTransform->SetGridRegion(  transformGridRegion );
	m_NonRigidTransform->SetGridSpacing( spacing             );
	m_NonRigidTransform->SetGridOrigin(  origin              );

  typedef typename TransformType::ParametersType TransformParametersType;
  const unsigned int numberOfParameters = m_NonRigidTransform->GetNumberOfParameters();
  TransformParametersType initialParameters( numberOfParameters );
  initialParameters.fill(0.0);

  // Parameters are stored in array as x1x2x3x4... y1y2y3y4... z1z2z3z4
  const unsigned int numberOfNodes = m_NonRigidTransform->GetNumberOfParametersPerDimension();
  for (unsigned int ii=0; ii < numberOfNodes; ii++ )
  {
    for (unsigned int jj=0; jj < ImageDimension; jj++)
    {
      initialParameters[ii+jj*numberOfNodes]   = m_RigidTransformParameters[jj];
    }
  }
  
  m_NonRigidTransform->SetParametersByValue( initialParameters );
  return;
}



template < typename TFixedImage, typename TMovingImage, typename TOutputImage >
void
NonRigidRegistration< TFixedImage, TMovingImage, TOutputImage  >
::GenerateData( void ) 
{
  // Initialize NonRigid Transformation
	this->InitializeTransform();

	return;
}




More information about the Insight-users mailing list