Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

gunu_raise_degree2.cpp

Go to the documentation of this file.
00001 /* LIBGUL - Geometry Utility Library
00002  * Copyright (C) 1998-1999 Norbert Irmer
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */ 
00019 
00020 
00021  
00022 #include "stdafx.h"
00023 
00024 #include <iostream>
00025 
00026 #include "gul_types.h"
00027 #include "gul_vector.h"
00028 #include "gunu_raise_degree.h"
00029 
00030 namespace gunu {
00031 
00032 using gul::rtr;
00033 using gul::Max;
00034 using gul::Min;
00035 using gul::Ptr;
00036 using gul::point;
00037 using gul::hpoint;
00038 using gul::point2;
00039 using gul::hpoint2;
00040 using gul::point1;
00041 using gul::hpoint1;
00042 using gul::set;
00043 
00044 /*-------------------------------------------------------------------------*//**
00045   raise the degree 'pu' or 'pv' of a surface by 't'. this function doesn't
00046   reserves memory for Uh,Vh and Qw, they must be dimensioned in u or v 
00047   direction like for curves.                                                  */
00048 /*----------------------------------------------------------------------------*/
00049 template< class T, class HP >
00050 void ElevateSurfaceDegreeV( 
00051              int nu, int pu, const Ptr<T>& U, int nv, int pv, const Ptr<T>& V,
00052              const Ptr< Ptr<HP> >& Pw, int t,
00053              int *nhu, Ptr<T>& Uh, int *nhv, Ptr<T>& Vh,
00054              Ptr< Ptr<HP> >& Qw )
00055 {
00056   int m,i,mpi,j,ph,ph2,mh,kind,r,a,b,cind,col;
00057   int mul,oldr,lbz,rbz,k,save,s,first,last,kj,tr;
00058   T inv,ua,ub,numer,den,bet,alf,gam;
00059   Ptr< Ptr<T> > bezalfs;
00060   Ptr<T> alfs;
00061   Ptr< Ptr< HP > > bpts,ebpts,Nextbpts;
00062 
00063   bezalfs.reserve_pool(pv+t+1);
00064   for( i = 0; i <= pv+t; i++ ) 
00065     bezalfs[i].reserve_pool(pv+1);
00066 
00067   bpts.reserve_pool(pv+1);
00068   for( i = 0; i <= pv; i++ )
00069     bpts[i].reserve_pool(nu+1);
00070 
00071   ebpts.reserve_pool(pv+t+1);
00072   for( i = 0; i <= pv+t; i++ )
00073     ebpts[i].reserve_pool(nu+1);
00074 
00075   if( pv > 1 )
00076   {
00077     Nextbpts.reserve_pool(pv-1);
00078     for( i = 0; i < pv-1; i++ )
00079       Nextbpts[i].reserve_pool(nu+1);
00080 
00081     alfs.reserve_pool(pv-1);
00082   }
00083   m = nv + pv + 1;
00084   ph = pv + t;
00085   ph2 = ph / 2;
00086   
00087 /* --- calc coefficients for raising the degree of the bezier segments ---- */  
00088 
00089   bezalfs[0][0] = 1.0;
00090   bezalfs[ph][pv] = 1.0;
00091   
00092   for( i = 1; i <= ph2; i++ )
00093   {
00094     inv = (T)1 / rtr<T>::BinCoeff( ph, i );
00095     mpi = Min( pv, i );
00096     
00097     for( j = Max( 0,i-t ); j <= mpi; j++ )
00098       bezalfs[i][j] = inv * rtr<T>::BinCoeff(pv,j) * rtr<T>::BinCoeff(t,i-j);
00099   }    
00100   for( i = ph2+1; i <= ph-1; i++ )
00101   {
00102     mpi = Min( pv, i );
00103     for( j = Max( 0,i-t ); j <= mpi; j++ )
00104       bezalfs[i][j] = bezalfs[ph-i][pv-j];
00105   }       
00106   mh = ph;
00107   kind = ph+1;
00108   r = -1;
00109   a = pv;
00110   b = pv+1;
00111   cind = 1;
00112   ua = V[0];
00113   for( col = 0; col <= nu; col++ )
00114     Qw[0][col] = Pw[0][col];
00115   
00116   for( i = 0; i <= ph; i++ )
00117     Vh[i] = ua;
00118     
00119   for( i = 0; i <= pv; i++ )
00120     for( col = 0; col <= nu; col++ )
00121       bpts[i][col] = Pw[i][col];  
00122     
00123   while( b < m )
00124   {
00125     i = b;
00126     while( (b < m) && (V[b] == V[b+1]) )
00127       b++;
00128 
00129     mul = b-i+1;
00130     mh = mh + mul + t;
00131     ub = V[b];
00132     oldr = r;
00133     r = pv - mul;
00134     
00135     if( oldr > 0)
00136       lbz = (oldr+2) / 2;
00137     else
00138       lbz = 1;
00139 
00140     if( r > 0 )
00141       rbz = ph - ((r+1) / 2);
00142     else
00143       rbz = ph;  
00144 
00145     if( r > 0 )
00146     {
00147       numer = ub - ua;
00148       for( k = pv; k > mul; k-- )
00149         alfs[k-mul-1] = numer / (V[a+k]-ua);
00150       for( j = 1; j <= r; j++ )  
00151       {
00152         save = r - j;
00153         s = mul + j;            
00154 
00155         for( k = pv; k >= s; k-- )
00156         {
00157           for( col = 0; col <= nu; col++ )
00158           {
00159             bpts[k][col] = 
00160               ((T)1 - alfs[k-s]) * bpts[k-1][col] + alfs[k-s] * bpts[k][col];
00161           }  
00162         }
00163         for( col = 0; col <= nu; col++ )
00164           Nextbpts[save][col] = bpts[pv][col];
00165       }  
00166     }
00167     for( i = lbz; i <= ph; i++ )
00168     {
00169       for( col = 0; col <= nu; col++ )
00170         set( ebpts[i][col], (T)0 );
00171 
00172       mpi = Min( pv, i );
00173       for( j = Max(0,i-t); j <= mpi; j++ )
00174       {
00175         for( col = 0; col <= nu; col++ )
00176           ebpts[i][col] = ebpts[i][col] + bezalfs[i][j] * bpts[j][col];
00177       }      
00178     }
00179     if( oldr > 1 )
00180     {
00181       first = kind-2;
00182       last = kind;
00183       den = ub-ua;
00184       bet = (ub-Vh[kind-1])/den;
00185       
00186       for( tr = 1; tr < oldr; tr++ )
00187       {        
00188         i = first;
00189         j = last;
00190         kj = j-kind+1;
00191         while( j - i > tr )
00192         {
00193           if( i < cind )
00194           {
00195             alf = (ub-Vh[i])/(ua-Vh[i]);
00196             for( col = 0; col <= nu; col++ )
00197               Qw[i][col] = ((T)1 - alf) * Qw[i-1][col] + alf * Qw[i][col];
00198           }        
00199           if( j >= lbz )
00200           {
00201             if( j - tr <= kind-ph+oldr )
00202             {  
00203               gam = (ub-Vh[j-tr])/den;
00204               for( col = 0; col <= nu; col++ )
00205               {
00206                 ebpts[kj][col] = 
00207                       ((T)1 - gam) * ebpts[kj+1][col] + gam * ebpts[kj][col];
00208               }
00209             }
00210             else
00211             {
00212               for( col = 0; col <= nu; col++ )
00213               {
00214                 ebpts[kj][col] =
00215                       ((T)1 - bet) * ebpts[kj+1][col] + bet * ebpts[kj][col];
00216               }
00217             }
00218           }
00219           i++;
00220           j--;
00221           kj--;
00222         }      
00223         first--;
00224         last++;
00225       }                    
00226     }    
00227     if( a != pv )
00228       for( i = 0; i < ph-oldr; i++ )
00229       {
00230         Vh[kind] = ua;
00231         kind++;
00232       }
00233     for( j = lbz; j <= rbz; j++ )
00234     {
00235       for( col = 0; col <= nu; col++ )
00236         Qw[cind][col] = ebpts[j][col];
00237       cind++;
00238     }
00239     if( b < m )
00240     {
00241       for( j = 0; j < r; j++ )
00242         for( col = 0; col <= nu; col++ )
00243           bpts[j][col] = Nextbpts[j][col];
00244       for( j = r; j <= pv; j++ )
00245         for( col = 0; col <= nu; col++ )
00246           bpts[j][col] = Pw[b-pv+j][col];
00247 
00248       a = b;
00249       b++;
00250       ua = ub;
00251     }
00252     else
00253       for( i = 0; i <= ph; i++ )
00254         Vh[kind+i] = ub;
00255   }                  
00256     
00257   *nhv = mh - ph - 1;
00258 
00259   // just copy knot vector for U-direction
00260   for( i = 0; i < nu + pu + 2; i++ )
00261     Uh[i] = U[i];
00262 
00263   *nhu = nu;  
00264 }          
00265 // template instantiation
00266 template void ElevateSurfaceDegreeV( 
00267       int nu, int pu, const Ptr<float>& U, int nv, int pv, const Ptr<float>& V,
00268       const Ptr< Ptr< point<float> > >& Pw, int t,
00269       int *nhu, Ptr<float>& Uh, int *nhv, Ptr<float>& Vh,
00270       Ptr< Ptr< point<float> > >& Qw );
00271 template void ElevateSurfaceDegreeV( 
00272       int nu, int pu, const Ptr<float>& U, int nv, int pv, const Ptr<float>& V,
00273       const Ptr< Ptr< hpoint<float> > >& Pw, int t,
00274       int *nhu, Ptr<float>& Uh, int *nhv, Ptr<float>& Vh,
00275       Ptr< Ptr< hpoint<float> > >& Qw );
00276 template void ElevateSurfaceDegreeV( 
00277       int nu, int pu, const Ptr<float>& U, int nv, int pv, const Ptr<float>& V,
00278       const Ptr< Ptr< point1<float> > >& Pw, int t,
00279       int *nhu, Ptr<float>& Uh, int *nhv, Ptr<float>& Vh,
00280       Ptr< Ptr< point1<float> > >& Qw );
00281 template void ElevateSurfaceDegreeV( 
00282       int nu, int pu, const Ptr<float>& U, int nv, int pv, const Ptr<float>& V,
00283       const Ptr< Ptr< hpoint1<float> > >& Pw, int t,
00284       int *nhu, Ptr<float>& Uh, int *nhv, Ptr<float>& Vh,
00285       Ptr< Ptr< hpoint1<float> > >& Qw );
00286 
00287 template void ElevateSurfaceDegreeV( 
00288     int nu, int pu, const Ptr<double>& U, int nv, int pv, const Ptr<double>& V,
00289     const Ptr< Ptr< point<double> > >& Pw, int t,
00290     int *nhu, Ptr<double>& Uh, int *nhv, Ptr<double>& Vh,
00291     Ptr< Ptr< point<double> > >& Qw );
00292 template void ElevateSurfaceDegreeV( 
00293     int nu, int pu, const Ptr<double>& U, int nv, int pv, const Ptr<double>& V,
00294     const Ptr< Ptr< hpoint<double> > >& Pw, int t,
00295     int *nhu, Ptr<double>& Uh, int *nhv, Ptr<double>& Vh,
00296     Ptr< Ptr< hpoint<double> > >& Qw );
00297 template void ElevateSurfaceDegreeV( 
00298     int nu, int pu, const Ptr<double>& U, int nv, int pv, const Ptr<double>& V,
00299     const Ptr< Ptr< point1<double> > >& Pw, int t,
00300     int *nhu, Ptr<double>& Uh, int *nhv, Ptr<double>& Vh,
00301     Ptr< Ptr< point1<double> > >& Qw );
00302 template void ElevateSurfaceDegreeV( 
00303     int nu, int pu, const Ptr<double>& U, int nv, int pv, const Ptr<double>& V,
00304     const Ptr< Ptr< hpoint1<double> > >& Pw, int t,
00305     int *nhu, Ptr<double>& Uh, int *nhv, Ptr<double>& Vh,
00306     Ptr< Ptr< hpoint1<double> > >& Qw );
00307 
00308 
00309 
00310 }
00311 
00312 
00313         

Generated on Mon Jan 21 04:17:41 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001