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

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

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