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

gunu_make_compatible.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 #include "stdafx.h"
00021 
00022 #include <iostream>
00023 
00024 #include "gul_types.h"
00025 #include "gul_float.h"
00026 #include "gul_vector.h"
00027 #include "gunu_raise_degree.h"
00028 #include "gunu_refine.h"
00029 #include "gunu_make_compatible.h"
00030 // #include "gul_io.h"
00031 
00032 namespace gunu {
00033 
00034 using gul::rtr;
00035 using gul::rel_equal;
00036 using gul::InternalError;
00037 using gul::ndebug;
00038 using gul::Ptr;
00039 using gul::point;
00040 using gul::hpoint;
00041 using gul::point2;
00042 using gul::hpoint2;
00043 using gul::point1;
00044 using gul::hpoint1;
00045 
00046 /*-------------------------------------------------------------------------*//**
00047   make two surfaces in U- or V- direction compatible, after this both surfaces
00048   have the same degree and knot vector in the wanted direction, while remaining
00049   geometrically unchanged. (remark: the knot vectors must already have the
00050   same bounds, for example U1 = [0,0,0.5,1,1], U2 = [0,0,0,0.2,0.4,1,1,1])    */
00051 /*----------------------------------------------------------------------------*/
00052 template< class T, class HP1, class HP2 >
00053 void MakeSurfacesCompatibleU(
00054                    int nu1, int pu1, Ptr<T>& U1,
00055                    int nv1, int pv1, Ptr<T>& V1,
00056                    Ptr< Ptr<HP1> >& Pw1,
00057                    int nu2, int pu2, Ptr<T>& U2,
00058                    int nv2, int pv2, Ptr<T>& V2,
00059                    Ptr< Ptr<HP2> >& Pw2,
00060                    int *ret_nu1, int *ret_pu1, Ptr<T> *ret_U1,
00061                    int *ret_nv1, int *ret_pv1, Ptr<T> *ret_V1,
00062                    Ptr< Ptr<HP1> > *ret_Pw1,
00063                    int *ret_nu2, int *ret_pu2, Ptr<T> *ret_U2,
00064                    int *ret_nv2, int *ret_pv2, Ptr<T> *ret_V2,
00065                    Ptr< Ptr<HP2> > *ret_Pw2 )
00066 {
00067   Ptr<T> Uh1, Uh2, Vh1, Vh2, X1, X2, Ur1, Ur2, Vr1, Vr2;
00068   T u;
00069   Ptr< Ptr<HP1> > Qwh1, Pwr1;
00070   Ptr< Ptr<HP2> > Qwh2, Pwr2;
00071   int i,j,nuh1,nuh2,nvh1,nvh2,maxx,x1,x2,k1,k2,k,t,pu;  
00072 
00073 /* --- make degrees beeing the same ---------------------------------------- */
00074 
00075   if( pu1 < pu2 )
00076   {
00077     t = pu2 - pu1;
00078      
00079     Uh1.reserve_pool(2*pu1 + (nu1-pu1+2)*(t+1));
00080     Vh1.reserve_pool(nv1 + pv1 + 2);
00081 
00082     Qwh1.reserve_pool(nv1+1); 
00083     for( i = 0; i < nv1+1; i++ )
00084       Qwh1[i].reserve_pool(pu1 + (nu1-pu1+1)*(t+1));
00085   
00086     ElevateSurfaceDegree(nu1, pu1, U1, nv1, pv1, V1, Pw1, t, gul::u_direction,
00087                          &nuh1, Uh1, &nvh1, Vh1, Qwh1 );
00088     nuh2 = nu2;
00089     nvh2 = nv2;
00090     Uh2 = U2;  // Uh2,Vh2,Qwh2 don't get changed, so the pointers can point
00091     Vh2 = V2;  // to the same location
00092     Qwh2 = Pw2;
00093 
00094     pu = pu2;
00095   }
00096   else if( pu2 < pu1 )
00097   {
00098     t = pu1 - pu2;
00099      
00100     Uh2.reserve_pool(2*pu2 + (nu2-pu2+2)*(t+1));
00101     Vh2.reserve_pool(nv2 + pv2 + 2);
00102 
00103     Qwh2.reserve_pool(nv2+1);
00104     for( i = 0; i < nv2+1; i++ )
00105       Qwh2[i].reserve_pool(pu2 + (nu2-pu2+1)*(t+1));
00106     
00107     ElevateSurfaceDegree(nu2, pu2, U2, nv2, pv2, V2, Pw2, t, gul::u_direction,
00108                          &nuh2, Uh2, &nvh2, Vh2, Qwh2 );
00109     nuh1 = nu1;
00110     nvh1 = nv1;
00111     Uh1 = U1;  // Uh1,Vh1,Qwh1 don't get changed, so the pointers can point
00112     Vh1 = V1;  // can point to the same location
00113     Qwh1 = Pw1;
00114 
00115     pu = pu1;
00116   }
00117   else                  /* p1 == p2 */    
00118   {
00119     nuh1 = nu1;
00120     nvh1 = nv1;
00121     Uh1 = U1;  // Uh1,Vh1,Qwh1 don't get changed, so the pointers can point       
00122     Vh1 = V1;  // can point to the same location
00123     Qwh1 = Pw1;
00124 
00125     nuh2 = nu2;
00126     nvh2 = nv2;
00127     Uh2 = U2;  // Uh2,Vh2,Qwh2 don't get changed, so the pointers can point
00128     Vh2 = V2;  // can point to the same location
00129     Qwh2 = Pw2;
00130 
00131     pu = pu1;
00132   }
00133 /* ----------------------------------------------------------
00134   now both surfaces have the same degree, and are given by:
00135    nuh1, pu, Uh1,  nvh1, pv1, Vh1,  Qwh1
00136    nuh2, pu, Uh2,  nvh2, pv2, Vh2,  Qwh2    
00137 ----------------------------------------------------------- */
00138 
00139 /* --- make both knot vectors beeing the same ----------------------------- */
00140 
00141   maxx = nuh1-pu + nuh2-pu;
00142   if( maxx > 0 )
00143   {
00144     X1.reserve_pool(maxx);
00145     X2.reserve_pool(maxx); 
00146   }    
00147   k1 = 0;
00148   k2 = 0;
00149   k = 0;
00150   x1 = 0;
00151   x2 = 0;
00152   
00153   while( (k1 <= nuh1 + pu + 1) && (k2 <= nuh2 + pu + 1) )
00154   { 
00155     if( rel_equal(Uh1[k1],Uh2[k2],rtr<T>::zero_tol()) )
00156     {
00157       k1++;
00158       k2++;
00159     }  
00160     else if( Uh1[k1] < Uh2[k2] )
00161     {
00162       X2[x2] = Uh1[k1];
00163       x2++;
00164       k1++;
00165     }
00166     else
00167     {
00168       X1[x1] = Uh2[k2];
00169       x1++;
00170       k2++;
00171     }  
00172     k++;
00173   }
00174   /* k now contains the number of knots of the union knot vector */
00175 
00176   gul::Assert<InternalError>( ndebug || (nuh1 + x1 == nuh2 + x2) );
00177 
00178 /* --- reserve memory for output arrays ------------------------- */
00179 
00180   Ur1.reserve_pool(k);
00181   Vr1.reserve_pool(nvh1+pv1+2);
00182 
00183   Pwr1.reserve_pool(nvh1+1);
00184   for( i = 0; i <= nvh1; i++ )
00185     Pwr1[i].reserve_pool(k-pu-1);
00186 
00187   Ur2.reserve_pool(k);
00188   Vr2.reserve_pool(nvh2+pv2+2);
00189 
00190   Pwr2.reserve_pool(nvh2+1);
00191   for( i = 0; i <= nvh2; i++ )
00192     Pwr2[i].reserve_pool(k-pu-1);
00193 
00194   if( x1 > 0 )
00195   {
00196     RefineSurface( nuh1, pu, Uh1, nvh1, pv1, Vh1, Qwh1,
00197                    X1, x1-1, gul::u_direction, Ur1, Vr1, Pwr1 );
00198   }
00199   else
00200   {        
00201     // copy the first surface, when it is not needed to refine it  
00202     for( i = 0; i < k; i++ ) Ur1[i] = Uh1[i];
00203     for( i = 0; i < nvh1+pv1+2; i++ ) Vr1[i] = Vh1[i];
00204 
00205     for( i = 0; i < nvh1+1; i++ )
00206       for( j = 0; j < k - pu - 1; j++ )
00207         Pwr1[i][j] = Qwh1[i][j];
00208   }  
00209   if( x2 > 0 )
00210   {
00211     RefineSurface( nuh2, pu, Uh2, nvh2, pv2, Vh2, Qwh2,
00212                    X2, x2-1, gul::u_direction, Ur2, Vr2, Pwr2 );
00213   }
00214   else
00215   {
00216     // copy the second surface, when it is not needed to refine it  
00217     for( i = 0; i < k; i++ ) Ur2[i] = Uh2[i];
00218     for( i = 0; i < nvh2+pv2+2; i++ ) Vr2[i] = Vh2[i];
00219 
00220     for( i = 0; i < nvh2+1; i++ )
00221       for( j = 0; j < k - pu - 1; j++ )
00222         Pwr2[i][j] = Qwh2[i][j];
00223   } 
00224   for( i = pu+1; i < k-pu-1; i++ )
00225   {
00226     u = (Ur1[i] + Ur2[i]) / (T)2;  // because of the knot coincidence tol
00227     Ur1[i] = u;
00228     Ur2[i] = u;
00229   }
00230   *ret_pu1 = pu;
00231   *ret_pu2 = pu;
00232   *ret_nu1 = k-pu-2;
00233   *ret_nu2 = k-pu-2;
00234   *ret_pv1 = pv1;
00235   *ret_pv2 = pv2;
00236   *ret_nv1 = nvh1;
00237   *ret_nv2 = nvh2;
00238   *ret_U1 = Ur1;
00239   *ret_U2 = Ur2;
00240   *ret_V1 = Vr1;
00241   *ret_V2 = Vr2;
00242   *ret_Pw1 = Pwr1;
00243   *ret_Pw2 = Pwr2;    
00244 }                   
00245 // template instantiation
00246 template void MakeSurfacesCompatibleU(
00247                 int nu1, int pu1, Ptr<float>& U1,
00248                 int nv1, int pv1, Ptr<float>& V1,
00249                 Ptr< Ptr< point<float> > >& Pw1,
00250                 int nu2, int pu2, Ptr<float>& U2,
00251                 int nv2, int pv2, Ptr<float>& V2,
00252                 Ptr< Ptr< point<float> > >& Pw2,
00253                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00254                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00255                 Ptr< Ptr< point<float> > > *ret_Pw1,
00256                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00257                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00258                 Ptr< Ptr< point<float> > > *ret_Pw2 );
00259 template void MakeSurfacesCompatibleU(
00260                 int nu1, int pu1, Ptr<float>& U1,
00261                 int nv1, int pv1, Ptr<float>& V1,
00262                 Ptr< Ptr< hpoint<float> > >& Pw1,
00263                 int nu2, int pu2, Ptr<float>& U2,
00264                 int nv2, int pv2, Ptr<float>& V2,
00265                 Ptr< Ptr< hpoint<float> > >& Pw2,
00266                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00267                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00268                 Ptr< Ptr< hpoint<float> > > *ret_Pw1,
00269                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00270                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00271                 Ptr< Ptr< hpoint<float> > > *ret_Pw2 );
00272 template void MakeSurfacesCompatibleU(
00273                 int nu1, int pu1, Ptr<float>& U1,
00274                 int nv1, int pv1, Ptr<float>& V1,
00275                 Ptr< Ptr< point1<float> > >& Pw1,
00276                 int nu2, int pu2, Ptr<float>& U2,
00277                 int nv2, int pv2, Ptr<float>& V2,
00278                 Ptr< Ptr< point1<float> > >& Pw2,
00279                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00280                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00281                 Ptr< Ptr< point1<float> > > *ret_Pw1,
00282                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00283                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00284                 Ptr< Ptr< point1<float> > > *ret_Pw2 );
00285 template void MakeSurfacesCompatibleU(
00286                 int nu1, int pu1, Ptr<float>& U1,
00287                 int nv1, int pv1, Ptr<float>& V1,
00288                 Ptr< Ptr< hpoint1<float> > >& Pw1,
00289                 int nu2, int pu2, Ptr<float>& U2,
00290                 int nv2, int pv2, Ptr<float>& V2,
00291                 Ptr< Ptr< hpoint1<float> > >& Pw2,
00292                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00293                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00294                 Ptr< Ptr< hpoint1<float> > > *ret_Pw1,
00295                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00296                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00297                 Ptr< Ptr< hpoint1<float> > > *ret_Pw2 );
00298 
00299 template void MakeSurfacesCompatibleU(
00300                 int nu1, int pu1, Ptr<double>& U1,
00301                 int nv1, int pv1, Ptr<double>& V1,
00302                 Ptr< Ptr< point<double> > >& Pw1,
00303                 int nu2, int pu2, Ptr<double>& U2,
00304                 int nv2, int pv2, Ptr<double>& V2,
00305                 Ptr< Ptr< point<double> > >& Pw2,
00306                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00307                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00308                 Ptr< Ptr< point<double> > > *ret_Pw1,
00309                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00310                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00311                 Ptr< Ptr< point<double> > > *ret_Pw2 );
00312 template void MakeSurfacesCompatibleU(
00313                 int nu1, int pu1, Ptr<double>& U1,
00314                 int nv1, int pv1, Ptr<double>& V1,
00315                 Ptr< Ptr< hpoint<double> > >& Pw1,
00316                 int nu2, int pu2, Ptr<double>& U2,
00317                 int nv2, int pv2, Ptr<double>& V2,
00318                 Ptr< Ptr< hpoint<double> > >& Pw2,
00319                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00320                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00321                 Ptr< Ptr< hpoint<double> > > *ret_Pw1,
00322                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00323                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00324                 Ptr< Ptr< hpoint<double> > > *ret_Pw2 );
00325 template void MakeSurfacesCompatibleU(
00326                 int nu1, int pu1, Ptr<double>& U1,
00327                 int nv1, int pv1, Ptr<double>& V1,
00328                 Ptr< Ptr< point1<double> > >& Pw1,
00329                 int nu2, int pu2, Ptr<double>& U2,
00330                 int nv2, int pv2, Ptr<double>& V2,
00331                 Ptr< Ptr< point1<double> > >& Pw2,
00332                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00333                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00334                 Ptr< Ptr< point1<double> > > *ret_Pw1,
00335                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00336                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00337                 Ptr< Ptr< point1<double> > > *ret_Pw2 );
00338 template void MakeSurfacesCompatibleU(
00339                 int nu1, int pu1, Ptr<double>& U1,
00340                 int nv1, int pv1, Ptr<double>& V1,
00341                 Ptr< Ptr< hpoint1<double> > >& Pw1,
00342                 int nu2, int pu2, Ptr<double>& U2,
00343                 int nv2, int pv2, Ptr<double>& V2,
00344                 Ptr< Ptr< hpoint1<double> > >& Pw2,
00345                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00346                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00347                 Ptr< Ptr< hpoint1<double> > > *ret_Pw1,
00348                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00349                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00350                 Ptr< Ptr< hpoint1<double> > > *ret_Pw2 );
00351                                      
00352 
00353 template void MakeSurfacesCompatibleU(
00354                 int nu1, int pu1, Ptr<float>& U1,
00355                 int nv1, int pv1, Ptr<float>& V1,
00356                 Ptr< Ptr< point1<float> > >& Pw1,
00357                 int nu2, int pu2, Ptr<float>& U2,
00358                 int nv2, int pv2, Ptr<float>& V2,
00359                 Ptr< Ptr< point<float> > >& Pw2,
00360                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00361                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00362                 Ptr< Ptr< point1<float> > > *ret_Pw1,
00363                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00364                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00365                 Ptr< Ptr< point<float> > > *ret_Pw2 );
00366 template void MakeSurfacesCompatibleU(
00367                 int nu1, int pu1, Ptr<float>& U1,
00368                 int nv1, int pv1, Ptr<float>& V1,
00369                 Ptr< Ptr< hpoint1<float> > >& Pw1,
00370                 int nu2, int pu2, Ptr<float>& U2,
00371                 int nv2, int pv2, Ptr<float>& V2,
00372                 Ptr< Ptr< hpoint<float> > >& Pw2,
00373                 int *ret_nu1, int *ret_pu1, Ptr<float> *ret_U1,
00374                 int *ret_nv1, int *ret_pv1, Ptr<float> *ret_V1,
00375                 Ptr< Ptr< hpoint1<float> > > *ret_Pw1,
00376                 int *ret_nu2, int *ret_pu2, Ptr<float> *ret_U2,
00377                 int *ret_nv2, int *ret_pv2, Ptr<float> *ret_V2,
00378                 Ptr< Ptr< hpoint<float> > > *ret_Pw2 );
00379 template void MakeSurfacesCompatibleU(
00380                 int nu1, int pu1, Ptr<double>& U1,
00381                 int nv1, int pv1, Ptr<double>& V1,
00382                 Ptr< Ptr< point1<double> > >& Pw1,
00383                 int nu2, int pu2, Ptr<double>& U2,
00384                 int nv2, int pv2, Ptr<double>& V2,
00385                 Ptr< Ptr< point<double> > >& Pw2,
00386                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00387                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00388                 Ptr< Ptr< point1<double> > > *ret_Pw1,
00389                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00390                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00391                 Ptr< Ptr< point<double> > > *ret_Pw2 );
00392 template void MakeSurfacesCompatibleU(
00393                 int nu1, int pu1, Ptr<double>& U1,
00394                 int nv1, int pv1, Ptr<double>& V1,
00395                 Ptr< Ptr< hpoint1<double> > >& Pw1,
00396                 int nu2, int pu2, Ptr<double>& U2,
00397                 int nv2, int pv2, Ptr<double>& V2,
00398                 Ptr< Ptr< hpoint<double> > >& Pw2,
00399                 int *ret_nu1, int *ret_pu1, Ptr<double> *ret_U1,
00400                 int *ret_nv1, int *ret_pv1, Ptr<double> *ret_V1,
00401                 Ptr< Ptr< hpoint1<double> > > *ret_Pw1,
00402                 int *ret_nu2, int *ret_pu2, Ptr<double> *ret_U2,
00403                 int *ret_nv2, int *ret_pv2, Ptr<double> *ret_V2,
00404                 Ptr< Ptr< hpoint<double> > > *ret_Pw2 );
00405 
00406 }

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