<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Your allocations of 256 map to an extent range of 0 to 255. Similarly,
your z dimension's 9 should map to a range of 0 to 8.<br>
<br>
Change the last arg to your SetExtent calls from 9 to 8:<br>
&nbsp;imageim-&gt;SetDataExtent(0,255,0,255,0,<font color="#ff0000"><b>8</b></font>);<br>
&nbsp;imageim-&gt;SetWholeExtent(0,255,0,255,0,<b><font color="#ff0000">8</font></b>);<br>
<br>
Also, looks like you're reading in shorts...? (inferred from the factor
of 2 in this line):<br>
&nbsp;p = new unsigned char[256*256*<font color="#ff0000"><b>2</b></font>*9];<br>
<br>
That would imply you should be making this call also:<br>
&nbsp;imageim-&gt;SetDataScalarTypeToShort(); // or perhaps
SetDataScalarTypeToUnsignedShort<br>
<br>
<br>
Hope this helps,<br>
David<br>
<br>
<br>
Y<br>
Uma Sindhura wrote:
<blockquote cite="mid20050520135831.88251.qmail@web53508.mail.yahoo.com"
 type="cite">
  <div>Hi Vtk users,</div>
  <div>I wanted to convert an image into polydata and i wanted store it
in .vtk format and i even wanted to open the corresponding .vtk file in
Mayavi data visualizer.But iam getting the access voilation error by
writing the following code.</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div>#include &lt;vtkImageImport.h&gt;<br>
#include &lt;vtkImageDataGeometryFilter.h&gt;<br>
#include &lt;fstream.h&gt;<br>
#include &lt;vtkPolyDataWriter.h&gt;<br>
#include &lt;iostream.h&gt;<br>
class dcmvtk<br>
{<br>
private:<br>
&nbsp;vtkImageImport *imageim;<br>
&nbsp;vtkImageDataGeometryFilter *gfil;<br>
&nbsp;vtkPolyDataWriter *vw;<br>
&nbsp;const char* s;<br>
public:<br>
&nbsp;dcmvtk();<br>
&nbsp;~dcmvtk();<br>
};<br>
dcmvtk::dcmvtk()<br>
{<br>
&nbsp;unsigned char* p = NULL;<br>
&nbsp;if(p != NULL)<br>
&nbsp;{<br>
&nbsp;&nbsp;delete []p;<br>
&nbsp;&nbsp;p = NULL;<br>
&nbsp;}<br>
&nbsp;p = new unsigned char[256*256*2*9];<br>
&nbsp;s="D:/vtk/PET_after_preFilter.raw";<br>
&nbsp;ifstream is(s,ios::in | ios::out | ios::binary);<br>
&nbsp;is.read(p,256*256*2*9);<br>
&nbsp;is.close();<br>
&nbsp;&nbsp;&nbsp; imageim=vtkImageImport::New();<br>
&nbsp;imageim-&gt;SetImportVoidPointer((void*)p,1);<br>
&nbsp;imageim-&gt;SetDataExtent(0,255,0,255,0,9);<br>
&nbsp;imageim-&gt;SetWholeExtent(0,255,0,255,0,9);<br>
&nbsp;imageim-&gt;SetDataSpacing(1.96,1.96,3.92);<br>
&nbsp;imageim-&gt;SetDataOrigin(0.0,0.0,0.0);<br>
&nbsp;gfil=vtkImageDataGeometryFilter::New();<br>
&nbsp;gfil-&gt;SetInput(imageim-&gt;GetOutput());<br>
&nbsp;ofstream ofile;<br>
&nbsp;<br>
&nbsp;const char* f=new char[256*256*9*2];<br>
&nbsp;&nbsp;f="d:/dcm2.vtk";<br>
&nbsp;&nbsp;ofile.open(f,ios::in | ios::out | ios::binary);<br>
&nbsp;&nbsp;vw=vtkPolyDataWriter::New();</div>
  <div>&nbsp;&nbsp;vw-&gt;SetInput(gfil-&gt;GetOutput());<br>
&nbsp;&nbsp;vw-&gt;SetFileName(f);<br>
&nbsp;&nbsp;vw-&gt;Write();<br>
}<br>
dcmvtk::~dcmvtk()<br>
{<br>
&nbsp;imageim-&gt;Delete();<br>
&nbsp;gfil-&gt;Delete();<br>
&nbsp;&nbsp;&nbsp; vw-&gt;Delete();<br>
}<br>
int main(int argc, char *argv[])<br>
{<br>
&nbsp;dcmvtk dc;<br>
&nbsp;return 0;<br>
}</div>
  <p> </p>
  <hr size="1">Do you Yahoo!?<br>
Yahoo! Mail - Find what you need with new enhanced search. <a
 href="http://us.rd.yahoo.com/evt=29917/*http://info.mail.yahoo.com/mail_250">Learn
more.</a>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
  </pre>
</blockquote>
</body>
</html>