[Insight-developers] Casting constructors for DTI and Sym Mat pixeltypes

Luis Ibanez luis.ibanez at kitware.com
Mon Mar 15 15:45:11 EDT 2010


Hi Luke,

Historically we have been cautious when adding implicit
conversions, since once that syntactic sugar is introduced
in the code, it is very easy to get unintended consequences
particularly when using templated code.


For the case of the itkPoint we were a lot more explicit, and
added a method:


itk::Point<T>::CastFrom( const itk::Point< R > & otherPoint );


See the definition in:

                   Insight/Code/Common/itkPoint.h

in lines 212-221:

  /** Copy from another Point with a different representation type.
   *  Casting is done with C-Like rules  */
  template < typename TCoordRepB >
  void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
    {
    for(unsigned int i=0; i<NPointDimension; i++ )
      {
      (*this)[i] = static_cast<TCoordRep>( pa[i] );
      }
    }



I would suggest that we follow this Explicit approach for
the Tensor classes.


Would you like to give it a try at implementing and testing
the CastFrom() methods for these classes ?


  Thanks


         Luis


----------------------------------------------------------------------------------
On Fri, Mar 5, 2010 at 2:00 PM, Luke Bloy <luke.bloy at gmail.com> wrote:
> The classes itkDiffusionTensor3D and itkSymmetricSecondRankTensor don't have
> constructors that enable casting. ( http://www.itk.org/Bug/view.php?id=10323
> ) so code such as the following fails.
>
>  typedef itk::SymmetricSecondRankTensor<int,3>     Int3DTensorType;
>  typedef itk::SymmetricSecondRankTensor<float,3>   Float3DTensorType;
>  typedef itk::SymmetricSecondRankTensor<double,3>  Double3DTensorType;
>  Int3DTensorType intTensor(1);
>
>  //Test constructors
>  Float3DTensorType floatTensor(intTensor);
>  Double3DTensorType doubleTensor(floatTensor);
>
>  //test Assignment
>  Float3DTensorType floatTensor2 = intTensor;
>
>
> adding templated constructors and assignment operators will allow this type
> of behavior.
>
> Is there a reason these constructors have been not been defined?
>
> -Luke
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>


More information about the Insight-developers mailing list