[Insight-developers] Convenience functions for Index, Offset, Point, Vector, etc.

Hans Johnson hjohnson@mail.psychiatry.uiowa.edu
Wed, 12 Mar 2003 20:42:37 -0600 (CST)


Jmaes,

I give a yes vote.  I think they would be quite useful.

Regards,
Hans


On Wed, 12 Mar 2003, Miller, James V (Research) wrote:

> Brad and I were discussing adding convenience functions to the primitive
> data types Index, Offset, Point, Vector, etc.
>  
> I'd like to get some feedback on what people think, in other words, are they
> necessary?
>  
> I have stumbled into this issue when writing targeted applications (where I
> know ahead of time the dimension of the data) as opposed to writing filters
> (where we need the generality of N dimensions).
>  
> So... anyway... if in your application you call a method that takes an
> Index, for instance a seed point, you need to create an Index, set the
> components of Index to desired values, and pass the index to the method:
>  
> Index<2> ind;
> ind[0] = 101;
> ind[1] = 46;
> someFilter->SetSeed( ind );
>  
> Now if we add some convenience methods, the code could look like:
>  
> someFilter->SetSeed( MakeIndex(101, 46) );
>  
> where MakeIndex is an overloaded function like below:
>  
> Index<2> MakeIndex(Index<2>::IndexValueType i0, Index<2>::IndexValueType
> i1);
> Index<3> MakeIndex(Index<3>::IndexValueType i0, Index<3>::IndexValueType i1,
>                    Index<3>::IndexValueType i2);
>  
> Basically, this methodology uses an overloaded function to get around the
> fact that we do not have a constructor for Index that takes the values of
> the components listed out explictly.  The reason we do not have such a
> constructor is that the class is templated over dimension and we would want
> the constructor to have a different number of arguments for each
> instantiation (over dimension).  We could have had a single constructor that
> took (say) 7 arguments where they all defaulted to a single value.  But that
> would impose a runtime penalty when the dimensions where small.
>  
> We could do this for the primitive types of Index, Offset, Point, Vector,
> CovarientVector, etc.
>  
> We could do the same to set the values of an index:
> 
> void SetIndex(Index<2> &ind, Index<2>::IndexValueType i0,
>               Index<2>::IndexValueType i1);
> void SetIndex(Index<3> &ind, Index<3>::IndexValueType i0,
>               Index<3>::IndexValueType i1,
>               Index<3>::IndexValueType i2);
> 
> I added these functions to my copy of Index, where I spec'ed out the
> functions up to 7 dimensions. MakeIndex is not terribly efficient since it
> must construct the Index, set the components, and return the index but it
> does make the notation "shorter".
>  
> Do people want these types of overloaded functions?
>  
> 
> Jim Miller 
> _____________________________________
> Visualization & Computer Vision
> GE Research
> Bldg. KW, Room C218B
> P.O. Box 8, Schenectady NY 12301
> 
> millerjv@research.ge.com <mailto:millerjv@research.ge.com> 
> 
> james.miller@research.ge.com
> (518) 387-4005, Dial Comm: 8*833-4005, 
> Cell: (518) 505-7065, Fax: (518) 387-6981 
> 
>  <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"
> />
> 
>  
>