aimsdata 6.0.0
Neuroimaging data handling
giftiutil.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_IO_GIFTIUTIL_H
35#define AIMS_IO_GIFTIUTIL_H
36
37#include <aims/vector/vector.h>
38#include <aims/io/gifti.h>
39
40namespace aims
41{
42
43 template <typename U>
44 class _convertedNiftiValue // functor to allow partial specialization
45 {
46 public:
47 inline U operator () ( void* data, int index, int dtype )
48 {
49 switch( dtype )
50 {
51 case NIFTI_TYPE_UINT8:
52 return (U) reinterpret_cast<uint8_t *>(data)[index];
53 case NIFTI_TYPE_INT16:
54 return (U) reinterpret_cast<int16_t *>(data)[index];
55 case NIFTI_TYPE_INT32:
56 return (U) reinterpret_cast<int32_t *>(data)[index];
57 case NIFTI_TYPE_FLOAT32:
58 return (U) reinterpret_cast<float *>(data)[index];
59 case NIFTI_TYPE_FLOAT64:
60 return (U) reinterpret_cast<double *>(data)[index];
61 case NIFTI_TYPE_INT8:
62 return (U) reinterpret_cast<int8_t *>(data)[index];
63 case NIFTI_TYPE_UINT16:
64 return (U) reinterpret_cast<uint16_t *>(data)[index];
65 case NIFTI_TYPE_UINT32:
66 return (U) reinterpret_cast<uint32_t *>(data)[index];
67 case NIFTI_TYPE_INT64:
68 return (U) reinterpret_cast<int64_t *>(data)[index];
69 case NIFTI_TYPE_UINT64:
70 return (U) reinterpret_cast<uint64_t *>(data)[index];
71 default:
72 return U();
73 }
74 }
75 };
76
77
78 template <typename U, int D>
80 {
81 public:
82 inline AimsVector<U,D> operator () ( void* data, int index, int dtype )
83 {
85 int i;
86 for( i=0; i<D; ++i )
87 v[i] = _convertedNiftiValue<U>()( data, index * D + i, dtype );
88 return v;
89 }
90 };
91
92
93 template <typename U>
94 class _convertedNiftiArrayValue // functor to allow partial specialization
95 {
96 public:
97 inline U operator () ( void* data, int index, int dtype, size_t )
98 {
99 return _convertedNiftiValue<U>()( data, index, dtype );
100 }
101 };
102
103
104 template <typename U, int D>
106 {
107 public:
108 inline AimsVector<U,D> operator () ( void* data, int index, int dtype,
109 size_t size
110 )
111 {
113 int i;
114 for( i=0; i<D; ++i )
115 v[i] = _convertedNiftiValue<U>()( data, index + size * i, dtype );
116 return v;
117 }
118 };
119
120
121 template <typename U> inline
122 U convertedNiftiValue( void* data, int index, int dtype )
123 {
124 return _convertedNiftiValue<U>()( data, index, dtype );
125 }
126
127
128 template <typename U> inline
129 U convertedNiftiArrayValue( void* data, int index, int dtype, size_t size )
130 {
131 return _convertedNiftiArrayValue<U>()( data, index, dtype, size );
132 }
133
134
135 std::string niftiDataType( int dt );
136 int niftiIntDataType( const std::string & typecode );
137 std::string giftiTextureDataType( int dtype, int & ndim, int* dims,
138 int intent, int & ntime );
139
140}
141
142#endif
U operator()(void *data, int index, int dtype, size_t)
Definition giftiutil.h:97
U operator()(void *data, int index, int dtype)
Definition giftiutil.h:47
The class for EcatSino data write operation.
U convertedNiftiArrayValue(void *data, int index, int dtype, size_t size)
Definition giftiutil.h:129
std::string giftiTextureDataType(int dtype, int &ndim, int *dims, int intent, int &ntime)
int niftiIntDataType(const std::string &typecode)
std::string niftiDataType(int dt)
U convertedNiftiValue(void *data, int index, int dtype)
Definition giftiutil.h:122