RSC  0.17.1
SequenceMonitor.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of RSC project
4  *
5  * Copyright (C) 2011 by Christian Emmerich <cemmeric at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <iostream>
30 #include <sstream>
31 #include <stdexcept>
32 #include <cmath>
33 
34 #include <boost/shared_ptr.hpp>
35 
36 #include "rsc/rscexports.h"
37 
38 namespace rsc {
39 namespace math {
40 
43 
44 class Metric;
45 typedef boost::shared_ptr<Metric> MetricPtr;
46 
53 class RSC_EXPORT Metric {
54 public:
55 
56  virtual ~Metric();
57 
65  virtual double calc(const double* v1, const double* v2,
66  const unsigned int& dim) = 0;
67 
68 };
69 
75 class RSC_EXPORT EuclidDist: public Metric {
76 public:
77 
85  double calc(const double* v1, const double* v2, const unsigned int& dim);
86 
87 };
88 
94 class RSC_EXPORT MaximumDist: public Metric {
95 public:
96 
105  double calc(const double* v1, const double* v2, const unsigned int& dim);
106 
107 };
108 
111 
113 typedef boost::shared_ptr<MetricCondition> MetricConditionPtr;
114 
120 class RSC_EXPORT MetricCondition {
121 public:
122 
123  MetricCondition(MetricPtr m);
124  virtual ~MetricCondition();
125 
134  virtual bool isFulfilled(const double* v1, const double* v2,
135  const unsigned int& dim) = 0;
136 
137 protected:
138  const MetricPtr metric;
139 
140 };
141 
148 class RSC_EXPORT BelowThreshold: public MetricCondition {
149 public:
150 
151  BelowThreshold(const MetricPtr m, const double threshold);
152 
160  bool isFulfilled(const double* v1, const double* v2,
161  const unsigned int& dim);
162 
163 protected:
164  const double threshold;
165 
166 };
167 
174 class RSC_EXPORT AboveThreshold: public MetricCondition {
175 public:
176 
177  AboveThreshold(const MetricPtr m, const double threshold);
178 
186  bool isFulfilled(const double* v1, const double* v2,
187  const unsigned int& dim);
188 
189 protected:
190  const double threshold;
191 
192 };
193 
196 
209 class RSC_EXPORT SequenceMonitor {
210 public:
211 
221  SequenceMonitor(const unsigned int dim, const unsigned int window,
222  MetricConditionPtr condition);
223 
224  ~SequenceMonitor();
225 
232  bool isConditionFulfilled(double* new_v, const unsigned int& dim);
233 
234 protected:
235 
236  void resetCnt();
237 
238  const unsigned int dim;
239  const unsigned int windowSize;
240  MetricConditionPtr metricCondition;
241 
245  double* prev_v;
249  int cnt;
250 
251 };
252 
253 }
254 }
255 
Defines interface for vector metrics providing a calc-method that calculates the metric of two vector...
int cnt
Counts whether the condition is fulfilled long enough.
Euclidean distance between two vectors.
double * prev_v
Previous sequence element.
boost::shared_ptr< MetricCondition > MetricConditionPtr
The BelowThreshold - condition tests whether a given metric of two vectors stays below a given upper ...
Euclidean distance between two vectors.
Defines a interface for metric conditions.
The AboveThreshold - condition tests whether a given metric of two vectors stays above a given thresh...
const unsigned int windowSize
boost::shared_ptr< Metric > MetricPtr
A monitor for (vector-) sequences.
MetricConditionPtr metricCondition