00001 // -*- C++ -*- 00002 //# VisibilityResampler.h: Definition of the VisibilityResampler class 00003 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 //# $Id$ 00028 00029 #ifndef SYNTHESIS_TRANSFORM2_VISIBILITYRESAMPLER_H 00030 #define SYNTHESIS_TRANSFORM2_VISIBILITYRESAMPLER_H 00031 00032 #include <synthesis/TransformMachines2/CFStore.h> 00033 #include <synthesis/TransformMachines2/Utils.h> 00034 #include <synthesis/TransformMachines2/VBStore.h> 00035 #include <synthesis/TransformMachines2/VisibilityResamplerBase.h> 00036 #include <msvis/MSVis/VisBuffer2.h> 00037 #include <casa/Arrays/Array.h> 00038 #include <casa/Arrays/Vector.h> 00039 //#include <msvis/MSVis/AsynchronousTools.h> 00040 00041 #include <casa/Logging/LogIO.h> 00042 #include <casa/Logging/LogSink.h> 00043 #include <casa/Logging/LogMessage.h> 00044 00045 namespace casa { //# NAMESPACE CASA - BEGIN 00046 namespace refim{ 00047 class VisibilityResampler: public VisibilityResamplerBase 00048 { 00049 public: 00050 VisibilityResampler(): VisibilityResamplerBase() {}; 00051 // VisibilityResampler(const CFStore& cfs): VisibilityResamplerBase(cfs) {}; 00052 VisibilityResampler(const VisibilityResampler& other):VisibilityResamplerBase() 00053 {copy(other);} 00054 00055 // {setConvFunc(cfs);}; 00056 virtual ~VisibilityResampler() {}; 00057 00058 // VisibilityResampler& operator=(const VisibilityResampler& other); 00059 00060 void copy(const VisibilityResamplerBase& other) 00061 {VisibilityResamplerBase::copy(other);} 00062 00063 virtual VisibilityResamplerBase* clone() 00064 {return new VisibilityResampler(*this);} 00065 00066 virtual void getParams(Vector<Double>& uvwScale, Vector<Double>& offset, Vector<Double>& dphase) 00067 {uvwScale.assign(uvwScale_p); offset.assign(offset_p); dphase.assign(dphase_p);}; 00068 virtual void setParams(const Vector<Double>& uvwScale, const Vector<Double>& offset, 00069 const Vector<Double>& dphase) 00070 { 00071 // SynthesisUtils::SETVEC(uvwScale_p, uvwScale); 00072 // SynthesisUtils::SETVEC(offset_p, offset); 00073 // SynthesisUtils::SETVEC(dphase_p, dphase); 00074 uvwScale_p.reference(uvwScale); 00075 offset_p.reference(offset); 00076 dphase_p.reference(dphase); 00077 }; 00078 00079 virtual void setMaps(const Vector<Int>& chanMap, const Vector<Int>& polMap) 00080 { 00081 // SynthesisUtils::SETVEC(chanMap_p,chanMap); 00082 // SynthesisUtils::SETVEC(polMap_p,polMap); 00083 chanMap_p.reference(chanMap); 00084 polMap_p.reference(polMap); 00085 } 00086 00087 virtual void setFreqMaps(const Matrix<Double>& spwChanFreqs, const Matrix<Double>& spwChanConjFreqs) 00088 { 00089 spwChanFreq_p.assign(spwChanFreqs); 00090 spwChanConjFreq_p.assign(spwChanConjFreqs); 00091 } 00092 00093 virtual void setConvFunc(const CFStore& cfs) 00094 { 00095 convFuncStore_p = cfs; 00096 }; 00097 virtual void setCFMaps(const Vector<Int>& cfMap, const Vector<Int>& conjCFMap) {(void)cfMap;(void)conjCFMap;}; 00098 // 00099 //------------------------------------------------------------------------------ 00100 // 00101 // Re-sample the griddedData on the VisBuffer (a.k.a gridding). 00102 // 00103 // In this class, these just call the private templated version. 00104 // The first variant grids onto a double precision grid while the 00105 // second one does it on a single precision grid. 00106 // 00107 virtual void DataToGrid(Array<DComplex>& griddedData, VBStore& vbs, 00108 Matrix<Double>& sumwt, const Bool& dopsf, 00109 Bool /*useConjFreqCF*/=False) 00110 {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);} 00111 00112 virtual void DataToGrid(Array<Complex>& griddedData, VBStore& vbs, 00113 Matrix<Double>& sumwt, const Bool& dopsf, 00114 Bool /*useConjFreqCF*/=False) 00115 {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);} 00116 00117 // 00118 //------------------------------------------------------------------------------ 00119 // 00120 // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding) 00121 // 00122 virtual void GridToData(VBStore& vbs,const Array<Complex>& griddedData); 00123 // virtual void GridToData(VBStore& vbs, Array<Complex>& griddedData); 00124 00125 virtual void ComputeResiduals(VBStore& vbs); 00126 virtual void setMutex(async::Mutex *mu) {myMutex_p = mu;}; 00127 00128 // Genealogical baggage -- required for the 00129 // MultiThreadedVisibilityResampler -- that everyone else has to 00130 // carray around. 00131 // 00132 // These are no-ops for unithreaded samplers. 00133 // 00134 virtual void init(const Bool& doublePrecision) {(void)doublePrecision;}; 00135 virtual void GatherGrids(Array<DComplex>& griddedData, Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;}; 00136 virtual void GatherGrids(Array<Complex>& griddedData, Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;}; 00137 virtual void initializePutBuffers(const Array<DComplex>& griddedData, 00138 const Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;}; 00139 virtual void initializePutBuffers(const Array<Complex>& griddedData, 00140 const Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;}; 00141 virtual void initializeDataBuffers(VBStore& vbs) {(void)vbs;}; 00142 00143 00144 virtual void releaseBuffers() {}; 00145 // 00146 //------------------------------------------------------------------------------ 00147 //----------------------------Private parts------------------------------------- 00148 //------------------------------------------------------------------------------ 00149 // 00150 protected: 00151 async::Mutex *myMutex_p; 00152 // Vector<Double> uvwScale_p, offset_p, dphase_p; 00153 // Vector<Int> chanMap_p, polMap_p; 00154 // CFStore convFuncStore_p; 00155 // Int inc0_p, inc1_p, inc2_p, inc3_p; 00156 // 00157 // Re-sample the griddedData on the VisBuffer (a.k.a de-gridding). 00158 // 00159 template <class T> 00160 void DataToGridImpl_p(Array<T>& griddedData, VBStore& vb, 00161 const Bool& dopsf, Matrix<Double>& sumwt,Bool useConjFreqCF=False); 00162 00163 // void sgrid(Vector<Double>& pos, Vector<Int>& loc, Vector<Int>& off, 00164 // Complex& phasor, const Int& irow, const Matrix<Double>& uvw, 00165 // const Double& dphase, const Double& freq, 00166 // const Vector<Double>& scale, const Vector<Double>& offset, 00167 // const Vector<Float>& sampling); 00168 00169 /* 00170 void sgrid(Int& ndim, Double* pos, Int* loc, Int* off, 00171 Complex& phasor, const Int& irow, const Double* uvw, 00172 const Double& dphase, const Double& freq, 00173 const Double* scale, const Double* offset, 00174 const Float* sampling); 00175 00176 inline Bool onGrid (const Int& nx, const Int& ny, 00177 const Vector<Int>& __restrict__ loc, 00178 const Vector<Int>& __restrict__ support) __restrict__ 00179 { 00180 return (((loc(0)-support[0]) >= 0 ) && ((loc(0)+support[0]) < nx) && 00181 ((loc(1)-support[1]) >= 0 ) && ((loc(1)+support[1]) < ny)); 00182 }; 00183 inline Bool onGrid (const Int& nx, const Int& ny, 00184 const Int& loc0, const Int& loc1, 00185 const Int& support) __restrict__ 00186 { 00187 return (((loc0-support) >= 0 ) && ((loc0+support) < nx) && 00188 ((loc1-support) >= 0 ) && ((loc1+support) < ny)); 00189 }; 00190 00191 // Array assignment operator in CASACore requires lhs.nelements() 00192 // == 0 or lhs.nelements()=rhs.nelements() 00193 // template <class T> 00194 // inline void SETVEC(Vector<T>& lhs, const Vector<T>& rhs) 00195 // {lhs.resize(rhs.shape()); lhs = rhs;}; 00196 00197 00198 // 00199 // Internal methods to address a 4D array. These should ulimately 00200 // moved to a Array4D class in CASACore 00201 // 00202 00203 // This is called less frequently. Currently once per VisBuffer 00204 inline void cacheAxisIncrements(Int& n0, Int& n1, Int& n2, Int& n3) 00205 {inc0_p=1, inc1_p=inc0_p*n0, inc2_p=inc1_p*n1, inc3_p=inc2_p*n2;(void)n3;} 00206 00207 00208 // The following two methods are called in the innermost loop. 00209 inline Complex getFrom4DArray(const Complex* __restrict__ store, 00210 const Int* __restrict__ iPos) __restrict__ 00211 {return store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p];}; 00212 00213 template <class T> 00214 void addTo4DArray(T* __restrict__ store, 00215 const Int* __restrict__ iPos, 00216 Complex& nvalue, Double& wt) __restrict__ 00217 {store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p] += (nvalue*wt);} 00218 */ 00219 }; 00220 }; //# NAMESPACE CASA - END 00221 }; 00222 #endif //