[Insight-users] link error GradientDescentOptimizer
Yannick Pannier
pannier at lms.polytechnique.fr
Thu Jun 28 03:18:30 EDT 2007
Hi,
You're right, I forgot some dynamic library linkages.
I don't use CMake at the moment, so it is difficult to know which
library to link with.
Thanks,
Yannick
Tomáš Kazmar a écrit :
> Hi,
>
> my guess would be you do not link with correct/all libraries, do you?
>
> If you use cmake, check the CMakeLists.txt (TARGET_LINK_LIBRARIES).
>
>
> Tomas
>
>
> # Hi everybody,
> # # I'm trying to use ITK with my application to compute affine #
> transformation parameters from 2 CT images.
> # I 've imported 2 3D images from my application and then try to #
> registrate them witk ITK, I 've choosen these parameters for the #
> registration :
> # affinetransform, bsplineinterpolator,gradientdescentoptimizer and #
> NormalizedCorrelationImageToImageMetric.
> # # Compilation of objects with g++ is ok, but there is an error
> during the # link operation.
> # Here is the message :
> # essai_ITK_lib.o: In function #
> `itk::ObjectFactory<itk::GradientDescentOptimizer>::Create()':
> # /home/pannier/src/Insight/Code/Common/itkObjectFactory.h:52:
> undefined # reference to `typeinfo for itk::GradientDescentOptimizer'
> # /home/pannier/src/Insight/Code/Common/itkObjectFactory.h:53:
> undefined # reference to `typeinfo for itk::GradientDescentOptimizer'
> # essai_ITK_lib.o: In function `CostFunction':
> # /home/pannier/src/Insight/Code/Numerics/itkCostFunction.h:61:
> undefined # reference to `vtable for itk::CostFunction'
> # essai_ITK_lib.o: In function `~CostFunction':
> # /home/pannier/src/Insight/Code/Numerics/itkCostFunction.h:62:
> undefined # reference to `vtable for itk::CostFunction'
> # essai_ITK_lib.o: In function #
> `itk::ImageToImageMetric<itk::Image<unsigned char, 3u>, #
> itk::Image<unsigned char, 3u> >::PrintSelf(std::basic_ostream<char, #
> std::char_traits<char> >&, itk::Indent) const':
> #
> /home/pannier/src/Insight/Code/Algorithms/itkImageToImageMetric.txx:168:
> # undefined reference to #
> `itk::CostFunction::PrintSelf(std::basic_ostream<char, #
> std::char_traits<char> >&, itk::Indent) const'
> # essai_ITK_lib.o: In function `itk::GradientDescentOptimizer::New()':
> #
> /home/pannier/src/Insight/Code/Numerics/itkGradientDescentOptimizer.h:59:
> # undefined reference to #
> `itk::GradientDescentOptimizer::GradientDescentOptimizer()'
> #
> essai_ITK_lib.o:(.gnu.linkonce.r._ZTIN3itk24SingleValuedCostFunctionE+0x8):
> # undefined reference to `typeinfo for itk::CostFunction'
> #
> essai_ITK_lib.o:(.gnu.linkonce.r._ZTVN3itk24SingleValuedCostFunctionE+0x2c):
> # undefined reference to #
> `itk::CostFunction::PrintSelf(std::basic_ostream<char, #
> std::char_traits<char> >&, itk::Indent) const'
> # collect2: ld a retourné 1 code d'état d'exécution
> # # Here is my code (essai_ITK_lib.cpp) :
> # extern "C"
> # {
> # VFloat ITK_registrate(VImage ini_ima, VImage ima, VLong
> coresizex, # VLong coresizey, VLong coresizez, double xini, double
> yini, double zini, # double xgro, double ygro, double zgro, double *
> x, double * y, double * z)
> # {
> # typedef unsigned char PixelType;
> # const unsigned int Dimension = 3;
> # typedef itk::Image< PixelType, Dimension > ImageType;
> # typedef itk::ImportImageFilter< PixelType, Dimension > #
> ImportFilterType;
> # ImportFilterType::Pointer importFilterIni = #
> ImportFilterType::New(); # ImportFilterType::Pointer
> importFilterDefo = # ImportFilterType::New(); #
> ImportFilterType::SizeType size;
> # size[0] = coresizex; // size along X
> # size[1] = coresizey; // size along Y
> # size[2] = coresizez; // size along Z
> # const unsigned int numberOfPixels = size[0] * size[1] * size[2];
> # PixelType * image0;
> # PixelType * image1;
> # image0 = & VPixel(ini_ima, 0, 0, 0,PixelType);
> # image1 = & VPixel(ima, 0, 0, 0,PixelType);
> # ImportFilterType::IndexType start;
> # start.Fill( 0 );
> # ImportFilterType::RegionType region;
> # region.SetIndex( start );
> # region.SetSize( size );
> # importFilterIni->SetRegion( region );
> # importFilterDefo->SetRegion( region );
> # double origin[ Dimension ];
> # origin[0] = 0.0; // X coordinate
> # origin[1] = 0.0; // Y coordinate
> # origin[2] = 0.0; // Z coordinate
> # importFilterIni->SetOrigin( origin );
> # importFilterDefo->SetOrigin( origin );
> # double spacing[ Dimension ];
> # spacing[0] = 1.0; // along X direction
> # spacing[1] = 1.0; // along Y direction
> # spacing[2] = 1.0; // along Z direction
> # importFilterIni->SetSpacing( spacing );
> # importFilterDefo->SetSpacing( spacing );
> # printf("coucou 94");
> # const bool importImageFilterWillOwnTheBuffer = false;
> # importFilterIni->SetImportPointer( image0, numberOfPixels,
> # importImageFilterWillOwnTheBuffer );
> # importFilterDefo->SetImportPointer( image1, numberOfPixels,
> # importImageFilterWillOwnTheBuffer );
> # typedef itk::AffineTransform<double, Dimension> TransformType;
> # typedef itk::GradientDescentOptimizer OptimizerType;
> # typedef itk::NormalizedCorrelationImageToImageMetric< ImageType,
> # ImageType > MetricType;
> # typedef itk::ImageRegistrationMethod<ImageType,ImageType> #
> RegistrationType;
> # typedef itk::BSplineInterpolateImageFunction<ImageType,double> #
> InterpolatorType; # MetricType::Pointer
> metric = MetricType::New();
> # TransformType::Pointer transform = TransformType::New();
> # OptimizerType::Pointer optimizer = OptimizerType::New();
> # InterpolatorType::Pointer interpolator =
> InterpolatorType::New();
> # RegistrationType::Pointer registration =
> RegistrationType::New();
> # registration->SetMetric( metric );
> # registration->SetOptimizer( optimizer );
> # registration->SetTransform( transform );
> # registration->SetInterpolator( interpolator );
> # registration->SetFixedImage( importFilterIni->GetOutput() );
> # registration->SetMovingImage(
> importFilterDefo->GetOutput() );
> # interpolator->SetSplineOrder(3);
> # #
> registration->SetFixedImageRegion(importFilterIni->GetOutput()->GetBufferedRegion());
>
> # typedef RegistrationType::ParametersType ParametersType;
> # ParametersType initialParameters( #
> transform->GetNumberOfParameters() );
> # initialParameters.Fill( 0.0 );
> # initialParameters[0] = 1.0;
> # initialParameters[4] = 1.0;
> # initialParameters[8] = 1.0;
> # registration->SetInitialTransformParameters(initialParameters);
> # optimizer->SetLearningRate( 15.0 );
> # optimizer->SetNumberOfIterations( 100 );
> # try
> # {
> # registration->Update();
> # }
> # catch( itk::ExceptionObject & err )
> # {
> # std::cerr << "ExceptionObject Caught !" << std::endl;
> # std::cerr << err << std::endl;
> # return -1;
> # }
> # # ParametersType finalParameters = #
> registration->GetLastTransformParameters();
> # std::cout << " parameters :" << finalParameters[0] << #
> finalParameters[1] << finalParameters[2] << finalParameters[3] << #
> finalParameters[4] << finalParameters[5]<< std::endl;
> # std::cout << finalParameters[6] << finalParameters[7] << #
> finalParameters[8] << finalParameters[9] << finalParameters[10] << #
> finalParameters[11] << std::endl;
> # const unsigned int numberOfIterations = #
> optimizer->GetCurrentIteration();
> # std::cout<<"number of iterations"<<numberOfIterations<<std::endl;
> # # return(0);
> # }
> # # }
> # # Could anybody help me ?
> # # Thanks,
> # # Yannick
> # _______________________________________________
> # Insight-users mailing list
> # Insight-users at itk.org
> # http://www.itk.org/mailman/listinfo/insight-users
> # # #
>
More information about the Insight-users
mailing list