~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomIndx_windex.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 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 General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU 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  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomIndx_windex.c,v $
 27  * Date    :  $Date: 2005/01/23 19:10:21 $
 28  * Version :  $Revision: 1.3 $
 29  * CVS Id  :  $Id: geomIndx_windex.c,v 1.3 2005/01/23 19:10:21 paul Exp $
 30  *
 31  * Notes : functions to support generic image index binning
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomIndx_windex.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <math.h>
 44 #include <stdio.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/image/imgDef.h>
 50 #include <tina/image/imgPro.h>
 51 #include <tina/geometry/geom_IndxDef.h>
 52 
 53 Windex *wx_alloc(Imregion * region, int m, int n, int type)
 54 {
 55     Windex *w;
 56     Imregion *roi_copy();
 57 
 58     w = ts_ralloc(Windex);
 59 
 60     w->index = parray_alloc(0, 0, m, n);
 61     w->type = type;
 62     w->region = roi_copy(region);
 63     w->m = m;
 64     w->n = n;
 65 
 66     return (w);
 67 }
 68 
 69 void    wx_free(Windex * w, void (*freefunc) ( /* ??? */ ))
 70 {
 71     void ***index;
 72     int     n, m;
 73     int     i, j;
 74 
 75     if (w == NULL)
 76         return;
 77 
 78     m = w->m;
 79     n = w->n;
 80     index = w->index;
 81 
 82     if (freefunc != NULL)
 83         for (i = 0; i < m; ++i)
 84             for (j = 0; j < n; ++j)
 85                 freefunc(index[i][j]);
 86 
 87     parray_free(index, 0, 0, m, n);
 88     rfree((void *) w);
 89 }
 90 
 91 void    wx_set(Windex * w, void *ptr, int i, int j, void (*freefunc) ( /* ??? */ ))
 92 {
 93     if (i < 0 || i >= w->m || j < 0 || j >= w->n)
 94         return;
 95 
 96     if (freefunc != NULL)
 97         freefunc(w->index[i][j]);
 98 
 99     w->index[i][j] = ptr;
100 }
101 
102 void   *wx_get(Windex * w, int i, int j)
103 {
104     if (i < 0 || i >= w->m || j < 0 || j >= w->n)
105         return (NULL);
106 
107     return (w->index[i][j]);
108 }
109 
110 Bool    wx_in_index(Windex * w, int i, int j)
111 {
112     return ((i < 0 || i >= w->m || j < 0 || j >= w->n) ? false : true);
113 }
114 
115 Ipos    wx_get_index(Windex * w, Vec2 p)
116 {
117     Ipos    i = {Ipos_id};
118 
119     if (w == NULL)
120         return (ipos(-1, -1));  /* unset dummy value */
121 
122     ipos_y(i) = (int)floor( w->m * (vec2_y(p) - w->region->ly) / (w->region->uy - w->region->ly));
123     ipos_x(i) = (int)floor( w->n * (vec2_x(p) - w->region->lx) / (w->region->ux - w->region->lx));
124     return (i);
125 }
126 
127 Vec2    wx_get_pos2(Windex * w, Ipos i)
128 {
129     Vec2    v = {Vec2_id};
130     float   x, y;
131 
132     x = (float)ipos_x(i);
133     y = (float)ipos_y(i);
134 
135     vec2_x(v) = w->region->lx + x * (w->region->ux - w->region->lx) / w->n;
136     vec2_y(v) = w->region->ly + y * (w->region->uy - w->region->ly) / w->m;
137     return (v);
138 }
139 
140 Vec2    wx_get_mid_pos2(Windex * w, Ipos i)
141 {
142     Vec2    v = {Vec2_id};
143     float   x, y;
144 
145     x = (float)(ipos_x(i) + 0.5);
146     y = (float)(ipos_y(i) + 0.5);
147 
148     vec2_x(v) = w->region->lx + x * (w->region->ux - w->region->lx) / w->n;
149     vec2_y(v) = w->region->ly + y * (w->region->uy - w->region->ly) / w->m;
150     return (v);
151 }
152 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.