[Insight-users] embarassingly basic question

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Apr 26 14:21:52 EDT 2012


Hello,

I tries something like adding the following as a constructor without success:


  template< class U >
  Point( ValueType v0, ValueType v1, U u = Self(),
         typename EnableIf< U::NPointDimension==2>::Type* = 0 )
    {
      (*this)[0] = v0;
      (*this)[1] = v1;
    }

  template< class U >
  Point( ValueType v0, ValueType v1, ValueType v2, U u = Self(),
         typename EnableIf< U::NPointDimension==3>::Type* = 0 )
    {
      (*this)[0] = v0;
      (*this)[1] = v1;
      (*this)[2] = v1;
    }

It was an interesting thought, but there is likely something more I needs to know about C++ to know if its possible or even valid.

Brad



On Apr 26, 2012, at 2:16 PM, Rupert Brooks wrote:

> Thanks to all
> 
> Bill,  your solution does work.  We will probably end up creating
> helper functions like Vladimir suggested.  Until C++ 11 arrives :-)
> 
> Best,
> 
> Rupert
> --------------------------------------------------------------
> Rupert Brooks
> rupert.brooks at gmail.com
> 
> 
> On Wed, Apr 25, 2012 at 15:44, Rupert Brooks <rupert.brooks at gmail.com> wrote:
>> Hi,
>> 
>> Its when I show ITK to other people that I end up with embarassingly
>> simple questions that I ought to know the answer to.
>> 
>> When declaring an itk::Point (or vector, etc, anything based on
>> FixedArray) there is no constructor that assigns values that i know
>> of.  So one always ends up doing something like
>> itk::Point<double, 3> p;
>> p[0]=1.1;
>> p[1]=2.2;
>> p[2]=3.3;
>> 
>> or
>> 
>> const double[3] dummy={1.1,2.2,3.3};
>> const itk::Point<double, 3>=dummy;  // at least this way we can get a
>> const itk::Point
>> 
>> It was pointed out to me that this is quite verbose.  A certain ideal
>> would be, eg
>> 
>> const itk::Point<double,3> p(1.1,2.2,3.3);
>> 
>> Is there a better way?  Was this a design choice, or an inevitable
>> consequence of variadic constructors not being possible in C++?
>> 
>> Thanks,
>> Rupert
>> 
>> --------------------------------------------------------------
>> Rupert Brooks
>> rupert.brooks at gmail.com
> _____________________________________
> 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://www.kitware.com/products/protraining.php
> 
> 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-users



More information about the Insight-users mailing list