[Insight-users] Streaming I/O
Ron Inbar
ron@mediguide.co.il
Tue, 8 Apr 2003 18:41:38 +0200
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_01C2FDED.B9A46370
Content-Type: text/plain
Hi James,
Can you please explain the role of the IORegion in relation to the three
Image Regions (Requested, Buffered, and LargestPossible)?
So far, my understanding was that the ImageFileWriter should set the
IORegion to the BufferedRegion in order to tell the ImageIO where (on the
disk) to write the contents of the buffer. For example, if the file format
dictates that each z-slice reside in a separate file, using some consistent
naming scheme, then the ImageIO should use the 3rd dimension of the IORegion
to know which files it has to modify. It may assume that the data are
contiguous and that the buffer size matches the size of the IORegion.
Likewise, the ImageFileReader should set the IORegion to the RequestedRegion
and allocate a buffer to match this size. The ImageIO should then use the
IORegion to find the requested data on the disk and place them
(contiguously) into the supplied buffer.
The ImageIO may also need to use the m_Dimensions member to figure out where
the data reside on the disk.
To sum up, I thought the data can be assumed to be contiguous in memory, but
not necessarily on the disk.
Is this not what you had in mind?
Ron
-----Original Message-----
From: Miller, James V (Research) [mailto:millerjv@crd.ge.com]
Sent: Tuesday, April 08, 2003 4:24 PM
To: 'Ron Inbar'; 'Insight-users@public.kitware.com'
Subject: RE: [Insight-users] Streaming I/O
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.
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_01C2FDED.B9A46370
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 name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.emailstyle17
{font-family:Arial;
color:windowtext;}
span.EmailStyle19
{font-family:Arial;
color:navy;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Hi James,</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Can you please explain the role of the IORegion
in relation to the three Image Regions (Requested, Buffered, and LargestPossible)?</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>So far, my understanding was that the ImageFileWriter
should set the IORegion to the BufferedRegion in order to tell the ImageIO where
(on the disk) to write the contents of the buffer. For example, if the file
format dictates that each z-slice reside in a separate file, using some
consistent naming scheme, then the ImageIO should use the 3<sup>rd</sup> dimension
of the IORegion to know which files it has to modify. It may assume that
the data are contiguous and that the buffer size matches the size of the IORegion.</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Likewise, the ImageFileReader should set
the IORegion to the RequestedRegion and allocate a buffer to match this
size. The ImageIO should then use the IORegion to find the requested data
on the disk and place them (contiguously) into the supplied buffer.</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The ImageIO may also need to use the m_Dimensions
member to figure out where the data reside on the disk.</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>To sum up, I thought the data can be assumed
to be contiguous in memory, but not necessarily on the disk. </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Is this not what you had in mind?</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Ron</span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font></p>
<div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'>
<p class=MsoNormal><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma'>-----Original Message-----<br>
<b><span style='font-weight:bold'>From:</span></b> Miller, James V (Research)
[mailto:millerjv@crd.ge.com] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, April 08, 2003 4:24
PM<br>
<b><span style='font-weight:bold'>To:</span></b> 'Ron Inbar';
'Insight-users@public.kitware.com'<br>
<b><span style='font-weight:bold'>Subject:</span></b> RE: [Insight-users]
Streaming I/O</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>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.</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>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 </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>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</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>that the IORegion is only a piece of a
bigger buffer.</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>I believe you had another streaming
question as well. A few months ago, I added methods to the IO objects</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>CanStreamRead()/CanStreamWrite(). The
current IO objects always return false for these methods because</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>they do not support streaming. When we
have an IO object that supports streaming, they will need to respond</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>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.</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 color=blue face="Times New Roman"><span
style='font-size:10.0pt;color:blue'>Jim</span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<blockquote style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>-----Original Message-----<br>
<b><span style='font-weight:bold'>From:</span></b> Ron Inbar
[mailto:ron@mediguide.co.il]<br>
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, April 08, 2003 6:32
AM<br>
<b><span style='font-weight:bold'>To:</span></b>
'Insight-users@public.kitware.com'<br>
<b><span style='font-weight:bold'>Subject:</span></b> [Insight-users] Streaming
I/O</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 color=blue face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:blue'>template</span></font><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'>
<<font color=blue><span style='color:blue'>class</span></font>
TInputImage></span></font></p>
<p class=MsoNormal><font size=2 color=blue face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:blue'>void</span></font><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'>
</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>ImageFileWriter<TInputImage></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>::Write(<font color=blue><span style='color:blue'>void</span></font>)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>{</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> // . . .</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ImageIORegion ioRegion(TInputImage::ImageDimension);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ImageRegion<TInputImage::ImageDimension> region = </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
input->GetLargestPossibleRegion();</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> m_ImageIO->SetNumberOfDimensions(TInputImage::ImageDimension);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ioRegion.SetSize(i,region.GetSize(i));</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ioRegion.SetIndex(i,region.GetIndex(i));</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
m_ImageIO->SetDimensions(i,region.GetSize(i));</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
m_ImageIO->SetSpacing(i,spacing[i]);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
m_ImageIO->SetOrigin(i,origin[i]);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> }</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> itkDebugMacro( <<"Region to write
= " << ioRegion );</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> <font color=blue><span style='color:blue'>this</span></font>->Write(ioRegion);
</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>}</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=2 face="Courier New"><span style='font-size:10.0pt;
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 size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Ron</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<div>
<p class=MsoNormal><strong><b><font size=2 color=navy face="Times New Roman"><span
style='font-size:10.0pt;color:navy'>This e-mail message has been sent by
MediGuide</span></font></b></strong></p>
</div>
<div>
<p class=MsoNormal><strong><b><font size=2 color=navy face="Times New Roman"><span
style='font-size:10.0pt;color:navy'>and is for the use of the intended
recipients only.</span></font></b></strong><b><font size=2 color=navy><span
style='font-size:10.0pt;color:navy;font-weight:bold'><br>
<strong><b><font face="Times New Roman">The message may contain privileged
or confidential information .</font></b></strong><br>
<strong><b><font face="Times New Roman">If you are not the intended recipient
you are hereby notified that any use,</font></b></strong><br>
<strong><b><font face="Times New Roman">distribution or copying of this
communication is strictly prohibited,</font></b></strong><br>
<strong><b><font face="Times New Roman">and you are requested to delete the
e-mail and any attachments</font></b></strong></span></font></b></p>
</div>
<div>
<p class=MsoNormal><strong><b><font size=2 color=navy face="Times New Roman"><span
style='font-size:10.0pt;color:navy'>and notify the sender immediately.</span></font></b></strong></p>
</div>
</blockquote>
</div>
</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>
</body>
</html>
------_=_NextPart_001_01C2FDED.B9A46370--