plastimatch
Loading...
Searching...
No Matches
bspline_macros.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef _bspline_macros_h_
5#define _bspline_macros_h_
6
7#include "plmbase_config.h"
8#include "bspline_xform.h"
9#include "plm_int.h"
10#include "volume_macros.h"
11
12/***************************************************************
13 * MACROS FOR VOXEL CENTRIC ALGORITHMS *
14 ***************************************************************/
15
16/* ITERATORS */
17
18/* For looping through volume ROI. Here:
19 * roi_ijk - coordinates within ROI
20 * vol_ijk - volume coordinate of ROI point roi_ijk
21 */
22#define LOOP_THRU_ROI_X(roi_ijk, vol_ijk, bxf) \
23 for (roi_ijk[0] = 0, vol_ijk[0] = bxf->roi_offset[0]; roi_ijk[0] < bxf->roi_dim[0]; roi_ijk[0]++, vol_ijk[0]++)
24
25#define LOOP_THRU_ROI_Y(roi_ijk, vol_ijk, bxf) \
26 for (roi_ijk[1] = 0, vol_ijk[1] = bxf->roi_offset[1]; roi_ijk[1] < bxf->roi_dim[1]; roi_ijk[1]++, vol_ijk[1]++)
27
28#define LOOP_THRU_ROI_Z(roi_ijk, vol_ijk, bxf) \
29 for (roi_ijk[2] = 0, vol_ijk[2] = bxf->roi_offset[2]; roi_ijk[2] < bxf->roi_dim[2]; roi_ijk[2]++, vol_ijk[2]++)
30
31
32/* COORDINATE MANIPULATION MACROS */
33#define REGION_INDEX_X(ijk, bxf) \
34 (ijk[0] / bxf->vox_per_rgn[0])
35
36#define REGION_INDEX_Y(ijk, bxf) \
37 (ijk[1] / bxf->vox_per_rgn[1])
38
39#define REGION_INDEX_Z(ijk, bxf) \
40 (ijk[2] / bxf->vox_per_rgn[2])
41
42static inline void
43get_region_index_3 (int p[3], const int ijk[3], const Bspline_xform *bxf) {
44 p[0] = ijk[0] / bxf->vox_per_rgn[0];
45 p[1] = ijk[1] / bxf->vox_per_rgn[1];
46 p[2] = ijk[2] / bxf->vox_per_rgn[2];
47}
48
49static inline void
50get_region_index_3 (int p[3], int i, int j, int k, const Bspline_xform *bxf) {
51 p[0] = i / bxf->vox_per_rgn[0];
52 p[1] = j / bxf->vox_per_rgn[1];
53 p[2] = k / bxf->vox_per_rgn[2];
54}
55
56static inline plm_long
57get_region_index (const plm_long ijk[3], const Bspline_xform *bxf) {
58 plm_long p[3];
59 p[0] = ijk[0] / bxf->vox_per_rgn[0];
60 p[1] = ijk[1] / bxf->vox_per_rgn[1];
61 p[2] = ijk[2] / bxf->vox_per_rgn[2];
62 return volume_index (bxf->rdims, p);
63}
64
65static inline plm_long
66get_region_index (plm_long i, plm_long j, plm_long k, const Bspline_xform *bxf) {
67 plm_long p[3];
68 p[0] = i / bxf->vox_per_rgn[0];
69 p[1] = j / bxf->vox_per_rgn[1];
70 p[2] = k / bxf->vox_per_rgn[2];
71 return volume_index (bxf->rdims, p);
72}
73
74#define REGION_OFFSET_X(ijk, bxf) \
75 (ijk[0] % bxf->vox_per_rgn[0])
76
77#define REGION_OFFSET_Y(ijk, bxf) \
78 (ijk[1] % bxf->vox_per_rgn[1])
79
80#define REGION_OFFSET_Z(ijk, bxf) \
81 (ijk[2] % bxf->vox_per_rgn[2])
82
83static inline void
84get_region_offset (int q[3], const int ijk[3], const Bspline_xform *bxf) {
85 q[0] = ijk[0] % bxf->vox_per_rgn[0];
86 q[1] = ijk[1] % bxf->vox_per_rgn[1];
87 q[2] = ijk[2] % bxf->vox_per_rgn[2];
88}
89
90static inline void
91get_region_offset (int q[3], int i, int j, int k, const Bspline_xform *bxf) {
92 q[0] = i % bxf->vox_per_rgn[0];
93 q[1] = j % bxf->vox_per_rgn[1];
94 q[2] = k % bxf->vox_per_rgn[2];
95}
96
97static inline plm_long
98get_region_offset (const plm_long ijk[3], const Bspline_xform *bxf) {
99 plm_long q[3];
100 q[0] = ijk[0] % bxf->vox_per_rgn[0];
101 q[1] = ijk[1] % bxf->vox_per_rgn[1];
102 q[2] = ijk[2] % bxf->vox_per_rgn[2];
103 return volume_index (bxf->vox_per_rgn, q);
104}
105
106static inline plm_long
107get_region_offset (plm_long i, plm_long j, plm_long k, const Bspline_xform *bxf) {
108 plm_long q[3];
109 q[0] = i % bxf->vox_per_rgn[0];
110 q[1] = j % bxf->vox_per_rgn[1];
111 q[2] = k % bxf->vox_per_rgn[2];
112 return volume_index (bxf->vox_per_rgn, q);
113}
114
115#define GET_WORLD_COORD_X_NO_DCOS(ijk_vol, bxf) \
116 (bxf->img_origin[0] + bxf->img_spacing[0] * ijk_vol[0])
117
118#define GET_WORLD_COORD_Y_NO_DCOS(ijk_vol, bxf) \
119 (bxf->img_origin[1] + bxf->img_spacing[1] * ijk_vol[1])
120
121#define GET_WORLD_COORD_Z_NO_DCOS(ijk_vol, bxf) \
122 (bxf->img_origin[2] + bxf->img_spacing[2] * ijk_vol[2])
123
124#define GET_WORLD_COORD_X(ijk_vol, vol, bxf) \
125 (bxf->img_origin[0] \
126 + ijk_vol[0]*vol->step[0*3+0] \
127 + ijk_vol[1]*vol->step[0*3+1] \
128 + ijk_vol[2]*vol->step[0*3+2])
129
130#define GET_WORLD_COORD_Y(ijk_vol, vol, bxf) \
131 (bxf->img_origin[1] \
132 + ijk_vol[0]*vol->step[1*3+0] \
133 + ijk_vol[1]*vol->step[1*3+1] \
134 + ijk_vol[2]*vol->step[1*3+2])
135
136#define GET_WORLD_COORD_Z(ijk_vol, vol, bxf) \
137 (bxf->img_origin[2] \
138 + ijk_vol[0]*vol->step[2*3+0] \
139 + ijk_vol[1]*vol->step[2*3+1] \
140 + ijk_vol[2]*vol->step[2*3+2])
141
142/***************************************************************
143 * MACROS FOR THE "PARALLEL FRIENDLY" TILE-CENTRIC ALGORITHMS *
144 ***************************************************************/
145
146/* ITERATORS */
147
148/* For linearlly cycling through regions/tiles in the volume */
149#define LOOP_THRU_VOL_TILES(idx_tile, bxf) \
150 for (idx_tile = 0; idx_tile < (bxf->rdims[0] * bxf->rdims[1] * bxf->rdims[2]); idx_tile++)
151
152/* For cycling through local coordinates within a tile */
153#define LOOP_THRU_TILE_X(ijk_local, bxf) \
154 for (ijk_local[0]=0; ijk_local[0] < bxf->vox_per_rgn[0]; ijk_local[0]++)
155
156#define LOOP_THRU_TILE_Y(ijk_local, bxf) \
157 for (ijk_local[1]=0; ijk_local[1] < bxf->vox_per_rgn[1]; ijk_local[1]++)
158
159#define LOOP_THRU_TILE_Z(ijk_local, bxf) \
160 for (ijk_local[2]=0; ijk_local[2] < bxf->vox_per_rgn[2]; ijk_local[2]++)
161
162
163
164/* COORDINATE MANIPULATION MACROS */
165
166/* Get volume coordinates given tile coordinates and local coordinates */
167#define GET_VOL_COORDS(ijk_vol, ijk_tile, ijk_local, bxf) \
168 do { \
169 ijk_vol[0] = bxf->roi_offset[0] + bxf->vox_per_rgn[0] * ijk_tile[0] + ijk_local[0]; \
170 ijk_vol[1] = bxf->roi_offset[1] + bxf->vox_per_rgn[1] * ijk_tile[1] + ijk_local[1]; \
171 ijk_vol[2] = bxf->roi_offset[2] + bxf->vox_per_rgn[2] * ijk_tile[2] + ijk_local[2]; \
172 } while (0);
173
174
175/* Get real-space coordinates from a set of volume indices */
176#define GET_REAL_SPACE_COORDS(xyz_vol, ijk_vol, bxf) \
177 do { \
178 xyz_vol[0] = bxf->img_origin[0] + bxf->img_spacing[0] * ijk_vol[0]; \
179 xyz_vol[1] = bxf->img_origin[1] + bxf->img_spacing[1] * ijk_vol[1]; \
180 xyz_vol[2] = bxf->img_origin[2] + bxf->img_spacing[2] * ijk_vol[2]; \
181 } while (0);
182
183/* Get real-space coordinates from a set of volume indices */
184#define GET_VOXEL_INDICES(xyz_vol, ijk_vol, bxf) \
185 do { \
186 xyz_vol[0] = ROUND_INT((ijk_vol[0] - bxf->img_origin[0])/ bxf->img_spacing[0]) ; \
187 xyz_vol[1] = ROUND_INT((ijk_vol[1] - bxf->img_origin[1])/ bxf->img_spacing[1]) ; \
188 xyz_vol[2] = ROUND_INT((ijk_vol[2] - bxf->img_origin[2])/ bxf->img_spacing[2]) ; \
189 } while (0);
190
191/* Get real-space coordinates from a set of volume indices */
192#if defined (commentout)
193#define GET_WORLD_COORDS(xyz_vol, ijk_vol, vol, bxf) \
194 VOXEL_COORDS (xyz_vol, ijk_vol, bxf->img_origin, vol->step)
195#endif
196
197#endif /* _bspline_macros_h_ */
static void get_region_offset(int q[3], const int ijk[3], const Bspline_xform *bxf)
Definition bspline_macros.h:84
static plm_long get_region_index(const plm_long ijk[3], const Bspline_xform *bxf)
Definition bspline_macros.h:57
static void get_region_index_3(int p[3], const int ijk[3], const Bspline_xform *bxf)
Definition bspline_macros.h:43
plm_long vox_per_rgn[3]
Definition bspline_header.h:31
plm_long rdims[3]
Definition bspline_header.h:33
The Bspline_xform class encapsulates the B-spline coefficients used by native registration and warpin...
Definition bspline_xform.h:24
static plm_long volume_index(const plm_long dims[3], plm_long i, plm_long j, plm_long k)
Definition volume_macros.h:14