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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomTrans_trnslation.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/geomTrans_trnslation.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomTrans_trnslation.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Notes :
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomTrans_trnslation.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <stdio.h>
 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/geometry/geomDef.h>
 50 #include <tina/geometry/geom_TransDef.h>
 51 
 52 static Mat3 trans_mat3_get(Vec3 p1, Vec3 v1, Vec3 p2, Vec3 v2, double weight)
 53 /* BUG p1 & p2 unused */
 54 
 55 
 56 {
 57     Mat3    V = {Mat3_id};
 58     int     i, j;
 59 
 60     for (i = 0; i < 3; ++i)
 61         V.el[i][i] = (float)((2 - v1.el[i] * v1.el[i] - v2.el[i] * v2.el[i]) * weight);
 62 
 63     for (i = 0; i < 3; ++i)
 64         for (j = i + 1; j < 3; ++j)
 65         {
 66             float   val;
 67 
 68             val = (float)((-v1.el[i] * v1.el[j] - v2.el[i] * v2.el[j]) * weight);
 69             V.el[i][j] = V.el[j][i] = val;
 70         }
 71 
 72     return (V);
 73 }
 74 
 75 Vec3    mlist_comp_translate_vec3(List * match_list, Mat3 R)
 76 {
 77     Mat3    P = {Mat3_id};
 78     Mat3    V = {Mat3_id};
 79     Vec3    Y = {Vec3_id};
 80     List   *lptr;
 81 
 82     Y = vec3_zero();
 83     P = mat3_zero();
 84 
 85     for (lptr = match_list; lptr != NULL; lptr = lptr->next)
 86     {
 87         Match  *mptr = (Match *) lptr->to;
 88         Vec3    p1 = {Vec3_id};
 89         Vec3    p2 = {Vec3_id};
 90         Vec3    v1 = {Vec3_id};
 91         Vec3    v2 = {Vec3_id};
 92         Vec3    diff = {Vec3_id};
 93 
 94         switch (mptr->type)
 95         {
 96         case LINE3:
 97             v1 = ((Line3 *) mptr->to1)->v;
 98             p1 = ((Line3 *) mptr->to1)->p;
 99             v2 = ((Line3 *) mptr->to2)->v;
100             p2 = ((Line3 *) mptr->to2)->p;
101             break;
102         case CONIC3:
103             v1 = ((Conic3 *) mptr->to1)->ez;
104             p1 = ((Conic3 *) mptr->to1)->origin;
105             v2 = ((Conic3 *) mptr->to2)->ez;
106             p2 = ((Conic3 *) mptr->to2)->origin;
107             break;
108         default:
109             continue;
110         }
111 
112         p1 = mat3_vprod(R, p1);
113         v1 = mat3_vprod(R, v1);
114         diff = vec3_diff(p2, p1);
115         V = trans_mat3_get(p1, v1, p2, v2, mptr->weight);
116         P = mat3_sum(P, V);
117         Y = vec3_sum(Y, mat3_vprod(V, diff));
118     }
119 
120     return (mat3_vprod(mat3_inverse(P), Y));
121 }
122 
123 Vec3    mlist_comp_translate_all(List * match_list, Mat3 R)
124 {
125     Mat3    P = {Mat3_id};
126     Mat3    V = {Mat3_id};
127     Vec3    Y = {Vec3_id};
128     List   *lptr1;
129     List   *lptr2;
130 
131     Y = vec3_zero();
132     P = mat3_zero();
133 
134     for (lptr1 = match_list; lptr1 != NULL; lptr1 = lptr1->next)
135     {
136         Match  *mptr1 = (Match *) lptr1->to;
137         Vec3    p1 = {Vec3_id};
138         Vec3    p2 = {Vec3_id};
139         Vec3    v1 = {Vec3_id};
140         Vec3    v2 = {Vec3_id};
141         Vec3    diff = {Vec3_id};
142 
143         switch (mptr1->type)
144         {
145         case POINT3:
146             break;
147         case LINE3:
148             v1 = ((Line3 *) mptr1->to1)->v;
149             p1 = ((Line3 *) mptr1->to1)->p;
150             v2 = ((Line3 *) mptr1->to2)->v;
151             p2 = ((Line3 *) mptr1->to2)->p;
152             break;
153         case CONIC3:
154             v1 = ((Conic3 *) mptr1->to1)->ez;
155             p1 = ((Conic3 *) mptr1->to1)->origin;
156             v2 = ((Conic3 *) mptr1->to2)->ez;
157             p2 = ((Conic3 *) mptr1->to2)->origin;
158             break;
159         default:
160             continue;
161         }
162 
163         if (mptr1->type != POINT3)
164         {
165             p1 = mat3_vprod(R, p1);
166             v1 = mat3_vprod(R, v1);
167             diff = vec3_diff(p2, p1);
168             V = trans_mat3_get(p1, v1, p2, v2, mptr1->weight);
169             P = mat3_sum(P, V);
170             Y = vec3_sum(Y, mat3_vprod(V, diff));
171         }
172         switch (mptr1->type)
173         {
174         default:
175             continue;
176         case POINT3:
177             p1 = ((Point3 *) mptr1->to1)->p;
178             p2 = ((Point3 *) mptr1->to2)->p;
179             break;
180         case CONIC3:
181             p1 = ((Conic3 *) mptr1->to1)->origin;
182             p2 = ((Conic3 *) mptr1->to2)->origin;
183             break;
184         }
185 
186         for (lptr2 = lptr1->next; lptr2 != NULL; lptr2 = lptr2->next)
187         {
188             Match  *mptr2 = (Match *) lptr2->to;
189 
190             switch (mptr2->type)
191             {
192             default:
193                 continue;
194             case POINT3:
195                 v1 = vec3_diff(((Point3 *) mptr2->to1)->p, p1);
196                 v2 = vec3_diff(((Point3 *) mptr2->to2)->p, p2);
197                 break;
198             case CONIC3:
199                 v1 = vec3_diff(((Conic3 *) mptr2->to1)->origin, p1);
200                 v2 = vec3_diff(((Conic3 *) mptr2->to2)->origin, p2);
201                 break;
202             }
203             v1 = vec3_unit(v1);
204             v2 = vec3_unit(v2);
205 
206             p1 = mat3_vprod(R, p1);
207             v1 = mat3_vprod(R, v1);
208             diff = vec3_diff(p2, p1);
209             V = trans_mat3_get(p1, v1, p2, v2, (mptr1->weight + mptr2->weight) * 0.5);
210             P = mat3_sum(P, V);
211             Y = vec3_sum(Y, mat3_vprod(V, diff));
212         }
213     }
214 
215     return (mat3_vprod(mat3_inverse(P), Y));
216 }
217 
218 Vec3    mlist_comp_translate_pos3(List * match_list, Mat3 R)
219 {
220     Vec3    T = {Vec3_id};
221     List   *lptr;
222     float   tot_weight = (float)0.0;
223 
224     T = vec3_zero();
225 
226     for (lptr = match_list; lptr != NULL; lptr = lptr->next)
227     {
228         Match  *mptr = (Match *) lptr->to;
229         Vec3    p1 = {Vec3_id};
230         Vec3    p2 = {Vec3_id};
231         Vec3    diff = {Vec3_id};
232 
233         switch (mptr->type)
234         {
235         default:
236             continue;
237         case POINT3:
238             p1 = ((Point3 *) mptr->to1)->p;
239             p2 = ((Point3 *) mptr->to2)->p;
240             break;
241         case CONIC3:
242             p1 = ((Conic3 *) mptr->to1)->origin;
243             p2 = ((Conic3 *) mptr->to2)->origin;
244             break;
245         }
246 
247         diff = vec3_diff(p2, mat3_vprod(R, p1));
248         T = vec3_sum(T, vec3_times(mptr->weight, diff));
249         tot_weight += mptr->weight;
250     }
251 
252     return (vec3_times(1 / tot_weight, T));
253 }
254 

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