ProtoVR.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //# ProtoVR.h: Definition of the ProtoVR 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_CUAWVISRESAMPLER_H
00030 #define SYNTHESIS_CUAWVISRESAMPLER_H
00031 
00032 #include <synthesis/TransformMachines/CFStore.h>
00033 #include <synthesis/TransformMachines/VBStore.h>
00034 #include <synthesis/TransformMachines/VisibilityResampler.h>
00035 #include <msvis/MSVis/VisBuffer.h>
00036 #include <casa/Arrays/Array.h>
00037 #include <casa/Arrays/Vector.h>
00038 
00039 #include <casa/Logging/LogIO.h>
00040 #include <casa/Logging/LogSink.h>
00041 #include <casa/Logging/LogMessage.h>
00042 
00043 namespace casa { //# NAMESPACE CASA - BEGIN
00044   class ProtoVR: public VisibilityResampler
00045   {
00046   public: 
00047     ProtoVR(): VisibilityResampler(),
00048                       cached_phaseGrad_p(),
00049                       cached_PointingOffset_p()
00050     {cached_PointingOffset_p.resize(2);cached_PointingOffset_p=-1000.0;runTimeG_p=runTimeDG_p=0.0;};
00051     //    ProtoVR(const CFStore& cfs): VisibilityResampler(cfs)      {}
00052     virtual ~ProtoVR()                                         {};
00053 
00054     virtual VisibilityResamplerBase* clone()
00055     {return new ProtoVR(*this);}
00056     
00057     // ProtoVR(const ProtoVR& other): VisibilityResampler(other),cfMap_p(), conjCFMap_p()
00058     // {copy(other);}
00059 
00060     virtual void copyMaps(const ProtoVR& other)
00061     {setCFMaps(other.cfMap_p, other.conjCFMap_p);}
00062     virtual void copy(const VisibilityResamplerBase& other) 
00063     {
00064       VisibilityResampler::copy(other);
00065       // const Vector<Int> cfmap=other.getCFMap();
00066       // const Vector<Int> conjcfmap = other.getConjCFMap();
00067 
00068       // setCFMaps(cfmap,conjcfmap);
00069     }
00070 
00071     virtual void copy(const ProtoVR& other) 
00072     {
00073       VisibilityResampler::copy(other);
00074       SynthesisUtils::SETVEC(cached_phaseGrad_p, other.cached_phaseGrad_p);
00075       SynthesisUtils::SETVEC(cached_PointingOffset_p, other.cached_PointingOffset_p);
00076     }
00077 
00078     ProtoVR& operator=(const ProtoVR& other) 
00079     {
00080       copy(other);      
00081       SynthesisUtils::SETVEC(cached_phaseGrad_p, other.cached_phaseGrad_p);
00082       SynthesisUtils::SETVEC(cached_PointingOffset_p, other.cached_PointingOffset_p);
00083       return *this;
00084     }
00085 
00086     virtual void setCFMaps(const Vector<Int>& cfMap, const Vector<Int>& conjCFMap)
00087     {SETVEC(cfMap_p,cfMap);SETVEC(conjCFMap_p,conjCFMap);}
00088 
00089     // virtual void setConvFunc(const CFStore& cfs) {convFuncStore_p = cfs;};
00090     //
00091     //------------------------------------------------------------------------------
00092     //
00093     // Re-sample the griddedData on the VisBuffer (a.k.a gridding).
00094     //
00095     // In this class, these just call the private templated version.
00096     // The first variant grids onto a double precision grid while the
00097     // second one does it on a single precision grid.
00098     //
00099     // Note that the following calls allow using any CFStore object
00100     // for gridding while de-gridding uses the internal
00101     // convFuncStore_p object.
00102     // virtual void DataToGrid(Array<DComplex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00103     //                      const Bool& dopsf, CFStore& cfs)
00104     // {DataToGridImpl_p(griddedData, vbs, sumwt,dopsf,cfs);}
00105 
00106     // virtual void DataToGrid(Array<Complex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00107     //                      const Bool& dopsf, CFStore& cfs)
00108     // {DataToGridImpl_p(griddedData, vbs, sumwt,dopsf,cfs);}
00109     //
00110     // Simulating defaulting CFStore arguemnt in the above calls to convFuncStore_p
00111     //
00112 
00113     //***TEMP REMOVAL OF DComplex gridder*****
00114 
00115     virtual void DataToGrid(Array<DComplex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00116                             const Bool& dopsf 
00117                             // Int& rowBegin, Int& rowEnd, 
00118                             // Int& startChan, Int& endChan, 
00119                             // Int& nDataPol, Int& nDataChan, Int& vbSpw,
00120                             // Bool useConjFreqCF=False
00121                             )
00122     {
00123       Vector<Int> gridShape=griddedData.shape().asVector();
00124       Bool Dummy;
00125       DComplex *store=griddedData.getStorage(Dummy);
00126       Int* shp=gridShape.getStorage(Dummy);
00127       DataToGridImpl_p(store, shp, vbs, sumwt,dopsf
00128                        // , rowBegin, rowEnd,
00129                        // startChan, endChan, nDataPol, nDataChan, vbSpw,useConjFreqCF
00130                        );}
00131 
00132     virtual void DataToGrid(Array<Complex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00133                             const Bool& dopsf
00134                             // , Int& rowBegin, Int& rowEnd, 
00135                             // Int& startChan, Int& endChan, 
00136                             // Int& nDataPol, Int& nDataChan, Int& vbSpw,
00137                             // Bool useConjFreqCF=False
00138                             )
00139     {
00140       Vector<Int> gridShape=griddedData.shape().asVector();
00141       Bool Dummy;
00142       Complex *store=griddedData.getStorage(Dummy);
00143       Int* shp=gridShape.getStorage(Dummy);
00144       DataToGridImpl_p(store, shp,vbs, sumwt,dopsf
00145                       //  , rowBegin, rowEnd,
00146                       // startChan, endChan, nDataPol, nDataChan, vbSpw,useConjFreqCF
00147                        );}
00148 
00149     //
00150     //------------------------------------------------------------------------------
00151     //
00152     // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding)
00153     //
00154     virtual void GridToData(VBStore& vbs,const Array<Complex>& griddedData); 
00155     //    virtual void GridToData(VBStore& vbs, Array<Complex>& griddedData); 
00156   protected:
00157     virtual Complex getConvFuncVal(const Cube<Double>& convFunc, const Matrix<Double>& uvw, 
00158                                    const Int& irow, const Vector<Int>& pixel)
00159     {
00160       (void)uvw; (void)irow;return convFunc(pixel[0],pixel[1],pixel[2]);
00161     }
00162     Complex getCFArea(Complex* __restrict__& convFuncV, Double& wVal,
00163                       Vector<Int>& scaledSupport, Vector<Float>& scaledSampling,
00164                       Vector<Double>& off,
00165                       Vector<Int>& convOrigin, Vector<Int>& cfShape,
00166                       Double& sinDPA, Double& cosDPA);
00167 
00168   // template <class T>
00169   // Complex accumulateOnGrid(Array<T>& grid, Complex* __restrict__& convFuncV, 
00170   //                       Complex& nvalue,
00171   //                       Double& wVal, Vector<Int>& scaledSupport, 
00172   //                       Vector<Float>& scaledSampling, Vector<Double>& off,
00173   //                       Vector<Int>& convOrigin, Vector<Int>& cfShape,
00174   //                       Vector<Int>& loc, Vector<Int>& igrdpos, 
00175   //                       Double& sinDPA, Double& cosDPA,
00176   //                       Bool& finitePointingOffset, Bool dopsf);
00177   template <class T>
00178   void XInnerLoop(const Int *scaleSupport, const Float* scaledSampling,
00179                   const Double* off,
00180                   const Int* loc, Complex& cfArea,  
00181                   const Int * __restrict__ iGrdPosPtr,
00182                   Complex *__restrict__& convFuncV,
00183                   const Int* convOrigin,
00184                   Complex& nvalue,
00185                   Double& wVal,
00186                   Bool& /*finitePointingOffset*/,
00187                   Bool& /*doPSFOnly*/,
00188                   T* __restrict__ gridStore,
00189                   Int* iloc,
00190                   Complex& norm,
00191                   Int* igrdpos);
00192 
00193   template <class T>
00194   Complex accumulateOnGrid(T* gridStore,
00195                            const Int* gridInc_p,
00196                            const Complex *cached_phaseGrad_p,
00197                            const Int cachedPhaseGradNX, const Int cachedPhaseGradNY,
00198                            const Complex* convFuncV, 
00199                            const Int *cfInc_p,
00200                            Complex nvalue,Double wVal, 
00201                            Int* scaledSupport_ptr, Float* scaledSampling_ptr, 
00202                            Double* off_ptr, Int* convOrigin_ptr, 
00203                            Int* cfShape, Int* loc_ptr, Int* iGrdpos_ptr,
00204                            Bool finitePointingOffset,
00205                            Bool doPSFOnly);
00206   template <class T>
00207   void accumulateFromGrid(T& nvalue, const T* __restrict__& grid, 
00208                           Vector<Int>& iGrdPos,
00209                           Complex* __restrict__& convFuncV, 
00210                           Double& wVal, Vector<Int>& scaledSupport, 
00211                           Vector<Float>& scaledSampling, Vector<Double>& off,
00212                           Vector<Int>& convOrigin, Vector<Int>& cfShape,
00213                           Vector<Int>& loc, 
00214                           Complex& phasor, 
00215                           Double& sinDPA, Double& cosDPA,
00216                           Bool& finitePointingOffset, 
00217                           Matrix<Complex>& cached_phaseGrad_p);
00218 
00219     virtual void DataToGrid(Array<DComplex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00220                             const Bool& dopsf,Bool useConjFreqCF=False);
00221     virtual void DataToGrid(Array<Complex>& griddedData, VBStore& vbs, Matrix<Double>& sumwt,
00222                             const Bool& dopsf,Bool useConjFreqCF=False);
00223     //
00224     //------------------------------------------------------------------------------
00225     //----------------------------Private parts-------------------------------------
00226     //------------------------------------------------------------------------------
00227     //
00228   private:
00229     // Vector<Double> uvwScale_p, offset_p, dphase_p;
00230     // Vector<Int> chanMap_p, polMap_p;
00231     // CFStore convFuncStore_p;
00232     // //    Int inc0_p, inc1_p, inc2_p, inc3_p;
00233     // Vector<Int> inc_p;
00234     //    Vector<Int> cfMap_p, conjCFMap_p;
00235     Int gridInc_p[4], cfInc_p[4];
00236     Matrix<Complex> cached_phaseGrad_p;
00237     Vector<Double> cached_PointingOffset_p;
00238 
00239     //
00240     // Re-sample the griddedData on the VisBuffer (a.k.a de-gridding).
00241     //
00242     template <class T>
00243     void DataToGridImpl_p(T* gridStore,  Int* gridShape /*4-elements*/,
00244                           VBStore& vbs, 
00245                           Matrix<Double>& sumwt,
00246                           const Bool& dopsf
00247                           // Int& rowBegin, Int& rowEnd,
00248                           // Int& startChan, Int& endChan,
00249                           // Int& nDataPol, Int& nDataChan,
00250                           // Int& vbSpw,
00251                           // const Bool accumCFs
00252                           );
00253     // void DataToGridImpl_p(Array<T>& griddedData, VBStore& vb,  
00254     //                    Matrix<Double>& sumwt,const Bool& dopsf,
00255     //                    Bool /*useConjFreqCF*/);
00256 
00257     void sgrid(Double pos[2], Int loc[3], Double off[3], 
00258                Complex& phasor, const Int& irow, const Matrix<Double>& uvw, 
00259                const Double& dphase, const Double& freq, 
00260                const Double* scale, const Double* offset,
00261                const Float sampling[2]);
00262 
00263     inline Bool onGrid (const Int& nx, const Int& ny, const Int& nw, 
00264                         const Int loc[3], 
00265                         const Int support[2])
00266     {
00267       return (((loc[0]-support[0]) >= 0 ) && ((loc[0]+support[0]) < nx) &&
00268               ((loc[1]-support[1]) >= 0 ) && ((loc[1]+support[1]) < ny) &&
00269               (loc[2] >= 0) && (loc[2] <= nw));
00270     };
00271 
00272     // Array assignment operator in CASACore requires lhs.nelements()
00273     // == 0 or lhs.nelements()=rhs.nelements()
00274     template <class T>
00275     inline void SETVEC(Vector<T>& lhs, const Vector<T>& rhs)
00276     {lhs.resize(rhs.shape()); lhs = rhs;};
00277 
00278 
00279     //
00280     // Internal methods to address a 4D array.  These should ulimately
00281     // moved to a Array4D class in CASACore
00282     //
00283 
00284     // This is called less frequently.  Currently once per VisBuffer
00285     // inline void cacheAxisIncrements(const Vector<Int>& n, Vector<Int>& inc)
00286     // {inc.resize(4);inc[0]=1, inc[1]=inc[0]*n[0], inc[2]=inc[1]*n[1], inc[3]=inc[2]*n[2];(void)n[3];}
00287 
00288 
00289     // The following method is also called from the inner loop, but
00290     // does not use CASA Vector (which are not thread safe, I (SB) am
00291     // told).
00292     // inline Complex getFrom4DArray(const Complex *__restrict__& store,
00293     //                            const Int* iPos, const Int* inc)
00294     // {
00295     //   return *(store+(iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]));
00296     //   //      return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];
00297     // };
00298 
00299     inline Complex getFrom4DArray(const Complex * store,
00300                                   const Int* iPos, const Int inc[4])
00301     {
00302       return *(store+(iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]));
00303       //      return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];
00304     };
00305 
00306     // The following two methods are called in the innermost loop.
00307     inline Complex getFrom4DArray(const Complex *__restrict__& store,
00308                                   const Vector<Int>& iPos, const Vector<Int>& inc)
00309     {
00310       return *(store+(iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]));
00311       //      return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];
00312     };
00313     inline DComplex getFrom4DArray(const DComplex *__restrict__& store,
00314                                   const Vector<Int>& iPos, const Vector<Int>& inc)
00315     {
00316       return *(store+(iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]));
00317       //      return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];
00318     };
00319 
00320     template <class T>
00321     void addTo4DArray(T *store,
00322                       const Int *iPos, const Int* inc, 
00323                       Complex& nvalue, Complex& wt)
00324     {
00325       // T *tmp=store+(iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]);
00326       // *tmp += nvalue*wt;
00327       store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]] += (nvalue*wt);
00328     }
00329 
00330     //
00331     // This rotates the convolution function by rotating the
00332     // co-ordinate system.  For the accuracies already required for
00333     // EVLA and ALMA, this is not useful.  Leaving it hear for now....
00334     //
00335     Bool reindex(const Vector<Int>& in, Vector<Int>& out,
00336                  const Double& sinDPA, const Double& cosDPA,
00337                  const Vector<Int>& Origin, const Vector<Int>& size);
00338 
00339     Complex* getConvFunc_p(Int cfShape[4], VBStore& vbs,
00340                            Double& wVal, Int& fndx, Int& wndx,
00341                            Int **mNdx, Int  **conjMNdx,
00342                            Int& ipol, uInt& mRow);
00343     // Complex* getConvFunc_p(Vector<Int>& cfShape,
00344     //                     VBStorer& vbs,
00345     //                     Double& wVal, Int& fndx, 
00346     //                     Int& wndx,
00347     //                     PolMapType& mNdx, PolMapType& conjMNdx,
00348     //                     Int& ipol, uInt& mRow);
00349 
00350 
00351     void cachePhaseGrad_g(Complex *cached_phaseGrad_p, 
00352                           Int phaseGradNX, Int phaseGradNY,
00353                           Double* cached_PointingOffset_p,
00354                           Double* pointingOffset,
00355                           Int cfShape[4],
00356                           Int convOrigin[4]);
00357     // void cachePhaseGrad_p(const Vector<Double>& pointingOffset,
00358     //                    const Vector<Int>&cfShape,
00359     //                    const Vector<Int>& convOrigin,
00360     //                    const Double& cfRefFreq,
00361     //                    const Double& imRefFreq);
00362   };
00363 }; //# NAMESPACE CASA - END
00364 
00365 #endif // 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1