Xmipp  v3.23.11-Nereus
xmipp_macros.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef CORE_XMIPP_MACROS_H
27 #define CORE_XMIPP_MACROS_H
28 
29 #ifndef __CYGWIN__
30 #ifdef __APPLE__
31 #include <limits.h>
32 #include <float.h>
33 #define MAXDOUBLE DBL_MAX
34 #define MINDOUBLE DBL_MIN
35 #else
36 #include <values.h>
37 #endif
38 #include <cmath>
39 #endif
40 
41 #ifndef MINFLOAT
42 #define MINFLOAT -1e30
43 #endif
44 #ifndef MAXFLOAT
45 #define MAXFLOAT 1e30
46 #endif
47 
48 
49 // Added for compatibility
50 #ifdef __CYGWIN__
51 #ifndef isnan
52 #define ISNAN(x) ((x)!=(x))
53 #else
54 #define ISNAN(x) isnan(x)
55 #endif
56 
57 // Added for compatibility
58 #ifndef isinf
59 #define ISINF(x) (!ISNAN (x) && ISNAN ((x) - (x)))
60 #else
61 #define ISINF(x) isinf(x)
62 #endif
63 #else
64 #define ISNAN(x) std::isnan(x)
65 #define ISINF(x) std::isinf(x)
66 #endif
67 
69 #ifdef __APPLE__
70 #include <math.h>
71 #define __MACH__
72 #endif
73 
75 #ifdef __MINGW32__
76 #include <windows.h>
77 #include <limits.h>
78 #include <time.h>
79 #endif
80 
82 #ifndef __MINGW32__
83 #define XMIPP_MMAP
84 #endif
85 
86 
89 
90 
92 
96 #ifndef PI
97 #define PI 3.14159265358979323846
98 #endif
99 
103 #ifndef HALFPI
104 #define HALFPI 1.57079632679489661923
105 #endif
106 
110 #ifndef TWOPI
111 #define TWOPI 6.283185307179586
112 #endif
113 
119 #define XMIPP_EQUAL_ACCURACY 1e-6
120 
122 #define XMIPP_EQUAL_REAL(x, y) ((fabs((x) - (y))) < XMIPP_EQUAL_ACCURACY)
123 #define XMIPP_EQUAL_ZERO(x) (ABS(x) < XMIPP_EQUAL_ACCURACY)
124 #define XMIPP_RANGE_INSIDE(x,min,max) ((x) >= (min) - XMIPP_EQUAL_ACCURACY && \
125  (x) < (max) + XMIPP_EQUAL_ACCURACY)
126 #define XMIPP_RANGE_OUTSIDE(x,min,max) ((x) < (min) - XMIPP_EQUAL_ACCURACY || \
127  (x) >= (max) + XMIPP_EQUAL_ACCURACY)
128 #define XMIPP_RANGE_OUTSIDE_FAST(x,min,max) ((x) < (min) || (x) >= (max))
129 
130 
132 
133 
141 #ifndef ABS
142 #define ABS(x) (((x) >= 0) ? (x) : (-(x)))
143 #endif
144 
154 #ifndef SGN
155 #define SGN(x) (((x) >= 0) ? 1 : -1)
156 #endif
157 
168 #ifndef SGN0
169 #define SGN0(x) (((x) >= 0) ? (((x) == 0) ? 0:1) : -1)
170 #endif
171 
180 #ifndef XMIPP_MIN
181 #define XMIPP_MIN(x, y) (((x) >= (y)) ? (y) : (x))
182 #endif
183 
192 #ifndef XMIPP_MAX
193 #define XMIPP_MAX(x,y) (((x)>=(y))?(x):(y))
194 #endif
195 
209 #ifndef ROUND
210 #define ROUND(x) (((x) > 0) ? (int)((x) + 0.5) : (int)((x) - 0.5))
211 #endif
212 
225 #define CEIL(x) (((x) == (int)(x)) ? (int)(x):(((x) > 0) ? (int)((x) + 1) : \
226  (int)(x)))
227 
240 #define FLOOR(x) (((x) == (int)(x)) ? (int)(x):(((x) > 0) ? (int)(x) : \
241  (int)((x) - 1)))
242 
247 #define FRACTION(x) ((x) - (int)(x))
248 
260 #define CLIP(x, x0, xF) (((x) < (x0)) ? (x0) : (((x) > (xF)) ? (xF) : (x)))
261 
272 #define intWRAP(x, x0, xF) (((x) >= (x0) && (x) <= (xF)) ? (x) : ((x) < (x0)) \
273  ? ((x) - (int)(((x) - (x0) + 1) / ((xF) - (x0) + 1) - 1) * \
274  ((xF) - (x0) + 1)) : ((x) - (int)(((x) - (xF) - 1) / ((xF) - (x0) + 1) \
275  + 1) * ((xF) - (x0) + 1)))
276 
280 #define fastIntWRAP(y, x, x0, xF) \
281 { \
282  if (((x) >= (x0) && (x) <= (xF))) \
283  y=x; \
284  else \
285  { \
286  int range=(xF) - (x0) + 1; \
287  if ((x)<(x0)) \
288  y=((x) - (int)(((x) - (x0) + 1) / range - 1) * range); \
289  else \
290  y=((x) - (int)(((x) - (xF) - 1) / range + 1) * range); \
291  } \
292 }
293 
304 #define realWRAP(x, x0, xF) ((x) - floor(((x) - (x0)) / ((xF) - (x0))) * ((xF) - (x0)))
305 
312 #define DEG2RAD(d) ((d) * PI / 180)
313 
320 #define RAD2DEG(r) ((r) * 180 / PI)
321 
329 #define COSD(x) cos(PI * (x) / 180.)
330 
338 #define ACOSD(x) acos((x)) * 180. / PI
339 
347 #define SIND(x) sin(PI * (x) / 180.)
348 
356 #define ASIND(x) asin((x)) * 180. / PI
357 
362 #define SINC(x) (((x) < 0.0001 && (x) > -0.0001) ? 1 : sin(PI * (x)) \
363  / (PI * (x)))
364 
374 #define NEXT_POWER_OF_2(x) pow(2, ceil(log((double) x) / log(2.0)-XMIPP_EQUAL_ACCURACY) )
375 
381 #define LIN_INTERP(a, l, h) ((l) + ((h) - (l)) * (a))
382 
387 #define XOR(a, b) (((a) && !(b)) || (!(a) && (b)))
388 
389 
391 
392 
394 #define SPEED_UP_temps0 \
395  double spduptmp0;
396 
398 #define SPEED_UP_temps01 \
399  SPEED_UP_temps0; \
400  double spduptmp1;
401 
403 #define SPEED_UP_temps012 \
404  SPEED_UP_temps01; \
405  double spduptmp2;
406 
408 #define SPEED_UP_tempsInt \
409  int ispduptmp0, ispduptmp1, ispduptmp2, \
410  ispduptmp3, ispduptmp4, ispduptmp5;
411 
413 #define SPEED_UP_tempsDouble \
414  SPEED_UP_temps012; \
415  double spduptmp3, spduptmp4, spduptmp5, \
416  spduptmp6, spduptmp7, spduptmp8; \
417 
418 
419 #define SPEED_UP_temps \
420  SPEED_UP_tempsDouble; \
421  SPEED_UP_tempsInt
422 
428 #define SWAP(a, b, tmp) {\
429  tmp = a; \
430  a = b; \
431  b = tmp; }
432 
439 #define FIRST_XMIPP_INDEX(size) -(int)((float) (size) / 2.0)
440 
448 #define LAST_XMIPP_INDEX(size) FIRST_XMIPP_INDEX(size) + (size) - 1
449 
458 #define SUM_INIT(var, value) if (first_time) var = (value); else var += (value);
459 #define SUM_INIT_COND(var, value, cond) if (cond) var = (value); else var += (value);
460 
464 #ifdef __GNUC__
465 # define XMIPP_ASSUME_ALIGNED(ptr, alignment) (__builtin_assume_aligned(ptr, alignment))
466 #else
467 # define XMIPP_ASSUME_ALIGNED(ptr, alignment) (ptr)
468 #endif
469 
471 
472 #endif