Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpBasicFeature.cpp
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 * Description:
31 * Visual feature.
32 *
33 * Authors:
34 * Nicolas Mansard
35 */
36
41
42#include <visp3/visual_features/vpBasicFeature.h>
43
45const unsigned int vpBasicFeature::FEATURE_LINE[32] = {
46 static_cast<unsigned int>(1 << 0), static_cast<unsigned int>(1 << 1), static_cast<unsigned int>(1 << 2), static_cast<unsigned int>(1 << 3),
47 static_cast<unsigned int>(1 << 4), static_cast<unsigned int>(1 << 5), static_cast<unsigned int>(1 << 6), static_cast<unsigned int>(1 << 7),
48 static_cast<unsigned int>(1 << 8), static_cast<unsigned int>(1 << 9), static_cast<unsigned int>(1 << 10), static_cast<unsigned int>(1 << 11),
49 static_cast<unsigned int>(1 << 12), static_cast<unsigned int>(1 << 13), static_cast<unsigned int>(1 << 14), static_cast<unsigned int>(1 << 15),
50 static_cast<unsigned int>(1 << 16), static_cast<unsigned int>(1 << 17), static_cast<unsigned int>(1 << 18), static_cast<unsigned int>(1 << 19),
51 static_cast<unsigned int>(1 << 20), static_cast<unsigned int>(1 << 21), static_cast<unsigned int>(1 << 22), static_cast<unsigned int>(1 << 23),
52 static_cast<unsigned int>(1 << 24), static_cast<unsigned int>(1 << 25), static_cast<unsigned int>(1 << 26), static_cast<unsigned int>(1 << 27),
53 static_cast<unsigned int>(1 << 28), static_cast<unsigned int>(1 << 29), static_cast<unsigned int>(1 << 30), static_cast<unsigned int>(1 << 31) };
54
55
60
65{
66 if (flags != nullptr) {
67 delete[] flags;
68 flags = nullptr;
69 }
70}
71
76 : s(), dim_s(0), flags(nullptr), nbParameters(0), deallocate(vpBasicFeature::user)
77{
78 *this = f;
79}
80
85{
86 s = f.s;
87 dim_s = f.dim_s;
90 if (flags)
91 delete[] flags;
92 flags = new bool[nbParameters];
93 for (unsigned int i = 0; i < nbParameters; i++)
94 flags[i] = f.flags[i];
95
96 return (*this);
97}
98
100unsigned int vpBasicFeature::getDimension(unsigned int select) const
101{
102 unsigned int dim = 0;
103 if (dim_s > 31)
104 return dim_s;
105 for (unsigned int i = 0; i < s.getRows(); i++) {
106 if (FEATURE_LINE[i] & select)
107 dim += 1;
108 }
109 return dim;
110}
111
113vpColVector vpBasicFeature::get_s(unsigned int select) const
114{
115 vpColVector state(0), stateLine(1);
116 // if s is higher than the possible selections (photometry), send back the
117 // whole vector
118 if (dim_s > 31)
119 return s;
120
121 for (unsigned int i = 0; i < dim_s; ++i) {
122 if (FEATURE_LINE[i] & select) {
123 stateLine[0] = s[i];
124 state.stack(stateLine);
125 }
126 }
127 return state;
128}
129
131{
132 if (flags != nullptr) {
133 for (unsigned int i = 0; i < nbParameters; i++)
134 flags[i] = false;
135 }
136}
137
141{
142 if (flags != nullptr) {
143 for (unsigned int i = 0; i < nbParameters; i++)
144 flags[i] = true;
145 }
146}
147
150vpColVector vpBasicFeature::error(const vpBasicFeature &s_star, unsigned int select)
151{
152 vpColVector e(0), eLine(1);
153 if (dim_s <= 31) {
154 for (unsigned int i = 0; i < dim_s; ++i) {
155 if (FEATURE_LINE[i] & select) {
156 eLine[0] = s[i] - s_star[i];
157 e.stack(eLine);
158 // std::cout << "dim_s <= 31"<<std::endl;
159 }
160 }
161 }
162 else {
163 e.resize(dim_s);
164 vpColVector sd = s_star.get_s();
165 e = s - sd;
166 }
167
168 return e;
169}
170END_VISP_NAMESPACE
171/*
172 * Local variables:
173 * c-basic-offset: 4
174 * End:
175 */
virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
vpColVector s
State of the visual feature.
virtual ~vpBasicFeature()
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpBasicFeature & operator=(const vpBasicFeature &f)
unsigned int getDimension(unsigned int select=FEATURE_ALL) const
Get the feature vector dimension.
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
unsigned int dim_s
Dimension of the visual feature.
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Implementation of column vector and the associated operations.