1 /**********
2 *
3 * This file is part of the TINA Open Source Image Analysis Environment
4 * henceforth known as TINA
5 *
6 * TINA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation.
9 *
10 * TINA is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with TINA; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 **********
20 *
21 * Program : TINA
22 * File : $Source: /home/tina/cvs/tina-libs/tina/geometry/geomIndx_windex.c,v $
23 * Date : $Date: 2005/01/23 19:10:21 $
24 * Version : $Revision: 1.3 $
25 * CVS Id : $Id: geomIndx_windex.c,v 1.3 2005/01/23 19:10:21 paul Exp $
26 *
27 * Notes : functions to support generic image index binning
28 *
29 *********
30 */
31
32
33 #include "geomIndx_windex.h"
34
35 #if HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include <math.h>
40 #include <stdio.h>
41 #include <tina/sys/sysDef.h>
42 #include <tina/sys/sysPro.h>
43 #include <tina/math/mathDef.h>
44 #include <tina/math/mathPro.h>
45 #include <tina/image/imgDef.h>
46 #include <tina/image/imgPro.h>
47 #include <tina/geometry/geom_IndxDef.h>
48
49 Windex *wx_alloc(Imregion * region, int m, int n, int type)
50 {
51 Windex *w;
52 Imregion *roi_copy();
53
54 w = ts_ralloc(Windex);
55
56 w->index = parray_alloc(0, 0, m, n);
57 w->type = type;
58 w->region = roi_copy(region);
59 w->m = m;
60 w->n = n;
61
62 return (w);
63 }
64
65 void wx_free(Windex * w, void (*freefunc) ( /* ??? */ ))
66 {
67 void ***index;
68 int n, m;
69 int i, j;
70
71 if (w == NULL)
72 return;
73
74 m = w->m;
75 n = w->n;
76 index = w->index;
77
78 if (freefunc != NULL)
79 for (i = 0; i < m; ++i)
80 for (j = 0; j < n; ++j)
81 freefunc(index[i][j]);
82
83 parray_free(index, 0, 0, m, n);
84 rfree((void *) w);
85 }
86
87 void wx_set(Windex * w, void *ptr, int i, int j, void (*freefunc) ( /* ??? */ ))
88 {
89 if (i < 0 || i >= w->m || j < 0 || j >= w->n)
90 return;
91
92 if (freefunc != NULL)
93 freefunc(w->index[i][j]);
94
95 w->index[i][j] = ptr;
96 }
97
98 void *wx_get(Windex * w, int i, int j)
99 {
100 if (i < 0 || i >= w->m || j < 0 || j >= w->n)
101 return (NULL);
102
103 return (w->index[i][j]);
104 }
105
106 Bool wx_in_index(Windex * w, int i, int j)
107 {
108 return ((i < 0 || i >= w->m || j < 0 || j >= w->n) ? false : true);
109 }
110
111 Ipos wx_get_index(Windex * w, Vec2 p)
112 {
113 Ipos i = {Ipos_id};
114
115 if (w == NULL)
116 return (ipos(-1, -1)); /* unset dummy value */
117
118 ipos_y(i) = (int)floor( w->m * (vec2_y(p) - w->region->ly) / (w->region->uy - w->region->ly));
119 ipos_x(i) = (int)floor( w->n * (vec2_x(p) - w->region->lx) / (w->region->ux - w->region->lx));
120 return (i);
121 }
122
123 Vec2 wx_get_pos2(Windex * w, Ipos i)
124 {
125 Vec2 v = {Vec2_id};
126 float x, y;
127
128 x = (float)ipos_x(i);
129 y = (float)ipos_y(i);
130
131 vec2_x(v) = w->region->lx + x * (w->region->ux - w->region->lx) / w->n;
132 vec2_y(v) = w->region->ly + y * (w->region->uy - w->region->ly) / w->m;
133 return (v);
134 }
135
136 Vec2 wx_get_mid_pos2(Windex * w, Ipos i)
137 {
138 Vec2 v = {Vec2_id};
139 float x, y;
140
141 x = (float)(ipos_x(i) + 0.5);
142 y = (float)(ipos_y(i) + 0.5);
143
144 vec2_x(v) = w->region->lx + x * (w->region->ux - w->region->lx) / w->n;
145 vec2_y(v) = w->region->ly + y * (w->region->uy - w->region->ly) / w->m;
146 return (v);
147 }
148
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.