Loading...
Searching...
No Matches
ImpulseAvgOp.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25 */
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31#ifndef ImpulseAvgOp_H
32#define ImpulseAvgOp_H
33
34#include <drain/UniTuple.h>
35
36
37//#include "drain/image/SegmentProber.h"
38
39#include "ImpulseResponseOp.h"
40
41namespace drain
42{
43namespace image
44{
45
46template <class T>
47class Decay2 : public UniTuple<T,2> {
48
49public:
50
51 double & forward;
52 double & backward;
53
54 Decay2(double decay = 1.0) : forward(this->next()), backward(this->next()) {
55 this->fill(decay);
56 }
57
58 // Reference
59 template <size_t N>
60 Decay2(drain::UniTuple<T,N> & tuple, size_t i) : drain::UniTuple<T,2>(tuple, i), forward(this->next()), backward(this->next()){
61 }
62};
63
64template <class T>
65struct Decay4 : public drain::UniTuple<T,4> {
66
67 Decay2<T> horz;
68 Decay2<T> vert;
69
70 Decay4(T decay=0.5) : horz(this->tuple(), 0), vert(this->tuple(), 2) {
71 this->fill(decay);
72 }
73
74
75 Decay4(const Decay4 & r) : horz(this->tuple(), 0), vert(this->tuple(), 2){
76 this->assign(r);
77 };
78
79 Decay4 & operator=(const Decay4<T> & decay){
80 this->set(decay.tuple());
81 return *this;
82 }
83
84};
85
86
87// IMPLEMENTATIONS
88
89
90struct ImpulseAvgConf : public BeanLike {
91
92
93 inline
94 ImpulseAvgConf() : BeanLike(__FUNCTION__, "Infinite-impulse response type spreading"), decays(0.75){
95 this->parameters.link("decayHorz", decays.horz.tuple()).fillArray = true;
96 this->parameters.link("decayVert", decays.vert.tuple()).fillArray = true;
97 // option:
98 // this->parameters.link("decay", decays.tuple()); //.fillArray = true;
99 };
100
101 inline
102 ImpulseAvgConf(const ImpulseAvgConf & conf) :
103 BeanLike(conf), decays(0.75){
104 this->parameters.link("decayHorz", decays.horz.tuple()).fillArray = true;
105 this->parameters.link("decayVert", decays.vert.tuple()).fillArray = true;
106 // consider copyStruct
107 // option:
108 // this->parameters.link("decay", decays.tuple()); //.fillArray = true;
109 };
110
111 Decay4<double> decays;
112
113};
114
115
117
132class ImpulseAvg : public ImpulseBucket<ImpulseAvgConf> {
133
134public:
135
136
137 inline
138 ImpulseAvg(){
139
140 };
141
142 inline
143 ImpulseAvg(const ImpulseAvg & avg){
144 decays = avg.decays;
145 }
146
147 inline
148 ImpulseAvg(const ImpulseAvgConf & conf){
149 decays = conf.decays;
150 }
151
152 virtual
153 void init(const Channel & src, bool horizontal);
154
155 virtual
156 void reset();
157
159 virtual
160 void addLeft(int i, double value, double weight);
161
163 virtual
164 void addRight(int i, double value, double weight);
165
167 virtual
168 void addDown(int i, double value, double weight);
169
171 virtual
172 void addUp(int i, double value, double weight);
173
174
175 virtual
176 double get(int i);
177
178 virtual
179 double getWeight(int i);
180
181
182protected:
183
184private:
185
186 drain::ValueScaling scaling;
187
189 struct entry {
190
191 double x;
192 double weight;
193
194 inline void set(double value, double weight){
195 this->x = value;
196 this->weight = weight;
197 }
198
199 };
200
201 /*
202 * \param curr
203 * \param prev
204 * \param
205 */
206 void update(entry & curr, entry & acc, double decay);
207
208 struct entryPair {
209 entry forward;
210 entry backward;
211 };
212
213 // typedef std::pair<entry,entry> entryPair;
214 typedef std::vector<entryPair> container;
215
216 // Horz or vert
217 container line;
218
219 // entry e;
220 entryPair accumulated; // utility
221
222
223};
224
225
226
227} // image::
228
229} // drain::
230
231
232#endif /* ImpulseResponse_H_ */
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
map_t parameters
Parameters (name -> linked variable), typically linked to member variables of the derived class.
Definition BeanLike.h:313
void fill(T i)
Set all the elements to i.
Definition TupleBase.h:315
Tuple of N elements of type T.
Definition UniTuple.h:65
Linear scaling and physical range for image intensities.
Definition ValueScaling.h:63
Image with static geometry.
Definition ImageChannel.h:58
Definition ImpulseAvgOp.h:47
Averaging operator. A simple example implementation of ImpulseBucket.
Definition ImpulseAvgOp.h:132
virtual void addUp(int i, double value, double weight)
Accumulate encoded value.
Definition ImpulseAvgOp.cpp:105
virtual void init(const Channel &src, bool horizontal)
Adapt to input geometry, type, and scaling.
Definition ImpulseAvgOp.cpp:41
virtual double getWeight(int i)
Return weight at position i.
Definition ImpulseAvgOp.cpp:114
virtual void addRight(int i, double value, double weight)
Accumulate encoded value.
Definition ImpulseAvgOp.cpp:93
virtual double get(int i)
Return natural (not encoded) value at position i.
Definition ImpulseAvgOp.cpp:119
virtual void addLeft(int i, double value, double weight)
Accumulate encoded value.
Definition ImpulseAvgOp.cpp:87
virtual void addDown(int i, double value, double weight)
Accumulate encoded value.
Definition ImpulseAvgOp.cpp:99
virtual void reset()
Clear statistics before traversing each row or column.
Definition ImpulseAvgOp.cpp:55
Definition ImpulseResponseOp.h:55
Definition Data.h:1473
Definition ImpulseAvgOp.h:65
Definition ImpulseAvgOp.h:90