1 #include <vtkDataArrayTemplate.h>
3 #include <vtkCharArray.h>
4 #include <vtkSignedCharArray.h>
5 #include <vtkUnsignedCharArray.h>
6 #include <vtkShortArray.h>
7 #include <vtkUnsignedShortArray.h>
8 #include <vtkIntArray.h>
9 #include <vtkUnsignedIntArray.h>
10 #include <vtkLongArray.h>
11 #include <vtkUnsignedLongArray.h>
12 #include <vtkFloatArray.h>
13 #include <vtkDoubleArray.h>
15 #include <vtkPointData.h>
16 #include <vtkTypeTraits.h>
17 #include <creaMessageManager.h>
22 vtkImageData* /*CREA_EXPORT*/ NewVtkImageDataFromRaw( T* data,
28 // std::cout << "NV "<<nx<<" " <<ny<<" " << nz<<std::endl;
29 // std::cout << vtkTypeTraits<T>::SizedName() << std::endl;
30 vtkImageData *image = vtkImageData::New();
31 image->SetNumberOfScalarComponents(1);
32 int vtktype = vtkTypeTraits<T>::VTKTypeID();
33 image->SetScalarType(vtktype);
34 image->SetDimensions(nx,ny,nz);
35 image->SetSpacing(1,1,1);
36 image->AllocateScalars();
37 vtkDataArray* array = 0;
41 array = vtkCharArray::New(); break;
43 array = vtkSignedCharArray::New(); break;
44 case VTK_UNSIGNED_CHAR:
45 array = vtkUnsignedCharArray::New(); break;
47 array = vtkShortArray::New(); break;
48 case VTK_UNSIGNED_SHORT:
49 array = vtkUnsignedShortArray::New(); break;
51 array = vtkIntArray::New(); break;
52 case VTK_UNSIGNED_INT:
53 array = vtkUnsignedIntArray::New(); break;
55 array = vtkLongArray::New(); break;
56 case VTK_UNSIGNED_LONG:
57 array = vtkUnsignedLongArray::New(); break;
59 array = vtkFloatArray::New(); break;
61 array = vtkDoubleArray::New(); break;
63 creaGlobalError("NewVtkImageDataFromRaw : type "
64 <<vtkTypeTraits<T>::SizedName()
65 <<" non implemented");
67 vtkDataArrayTemplate<T>* tarray
68 = dynamic_cast<vtkDataArrayTemplate<T>*>(array);
69 array->SetNumberOfComponents( 1 );
70 size_t size = (long)nx*(long)ny*(long)nz;
71 // The last param of SetArray is set to 1 to keep the class from deleting the array
72 // when it cleans up or reallocates memory.
74 if (do_not_desalloc) dndesa = 1;
75 tarray->SetArray( data, size, dndesa );
76 image->GetPointData( )->SetScalars( tarray );