<!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>
imageim->SetDataExtent(0,255,0,255,0,<font color="#ff0000"><b>8</b></font>);<br>
imageim->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>
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>
imageim->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> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div>#include <vtkImageImport.h><br>
#include <vtkImageDataGeometryFilter.h><br>
#include <fstream.h><br>
#include <vtkPolyDataWriter.h><br>
#include <iostream.h><br>
class dcmvtk<br>
{<br>
private:<br>
vtkImageImport *imageim;<br>
vtkImageDataGeometryFilter *gfil;<br>
vtkPolyDataWriter *vw;<br>
const char* s;<br>
public:<br>
dcmvtk();<br>
~dcmvtk();<br>
};<br>
dcmvtk::dcmvtk()<br>
{<br>
unsigned char* p = NULL;<br>
if(p != NULL)<br>
{<br>
delete []p;<br>
p = NULL;<br>
}<br>
p = new unsigned char[256*256*2*9];<br>
s="D:/vtk/PET_after_preFilter.raw";<br>
ifstream is(s,ios::in | ios::out | ios::binary);<br>
is.read(p,256*256*2*9);<br>
is.close();<br>
imageim=vtkImageImport::New();<br>
imageim->SetImportVoidPointer((void*)p,1);<br>
imageim->SetDataExtent(0,255,0,255,0,9);<br>
imageim->SetWholeExtent(0,255,0,255,0,9);<br>
imageim->SetDataSpacing(1.96,1.96,3.92);<br>
imageim->SetDataOrigin(0.0,0.0,0.0);<br>
gfil=vtkImageDataGeometryFilter::New();<br>
gfil->SetInput(imageim->GetOutput());<br>
ofstream ofile;<br>
<br>
const char* f=new char[256*256*9*2];<br>
f="d:/dcm2.vtk";<br>
ofile.open(f,ios::in | ios::out | ios::binary);<br>
vw=vtkPolyDataWriter::New();</div>
<div> vw->SetInput(gfil->GetOutput());<br>
vw->SetFileName(f);<br>
vw->Write();<br>
}<br>
dcmvtk::~dcmvtk()<br>
{<br>
imageim->Delete();<br>
gfil->Delete();<br>
vw->Delete();<br>
}<br>
int main(int argc, char *argv[])<br>
{<br>
dcmvtk dc;<br>
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>