Main Page   Class Hierarchy   Compound List   File List   Compound Members  

barray2d_hpoint.cpp

00001 /*=============================================================================
00002         File: barray2d.cpp
00003      Purpose:
00004     Revision: $Id: barray2d_hpoint.cpp,v 1.3 2003/01/13 19:41:13 philosophil Exp $
00005   Created by: Philippe Lavoie          (3 Oct, 1996)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-2002 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 =============================================================================*/
00025 
00026 #ifndef PLIB_BARRAY2D_SOURCE
00027 #define PLIB_BARRAY2D_SOURCE
00028 
00029 #include "barray2d.cpp"
00030 
00031 namespace PLib {
00032 
00033 template <class T, const int D>
00034 void initBasic2DArrayHPoint(Basic2DArray<HPoint_nD<T,D> >& a, const int r,const int c)
00035 {
00036   if ( r <= 0  || c <= 0 )
00037     {
00038       if(a.m)
00039         delete []a.m ;
00040       if(a.vm)
00041         delete []a.vm ;
00042       a.rz = r ;
00043       a.cz = c ;
00044       return ;
00045     }
00046         
00047   a.rz = r;     a.cz = c;
00048 
00049   a.created = 1 ;
00050 #ifdef COLUMN_ORDER
00051   a.vm = new HPoint_nD<T,D>* [a.cz] ;
00052 #else
00053   a.vm = new HPoint_nD<T,D>* [a.rz] ;
00054 #endif
00055 
00056   T* dn ;
00057   dn = new T[a.rz*a.cz*(D+1)] ;
00058   int i ;
00059 
00060   a.m = new NoInitHPoint_nD<T,D>[a.rz*a.cz] ;
00061   // At this point the elements data pointer points to null
00062   // and their created status is 0.
00063   // The following is done so that the data point to 
00064   // their proper place inside the consecutive memory
00065   // array allocated inside dn.
00066 
00067 #ifdef COLUMN_ORDER
00068   const int sze = a.rz*a.cz ;
00069   for(i=sze-1;i>=0;--i){
00070     a.m[i].data = dn+i*(D+1) ;  
00071   }
00072 #else
00073   for(i=a.rz-1;i>=0;--i){
00074     for(int j=a.cz-1;j>=0;--j){
00075       a.m[i*a.cz+j].data = dn+(a.rz*j+i)*(D+1) ; 
00076     }
00077   }
00078 #endif 
00079 
00080   memset((void*)dn,0,(a.cz*a.rz*(D+1))*sizeof(T)) ;
00081 
00082   // Ok so everyone points to the consecutive array
00083   // but someone needs to delete it when the times
00084   // come. That's the job of the first HPoint.
00085   if((a.rz*a.cz)>0)
00086     a.m[0].created = 1;
00087 
00088 #ifdef COLUMN_ORDER
00089   for(i=a.cz-1;i>=0;--i)
00090     a.vm[i] = &a.m[i*a.rz] ;
00091 #else
00092   for(i=a.rz-1;i>=0;--i)
00093     a.vm[i] = &a.m[i*a.cz] ;
00094 #endif
00095 }
00096 
00097 template <class T, const int D>
00098 void resizeKeepBasic2DArrayHPoint(Basic2DArray<HPoint_nD<T,D> > &a, const int nr,const int nc)
00099 {
00100   if(nr==a.rz && nc==a.cz){
00101     return ;
00102   }
00103 
00104   HPoint_nD<T,D> *mn ;
00105   HPoint_nD<T,D> *p,*pn ;
00106 
00107   pn = 0 ;
00108 
00109   mn = new NoInitHPoint_nD<T,D>[nr*nc] ;
00110   // At this point the elements data pointer points to null
00111   // and their created status is 0.
00112   // The following is done so that the data point to 
00113   // their proper place inside the consecutive memory
00114   // array allocated inside dn.
00115 
00116   T* dn ;
00117   dn = new T[nr*nc*(D+1)] ;
00118   memset((void*)dn,0,(nr*nc*(D+1))*sizeof(T)) ;
00119 
00120   int i,j ;
00121 #ifdef COLUMN_ORDER
00122   for(i=0;i<nr*nc;++i){
00123     mn[i].created = 0 ; 
00124     mn[i].data = &dn[i*(D+1)] ;
00125   }
00126   for(j=0;j<minimum(nc,a.cz);j++){
00127     p = &a.m[j*a.rz] -1;
00128     pn = &mn[j*nr] -1 ;
00129     for(i=0;i<minimum(nr,a.rz);i++){
00130       *(++pn) = *(++p) ;
00131     }
00132   }
00133 
00134   for(j=a.cz;j<nc;j++)
00135     pn = &mn[j*nr+a.rz]-1 ;
00136     for(i=a.rz;i<nr;i++){
00137       *(pn++) = HPoint_nD<T,D>(0) ;
00138   }
00139 
00140 #else
00141   for(i=0;i<nr;++i){
00142     for(j=0;j<nc;++j){
00143       mn[i*nc+j].created = 0 ; 
00144       mn[i*nc+j].data = &dn[(nr*j+i)*(D+1)] ;
00145     }
00146   }
00147   for(i=0;i<minimum(nr,a.rz);i++){
00148     p = &a.m[i*a.cz] -1;
00149     pn = &mn[i*nc] -1 ;
00150     for(j=0;j<minimum(nc,a.cz);j++){
00151       *(++pn) = *(++p) ;
00152     }
00153   }
00154 
00155   for(i=a.rz;i<nr;i++){
00156     pn = &mn[i*nc+a.cz]-1 ;
00157     for(j=a.cz;j<nc;j++)
00158       *(pn++) = HPoint_nD<T,D>(0) ;
00159   }
00160 
00161 #endif
00162 
00163   a.rz = nr ;
00164   a.cz = nc ;
00165 
00166   if(a.m && a.created){
00167     delete []a.m ;
00168   }
00169   a.created = 1 ;
00170   a.m = mn ;
00171   // Ok so everyone points to the consecutive array
00172   // but someone needs to delete it when the times
00173   // come. That's the job of the first HPoint.
00174   if((nr*nc)>0)
00175     a.m[0].created = 1 ;
00176   if(a.vm)
00177     delete []a.vm ;
00178 #ifdef COLUMN_ORDER
00179   a.vm = new HPoint_nD<T,D>* [a.cz] ;
00180   for(i=0;i<a.cz;++i)
00181     a.vm[i] = &a.m[i*a.rz] ;
00182 #else
00183   a.vm = new HPoint_nD<T,D>* [a.rz] ;
00184   for(i=0;i<a.rz;++i)
00185     a.vm[i] = &a.m[i*a.cz] ;
00186 #endif
00187 }
00188 
00189 template<>
00190 void initBasic2DArray(Basic2DArray<HPoint_nD<float,2> >& a, const int nr, const int nc){
00191   initBasic2DArrayHPoint(a,nr,nc) ;
00192 }
00193 
00194 template<>
00195 void initBasic2DArray(Basic2DArray<HPoint_nD<float,3> >& a, const int nr, const int nc){
00196   initBasic2DArrayHPoint(a,nr,nc) ;
00197 }
00198 
00199 template<>
00200 void initBasic2DArray(Basic2DArray<HPoint_nD<double,2> >& a, const int nr, const int nc){
00201   initBasic2DArrayHPoint(a,nr,nc) ;
00202 }
00203 
00204 template<>
00205 void initBasic2DArray(Basic2DArray<HPoint_nD<double,3> >& a, const int nr, const int nc){
00206   initBasic2DArrayHPoint(a,nr,nc) ;
00207 }
00208 
00209 template<>
00210 void resizeKeepBasic2DArray(Basic2DArray<HPoint_nD<float,2> >& a, const int nr, const int nc){
00211   resizeKeepBasic2DArrayHPoint(a,nr,nc) ;
00212 }
00213 
00214 template<>
00215 void resizeKeepBasic2DArray(Basic2DArray<HPoint_nD<float,3> >& a, const int nr, const int nc){
00216   resizeKeepBasic2DArrayHPoint(a,nr,nc) ;
00217 }
00218 
00219 template<>
00220 void resizeKeepBasic2DArray(Basic2DArray<HPoint_nD<double,2> >& a, const int nr, const int nc){
00221   resizeKeepBasic2DArrayHPoint(a,nr,nc) ;
00222 }
00223 
00224 template<>
00225 void resizeKeepBasic2DArray(Basic2DArray<HPoint_nD<double,3> >& a, const int nr, const int nc){
00226   resizeKeepBasic2DArrayHPoint(a,nr,nc) ;
00227 }
00228 
00229 #ifdef NO_IMPLICIT_TEMPLATES
00230 
00231 template class Basic2DArray<HPoint3Df> ;
00232 template void initBasic2DArrayHPoint(Basic2DArray<HPoint3Df>&,const int,const int) ;
00233 template void resizeKeepBasic2DArrayHPoint(Basic2DArray<HPoint3Df>&,const int,const int) ;
00234 template istream& operator>>(istream& is, Basic2DArray<HPoint3Df>& ary);
00235 template ostream& operator<<(ostream& os, const Basic2DArray<HPoint3Df>& ary);
00236 
00237 template class Basic2DArray<HPoint2Df> ;
00238 template void initBasic2DArrayHPoint(Basic2DArray<HPoint2Df>&,const int,const int) ;
00239 template void resizeKeepBasic2DArrayHPoint(Basic2DArray<HPoint2Df>&,const int,const int) ;
00240 template istream& operator>>(istream& is, Basic2DArray<HPoint2Df>& ary);
00241 template ostream& operator<<(ostream& os, const Basic2DArray<HPoint2Df>& ary);
00242 
00243 template class Basic2DArray<HPoint3Dd> ;
00244 template void initBasic2DArrayHPoint(Basic2DArray<HPoint3Dd>&,const int,const int) ;
00245 template void resizeKeepBasic2DArrayHPoint(Basic2DArray<HPoint3Dd>&,const int,const int) ;
00246 template istream& operator>>(istream& is, Basic2DArray<HPoint3Dd>& ary);
00247 template ostream& operator<<(ostream& os, const Basic2DArray<HPoint3Dd>& ary);
00248 
00249 template class Basic2DArray<HPoint2Dd> ;
00250 template void initBasic2DArrayHPoint(Basic2DArray<HPoint2Dd>&,const int,const int) ;
00251 template void resizeKeepBasic2DArrayHPoint(Basic2DArray<HPoint2Dd>&,const int,const int) ;
00252 template istream& operator>>(istream& is, Basic2DArray<HPoint2Dd>& ary);
00253 template ostream& operator<<(ostream& os, const Basic2DArray<HPoint2Dd>& ary);
00254 
00255 #endif
00256 
00257 }
00258 
00259 #endif //  PLIB_BARRAY2D_SOURCE

Generated on Tue Jun 24 13:26:54 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002