casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisibilityResampler.h
Go to the documentation of this file.
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_VISIBILITYRESAMPLER_H
00030 #define SYNTHESIS_VISIBILITYRESAMPLER_H
00031 
00032 #include <synthesis/TransformMachines/CFStore.h>
00033 #include <synthesis/TransformMachines/Utils.h>
00034 #include <synthesis/TransformMachines/VBStore.h>
00035 #include <synthesis/TransformMachines/VisibilityResamplerBase.h>
00036 #include <synthesis/MSVis/VisBuffer.h>
00037 #include <casa/Arrays/Array.h>
00038 #include <casa/Arrays/Vector.h>
00039 //#include <synthesis/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   class VisibilityResampler: public VisibilityResamplerBase
00047   {
00048   public: 
00049     VisibilityResampler(): VisibilityResamplerBase() {};
00050     //    VisibilityResampler(const CFStore& cfs): VisibilityResamplerBase(cfs) {};
00051     VisibilityResampler(const VisibilityResampler& other):VisibilityResamplerBase()
00052     {copy(other);}
00053 
00054     //    {setConvFunc(cfs);};
00055     virtual ~VisibilityResampler() {};
00056 
00057     //    VisibilityResampler& operator=(const VisibilityResampler& other);
00058 
00059     void copy(const VisibilityResamplerBase& other)
00060     {VisibilityResamplerBase::copy(other);}
00061 
00062     virtual VisibilityResamplerBase* clone() 
00063     {return new VisibilityResampler(*this);}
00064 
00065     virtual void getParams(Vector<Double>& uvwScale, Vector<Double>& offset, Vector<Double>& dphase)
00066     {uvwScale.assign(uvwScale_p); offset.assign(offset_p); dphase.assign(dphase_p);};
00067     virtual void setParams(const Vector<Double>& uvwScale, const Vector<Double>& offset,
00068                            const Vector<Double>& dphase)
00069     {
00070       // SynthesisUtils::SETVEC(uvwScale_p, uvwScale); 
00071       // SynthesisUtils::SETVEC(offset_p, offset);
00072       // SynthesisUtils::SETVEC(dphase_p, dphase);
00073       uvwScale_p.reference(uvwScale);
00074       offset_p.reference(offset);
00075       dphase_p.reference(dphase);
00076     };
00077 
00078     virtual void setMaps(const Vector<Int>& chanMap, const Vector<Int>& polMap)
00079     {
00080       // SynthesisUtils::SETVEC(chanMap_p,chanMap);
00081       // SynthesisUtils::SETVEC(polMap_p,polMap);
00082       chanMap_p.reference(chanMap);
00083       polMap_p.reference(polMap);
00084     }
00085 
00086     virtual void setFreqMaps(const Matrix<Double>& spwChanFreqs, const Matrix<Double>& spwChanConjFreqs)
00087     {
00088       spwChanFreq_p.assign(spwChanFreqs);
00089       spwChanConjFreq_p.assign(spwChanConjFreqs);
00090     }
00091 
00092     virtual void setConvFunc(const CFStore& cfs) 
00093     {
00094       convFuncStore_p = cfs;
00095     };
00096     virtual void setCFMaps(const Vector<Int>& cfMap, const Vector<Int>& conjCFMap) {(void)cfMap;(void)conjCFMap;};
00097     //
00098     //------------------------------------------------------------------------------
00099     //
00100     // Re-sample the griddedData on the VisBuffer (a.k.a gridding).
00101     //
00102     // In this class, these just call the private templated version.
00103     // The first variant grids onto a double precision grid while the
00104     // second one does it on a single precision grid.
00105     //
00106     virtual void DataToGrid(Array<DComplex>& griddedData, VBStore& vbs, 
00107                             Matrix<Double>& sumwt, const Bool& dopsf,
00108                             Bool /*useConjFreqCF*/=False)
00109     {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);}
00110 
00111     virtual void DataToGrid(Array<Complex>& griddedData, VBStore& vbs, 
00112                             Matrix<Double>& sumwt, const Bool& dopsf,
00113                             Bool /*useConjFreqCF*/=False)
00114     {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);}
00115 
00116     //
00117     //------------------------------------------------------------------------------
00118     //
00119     // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding)
00120     //
00121     virtual void GridToData(VBStore& vbs,const Array<Complex>& griddedData); 
00122     //    virtual void GridToData(VBStore& vbs, Array<Complex>& griddedData); 
00123 
00124     virtual void ComputeResiduals(VBStore& vbs);
00125     virtual void setMutex(async::Mutex *mu) {myMutex_p = mu;};
00126 
00127     // Genealogical baggage -- required for the
00128     // MultiThreadedVisibilityResampler -- that everyone else has to
00129     // carray around.
00130     //
00131     // These are no-ops for unithreaded samplers.
00132     //
00133     virtual void init(const Bool& doublePrecision) {(void)doublePrecision;};
00134     virtual void GatherGrids(Array<DComplex>& griddedData, Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;};
00135     virtual void GatherGrids(Array<Complex>& griddedData, Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;};
00136     virtual void initializePutBuffers(const Array<DComplex>& griddedData,
00137                                       const Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;};
00138     virtual void initializePutBuffers(const Array<Complex>& griddedData,
00139                                       const Matrix<Double>& sumwt) {(void)griddedData;(void)sumwt;};
00140 
00141 
00142     virtual void releaseBuffers() {};
00143     //
00144     //------------------------------------------------------------------------------
00145     //----------------------------Private parts-------------------------------------
00146     //------------------------------------------------------------------------------
00147     //
00148   protected:
00149     async::Mutex *myMutex_p;
00150     // Vector<Double> uvwScale_p, offset_p, dphase_p;
00151     // Vector<Int> chanMap_p, polMap_p;
00152     // CFStore convFuncStore_p;
00153     //    Int inc0_p, inc1_p, inc2_p, inc3_p;
00154     //
00155     // Re-sample the griddedData on the VisBuffer (a.k.a de-gridding).
00156     //
00157     template <class T>
00158     void DataToGridImpl_p(Array<T>& griddedData, VBStore& vb,  
00159                           const Bool& dopsf, Matrix<Double>& sumwt,Bool useConjFreqCF=False);
00160 
00161     // void sgrid(Vector<Double>& pos, Vector<Int>& loc, Vector<Int>& off, 
00162     //         Complex& phasor, const Int& irow, const Matrix<Double>& uvw, 
00163     //         const Double& dphase, const Double& freq, 
00164     //         const Vector<Double>& scale, const Vector<Double>& offset,
00165     //         const Vector<Float>& sampling);
00166 
00167     /*
00168     void sgrid(Int& ndim, Double* pos, Int* loc, Int* off, 
00169                Complex& phasor, const Int& irow, const Double* uvw, 
00170                const Double& dphase, const Double& freq, 
00171                const Double* scale, const Double* offset,
00172                const Float* sampling);
00173 
00174     inline Bool onGrid (const Int& nx, const Int& ny, 
00175                         const Vector<Int>& __restrict__ loc, 
00176                         const Vector<Int>& __restrict__ support) __restrict__ 
00177     {
00178       return (((loc(0)-support[0]) >= 0 ) && ((loc(0)+support[0]) < nx) &&
00179               ((loc(1)-support[1]) >= 0 ) && ((loc(1)+support[1]) < ny));
00180     };
00181     inline Bool onGrid (const Int& nx, const Int& ny, 
00182                         const Int& loc0, const Int& loc1, 
00183                         const Int& support) __restrict__ 
00184     {
00185       return (((loc0-support) >= 0 ) && ((loc0+support) < nx) &&
00186               ((loc1-support) >= 0 ) && ((loc1+support) < ny));
00187     };
00188 
00189     // Array assignment operator in CASACore requires lhs.nelements()
00190     // == 0 or lhs.nelements()=rhs.nelements()
00191     // template <class T>
00192     // inline void SETVEC(Vector<T>& lhs, const Vector<T>& rhs)
00193     // {lhs.resize(rhs.shape()); lhs = rhs;};
00194 
00195 
00196     //
00197     // Internal methods to address a 4D array.  These should ulimately
00198     // moved to a Array4D class in CASACore
00199     //
00200 
00201     // This is called less frequently.  Currently once per VisBuffer
00202     inline void cacheAxisIncrements(Int& n0, Int& n1, Int& n2, Int& n3)
00203     {inc0_p=1, inc1_p=inc0_p*n0, inc2_p=inc1_p*n1, inc3_p=inc2_p*n2;(void)n3;}
00204 
00205 
00206     // The following two methods are called in the innermost loop.
00207     inline Complex getFrom4DArray(const Complex* __restrict__ store,
00208                                   const Int* __restrict__ iPos) __restrict__ 
00209     {return store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p];};
00210 
00211     template <class T>
00212     void addTo4DArray(T* __restrict__ store,
00213                       const Int* __restrict__ iPos, 
00214                       Complex& nvalue, Double& wt) __restrict__ 
00215     {store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p] += (nvalue*wt);}
00216     */
00217   };
00218 }; //# NAMESPACE CASA - END
00219 
00220 #endif //