2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */
27 #include <vtkDataArrayTemplate.h>
29 #include <vtkCharArray.h>
30 #include <vtkSignedCharArray.h>
31 #include <vtkUnsignedCharArray.h>
32 #include <vtkShortArray.h>
33 #include <vtkUnsignedShortArray.h>
34 #include <vtkIntArray.h>
35 #include <vtkUnsignedIntArray.h>
36 #include <vtkLongArray.h>
37 #include <vtkUnsignedLongArray.h>
38 #include <vtkFloatArray.h>
39 #include <vtkDoubleArray.h>
41 #include <vtkPointData.h>
42 #include <vtkTypeTraits.h>
43 #include <creaMessageManager.h>
47 /*CREA_EXPORT*/ vtkImageData* NewVtkImageDataFromRaw( T* data,
53 // std::cout << "NV "<<nx<<" " <<ny<<" " << nz<<std::endl;
54 // std::cout << vtkTypeTraits<T>::SizedName() << std::endl;
55 vtkImageData *image = vtkImageData::New();
57 // Shouldn't we pass NumberOfScalarComponents to deal with RGB, RGBA images as well? // JPR
59 image->SetNumberOfScalarComponents(1);
61 int vtktype = vtkTypeTraits<T>::VTKTypeID();
62 image->SetScalarType(vtktype);
63 image->SetDimensions(nx, ny ,nz);
64 image->SetSpacing(1, 1, 1);
65 image->AllocateScalars();
66 vtkDataArray* array = 0;
70 array = vtkCharArray::New(); break;
72 array = vtkSignedCharArray::New(); break;
73 case VTK_UNSIGNED_CHAR:
74 array = vtkUnsignedCharArray::New(); break;
76 array = vtkShortArray::New(); break;
77 case VTK_UNSIGNED_SHORT:
78 array = vtkUnsignedShortArray::New(); break;
80 array = vtkIntArray::New(); break;
81 case VTK_UNSIGNED_INT:
82 array = vtkUnsignedIntArray::New(); break;
84 array = vtkLongArray::New(); break;
85 case VTK_UNSIGNED_LONG:
86 array = vtkUnsignedLongArray::New(); break;
88 array = vtkFloatArray::New(); break;
90 array = vtkDoubleArray::New(); break;
92 creaGlobalError("NewVtkImageDataFromRaw : type "
93 <<vtkTypeTraits<T>::SizedName()
94 <<" non implemented");
96 vtkDataArrayTemplate<T>* tarray
97 = dynamic_cast<vtkDataArrayTemplate<T>*>(array);
98 array->SetNumberOfComponents( 1 );
99 size_t size = (long)nx*(long)ny*(long)nz;
100 // The last param of SetArray is set to 1 to keep the class from deleting the array
101 // when it cleans up or reallocates memory.
105 tarray->SetArray( data, size, dndesa );
106 image->GetPointData( )->SetScalars( tarray );