#include <vtkDataArrayTemplate.h>
#include <vtkPointData.h>
-
+#include <typeinfo>
namespace crea
{
template <class T>
vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data,
- size_t size)
+ int nx,
+ int ny,
+ int nz)
{
+ std::cout << "NV "<<nx<<" " <<ny<<" " << nz<<std::endl;
+ std::cout << typeid(T).name() << std::endl;
vtkImageData *image = vtkImageData::New();
image->SetNumberOfScalarComponents(1);
image->SetScalarType(GetVtkIdType<T>(*data));
+ image->SetDimensions(nx,ny,nz);
+ image->SetSpacing(1,1,1);
+ std::cout << "alloc"<<std::endl;
image->AllocateScalars();
+ std::cout << "alloc ok"<<std::endl;
vtkDataArrayTemplate<T>* array
= (vtkDataArrayTemplate<T>*)vtkDataArrayTemplate<T>::New();
- array->SetNumberOfComponents( 1 );
+ std::cout << "data array alloc ok"<<std::endl;
+ // array->SetNumberOfComponents( 1 );
+ std::cout << "nb compo ok"<<std::endl;
// The last param of SetArray is set to 1 to keep the class from deleting the array when it cleans up or reallocates memory.
+ size_t size = (long)nx*(long)ny*(long)nz;
+ std::cout << "SetArray"<<std::endl;
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 );
+ std::cout << "SetScalars"<<std::endl;
+ image->GetPointData( )->SetScalars( array );
+ std::cout << "Delete"<<std::endl;
array->Delete( );
return image;
}