[Insight-developers] itkPoint & itkVector (fwd)

Brad King brad.king@kitware.com
Thu, 25 Jan 2001 09:15:52 -0500 (EST)


This discussion has occured amongst a few of us, but belongs on the
list, so I'm forwarding it.

---------- Forwarded message ----------
Date: Thu, 25 Jan 2001 08:52:12 -0500 (EST)
From: Brad King <brad.king@kitware.com>
To: "Miller, James V (CRD)" <millerjv@crd.ge.com>
Cc: "'luis.ibanez@ieee.org'" <luis.ibanez@ieee.org>,
     Will Schroeder <will.schroeder@kitware.com>,
     Brad King <brad.king@kitware.com>
Subject: RE: [Insight-developers] itkPoint & itkVector

> a = 5*ones(3,1)
> b = a + 7*ones(3,1)
All we have to do is create multiply/divide operators that can take a
scalar and a vector, and then add something like the Array<int, 3>::Ones
to the Array class as a static member.

> 
> Is it possible (in a cross platform sense) to have an operation like
> 
> Array<int, 5> v;
> v[1:3] = Array<int, 3>::Ones;
Well, we can't do it quite like that, but multiple-argument function call
operators are allowed, so I might be able to create something that would
allow

Array<int, 5> v;
v(1,3) = ....

but this would need more run-time checking.  Perhaps even better would be
a template member function that would allow something like this:

v.Range<1,3>() = ....

Where Range is defined as

template <typename TValueType, unsigned int VLength>
class Array
{
public:
  template <unsigned int first, unsigned int last>
  Array<ValueType, (last-first+1)>::Reference
  Range()
    {
    return Array<ValueType, (last-first+1)>::Reference(m_InternalArray+first);
    }

  //....
private:
  ValueType m_InternalArray[Length];

  //....
};

This would allow the same compile-time range check as the Array, if I can
figure out how to do that.  As far as that is concerned, I know it is
possible to do a compile-time upper-bound check on the comma-separated
list's length, but I'm not sure about a lower.  Also, it requires partial
specialization to do the check, so it won't be supported in Visual C++.

I'll look into quickly writing up solutions to as many of these problems
as I can.

Thoughts?
-Brad