source: trunk/src/MathUtils.cc@ 109

Last change on this file since 109 was 81, checked in by mar637, 20 years ago

updated to use CASA include paths and .h guards.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1//#---------------------------------------------------------------------------
2//# MathUtilities.cc: General math operations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# Malte Marquarding, ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31
32#include <casa/Arrays/Vector.h>
33#include <casa/Arrays/VectorSTLIterator.h>
34
35template <class T>
36void hanning(Vector<T>& out, Vector<Bool>& outmask,
37 const Vector<T>& in, const Vector<Bool>& mask,
38 Bool relaxed, Bool ignoreOther) {
39
40 Vector< Vector<T> > weights(8);
41 Vector<Float> vals(3);
42 vals = 0.0;weights[0] = vals;// FFF
43 vals[0] = 1.0; vals[1] = 0.0; vals[2] = 0.0; weights[1] = vals;// TFF
44 vals[0] = 0.0; vals[1] = 1.0; vals[2] = 0.0; weights[2] = vals;// FTF
45 vals[0] = 1.0/3.0; vals[1] = 2.0/3.0; vals[2] = 0.0; weights[3] = vals;// TTF
46 vals[0] = 0.0; vals[1] = 0.0; vals[2] = 1.0;weights[4] = vals;// FFT
47 vals[0] = 0.5; vals[1] = 0.0; vals[2] = 0.5; weights[5] = vals;// TFT
48 vals[0] = 0.0; vals[1] = 2.0/3.0; vals[2] = 1.0/3.0; weights[6] = vals;// FTT
49 vals[0] = 0.25; vals[1] = 0.5; vals[2] = 0.25; weights[7] = vals;// TTT
50 // Chris' case
51 Vector<Bool> weighted(8);
52 if (relaxed) {
53 weighted = False;
54 weighted[7] = True;
55
56 } else {
57 weighted = True;
58 weighted[0] = False;
59 }
60
61 out.resize(in.nelements());
62 outmask.resize(mask.nelements());
63
64 // make special case for first and last
65 /// ...here
66 // loop from 1..n-2
67 uInt i = 1;
68 VectorSTLIterator<T> outit(out);
69 outit++;
70 VectorSTLIterator<Bool> outmit(outmask);outmit++;
71 uInt m;Vector<T>* w;
72 for (VectorSTLIterator<T> it = outit;it != out.end()-1;++it) {
73
74 m = mask[i-1] + 2*mask[i] + 4*mask[i+1];
75 w = &(weights[m]);
76 if (weighted[m]) {
77 (*it) = (*w)[0]*in[i-1] + (*w)[1]*in[i] + (*w)[2]*in[i+1];
78 (*outmit) = True;
79 } else { // mask it
80 (*outmit) = False;
81 }
82 ++i;
83 ++outmit;
84 }
85}
Note: See TracBrowser for help on using the repository browser.