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

Linux Cross Reference
Tina4/src/vision/curve2/curvinvar.c

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

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

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