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

Linux Cross Reference
Tina4/src/tools/coreg/coreg_view.c

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

  1 #include <stdio.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 #include <tina/visionfuncs.h>
  8 #include <tina/tv.h>
  9 #include <tina/tvfuncs.h>
 10 #include <tina/draw.h>
 11 #include <tina/drawfuncs.h>
 12 #include <tina/seqoral.h>
 13 #include <tina/AIR.h>
 14 #define Bit(mask,num)     (mask&(1<<num))
 15 
 16 static Imrect *xcoreg_im=NULL,*xcoreg_disp=NULL;
 17 static Imrect *ycoreg_im=NULL,*ycoreg_disp=NULL;
 18 static Imrect *zcoreg_im=NULL,*zcoreg_disp=NULL;
 19 static Tv* zcoreg_tv = NULL;
 20 static Tv* ycoreg_tv = NULL;
 21 static Tv* xcoreg_tv = NULL;
 22 static double xcentre = 128.0;
 23 static double ycentre = 128.0;
 24 static double zcentre = 40.0;
 25 static Imrect *imref=NULL;
 26 double xscale = 1.0;
 27 double yscale = 1.0;
 28 double zscale = 2.0;
 29 double nxscale = 1.0;
 30 double nyscale = 1.0;
 31 double nzscale = 2.0;
 32 double ixscale = 1.0;
 33 double iyscale = 1.0;
 34 double izscale = 2.0;
 35 static double min_scale = 1.0;
 36 static Bool zoom_on = false;
 37 static double zoom_fac = 1.0;
 38 static int imptrlx, imptrux,imptrly, imptruy, imptrlz, imptruz;
 39 /*Vec3 coreg_ex, coreg_ey, coreg_ez, coreg_ec;
 40 */
 41 double ex[3],ey[3],ez[3],ec[3];
 42 static double threshold = 600.0;
 43 static void ***imptrs=NULL;
 44 static disp_im_type = 0;
 45 static Mat3 *store_rot=NULL, *store_inv = NULL;
 46 extern Imrect * coreg_slicez(float zslice, Imregion *within);
 47 extern Imrect * coreg_slicey(float yslice, Imregion *within);
 48 extern Imrect * coreg_slicex(float xslice, Imregion *within);
 49 extern void reset_air();
 50 extern void reset_centre(double xcen, double ycen, double zcen);
 51 extern double transfer_threshold_to_coreg_view();
 52 
 53 
 54 /* Modified 12/10/01 PAB: receive threshold from coreg_tool.c and apply it when image is latched 
 55 for anaglyph display */
 56 
 57 void store_rot_init()
 58 {
 59    store_rot = mat3_alloc();
 60    store_inv = mat3_alloc();
 61    store_rot->el[0][0] = ex[0];
 62    store_rot->el[0][1] = ex[1];
 63    store_rot->el[0][2] = ex[2];
 64    store_rot->el[1][0] = ey[0];
 65    store_rot->el[1][1] = ey[1];
 66    store_rot->el[1][2] = ey[2];
 67    store_rot->el[2][0] = ez[0];
 68    store_rot->el[2][1] = ez[1];
 69    store_rot->el[2][2] = ez[2];
 70    *store_inv = mat3_inverse(*store_rot); 
 71 }
 72 
 73 void store_rot_reset()
 74 {
 75    mat3_free(store_rot);
 76    mat3_free(store_inv);
 77 
 78    store_rot = NULL;
 79    store_inv = NULL;
 80 }
 81 
 82 Imrect *get_zcoreg_im()
 83 {
 84     return(zcoreg_im);
 85 }
 86 
 87 Imrect *get_ycoreg_im()
 88 {
 89     return(ycoreg_im);
 90 }
 91 
 92 Imrect *get_xcoreg_im()
 93 {
 94     return(xcoreg_im);
 95 }
 96 
 97 int coreg_get_vec(double *coreg_vec, int mask)
 98 {
 99     double vec[4];
100     Mat3 mat;
101     int i=0;
102 
103     if (Bit(mask,0))
104     {
105       coreg_vec[i++] = ec[0];
106       coreg_vec[i++] = ec[1];
107       coreg_vec[i++] = ec[2];
108     }
109     if (Bit(mask,1))
110     {
111       mat.el[0][0] = ex[0];
112       mat.el[0][1] = ex[1];
113       mat.el[0][2] = ex[2];
114       mat.el[1][0] = ey[0];
115       mat.el[1][1] = ey[1];
116       mat.el[1][2] = ey[2];
117       mat.el[2][0] = ez[0];
118       mat.el[2][1] = ez[1];
119       mat.el[2][2] = ez[2];
120       mat = mat3_prod(*store_inv,mat);
121       conv_rot_to_quat(&mat,vec);
122       coreg_vec[i++] = vec[1];
123       coreg_vec[i++] = vec[2];
124       coreg_vec[i++] = vec[3];
125     }
126     if (Bit(mask,2))
127     {
128       coreg_vec[i++] = xscale;
129       coreg_vec[i++] = yscale;
130       coreg_vec[i++] = zscale;
131     }
132     return(i);
133 }
134 
135 int coreg_set_vec(double *coreg_vec, int mask)
136 {
137     double x[4];
138     Mat3 mat;
139     int i=0;
140 
141     if (Bit(mask,0))
142     {
143       ec[0] = coreg_vec[i++];
144       ec[1] = coreg_vec[i++];
145       ec[2] = coreg_vec[i++];
146     }
147     if (Bit(mask,1))
148     {
149       x[1] = coreg_vec[i++];
150       x[2] = coreg_vec[i++];
151       x[3] = coreg_vec[i++];
152       if ((x[0] = 1.0 - x[1] * x[1] - x[2] * x[2] - x[3] * x[3]) > 0.0)
153           x[0] = sqrt(x[0]);
154       else
155           return (0);
156 
157       conv_quat_to_rot(x,&mat);
158       mat = mat3_prod(*store_rot,mat);
159       ex[0] = mat.el[0][0];
160       ex[1] = mat.el[0][1];
161       ex[2] = mat.el[0][2];
162       ey[0] = mat.el[1][0];
163       ey[1] = mat.el[1][1];
164       ey[2] = mat.el[1][2];
165       ez[0] = mat.el[2][0];
166       ez[1] = mat.el[2][1];
167       ez[2] = mat.el[2][2];
168     }
169     if (Bit(mask,2))
170     {
171       xscale = coreg_vec[i++];
172       yscale = coreg_vec[i++];
173       zscale = coreg_vec[i++];
174     }
175     return(1);
176 }
177 
178 Vec3 coreg_ex()
179 {
180    return(vec3(ex[0],ex[1],ex[2]));
181 }
182 
183 Vec3 coreg_ey()
184 {
185    return(vec3(ey[0],ey[1],ey[2]));
186 }
187 
188 Vec3 coreg_ez()
189 {
190    return(vec3(ez[0],ez[1],ez[2]));
191 }
192 
193 Vec3 coreg_ec()
194 {
195    return(vec3(ec[0],ec[1],ec[2]));
196 }
197 
198 void coreg_comp(double *a, Vec3 vec)
199 {
200     a[0] = (double)vec.el[0];
201     a[1] = (double)vec.el[1];
202     a[2] = (double)vec.el[2];
203 }
204 
205 void reset_tv_coords()
206 {
207     if (zcoreg_tv!=NULL)
208     {
209         zcoreg_tv->centre3 = coreg_ec();
210         zcoreg_tv->centre2.el[0] = xcentre;
211         zcoreg_tv->centre2.el[1] = ycentre;
212         zcoreg_tv->ex3 = coreg_ex(); 
213         zcoreg_tv->ey3 = coreg_ey(); 
214         zcoreg_tv->ez3 = coreg_ez(); 
215         zcoreg_tv->scalex = xscale/min_scale;
216         zcoreg_tv->scaley = yscale/min_scale;
217     }
218  
219     if (ycoreg_tv!=NULL)
220     {
221         ycoreg_tv->centre3 = coreg_ec();
222         ycoreg_tv->centre2.el[0] = xcentre;
223         ycoreg_tv->centre2.el[1] = zcentre;
224         ycoreg_tv->ex3 = coreg_ex(); 
225         ycoreg_tv->ey3 = coreg_ez(); 
226         ycoreg_tv->ez3 = vec3_minus(coreg_ey()); 
227         ycoreg_tv->scalex = xscale/min_scale;
228         ycoreg_tv->scaley = zscale/min_scale;
229     }
230     if (xcoreg_tv!=NULL)
231     {
232         xcoreg_tv->centre3 = coreg_ec();
233         xcoreg_tv->centre2.el[0] = zcentre;
234         xcoreg_tv->centre2.el[1] = ycentre;
235         xcoreg_tv->ex3 = coreg_ez(); 
236         xcoreg_tv->ey3 = coreg_ey(); 
237         xcoreg_tv->ez3 = vec3_minus(coreg_ex()); 
238         xcoreg_tv->scalex = zscale/min_scale;
239         xcoreg_tv->scaley = yscale/min_scale;
240     }
241 }
242 
243 void xcoreg_tv_set(Tv *tv)
244 {
245     xcoreg_tv = tv;
246 }
247 
248 Tv *xcoreg_tv_get()
249 {
250    return(xcoreg_tv);
251 }
252 
253 void ycoreg_tv_set(Tv *tv)
254 {
255     ycoreg_tv = tv;
256 }
257 
258 Tv *ycoreg_tv_get()
259 {
260    return(ycoreg_tv);
261 }
262 
263 void zcoreg_tv_set(Tv *tv)
264 {
265     zcoreg_tv = tv;
266 }
267 
268 Tv *zcoreg_tv_get()
269 {
270    return(zcoreg_tv);
271 }
272 
273 static void cmap_set_anaglyph(Tv *tv)
274 {
275     extern void tv_screen_cmap_find_and_install ();
276 
277     if (tv && tv->tv_screen)
278       {
279           Bool (*cmap_create_fn) () = NULL;
280           extern void tv_cmap_create_fn_set ();
281 
282           tv->cmap_create_fn = tv_anag_cmap_create;
283           tv_screen_cmap_find_and_install (tv, tv->tv_screen);
284           tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
285       }
286 }
287 
288 static void cmap_set_standard(Tv *tv)
289 {
290     extern void tv_screen_cmap_find_and_install ();
291 
292     if (tv && tv->tv_screen )
293       {
294           Bool (*cmap_create_fn) () = NULL;
295           extern void tv_cmap_create_fn_set ();
296 
297           tv->cmap_create_fn = tv_standard_cmap_create;
298           tv_screen_cmap_find_and_install (tv, tv->tv_screen);
299           tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
300       }
301 }
302 
303 void ***coreg_limits(int *lz, int *uz, int *ly, int *uy, int *lx, int *ux)
304 {
305    *lz = imptrlz;
306    *uz = imptruz;
307    *ly = imptrly;
308    *uy = imptruy;
309    *lx = imptrlx;
310    *ux = imptrux;
311    return(imptrs);
312 }
313 
314 void coreg_coords(Vec3 *nex, Vec3 *ney, Vec3 *nez)
315 {
316     *nex = coreg_ex();
317     *ney = coreg_ey();
318     *nez = coreg_ez();
319 }
320 
321 void coreg_tcoords(Vec3 *nex, Vec3 *ney, Vec3 *nez)
322 {
323     nex->el[0] = (float)ex[0];
324     nex->el[1] = (float)ey[0];
325     nex->el[2] = (float)ez[0];
326     ney->el[0] = (float)ex[1];
327     ney->el[1] = (float)ey[1];
328     ney->el[2] = (float)ez[1];
329     nez->el[0] = (float)ex[2];
330     nez->el[1] = (float)ey[2];
331     nez->el[2] = (float)ez[2];
332 }
333 
334 
335 void coreg_centre(double *x, double *y, double *z, Vec3*c)
336 {
337    *x = xcentre;
338    *y = ycentre;
339    *z = zcentre;
340    *c = coreg_ec();
341 }
342 
343 void coreg_scales(double *x, double *y, double *z, double *nx, double *ny, double *nz)
344 {
345     *x = xscale;
346     *y = yscale;
347     *z = zscale;
348     *nx = nxscale;
349     *ny = nyscale;
350     *nz = nzscale;
351 }
352 
353 
354 void set_coreg_zoom(double zfac, int mask)
355 {
356     if (mask >0 && (mask&4)) zoom_on = true; 
357     if (mask >0 && !(mask&4)) zoom_on = false; 
358     
359     zoom_fac = zfac;
360     min_scale = zoom_fac *MIN(MIN(xscale,yscale),zscale);
361     if(zcoreg_tv!=NULL) zcoreg_tv->scalex = xscale/min_scale;
362     if(zcoreg_tv!=NULL) zcoreg_tv->scaley = yscale/min_scale;
363     if(ycoreg_tv!=NULL) ycoreg_tv->scalex = xscale/min_scale;
364     if(ycoreg_tv!=NULL) ycoreg_tv->scaley = zscale/min_scale;
365     if(xcoreg_tv!=NULL) xcoreg_tv->scalex = zscale/min_scale;
366     if(xcoreg_tv!=NULL) xcoreg_tv->scaley = yscale/min_scale;
367 }
368 
369 void coreg_coords_init()
370 {
371     coreg_comp(ex, vec3_ex());
372     coreg_comp(ey, vec3_ey());
373     coreg_comp(ez, vec3_ez());
374     xscale = ixscale;
375     yscale = iyscale;
376     zscale = izscale;
377     if (disp_im_type == 0)
378         coreg_comp(ec, vec3(xcentre,ycentre,zcentre));
379     else
380         coreg_comp(ec, vec3(xcentre*nxscale/xscale,ycentre*nyscale/yscale,zcentre*nzscale/zscale));
381 }
382 
383 Vec3 coreg_bproj(double x, double y, double z)
384 /* compute equivalent location of transformed data point in original
385    data set */
386 {
387     Vec3 posi, post;
388     Vec3 ex,ey,ez;
389     coreg_tcoords(&ex,&ey,&ez);
390 
391     posi.el[0] = (x - xcentre)*nxscale;
392     posi.el[1] = (y - ycentre)*nyscale;
393     posi.el[2] = (z - zcentre)*nzscale;
394     post.el[0] = ec[0] + vec3_dot(posi,ex)/xscale;
395     post.el[1] = ec[1] + vec3_dot(posi,ey)/yscale;
396     post.el[2] = ec[2] + vec3_dot(posi,ez)/zscale;
397     return(post);
398 }
399 
400 Vec3 coreg_proj(double x, double y, double z)
401 /* compute equivalent location of original data set in new coordinates */
402 {
403     Vec3 posi, post;
404 
405     post.el[0] = (x - ec[0])*xscale;
406     post.el[1] = (y - ec[1])*yscale;
407     post.el[2] = (z - ec[2])*zscale;
408 
409     posi.el[0] = vec3_dot(post,coreg_ex())/nxscale + xcentre;
410     posi.el[1] = vec3_dot(post,coreg_ey())/nyscale + ycentre;
411     posi.el[2] = vec3_dot(post,coreg_ez())/nzscale + zcentre;
412     
413     return(posi);
414 }
415 
416 static Imrect *imf_edges(Imrect *im)
417 {
418     static double sigma = 1.0, precision = 0.01;
419     static double low_edge_thres = 20.0, up_edge_thres = 35.0;
420     static int len_thres = 5;
421     Imrect *edgeim;
422 
423     edgeim = canny(im, sigma, precision, low_edge_thres, up_edge_thres,
424                    len_thres); 
425 
426     return(edgeim);
427 }
428 
429 
430 static void tv_crosshair(Tv * tv, Ipos pos)
431 {
432     int x, y;
433     int w = tv->width;
434     int h = tv->height;
435 
436     x = ipos_x(pos);
437     y = ipos_y(pos);
438     tv_linexy(tv, 0, y, w, y);
439     tv_linexy(tv, x, 0, x, h);
440 }
441 
442 
443 static Imrect *imf_interlace(Imrect *ima, Imrect *imb, Imregion *roi)
444 {
445     Imrect *im2,*im3,*im4,*im5,*im6,*im7;
446     im2 = imf_checquer(roi->ux-roi->lx,roi->uy-roi->ly,
447                        16 , 16);
448     imf_times_inplace(1.0/256.0,im2);
449     im3 = imf_times(-1.0,im2);
450     im4 = imf_add(1.0,im3);
451     im_free(im3);
452     im5 = imf_prod(im2, ima);
453     im_free(im2);
454     im6 = imf_prod(im4,imb);
455     im_free(im4);
456     im7 = imf_sum(im5,im6);
457     im_free(im5);
458     im_free(im6);
459     return(im7);
460 }
461 
462 
463 static Imrect *apply_threshold(Imrect *im1, int image_code)
464 {
465 /* Function to apply the threshold from the air parameters dialog box to the second image in the 
466 anaglyph display mode */
467 
468         Imrect *im2=NULL;
469         Imregion *roi;
470         int lx, ux, ly, uy, i, j;
471         int tot_pix=0, pix_left=0;
472         float *row1, *row2, percentage, min, max;
473 
474         threshold = transfer_threshold_to_coreg_view();
475         roi = im1->region;
476         lx = roi->lx;
477         ly = roi->ly;
478         ux = roi->ux;
479         uy = roi->uy;
480         row1 = fvector_alloc(lx, ux);
481         row2 = fvector_alloc(lx, ux);
482 
483         imf_minmax_nzero(im1, &min, &max);
484         im2 = im_alloc(im1->height, im1->width, roi, float_v);
485 
486         for(i=ly; i<uy; i++)
487         {
488                 im_get_rowf(row1, im1, i, lx, ux);
489                 for(j=lx; j<ux; j++)
490                 {
491                         tot_pix++;
492                         if(row1[j]>threshold)
493                         {
494                                 row2[j]=row1[j];
495                                 pix_left++;
496                         }       
497                         else
498                         {
499                                 row2[j] = min;
500                         }
501                 }
502                 im_put_rowf(row2, im2, i, lx, ux);
503         }
504         percentage = 100* pix_left/tot_pix;
505         if(image_code==0)
506         {
507                 format("Threshold retains %f%% of z image pixels.\n", percentage);
508         }
509         else if(image_code==1)
510         {
511                 format("Threshold retains %f%% of y image pixels.\n", percentage);
512         }
513         else
514         {
515                 format("Threshold retains %f%% of x image pixels.\n", percentage);
516         }
517         fvector_free((void *) row1, lx);
518         fvector_free((void *) row2, lx);
519         return im2;
520 }
521 
522 
523 static void zpartdraw(Tv * tv)
524 {
525     Imrect *im=NULL,*im1,*im2;
526     double storex,storey;
527     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
528     Imregion *roi;
529     float percentage;
530 
531     tv_erase(tv);
532     if (imptrs == NULL) return;
533     storex = tv->scalex;
534     storey = tv->scaley;
535     tv->scalex = nxscale/min_nscale;
536     tv->scaley = nyscale/min_nscale;
537     if (zcoreg_im==NULL)
538     {
539        im = coreg_slicez(zcentre,NULL);
540        cmap_set_standard(tv);
541        im1 = imf_scale_nzero(im, 0.0, 255.0);
542        tv_imrect2(tv, im1);
543        im_free(im1);
544     }
545     else if(zcoreg_disp!=NULL && zcoreg_disp->vtype!= ptr_v)
546     {
547        roi = zcoreg_disp->region;
548        im = coreg_slicez(zcentre,roi);
549        im1 = imf_scale_nzero(im, 0.0, 255.0); 
550        if (disp_im_type == 1)
551        {
552           cmap_set_anaglyph(tv);  
553           tv_imrect_anaglyph(tv, im1, zcoreg_disp, 0.0, 255.0);
554        }
555        else
556        {
557           im2 = imf_interlace(im1,zcoreg_disp, roi);
558           cmap_set_standard(tv);
559           tv_imrect2(tv, im2);
560           im_free(im2);
561        }
562        im_free(im1); 
563     }
564     else
565     {
566        im = coreg_slicez(zcentre,NULL);
567        cmap_set_standard(tv);
568        im1 = imf_scale_nzero(im, 0.0, 255.0);
569        tv_imrect2(tv, im1);
570        im_free(im1);
571        tv_edges_conn(zcoreg_tv, zcoreg_disp);       
572     }
573     tv->scalex = storex;
574     tv->scaley = storey;
575     if (im!=NULL) im_free(im);
576     tv_color_set(tv, blue);
577     tv_crosshair(tv,ipos(tv->width/2,tv->height/2));
578     tv_reset_draw(tv);
579 }
580 
581 
582 static void ypartdraw(Tv * tv)
583 {
584     Imrect *im=NULL,*im1,*im2;
585     double storex,storey;
586     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
587     Imregion *roi;
588     float percentage;
589 
590     tv_erase(tv);
591     if (imptrs==NULL) return;
592     storex = tv->scalex;
593     storey = tv->scaley;
594     tv->scalex = nxscale/min_nscale;
595     tv->scaley = nzscale/min_nscale;
596     if (ycoreg_im==NULL)
597     {
598        im = coreg_slicey(ycentre,NULL);
599        cmap_set_standard(tv);
600        im1 = imf_scale_nzero(im, 0.0, 255.0);
601        tv_imrect2(tv, im1);
602        im_free(im1);
603     }
604     else if(ycoreg_disp!=NULL && ycoreg_disp->vtype != ptr_v)
605     {
606        roi = ycoreg_disp->region;
607        im = coreg_slicey(ycentre,roi);
608        im1 = imf_scale_nzero(im, 0.0, 255.0);
609        if (disp_im_type == 1)
610        {
611           cmap_set_anaglyph(tv);
612           tv_imrect_anaglyph(tv, im1, ycoreg_disp, 0.0, 255.0);
613        }
614        else
615        {
616           im2 = imf_interlace(im1,ycoreg_disp, roi);
617           cmap_set_standard(tv);
618           tv_imrect2(tv, im2);
619           im_free(im2);
620        }
621        im_free(im1);
622     }
623     else
624     {
625        im = coreg_slicey(ycentre,NULL);
626        cmap_set_standard(tv);
627        im1 = imf_scale_nzero(im, 0.0, 255.0);
628        tv_imrect2(tv, im1);
629        im_free(im1);
630        tv_edges_conn(ycoreg_tv, ycoreg_disp);       
631     }
632     tv->scalex = storex;
633     tv->scaley = storey;
634     if (im!=NULL) im_free(im);
635     tv_color_set(tv, blue);
636     tv_crosshair(tv,ipos(tv->width/2,tv->height/2));
637     tv_reset_draw(tv);
638 }
639 
640 static void xpartdraw(Tv * tv)
641 {
642     Imrect *im=NULL,*im1,*im2;
643     double storex,storey;
644     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
645     Imregion *roi;
646     float percentage;
647 
648     tv_erase(tv);
649     if (imptrs == NULL) return;
650     storex = tv->scalex;
651     storey = tv->scaley;
652     tv->scalex = nzscale/min_nscale;
653     tv->scaley = nyscale/min_nscale;
654     if (xcoreg_im==NULL)
655     {
656        im = coreg_slicex(xcentre,NULL);
657        im1 = imf_scale_nzero(im, 0.0, 255.0);
658        cmap_set_standard(tv);
659        tv_imrect2(tv, im1);
660        im_free(im1);
661     }
662     else if(xcoreg_disp!=NULL && xcoreg_disp->vtype != ptr_v )
663     {
664        roi = xcoreg_disp->region;
665        im = coreg_slicex(xcentre,roi);
666        im1 = imf_scale_nzero(im, 0.0, 255.0);
667        if (disp_im_type == 1)
668        {
669           cmap_set_anaglyph(tv);
670           tv_imrect_anaglyph(tv, im1, xcoreg_disp, 0.0, 255.0);
671        }
672        else
673        {
674           im2 = imf_interlace(im1,xcoreg_disp, roi);
675           cmap_set_standard(tv);
676           tv_imrect2(tv, im2);
677           im_free(im2);
678        }
679        im_free(im1);
680        
681     }
682     else 
683     {
684        im = coreg_slicex(xcentre,NULL);
685        cmap_set_standard(tv);
686        im1 = imf_scale_nzero(im, 0.0, 255.0);
687        tv_imrect2(tv, im1);
688        im_free(im1);
689        tv_edges_conn(xcoreg_tv, xcoreg_disp);
690     }
691     tv->scalex = storex;
692     tv->scaley = storey;
693     if (im!=NULL) im_free(im);
694     tv_color_set(tv, blue);
695     tv_crosshair(tv,ipos(tv->width/2,tv->height/2));
696     tv_reset_draw(tv);
697 }
698 
699 static void xfulldraw(Tv *tv)
700 {
701     double shiftcx;
702     double shiftcy;
703 /*
704     double min_scale = zoom_fac*MIN(MIN(xscale,yscale),zscale);
705 */
706     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
707     static int first= 0;
708 
709     shiftcx = ((float)(tv->width / 2) - tv->cx)*min_nscale/nzscale;
710     shiftcy = ((float)(tv->height / 2) - tv->cy)*min_nscale/nyscale;
711 
712     tv_erase(tv);
713     coreg_comp(ex, vec3_minus(tv->ez3));
714     coreg_comp(ey, tv->ey3);
715     coreg_comp(ez, tv->ex3);
716     tv->centre3 = coreg_bproj(xcentre,
717                               shiftcy+ycentre,
718                               shiftcx+zcentre);
719 
720     if (xcoreg_im==NULL)
721     {
722        zcentre = tv->centre3.el[2];
723        ycentre = tv->centre3.el[1];
724        tv->centre2.el[0] = zcentre;
725        tv->centre2.el[1] = ycentre;
726     }
727     tv->cx = (float)(tv->width / 2);
728     tv->cy = (float)(tv->height / 2);
729     coreg_comp(ec, tv->centre3);
730     if (first++>1) /* stop X from arbitrarily rescaling first time */
731     {
732        zscale = tv->scalex*min_scale;
733        yscale = tv->scaley*min_scale;
734     }
735     reset_tv_coords();
736     xpartdraw(tv);
737     if (ycoreg_tv!=NULL) ypartdraw(ycoreg_tv);   
738     if (zcoreg_tv!=NULL) zpartdraw(zcoreg_tv);   
739     reset_air();
740     reset_centre(xcentre,ycentre,zcentre);
741 }
742 
743 static void yfulldraw(Tv *tv)
744 {
745     double shiftcx;
746     double shiftcy;
747 /*
748     double min_scale = zoom_fac*MIN(MIN(xscale,yscale),zscale);
749 */
750     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
751     static int first = 0 ;
752 
753     shiftcx = ((float)(tv->width / 2) - tv->cx)*min_nscale/nxscale;
754     shiftcy = ((float)(tv->height / 2) - tv->cy)*min_nscale/nzscale;
755 
756     tv_erase(tv);
757     coreg_comp(ex, tv->ex3);
758     coreg_comp(ey, vec3_minus(tv->ez3));
759     coreg_comp(ez, tv->ey3);
760     tv->centre3 = coreg_bproj(shiftcx+xcentre
761                             , ycentre
762                             , shiftcy+zcentre);
763     if (ycoreg_im==NULL)
764     {
765        xcentre = tv->centre3.el[0];
766        zcentre = tv->centre3.el[2];
767        tv->centre2.el[0] = xcentre;
768        tv->centre2.el[1] = zcentre;
769     }
770 
771     tv->cx = (float)(tv->width / 2);
772     tv->cy = (float)(tv->height / 2);
773     coreg_comp(ec , tv->centre3);
774     if (first++>1) /* stop X from arbitrarily rescaling first time */
775     {
776        xscale = tv->scalex*min_scale;
777        zscale = tv->scaley*min_scale;
778     }
779     reset_tv_coords();
780     ypartdraw(tv);
781     if (zcoreg_tv!=NULL) zpartdraw(zcoreg_tv);
782     if (xcoreg_tv!=NULL) xpartdraw(xcoreg_tv);
783     reset_air();
784     reset_centre(xcentre,ycentre,zcentre);
785 }
786 
787 static void zfulldraw(Tv *tv)
788 {
789     double shiftcx;
790     double shiftcy;
791 /*
792     double min_scale = zoom_fac*MIN(MIN(xscale,yscale),zscale);
793 */
794     double min_nscale = zoom_fac*MIN(MIN(nxscale,nyscale),nzscale);
795     static int first = 0;
796 
797     shiftcx = ((float)(tv->width / 2) - tv->cx)*min_nscale/nxscale;
798     shiftcy = ((float)(tv->height / 2) - tv->cy)*min_nscale/nyscale;
799 
800     tv_erase(tv);
801     coreg_comp(ex, tv->ex3);
802     coreg_comp(ey, tv->ey3);
803     coreg_comp(ez, tv->ez3);
804     tv->centre3 = coreg_bproj(shiftcx+xcentre,
805                               shiftcy+ycentre,
806                               zcentre);
807 
808     if (zcoreg_im==NULL)
809     {
810        xcentre = tv->centre3.el[0];
811        ycentre = tv->centre3.el[1];
812        tv->centre2.el[0] = xcentre;
813        tv->centre2.el[1] = ycentre;
814     }
815     tv->cx = (float)(tv->width / 2);
816     tv->cy = (float)(tv->height / 2);
817     coreg_comp(ec , tv->centre3);
818     if (first++>1)/* stop X from arbitrarily rescaling first time */
819     {
820        xscale = tv->scalex*min_scale;
821        yscale = tv->scaley*min_scale;
822     }
823     reset_tv_coords();
824     zpartdraw(tv);
825     if (ycoreg_tv!=NULL) ypartdraw(ycoreg_tv);
826     if (xcoreg_tv!=NULL) xpartdraw(xcoreg_tv);
827     reset_air();
828     reset_centre(xcentre,ycentre,zcentre);
829 }
830 
831 
832 static Ipos proj3_orthx(Tv * tv, Vec3 v)
833 {
834     Ipos    pos = {Ipos_id};
835     double  x, y;
836     Vec3    vx;
837 
838     v = vec3_diff(v, tv->centre3);
839     vx.el[0] = v.el[0]*ixscale;
840     vx.el[1] = v.el[1]*iyscale;
841     vx.el[2] = v.el[2]*izscale;
842     x = tv->cx + tv->scalex*vec3_dot(vx, tv->ex3)/izscale;
843     y = tv->cy + tv->scaley*vec3_dot(vx, tv->ey3)/iyscale;
844     pos.x = ROUND(x);
845     pos.y = ROUND(y);
846     return (pos);
847 }
848 
849 static Ipos proj3_orthy(Tv * tv, Vec3 v)
850 {
851     Ipos    pos = {Ipos_id};
852     double  x, y;
853     Vec3    vx;
854 
855     v = vec3_diff(v, tv->centre3);
856     vx.el[0] = v.el[0]*ixscale;
857     vx.el[1] = v.el[1]*iyscale;
858     vx.el[2] = v.el[2]*izscale;
859     x = tv->cx + tv->scalex*vec3_dot(vx, tv->ex3)/ixscale;
860     y = tv->cy + tv->scaley*vec3_dot(vx, tv->ey3)/izscale;
861     pos.x = ROUND(x);
862     pos.y = ROUND(y);
863     return (pos);
864 }
865 
866 static Ipos proj3_orthz(Tv * tv, Vec3 v)
867 {
868     Ipos    pos = {Ipos_id};
869     double  x, y;
870     Vec3    vx;
871 
872     v = vec3_diff(v, tv->centre3);
873     vx.el[0] = v.el[0] * ixscale;
874     vx.el[1] = v.el[1] * iyscale;
875     vx.el[2] = v.el[2] * izscale;
876     x = tv->cx + tv->scalex*vec3_dot(vx, tv->ex3)/ixscale;
877     y = tv->cy + tv->scaley*vec3_dot(vx, tv->ey3)/iyscale;
878     pos.x = ROUND(x);
879     pos.y = ROUND(y);
880     return (pos);
881 }
882 
883 static void linexy(Tv * tv, int x1, int y1, int x2, int y2)
884 {
885     tv_line3(tv, vec3((float) x1 , (float) y1 , tv->centre3.el[2]),
886                  vec3((float) x2 , (float) y2 , tv->centre3.el[2]));
887 }
888 
889 static void linexz(Tv * tv, int x1, int y1, int x2, int y2)
890 {
891     tv_line3(tv, vec3((float) x1 , tv->centre3.el[1], (float) y1),
892                  vec3((float) x2 , tv->centre3.el[1], (float) y2));
893 }
894 
895 static void linezy(Tv * tv, int x1, int y1, int x2, int y2)
896 {
897     tv_line3(tv, vec3(tv->centre3.el[0], (float) y1, (float)x1),
898                  vec3(tv->centre3.el[0], (float) y2, (float)x2));
899 }
900 
901 static void    zskeldraw(Tv * tv)
902 {
903     int     lx, ly, ux, uy;
904     int     dx, dy;
905     int     x, y;
906 
907     if (tv == NULL || tv->tv_screen == NULL)
908         return;
909 
910     if (!zoom_on) set_coreg_zoom(zoom_fac,-1);
911     lx = imptrlx ;
912     ux = imptrux ;
913     ly = imptrly ;
914     uy = imptruy ;
915 
916     dx = (ux - lx) / 16;
917     dy = (uy - ly) / 16;
918     if (dx<1) dx = 1; /* BUG fix NAT */
919     if (dy<1) dy = 1; /* 26/5/95     */
920 
921     for (x = lx; x < ux; x += dx)
922         linexy(tv, x, ly, x, uy);
923     linexy(tv, ux, ly, ux, uy);
924     for (y = ly; y < uy; y += dy)
925         linexy(tv, lx, y, ux, y);
926     linexy(tv, lx, y, ux, y);
927 }
928 
929 static void    yskeldraw(Tv * tv)
930 {
931     int     lx, ly, ux, uy;
932     int     dx, dy;
933     int     x, y;
934 
935     if (tv == NULL || tv->tv_screen == NULL)
936         return;
937 
938     if (!zoom_on) set_coreg_zoom(zoom_fac,-1);
939     lx = imptrlx ;
940     ux = imptrux ;
941     ly = imptrlz ;
942     uy = imptruz ;
943 
944     dx = (ux - lx) / 16;
945     dy = (uy - ly) / 16;
946     if (dx<1) dx = 1; /* BUG fix NAT */
947     if (dy<1) dy = 1; /* 26/5/95     */
948 
949     for (x = lx; x < ux; x += dx)
950         linexz(tv, x, ly, x, uy);
951     linexz(tv, ux, ly, ux, uy);
952     for (y = ly; y < uy; y += dy)
953         linexz(tv, lx, y, ux, y);
954     linexz(tv, lx, y, ux, y);
955 }
956 
957 static void    xskeldraw(Tv * tv)
958 {
959     int     lx, ly, ux, uy;
960     int     dx, dy;
961     int     x, y;
962 
963     if (tv == NULL || tv->tv_screen == NULL)
964         return;
965 
966     if (!zoom_on) set_coreg_zoom(zoom_fac,-1);
967     lx = imptrlz ;
968     ux = imptruz ;
969     ly = imptrly ;
970     uy = imptruy ;
971 
972     dx = (ux - lx) / 16;
973     dy = (uy - ly) / 16;
974     if (dx<1) dx = 1; /* BUG fix NAT */
975     if (dy<1) dy = 1; /* 26/5/95     */
976 
977     for (x = lx; x < ux; x += dx)
978         linezy(tv, x, ly, x, uy);
979     linezy(tv, ux, ly, ux, uy);
980     for (y = ly; y < uy; y += dy)
981         linezy(tv, lx, y, ux, y);
982     linezy(tv, lx, y, ux, y);
983 }
984 
985 static void zinit(Tv * tv)
986 {
987     List *frame, *get_start_el();
988     frame = get_start_el();
989     if (frame!=NULL) imref = frame->to;
990 
991     tv_camera3(tv, vec3(xcentre, ycentre, zcentre), 1.0, 3.0, vec3_ez(), vec3_ey());
992     if (imref != NULL)
993     {
994        tv_camera2(tv, vec2(xcentre, ycentre), MAX(imref->width,imref->height)/2.0, vec2_ey());
995     }
996     else
997     {
998        tv_camera2(tv, vec2(xcentre, ycentre), 256, vec2_ey());
999     }
1000     xscale = ixscale;
1001     yscale = iyscale;
1002     zscale = izscale;
1003     min_scale = zoom_fac *MIN(MIN(xscale,yscale),zscale);
1004     tv->proj3 = proj3_orthz;
1005     tv->scalex = xscale/min_scale;
1006     tv->scaley = yscale/min_scale;
1007 }
1008 
1009 static void yinit(Tv * tv)
1010 {
1011     List *frame, *get_start_el();
1012     frame = get_start_el();
1013     if (frame!=NULL) imref = frame->to;
1014 
1015     tv_camera3(tv, vec3(xcentre,ycentre,zcentre), 1.0, 3.0, vec3_minus(vec3_ey()), vec3_ez());
1016     if (imref != NULL)
1017     {
1018        tv_camera2(tv, vec2(xcentre, zcentre), MAX(imref->height,imref->width)/2.0, vec2_ey());
1019     }
1020     else
1021     {
1022        tv_camera2(tv, vec2(xcentre, zcentre), 256, vec2_ey());
1023     }
1024     xscale = ixscale;
1025     yscale = iyscale;
1026     zscale = izscale;
1027     min_scale = zoom_fac*MIN(MIN(xscale,yscale),zscale);
1028     tv->proj3 = proj3_orthy;
1029     tv->scalex = xscale/min_scale;
1030     tv->scaley = zscale/min_scale;
1031 }
1032 
1033 static void xinit(Tv * tv)
1034 {
1035     List *frame, *get_start_el();
1036     frame = get_start_el();
1037     if (frame!=NULL) imref = frame->to;
1038 
1039     tv_camera3(tv, vec3(xcentre,ycentre,zcentre), 1.0, 3.0, vec3_minus(vec3_ex()), vec3_ey());
1040     if (imref != NULL)
1041     {
1042        tv_camera2(tv, vec2(zcentre, ycentre), MAX(imref->height,imref->width)/2.0, vec2_ey());
1043     }
1044     else
1045     {
1046        tv_camera2(tv, vec2(zcentre, ycentre), 256, vec2_ey());
1047     }
1048     xscale = ixscale;
1049     yscale = iyscale;
1050     zscale = izscale;
1051     min_scale = zoom_fac*MIN(MIN(xscale,yscale),zscale);
1052     tv->proj3 = proj3_orthx;
1053     tv->scalex = zscale/min_scale;
1054     tv->scaley = yscale/min_scale;
1055 }
1056 
1057 
1058 void coreg_init(Tv *tv)
1059 {
1060     if(zcoreg_tv!=NULL) zinit(zcoreg_tv);
1061     if(ycoreg_tv!=NULL) yinit(ycoreg_tv);
1062     if(xcoreg_tv!=NULL) xinit(xcoreg_tv);
1063 }
1064 
1065 void coreg_redraw()
1066 {
1067     if(zcoreg_tv!=NULL) zfulldraw(zcoreg_tv);
1068     else if(ycoreg_tv!=NULL) yfulldraw(ycoreg_tv);
1069     else if(xcoreg_tv!=NULL) xfulldraw(xcoreg_tv);
1070 }
1071 
1072 Tv     *xcoreg_tv_make(void)
1073 {
1074     static Tv *tv;
1075 
1076     tv = tv_create("Xcoreg");
1077     xcoreg_tv = tv;
1078     xinit(tv);
1079     (void) tv_set_backdraw(tv, xfulldraw);
1080     (void) tv_set_skeldraw(tv, xskeldraw);
1081     tv_set_init(tv, coreg_init);
1082     (void) tv_set_zoomlevel(tv, IMZOOM);
1083     return (tv);
1084 }
1085 
1086 Tv     *ycoreg_tv_make(void)
1087 {
1088     static Tv *tv;
1089 
1090     tv = tv_create("Ycoreg");
1091     ycoreg_tv = tv;
1092     yinit(tv);
1093     (void) tv_set_backdraw(tv, yfulldraw);
1094     (void) tv_set_skeldraw(tv, yskeldraw);
1095     tv_set_init(tv, coreg_init);
1096     (void) tv_set_zoomlevel(tv, IMZOOM);
1097     
1098     return (tv);
1099 }
1100 
1101 Tv     *zcoreg_tv_make(void)
1102 {
1103     static Tv *tv;
1104 
1105     tv = tv_create("Zcoreg");
1106     zcoreg_tv = tv;
1107     zinit(tv);
1108     (void) tv_set_backdraw(tv, zfulldraw);
1109     (void) tv_set_skeldraw(tv, zskeldraw);
1110     tv_set_init(tv, coreg_init);
1111     (void) tv_set_zoomlevel(tv, IMZOOM);
1112     return (tv);
1113 }
1114 
1115 void set_coreg_centre(double slicex, double slicey, double slicez)
1116 {
1117     xcentre = slicex;
1118     ycentre = slicey;
1119     zcentre = slicez;
1120     ec[0] = xcentre;
1121     ec[1] = ycentre;
1122     ec[2] = zcentre;
1123 }
1124 
1125 void set_coreg_trans(struct air16  air1)
1126 {
1127     Vec3 posi,post;
1128     Vec3 nex,ney,nez;
1129     double min_nscale;
1130 
1131     nxscale = air1.s.x_size;
1132     nyscale = air1.s.y_size;
1133     nzscale = air1.s.z_size;
1134     xscale = air1.r.x_size;
1135     yscale = air1.r.y_size;
1136     zscale = air1.r.z_size;
1137     ixscale = xscale;
1138     iyscale = yscale;
1139     izscale = zscale;
1140     min_nscale = MIN(MIN(nxscale,nyscale),nzscale);
1141     min_scale = MIN(MIN(xscale,yscale),zscale);
1142  
1143     ex[0] = air1.e[0][0]*air1.s.x_size/min_nscale;  
1144     ex[1] = air1.e[0][1]*air1.s.y_size/min_nscale;  
1145     ex[2] = air1.e[0][2]*air1.s.z_size/min_nscale;  
1146     ey[0] = air1.e[1][0]*air1.s.x_size/min_nscale;  
1147     ey[1] = air1.e[1][1]*air1.s.y_size/min_nscale;  
1148     ey[2] = air1.e[1][2]*air1.s.z_size/min_nscale;  
1149     ez[0] = air1.e[2][0]*air1.s.x_size/min_nscale;  
1150     ez[1] = air1.e[2][1]*air1.s.y_size/min_nscale;  
1151     ez[2] = air1.e[2][2]*air1.s.z_size/min_nscale;  
1152     post.el[0] = air1.e[3][0]*air1.s.x_size/min_nscale;
1153     post.el[1] = air1.e[3][1]*air1.s.y_size/min_nscale;
1154     post.el[2] = air1.e[3][2]*air1.s.z_size/min_nscale;
1155  
1156 /* now transform centre location */
1157     coreg_tcoords(&nex,&ney,&nez);
1158  
1159     posi.el[0] = xcentre*nxscale;
1160     posi.el[1] = ycentre*nyscale;
1161     posi.el[2] = zcentre*nzscale;
1162     ec[0]  = (post.el[0] + vec3_dot(posi,nex))/xscale;  
1163     ec[1]  = (post.el[1] + vec3_dot(posi,ney))/yscale;  
1164     ec[2]  = (post.el[2] + vec3_dot(posi,nez))/zscale;  
1165     reset_tv_coords();
1166     coreg_redraw();
1167 }
1168     
1169 
1170 void get_coreg_trans(struct air16 *air1)
1171 {
1172     Vec3 posi,post;
1173     Vec3 nex,ney,nez;
1174     double min_scale = MIN(MIN(nxscale,nyscale),nzscale);
1175  
1176     air1->e[0][0] = ex[0]*min_scale/nxscale;
1177     air1->e[0][1] = ex[1]*min_scale/nyscale;
1178     air1->e[0][2] = ex[2]*min_scale/nzscale;
1179     air1->e[1][0] = ey[0]*min_scale/nxscale;
1180     air1->e[1][1] = ey[1]*min_scale/nyscale;
1181     air1->e[1][2] = ey[2]*min_scale/nzscale;
1182     air1->e[2][0] = ez[0]*min_scale/nxscale;
1183     air1->e[2][1] = ez[1]*min_scale/nyscale;
1184     air1->e[2][2] = ez[2]*min_scale/nzscale;
1185     air1->s.x_size = nxscale;
1186     air1->s.y_size = nyscale;
1187     air1->s.z_size = nzscale;
1188     air1->r.x_size = xscale;
1189     air1->r.y_size = yscale;
1190     air1->r.z_size = zscale;
1191  
1192 /* now transform centre location */
1193     coreg_tcoords(&nex,&ney,&nez);
1194  
1195     posi.el[0] = -xcentre*nxscale;
1196     posi.el[1] = -ycentre*nyscale;
1197     posi.el[2] = -zcentre*nzscale;
1198     post.el[0] = ec[0]*xscale + vec3_dot(posi,nex);
1199     post.el[1] = ec[1]*yscale + vec3_dot(posi,ney);
1200     post.el[2] = ec[2]*zscale + vec3_dot(posi,nez);
1201     air1->e[3][0] = post.el[0]*min_scale/nxscale;
1202     air1->e[3][1] = post.el[1]*min_scale/nyscale;
1203     air1->e[3][2] = post.el[2]*min_scale/nzscale;
1204 }
1205  
1206 
1207 float display_scaler(Imrect *pre_thresh_im, Imrect *post_thresh_im)
1208 {
1209         /* Determines the scaling parameters for imf_scale_nzero such that 
1210         the same scaling that would have been applied to the pre threshold
1211         image is applied to the post threshold image for dispaly in the tv */
1212 
1213         float old_min, old_max, new_min, new_max, old_scale, new_scale_low;
1214 
1215         imf_minmax_nzero(pre_thresh_im, &old_min, &old_max);
1216         imf_minmax_nzero(post_thresh_im, &new_min, &new_max);
1217         
1218         old_scale = (256.0)/(old_max-old_min);
1219         new_scale_low = (new_min-old_min)*old_scale;
1220         return(new_scale_low);
1221 }
1222 
1223 
1224 void latch_slices(int im_type)
1225 {
1226     Imrect *edgeim, *im1, *im2, *im3;
1227     extern Imregion *tv_get_im_roi(); 
1228     Imregion *roi;
1229     float scale_low;
1230     
1231     disp_im_type = im_type;
1232     if (imptrs!=NULL)
1233     {
1234       if(zcoreg_im==NULL)
1235       {
1236          nxscale = xscale;
1237          nyscale = yscale;
1238          nzscale = zscale;
1239          roi = tv_get_im_roi(zcoreg_tv_get()); 
1240          zcoreg_im = coreg_slicez(zcentre,roi);
1241          roi = tv_get_im_roi(ycoreg_tv_get());
1242          ycoreg_im = coreg_slicey(ycentre,roi);
1243          roi = tv_get_im_roi(xcoreg_tv_get());
1244          xcoreg_im = coreg_slicex(xcentre,roi);
1245       }
1246       if (zcoreg_disp!=NULL) im_free(zcoreg_disp);
1247       if (ycoreg_disp!=NULL) im_free(ycoreg_disp);
1248       if (xcoreg_disp!=NULL) im_free(xcoreg_disp);
1249       zcoreg_disp=NULL;
1250       ycoreg_disp=NULL;
1251       xcoreg_disp=NULL;
1252       if (im_type==2)
1253       {
1254          zcoreg_disp = imf_edges(zcoreg_im);
1255          ycoreg_disp = imf_edges(ycoreg_im);
1256          xcoreg_disp = imf_edges(xcoreg_im);
1257       }
1258       else if(im_type==1||im_type==3)
1259       {
1260          im1 = apply_threshold(zcoreg_im, 0);
1261          /* scale_low = display_scaler(zcoreg_im, im1);  */
1262          zcoreg_disp = imf_scale_nzero(im1, 0.0, 255.0);
1263          im_free(im1);
1264 
1265          im2 = apply_threshold(ycoreg_im, 1);
1266          /* scale_low = display_scaler(ycoreg_im, im2);  */
1267          ycoreg_disp = imf_scale_nzero(im2, 0.0, 255.0);
1268          im_free(im2);
1269 
1270          im3 = apply_threshold(xcoreg_im, 2);       
1271          /* scale_low = display_scaler(xcoreg_im, im3);  */
1272          xcoreg_disp = imf_scale_nzero(im3, 0.0, 255.0);
1273          im_free(im3);
1274       }
1275     }
1276     coreg_init(NULL);
1277     coreg_redraw();
1278 }
1279 
1280 void ***coreg_slice_init(Vec3 *newiscale)
1281 {
1282     List *frame,*find_frame(Sequence *data);
1283     List *get_start_el();
1284     Sequence *get_seq_ptr();
1285     Sequence *seq = get_seq_ptr();
1286     void set_voxel_vtype(Vartype vtype);
1287     Imrect *im;
1288     Imregion roi;
1289     int i,j;
1290 
1291     if (imptrs!=NULL) parray_free(imptrs,imptrlz,imptrly,imptruz,imptruy);
1292     imptrs = NULL;
1293     frame = get_start_el();
1294     if((frame==NULL)||(imref = frame->to)==NULL) return;
1295     set_voxel_vtype(imref->vtype);
1296     roi = *(imref->region);
1297     if (newiscale !=NULL)
1298     {
1299        xscale = newiscale->el[0];
1300        yscale = newiscale->el[1];
1301        zscale = newiscale->el[2];
1302        ixscale = newiscale->el[0];
1303        iyscale = newiscale->el[1];
1304        izscale = newiscale->el[2];
1305     }
1306     imptrlx = roi.lx;
1307     imptrux = roi.ux;
1308     imptrly = roi.ly;
1309     imptruy = roi.uy;
1310     imptrlz = seq->seq_start;
1311     imptruz = seq->seq_end+1;
1312     imptrs = (void ***)parray_alloc(imptrlz,imptrly,imptruz,imptruy);
1313     im = imref;
1314     for (i=imptrlz;i<imptruz;i++)
1315     {
1316        for (j=imptrly;j<imptruy;j++)
1317        {
1318            imptrs[i][j] = (void *)IM_ROW(im,j);
1319        }
1320        if( frame !=NULL)
1321        {
1322           frame = frame->next;
1323           if (frame!=NULL) im = frame->to;
1324        }
1325     } 
1326     if (zcoreg_tv!=NULL) tv_set_roi(zcoreg_tv,&roi);
1327     roi.ly = imptrlz;
1328     roi.uy = imptruz;
1329     if (ycoreg_tv!=NULL) tv_set_roi(ycoreg_tv,&roi);
1330     roi.ly = imptrly;
1331     roi.uy = imptruy;
1332     roi.lx = imptrlz;
1333     roi.ux = imptruz;
1334     if (xcoreg_tv!=NULL) tv_set_roi(xcoreg_tv,&roi);
1335     coreg_init(NULL);
1336 
1337     return(imptrs);
1338 }
1339 
1340 void latch_clear()
1341 {
1342     if (zcoreg_im!=NULL) im_free(zcoreg_im);
1343     zcoreg_im = NULL;
1344     if (ycoreg_im!=NULL) im_free(ycoreg_im);
1345     ycoreg_im = NULL;
1346     if (xcoreg_im!=NULL) im_free(xcoreg_im);
1347     xcoreg_im = NULL;
1348     if (zcoreg_disp!=NULL) im_free(zcoreg_disp);
1349     zcoreg_disp = NULL;
1350     if (ycoreg_disp!=NULL) im_free(ycoreg_disp);
1351     ycoreg_disp = NULL;
1352     if (xcoreg_disp!=NULL) im_free(xcoreg_disp);
1353     xcoreg_disp = NULL;
1354     coreg_coords_init();
1355     nxscale = xscale;
1356     nyscale = yscale;
1357     nzscale = zscale;
1358     set_coreg_zoom(zoom_fac, -1);
1359     coreg_slice_init(NULL);
1360     coreg_init(NULL);
1361     coreg_redraw();
1362 }
1363 

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