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/imgPrc_spiral.c,v $
37 * Date : $Date: 2005/01/23 19:10:21 $
38 * Version : $Revision: 1.7 $
39 * CVS Id : $Id: imgPrc_spiral.c,v 1.7 2005/01/23 19:10:21 paul Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Generate spiral test images.
47 *
48 * Angle is measured with reference to the positive x-axis from the centre.
49 * This is version 3, discrete solution. PAB 17 / 5 / 2001.
50 *
51 */
52
53 #include "imgPrc_spiral.h"
54
55 #if HAVE_CONFIG_H
56 #include <config.h>
57 #endif
58
59 #include <math.h>
60 #include <tina/sys/sysDef.h>
61 #include <tina/sys/sysPro.h>
62 #include <tina/math/mathDef.h>
63 #include <tina/math/mathPro.h>
64 #include <tina/image/img_GenDef.h>
65 #include <tina/image/img_GenPro.h>
66
67
68 Imrect *imf_spiral(int x_centre, int y_centre, int height, int width,
69 double overtake, double loops)
70 {
71
72
73
74 Imrect *im;
75 Imregion *roi;
76 float *row = fvector_alloc(0, width);
77 float radius, radius_a, radius_b, theta, x, y;
78 float k_a, k_b;
79 int i, j, flag;
80
81 if (loops < 0 || overtake < 0)
82 {
83 error("Positive parameters only", warning);
84 fvector_free(row, 0);
85 return (NULL);
86 }
87 im = im_alloc(height, width, (Imregion *) NULL, float_v);
88 if (im == NULL)
89 {
90 return (NULL);
91 }
92 roi = im->region;
93
94 k_a = exp(log(width / 2) / (TWOPI * loops));
95 k_b = pow(k_a, ((overtake + 1) / overtake));
96
97 for (i = roi->ly; i < roi->uy; i++)
98 {
99 for (j = roi->lx; j < roi->ux; j++)
100 {
101 x = j - x_centre;
102 y = y_centre - i;
103 radius = sqrt(sqr(x) + sqr(y));
104 theta = atan2(y, x);
105 if (y < 0)
106 theta = TWOPI + theta;
107
108 flag = 0;
109 while (flag == 0)
110 {
111 radius_a = (pow(k_a, theta));
112 radius_b = (pow(k_b, theta)) + 1;
113
114 /*
115 * Note: the plus one in the previous line is
116 * used to get the inner parts of the spiral
117 * fully painted, by ensuring that there is
118 * always at least a one pixel gap between
119 * the two radii: equivalent to an angular
120 * offset on the outer spiral
121 */
122
123 if (radius_a <= radius && radius_b >= radius)
124 {
125 row[j] = 255.0;
126 flag = 1;
127 }
128 if (radius < radius_a && radius < radius_b)
129 {
130 row[j] = 0.0;
131 flag = 1;
132 }
133 if (radius > radius_a && radius > radius_b)
134 {
135 theta += TWOPI;
136 }
137 }
138 }
139 im_put_rowf(row, im, i, 0, width);
140 }
141
142 fvector_free(row, 0);
143 return (im);
144 }
145
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.