[Insight-developers] itkPoint & itkVector (fwd)
Brad King
brad.king@kitware.com
Thu, 25 Jan 2001 09:14:53 -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 07:58:12 -0500
From: "Miller, James V (CRD)" <millerjv@crd.ge.com>
To: "'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
I really like the methods that allow you to assign/add a scalar to a vector. They are useful for
setting the elements of a vector to zero and as well as setting a vector to ones (or any other
scalar).
I find that in my matlab code, I constantly write code like
a = 5*ones(3,1)
etc. The itk shortcut for this was a = 5;
I can give this one up if we have the a "ones" and "zero" method so that I can quickly assign all the
elements of a vector to a given value or add a vector of a constant to a vector. So I'd like to have
the capability to write code equivalent to
a = 5*ones(3,1)
b = a + 7*ones(3,1)
As for the second point, I think the comma separated version should force the user to specify all the
values for the length of the array and not compile otherwise. This would make it consistent it
"aggregate" initialization. Actually, I think aggregate initialization allows you to say "int v[5] =
{1};" which either assigns all the elements to 1 or assigns the first element to 1 and zero to all
the other elements (I always have to look this up).
Another challenge for Brad:
Is it possible (in a cross platform sense) to have an operation like
Array<int, 5> v;
v[1:3] = Array<int, 3>::Ones;
i.e. use a "colon" to specify a range of value? Another way to implement this would be to use a
"Range" class, i.e. v[Range(1,3)] = Array<int, 3>::Ones;
Jim
Jim
-----Original Message-----
From: Luis Ibanez [mailto:ibanez@cs.unc.edu]
Sent: Wednesday, January 24, 2001 12:26 PM
To: Will Schroeder; Brad King; Miller, James V (CRD)
Subject: Re: [Insight-developers] itkPoint & itkVector
Hi,
I'm tracking these errors and the are basically produced by two things:
1) Operations between Vector & Scalars
2) The comma initialization syntaxis
I have some ideas about how to fix it, but I'm not sure that it will
be convenient for everybody. So I will appreciate your comments
on this.
---------
About (1) and (2) , the problem comes from expresions like
itk::Vector< double, 3 > v;
v = 3.0;
Originally this was supposed to initialize all the elements of
the vector with the value 3.0. This operation lacks of geometrical
meaning. So in the current version of itkVector the operator=( T )
was removed. The only case when it make sense is when the vector
is initialized to zeros, and for this, it seem to be better to
define a SetNull() method.
Similar operations with scalars like:
itk::Vector< double, 3 > v;
itk::Vector< double, 3 > w;
v += 4.0
v = w + 3.0
were also removed.
In order to enforce the good use of Vector and Point for
geometry, these operations shouldn't be possible.
but...
In order to use the list initialization like
v = 1,2,4;
which do has geometrical meaning, we need to declare again
method like operator=( T );
The following problems arise when the support for ArrayCommaListCopier
is added :
a- Vector can be assigned to Points and Points can be
assigned to Vectors, becase both derive from itkArray.
This direct assignment is undesirable.
b- The initialization doesn't allow to check for number of
elements (a run time check for max could be easily set,
but not for an insuficient number of elements)
so a vector of dimension 6 can be initialized as:
v = 19; // but this will just put the first element to 19
// not all the elements as in the previous syntaxis.
or it can be
v = 19, 32; // in which case only the two first elements
// become initialized.
I certainly will like to use the comma initialization, but couldn't
figure out a way of preventing these other inconsistent uses of type
from happening.
Any suggestions ?
Thanks
Luis
-------------------------------------------
Will Schroeder wrote:
Hi Luis-
I've got some more itkPoint/itkVector problems that you might want to
look at. If you go to the Insight Dashboard:
http://public.kitware.com/Insight/Testing/HTML/TestingResults/Dashboard/MostRecentResults-Nightly/Das
hboard.html
And click on build errors, the digested version of the error log will
appear. There are several related to point and vector. Here are just a
few
of last's night build errors:
* itkImageIteratorTest.cxx:209: no matching function for call to
`itk::Vector::GetVector ()'
* itkPixelAccessTest.cxx:74: no matching function for call to
`itk::Vector::GetVector ()
* itkVectorTest.cxx:87: no match for `main()::FloatVector & += double
* File: Code/Common/itkVector.txx Line: 111 CVS and Doxygen access
../../../../Insight/Testing/Code/Common/itkTraitsTest.cxx:14: warning:
unused variable `short unsigned int max'
c++ -Wall -fprofile-arcs
-ftest-coverage -I/projects/quality/itkQuality/Insight-linux-coverage
-I/projects/quality/itkQuality/Insight-linux-coverage/Code/Insight3DParty/vxl
-I/projects/quality/itkQuality/Insight/Code/Common
-I/projects/quality/itkQuality/Insight/Code/Insight3DParty/vxl -c
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx -o
itkVectorTest.o
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:87: no match
for
`main()::FloatVector & += double'
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:93: no match
for
`main()::FloatVector & -= double'
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:106: no match
for
`main()::FloatVector & += float &'
/projects/quality/itkQuality/Insight/Code/Common/itkVector.txx:111:
candidates are: const class itk::Vector & itk::Vector::operator +=(const
itk::Vector &)
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:112: no match
for
`main()::FloatVector & -= float &'
/projects/quality/itkQuality/Insight/Code/Common/itkVector.txx:127:
candidates are: const class itk::Vector & itk::Vector::operator -=(const
itk::Vector &)
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:130: no
matching
function for call to `itk::Vector::GetVector ()'
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:142: no
matching
function for call to `itk::Vector::GetVector ()'
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:153: no
matching
function for call to `itk::Vector::GetVector ()'
../../../../Insight/Testing/Code/Common/itkVectorTest.cxx:164: no
matching
function for call to `itk::Vector::GetVector ()'
Will
--
______________________________________________________________________
Luis Ibanez
Research Assistant Professor - Division of Neurosurgery
University of North Carolina at Chapel Hill
CB# 7060, Chapel Hill, NC 27599
email : ibanez@cs.unc.edu home : http://www.cs.unc.edu/~ibanez
phone : (919)-843-9961 fax : (919)-966-6627
______________________________________________________________________