Woolz Image Processing
Version 1.8.3
WlzMacro.h
Go to the documentation of this file.
1
#ifndef WLZMACRO_H
2
#define WLZMACRO_H
3
#if defined(__GNUC__)
4
#ident "University of Edinburgh $Id: cdd543f95c0f143485246493458d74bc07f5d2c4 $"
5
#else
6
static
char
_WlzMacro_h[] =
"University of Edinburgh $Id: cdd543f95c0f143485246493458d74bc07f5d2c4 $"
;
7
#endif
8
/*!
9
* \file libWlz/WlzMacro.h
10
* \author Bill Hill
11
* \date March 1999
12
* \version $Id: cdd543f95c0f143485246493458d74bc07f5d2c4 $
13
* \par
14
* Address:
15
* MRC Human Genetics Unit,
16
* MRC Institute of Genetics and Molecular Medicine,
17
* University of Edinburgh,
18
* Western General Hospital,
19
* Edinburgh, EH4 2XU, UK.
20
* \par
21
* Copyright (C), [2012],
22
* The University Court of the University of Edinburgh,
23
* Old College, Edinburgh, UK.
24
*
25
* This program is free software; you can redistribute it and/or
26
* modify it under the terms of the GNU General Public License
27
* as published by the Free Software Foundation; either version 2
28
* of the License, or (at your option) any later version.
29
*
30
* This program is distributed in the hope that it will be
31
* useful but WITHOUT ANY WARRANTY; without even the implied
32
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
33
* PURPOSE. See the GNU General Public License for more
34
* details.
35
*
36
* You should have received a copy of the GNU General Public
37
* License along with this program; if not, write to the Free
38
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39
* Boston, MA 02110-1301, USA.
40
* \brief Woolz C pre-processor directives, eg macros.
41
* \ingroup Wlz
42
*/
43
44
#ifndef WLZ_EXT_BIND
45
#ifdef __cplusplus
46
extern
"C"
{
47
#endif
/* __cplusplus */
48
#endif
/* WLZ_EXT_BIND */
49
50
#define WLZ_VERSION PACKAGE_VERSION
51
52
/************************************************************************
53
* Simple macros not always available elsewhere. *
54
************************************************************************/
55
#define WLZ_MAX(X,Y) (((X)>=(Y))?(X):(Y))
56
#define WLZ_MIN(X,Y) (((X)<=(Y))?(X):(Y))
57
#define WLZ_ABS(X) (((X)>0)?(X):(-(X)))
58
#define WLZ_NINT(X) ((int)(((X)<0)?((X)-(0.5)):((X)+(0.5))))
59
#define WLZ_SIGN(X) (((X)<0)?-1:((X)>0)?1:0)
60
61
/*!
62
* \def WLZ_SWAP(T,A,B)
63
* \brief Swaps the values of the variables A and B using the
64
* temporary variable T.
65
*/
66
#define WLZ_SWAP(T,A,B) {(T)=(A);(A)=(B);(B)=(T);}
67
68
/************************************************************************
69
* Pixel value clamping. Used in WlzGreyScan() and WlzConvertPix(). *
70
************************************************************************/
71
/*!
72
* \def WLZ_CLAMP(V,N,X)
73
* \brief Clamps the value of V such that V >= N and V <= X.
74
*/
75
#define WLZ_CLAMP(V,N,X) (((V)<(N))?(N):((V)>(X))?(X):(V))
76
77
/*!
78
* \def WLZ_CLAMP_DOUBLE_TO_GREYP(U,V,G)
79
* \brief Clamps a single double value from V setting U offset by
80
* F such that U >= MIN and U <= MAX where MIN and MAX are
81
* the minimum and maximum values for the grey type G.
82
* The only valid types for G are: WLZ_GREY_UBYTE,
83
* WLZ_GREY_SHORT, WLZ_GREY_INT, WLZ_GREY_FLOAT, and
84
* WLZ_GREY_DOUBLE; there is no check that G is none of
85
* these types.
86
*/
87
#define WLZ_CLAMP_DOUBLE_TO_GREYP(U,F,V,G) \
88
{\
89
switch((G))\
90
{\
91
case WLZ_GREY_UBYTE:\
92
(U).inp[(F)]=WLZ_CLAMP((V),0,255);\
93
break;\
94
case WLZ_GREY_SHORT:\
95
(U).shp[(F)]=WLZ_CLAMP((V),SHRT_MIN,SHRT_MAX);\
96
break;\
97
case WLZ_GREY_INT:\
98
(U).inp[(F)]=WLZ_CLAMP((V),-FLT_MAX,FLT_MAX);\
99
break;\
100
case WLZ_GREY_FLOAT:\
101
(U).flp[(F)]=WLZ_CLAMP((V),-FLT_MAX,FLT_MAX);\
102
break;\
103
case WLZ_GREY_DOUBLE:\
104
(U).dbp[(F)]=(V);\
105
break;\
106
default:\
107
break;\
108
}\
109
}\
110
111
/************************************************************************
112
* Math constants. *
113
************************************************************************/
114
#define WLZ_M_E (2.7182818284590452354)0
115
#define WLZ_M_LOG2E (1.4426950408889634074)
116
#define WLZ_M_LOG2E (1.4426950408889634074)
117
#define WLZ_M_LOG10E (0.43429448190325182765)
118
#define WLZ_M_LN2 (0.69314718055994530942)
119
#define WLZ_M_LN10 (2.30258509299404568402)
120
#define WLZ_M_PI (3.14159265358979323846)
121
#define WLZ_M_PI_2 (1.57079632679489661923)
122
#define WLZ_M_PI_4 (0.78539816339744830961)
123
#define WLZ_M_1_PI (0.31830988618379067154)
124
#define WLZ_M_2_PI (0.63661977236758134308)
125
#define WLZ_M_2_SQRTPI (1.12837916709551257390)
126
#define WLZ_M_SQRT2 (1.41421356237309504880)
127
#define WLZ_M_SQRT1_2 (0.70710678118654752440)
128
#define WLZ_M_SQRT3 (1.73205080756887729352)
129
#define WLZ_M_SQRT3_2 (0.86602540378443864676)
130
131
/************************************************************************
132
* Mesh tolerance control. *
133
************************************************************************/
134
#define WLZ_MESH_TOLERANCE (1.0E-04)
135
#define WLZ_MESH_TOLERANCE_SQ (WLZ_MESH_TOLERANCE * WLZ_MESH_TOLERANCE)
136
#define WLZ_MESH_ELEM_AREA_TOLERANCE (WLZ_M_SQRT3_2 * WLZ_MESH_TOLERANCE_SQ)
137
138
/************************************************************************
139
* Byte packed bitmap macros
140
************************************************************************/
141
#define WLZ_BIT_SET(A,B) *((A)+((B)>>3))|=(1<<((B)&7))
142
#define WLZ_BIT_GET(A,B) (*((A)+((B)>>3))&(1<<((B)&7)))
143
144
/************************************************************************
145
* Colour values macros
146
************************************************************************/
147
#define WLZ_RGBA_RED_GET(V) ((((WlzUInt )V) & 0xff)>>0)
148
#define WLZ_RGBA_GREEN_GET(V) ((((WlzUInt )V) & 0xff00)>>8)
149
#define WLZ_RGBA_BLUE_GET(V) ((((WlzUInt )V) & 0xff0000)>>16)
150
#define WLZ_RGBA_ALPHA_GET(V) ((((WlzUInt )V) & 0xff000000)>>24)
151
152
#define WLZ_RGBA_RED_SET(V,C) (V = (((WlzUInt )V)&0xffffff00) | \
153
(((WlzUInt) C)&0xff))
154
#define WLZ_RGBA_GREEN_SET(V,C) (V = (((WlzUInt )V)&0xffff00ff) | \
155
((((WlzUInt) C)&0xff)<<8))
156
#define WLZ_RGBA_BLUE_SET(V,C) (V = (((WlzUInt )V)&0xff00ffff) | \
157
((((WlzUInt) C)&0xff)<<16))
158
#define WLZ_RGBA_ALPHA_SET(V,C) (V = (((WlzUInt )V)&0x00ffffff) | \
159
((((WlzUInt) C)&0xff)<<24))
160
#define WLZ_RGBA_RGBA_SET(V,R,G,B,A) (V = ((((WlzUInt )R)&0xff) + \
161
((((WlzUInt )G)&0xff)<<8) + \
162
((((WlzUInt )B)&0xff)<<16) + \
163
((((WlzUInt )A)&0xff)<<24)))
164
165
#define WLZ_RGBA_MEAN(V) ((WLZ_RGBA_RED_GET(V) + \
166
WLZ_RGBA_GREEN_GET(V) + \
167
WLZ_RGBA_BLUE_GET(V))/3.0)
168
169
#define WLZ_RGBA_MODULUS_2(V)(WLZ_RGBA_RED_GET(V)*WLZ_RGBA_RED_GET(V) + \
170
WLZ_RGBA_GREEN_GET(V)*WLZ_RGBA_GREEN_GET(V) + \
171
WLZ_RGBA_BLUE_GET(V)*WLZ_RGBA_BLUE_GET(V))
172
173
#define WLZ_RGBA_MODULUS(V) (sqrt((double) WLZ_RGBA_MODULUS_2(V)))
174
175
/************************************************************************
176
* Vertex macros. *
177
************************************************************************/
178
/* WLZ_VTX_2_ABS: Absolute value of a Wlz[DFI]Vertex2 */
179
#define WLZ_VTX_2_ABS(A,X) \
180
(A).vtX = WLZ_ABS((X).vtX), \
181
(A).vtY = WLZ_ABS((X).vtY)
182
/* WLZ_VTX_3_ABS: Absolute value of a Wlz[DFI]Vertex3 */
183
#define WLZ_VTX_3_ABS(A,X) \
184
(A).vtX = WLZ_ABS((X).vtX), \
185
(A).vtY = WLZ_ABS((X).vtY), \
186
(A).vtZ = WLZ_ABS((X).vtZ)
187
/* WLZ_VTX_2_SIGN: Sign of a Wlz[DFI]Vertex2 */
188
#define WLZ_VTX_2_SIGN(S,X) \
189
(S).vtX = WLZ_SIGN((X).vtX), \
190
(S).vtY = WLZ_SIGN((X).vtY)
191
/* WLZ_VTX_3_SIGN: Sign of a Wlz[DFI]Vertex3 */
192
#define WLZ_VTX_3_SIGN(S,X) \
193
(S).vtX = WLZ_SIGN((X).vtX), \
194
(S).vtY = WLZ_SIGN((X).vtY), \
195
(S).vtZ = WLZ_SIGN((X).vtZ)
196
/* WLZ_VTX_2_COPY: Copy values of Wlz[DFI]Vertex2 */
197
#define WLZ_VTX_2_COPY(D,S) \
198
(D).vtX = (S).vtX, \
199
(D).vtY = (S).vtY
200
/* WLZ_VTX_3_COPY: Copy values of Wlz[DFI]Vertex3 */
201
#define WLZ_VTX_3_COPY(D,S) \
202
(D).vtX = (S).vtX, \
203
(D).vtY = (S).vtY, \
204
(D).vtZ = (S).vtZ
205
/* WLZ_VTX_2_SET: Set Wlz[DFI]Vertex2 */
206
#define WLZ_VTX_2_SET(U,X,Y) \
207
(U).vtX = (X), \
208
(U).vtY = (Y)
209
210
/* WLZ_VTX_3_SET: Set Wlz[DFI]Vertex3 */
211
#define WLZ_VTX_3_SET(U,X,Y,Z) \
212
(U).vtX = (X), \
213
(U).vtY = (Y), \
214
(U).vtZ = (Z)
215
216
/* WLZ_VTX_2_ADD: Add two Wlz[DFI]Vertex2's */
217
#define WLZ_VTX_2_ADD(U,V,W) \
218
(U).vtX = (V).vtX + (W).vtX, \
219
(U).vtY = (V).vtY + (W).vtY
220
221
/* WLZ_VTX_3_ADD: Add two Wlz[DFI]Vertex3's */
222
#define WLZ_VTX_3_ADD(U,V,W) \
223
(U).vtX = (V).vtX + (W).vtX, \
224
(U).vtY = (V).vtY + (W).vtY, \
225
(U).vtZ = (V).vtZ + (W).vtZ
226
227
/* WLZ_VTX_2_ADD: Add three Wlz[DFI]Vertex2's */
228
#define WLZ_VTX_2_ADD3(U,V,W,X) \
229
(U).vtX = (V).vtX + (W).vtX + (X).vtX, \
230
(U).vtY = (V).vtY + (W).vtY + (X).vtY
231
232
/* WLZ_VTX_3_ADD: Add three Wlz[DFI]Vertex3's */
233
#define WLZ_VTX_3_ADD3(U,V,W,X) \
234
(U).vtX = (V).vtX + (W).vtX + (X).vtX, \
235
(U).vtY = (V).vtY + (W).vtY + (X).vtY, \
236
(U).vtZ = (V).vtZ + (W).vtZ + (X).vtZ
237
238
/* WLZ_VTX_4_ADD: Add four Wlz[DFI]Vertex3's */
239
#define WLZ_VTX_3_ADD4(U,V,W,X,Y) \
240
(U).vtX = (V).vtX + (W).vtX + (X).vtX + (Y).vtX, \
241
(U).vtY = (V).vtY + (W).vtY + (X).vtY + (Y).vtY, \
242
(U).vtZ = (V).vtZ + (W).vtZ + (X).vtZ + (Y).vtZ
243
244
/* WLZ_VTX_2_SUB: Subtract two Wlz[DFI]Vertex2's */
245
#define WLZ_VTX_2_SUB(U,V,W) \
246
(U).vtX = (V).vtX - (W).vtX, \
247
(U).vtY = (V).vtY - (W).vtY
248
249
/* WLZ_VTX_3_SUB: Subtract two Wlz[DFI]Vertex3's */
250
#define WLZ_VTX_3_SUB(U,V,W) \
251
(U).vtX = (V).vtX - (W).vtX, \
252
(U).vtY = (V).vtY - (W).vtY, \
253
(U).vtZ = (V).vtZ - (W).vtZ
254
255
/* WLZ_VTX_2_SCALE: Scale a Wlz[DFI]Vertex2 */
256
#define WLZ_VTX_2_SCALE(U,V,C) \
257
(U).vtX = (V).vtX * (C), \
258
(U).vtY = (V).vtY * (C)
259
260
/* WLZ_VTX_3_SCALE: Scale a Wlz[DFI]Vertex3 */
261
#define WLZ_VTX_3_SCALE(U,V,C) \
262
(U).vtX = (V).vtX * (C), \
263
(U).vtY = (V).vtY * (C), \
264
(U).vtZ = (V).vtZ * (C)
265
/* WLZ_VTX_2_SCALE_ADD: Scale a Wlz[DFI]Vertex2 then add a Wlz[DFI]Vertex2. */
266
#define WLZ_VTX_2_SCALE_ADD(U,V,C,W) \
267
(U).vtX = (V).vtX * (C) + (W.vtX), \
268
(U).vtY = (V).vtY * (C) + (W.vtY)
269
270
/* WLZ_VTX_3_SCALE_ADD: Scale a Wlz[DFI]Vertex3 then add a Wlz[DFI]Vertex3. */
271
#define WLZ_VTX_3_SCALE_ADD(U,V,C,W) \
272
(U).vtX = (V).vtX * (C) + (W.vtX), \
273
(U).vtY = (V).vtY * (C) + (W.vtY), \
274
(U).vtZ = (V).vtZ * (C) + (W.vtZ)
275
276
/* WLZ_VTX_2_DOT: Dot (scalar) product of two Wlz[DFI]Vertex2's */
277
#define WLZ_VTX_2_DOT(V,W) \
278
(((V).vtX * (W).vtX) + \
279
((V).vtY * (W).vtY))
280
281
/* WLZ_VTX_2_HAD: Hadamard (element wise) product of two Wlz[DFI]Vertex2s */
282
#define WLZ_VTX_2_HAD(U,V,W) \
283
(U).vtX = (V).vtX * (W).vtX, \
284
(U).vtY = (V).vtY * (W).vtY
285
286
/* WLZ_VTX_3_DOT: Dot (scalar) product of two Wlz[DFI]Vertex3s */
287
#define WLZ_VTX_3_DOT(V,W) \
288
(((V).vtX * (W).vtX) + \
289
((V).vtY * (W).vtY) + \
290
((V).vtZ * (W).vtZ))
291
292
/* WLZ_VTX_3_HAD: Hadamard (element wise) product of two Wlz[DFI]Vertex3s */
293
#define WLZ_VTX_3_HAD(U,V,W) \
294
(U).vtX = (V).vtX * (W).vtX, \
295
(U).vtY = (V).vtY * (W).vtY, \
296
(U).vtZ = (V).vtZ * (W).vtZ
297
298
/* WLZ_VTX_3_CROSS: Cross (vector) product of two Wlz[DFI]Vertex3s */
299
#define WLZ_VTX_3_CROSS(U,V,W) \
300
(U).vtX = ((V).vtY * (W).vtZ) - ((W).vtY * (V).vtZ), \
301
(U).vtY = ((V).vtZ * (W).vtX) - ((W).vtZ * (V).vtX), \
302
(U).vtZ = ((V).vtX * (W).vtY) - ((W).vtX * (V).vtY)
303
304
/* WLZ_VTX_2_LENGTH: Square of length of a Wlz[DFI]Vertex2 */
305
#define WLZ_VTX_2_SQRLEN(U) \
306
(((U).vtX * (U).vtX) + \
307
((U).vtY * (U).vtY))
308
309
/* WLZ_VTX_3_LENGTH: Square of length of a Wlz[DFI]Vertex3 */
310
#define WLZ_VTX_3_SQRLEN(U) \
311
(((U).vtX * (U).vtX) + \
312
((U).vtY * (U).vtY) + \
313
((U).vtZ * (U).vtZ))
314
315
/* WLZ_VTX_2_LENGTH: Length of a Wlz[DFI]Vertex2 */
316
#define WLZ_VTX_2_LENGTH(U) \
317
(sqrt(WLZ_VTX_2_SQRLEN(U)))
318
319
/* WLZ_VTX_3_LENGTH: Length of a Wlz[DFI]Vertex3 */
320
#define WLZ_VTX_3_LENGTH(U) \
321
(sqrt(WLZ_VTX_3_SQRLEN(U)))
322
323
/* WLZ_VTX_2_ZERO: Set vector to zero. */
324
#define WLZ_VTX_2_ZERO(U) \
325
(U).vtX = 0, \
326
(U).vtY = 0
327
328
/* WLZ_VTX_3_ZERO: Set vector to zero. */
329
#define WLZ_VTX_3_ZERO(U) \
330
(U).vtX = 0, \
331
(U).vtY = 0, \
332
(U).vtZ = 0
333
334
/* WLZ_VTX_2_NEGATE: Set vector to zero. */
335
#define WLZ_VTX_2_NEGATE(U,V) \
336
(U).vtX = -((V).vtX), \
337
(U).vtY = -((V).vtY)
338
339
/* WLZ_VTX_3_NEGATE: Set vector to zero. */
340
#define WLZ_VTX_3_NEGATE(U,V) \
341
(U).vtX = -((V).vtX), \
342
(U).vtY = -((V).vtY), \
343
(U).vtZ = -((V).vtZ)
344
345
/* WLZ_VTX_2_EQUAL: Tests for equality of vertices. */
346
#define WLZ_VTX_2_EQUAL(U,V,T) \
347
((fabs((U).vtX - (V).vtX) < (T)) && \
348
(fabs((U).vtY - (V).vtY) < (T)))
349
350
/* WLZ_VTX_3_EQUAL: Tests for equality of vertices. */
351
#define WLZ_VTX_3_EQUAL(U,V,T) \
352
((fabs((U).vtX - (V).vtX) < (T)) && \
353
(fabs((U).vtY - (V).vtY) < (T)) && \
354
(fabs((U).vtZ - (V).vtZ) < (T)))
355
356
/* WLZ_VTX_2_FABS: Floating point absolute value. */
357
#define WLZ_VTX_2_FABS(U,V) \
358
((U).vtX = fabs((V).vtX), \
359
(U).vtY = fabs((V).vtY))
360
361
/* WLZ_VTX_3_FABS: Floating point absolute value. */
362
#define WLZ_VTX_3_FABS(U,V) \
363
((U).vtX = fabs((V).vtX), \
364
(U).vtY = fabs((V).vtY), \
365
(U).vtZ = fabs((V).vtZ))
366
367
/* WLZ_VTX_2_NINT: Nearest integer position. */
368
#define WLZ_VTX_2_NINT(U,P) \
369
((U).vtX = WLZ_NINT((P).vtX), \
370
(U).vtY = WLZ_NINT((P).vtY))
371
372
/* WLZ_VTX_3_NINT: Nearest integer position. */
373
#define WLZ_VTX_3_NINT(U,P) \
374
((U).vtX = WLZ_NINT((P).vtX), \
375
(U).vtY = WLZ_NINT((P).vtY), \
376
(U).vtZ = WLZ_NINT((P).vtZ))
377
378
/************************************************************************
379
* CMesh node access
380
************************************************************************/
381
#define WLZ_CMESH_ELM2D_GET_NODE_0(e) ((e)->edu[0].nod)
382
#define WLZ_CMESH_ELM2D_GET_NODE_1(e) ((e)->edu[1].nod)
383
#define WLZ_CMESH_ELM2D_GET_NODE_2(e) ((e)->edu[2].nod)
384
#define WLZ_CMESH_ELM2D5_GET_NODE_0(e) ((e)->edu[0].nod)
385
#define WLZ_CMESH_ELM2D5_GET_NODE_1(e) ((e)->edu[1].nod)
386
#define WLZ_CMESH_ELM2D5_GET_NODE_2(e) ((e)->edu[2].nod)
387
#define WLZ_CMESH_ELM3D_GET_NODE_0(e) ((e)->face[0].edu[0].nod)
388
#define WLZ_CMESH_ELM3D_GET_NODE_1(e) ((e)->face[0].edu[1].nod)
389
#define WLZ_CMESH_ELM3D_GET_NODE_2(e) ((e)->face[0].edu[2].nod)
390
#define WLZ_CMESH_ELM3D_GET_NODE_3(e) ((e)->face[1].edu[1].nod)
391
392
#ifndef WLZ_EXT_BIND
393
#ifdef __cplusplus
394
}
395
#endif
/* __cplusplus */
396
#endif
/* WLZ_EXT_BIND */
397
398
#endif
/* WLZMACRO_H */
export
data0
bill
MouseAtlas
Build
src
Woolz
libWlz
WlzMacro.h
Generated by
1.8.14