src/shscal.c

00001 
00006 /*
00007  *  PROGRAM NAME:  sh
00008  *
00009  *  (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES
00010  *  CORPORATION 12/1/2001.  ALL RIGHTS RESERVED.
00011  *
00012  *  Please refer to the LICENSE file in the top directory
00013  *
00014  *      author: Mike Henderson mhender@watson.ibm.com
00015  */
00016 
00017 static char *id="@(#) $Id: shscal.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018 
00019 #include <shInternal.h>
00020 
00031 void shscal(float *xmin,float *xmax,float *ymin,float *ymax,float *zmin,float *zmax)
00032  {
00033   int i,j;
00034 
00035   float one=1.;
00036   float zero=0.;
00037   float smax,smin;
00038   float tmax,tmin;
00039   float dmax,dmin;
00040   float s=0.;
00041   float t=0.;
00042   float d=0.;
00043   float x,y,z;
00044   float as,at,pcale;
00045   float soff;
00046   float toff;
00047   float dcale;
00048   float doff;
00049 
00050   float I[8*6]={0.,0.,0.,0.,1.,1.,1.,1.,
00051                 1.,1.,1.,1.,0.,0.,0.,0.,
00052                 0.,0.,1.,1.,0.,0.,1.,1.,
00053                 1.,1.,0.,0.,1.,1.,0.,0.,
00054                 0.,1.,0.,1.,0.,1.,0.,1.,
00055                 1.,0.,1.,0.,1.,0.,1.,0.};
00056 
00057 /* Perform Scaling for the perspective transform. */
00058 
00059   shsize(&one,&zero,&zero,&one,&zero);
00060 
00061   smax=-1.e5;
00062   smin=1.e5;
00063   tmax=-1.e5;
00064   tmin=1.e5;
00065   dmax=-1.e5;
00066   dmin=1.e5;
00067 
00068   for(j=0;j<8;j++)
00069    {
00070     x=I[j+8*0]*(*xmax)+I[j+8*1]*(*xmin);
00071     y=I[j+8*2]*(*ymax)+I[j+8*3]*(*ymin);
00072     z=I[j+8*4]*(*zmax)+I[j+8*5]*(*zmin);
00073     shpers(&x,&y,&z,&s,&t,&d);
00074     if(s>smax)smax=s;
00075     if(s<smin)smin=s;
00076     if(t>tmax)tmax=t;
00077     if(t<tmin)tmin=t;
00078     if(d>dmax)dmax=d;
00079     if(d<dmin)dmin=d;
00080    }
00081 
00082   as=1.*shIMax/shMax;
00083   at=1.*shJMax/shMax;
00084   pcale=.9*as/(smax-smin);
00085   if(pcale*(tmax-tmin)>.9*at)pcale=.9*at/(tmax-tmin);
00086   soff=.5*(as-pcale*(smax+smin));
00087   toff=.5*(at-pcale*(tmax+tmin));
00088   dcale=.9/(dmax-dmin);
00089   doff=.5*(1.-dcale*(dmax+dmin));
00090   shsize(&pcale,&soff,&toff,&dcale,&doff);
00091   return;
00092  }

Generated on Thu Aug 17 15:29:43 2006 for sh by  doxygen 1.4.6