gft_common.h
Go to the documentation of this file.
1 
6 #ifndef _GFT_COMMON_H_
7 #define _GFT_COMMON_H_
8 
9 extern "C" {
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <malloc.h>
13 #include <math.h>
14 #include <string.h>
15 #include <limits.h>
16 #include <float.h>
17 #include <sys/time.h>
18 
19 #include <xmmintrin.h>
20 }
21 
25 namespace gft{
26 
27 /* Error messages */
28 #define MSG1 "Cannot allocate memory space"
29 #define MSG2 "Cannot open file"
30 #define MSG3 "Invalid option"
31 #define MSG4 "Could not locate nifti header"
32 #define MSG5 "Nifti-1 data type not supported"
33 
34 /* Common data types to all programs */
35 #ifndef __cplusplus
36 typedef enum boolean {false,true} bool;
37 #endif
38 typedef unsigned short ushort;
39 typedef unsigned int uint;
40 typedef unsigned char uchar;
41 
42 typedef struct timeval timer;
43 
44 
45 /* Common definitions */
46 #define PI 3.1415926536
47 #define INTERIOR 0
48 #define EXTERIOR 1
49 #define BOTH 2
50 #define WHITE 0
51 #define GRAY 1
52 #define BLACK 2
53 #define NIL -1
54 #define INCREASING 1
55 #define DECREASING 0
56 #define Epsilon 1E-05
57 
58 /* Common operations */
59 
64 #ifndef MAX
65 #define MAX(x,y) (((x) > (y))?(x):(y))
66 #endif
67 
71 #ifndef MIN
72 #define MIN(x,y) (((x) < (y))?(x):(y))
73 #endif
74 
75 #define ROUND(x) ((x < 0)?(int)(x-0.5):(int)(x+0.5))
76 
77 #define SIGN(x) ((x >= 0)?1:-1)
78 
79 
83  typedef float v4sf __attribute__ ((vector_size(16),aligned(16)));
84 
88  typedef int v4si __attribute__ ((vector_size(16),aligned(16)));
89 
93  typedef uchar v8qi __attribute__ ((vector_size(8),aligned(16)));
94 
98  typedef uchar v16qi __attribute__ ((vector_size(16),aligned(16)));
99 
103  typedef ushort v8hi __attribute__ ((vector_size(16),aligned(16)));
104 
105 
106  typedef union _voxel {
108  int data[4];
109  struct{ int x,y,z; } c;
110  } Voxel;
111 
112 
113  typedef struct _pixel {
114  int x,y;
115  } Pixel;
116 
117 
118  char *AllocCharArray(int n); /* It allocates 1D array of n characters */
119 
120 
124  uchar *AllocUCharArray(int n);
125 
129  ushort *AllocUShortArray(int n);
130 
131  uint *AllocUIntArray(int n); /* It allocates 1D array of n uints */
132 
136  int *AllocIntArray(int n);
137 
141  float *AllocFloatArray(int n);
142 
143  double *AllocDoubleArray(int n);/* It allocates 1D array of n doubles */
144 
145  void FreeIntArray(int **a);
146  void FreeFloatArray(float **a);
147  void FreeUCharArray(uchar **a);
148  void FreeUShortArray(ushort **a);
149 
153  void Error(char *msg,char *func);
154 
158  void Warning(char *msg,char *func);
159 
163  inline void SwapInt(int *a, int *b){
164  int c;
165  c = *a;
166  *a = *b;
167  *b = c;
168  }
169 
173  inline void SwapFloat(float *a, float *b){
174  float c;
175  c = *a;
176  *a = *b;
177  *b = c;
178  }
179 
180 
181  int NCFgets(char *s, int m, FILE *f); /* It skips # comments */
182 
188  int RandomInteger (int low, int high);
189  void RandomSeed();
190 
191 } //end gft namespace
192 
193 #endif
194 
double * AllocDoubleArray(int n)
Definition: gft_common.cpp:104
float * AllocFloatArray(int n)
It allocates 1D array of n floats.
Definition: gft_common.cpp:89
void Error(char *msg, char *func)
It prints error message and exits the program.
Definition: gft_common.cpp:132
float v4sf
Vector of four single floats.
Definition: gft_common.h:83
ushort v8hi
Vector of eight unsigned short integers.
Definition: gft_common.h:103
uchar * AllocUCharArray(int n)
It allocates 1D array of n characters.
Definition: gft_common.cpp:23
int y
Definition: gft_common.h:109
Definition: gft_common.h:106
enum gft::boolean bool
v4si v
Definition: gft_common.h:107
int y
Definition: gft_common.h:114
Definition: gft_common.h:113
void SwapFloat(float *a, float *b)
It changes content between a and b.
Definition: gft_common.h:173
ushort * AllocUShortArray(int n)
It allocates 1D array of n ushorts.
Definition: gft_common.cpp:42
void FreeUCharArray(uchar **a)
Definition: gft_common.cpp:122
void FreeFloatArray(float **a)
Definition: gft_common.cpp:117
char * AllocCharArray(int n)
Definition: gft_common.cpp:6
unsigned char uchar
Definition: gft_common.h:40
struct timeval timer
Definition: gft_common.h:42
int NCFgets(char *s, int m, FILE *f)
Definition: gft_common.cpp:144
uchar v8qi
Vector of eight unsigned 8-bit integers.
Definition: gft_common.h:93
void Warning(char *msg, char *func)
It prints warning message and leaves the routine.
Definition: gft_common.cpp:138
int v4si
Vector of four single integers.
Definition: gft_common.h:88
int z
Definition: gft_common.h:109
union gft::_voxel Voxel
int x
Definition: gft_common.h:109
struct gft::_voxel::@2 c
void FreeUShortArray(ushort **a)
Definition: gft_common.cpp:127
uint * AllocUIntArray(int n)
Definition: gft_common.cpp:53
double f(double t)
Definition: gft_color.cpp:15
int data[4]
Definition: gft_common.h:108
struct gft::_pixel Pixel
uchar v16qi
Vector of sixteen unsigned 8-bit integers.
Definition: gft_common.h:98
unsigned short ushort
Definition: gft_common.h:38
int x
Definition: gft_common.h:114
void RandomSeed()
Definition: gft_common.cpp:165
int RandomInteger(int low, int high)
Definition: gft_common.cpp:156
void SwapInt(int *a, int *b)
It changes content between a and b.
Definition: gft_common.h:163
int * AllocIntArray(int n)
It allocates 1D array of n integers.
Definition: gft_common.cpp:70
unsigned int uint
Definition: gft_common.h:39
void FreeIntArray(int **a)
Definition: gft_common.cpp:112