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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visPgh_misc.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/vision/visPgh_misc.c,v $
 27  * Date    :  $Date: 2008/12/02 22:03:07 $
 28  * Version :  $Revision: 1.5 $
 29  * CVS Id  :  $Id: visPgh_misc.c,v 1.5 2008/12/02 22:03:07 paul Exp $
 30  *
 31  * Author  : A.Ashbrook, NAT.
 32  */
 33 /**
 34  * @file support functions for aligning poly line geometry with scene.
 35  * @brief Includes functions for producing mirror symmetric version and 180 degree
 36  *        rotations, in accordance with assumptions used in some PGH variants.
 37 */
 38 
 39 #include "visPgh_misc.h"
 40 #include <stdio.h>
 41 
 42 #include <math.h>
 43 #include <tina/sys/sysDef.h>
 44 #include <tina/sys/sysPro.h>
 45 #include <tina/math/mathDef.h>
 46 #include <tina/math/mathPro.h>
 47 #include <tina/image/imgGen_alloc.h>
 48 #include <tina/image/imgGen_alloc.h>
 49 #include <tina/geometry/geom_LinePro.h>
 50 #include <tina/vision/visPgh_types.h>
 51 #include <tina/vision/visPgh_var.h>
 52 #include <tina/vision/visPgh_histfuncs.h>
 53 
 54 /* This function generates pairwise histograms for each line which has been
 55    selected in the mono tv. Each histogram is pushed onto the stack.
 56 */
 57 
 58 void rotate_matched_model(void)
 59 {
 60     List  *matched_models_list;
 61     Line2 *matched_line;
 62 
 63     matched_models_list = pairs_matched_models_list_get();
 64     matched_line = pairs_matched_line_get();
 65 
 66     if (matched_line==NULL) 
 67                 return; /* not a single model */
 68 
 69     poly_rotate(matched_models_list, PI, matched_line->p);
 70 
 71 }
 72 
 73 /* ---------- */
 74 
 75 void mirror_matched_model(void)
 76 {
 77     Vec2        translation, matched_line_pos; 
 78     Mat2        rotation_matrix;
 79     List       *ptr;
 80     Line2      *lptr;
 81     double      rotation;
 82     Transform2  model_trans;
 83     List       *matched_models_list;
 84     Line2      *matched_line;
 85 
 86     matched_models_list = pairs_matched_models_list_get();
 87     matched_line = pairs_matched_line_get();
 88 
 89 
 90     if (matched_models_list==NULL||matched_line==NULL) 
 91                 return;
 92 
 93         /* (1) Determine the transformation to map the matched_line
 94                onto the origin oriented along the y-axis.
 95            (2) Multiply each x-coord of the transformed model data 
 96                by -1.
 97            (3) Transform the matched_line back to its original position.
 98         */
 99 
100 /* Make a note of the position of the matched_line so that it can be 
101    repositioned later. */
102 
103     matched_line_pos = matched_line->p;
104 
105 /* Now determine the transformation */
106 
107     rotation = vec2_angle(vec2_ey(),matched_line->v); 
108     rotation_matrix = rot2(rotation);
109  
110     translation = vec2_diff(matched_line->p,
111                    mat2_vprod(rotation_matrix, matched_line->p));
112 
113     translation = vec2_diff(translation, matched_line->p );
114 
115     model_trans.R = rotation_matrix;
116     model_trans.t = translation;
117 
118 /* Now transform the model data to the origin*/
119 
120     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
121         line2_transform(ptr->to, model_trans);  
122 
123 /* Now multiply the x-coord of each model line by -1 */
124 
125     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
126     {
127         lptr = ptr->to;
128         vec2_x(lptr->p1) = -1*vec2_x(lptr->p1);
129         vec2_x(lptr->p2) = -1*vec2_x(lptr->p2);
130         vec2_x(lptr->p) = -1*vec2_x(lptr->p);
131         vec2_x(lptr->v) = -1*vec2_x(lptr->v);
132     }
133 
134 /* Now transform the matched line back to its original position */
135 
136     rotation = -1*rotation;
137     rotation_matrix = rot2(rotation);
138 
139     model_trans.R = rotation_matrix;
140     model_trans.t = matched_line_pos;
141 
142     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
143         line2_transform(ptr->to, model_trans);  
144 
145 }
146 
147 /* ---------- */
148 
149 List *geom_to_pairwise_list(List *geom, List *scene_pairs_list, double min_length, double window_r)
150 {
151     List     *ptr;
152     Line2    *lptr;
153     Imrect   *im;
154 
155     if (geom==NULL) return(NULL);
156 
157 /* set the p-field of each line to the lines mid-point */
158 
159     for(ptr=geom; ptr!=NULL;ptr=ptr->next)
160     {
161         lptr = ptr->to;
162         lptr->p = vec2_midpoint(lptr->p1, lptr->p2);
163     }
164 
165 /* If a pairwise list has already been constructed free this to make room 
166    for the new list */
167 
168     if (scene_pairs_list!=NULL)
169     {
170         list_rm(scene_pairs_list, im_free);
171         scene_pairs_list = NULL;
172     }
173 
174 /* Now build the histograms and adds them to the scene_pairs_list */
175 
176     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
177     {
178         lptr = ptr->to;
179                 if (lptr->length>min_length)
180                 {
181                         im = build_normalized_pairwise(lptr, NULL, geom, window_r);
182                         scene_pairs_list = ref_addtostart(scene_pairs_list, im, IMRECT);
183                 }
184 
185     }/*endfor(ptr)*/
186 
187     return scene_pairs_list;
188 }
189 
190 /* ---------- */
191 
192 /* This function determines the origin of a model by overlaying the scaled
193    model line on top of the scene line */
194 
195 Point2 origin1_from_match(Line2 *scene_line, Line2 *model_line, double scale_factor)
196 {
197     Vec2   model_vec, scene_vec, origin_vec;
198     double rotation;
199     Mat2   rotation_mat;
200     Point2 origin;
201 
202     /* Added to prevent compiler warnings PAB 02/12/2008 */
203 
204     origin.props = NULL;
205     origin.label = 0;
206     origin.type = 0;
207     origin.ts_id = 0;
208     origin.p.ts_id = 0;
209 
210     model_vec = vec2_times(scale_factor, model_line->p);
211 
212     rotation = vec2_angle(model_line->v, scene_line->v);
213     rotation_mat = rot2(rotation);
214     scene_vec = mat2_vprod(rotation_mat, model_vec);
215     origin_vec = vec2_diff(scene_line->p, scene_vec);
216 
217     vec2_x(origin.p) = vec2_x(origin_vec);
218     vec2_y(origin.p) = vec2_y(origin_vec);
219 
220     return (origin);
221 }
222 
223 /* ---------- */
224 
225 /* This function determines the origin of a model by overlaying the scaled
226    model line on top of the scene line */
227 
228 Point2 origin2_from_match(Line2 *scene_line, Line2 *model_line, double scale_factor)
229 {
230     Vec2   model_vec, scene_vec, origin_vec;
231     double rotation;
232     Mat2   rotation_mat;
233     Point2 origin;
234 
235     /* Added to prevent compiler warnings PAB 02/12/2008 */
236 
237     origin.props = NULL;
238     origin.label = 0;
239     origin.type = 0;
240     origin.ts_id = 0;
241     origin.p.ts_id = 0;
242 
243     model_vec = vec2_times(scale_factor, model_line->p);
244 
245     rotation = vec2_angle(model_line->v, scene_line->v);
246     rotation_mat = rot2(rotation);
247     scene_vec = mat2_vprod(rotation_mat, model_vec);
248     origin_vec = vec2_sum(scene_line->p, scene_vec);
249 
250     vec2_x(origin.p) = vec2_x(origin_vec);
251     vec2_y(origin.p) = vec2_y(origin_vec);
252 
253     return (origin);
254 }
255 
256 /* ---------- */
257 

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