[Insight-users] static_cast<DiffusionTensor3D>

Karthik Krishnan karthik.krishnan at kitware.com
Sat Nov 8 12:46:11 EST 2008


That is because the class itk::Vector defines copy constructors and
assignment operators that support implicit casting ... for instance..

  Vector< float , N > can be assigned to Vector< double, N >

----
See
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkVector.h?annotate=1.82&root=Insight

  /** Pass-through constructor for the Array base class. */
  template< class TVectorValueType >
  Vector(const Vector< TVectorValueType, NVectorDimension>& r): 
BaseArray(r) {}
  Vector(const ValueType r[Dimension]): BaseArray(r) {} 
   
  /** Pass-through assignment operator for the Array base class. */
  template< class TVectorValueType >
  Vector& operator= (const Vector< TVectorValueType, NVectorDimension> & r)
    {
    BaseArray::operator=(r);
    return *this;
    }
----

Thus the copy constructor and the assignment operator are templated 
member functions.
I did not add these to the DiffusionTensor3D or the 
SymmetricSecondRankTensor classes.
If you can add it to the SymmetricSecondRankTensor and DiffusionTensor3D 
class as
well... (should be just 5 lines), and send us the patch, we'd be happy 
to commit it.


Thanks


Luke Bloy wrote:
> Hi all,
>
> I'm not sure what the correct forum for this question is but hopefully 
> i can get some input here.
>
> I'm trying to work with itkNaryFunctorImageFilter, I'm starting with 
> the itkNaryAddImageFilter since it is fairly straight forward.
>
> The problem is that i'd like to use it over DTI images, and there 
> isn't a itkNumericTraits definition file for itkDiffusionTensor3D. So 
> I created one based off of NumericTraitsVectorPixel.h and 
> NumericTraitsVectorPixel.cxx. I also fixed the file 
> itkNumericTraitsTensorPixel. I added my cxx classes to the CmakeLists 
> in Code/Common and everything is working... except casting.
>
> It seems that the AccumulateType is often defined to be above the 
> pixelType
> ie the accumulateType for a itk::vector<int,2> is 
> itk::vector<long::2>, this makes sense and I maintained that in my 
> DiffusionTensor3D NumericTraits file.
>
> How ever static_casts fail which causes problems with code like this.
>
>  typedef typename NumericTraits< TInput >::AccumulateType 
> AccumulatorType;
>  AccumulatorType sum = NumericTraits< TOutput >::Zero;
>  for( unsigned int i=0; i< B.size(); i++ )
>      {
>      sum += static_cast< TOutput >(B[i]);
>      }         return static_cast<TOutput>( sum );
>  }
>
> So what am I missing? Is there somewhere else the I have to explicitly 
> define the casting. There doesn't seem to be anything in the class 
> definitions for itkVector, so I assume that it goes someplace other 
> then in the class definitions.
>
> Thanks in advance.
> -Luke
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users

-- 
Karthik Krishnan
R & D Engineer,
Kitware Inc,
Ph:  518 371 3971 x119
Fax: 518 371 3971



More information about the Insight-users mailing list