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

Miller, James V (Research) millerjv@crd.ge.com
Wed, 12 Mar 2003 16:54:13 -0500


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2E8E1.EBADD980
Content-Type: text/plain;
	charset="iso-8859-1"

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"
/>

 

------_=_NextPart_001_01C2E8E1.EBADD980
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=395202921-12032003><FONT size=2>Brad and I were discussing 
adding convenience functions to the primitive data types Index, Offset, Point, 
Vector, etc.</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>I'd like to get some feedback 
on what people think, in other words, are they necessary?</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>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).</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>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:</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>Index&lt;2&gt; 
ind;</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>ind[0] = 
101;</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>ind[1] = 
46;</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>someFilter-&gt;SetSeed( ind 
);</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>Now if we add some convenience 
methods, the code could look like:</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>someFilter-&gt;SetSeed( 
MakeIndex(101, 46) );</FONT></SPAN></DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003></SPAN><SPAN class=395202921-12032003><FONT 
size=2>where MakeIndex is an overloaded function like below:</FONT></SPAN></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Index&lt;2&gt; MakeIndex(Index&lt;2&gt;::IndexValueType i0, 
Index&lt;2&gt;::IndexValueType i1);<BR>Index&lt;3&gt; 
MakeIndex(Index&lt;3&gt;::IndexValueType i0, Index&lt;3&gt;::IndexValueType 
i1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Index&lt;3&gt;::IndexValueType i2);</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>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.&nbsp; 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).&nbsp; We 
could have had a single constructor that took (say) 7 arguments where they all 
defaulted to a single value.&nbsp; But that would impose a runtime penalty when 
the dimensions where small.</FONT></SPAN></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2><SPAN class=395202921-12032003>We could do this for the 
primitive types of Index, Offset, Point, Vector, CovarientVector, 
etc.</SPAN></FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=395202921-12032003><FONT size=2>We could do the same to set the 
values of an index:</FONT></SPAN><FONT size=2><BR></DIV></FONT>
<DIV><FONT size=2>void SetIndex(Index&lt;2&gt; &amp;ind, 
Index&lt;2&gt;::IndexValueType 
i0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Index&lt;2&gt;::IndexValueType i1);<BR>void SetIndex(Index&lt;3&gt; &amp;ind, 
Index&lt;3&gt;::IndexValueType 
i0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Index&lt;3&gt;::IndexValueType 
i1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Index&lt;3&gt;::IndexValueType i2);<BR></FONT></DIV>
<DIV><FONT><SPAN class=395202921-12032003><FONT size=2>I added these 
functions&nbsp;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".</FONT></SPAN></FONT></DIV>
<DIV><FONT><SPAN class=395202921-12032003><FONT 
size=2></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT><SPAN class=395202921-12032003><FONT size=2>Do people want these 
types of overloaded functions?</FONT></SPAN></FONT></DIV>
<DIV><FONT><SPAN class=395202921-12032003></SPAN></FONT>&nbsp;</DIV>
<DIV class=Section1>
<P style="MARGIN: 0in 0in 0pt"><B><SPAN 
style="COLOR: navy; FONT-FAMILY: 'Comic Sans MS'">Jim Miller</SPAN></B> 
<BR><B><I><SPAN 
style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: Arial">_____________________________________</SPAN></I></B><BR><EM><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">Visualization &amp; 
Computer Vision</SPAN></EM><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial"><BR><EM>GE 
Research</EM><BR><EM>Bldg. KW, Room C218B</EM><BR><EM>P.O. Box 8, Schenectady NY 
12301</EM><BR><BR></SPAN></I><EM><U><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: blue"><A 
href="mailto:millerjv@research.ge.com">millerjv@research.ge.com</A></SPAN></U></EM></P>
<P style="MARGIN: 0in 0in 0pt"><EM><U><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: blue">james.miller@research.ge.com</SPAN></U></EM><BR><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">(518) 387-4005, Dial 
Comm: 8*833-4005, </SPAN></I><BR><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">Cell: (518) 505-7065, 
Fax: (518) 387-6981</SPAN></I> </P>
<P class=MsoNormal>&nbsp;<?xml:namespace prefix = o ns = 
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></P></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C2E8E1.EBADD980--