--- /dev/null
+#ifndef __creaVtk_h_INCLUDED__
+#define __creaVtk_h_INCLUDED__
+
+#ifdef USE_VTK
+
+#include <creaSystem.h>
+#include <vtkImageData.h>
+
+namespace crea
+{
+
+ template <class T>
+ vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data,
+ size_t size);
+
+ template <class T>
+ vtkIdType GetVtkIdType(T&) { return VTK_VOID; }
+
+#define SPECIALIZE_GETVTKIDTYPE(T,R) \
+ template <> vtkIdType GetVtkIdType<T>(T&) { return R; }
+
+ SPECIALIZE_GETVTKIDTYPE(char,VTK_CHAR)
+ SPECIALIZE_GETVTKIDTYPE(signed char,VTK_SIGNED_CHAR)
+ SPECIALIZE_GETVTKIDTYPE(unsigned char,VTK_UNSIGNED_CHAR)
+ SPECIALIZE_GETVTKIDTYPE(short,VTK_SHORT)
+ SPECIALIZE_GETVTKIDTYPE(unsigned short,VTK_UNSIGNED_SHORT)
+ SPECIALIZE_GETVTKIDTYPE(int,VTK_INT)
+ SPECIALIZE_GETVTKIDTYPE(unsigned int,VTK_UNSIGNED_INT)
+ SPECIALIZE_GETVTKIDTYPE(long,VTK_LONG)
+ SPECIALIZE_GETVTKIDTYPE(unsigned long,VTK_UNSIGNED_LONG)
+ SPECIALIZE_GETVTKIDTYPE(float,VTK_FLOAT)
+ SPECIALIZE_GETVTKIDTYPE(double,VTK_DOUBLE)
+
+#undef SPECIALIZE_GETVTKIDTYPE
+}
+
+#include <creaVtk.txx>
+
+
+#endif // USE_VTK
+#endif // __creaVtk_h_INCLUDED__
--- /dev/null
+#include <vtkDataArrayTemplate.h>
+#include <vtkPointData.h>
+
+namespace crea
+{
+
+ template <class T>
+ vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data,
+ size_t size)
+ {
+ vtkImageData *image = vtkImageData::New();
+ image->SetNumberOfScalarComponents(1);
+ image->SetScalarType(GetVtkIdType<T>(*data));
+ image->AllocateScalars();
+ vtkDataArrayTemplate<T>* array
+ = (vtkDataArrayTemplate<T>*)vtkDataArrayTemplate<T>::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;
+ }
+
+}
+