1 #include <vtkDataArrayTemplate.h>
2 #include <vtkPointData.h>
8 vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data,
13 std::cout << "NV "<<nx<<" " <<ny<<" " << nz<<std::endl;
14 std::cout << typeid(T).name() << std::endl;
15 vtkImageData *image = vtkImageData::New();
16 image->SetNumberOfScalarComponents(1);
17 image->SetScalarType(GetVtkIdType<T>(*data));
18 image->SetDimensions(nx,ny,nz);
19 image->SetSpacing(1,1,1);
20 std::cout << "alloc"<<std::endl;
21 image->AllocateScalars();
22 std::cout << "alloc ok"<<std::endl;
23 vtkDataArrayTemplate<T>* array
24 = (vtkDataArrayTemplate<T>*)vtkDataArrayTemplate<T>::New();
25 std::cout << "data array alloc ok"<<std::endl;
26 // array->SetNumberOfComponents( 1 );
27 std::cout << "nb compo ok"<<std::endl;
28 // The last param of SetArray is set to 1 to keep the class from deleting the array when it cleans up or reallocates memory.
29 size_t size = (long)nx*(long)ny*(long)nz;
30 std::cout << "SetArray"<<std::endl;
31 array->SetArray( data, size, 1 );
32 //Pay attention in particular to the last param of SetArray:
33 //http://www.vtk.org/doc/nightly/html/classvtkUnsignedShortArray.html#z798_0
34 std::cout << "SetScalars"<<std::endl;
35 image->GetPointData( )->SetScalars( array );
36 std::cout << "Delete"<<std::endl;