[Insight-developers] extracting components of vector image

Tessa Sundaram tessa at rad . upenn . edu
Thu, 08 Aug 2002 15:20:43 -0400


This is a multi-part message in MIME format.
--------------080001000102050203020707
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Dear ITK gurus,

I'm trying to write a filter to extract one component of a vector image
(for use with displacement fields, etc.).  I've tried modifying the
CastImageFilter to create a VectorIndexSelectionCastImageFilter.
 However, I keep getting errors when I try to access the functor as
this->GetFunctor()  within the filter:

C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: error C2819: type 'itk::Functor::VectorIndexSelectionCast<class
itk::Vector<double,2>,float>' does not have an overloaded member
'operator ->'
        
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: while compiling class-template member function 'void __thiscall
itk::VectorIndexSelectionCastImageFilter<class itk::Image<class
itk::Vector<double,2>,2>,class itk::Image<float,2> >::SetIndex(unsigned
int)'
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: error C2227: left of '->SetIndex' must point to class/struct/union
        
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: while compiling class-template member function 'void __thiscall
itk::VectorIndexSelectionCastImageFilter<class itk::Image<class
itk::Vector<double,2>,2>,class itk::Image<float,2> >::SetIndex(unsigned
int)'

I'm confused as to why this isn't working since I'm deriving from the
UnaryFunctorImageFilter.  The index selection filter code is attached,
and below is the method in which I'm trying to use it.  Any suggestions
are greatly appreciated - thanks!

void ImageRegLMEx::WriteDisplacementField(unsigned int index)
  // Outputs the displacement field for the index provided (0=x,1=y,2=z)
{
  // Initialize the caster to the displacement field
  IndexSelectCasterType::Pointer fieldCaster = IndexSelectCasterType::New();
  fieldCaster->SetInput( m_Field );
  fieldCaster->SetIndex( index );
  fieldCaster->Update();

  // Set up the output filename
  char* outfile = new char[strlen(m_DisplacementsFileName+10)];
  sprintf(outfile, "%s%c.raw", m_DisplacementsFileName, 'x'+index);
  std::cout << "Writing displacements (" << fieldCaster->GetIndex() <<
") to " << outfile;

  itk::RawImageIO<Float,2>::Pointer io = itk::RawImageIO<Float,2>::New();
  itk::ImageFileWriter<FloatImageType>::Pointer writer =
itk::ImageFileWriter<FloatImageType>::New();
  writer->SetImageIO(io);
  writer->SetFileName(outfile);
  writer->SetInput(fieldCaster->GetOutput());
  writer->Write();

  std::cout << "...done" << std::endl;
}

-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Tessa A. Sundaram
M.D./Ph.D. Candidate, Penn SOM/SEAS
tessa@mail.med.upenn.edu / tessa@seas.upenn.edu
http://mail.med.upenn.edu/~tessa

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




--------------080001000102050203020707
Content-Type: text/plain;
 name="itkVectorIndexSelectionCastImageFilter.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="itkVectorIndexSelectionCastImageFilter.h"

/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkVectorIndexSelectionCastImageFilter.h,v $
  Language:  C++
  Date:      $Date: 2002/08/07 19:21:26 $
  Version:   $Revision: 1.2 $

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkVectorIndexSelectionCastImageFilter_h
#define __itkVectorIndexSelectionCastImageFilter_h

#include "itkUnaryFunctorImageFilter.h"

namespace itk
{
  
/** \class VectorIndexSelectionCastImageFilter
 *
 * \brief Extracts the selected index of the vector that is the input
 * pixel type
 *
 * This filter is templated over the input image type and 
 * output image type.
 * 
 * The filter expect the input image pixel type to be a vector and 
 * the output image pixel type to be a scalar.
 *
 * \ingroup IntensityImageFilters  Multithreaded
 */

namespace Functor {  
  
  template< class TInput, class TOutput>
    class VectorIndexSelectionCast
    {
    public:
      VectorIndexSelectionCast() {}
      ~VectorIndexSelectionCast() {}

      unsigned int GetIndex() const { return m_Index; }
      void SetIndex(unsigned int i) { m_Index = i; }

      inline TOutput operator()( const TInput & A )
      {
        return static_cast<TOutput>( A[m_Index] );
      }
      
    private:
      unsigned int m_Index;   
    }; 
}
 
template <class TInputImage, class TOutputImage>
class ITK_EXPORT VectorIndexSelectionCastImageFilter :
  public
  UnaryFunctorImageFilter<TInputImage,TOutputImage, 
  Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
                         typename TOutputImage::PixelType>   >
  {
  public:
    /** Standard class typedefs. */
    typedef VectorIndexSelectionCastImageFilter Self;
    typedef UnaryFunctorImageFilter<TInputImage,TOutputImage, 
      Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
      typename TOutputImage::PixelType> > Superclass;
    typedef SmartPointer<Self> Pointer;
    typedef SmartPointer<const Self> ConstPointer;
    
    /** Method for creation through the object factory. */
    itkNewMacro(Self);
    //itkTypeMacro(VectorIndexSelectionCastImageFilter, UnaryFunctorImageFilter);

    /** Get/Set methods for the index */
    void SetIndex(unsigned int i) { this->GetFunctor()->SetIndex(i); }
    unsigned int GetIndex(void) const { return this->GetFunctor()->GetIndex(); }

  protected:
    VectorIndexSelectionCastImageFilter() {}
    virtual ~VectorIndexSelectionCastImageFilter() {}
    
  private:
    VectorIndexSelectionCastImageFilter(const Self&); //purposely not implemented
    void operator=(const Self&); //purposely not implemented
  };
 
} // end namespace itk


#endif

--------------080001000102050203020707--