Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpTemporalWeighting.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 */
30#ifndef VP_TEMPORAL_WEIGHTING_H
31#define VP_TEMPORAL_WEIGHTING_H
32
33#include <visp3/core/vpConfig.h>
34#include <visp3/core/vpException.h>
35
36#if defined(VISP_HAVE_NLOHMANN_JSON)
37#include VISP_NLOHMANN_JSON(json_fwd.hpp)
38#endif
39
41class VISP_EXPORT vpTemporalWeighting
42{
43public:
45 virtual double weight(const double progress) const = 0;
46 virtual ~vpTemporalWeighting() = default;
47#if defined(VISP_HAVE_NLOHMANN_JSON)
48 static std::shared_ptr<vpTemporalWeighting> parseTemporalWeighting(const nlohmann::json &j);
49 static std::shared_ptr<vpTemporalWeighting> parseTemporalWeightingRawJson(const std::string &j);
50
51#endif
52};
53
55{
56public:
57 vpFixedTemporalWeighting(double weight) : m_weight(weight) { }
58
59 double weight(const double /*progress*/) const VP_OVERRIDE;
60
61 double getWeight() const { return m_weight; }
62 void setWeight(double weight) { m_weight = weight; }
63private:
64 double m_weight;
65};
66
68{
69public:
70 vpSigmoidTemporalWeighting(double minWeight, double maxWeight, double location, double power)
71 {
72 setLocation(location);
73 setSlopePower(power);
74 setMinimumWeight(minWeight);
75 setMaximumWeight(maxWeight);
76
77 if (maxWeight < minWeight) {
78 throw vpException(vpException::badValue, "Maximum weight should be equal or greater than the minimum weight");
79 }
80 }
81
82 double getLocation() const { return m_location; }
83 void setLocation(double location)
84 {
85 if (location < 0 || location > 1) {
86 throw vpException(vpException::badValue, "Location parameter needs to be between 0 and 1");
87 }
88 m_location = location;
89 }
90
91 double weight(const double progress) const VP_OVERRIDE;
92
93 double getSlopePower() const { return m_power; }
94 void setSlopePower(double power) { m_power = power; }
95
96 double getMinimumWeight() const { return m_minWeight; }
97 void setMinimumWeight(double w) { m_minWeight = w; }
98
99 double getMaximumWeight() const { return m_maxWeight; }
100 void setMaximumWeight(double w) { m_maxWeight = w; }
101
102
103private:
104 double m_location;
105 double m_power;
106 double m_minWeight;
107 double m_maxWeight;
108
109};
110
111END_VISP_NAMESPACE
112
113#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
double weight(const double) const VP_OVERRIDE
void setWeight(double weight)
vpFixedTemporalWeighting(double weight)
void setLocation(double location)
vpSigmoidTemporalWeighting(double minWeight, double maxWeight, double location, double power)
virtual double weight(const double progress) const =0
virtual ~vpTemporalWeighting()=default
vpTemporalWeighting()=default
static std::shared_ptr< vpTemporalWeighting > parseTemporalWeighting(const nlohmann::json &j)
static std::shared_ptr< vpTemporalWeighting > parseTemporalWeightingRawJson(const std::string &j)