1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgSeq_imstack.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgSeq_imstack.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 *
43 * Notes : image stack handling
44 *
45 */
46
47 /**
48 * @file
49 * @brief Image stack handling
50 *
51 */
52
53
54 #include "imgSeq_imstack.h"
55
56 #if HAVE_CONFIG_H
57 #include <config.h>
58 #endif
59
60 #include <stdio.h>
61 #include <tina/sys/sysDef.h>
62 #include <tina/sys/sysPro.h>
63 #include <tina/image/img_GenDef.h>
64 #include <tina/image/img_GenPro.h>
65 #include <tina/image/img_SeqDef.h>
66 #include <tina/image/imgSeq_voi.h>
67
68 /*
69 Allocate a slice with space for NVOI volumes of interest.
70 */
71 static Seqslice *seqslice_alloc(double z)
72 {
73 Seqslice *slice = ralloc(sizeof(Seqslice));
74 int i;
75 slice->im = NULL;
76 for (i = 0; i < NVOI; i++)
77 slice->voi[i] = svoi_alloc();
78 slice->z = z;
79 return (slice);
80 }
81
82 /*
83 Free a slice.
84 */
85 static void seqslice_free(Seqslice * slice)
86 {
87 int i;
88 if (slice == NULL)
89 return;
90 im_free(slice->im);
91 for (i = 0; i < NVOI; i++)
92 svoi_free(slice->voi[i]);
93 rfree(slice);
94 }
95
96 /*
97 Find power of 2 greater than x
98 */
99 static int above2n(int x)
100 {
101 int y = 1;
102 while (y < x)
103 y *= 2;
104 return (y);
105 }
106
107 /*
108 Return an image stack of given image variable type (uchar_v etc.)
109 with slice numbers ranging from lz to uz (excluding uz).
110 */
111 Br_imstack *seq_imstack_make(Vartype vtype, int lz, int uz, double zscale)
112 {
113 Br_imstack *imstack = ralloc(sizeof(Br_imstack));
114 int z;
115
116 imstack->vtype = vtype;
117 imstack->lx = imstack->ux = imstack->x = 0;
118 imstack->ly = imstack->uy = imstack->y = 0;
119 imstack->lz = lz;
120 imstack->uz = uz;
121 imstack->z = (lz + uz) / 2;
122 imstack->zmark = 0;
123 imstack->slice = tvector_alloc(lz, uz, Seqslice *);
124 imstack->zscale = zscale;
125 for (z = lz; z < uz; z++)
126 imstack->slice[z] = seqslice_alloc(seq_imstack_zscaled(imstack, z));
127 /*
128 * imstack->stats = NULL; imstack->tube = NULL;
129 */
130 return (imstack);
131 }
132
133 /*
134 Free an image stack and associated memory
135 */
136 void seq_imstack_free(Br_imstack * imstack)
137 {
138 int z;
139
140 if (imstack == NULL)
141 return;
142 for (z = imstack->lz; z < imstack->uz; z++)
143 seqslice_free(imstack->slice[z]);
144 tvector_free(imstack->slice, imstack->lz, Seqslice *);
145 /*
146 * rfree(imstack->stats); tube_free(imstack->tube);
147 */
148 rfree(imstack);
149 }
150
151 /*
152 Get true z-coordinate associated with slice number z
153 */
154 double seq_imstack_zscaled(Br_imstack * imstack, int z)
155 {
156 z -= (imstack->lz + imstack->uz) / 2;
157 return (imstack->zscale * z);
158 }
159
160 /*
161 Get slice number associated wth true z-coordinate z
162 */
163 int seq_imstack_zunscaled(Br_imstack * imstack, double z)
164 {
165 int zi;
166 z /= imstack->zscale;
167 z += (imstack->lz + imstack->uz) / 2;
168 zi = ROUND(z);
169 return (zi);
170 }
171
172 /*
173 Return transverse image in (y, z) plane at current x-cursor position.
174 */
175 Imrect *seq_imstack_xslice(Br_imstack * imstack, int x)
176 {
177 Imrect *im;
178 Imregion *roi;
179 float *row;
180 int z, width, height;
181
182 if (imstack == NULL)
183 return (NULL);
184
185 height = above2n(imstack->uz);
186 width = above2n(imstack->uy);
187 roi = roi_alloc(imstack->ly, imstack->lz, imstack->uy, imstack->uz);
188 im = im_alloc(height, width, roi, imstack->vtype);
189 rfree(roi);
190
191 row = tvector_alloc(imstack->ly, imstack->uy, float);
192 for (z = imstack->lz; z < imstack->uz; z++)
193 {
194 im_get_colf(row, imstack->slice[z]->im, x, imstack->ly, imstack->uy);
195 im_put_rowf(row, im, z, imstack->ly, imstack->uy);
196 }
197 tvector_free(row, imstack->ly, float);
198
199 return (im);
200 }
201
202 /*
203 Return transverse image in (x, z) plane at current y-cursor position.
204 */
205 Imrect *seq_imstack_yslice(Br_imstack * imstack, int y)
206 {
207 Imrect *im;
208 Imregion *roi;
209 float *row;
210 int z, width, height;
211
212 if (imstack == NULL)
213 return (NULL);
214
215 height = above2n(imstack->uz);
216 width = above2n(imstack->ux);
217 roi = roi_alloc(imstack->lx, imstack->lz, imstack->ux, imstack->uz);
218 im = im_alloc(height, width, roi, imstack->vtype);
219 rfree(roi);
220
221 row = tvector_alloc(imstack->lx, imstack->ux, float);
222 for (z = imstack->lz; z < imstack->uz; z++)
223 {
224 im_get_rowf(row, imstack->slice[z]->im, y, imstack->lx, imstack->ux);
225 im_put_rowf(row, im, z, imstack->lx, imstack->ux);
226 }
227 tvector_free(row, imstack->lx, float);
228
229 return (im);
230 }
231
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.