00001
00002
00003
00004
00005
00006 #ifndef AMROC_FIXUP2_H
00007 #define AMROC_FIXUP2_H
00008
00016 #include "FixupBase.h"
00017
00024 template <class VectorType, class FixupType>
00025 class FixupOps<VectorType,FixupType,2> {
00026 public:
00027 FixupOps() {}
00028
00029 void AlignBBox(BBox &bb, const int s) {
00030 int DAGH_Base = DAGH_Y;
00031 #ifdef DEBUG_PRINT
00032 assert (s>=0 && s<2*2);
00033 #endif
00034 int dim_1 = 1;
00035 if (s % 2 != 0)
00036 DAGH_Base = DAGH_Base | DAGH_Dim1ToTop;
00037 gdbAlignBBox(dim_1, bb, DAGH_Base - s/2);
00038 bb.rank = dim_1;
00039 bb.lower().rank = dim_1;
00040 bb.upper().rank = dim_1;
00041 bb.stepsize().rank = dim_1;
00042 }
00043
00044 void copy_to(GridData<FixupType,1> &target, const BBox &to,
00045 const GridData<VectorType,2> &source, const BBox &fromwhere, const int s) {
00046
00047 BBox tobb(to * target.bbox());
00048 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00049 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00050 const int dk = frombb.lower(0)-tobb.lower(0);
00051
00052 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00053 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00054 switch(s) {
00055 case 0:
00056 case 1:
00057 for_1 (k, tobb, tobb.stepsize())
00058 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00059 FastIndex2(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0)));
00060 end_for
00061 break;
00062 case 2:
00063 case 3:
00064 for_1 (k, tobb, tobb.stepsize())
00065 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00066 FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1)));
00067 end_for
00068 break;
00069 default:
00070 assert(0);
00071 }
00072 EndFastIndex2(src);
00073 EndFastIndex1(tgt);
00074 }
00075 void copy_to(GridData<FixupType,1> &target,
00076 const GridData<VectorType,2> &source, const BBox &fromwhere, const int s) {
00077
00078 BBox tobb(target.bbox());
00079 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00080 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00081 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00082
00083 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00084 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00085 switch(s) {
00086 case 0:
00087 case 1:
00088 for_1 (k, tobb, tobb.stepsize())
00089 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00090 FastIndex2(src, from.lower(0), k-k%frombb.stepsize(0)));
00091 end_for
00092 break;
00093 case 2:
00094 case 3:
00095 for_1 (k, tobb, tobb.stepsize())
00096 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00097 FastIndex2(src, k-k%frombb.stepsize(0), from.lower(1)));
00098 end_for
00099 break;
00100 default:
00101 assert(0);
00102 }
00103 EndFastIndex2(src);
00104 EndFastIndex1(tgt);
00105 }
00106
00107 void copy_from(GridData<VectorType,2> &target, const BBox &towhere,
00108 const GridData<FixupType,1> &source, const BBox &from, const int s) {
00109
00110 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00111 BBox frombb(from * source.bbox());
00112 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00113 const int dk = frombb.lower(0)-tobb.lower(0);
00114
00115 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType);
00116 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType);
00117 switch(s) {
00118 case 0:
00119 case 1:
00120 for_1 (k, tobb, tobb.stepsize())
00121 equals_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)),
00122 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0)));
00123 end_for
00124 break;
00125 case 2:
00126 case 3:
00127 for_1 (k, tobb, tobb.stepsize())
00128 equals_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)),
00129 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0)));
00130 end_for
00131 break;
00132 default:
00133 assert(0);
00134 }
00135 EndFastIndex1(src);
00136 EndFastIndex2(tgt);
00137 }
00138 void copy_from(GridData<VectorType,2> &target, const BBox &towhere,
00139 const GridData<FixupType,1> &source, const int s) {
00140
00141 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00142 BBox frombb(source.bbox());
00143 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00144 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00145
00146 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType);
00147 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType);
00148 switch(s) {
00149 case 0:
00150 case 1:
00151 for_1 (k, tobb, tobb.stepsize())
00152 equals_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)),
00153 FastIndex1(src, k-k%frombb.stepsize(0)));
00154 end_for
00155 break;
00156 case 2:
00157 case 3:
00158 for_1 (k, tobb, tobb.stepsize())
00159 equals_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)),
00160 FastIndex1(src, k-k%frombb.stepsize(0)));
00161 end_for
00162 break;
00163 default:
00164 assert(0);
00165 }
00166 EndFastIndex1(src);
00167 EndFastIndex2(tgt);
00168 }
00169
00170 void add_to(GridData<FixupType,1> &target, const BBox &to,
00171 const GridData<VectorType,2> &source, const BBox &fromwhere, const int s) {
00172
00173 BBox tobb(to * target.bbox());
00174 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00175 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00176 const int dk = frombb.lower(0)-tobb.lower(0);
00177
00178 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00179 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00180 switch(s) {
00181 case 0:
00182 case 1:
00183 for_1 (k, tobb, tobb.stepsize())
00184 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00185 FastIndex2(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0)));
00186 end_for
00187 break;
00188 case 2:
00189 case 3:
00190 for_1 (k, tobb, tobb.stepsize())
00191 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00192 FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1)));
00193 end_for
00194 break;
00195 default:
00196 assert(0);
00197 }
00198 EndFastIndex2(src);
00199 EndFastIndex1(tgt);
00200 }
00201 void add_to(GridData<FixupType,1> &target,
00202 const GridData<VectorType,2> &source, const BBox &fromwhere, const int s) {
00203
00204 BBox tobb(target.bbox());
00205 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00206 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00207 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00208
00209 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00210 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00211 switch(s) {
00212 case 0:
00213 case 1:
00214 for_1 (k, tobb, tobb.stepsize())
00215 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00216 FastIndex2(src, from.lower(0), k-k%frombb.stepsize(0)));
00217 end_for
00218 break;
00219 case 2:
00220 case 3:
00221 for_1 (k, tobb, tobb.stepsize())
00222 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00223 FastIndex2(src, k-k%frombb.stepsize(0), from.lower(1)));
00224 end_for
00225 break;
00226 default:
00227 assert(0);
00228 }
00229 EndFastIndex2(src);
00230 EndFastIndex1(tgt);
00231 }
00232
00233 void add_from(GridData<VectorType,2> &target, const BBox &towhere,
00234 const GridData<FixupType,1> &source, const BBox &from, const int s) {
00235
00236 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00237 BBox frombb(from * source.bbox());
00238 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00239 const int dk = frombb.lower(0)-tobb.lower(0);
00240
00241 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType);
00242 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType);
00243 switch(s) {
00244 case 0:
00245 case 1:
00246 for_1 (k, tobb, tobb.stepsize())
00247 plus_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)),
00248 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0)));
00249 end_for
00250 break;
00251 case 2:
00252 case 3:
00253 for_1 (k, tobb, tobb.stepsize())
00254 plus_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)),
00255 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0)));
00256 end_for
00257 break;
00258 default:
00259 assert(0);
00260 }
00261 EndFastIndex1(src);
00262 EndFastIndex2(tgt);
00263 }
00264 void add_from(GridData<VectorType,2> &target, const BBox &towhere,
00265 const GridData<FixupType,1> &source, const int s) {
00266
00267 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00268 BBox frombb(source.bbox());
00269 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00270 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00271
00272 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType);
00273 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType);
00274 switch(s) {
00275 case 0:
00276 case 1:
00277 for_1 (k, tobb, tobb.stepsize())
00278 plus_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)),
00279 FastIndex1(src, k-k%frombb.stepsize(0)));
00280 end_for
00281 break;
00282 case 2:
00283 case 3:
00284 for_1 (k, tobb, tobb.stepsize())
00285 plus_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)),
00286 FastIndex1(src, k-k%frombb.stepsize(0)));
00287 end_for
00288 break;
00289 default:
00290 assert(0);
00291 }
00292 EndFastIndex1(src);
00293 EndFastIndex2(tgt);
00294 }
00295
00296 void add_to(GridData<FixupType,1> &target, const BBox &to,
00297 const GridData<VectorType,1> &source, const BBox &from) {
00298
00299 BBox tobb(to * target.bbox());
00300 BBox frombb(from * source.bbox());
00301 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00302 const int dk = frombb.lower(0)-tobb.lower(0);
00303
00304 BeginFastIndex1(src, source.bbox(), source.data(), const VectorType);
00305 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00306 for_1 (k, tobb, tobb.stepsize())
00307 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00308 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0)));
00309 end_for
00310 EndFastIndex1(src);
00311 EndFastIndex1(tgt);
00312 }
00313 void add_to(GridData<FixupType,1> &target,
00314 const GridData<VectorType,1> &source, const BBox &where) {
00315
00316 BBox tobb(target.bbox());
00317 BBox frombb(where * source.bbox());
00318 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);
00319 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00320
00321 BeginFastIndex1(src, source.bbox(), source.data(), const VectorType);
00322 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType);
00323 for_1 (k, tobb, tobb.stepsize())
00324 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)),
00325 FastIndex1(src, k-k%frombb.stepsize(0)));
00326 end_for
00327 EndFastIndex1(src);
00328 EndFastIndex1(tgt);
00329 }
00330 };
00331
00338 template <class VectorType, class FixupType>
00339 class Fixup<VectorType,FixupType,2> : public FixupBase<VectorType,FixupType,2> {
00340 typedef GridData<VectorType,2> vec_grid_data_type;
00341 typedef GridData<VectorType,minus_1<2>::dim> ld_vec_grid_data_type;
00342 typedef GridData<FixupType,minus_1<2>::dim> ld_fixup_grid_data_type;
00343
00344 public:
00345 Fixup() : FixupBase<VectorType,FixupType,2>() {}
00346
00347 protected:
00348 void debug_print(vec_grid_data_type &gd, const BBox &where) {
00349 #ifdef DEBUG_PRINT
00350 Coords lower(2,std::max(where.lower(0),gd.lower(0)),
00351 std::max(where.lower(1),gd.lower(1)));
00352 Coords upper(2,std::min(where.upper(0),gd.upper(0)),
00353 std::min(where.upper(1),gd.upper(1)));
00354 for (register int j=lower(1); j<=upper(1); j+=where.stepsize(1)) {
00355 for (register int i=lower(0); i<=upper(0); i+=where.stepsize(0))
00356 ( comm_service::log() << "[" << i << "," << j << "]="
00357 << gd(i,j)(0) << " " ).flush();
00358 }
00359 #endif
00360 }
00361
00362 void debug_print_ldv(ld_vec_grid_data_type &gd, const BBox &where) {
00363 #ifdef DEBUG_PRINT
00364 int lower = std::max(where.lower(0),gd.lower(0));
00365 int upper = std::min(where.upper(0),gd.upper(0));
00366 for (register int i=lower; i<=upper; i+=where.stepsize(0))
00367 ( comm_service::log() << "[" << i << "]="
00368 << gd(i)(0) << " " ).flush();
00369 ( comm_service::log() << "\n" ).flush();
00370 #endif
00371 }
00372 void debug_print_ldv(ld_vec_grid_data_type &gd) {
00373 debug_print_ldv(gd, gd.bbox());
00374 }
00375
00376 void debug_print_ld(ld_fixup_grid_data_type &gd, const BBox &where) {
00377 #ifdef DEBUG_PRINT
00378 int lower = std::max(where.lower(0),gd.lower(0));
00379 int upper = std::min(where.upper(0),gd.upper(0));
00380 for (register int i=lower; i<=upper; i+=where.stepsize(0))
00381 ( comm_service::log() << "[" << i << "]="
00382 << gd(i)(0) << " " ).flush();
00383 ( comm_service::log() << "\n" ).flush();
00384 #endif
00385 }
00386 void debug_print_ld(ld_fixup_grid_data_type &gd) {
00387 debug_print_ld(gd, gd.bbox());
00388 }
00389 };
00390
00391
00392 #endif