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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomCurve_curvinvar.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/geomCurve_curvinvar.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomCurve_curvinvar.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  *
 35  *********
 36 */
 37 
 38 #include "geomCurve_curvinvar.h"
 39 
 40 #if HAVE_CONFIG_H
 41   #include <config.h>
 42 #endif
 43 
 44 #include <math.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/geomCurve_curvature.h>
 52 
 53 
 54 double  curv_invar_ratio(Tstring * es1, List * d1, Tstring * es2, List * d2)
 55 {
 56     double  k1, k2;
 57     double  theta1, theta2, r;
 58     Vec2    p1 = {Vec2_id};
 59     Vec2    p2 = {Vec2_id};
 60     Vec2    t1 = {Vec2_id};
 61     Vec2    t2 = {Vec2_id};
 62 
 63     es_diffgeom(es1, d1, 0.4, 5.0, 25.0, &p1, &t1, &k1);
 64     es_diffgeom(es2, d2, 0.4, 5.0, 25.0, &p2, &t2, &k2);
 65     theta1 = vec2_angle(t1, vec2_diff(p1, p2));
 66     theta2 = vec2_angle(t2, vec2_diff(p2, p1));
 67     r = sin(theta1) / sin(theta2);
 68     r = r * r * r;
 69     return (k1 / k2 / r);
 70 }
 71 
 72 void    curv_invar_ratio_range(Tstring * es1, List * d1, Tstring * es2, List * d2, int sample, float *lowp, float *upp)
 73 {
 74     List *ptr1;
 75     List *ptr2;
 76     List *start1;
 77     List *start2;
 78     List *end1;
 79     List *end2;
 80     float   low, up;
 81     int     i;
 82 
 83     start1 = es1->start;
 84     end1 = es1->end;
 85     start2 = es2->start;
 86     end2 = es2->end;
 87     for (ptr1 = d1, i = 0; i < sample; i++, ptr1 = ptr1->last)
 88         if (ptr1 == start1)
 89             break;
 90     start1 = ptr1;
 91     for (ptr1 = d1, i = 0; i < sample; i++, ptr1 = ptr1->next)
 92         if (ptr1 == end1)
 93             break;
 94     end1 = ptr1;
 95     for (ptr2 = d2, i = 0; i < sample; i++, ptr2 = ptr2->last)
 96         if (ptr2 == start2)
 97             break;
 98     start2 = ptr2;
 99     for (ptr2 = d2, i = 0; i < sample; i++, ptr2 = ptr2->next)
100         if (ptr2 == end2)
101             break;
102     end2 = ptr2;
103 
104     low = up = (float) curv_invar_ratio(es1, d1, es2, d2);
105     for (ptr1 = start1;; ptr1 = ptr1->next)
106     {
107         for (ptr2 = start2;; ptr2 = ptr2->next)
108         {
109             if (ptr1 != d1 || ptr2 != d2)
110             {
111                 float   invar = (float)curv_invar_ratio(es1, ptr1, es2, ptr2);
112 
113                 if (invar < low)
114                     low = invar;
115                 if (invar > up)
116                     up = invar;
117             }
118             if (ptr2 == end2)
119                 break;
120         }
121         if (ptr1 == end1)
122             break;
123     }
124     *upp = up;
125     *lowp = low;
126 }
127 
128 Terrain_data *curv_invar_surf(Tstring * es, int sample, int buffer, double scale)
129 {
130     Terrain_data *surf;
131     List *ptr1;
132     List *ptr2;
133     List *start;
134     List *end = (List *) NULL;
135     double  invar;
136     int     n, i, j;
137     int     ii, jj;
138 
139     if (es == NULL || es->start == es->end)
140         return (NULL);
141 
142     for (i = 0, start = es->start;; i++, start = start->next)
143     {
144         if (start == end)
145             return (NULL);
146         if (i >= buffer)
147             break;
148     }
149 
150     for (i = 0, end = es->end;; i++, end = end->last)
151     {
152         if (start == end)
153             return (NULL);
154         if (i >= buffer)
155             break;
156     }
157 
158     for (n = i = 0, ptr1 = start;; i++, ptr1 = ptr1->next)
159     {
160         if (i % sample == 0)
161             ++n;
162         if (ptr1 == end)
163             break;
164     }
165 
166     surf = terrain_alloc(TERRAIN, n, n);
167 
168     for (i = 0, ptr1 = start;; i++, ptr1 = ptr1->next)
169     {
170         if (i % sample == 0)
171         {
172             ii = i / sample;
173             surf->data[ii][ii] = vec3((float) i, (float) i, scale);
174             if (ptr1 == end)
175                 break;
176             for (j = i + 1, ptr2 = ptr1->next;; j++, ptr2 = ptr2->next)
177             {
178                 if (j % sample == 0)
179                 {
180                     jj = j / sample;
181 
182                     invar = curv_invar_ratio(es, ptr1, es, ptr2);
183                     invar = fabs(log(fabs(invar)));
184                     surf->data[ii][jj] = vec3((float) j, (float) i, invar * scale);
185                     surf->data[jj][ii] = vec3((float) i, (float) j, invar * scale);
186                 }
187                 if (ptr2 == end)
188                     break;
189             }
190         }
191         if (ptr1 == end)
192             break;
193     }
194     return (surf);
195 }
196 
197 double  curv_invar_ratio_dds(List * d1, List * d2, int n)
198 {
199     double  k1, k2;
200     double  theta1, theta2, r;
201     Vec2    p1 = {Vec2_id};
202     Vec2    p2 = {Vec2_id};
203     Vec2    t1 = {Vec2_id};
204     Vec2    t2 = {Vec2_id};
205 
206     dds_diffgeom(d1, &p1, &t1, &k1, n);
207     dds_diffgeom(d2, &p2, &t2, &k2, n);
208     theta1 = vec2_angle(t1, vec2_diff(p1, p2));
209     theta2 = vec2_angle(t2, vec2_diff(p2, p1));
210     r = sin(theta1) / sin(theta2);
211     r = r * r * r;
212     return (k1 / k2 / r);
213 }
214 
215 void    curv_invar_ratio_range_dds(Tstring * es1, List * d1, Tstring * es2, List * d2, int sample, float *lowp, float *upp)
216 {
217     List *ptr1;
218     List *ptr2;
219     List *start1;
220     List *start2;
221     List *end1;
222     List *end2;
223     float   low, up;
224     int     i;
225 
226     start1 = es1->start;
227     end1 = es1->end;
228     start2 = es2->start;
229     end2 = es2->end;
230     for (ptr1 = d1, i = 0; i < sample; i++, ptr1 = ptr1->last)
231         if (ptr1 == start1)
232             break;
233     start1 = ptr1;
234     for (ptr1 = d1, i = 0; i < sample; i++, ptr1 = ptr1->next)
235         if (ptr1 == end1)
236             break;
237     end1 = ptr1;
238     for (ptr2 = d2, i = 0; i < sample; i++, ptr2 = ptr2->last)
239         if (ptr2 == start2)
240             break;
241     start2 = ptr2;
242     for (ptr2 = d2, i = 0; i < sample; i++, ptr2 = ptr2->next)
243         if (ptr2 == end2)
244             break;
245     end2 = ptr2;
246 
247     low = up = (float)curv_invar_ratio_dds(d1, d2, 1);
248     for (ptr1 = start1;; ptr1 = ptr1->next)
249     {
250         for (ptr2 = start2;; ptr2 = ptr2->next)
251         {
252             if (ptr1 != d1 || ptr2 != d2)
253             {
254                 float   invar = (float)curv_invar_ratio_dds(ptr1, ptr2, 1);
255 
256                 if (invar < low)
257                     low = invar;
258                 if (invar > up)
259                     up = invar;
260             }
261             if (ptr2 == end2)
262                 break;
263         }
264         if (ptr1 == end1)
265             break;
266     }
267     *upp = up;
268     *lowp = low;
269 }
270 
271 Terrain_data *curv_invar_surf_dds(Tstring * es, int sample, int buffer, double scale)
272 {
273     Terrain_data *surf;
274     List *ptr1;
275     List *ptr2;
276     List *start;
277     List *end = (List *) NULL;
278     double  invar;
279     int     n, i, j;
280     int     ii, jj;
281 
282     if (es == NULL || es->start == es->end)
283         return (NULL);
284 
285     for (i = 0, start = es->start;; i++, start = start->next)
286     {
287         if (start == end)
288             return (NULL);
289         if (i >= buffer)
290             break;
291     }
292 
293     for (i = 0, end = es->end;; i++, end = end->last)
294     {
295         if (start == end)
296             return (NULL);
297         if (i >= buffer)
298             break;
299     }
300 
301     for (n = i = 0, ptr1 = start;; i++, ptr1 = ptr1->next)
302     {
303         if (i % sample == 0)
304             ++n;
305         if (ptr1 == end)
306             break;
307     }
308 
309     surf = terrain_alloc(TERRAIN, n, n);
310 
311     for (i = 0, ptr1 = start;; i++, ptr1 = ptr1->next)
312     {
313         if (i % sample == 0)
314         {
315             ii = i / sample;
316             surf->data[ii][ii] = vec3((float) i, (float) i, scale);
317             if (ptr1 == end)
318                 break;
319             for (j = i + 1, ptr2 = ptr1->next;; j++, ptr2 = ptr2->next)
320             {
321                 if (j % sample == 0)
322                 {
323                     jj = j / sample;
324 
325                     invar = curv_invar_ratio_dds(ptr1, ptr2, 1);
326                     invar = fabs(log(fabs(invar)));
327                     surf->data[ii][jj] = vec3((float) j, (float) i, invar * scale);
328                     surf->data[jj][ii] = vec3((float) i, (float) j, invar * scale);
329                 }
330                 if (ptr2 == end)
331                     break;
332             }
333         }
334         if (ptr1 == end)
335             break;
336     }
337     return (surf);
338 }
339 
340 Pair   *curv_invar_closest(Tstring * es, double ratio)
341 /* pos2 string */
342 /* invar ratio to obtain */
343 {
344     List *ptr1;
345     List *ptr2;
346     List *start;
347     List *end;
348     double  rdiff = 0.0;
349     double  mindiff = 0.0;
350     List *minptr1 = NULL;
351     List *minptr2 = NULL;
352 
353     if (es == NULL || es->start == es->end)
354         return (NULL);
355 
356     start = es->start;
357     end = es->end;
358     for (ptr1 = start; ptr1->next != end; ptr1 = ptr1->next)
359         for (ptr2 = ptr1->next; ptr2 != end; ptr2 = ptr2->next)
360         {
361             rdiff = fabs(curv_invar_ratio(es, ptr1, es, ptr2) - ratio);
362 
363             if (minptr1 == NULL || rdiff < mindiff)
364             {
365                 minptr1 = ptr1;
366                 minptr2 = ptr2;
367                 mindiff = rdiff;
368             }
369         }
370     return (pair_alloc((void *) minptr1, (int) LIST, (void *) minptr2, (int) LIST));
371 }
372 
373 List   *curv_invar_matches(Tstring * es, double ratio)
374 /* pos2 string */
375 /* invar ratio to obtain */
376 {
377     List *ptr1;
378     List *ptr2;
379     List *start;
380     List *end;
381     double  last_ratio = 0.0;
382     double  this_ratio = 0.0;
383     List   *matches = NULL;
384 
385     if (es == NULL || es->start == es->end)
386         return (NULL);
387 
388     start = es->start;
389     end = es->end;
390     for (ptr1 = start;; ptr1 = ptr1->next)
391     {
392         for (ptr2 = start;; ptr2 = ptr2->next, last_ratio = this_ratio)
393         {
394             if (ptr1 == ptr2)
395             {
396                 if (ptr2 == end)
397                     break;
398                 continue;
399             }
400             this_ratio = curv_invar_ratio(es, ptr1, es, ptr2);
401 
402             if (ptr2 == start)
403                 continue;
404 
405             if (BETWEEN(ratio, last_ratio, this_ratio))
406             {
407                 Pair   *pair;
408                 double  lastrdiff = fabs(last_ratio - ratio);
409                 double  thisrdiff = fabs(this_ratio - ratio);
410                 List *ptr;
411                 double  diff;
412 
413                 diff = MIN(lastrdiff, thisrdiff);
414                 if (fabs(diff / ratio) > 0.05)
415                     continue;
416                 ptr = (lastrdiff < thisrdiff) ? ptr2->last : ptr2;
417                 pair = pair_alloc((void *) ptr1, (int) LIST, (void *) ptr, (int) LIST);
418                 matches = ref_addtostart((List *) matches, (void *) pair, PAIRS);
419             }
420             if (ptr2 == end)
421                 break;
422         }
423         if (ptr1 == end)
424             break;
425     }
426     return (matches);
427 }
428 

~ [ 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.