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

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

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