#include #include namespace crea { template vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data, size_t size) { vtkImageData *image = vtkImageData::New(); image->SetNumberOfScalarComponents(1); image->SetScalarType(GetVtkIdType(*data)); image->AllocateScalars(); vtkDataArrayTemplate* array = (vtkDataArrayTemplate*)vtkDataArrayTemplate::New(); array->SetNumberOfComponents( 1 ); // The last param of SetArray is set to 1 to keep the class from deleting the array when it cleans up or reallocates memory. array->SetArray( data, size, 1 ); //Pay attention in particular to the last param of SetArray: //http://www.vtk.org/doc/nightly/html/classvtkUnsignedShortArray.html#z798_0 image->GetPointData( )->SetScalars( array ); array->Delete( ); return image; } }