]> Creatis software - crea.git/blobdiff - src/creaVtk.txx
*** empty log message ***
[crea.git] / src / creaVtk.txx
index a7d6a04733b9805a2180f6232302054d85a9be92..4d39387958debb94ce4b6316ccdff53b8986af9d 100644 (file)
@@ -1,25 +1,39 @@
 #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;
   }