[Insight-users] Re: make problem

Luis Ibanez luis.ibanez at kitware.com
Thu Oct 11 18:21:55 EDT 2007



Hi Burak,


The link problem was due to:


    1) You didn't rename the class name in the
        myLevelSetFunction.txx
       The base of the method it was still called
       "ShapeDetectionLevelSetFunction"


    2) You removed the #include of the .txx from
       the header (.h) file.  Without it, the
       compiler never gets to see the implementation
       of the CalculateSpeedImage() method.


Please find attached the fixed files.


    Regards,


        Luis


---------------------------------------------------------
Burak Özkalaycı wrote:
> Sorry for this inconvenience. Here the code in tar.gz.
> 
> Burak
> 
> On 10/10/07, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> 
>>Hi Burak,
>>
>>Thanks for the update.
>>
>>Could you please resend your code using a packaging
>>method other than RAR ?
>>
>>RAR is not an open standard:
>>
>>    http://en.wikipedia.org/wiki/RAR_(file_format)
>>
>>and there are no free tools for it on Debian linux.
>>
>>Please use zip or tar.gz.
>>
>>
>>   Thanks
>>
>>
>>      Luis
>>
>>
>>------------------------
>>Burak Özkalaycı wrote:
>>
>>>In fact there was no myLevelSetFunction header file since I just
>>>create a subclass derived from the SegmentationLevelSetFunction to
>>>implement the CalculateSpeedImage. But now I wrote it by copying from
>>>itkShapeDetectionLevelSetFunction.h.
>>>
>>>Now it compiles but can not link the obj files. The make error log is now :
>>>
>>>============================================================
>>>make
>>>Scanning dependencies of target myMain
>>>[100%] Building CXX object CMakeFiles/myMain.dir/myMain.o
>>>Linking CXX executable myMain
>>>CMakeFiles/myMain.dir/myMain.o:(.rodata._ZTVN3itk18myLevelSetFunctionINS_5ImageIfLj3EEES2_EE[vtable
>>>for itk::myLevelSetFunction<itk::Image<float, 3u>, itk::Image<float,
>>>3u> >]+0x118): undefined reference to
>>>`itk::myLevelSetFunction<itk::Image<float, 3u>, itk::Image<float, 3u>
>>>
>>>>::CalculateSpeedImage()'
>>>
>>>collect2: ld returned 1 exit status
>>>make[2]: *** [myMain] Error 1
>>>make[1]: *** [CMakeFiles/myMain.dir/all] Error 2
>>>make: *** [all] Error 2
>>>============================================================
>>>
>>>I attach the all files you need to compile this code. Thanks a lot for
>>>your concern.
>>>
>>>Burak
>>>
>>>On 10/10/07, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>>>
>>>
>>>>Hi Burak,
>>>>
>>>>It seems that you forgot to put typedefs for "Pointer"
>>>>in the definition of the class: myLevelSetFunction"
>>>>
>>>>We will need the source code of "myLevelSetFunction.h"
>>>>to verify this.
>>>>
>>>>Please post that header file to the mailing list if you
>>>>are still interested in further advice.
>>>>
>>>>Otherwise, please look at files such as
>>>>
>>>>    itkShapeDetectionLevelSetFunction.h
>>>>    itkGeodesicActiveContoursLevelSetFunction.h
>>>>
>>>>for examples on the basic typedefs that you should
>>>>have in a class that is managed by SmartPointers.
>>>>
>>>>
>>>>   Thanks
>>>>
>>>>
>>>>      Luis
>>>>
>>>>
>>>>----------------------
>>>>Burak Özkalaycı wrote:
>>>>
>>>>
>>>>>I figured out that to have a working segmentationLevelSetFunction I
>>>>>have to implement the CalculateSpeedImage in a subclass. That's why I
>>>>>changed my code a little bit and I attach it with the make error log.
>>>>>Thanks again
>>>>>
>>>>>Burak
>>>>>
>>>>>Revised code
>>>>>===============================
>>>>>// file name : tpls_main.cpp
>>>>>
>>>>>#if defined(_MSC_VER)
>>>>>#pragma warning ( disable : 4786 )
>>>>>#endif
>>>>>
>>>>>#ifdef __BORLANDC__
>>>>>#define ITK_LEAN_AND_MEAN
>>>>>#endif
>>>>>
>>>>>#include "itkImage.h"
>>>>>#include "itkImageFileReader.h"
>>>>>#include "itkImageFileWriter.h"
>>>>>
>>>>>#include "itkSegmentationLevelSetFunction.h"
>>>>>
>>>>>template <class TImageType, class TFeatureImageType>
>>>>>class myLevelSetFunction:itk::SegmentationLevelSetFunction<TImageType,
>>>>>TFeatureImageType>
>>>>>{
>>>>> void CalculateSpeedImage()
>>>>> {
>>>>>   this->SetSpeedImage(this->GetFeatureImage);
>>>>> }
>>>>>};
>>>>>
>>>>>int main( int argc, char *argv[] )
>>>>>{
>>>>> // Input Image
>>>>> typedef   float           InputPixelType;
>>>>> const     unsigned int    Dimension = 3;
>>>>> typedef itk::Image< InputPixelType, Dimension >  InputImageType;
>>>>>
>>>>> // Internal Image
>>>>> typedef   float           InternalPixelType;
>>>>> typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
>>>>>
>>>>> // Output Image
>>>>> typedef float OutputPixelType;
>>>>> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>>>>>
>>>>> typedef  itk::ImageFileReader< InternalImageType > ReaderType;
>>>>> typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
>>>>>
>>>>> // Read write initialization
>>>>> ReaderType::Pointer reader1 = ReaderType::New();
>>>>> ReaderType::Pointer reader2 = ReaderType::New();
>>>>> WriterType::Pointer writer = WriterType::New();
>>>>>
>>>>> reader1->SetFileName( argv[1] );
>>>>> reader2->SetFileName( argv[2] );
>>>>> writer->SetFileName(  argv[3] );
>>>>>
>>>>> // MAIN ALGORITHM CAN START HERE !!
>>>>>
>>>>> typedef myLevelSetFunction<InternalImageType, InternalImageType>
>>>>>LSFunctionType;
>>>>> LSFunctionType::Pointer LS_function = LSFunctionType::New();
>>>>>
>>>>> return 0;
>>>>>}
>>>>>===============================
>>>>>
>>>>>the make error log:
>>>>>===============================
>>>>>make
>>>>>Scanning dependencies of target tpls_main
>>>>>[100%] Building CXX object CMakeFiles/tpls_main.dir/tpls_main.o
>>>>>/home/xonobo/itk/InsightToolkit-3.2.0/Code/Common/itkSegmentationLevelSetFunction.h:
>>>>>In function 'int main(int, char**)':
>>>>>/home/xonobo/itk/InsightToolkit-3.2.0/Code/Common/itkSegmentationLevelSetFunction.h:52:
>>>>>error: 'typedef class
>>>>>itk::SmartPointer<itk::SegmentationLevelSetFunction<itk::Image<float,
>>>>>3u>, itk::Image<float, 3u> > >
>>>>>itk::SegmentationLevelSetFunction<itk::Image<float, 3u>,
>>>>>itk::Image<float, 3u> >::Pointer' is inaccessible
>>>>>/home/xonobo/CPP/itk_based/itkTPLS/tpls_main.cpp:80: error: within this context
>>>>>/home/xonobo/itk/InsightToolkit-3.2.0/Code/Common/itkLevelSetFunction.h:75:
>>>>>error: 'static itk::SmartPointer<itk::LevelSetFunction<TImageType> >
>>>>>itk::LevelSetFunction<TImageType>::New() [with TImageType =
>>>>>itk::Image<float, 3u>]' is inaccessible
>>>>>/home/xonobo/CPP/itk_based/itkTPLS/tpls_main.cpp:80: error: within this context
>>>>>/home/xonobo/CPP/itk_based/itkTPLS/tpls_main.cpp:80: error: conversion
>>>>
>>>>>from 'itk::SmartPointer<itk::LevelSetFunction<itk::Image<float, 3u> >
>>>>
>>>>>>' to non-scalar type
>>>>>
>>>>>'itk::SmartPointer<itk::SegmentationLevelSetFunction<itk::Image<float,
>>>>>3u>, itk::Image<float, 3u> > >' requested
>>>>>make[2]: *** [CMakeFiles/tpls_main.dir/tpls_main.o] Error 1
>>>>>make[1]: *** [CMakeFiles/tpls_main.dir/all] Error 2
>>>>>make: *** [all] Error 2
>>>>>===============================
>>>>>_______________________________________________
>>>>>Insight-users mailing list
>>>>>Insight-users at itk.org
>>>>>http://www.itk.org/mailman/listinfo/insight-users
>>>>>
>>>>
-------------- next part --------------
// filename: myLevelSetFunction.h
#ifndef __myLevelSetFunction_h_
#define __myLevelSetFunction_h_

#include "itkSegmentationLevelSetFunction.h"

namespace itk {

template <class TImageType, class TFeatureImageType = TImageType>
class ITK_EXPORT myLevelSetFunction
  : public SegmentationLevelSetFunction<TImageType, TFeatureImageType>
{
public:
  /** Standard class typedefs. */
  typedef myLevelSetFunction Self;
  typedef SegmentationLevelSetFunction<TImageType, TFeatureImageType> Superclass;
  typedef SmartPointer<Self> Pointer;
  typedef SmartPointer<const Self> ConstPointer;
  typedef TFeatureImageType FeatureImageType;

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

  /** Run-time type information (and related methods) */
  itkTypeMacro( myLevelSetFunction, SegmentationLevelSetFunction );

  /** Extract some parameters from the superclass. */
  typedef typename Superclass::ImageType ImageType;
  typedef typename Superclass::NeighborhoodType NeighborhoodType;
  typedef typename Superclass::ScalarValueType ScalarValueType;
  typedef typename Superclass::FeatureScalarType FeatureScalarType;
  typedef typename Superclass::RadiusType RadiusType;
  typedef typename Superclass::FloatOffsetType FloatOffsetType;
  typedef typename Superclass::GlobalDataStruct GlobalDataStruct;

  /** Extract some parameters from the superclass. */
  itkStaticConstMacro(ImageDimension, unsigned int,
                      Superclass::ImageDimension);

  virtual void CalculateSpeedImage();

  /** The curvature speed is same as the propagation speed. */
/*
  virtual ScalarValueType CurvatureSpeed(const NeighborhoodType & neighborhood,
                                         const FloatOffsetType & offset, GlobalDataStruct *gd ) const
  { return PropagationSpeed( neighborhood, offset, gd ); }


  virtual void Initialize(const RadiusType &r)
  {
    Superclass::Initialize(r);
    
    this->SetAdvectionWeight( NumericTraits<ScalarValueType>::Zero );
    this->SetPropagationWeight( NumericTraits<ScalarValueType>::One );
    this->SetCurvatureWeight( NumericTraits<ScalarValueType>::One );
  }
*/  
protected:
  myLevelSetFunction()
  {
    this->SetAdvectionWeight( NumericTraits<ScalarValueType>::Zero );
    this->SetPropagationWeight( NumericTraits<ScalarValueType>::One );
    this->SetCurvatureWeight( NumericTraits<ScalarValueType>::Zero );
  }
  virtual ~myLevelSetFunction() {}

  myLevelSetFunction(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented
  
  void PrintSelf(std::ostream& os, Indent indent) const
  {
    Superclass::PrintSelf(os, indent );
  }
  
};
  
} // end namespace itk

#include "myLevelSetFunction.txx"

#endif
-------------- next part --------------
//filename: myLevelSetFunction.txx
#ifndef __myLevelSetFunction_txx_
#define __myLevelSetFunction_txx_

#include "myLevelSetFunction.h"
#include "itkImageRegionIterator.h"

namespace itk {

template <class TImageType, class TFeatureImageType>
void myLevelSetFunction<TImageType, TFeatureImageType>
::CalculateSpeedImage()
{
  /* copy the feature image into the speed image */
  ImageRegionConstIterator<FeatureImageType>
    fit(this->GetFeatureImage(), this->GetFeatureImage()->GetRequestedRegion());
  ImageRegionIterator<ImageType>
    sit(this->GetSpeedImage(), this->GetFeatureImage()->GetRequestedRegion());

  for ( fit = fit.Begin(), sit = sit.Begin(); ! fit.IsAtEnd(); ++sit, ++fit)
    {
    sit.Set( static_cast<ScalarValueType>( fit.Get() ) );
    }
}


} // end namespace itk


#endif


More information about the Insight-users mailing list