[vtkusers] vtkImageImport

Erik Türke tuerke at cbs.mpg.de
Mon Mar 29 13:18:56 EDT 2010


On 03/29/2010 07:01 PM, Jothybasu K Selvaraj wrote:
> It seems like paraview is expecting vtkXMLImageData, so you are 
> getting vtkXMLReader related error.Try using vtkXMLImageDataWriter and 
> vtkXMLImageDataReader.
>
> Jothy
>
> On Mon, Mar 29, 2010 at 5:46 PM, Erik Türke <tuerke at cbs.mpg.de 
> <mailto:tuerke at cbs.mpg.de>> wrote:
>
>     Hi!
>
>     I am new to vtk.
>
>     I am using the vtkImageImport class to view a non vtk object:
>
>     importer->SetImportVoidPointer(&myAdapter->m_ImageISIS->voxel<short>(0,0,0,0));
>     importer->SetWholeExtent(0,dimensions[0]-1,0,dimensions[1]-1,0,dimensions[2]-1);
>     importer->SetDataExtentToWholeExtent();
>     importer->SetDataScalarTypeToShort();
>     importer->Update();
>     viewer->SetInputConnection(importer->GetOutputPort());
>     viewer->SetZSlice(100);
>     viewer->Render();
>     sleep(5);
>
>     This works fine. The second thing i want to do is safe the data as
>     a vtk image and open it with paraview:
>
>     vtkImageWriter* writer = vtkImageWriter::New();
>     writer->SetFileDimensionality(3);
>     writer->SetInputConnection(importer->GetOutputPort());
>     writer->SetFileName("test.vtk");
>     writer->UpdateWholeExtent();
>     writer->Write();
>
>     The file is safed, but i can not open it with paraview. There is
>     always a message: "a reader for ... could not be found. please
>     choose one".
>     And when i choose vtk image reader the message:
>     "
>
>     index 0: not well-formed (invalid token)
>
>     ERROR: In /build/buildd/paraview-3.4.0/VTK/IO/vtkXMLReader.cxx,
>     line 360
>
>     vtkXMLImageDataReader (0x24b7720): Error parsing input file.
>     ReadXMLInformation aborting.
>
>     ERROR: In
>     /build/buildd/paraview-3.4.0/VTK/Filtering/vtkExecutive.cxx, line 757
>
>     vtkCompositeDataPipeline (0x24c2030): Algorithm
>     vtkXMLImageDataReader(0x24b7720) returned failure for request:
>     vtkInformation (0x24dc890)
>
>     Debug: Off
>
>     Modified Time: 79214
>
>     Reference Count: 1
>
>     Registered Events: (none)
>
>     Request: REQUEST_INFORMATION
>
>     ALGORITHM_AFTER_FORWARD: 1
>
>     FORWARD_DIRECTION: 0"
>
>
>
>     appears.
>
>     The third thing i want to do is store the data to a vtkImageData
>     object.
>     Is there any possibility to directly forward the vtkImageImport
>     (or pointer of the first element of the data array) to the
>     vtkImageData, so i do not have to do it voxel by voxel? Because
>     this needs a lot of time for big data.
>
>     Thanks for your help!
>
>     cheers
>
>
>     _______________________________________________
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>
>     Please keep messages on-topic and check the VTK FAQ at:
>     http://www.vtk.org/Wiki/VTK_FAQ
>
>     Follow this link to subscribe/unsubscribe:
>     http://www.vtk.org/mailman/listinfo/vtkusers
>
>
Ahh very thanks....visualization is working now (at least slice-wise). I 
guess 3d rendering is a bit more complicated.

So the problem which remains is the storage in a vtkImageData object.
My approach is:

vtkImage->SetDimensions(dimensions[0],
                 dimensions[1],
                 dimensions[2]);
vtkImage->SetWholeExtent(0,dimensions[0]-1,0,dimensions[1]-1,0,dimensions[2]-1);

vtkImage->SetSpacing(1,1,1);
vtkImage->SetNumberOfScalarComponents(1);
vtkImage->SetOrigin(0,0,0);
vtkImage->AllocateScalars();
short* scalarPtr = static_cast<short*>(vtkImage->GetScalarPointer());
scalarPtr = &myAdapter->m_ImageISIS->voxel<short>(0,0,0,0);
vtkImage->Update();

But if i hand the vtkImage to the viewer by:

viewer->SetInput(vtkImage);

the shown image is black :-(

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100329/2ef25e10/attachment.htm>


More information about the vtkusers mailing list