[932] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | //--------------------------------------------------------------------------
|
---|
| 3 | // File and Version Information:
|
---|
| 4 | // Simple Operations on Maps
|
---|
| 5 | // Description:
|
---|
| 6 | //
|
---|
| 7 | // History (add to end):
|
---|
| 8 | // Sophie April, 2000 - creation
|
---|
| 9 | // code from Reza
|
---|
| 10 | //------------------------------------------------------------------------
|
---|
| 11 | #include "machdefs.h"
|
---|
| 12 | #include <math.h>
|
---|
| 13 | #include "mapoperation.h"
|
---|
| 14 | /*!
|
---|
[1371] | 15 | * \class SOPHYA::MapOperations
|
---|
[932] | 16 | * This class is for simple operations on maps
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | template <class T>
|
---|
| 20 | void MapOperations<T>::sphTosph(PixelMap<T>& in, PixelMap<T>& out)
|
---|
| 21 | // Cette fonction remplit la sphere out a partir de la sphere in
|
---|
| 22 | // Les spheres peuvent etre de type et de pixelisations differentes
|
---|
| 23 | {
|
---|
| 24 | int kin,kout;
|
---|
| 25 | double teta,phi;
|
---|
| 26 |
|
---|
| 27 | int* cnt = new int[out.NbPixels()+1];
|
---|
| 28 | for(kout=0; kout<out.NbPixels(); kout++)
|
---|
| 29 | { cnt[kout] = 0; out(kout) = 0.; }
|
---|
| 30 |
|
---|
| 31 | for(kin=0; kin<in.NbPixels(); kin++) {
|
---|
| 32 | in.PixThetaPhi(kin, teta, phi);
|
---|
| 33 | kout = out.PixIndexSph(teta, phi);
|
---|
| 34 | out(kout) += in(kin);
|
---|
| 35 | cnt[kout] ++;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | double moy, sig, dcn;
|
---|
| 39 | moy = 0.; sig = 0.;
|
---|
| 40 | for(kout=0; kout<out.NbPixels(); kout++) {
|
---|
| 41 | dcn = cnt[kout]; moy += dcn; sig += (dcn*dcn);
|
---|
| 42 | if (cnt[kout] > 0) out(kout) /= dcn;
|
---|
| 43 | else {
|
---|
| 44 | out.PixThetaPhi(kout, teta, phi);
|
---|
| 45 | int pixel = in.PixIndexSph(teta,phi);
|
---|
| 46 | out(kout) = in.PixVal(pixel);
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | moy /= out.NbPixels();
|
---|
| 51 | sig = sig/out.NbPixels() - moy*moy;
|
---|
| 52 | if (sig >= 0.) sig = sqrt(sig);
|
---|
| 53 |
|
---|
| 54 | delete[] cnt;
|
---|
| 55 |
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | template <class T>
|
---|
| 59 | void MapOperations<T>::meanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig)
|
---|
| 60 | {
|
---|
| 61 | gmoy=0.;
|
---|
| 62 | gsig = 0.;
|
---|
| 63 | double valok;
|
---|
| 64 | for(int k=0; k<(int)dbl.Size(); k++) {
|
---|
| 65 | valok = dbl(k);
|
---|
| 66 | gmoy += valok; gsig += valok*valok;
|
---|
| 67 | }
|
---|
| 68 | gmoy /= (double)dbl.Size();
|
---|
| 69 | gsig = gsig/(double)dbl.Size() - gmoy*gmoy;
|
---|
| 70 | if (gsig >= 0.) gsig = sqrt(gsig);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | ///////////////////////////////////////////////////////////////
|
---|
| 74 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 75 | #pragma define_template MapOperations<r_4>
|
---|
| 76 | #pragma define_template MapOperations<r_8>
|
---|
| 77 | #endif
|
---|
| 78 |
|
---|
| 79 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 80 | template class MapOperations<r_4>;
|
---|
[940] | 81 | template class MapOperations<r_8>;
|
---|
[932] | 82 | #endif
|
---|
| 83 |
|
---|