[vtkusers] Convert image to .vtk File

Uma Sindhura usindhura at yahoo.com
Fri May 20 09:58:31 EDT 2005


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

		
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - Find what you need with new enhanced search. Learn more.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050520/ecfe3696/attachment.htm>


More information about the vtkusers mailing list