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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomCurve_str3_tris.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_str3_tris.c,v $
 23  * Date    :  $Date: 2002/12/09 11:51:23 $
 24  * Version :  $Revision: 1.1.1.1 $
 25  * CVS Id  :  $Id: geomCurve_str3_tris.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_str3_tris.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/geometry/geomDef.h>
 46 
 47 
 48 Bool    dist_to_pos3(Vec3 * ptr, int type, Vec3 * pp, double *dist)
 49 {
 50     if (ptr == NULL || type != VEC3)
 51         return (false);
 52 
 53     *dist = vec3_mod(vec3_diff(*pp, *ptr));
 54     return (true);
 55 }
 56 
 57 Vec3   *tri3_make(Vec3 p1, Vec3 p2, Vec3 p3)
 58 {
 59     Vec3   *tri;
 60 
 61     tri = ts_nvector_alloc(0, 3, Vec3); /* array of VEC3 */
 62     tri[0] = p1;
 63     tri[1] = p2;
 64     tri[2] = p3;
 65     return (tri);
 66 }
 67 
 68 List   *str3_triangulate(Tstring * s1, Tstring * s2, int sample)
 69 {
 70     List *ptr1;
 71     List *ptr2;
 72     List *end;
 73     Vec3    p1 = {Vec3_id};
 74     Vec3    p2 = {Vec3_id};
 75     Vec3    p1_last = {Vec3_id};
 76     Vec3    p2_last = {Vec3_id};
 77     List   *tris = NULL;
 78     int     i;
 79 
 80     if (s1 == NULL || s2 == NULL || s1->start == s1->end)
 81         return (NULL);
 82 
 83     ptr1 = s1->start;
 84     end = s1->end;
 85     p1_last = *(Vec3 *) (ptr1->to);
 86     ptr2 = str_get_min(s2, dist_to_pos3, (void *) &p1_last);
 87     p2_last = *(Vec3 *) (ptr2->to);
 88     ptr1 = ptr1->next;
 89 
 90     for (i = 1;; i++, ptr1 = ptr1->next)
 91     {
 92         if (i % sample == 0 || ptr1 == end)
 93         {
 94             if (ptr1 == end && s1->type == LOOP)
 95                 p1 = *(Vec3 *) (s1->start->to);
 96             else
 97                 p1 = *(Vec3 *) (ptr1->to);
 98             ptr2 = str_get_min(s2, dist_to_pos3, (void *) &p1);
 99             p2 = *(Vec3 *) (ptr2->to);
100 
101             tris = ref_addtostart(tris, (void *) tri3_make(p1_last, p2_last, p2), TRIANGLE3);
102             tris = ref_addtostart(tris, (void *) tri3_make(p1_last, p2, p1), TRIANGLE3);
103             p1_last = p1;
104             p2_last = p2;
105         }
106         if (ptr1 == end)
107             break;
108     }
109     return (tris);
110 }
111 
112 static Vec3 *make_vec3_from_vec2(Vec2 * v2, int *type, double *z)
113 {
114     Vec3   *v3;
115 
116     v3 = vec3_make(vec3_of_vec2(*v2));
117     vec3_z(*v3) = (float) *z;
118     *type = VEC3;
119     return (v3);
120 }
121 
122 List   *str2_triangulate3(Tstring * s1, double z1, Tstring * s2, double z2, int sample)
123 {
124     Tstring *s1_3, *s2_3;
125     List   *tris;
126 
127     s1_3 = reclist_string_update(s1, (void *(*) ()) make_vec3_from_vec2,
128                                  VEC2, (void *) &z1);
129     s2_3 = reclist_string_update(s2, (void *(*) ()) make_vec3_from_vec2,
130                                  VEC2, (void *) &z2);
131     tris = str3_triangulate(s1_3, s2_3, sample);
132     str_rm(s1_3, rfree);
133     str_rm(s2_3, rfree);
134     return (tris);
135 }
136 

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