00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00062
00063
00064
00065
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
00083
00084
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
00111
00112
00113
00114
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
00172
00173
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