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>
21 /*CREA_EXPORT*/ vtkImageData* NewVtkImageDataFromRaw( T* data,
27 // std::cout << "NV "<<nx<<" " <<ny<<" " << nz<<std::endl;
28 // std::cout << vtkTypeTraits<T>::SizedName() << std::endl;
29 vtkImageData *image = vtkImageData::New();
31 // Shouldn't we pass NumberOfScalarComponents to deal with RGB, RGBA images as well? // JPR
33 image->SetNumberOfScalarComponents(1);
35 int vtktype = vtkTypeTraits<T>::VTKTypeID();
36 image->SetScalarType(vtktype);
37 image->SetDimensions(nx, ny ,nz);
38 image->SetSpacing(1, 1, 1);
39 image->AllocateScalars();
40 vtkDataArray* array = 0;
44 array = vtkCharArray::New(); break;
46 array = vtkSignedCharArray::New(); break;
47 case VTK_UNSIGNED_CHAR:
48 array = vtkUnsignedCharArray::New(); break;
50 array = vtkShortArray::New(); break;
51 case VTK_UNSIGNED_SHORT:
52 array = vtkUnsignedShortArray::New(); break;
54 array = vtkIntArray::New(); break;
55 case VTK_UNSIGNED_INT:
56 array = vtkUnsignedIntArray::New(); break;
58 array = vtkLongArray::New(); break;
59 case VTK_UNSIGNED_LONG:
60 array = vtkUnsignedLongArray::New(); break;
62 array = vtkFloatArray::New(); break;
64 array = vtkDoubleArray::New(); break;
66 creaGlobalError("NewVtkImageDataFromRaw : type "
67 <<vtkTypeTraits<T>::SizedName()
68 <<" non implemented");
70 vtkDataArrayTemplate<T>* tarray
71 = dynamic_cast<vtkDataArrayTemplate<T>*>(array);
72 array->SetNumberOfComponents( 1 );
73 size_t size = (long)nx*(long)ny*(long)nz;
74 // The last param of SetArray is set to 1 to keep the class from deleting the array
75 // when it cleans up or reallocates memory.
79 tarray->SetArray( data, size, dndesa );
80 image->GetPointData( )->SetScalars( tarray );