Xmipp  v3.23.11-Nereus
Collaboration diagram for Macros:

Constants

#define PI   3.14159265358979323846
 
#define HALFPI   1.57079632679489661923
 
#define TWOPI   6.283185307179586
 
#define XMIPP_EQUAL_ACCURACY   1e-6
 
#define XMIPP_EQUAL_REAL(x, y)   ((fabs((x) - (y))) < XMIPP_EQUAL_ACCURACY)
 
#define XMIPP_EQUAL_ZERO(x)   (ABS(x) < XMIPP_EQUAL_ACCURACY)
 
#define XMIPP_RANGE_INSIDE(x, min, max)
 
#define XMIPP_RANGE_OUTSIDE(x, min, max)
 
#define XMIPP_RANGE_OUTSIDE_FAST(x, min, max)   ((x) < (min) || (x) >= (max))
 

Numerical functions

#define ABS(x)   (((x) >= 0) ? (x) : (-(x)))
 
#define SGN(x)   (((x) >= 0) ? 1 : -1)
 
#define SGN0(x)   (((x) >= 0) ? (((x) == 0) ? 0:1) : -1)
 
#define XMIPP_MIN(x, y)   (((x) >= (y)) ? (y) : (x))
 
#define XMIPP_MAX(x, y)   (((x)>=(y))?(x):(y))
 
#define ROUND(x)   (((x) > 0) ? (int)((x) + 0.5) : (int)((x) - 0.5))
 
#define CEIL(x)
 
#define FLOOR(x)
 
#define FRACTION(x)   ((x) - (int)(x))
 
#define CLIP(x, x0, xF)   (((x) < (x0)) ? (x0) : (((x) > (xF)) ? (xF) : (x)))
 
#define intWRAP(x, x0, xF)
 
#define fastIntWRAP(y, x, x0, xF)
 
#define realWRAP(x, x0, xF)   ((x) - floor(((x) - (x0)) / ((xF) - (x0))) * ((xF) - (x0)))
 
#define DEG2RAD(d)   ((d) * PI / 180)
 
#define RAD2DEG(r)   ((r) * 180 / PI)
 
#define COSD(x)   cos(PI * (x) / 180.)
 
#define ACOSD(x)   acos((x)) * 180. / PI
 
#define SIND(x)   sin(PI * (x) / 180.)
 
#define ASIND(x)   asin((x)) * 180. / PI
 
#define SINC(x)
 
#define NEXT_POWER_OF_2(x)   pow(2, ceil(log((double) x) / log(2.0)-XMIPP_EQUAL_ACCURACY) )
 
#define LIN_INTERP(a, l, h)   ((l) + ((h) - (l)) * (a))
 
#define XOR(a, b)   (((a) && !(b)) || (!(a) && (b)))
 

Miscellaneous

#define SPEED_UP_temps0   double spduptmp0;
 
#define SPEED_UP_temps01
 
#define SPEED_UP_temps012
 
#define SPEED_UP_tempsInt
 
#define SPEED_UP_tempsDouble
 
#define SPEED_UP_temps
 
#define SWAP(a, b, tmp)
 
#define FIRST_XMIPP_INDEX(size)   -(int)((float) (size) / 2.0)
 
#define LAST_XMIPP_INDEX(size)   FIRST_XMIPP_INDEX(size) + (size) - 1
 
#define SUM_INIT(var, value)   if (first_time) var = (value); else var += (value);
 
#define SUM_INIT_COND(var, value, cond)   if (cond) var = (value); else var += (value);
 
#define XMIPP_ASSUME_ALIGNED(ptr, alignment)   (ptr)
 

Detailed Description

Macro Definition Documentation

◆ ABS

#define ABS (   x)    (((x) >= 0) ? (x) : (-(x)))

Absolute value

Valid for any kind of number (int, short, float, etc)

x = ABS(x);

Definition at line 142 of file xmipp_macros.h.

◆ ACOSD

#define ACOSD (   x)    acos((x)) * 180. / PI

ArcCosine in degrees

if (ACOSD(0.5) == 60)
std::cout << "This is in degrees!\n";

Definition at line 338 of file xmipp_macros.h.

◆ ASIND

#define ASIND (   x)    asin((x)) * 180. / PI

ArcSine in degrees

if (ASIND(0.5) == 30.)
std::cout << "This is in degrees!\n";

Definition at line 356 of file xmipp_macros.h.

◆ CEIL

#define CEIL (   x)
Value:
(((x) == (int)(x)) ? (int)(x):(((x) > 0) ? (int)((x) + 1) : \
(int)(x)))
doublereal * x

Round to next larger integer.

Valid for any kind of numbers (int, short, float, etc). The result is of type integer.

a = CEIL(-0.8); // a = 0
a = CEIL(-0.2); // a = 0
a = CEIL(0.2); // a = 1
a = CEIL(0.8); // a = 1

Definition at line 225 of file xmipp_macros.h.

◆ CLIP

#define CLIP (   x,
  x0,
  xF 
)    (((x) < (x0)) ? (x0) : (((x) > (xF)) ? (xF) : (x)))

Clip in a saturation fashion

CLIP is a macro which acts like a saturation curve, a value x is "clipped" to a range defined by x0 and xF, for example the output values for the following x and CLIP(x,-2,2) would be

x = ... -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 ...
output = ... -2 -2 -2 -2 -2 -2 -2 -1 0 1 2 2 2 2 2 2 2 ...

Definition at line 260 of file xmipp_macros.h.

◆ COSD

#define COSD (   x)    cos(PI * (x) / 180.)

Cosine in degrees

if (COSD(90) == 0)
std::cout << "This is in degrees!\n";

Definition at line 329 of file xmipp_macros.h.

◆ DEG2RAD

#define DEG2RAD (   d)    ((d) * PI / 180)

Degrees to radians

angle_in_radians = DEG2RAD(ang_in_degrees);

Definition at line 312 of file xmipp_macros.h.

◆ fastIntWRAP

#define fastIntWRAP (   y,
  x,
  x0,
  xF 
)
Value:
{ \
if (((x) >= (x0) && (x) <= (xF))) \
y=x; \
else \
{ \
int range=(xF) - (x0) + 1; \
if ((x)<(x0)) \
y=((x) - (int)(((x) - (x0) + 1) / range - 1) * range); \
else \
y=((x) - (int)(((x) - (xF) - 1) / range + 1) * range); \
} \
}
doublereal * x
#define x0
#define xF

Fast wrapping for integers

y=intWRAP(x,x0,xF)

Definition at line 280 of file xmipp_macros.h.

◆ FIRST_XMIPP_INDEX

#define FIRST_XMIPP_INDEX (   size)    -(int)((float) (size) / 2.0)

Starting point for Xmipp volume/image

Given a size (in some direction), this function returns the first index for a volume/image/array with this size. The formula is -(int) ((float) (size) / 2.0)

Definition at line 439 of file xmipp_macros.h.

◆ FLOOR

#define FLOOR (   x)
Value:
(((x) == (int)(x)) ? (int)(x):(((x) > 0) ? (int)(x) : \
(int)((x) - 1)))
doublereal * x

Round to next smaller integer

Valid for any kind of numbers (int, short, float, etc). The result is of type integer.

a = FLOOR(-0.8); // a = -1
a = FLOOR(-0.2); // a = -1
a = FLOOR(0.2); // a = 0
a = FLOOR(0.8); // a = 0

Definition at line 240 of file xmipp_macros.h.

◆ FRACTION

#define FRACTION (   x)    ((x) - (int)(x))

Return the fractional part of a value

The fractional part of 3.7 is 0.7 and of -3.7 is -0.7.

Definition at line 247 of file xmipp_macros.h.

◆ HALFPI

#define HALFPI   1.57079632679489661923

Pi/2

Definition at line 104 of file xmipp_macros.h.

◆ intWRAP

#define intWRAP (   x,
  x0,
  xF 
)
Value:
(((x) >= (x0) && (x) <= (xF)) ? (x) : ((x) < (x0)) \
? ((x) - (int)(((x) - (x0) + 1) / ((xF) - (x0) + 1) - 1) * \
((xF) - (x0) + 1)) : ((x) - (int)(((x) - (xF) - 1) / ((xF) - (x0) + 1) \
+ 1) * ((xF) - (x0) + 1)))
doublereal * x
#define x0
#define xF

Wrapping for integers

intWRAP performs a wrapping in the integer set, when the cycle is finsihed it begins again. For example, for intWRAP(x,-2,2) would be

x = ... -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 ...
output = ... 2 -2 -1 0 1 2 -2 -1 0 1 2 -2 -1 0 1 2 -2 ...

Definition at line 272 of file xmipp_macros.h.

◆ LAST_XMIPP_INDEX

#define LAST_XMIPP_INDEX (   size)    FIRST_XMIPP_INDEX(size) + (size) - 1

Starting point for Xmipp volume/image

Given a size (in some direction), this function returns the first index for a volume/image/array with this size. The formula is FIRST_XMIPP_INDEX(size) + (size) - 1

Definition at line 448 of file xmipp_macros.h.

◆ LIN_INTERP

#define LIN_INTERP (   a,
  l,
 
)    ((l) + ((h) - (l)) * (a))

Linear interpolation

From low (when a=0) to high (when a=1). The following value is returned (equal to (a*h)+((1-a)*l)

Definition at line 381 of file xmipp_macros.h.

◆ NEXT_POWER_OF_2

#define NEXT_POWER_OF_2 (   x)    pow(2, ceil(log((double) x) / log(2.0)-XMIPP_EQUAL_ACCURACY) )

Returns next positive power of 2

It is supposed that the given number is positive although it's not needed to be an integer

next_power = NEXT_POWER_OF_2(1000); // next_power = 1024

Definition at line 374 of file xmipp_macros.h.

◆ PI

#define PI   3.14159265358979323846

Pi

Definition at line 97 of file xmipp_macros.h.

◆ RAD2DEG

#define RAD2DEG (   r)    ((r) * 180 / PI)

Radians to degrees

angle_in_degrees = RAD2DEG(ang_in_radians);

Definition at line 320 of file xmipp_macros.h.

◆ realWRAP

#define realWRAP (   x,
  x0,
  xF 
)    ((x) - floor(((x) - (x0)) / ((xF) - (x0))) * ((xF) - (x0)))

Wrapping for real numbers

realWRAP is used to keep a floating number between a range with a wrapping fashion. For instance, it is used in trigonometry to say that an angle of 5*PI is the same as PI, ie, to keep an angle in the range 0...2*PI

Corrected_angle = realWRAP(angle, 0, 2*PI);

Definition at line 304 of file xmipp_macros.h.

◆ ROUND

#define ROUND (   x)    (((x) > 0) ? (int)((x) + 0.5) : (int)((x) - 0.5))

Round to next integer

Valid for any kind of numbers (int, short, float, etc). The result is of type integer.

a = ROUND(-0.8); // a = -1
a = ROUND(-0.2); // a = 0
a = ROUND(0.2); // a = 0
a = ROUND(0.8); // a = 1

Definition at line 210 of file xmipp_macros.h.

◆ SGN

#define SGN (   x)    (((x) >= 0) ? 1 : -1)

Sign of

Valid for any kind of number (int, short, float, etc). It returns +1 or -1

if (SGN(x) == -1)
std::cout << "x is negative" << std::endl;

Definition at line 155 of file xmipp_macros.h.

◆ SGN0

#define SGN0 (   x)    (((x) >= 0) ? (((x) == 0) ? 0:1) : -1)

Sign of, considering 0 as 0

Valid for any kind of number (int, short, float, etc). It returns +1 if the number is positive, -1 if the number is negative, and 0 if the number is 0.

if (SGN0(x) == -1)
std::cout << "x is negative" << std::endl;

Definition at line 169 of file xmipp_macros.h.

◆ SINC

#define SINC (   x)
Value:
(((x) < 0.0001 && (x) > -0.0001) ? 1 : sin(PI * (x)) \
/ (PI * (x)))
doublereal * x
#define PI
Definition: xmipp_macros.h:97

SINC function

The sinc function is defined as sin(PI*x)/(PI*x).

Definition at line 362 of file xmipp_macros.h.

◆ SIND

#define SIND (   x)    sin(PI * (x) / 180.)

Sine in degrees

if (SIND(90) == 1)
std::cout << "This is in degrees!\n";

Definition at line 347 of file xmipp_macros.h.

◆ SPEED_UP_temps

#define SPEED_UP_temps
Value:
SPEED_UP_tempsInt
#define SPEED_UP_tempsDouble
Definition: xmipp_macros.h:413

Speed up temporary variables

Definition at line 419 of file xmipp_macros.h.

◆ SPEED_UP_temps0

#define SPEED_UP_temps0   double spduptmp0;

Speed up temporary variables

Definition at line 394 of file xmipp_macros.h.

◆ SPEED_UP_temps01

#define SPEED_UP_temps01
Value:
double spduptmp1;
#define SPEED_UP_temps0
Definition: xmipp_macros.h:394

Speed up temporary variables

Definition at line 398 of file xmipp_macros.h.

◆ SPEED_UP_temps012

#define SPEED_UP_temps012
Value:
double spduptmp2;
#define SPEED_UP_temps01
Definition: xmipp_macros.h:398

Speed up temporary variables

Definition at line 403 of file xmipp_macros.h.

◆ SPEED_UP_tempsDouble

#define SPEED_UP_tempsDouble
Value:
double spduptmp3, spduptmp4, spduptmp5, \
spduptmp6, spduptmp7, spduptmp8; \
#define SPEED_UP_temps012
Definition: xmipp_macros.h:403

Speed up temporary variables

Definition at line 413 of file xmipp_macros.h.

◆ SPEED_UP_tempsInt

#define SPEED_UP_tempsInt
Value:
int ispduptmp0, ispduptmp1, ispduptmp2, \
ispduptmp3, ispduptmp4, ispduptmp5;

Speed up temporary variables

Definition at line 408 of file xmipp_macros.h.

◆ SUM_INIT

#define SUM_INIT (   var,
  value 
)    if (first_time) var = (value); else var += (value);

Sum values, initializing with the first one

Inside a loop, the first time the value will be assigned and after that it will be summed. This macro assumes there exists a boolean flag named first_time The second macro is the same but allowing a diffent flag name

Definition at line 458 of file xmipp_macros.h.

◆ SUM_INIT_COND

#define SUM_INIT_COND (   var,
  value,
  cond 
)    if (cond) var = (value); else var += (value);

Definition at line 459 of file xmipp_macros.h.

◆ SWAP

#define SWAP (   a,
  b,
  tmp 
)
Value:
{\
tmp = a; \
a = b; \
b = tmp; }
doublereal * b
doublereal * a

Swap two values

It uses a temporal variable which must be of the same type as the two parameters

Definition at line 428 of file xmipp_macros.h.

◆ TWOPI

#define TWOPI   6.283185307179586

2 * Pi

Definition at line 111 of file xmipp_macros.h.

◆ XMIPP_ASSUME_ALIGNED

#define XMIPP_ASSUME_ALIGNED (   ptr,
  alignment 
)    (ptr)

XMIPP_ASSUME_ALIGNED(ptr, alignment) Tell compiler to assume, that ptr has given alignment, even if the compiler can't prove it. This serves as a performance hint, useful to allow auto-vectorization.

Definition at line 467 of file xmipp_macros.h.

◆ XMIPP_EQUAL_ACCURACY

#define XMIPP_EQUAL_ACCURACY   1e-6

Equal accuracy

In a comparison if two values are closer than this epsilon they are said to be the same. Actually set to 1e-6

Definition at line 119 of file xmipp_macros.h.

◆ XMIPP_EQUAL_REAL

#define XMIPP_EQUAL_REAL (   x,
  y 
)    ((fabs((x) - (y))) < XMIPP_EQUAL_ACCURACY)

Compare if two real values are equals

Definition at line 122 of file xmipp_macros.h.

◆ XMIPP_EQUAL_ZERO

#define XMIPP_EQUAL_ZERO (   x)    (ABS(x) < XMIPP_EQUAL_ACCURACY)

Definition at line 123 of file xmipp_macros.h.

◆ XMIPP_MAX

#define XMIPP_MAX (   x,
  y 
)    (((x)>=(y))?(x):(y))

Maximum

Valid for any kind of numbers (int, short, float, etc).

max_val = XMIPP_MAX(x, y);

Definition at line 193 of file xmipp_macros.h.

◆ XMIPP_MIN

#define XMIPP_MIN (   x,
  y 
)    (((x) >= (y)) ? (y) : (x))

Minimum

Valid for any kind of numbers (int, short, float, etc).

min_val = XMIPP_MIN(x, y);

Definition at line 181 of file xmipp_macros.h.

◆ XMIPP_RANGE_INSIDE

#define XMIPP_RANGE_INSIDE (   x,
  min,
  max 
)
Value:
((x) >= (min) - XMIPP_EQUAL_ACCURACY && \
void min(Image< double > &op1, const Image< double > &op2)
doublereal * x
#define XMIPP_EQUAL_ACCURACY
Definition: xmipp_macros.h:119
void max(Image< double > &op1, const Image< double > &op2)

Definition at line 124 of file xmipp_macros.h.

◆ XMIPP_RANGE_OUTSIDE

#define XMIPP_RANGE_OUTSIDE (   x,
  min,
  max 
)
Value:
((x) < (min) - XMIPP_EQUAL_ACCURACY || \
void min(Image< double > &op1, const Image< double > &op2)
doublereal * x
#define XMIPP_EQUAL_ACCURACY
Definition: xmipp_macros.h:119
void max(Image< double > &op1, const Image< double > &op2)

Definition at line 126 of file xmipp_macros.h.

◆ XMIPP_RANGE_OUTSIDE_FAST

#define XMIPP_RANGE_OUTSIDE_FAST (   x,
  min,
  max 
)    ((x) < (min) || (x) >= (max))

Definition at line 128 of file xmipp_macros.h.

◆ XOR

#define XOR (   a,
  b 
)    (((a) && !(b)) || (!(a) && (b)))

XOR

Logical Xor

Definition at line 387 of file xmipp_macros.h.