casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MedianSlider.h
Go to the documentation of this file.
1 //# MedianSlider.h: Optimized sliding-median computator
2 //# Copyright (C) 2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef SCIMATH_MEDIANSLIDER_H
29 #define SCIMATH_MEDIANSLIDER_H
30 
31 //#! Includes go here
32 
33 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 
40 // <summary>
41 // Class to compute sliding median
42 // </summary>
43 
44 // <use visibility=export>
45 
46 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
47 // </reviewed>
48 
49 // <synopsis>
50 // MedianSlider is a class for efficient computing of sliding medians.
51 // </synopsis>
52 //
53 // <example>
54 // </example>
55 //
56 // <motivation>
57 // Flagging Agents make extended use of sliding medians.
58 // </motivation>
59 //
60 // <todo asof="yyyy/mm/dd">
61 // <li> think about a 2D sliding median
62 // </todo>
63 
65 {
66 public:
67 
68  MedianSlider ();
69  MedianSlider ( int halfwin );
70  MedianSlider ( const MedianSlider &other );
71  ~MedianSlider ();
72  MedianSlider & operator = ( const MedianSlider &other );
73 
74  void cleanup ();
75 
76 // Adds a datum to the slider. Once the window is full, newer values will
77 // push out older values. Returns the new median value.
78 // If flag is set to true, adds a "flagged" datum, one which takes
79 // up space in the window but is skipped during median computations.
80  Float add ( Float d,Bool flag=False );
81 // Adds a flagged datum
82  Float add () { return add(0,True); }
83 // Adds N flagged datums
84  Float next ( uInt n=1 );
85 // Adds several datums at once (with corresponding flags)
86  Float add ( const Vector<Float> &d,const Vector<Bool> &flag );
87 // Adds several non-flagged datums at once
88  Float add ( const Vector<Float> &d );
89 
90 // Returns the number of values currently in the window. This is less
91 // than the window width initially.
92 // Int size ();
93 
94 // Returns the number of non-flagged values in window
95  Int nval ();
96 
97 // Returns the current median value
98  Float median ();
99 
100 // Returns a previous value (from n steps ago) from the sliding window
101  Float prevVal ( uInt n,Bool &flag );
102 
103 // Returns value from midpoint (center) of window, possibly with flag
104  Float midpoint ( Bool &flag );
106  { Bool dum; return midpoint(dum); }
107 
108 // Returns the difference between the current median and the value
109 // at window center. Optionally, also returns flag of median center
110  Float diff ( Bool &flag ) { return midpoint(flag) - median(); }
112  { Bool dum; return diff(dum); }
113 
114 // returns total memory usage (in bytes) for a given halfwin size
115  static size_t objsize ( int halfwin )
116  { return sizeof(MedianSlider)+(sizeof(Float)+sizeof(uInt)+sizeof(Bool))*(halfwin*2+1); }
117 
118 // For testing purposes only: verifies current value of median.
119 // Throws an exception if it fails.
120  Bool assure ();
121 
122 private:
123 
129 
130 };
131 
132 
134 {
135  return nind;
136 }
137 
139 {
140  if( !nind )
141  return 0;
142  return nind%2 ? buf[ index[nind/2] ]
143  : ( buf[ index[nind/2-1] ] + buf[ index[nind/2] ] )/2;
144 // return nind%2 ? buf[ index[nind/2] ]
145 // : buf[ index[nind/2-1] ];
146 }
147 
149 {
150  return prevVal(halfwin+1,flag);
151 }
152 
153 
154 
155 } //# NAMESPACE CASACORE - END
156 
157 #endif
static size_t objsize(int halfwin)
returns total memory usage (in bytes) for a given halfwin size
Definition: MedianSlider.h:115
Float diff(Bool &flag)
Returns the difference between the current median and the value at window center. ...
Definition: MedianSlider.h:110
int Int
Definition: aipstype.h:50
Int nval()
Returns the number of values currently in the window.
Definition: MedianSlider.h:133
Float add()
Adds a flagged datum.
Definition: MedianSlider.h:82
Float prevVal(uInt n, Bool &flag)
Returns a previous value (from n steps ago) from the sliding window.
Class to compute sliding median.
Definition: MedianSlider.h:64
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool assure()
For testing purposes only: verifies current value of median.
float Float
Definition: aipstype.h:54
const Bool False
Definition: aipstype.h:44
Float next(uInt n=1)
Adds N flagged datums.
MedianSlider & operator=(const MedianSlider &other)
Float median()
Returns the current median value.
Definition: MedianSlider.h:138
const Bool True
Definition: aipstype.h:43
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42