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

Linux Cross Reference
Tina4/src/pgh/pgh_misc.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <stdio.h>
  2 #include <sys/param.h>
  3 #include <string.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 #include <tina/file.h>
 11 #include <tina/filefuncs.h>
 12 #include <tina/file_gen.h>
 13 #include <tina/draw.h>
 14 #include <tina/drawfuncs.h>
 15 #include <tina/tv.h>
 16 #include <tina/tvfuncs.h>
 17 #include <tina/toolsfuncs.h>
 18 #include <tina/tw_Xfuncs.h>
 19 #include <pgh/pgh_defs.h>
 20 #include <pgh/pgh_types.h>
 21 #include <pgh/pgh_funcs.h>
 22 
 23 /* ---------- */
 24 
 25 void pgh_status(void)
 26 {
 27         int count = 0;
 28     List            *geom, *ptr;
 29     Line2           *lptr;
 30     Pairs_hist_def  *hist_def;
 31         List                    *model_pairs_list;
 32         Imrect                  *hist;
 33 
 34     hist_def = pairs_hist_def_get();
 35         model_pairs_list = pairs_model_pairs_list_get();
 36         geom = mono_geom_get();
 37 
 38         format("Status\n------\n");
 39 
 40         if (model_pairs_list!=NULL)
 41         {
 42                 hist = model_pairs_list->to;
 43                 format("Stored histogram widths:  %d\n", hist->region->ux-hist->region->lx);
 44                 format("Stored histogram heights: %d\n", hist->region->uy-hist->region->ly);
 45         }
 46 
 47         for(ptr=model_pairs_list;ptr!=NULL;ptr=ptr->next)
 48         {
 49                 count++;
 50         }
 51 
 52         format("Num stored histograms: %d\n", count);
 53 
 54         count=0;
 55 
 56         for(ptr=geom;ptr!=NULL;ptr=ptr->next)
 57     {
 58         lptr = ptr->to;
 59         if (lptr->length>hist_def->min_length)
 60         {
 61                         count++;
 62 
 63         }
 64     }
 65         format("Num scene lines: %d\n\n", count);
 66 }
 67 
 68 /* ---------- */
 69 
 70 /* This function generates pairwise histograms for each line which has been
 71    selected in the mono tv. Each histogram is pushed onto the stack.
 72 */
 73 
 74 void lines_to_histograms(void)
 75 {
 76     List            *geom=NULL;
 77     List            *ptr;
 78     Imrect          *im;
 79     List            *picked_geom;
 80     Pairs_hist_def  *hist_def;
 81 
 82     picked_geom = pairs_picked_geom_get();
 83     hist_def = pairs_hist_def_get();
 84 
 85     init_pairs_entry(hist_def->pairs_type,
 86                      hist_def->dbin_max,
 87                      hist_def->dbin_size,
 88                      hist_def->num_abin,
 89                      hist_def->angle_sigma,
 90                      hist_def->dist_ramp);
 91 
 92     geom = mono_geom_get();
 93     if (geom==NULL||picked_geom==NULL) return;
 94 
 95     for (ptr = picked_geom;ptr!=NULL;ptr=ptr->next)
 96     {
 97         im = build_pairwise(ptr->to, NULL, geom, hist_def->dbin_max);       
 98         stack_push(im, IMRECT, im_free);
 99     }
100 }
101 
102 /* ---------- */
103 
104 void draw_matched_models(void)
105 {
106     List  *matched_models_list;
107     Line2 *matched_line;
108 
109     matched_models_list = pairs_matched_models_list_get();
110     matched_line = pairs_matched_line_get();
111 
112     tv_repaint(mono_tv());
113     tv_save_draw(mono_tv());  /* save context */
114 
115     if (matched_models_list!=NULL)
116     {
117         tv_set_color(mono_tv(), wheat); 
118         line2_list_draw(mono_tv(), matched_models_list);
119     }
120     
121     if (matched_line!=NULL)
122     {
123         tv_set_color(mono_tv(), green);
124         line2_draw(mono_tv(), matched_line);
125     }
126 
127     tv_reset_draw(mono_tv()); /* reset context */
128 }
129 
130 /* ---------- */
131 
132 void rotate_matched_model(void)
133 {
134     List  *matched_models_list;
135     Line2 *matched_line;
136 
137     matched_models_list = pairs_matched_models_list_get();
138     matched_line = pairs_matched_line_get();
139 
140     if (matched_line==NULL) return; /* not a single model */
141 
142     poly_rotate(matched_models_list, PI, matched_line->p);
143 
144 /* Now redraw the model on a fresh tv */
145 
146     tv_repaint(mono_tv());
147     draw_matched_models();
148 
149 }
150 
151 /* ---------- */
152 
153 void mirror_matched_model(void)
154 {
155     Vec2        translation, matched_line_pos; 
156     Mat2        rotation_matrix;
157     List       *ptr;
158     Line2      *lptr;
159     double      rotation;
160     Transform2  model_trans;
161     List       *matched_models_list;
162     Line2      *matched_line;
163 
164     matched_models_list = pairs_matched_models_list_get();
165     matched_line = pairs_matched_line_get();
166 
167 
168     if (matched_models_list==NULL||matched_line==NULL) return;
169 
170         /* (1) Determine the transformation to map the matched_line
171                onto the origin oriented along the y-axis.
172            (2) Multiply each x-coord of the transformed model data 
173                by -1.
174            (3) Transform the matched_line back to its original position.
175         */
176 
177 /* Make a note of the position of the matched_line so that it can be 
178    repositioned later. */
179 
180     matched_line_pos = matched_line->p;
181 
182 /* Now determine the transformation */
183 
184     rotation = vec2_angle(vec2_ey(),matched_line->v); 
185     rotation_matrix = rot2(rotation);
186  
187     translation = vec2_diff(matched_line->p,
188                    mat2_vprod(rotation_matrix, matched_line->p));
189 
190     translation = vec2_diff(translation, matched_line->p );
191 
192     model_trans.R = rotation_matrix;
193     model_trans.t = translation;
194 
195 /* Now transform the model data to the origin*/
196 
197     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
198         line2_transform(ptr->to, model_trans);  
199 
200 /* Now multiply the x-coord of each model line by -1 */
201 
202     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
203     {
204         lptr = ptr->to;
205         vec2_x(lptr->p1) = -1*vec2_x(lptr->p1);
206         vec2_x(lptr->p2) = -1*vec2_x(lptr->p2);
207         vec2_x(lptr->p) = -1*vec2_x(lptr->p);
208         vec2_x(lptr->v) = -1*vec2_x(lptr->v);
209     }
210 
211 /* Now transform the matched line back to its original position */
212 
213     rotation = -1*rotation;
214     rotation_matrix = rot2(rotation);
215 
216     model_trans.R = rotation_matrix;
217     model_trans.t = matched_line_pos;
218 
219     for(ptr=matched_models_list;ptr!=NULL;ptr=ptr->next)
220         line2_transform(ptr->to, model_trans);  
221 
222 /* Now redraw the model on a fresh tv */
223 
224     tv_repaint(mono_tv());
225     draw_matched_models();
226 
227 }
228 
229 /* ---------- */
230 
231 List *geom_to_pairwise_list(List *geom, List *scene_pairs_list, double min_length, double window_r)
232 {
233     List     *ptr;
234     List     *link_alloc();
235     List     * mono_geom_get();
236     Line2    *lptr;
237     Imrect   *im,*im_pairs_alloc();
238 
239     if (geom==NULL) return(NULL);
240 
241 /* set the p-field of each line to the lines mid-point */
242 
243     for(ptr=geom; ptr!=NULL;ptr=ptr->next)
244     {
245         lptr = ptr->to;
246         lptr->p = vec2_midpoint(lptr->p1, lptr->p2);
247     }
248 
249 /* If a pairwise list has already been constructed free this to make room 
250    for the new list */
251 
252     if (scene_pairs_list!=NULL)
253     {
254         list_rm(scene_pairs_list, im_free);
255         scene_pairs_list = NULL;
256     }
257 
258 /* Now build the histograms and adds them to the scene_pairs_list */
259 
260     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
261     {
262         lptr = ptr->to;
263                 if (lptr->length>min_length)
264                 {
265                         im = build_normalized_pairwise(lptr, NULL, geom, window_r);
266                         scene_pairs_list = ref_addtostart(scene_pairs_list, im, IMRECT);
267                 }
268 
269     }/*endfor(ptr)*/
270 
271     return scene_pairs_list;
272 }
273 
274 /* ---------- */
275 
276 /* This function determines the origin of a model by overlaying the scaled
277    model line on top of the scene line */
278 
279 Point2 origin1_from_match(Line2 *scene_line, Line2 *model_line, double scale_factor)
280 {
281     Vec2   model_vec, scene_vec, origin_vec;
282     double rotation;
283     Mat2   rotation_mat;
284     Point2 origin;
285 
286     model_vec = vec2_times(scale_factor, model_line->p);
287 
288     rotation = vec2_angle(model_line->v, scene_line->v);
289     rotation_mat = rot2(rotation);
290     scene_vec = mat2_vprod(rotation_mat, model_vec);
291     origin_vec = vec2_diff(scene_line->p, scene_vec);
292 
293     vec2_x(origin.p) = vec2_x(origin_vec);
294     vec2_y(origin.p) = vec2_y(origin_vec);
295 
296     return (origin);
297 }
298 
299 /* ---------- */
300 
301 /* This function determines the origin of a model by overlaying the scaled
302    model line on top of the scene line */
303 
304 Point2 origin2_from_match(Line2 *scene_line, Line2 *model_line, double scale_factor)
305 {
306     Vec2   model_vec, scene_vec, origin_vec;
307     double rotation;
308     Mat2   rotation_mat;
309     Point2 origin;
310 
311     model_vec = vec2_times(scale_factor, model_line->p);
312 
313     rotation = vec2_angle(model_line->v, scene_line->v);
314     rotation_mat = rot2(rotation);
315     scene_vec = mat2_vprod(rotation_mat, model_vec);
316     origin_vec = vec2_sum(scene_line->p, scene_vec);
317 
318     vec2_x(origin.p) = vec2_x(origin_vec);
319     vec2_y(origin.p) = vec2_y(origin_vec);
320 
321     return (origin);
322 }
323 
324 /* ---------- */
325 
326 

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