[Insight-users] Streaming I/O
Miller, James V (Research)
millerjv@crd.ge.com
Tue, 8 Apr 2003 10:23:31 -0400
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_01C2FDDA.6E7BF330
Content-Type: text/plain
This is a problem with out current IO structure. In my opinion, the region
that should be written to disk should be the RequestedRegion (or at worst
the BufferedRegion). Having it set to the LargestPossibleRegion is a
problem because you do not know whether the pipeline actually gave you a
buffer that contains the LargestPossibleRegion.
I think there is a level of communication that is missing between the
FileWrite/FileReader and the IO objects. From what I can deduce from the
code, the IO objects assume that the IORegion maps to a contiguous block of
memory in a buffer. The pipeline mechanism doesn't necessarily ensure that
is the case. The only region that is contiguous in memory is the
BufferedRegion. So we either have to stick with this assumption and be
forced to copy the RequestedRegion to a contiguous block of memory sometimes
or we need expand the IO objects to understand
that the IORegion is only a piece of a bigger buffer.
I believe you had another streaming question as well. A few months ago, I
added methods to the IO objects
CanStreamRead()/CanStreamWrite(). The current IO objects always return
false for these methods because
they do not support streaming. When we have an IO object that supports
streaming, they will need to respond
true to these methods. I think I put a call to CanStreamRead() in
ImageFileReader but I am not sure I put a corresponding call in
ImageFileWriter. I look into that.
Jim
-----Original Message-----
From: Ron Inbar [mailto:ron@mediguide.co.il]
Sent: Tuesday, April 08, 2003 6:32 AM
To: 'Insight-users@public.kitware.com'
Subject: [Insight-users] Streaming I/O
In the course of my efforts to implement an ImageIO subclass that supports
streaming, I came across the following code segment (in
itkImageFileWriter.txx):
template <class TInputImage>
void
ImageFileWriter<TInputImage>
::Write(void)
{
// . . .
// Make sure region is within the image, crop if necessary
ImageIORegion ioRegion(TInputImage::ImageDimension);
ImageRegion<TInputImage::ImageDimension> region =
input->GetLargestPossibleRegion();
const double *spacing = input->GetSpacing();
const double *origin = input->GetOrigin();
m_ImageIO->SetNumberOfDimensions(TInputImage::ImageDimension);
for(unsigned int i=0; i<TInputImage::ImageDimension; i++)
{
ioRegion.SetSize(i,region.GetSize(i));
ioRegion.SetIndex(i,region.GetIndex(i));
m_ImageIO->SetDimensions(i,region.GetSize(i));
m_ImageIO->SetSpacing(i,spacing[i]);
m_ImageIO->SetOrigin(i,origin[i]);
}
itkDebugMacro( <<"Region to write = " << ioRegion );
this->Write(ioRegion);
}
My question is: why does it set the ioRegion to the LargestPossibleRegion
and not to the BufferedRegion?
(I tried to change it and on first inspection it seems to work OK with the
BufferedRegion).
Ron
This e-mail message has been sent by MediGuide
and is for the use of the intended recipients only.
The message may contain privileged or confidential information .
If you are not the intended recipient you are hereby notified that any use,
distribution or copying of this communication is strictly prohibited,
and you are requested to delete the e-mail and any attachments
and notify the sender immediately.
------_=_NextPart_001_01C2FDDA.6E7BF330
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META content="MSHTML 6.00.2715.400" name=GENERATOR>
<STYLE>@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
COLOR: windowtext; FONT-FAMILY: Arial
}
DIV.Section1 {
page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>This is a problem
with out current IO structure. In my opinion, the region that should be written
to </FONT></SPAN><SPAN class=738061014-08042003><FONT color=#0000ff size=2>disk
should be the RequestedRegion (or at worst the BufferedRegion). Having it
set to the LargestPossibleRegion is a problem because you do not know whether
the pipeline actually gave you a buffer that contains the
LargestPossibleRegion.</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>I think there is
a level of communication that is missing between the FileWrite/FileReader and
the IO objects. From what I can deduce from the code, the IO objects
assume that the IORegion maps to a contiguous block of </FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>memory in a
buffer. The pipeline mechanism doesn't necessarily ensure that is the
case. The only region that is contiguous in memory is the
BufferedRegion. So we either have to stick with this assumption and be
forced to copy the RequestedRegion to a contiguous block of memory sometimes or
we need expand the IO objects to understand</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>that the IORegion
is only a piece of a bigger buffer.</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>I believe you had
another streaming question as well. A few months ago, I added methods to
the IO objects</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2>CanStreamRead()/CanStreamWrite(). The current IO objects always
return false for these methods because</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>they do not
support streaming. When we have an IO object that supports streaming, they
will need to respond</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff size=2>true to these
methods. I think I put a call to CanStreamRead() in ImageFileReader but I am not
sure I put a corresponding call in ImageFileWriter. I look into
that.</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2>Jim</FONT></SPAN></DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=738061014-08042003><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Ron Inbar
[mailto:ron@mediguide.co.il]<BR><B>Sent:</B> Tuesday, April 08, 2003 6:32
AM<BR><B>To:</B> 'Insight-users@public.kitware.com'<BR><B>Subject:</B>
[Insight-users] Streaming I/O<BR><BR></FONT></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">In the course of my
efforts to implement an ImageIO subclass that supports streaming, I came
across the following code segment (in
itkImageFileWriter.txx):</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">template</SPAN></FONT><FONT
face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <<FONT
color=blue><SPAN style="COLOR: blue">class</SPAN></FONT>
TInputImage></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">void</SPAN></FONT><FONT
face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> </SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">ImageFileWriter<TInputImage></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">::Write(<FONT
color=blue><SPAN style="COLOR: blue">void</SPAN></FONT>)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> // . .
.</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT
color=green><SPAN style="COLOR: green">// Make sure region is within the
image, crop if necessary</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> ImageIORegion
ioRegion(TInputImage::ImageDimension);</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ImageRegion<TInputImage::ImageDimension> region = </SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
input->GetLargestPossibleRegion();</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT
color=blue><SPAN style="COLOR: blue">const</SPAN></FONT> <FONT
color=blue><SPAN style="COLOR: blue">double</SPAN></FONT> *spacing =
input->GetSpacing();</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT
color=blue><SPAN style="COLOR: blue">const</SPAN></FONT> <FONT
color=blue><SPAN style="COLOR: blue">double</SPAN></FONT> *origin =
input->GetOrigin();</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
m_ImageIO->SetNumberOfDimensions(TInputImage::ImageDimension);</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT
color=blue><SPAN style="COLOR: blue">for</SPAN></FONT>(<FONT color=blue><SPAN
style="COLOR: blue">unsigned</SPAN></FONT> <FONT color=blue><SPAN
style="COLOR: blue">int</SPAN></FONT> i=0; i<TInputImage::ImageDimension;
i++)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ioRegion.SetSize(i,region.GetSize(i));</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ioRegion.SetIndex(i,region.GetIndex(i));</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
m_ImageIO->SetDimensions(i,region.GetSize(i));</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
m_ImageIO->SetSpacing(i,spacing[i]);</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
m_ImageIO->SetOrigin(i,origin[i]);</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> itkDebugMacro(
<<"Region to write = " << ioRegion );</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT
color=blue><SPAN
style="COLOR: blue">this</SPAN></FONT>->Write(ioRegion);
</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">}</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">My question is: why does
it set the ioRegion to the LargestPossibleRegion and not to the
BufferedRegion?</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">(I tried to change it and
on first inspection it seems to work OK with the
BufferedRegion).</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Ron</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P></DIV>
<DIV><STRONG><FONT color=#000080 size=2></FONT></STRONG> </DIV>
<DIV><STRONG><FONT color=#000080 size=2></FONT></STRONG> </DIV>
<DIV><STRONG><FONT color=#000080 size=2>This e-mail message has been sent by
MediGuide</FONT></STRONG></DIV>
<DIV><STRONG><FONT color=#000080 size=2>and is for the use of the intended
recipients only.<BR>The message may contain privileged or confidential
information .<BR>If you are not the intended recipient you are hereby notified
that any use,<BR>distribution or copying of this communication is strictly
prohibited,<BR>and you are requested to delete the e-mail and any
attachments</FONT></STRONG></DIV>
<DIV><STRONG><FONT color=#000080 size=2>and notify the sender
immediately.</FONT></STRONG></DIV></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C2FDDA.6E7BF330--