00001 #ifndef __TSOPT_GRIDPP_OPS__
00002 #define __TSOPT_GRIDPP_OPS__
00003
00004 #include "rn.hh"
00005 #include "op.hh"
00006 #include "productspace.hh"
00007 #include "mpiserialfo.hh"
00008
00009 #ifdef IWAVE_USE_MPI
00010 #include "mpigridpp.hh"
00011 #else
00012 #include "gridpp.hh"
00013 #endif
00014
00015
00016
00017 using RVL::ScalarFieldTraits;
00018 using RVL::SpaceTest;
00019 using RVL::Operator;
00020 using RVL::LinearOp;
00021 using RVL::Space;
00022 using RVL::ProductSpace;
00023 using RVL::Vector;
00024 using RVL::Components;
00025 using RVL::ProtectedDivision;
00026 using RVL::RnArray;
00027 using RVL::RVLScale;
00028
00031 template<typename Scalar>
00032 inline Scalar window(Scalar a, Scalar b, Scalar w, Scalar x) {
00033 return min(min(ScalarFieldTraits<Scalar>::One(),max(ScalarFieldTraits<Scalar>::Zero(),(x-a)/w)),min(ScalarFieldTraits<Scalar>::One(),max(ScalarFieldTraits<Scalar>::Zero(),(b-x)/w)));
00034 }
00035
00036 namespace TSOpt {
00037
00038 using RVL::BinaryLocalFunctionObject;
00039 using RVL::RVLException;
00040 using RVL::ContentPackage;
00041 using RVL::LocalDataContainer;
00042
00043
00049 class GridMaskFO: public BinaryLocalFunctionObject<float> {
00050
00051 private:
00052
00053 IPNT siw;
00054 IPNT eiw;
00055 RPNT width;
00056 bool bias;
00057 GridMaskFO();
00058
00059 public:
00060
00061 GridMaskFO(IPNT const & _siw, IPNT const & _eiw, RPNT const & _width, bool _bias=false)
00062 : bias(_bias){
00063 IASN(siw,_siw);
00064 IASN(eiw,_eiw);
00065 RASN(width,_width);
00066 }
00067
00068 GridMaskFO(GridMaskFO const & f)
00069 : bias(f.bias){
00070 IASN(siw,f.siw);
00071 IASN(eiw,f.eiw);
00072 RASN(width,f.width);
00073 }
00074
00075 using RVL::LocalEvaluation<float>::operator();
00076 void operator()(LocalDataContainer<float> &,
00077 LocalDataContainer<float> const &);
00078
00079 string getName() const { string tmp = "GridMaskFO"; return tmp; }
00080
00081 };
00082
00091 class GridMaskOp: public Operator<float> {
00092
00093 private:
00094
00095 Space<float> const & dom;
00096 Vector<float> const & bg;
00097 IPNT siw;
00098 IPNT eiw;
00099 RPNT width;
00100 GridMaskOp();
00101
00102 protected:
00103
00104 void apply(Vector<float> const &,
00105 Vector<float> &) const;
00106 void applyDeriv(Vector<float> const &,
00107 Vector<float> const &,
00108 Vector<float> &) const;
00109 void applyAdjDeriv(Vector<float> const &,
00110 Vector<float> const &,
00111 Vector<float> &) const;
00112 void applyDeriv2(const Vector<float> &,
00113 const Vector<float> &,
00114 const Vector<float> &,
00115 Vector<float> & dy) const { dy.zero(); }
00116 void applyAdjDeriv2(const Vector<float> &,
00117 const Vector<float> &,
00118 const Vector<float> &,
00119 Vector<float> & dx1) const { dx1.zero(); }
00120
00121 Operator<float> * clone() const { return new GridMaskOp(*this); }
00122
00123 public:
00124
00128 GridMaskOp(Space<float> const & _dom,
00129 Vector<float> const & _bg,
00130 RPNT const & sw = RPNT_0, RPNT const & ew = RPNT_0,
00131 RPNT const & width = RPNT_1);
00132
00134 GridMaskOp(GridMaskOp const & op)
00135 : dom(op.dom), bg(op.bg) {
00136 IASN(siw,op.siw);
00137 IASN(eiw,op.eiw);
00138 RASN(width,op.width);
00139 }
00140
00141 ~GridMaskOp() {}
00142
00143 Space<float> const & getDomain() const { return dom; }
00144 Space<float> const & getRange() const { return bg.getSpace(); }
00145
00146 ostream & write(ostream & str) const;
00147 };
00148
00154 class GridWindowFO: public BinaryLocalFunctionObject<float> {
00155
00156 private:
00157
00158 IPNT iw;
00159 bool bias;
00160
00161 GridWindowFO();
00162
00163 public:
00164
00165 GridWindowFO(IPNT const & _iw, bool _bias=false)
00166 : bias(_bias) {
00167 IASN(iw,_iw);
00168 }
00169
00170 GridWindowFO(GridWindowFO const & f)
00171 : bias(f.bias) {
00172 IASN(iw,f.iw);
00173 }
00174
00175 using RVL::LocalEvaluation<float>::operator();
00176 void operator()(LocalDataContainer<float> & x,
00177 LocalDataContainer<float> const & y);
00178
00179 string getName() const { string tmp = "GridWindoFO"; return tmp; }
00180
00181 };
00182
00192 class GridWindowOp: public Operator<float> {
00193
00194 private:
00195
00196 std::shared_ptr<Space<float> > dom;
00197 std::shared_ptr<Vector<float> > bg;
00198 IPNT iw;
00199 void initialize(RPNT const w);
00200 GridWindowOp();
00201
00202 protected:
00203
00204 void apply(Vector<float> const &,
00205 Vector<float> &) const;
00206 void applyDeriv(Vector<float> const &,
00207 Vector<float> const &,
00208 Vector<float> &) const;
00209 void applyAdjDeriv(Vector<float> const &,
00210 Vector<float> const &,
00211 Vector<float> &) const;
00212 void applyDeriv2(const Vector<float> &,
00213 const Vector<float> &,
00214 const Vector<float> &,
00215 Vector<float> & dy) const { dy.zero(); }
00216 void applyAdjDeriv2(const Vector<float> &,
00217 const Vector<float> &,
00218 const Vector<float> &,
00219 Vector<float> & dx1) const { dx1.zero(); }
00220
00221 Operator<float> * clone() const { return new GridWindowOp(*this); }
00222
00223 public:
00224
00227 GridWindowOp(Space<float> const & _dom,
00228 Vector<float> const & _bg,
00229 RPNT const sw = RPNT_0);
00230
00236 GridWindowOp(Space<float> const & _dom,
00237 shared_ptr<RVL::Vector<float> > const _bg,
00238 RPNT const sw = RPNT_0);
00239
00241 GridWindowOp(GridWindowOp const & op)
00242 : dom(op.dom), bg(op.bg) {
00243 IASN(iw,op.iw);
00244 }
00245
00246 ~GridWindowOp() {}
00247
00248 Space<float> const & getDomain() const { return *dom; }
00249 Space<float> const & getRange() const { return bg->getSpace(); }
00250
00251 ostream & write(ostream & str) const;
00252 };
00253
00254 class GridFwdDerivFO: public BinaryLocalFunctionObject<float> {
00255
00256 private:
00257
00258 int dir;
00259 float fac;
00260
00261 GridFwdDerivFO();
00262
00263 public:
00264 GridFwdDerivFO(int _dir, float _fac)
00265 : dir(_dir), fac(_fac) {}
00266 GridFwdDerivFO(GridFwdDerivFO const & a)
00267 : dir(a.dir), fac(a.fac) {}
00268
00269 using RVL::LocalEvaluation<float>::operator();
00270 void operator()(LocalDataContainer<float> & x,
00271 LocalDataContainer<float> const & y);
00272
00273 string getName() const { string tmp = "GridFwdDerivFO"; return tmp; }
00274 };
00275
00276 class GridAdjDerivFO: public BinaryLocalFunctionObject<float> {
00277
00278 private:
00279
00280 int dir;
00281 float fac;
00282
00283 GridAdjDerivFO();
00284
00285 public:
00286 GridAdjDerivFO(int _dir, float _fac)
00287 : dir(_dir), fac(_fac) {}
00288 GridAdjDerivFO(GridAdjDerivFO const & a)
00289 : dir(a.dir), fac(a.fac) {}
00290
00291 using RVL::LocalEvaluation<float>::operator();
00292 void operator()(LocalDataContainer<float> & x,
00293 LocalDataContainer<float> const & y);
00294
00295 string getName() const { string tmp = "GridAdjDerivFO"; return tmp; }
00296 };
00297
00298 class GridDerivOp: public LinearOp<float> {
00299
00300 private:
00301
00302 int dir;
00303 std::vector<float> fac;
00304 Space<float> const & dom;
00305
00306 GridDerivOp();
00307
00308 protected:
00309
00310 void apply(Vector<float> const & x,
00311 Vector<float> & y) const;
00312 void applyAdj(Vector<float> const & x,
00313 Vector<float> & y) const;
00314
00315 Operator<float> * clone() const { return new GridDerivOp(*this); }
00316
00317 public:
00318
00322 GridDerivOp(Space<float> const & _dom, int _dir, float scale = REAL_ONE);
00323
00325 GridDerivOp(GridDerivOp const & op);
00326
00327 ~GridDerivOp() {}
00328
00329 Space<float> const & getDomain() const { return dom; }
00330 Space<float> const & getRange() const { return dom; }
00331
00332 ostream & write(ostream & str) const;
00333 };
00334
00335 class GridFwdExtendFO: public BinaryLocalFunctionObject<float> {
00336
00337 private:
00338
00339 int n_ext;
00340 bool ext;
00341 float fac;
00342
00343 GridFwdExtendFO();
00344
00345 public:
00346 GridFwdExtendFO(int _n_ext, bool _ext, float _fac)
00347 : n_ext(_n_ext), ext(_ext), fac(_fac) {}
00348 GridFwdExtendFO(GridFwdExtendFO const & a)
00349 : n_ext(a.n_ext), ext(a.ext), fac(a.fac) {}
00350
00351 using RVL::LocalEvaluation<float>::operator();
00352 void operator()(LocalDataContainer<float> & x,
00353 LocalDataContainer<float> const & y);
00354
00355 string getName() const { string tmp = "GridFwdExtendFO"; return tmp; }
00356 };
00357
00358 class GridAdjExtendFO: public BinaryLocalFunctionObject<float> {
00359
00360 private:
00361
00362 int n_ext;
00363 bool ext;
00364 float fac;
00365
00366 GridAdjExtendFO();
00367
00368 public:
00369
00370 GridAdjExtendFO(int _n_ext, bool _ext, float _fac)
00371 : n_ext(_n_ext), ext(_ext), fac(_fac) {}
00372 GridAdjExtendFO(GridAdjExtendFO const & a)
00373 : n_ext(a.n_ext), ext(a.ext), fac(a.fac) {}
00374
00375 using RVL::LocalEvaluation<float>::operator();
00376 void operator()(LocalDataContainer<float> & x,
00377 LocalDataContainer<float> const & y);
00378
00379 string getName() const { string tmp = "GridAdjExtendFO"; return tmp; }
00380 };
00381
00382 class GridExtendOp: public LinearOp<float> {
00383
00384 private:
00385
00386 Space<float> const & dom;
00387 Space<float> const & rng;
00388 std::vector<int> n_ext;
00389 std::vector<bool> ext;
00390 std::vector<float> fac;
00391
00392 GridExtendOp();
00393
00394 protected:
00395
00396 void apply(Vector<float> const & x,
00397 Vector<float> & y) const;
00398 void applyAdj(Vector<float> const & x,
00399 Vector<float> & y) const;
00400
00401 Operator<float> * clone() const { return new GridExtendOp(*this); }
00402
00403 public:
00404
00408 GridExtendOp(Space<float> const & _dom, Space<float> const & _rng);
00409
00411 GridExtendOp(GridExtendOp const & op);
00412
00413 ~GridExtendOp() {}
00414
00415 Space<float> const & getDomain() const { return dom; }
00416 Space<float> const & getRange() const { return rng; }
00417
00418 ostream & write(ostream & str) const;
00419 };
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 }
00528 #endif