forked from fristed/BEaST
-
Notifications
You must be signed in to change notification settings - Fork 6
/
basic.h
176 lines (145 loc) · 4.49 KB
/
basic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* basic.h
*
* Copyright 2011 Simon Fristed Eskildsen, Vladimir Fonov,
* Pierrick Coupé, Jose V. Manjon
*
* This file is part of mincbeast.
*
* mincbeast is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mincbeast is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mincbeast. If not, see <http://www.gnu.org/licenses/>.
*
* For questions and feedback, please contact:
* Simon Fristed Eskildsen <[email protected]>
*/
#ifndef BASIC_H
#define BASIC_H
#ifdef HAVE_MINC
#include <volume_io.h>
#endif //HAVE_MINC
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef STATUS_OK
#define STATUS_OK 0
#endif
#ifndef STATUS_ERR
#define STATUS_ERR -1
#endif
#ifndef STATUS_GIVE_UP
#define STATUS_GIVE_UP 5
#endif
#ifndef PI
#define PI 3.141592654
#endif
#ifndef EPSILON
#define EPSILON 0.0001
#endif
#define byte unsigned char
#ifndef ABS
#define ABS(a) ((a) > 0.0 ? (a) : -(a))
#endif
#ifndef SQR
#define SQR(a) ((a)*(a))
#endif
#ifdef MAX
#undef MAX
#endif
#define MAX( x, y ) ( ((x) >= (y)) ? (x) : (y) )
#ifdef MIN
#undef MIN
#endif
#define MIN( x, y ) ( ((x) <= (y)) ? (x) : (y) )
#ifdef MAX3
#undef MAX3
#endif
#define MAX3(a,b,c) MAX(MAX(a,b),c)
#ifdef MIN3
#undef MIN3
#endif
#define MIN3(a,b,c) MIN(MIN(a,b),c)
#ifdef CLAMP
#undef CLAMP
#endif
#define CLAMP(a,b,c) ( (a) < (b) ? (b) : ( (a) > (c) ? (c) : (a) ) )
#ifdef ROUND
#undef ROUND
#endif
#define ROUND( x ) ((long) ((x) + ( ((x) >= 0) ? 0.5 : (-0.5) ) ))
#ifndef HAVE_MINC
typedef int VIO_BOOL;
typedef double VIO_Real;
#endif
#ifndef _NETCDF_
typedef int nc_type;
#endif
#ifndef HAVE_MINC
#define NC_NAT 0 /* NAT = 'Not A Type' (c.f. NaN) */
#define NC_BYTE 1 /* signed 1 byte integer */
#define NC_CHAR 2 /* ISO/ASCII character */
#define NC_SHORT 3 /* signed 2 byte integer */
#define NC_INT 4 /* signed 4 byte integer */
#define NC_LONG NC_INT /* deprecated, but required for backward compatibility. */
#define NC_FLOAT 5 /* single precision floating point number */
#define NC_DOUBLE 6 /* double precision floating point number */
#define NC_UBYTE 7 /* unsigned 1 byte int */
#define NC_USHORT 8 /* unsigned 2-byte int */
#define NC_UINT 9 /* unsigned 4-byte int */
#define NC_INT64 10 /* signed 8-byte int */
#define NC_UINT64 11 /* unsigned 8-byte int */
#define NC_STRING 12 /* string */
#endif
#define NC_DOUBLE_SIZE sizeof(double)
typedef struct {
float x;
float y;
float z;
} point3D;
typedef struct {
int x;
int y;
int z;
} point3D_int;
typedef struct {
float *start;
float *step;
int *length;
char *history;
} image_metadata;
#define FALSE 0
#define TRUE 1
#define STATUS_OK 0
#define STATUS_ERR -1
#define STATUS_GIVE_UP 5
#define byte unsigned char
#define DTOR 0.017453293
#define SQR(a) ((a)*(a))
#define SET_3DPOINT(p,a,b,c) (p).x=(a); (p).y=(b); (p).z=(c)
#define ADD_3DPOINT(p,p1,p2) (p).x=(p1).x+(p2).x; (p).y=(p1).y+(p2).y; (p).z=(p1).z+(p2).z
#define SUB_3DPOINT(p,p1,p2) (p).x=(p1).x-(p2).x; (p).y=(p1).y-(p2).y; (p).z=(p1).z-(p2).z
#define DIV_3DPOINT(p,p1,a) (p).x=(p1).x/(a); (p).y=(p1).y/(a); (p).z=(p1).z/(a)
#define MUL_3DPOINT(p,p1,a) (p).x=(p1).x*(a); (p).y=(p1).y*(a); (p).z=(p1).z*(a)
#define COPY_3DPOINT(a,b) (a).x=(b).x; (a).y=(b).y; (a).z=(b).z
#define PRINTVEC(a) fprintf(stderr,"X:%3.5f Y:%3.5f Z:%3.5f\n",(a).x,(a).y, (a).z)
#define EUCLID_SQR_DIST(a,b,result) (result)=(SQR((a).x - (b).x) + SQR((a).y - (b).y) + SQR((a).z - (b).z))
#define GROUP_SET_VOXEL(vox,a,b,c) (vox).x=(a); (vox).y=(b); (vox).z=(c);
#define GROUP_GET_VOXEL_VALUE(val,vol,a,b,c,x,y,z) \
if(((a)>=0) && ((a)<x) && ((b)>=0) && ((b)<y) && \
((c)>=0) && ((c)<z)) \
val=(short)get_volume_voxel_value(vol,a, b, c,0,0); \
else val=255;
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
#define VEC_TRANS_MULT(t,v) ((t).x*(v).x+(t).y*(v).y+(t).z*(v).z)
#endif