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

Linux Cross Reference
Tina4/src/vision/curve3/str3_tris.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 Bool    dist_to_pos3(Vec3 * ptr, int type, Vec3 * pp, double *dist)
 12 {
 13     if (ptr == NULL || type != VEC3)
 14         return (false);
 15 
 16     *dist = vec3_mod(vec3_diff(*pp, *ptr));
 17     return (true);
 18 }
 19 
 20 Vec3   *tri3_make(Vec3 p1, Vec3 p2, Vec3 p3)
 21 {
 22     Vec3   *tri;
 23 
 24     tri = ts_nvector_alloc(0, 3, Vec3); /* array of VEC3 */
 25     tri[0] = p1;
 26     tri[1] = p2;
 27     tri[2] = p3;
 28     return (tri);
 29 }
 30 
 31 List   *str3_triangulate(Tstring * s1, Tstring * s2, int sample)
 32 {
 33     List *ptr1;
 34     List *ptr2;
 35     List *end;
 36     Vec3    p1 = {Vec3_id};
 37     Vec3    p2 = {Vec3_id};
 38     Vec3    p1_last = {Vec3_id};
 39     Vec3    p2_last = {Vec3_id};
 40     List   *tris = NULL;
 41     int     i;
 42 
 43     if (s1 == NULL || s2 == NULL || s1->start == s1->end)
 44         return (NULL);
 45 
 46     ptr1 = s1->start;
 47     end = s1->end;
 48     p1_last = *(Vec3 *) (ptr1->to);
 49     ptr2 = str_get_min(s2, dist_to_pos3, (void *) &p1_last);
 50     p2_last = *(Vec3 *) (ptr2->to);
 51     ptr1 = ptr1->next;
 52 
 53     for (i = 1;; i++, ptr1 = ptr1->next)
 54     {
 55         if (i % sample == 0 || ptr1 == end)
 56         {
 57             if (ptr1 == end && s1->type == LOOP)
 58                 p1 = *(Vec3 *) (s1->start->to);
 59             else
 60                 p1 = *(Vec3 *) (ptr1->to);
 61             ptr2 = str_get_min(s2, dist_to_pos3, (void *) &p1);
 62             p2 = *(Vec3 *) (ptr2->to);
 63 
 64             tris = ref_addtostart(tris, (void *) tri3_make(p1_last, p2_last, p2), TRIANGLE3);
 65             tris = ref_addtostart(tris, (void *) tri3_make(p1_last, p2, p1), TRIANGLE3);
 66             p1_last = p1;
 67             p2_last = p2;
 68         }
 69         if (ptr1 == end)
 70             break;
 71     }
 72     return (tris);
 73 }
 74 
 75 static Vec3 *make_vec3_from_vec2(Vec2 * v2, int *type, double *z)
 76 {
 77     Vec3   *v3;
 78 
 79     v3 = vec3_make(vec3_of_vec2(*v2));
 80     vec3_z(*v3) = (float) *z;
 81     *type = VEC3;
 82     return (v3);
 83 }
 84 
 85 List   *str2_triangulate3(Tstring * s1, double z1, Tstring * s2, double z2, int sample)
 86 {
 87     Tstring *s1_3, *s2_3;
 88     List   *tris;
 89 
 90     s1_3 = reclist_string_update(s1, (void *(*) ()) make_vec3_from_vec2,
 91                                  VEC2, (void *) &z1);
 92     s2_3 = reclist_string_update(s2, (void *(*) ()) make_vec3_from_vec2,
 93                                  VEC2, (void *) &z2);
 94     tris = str3_triangulate(s1_3, s2_3, sample);
 95     str_rm(s1_3, rfree);
 96     str_rm(s2_3, rfree);
 97     return (tris);
 98 }
 99 

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