00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef NDINDEX_INLINES_H
00012 #define NDINDEX_INLINES_H
00013
00014
00015 #include "Utility/PAssert.h"
00016
00017
00019
00020 template<unsigned Dim>
00021 inline
00022 NDIndex<Dim>::NDIndex(const Index* idx)
00023 {
00024 for (unsigned i=0; i<Dim; ++i)
00025 p[i]=idx[i];
00026 }
00027
00028
00029 template<unsigned Dim>
00030 inline NDIndex<Dim>
00031 NDIndex<Dim>::intersect(const NDIndex<Dim>& i) const
00032 {
00033 NDIndex<Dim> r;
00034 for (unsigned d=0;d<Dim;++d)
00035 r[d] = p[d].intersect( i[d] );
00036 return r;
00037 }
00038
00040
00041
00042
00043 template<unsigned D1, unsigned D2>
00044 inline NDIndex<D1> plugBase(const NDIndex<D1>& i1, const NDIndex<D2>& i2)
00045 {
00046
00047 NDIndex<D1> ret(i1);
00048
00049 for (unsigned d1=0; d1<D1; ++d1)
00050
00051 for (unsigned d2=0; d2<D2; ++d2)
00052 if ( i1[d1].sameBase( i2[d2] ) )
00053 {
00054
00055 ret[d1] = ret[d1].plugBase( i2[d2] );
00056 break;
00057 }
00058 return ret;
00059 }
00060
00061
00062
00064
00065
00066 template<unsigned Dim>
00067 inline unsigned
00068 NDIndex<Dim>::size() const
00069 {
00070 unsigned s = p[0].length();
00071 for (int d=1; d<Dim; ++d)
00072 s *= p[d].length();
00073 return s;
00074 }
00075
00076
00077
00078 template <unsigned Dim>
00079 inline bool
00080 NDIndex<Dim>::touches(const NDIndex<Dim>& a) const
00081 {
00082 bool touch = true;
00083 for (int d=0; (d<Dim)&&touch ; ++d)
00084 touch = touch && p[d].touches(a.p[d]);
00085 return touch;
00086 }
00087
00088
00089
00090 template <unsigned Dim>
00091 inline bool
00092 NDIndex<Dim>::contains(const NDIndex<Dim>& a) const
00093 {
00094 bool cont = true;
00095 for (int d=0; (d<Dim)&&cont ; ++d)
00096 cont = cont && p[d].contains(a.p[d]);
00097 return cont;
00098 }
00099
00100
00101
00102 template <unsigned Dim>
00103 inline bool
00104 NDIndex<Dim>::containsAllPoints(const NDIndex<Dim>& a) const
00105 {
00106 bool cont = true;
00107 for (int d=0; (d<Dim)&&cont ; ++d)
00108 cont = cont && p[d].containsAllPoints(a.p[d]);
00109 return cont;
00110 }
00111
00112
00113
00114 template<unsigned Dim>
00115 inline bool
00116 NDIndex<Dim>::empty() const
00117 {
00118 bool r = false;
00119 for (unsigned d=0; d<Dim; ++d)
00120 r = r || p[d].empty();
00121 return r;
00122 }
00123
00124
00125
00126 template<unsigned Dim>
00127 inline bool
00128 NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r,
00129 unsigned d, double a) const
00130 {
00131 if ( &l != this )
00132 l = *this;
00133 if ( &r != this )
00134 r = *this;
00135 return p[d].split(l[d],r[d],a);
00136 }
00137
00138 template<unsigned Dim>
00139 inline bool
00140 NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d) const
00141 {
00142 if ( &l != this )
00143 l = *this;
00144 if ( &r != this )
00145 r = *this;
00146 return p[d].split(l[d],r[d]);
00147 }
00148
00149
00150
00151 template<unsigned Dim>
00152 inline bool
00153 NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r) const
00154 {
00155 int max_dim = 0;
00156 int max_length = 0;
00157 for (int d=0; d<Dim; ++d)
00158 if ( p[d].length() > max_length ) {
00159 max_dim = d;
00160 max_length = p[d].length();
00161 }
00162 return split(l,r,max_dim);
00163 }
00164
00166
00167 template<unsigned Dim>
00168 inline
00169 NDIndex<Dim>::NDIndex(const Index& i0)
00170 {
00171 PInsist(Dim==1, "Number of arguments does not match NDIndex dimension!!");
00172 p[0] = i0;
00173 }
00174
00175 template<unsigned Dim>
00176 inline
00177 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1)
00178 {
00179 PInsist(Dim==2, "Number of arguments does not match NDIndex dimension!!");
00180 p[0] = i0;
00181 p[1] = i1;
00182 }
00183
00184 template<unsigned Dim>
00185 inline
00186 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2)
00187 {
00188 PInsist(Dim==3, "Number of arguments does not match NDIndex dimension!!");
00189 p[0] = i0;
00190 p[1] = i1;
00191 p[2] = i2;
00192 }
00193
00194 template<unsigned Dim>
00195 inline
00196 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
00197 const Index& i3)
00198 {
00199 PInsist(Dim==4, "Number of arguments does not match NDIndex dimension!!");
00200 p[0] = i0;
00201 p[1] = i1;
00202 p[2] = i2;
00203 p[3] = i3;
00204 }
00205
00206 template<unsigned Dim>
00207 inline
00208 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
00209 const Index& i3,const Index& i4)
00210 {
00211 PInsist(Dim==5, "Number of arguments does not match NDIndex dimension!!");
00212 p[0] = i0;
00213 p[1] = i1;
00214 p[2] = i2;
00215 p[3] = i3;
00216 p[4] = i4;
00217 }
00218
00219 template<unsigned Dim>
00220 inline
00221 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
00222 const Index& i3,const Index& i4,const Index& i5)
00223 {
00224 PInsist(Dim==6, "Number of arguments does not match NDIndex dimension!!");
00225 p[0] = i0;
00226 p[1] = i1;
00227 p[2] = i2;
00228 p[3] = i3;
00229 p[4] = i4;
00230 p[5] = i5;
00231 }
00232
00233 template<> inline
00234 NDIndex<2>::NDIndex(const NDIndex<1>& ndi, const Index& i)
00235 {
00236 p[0] = ndi[0];
00237 p[1] = i;
00238 }
00239 template<> inline
00240 NDIndex<3>::NDIndex(const NDIndex<2>& ndi, const Index& i)
00241 {
00242 p[0] = ndi[0];
00243 p[1] = ndi[1];
00244 p[2] = i;
00245 }
00246 template<> inline
00247 NDIndex<4>::NDIndex(const NDIndex<3>& ndi, const Index& i)
00248 {
00249 p[0] = ndi[0];
00250 p[1] = ndi[1];
00251 p[2] = ndi[2];
00252 p[3] = i;
00253 }
00254 template<> inline
00255 NDIndex<5>::NDIndex(const NDIndex<4>& ndi, const Index& i)
00256 {
00257 p[0] = ndi[0];
00258 p[1] = ndi[1];
00259 p[2] = ndi[2];
00260 p[3] = ndi[3];
00261 p[4] = i;
00262 }
00263 template<> inline
00264 NDIndex<6>::NDIndex(const NDIndex<5>& ndi, const Index& i)
00265 {
00266 p[0] = ndi[0];
00267 p[1] = ndi[1];
00268 p[2] = ndi[2];
00269 p[3] = ndi[3];
00270 p[4] = ndi[4];
00271 p[5] = i;
00272 }
00273
00275
00276
00277
00278
00279
00280
00281
00282
00283
00285
00286 template<unsigned D1, unsigned D2>
00287 inline bool isStencil(const NDIndex<D1> &i1, const NDIndex<D2> &i2)
00288 {
00289 for (unsigned i = 0; i < D1; i++)
00290 {
00291 bool found = false;
00292 for (unsigned j = 0; j < D2; j++)
00293 {
00294 if (i1[i].id() == i2[j].id())
00295 {
00296 found = true;
00297 if (!(i1[i] == i2[j]))
00298 return true;
00299 }
00300 }
00301 if (!found)
00302 return true;
00303 }
00304
00305 return false;
00306 }
00307
00308 #endif // NDINDEX_INLINES_H
00309
00310
00311
00312
00313
00314