Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpBasicFeature.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Visual feature.
33  *
34  * Authors:
35  * Nicolas Mansard
36  *
37 *****************************************************************************/
38 
44 #include <visp3/visual_features/vpBasicFeature.h>
45 
47 const unsigned int vpBasicFeature::FEATURE_LINE[32] = {
48  (unsigned int)(1 << 0), (unsigned int)(1 << 1), (unsigned int)(1 << 2), (unsigned int)(1 << 3),
49  (unsigned int)(1 << 4), (unsigned int)(1 << 5), (unsigned int)(1 << 6), (unsigned int)(1 << 7),
50  (unsigned int)(1 << 8), (unsigned int)(1 << 9), (unsigned int)(1 << 10), (unsigned int)(1 << 11),
51  (unsigned int)(1 << 12), (unsigned int)(1 << 13), (unsigned int)(1 << 14), (unsigned int)(1 << 15),
52  (unsigned int)(1 << 16), (unsigned int)(1 << 17), (unsigned int)(1 << 18), (unsigned int)(1 << 19),
53  (unsigned int)(1 << 20), (unsigned int)(1 << 21), (unsigned int)(1 << 22), (unsigned int)(1 << 23),
54  (unsigned int)(1 << 24), (unsigned int)(1 << 25), (unsigned int)(1 << 26), (unsigned int)(1 << 27),
55  (unsigned int)(1 << 28), (unsigned int)(1 << 29), (unsigned int)(1 << 30), (unsigned int)(1 << 31) };
56 
57 
61 vpBasicFeature::vpBasicFeature() : s(), dim_s(0), flags(nullptr), nbParameters(0), deallocate(vpBasicFeature::user) { }
62 
67 {
68  if (flags != nullptr) {
69  delete[] flags;
70  flags = nullptr;
71  }
72 }
73 
78  : s(), dim_s(0), flags(nullptr), nbParameters(0), deallocate(vpBasicFeature::user)
79 {
80  *this = f;
81 }
82 
87 {
88  s = f.s;
89  dim_s = f.dim_s;
92  if (flags)
93  delete[] flags;
94  flags = new bool[nbParameters];
95  for (unsigned int i = 0; i < nbParameters; i++)
96  flags[i] = f.flags[i];
97 
98  return (*this);
99 }
100 
102 unsigned int vpBasicFeature::getDimension(unsigned int select) const
103 {
104  unsigned int dim = 0;
105  if (dim_s > 31)
106  return dim_s;
107  for (unsigned int i = 0; i < s.getRows(); i++) {
108  if (FEATURE_LINE[i] & select)
109  dim += 1;
110  }
111  return dim;
112 }
113 
115 vpColVector vpBasicFeature::get_s(unsigned int select) const
116 {
117  vpColVector state(0), stateLine(1);
118  // if s is higher than the possible selections (photometry), send back the
119  // whole vector
120  if (dim_s > 31)
121  return s;
122 
123  for (unsigned int i = 0; i < dim_s; ++i) {
124  if (FEATURE_LINE[i] & select) {
125  stateLine[0] = s[i];
126  state.stack(stateLine);
127  }
128  }
129  return state;
130 }
131 
133 {
134  if (flags != nullptr) {
135  for (unsigned int i = 0; i < nbParameters; i++)
136  flags[i] = false;
137  }
138 }
139 
143 {
144  if (flags != nullptr) {
145  for (unsigned int i = 0; i < nbParameters; i++)
146  flags[i] = true;
147  }
148 }
149 
152 vpColVector vpBasicFeature::error(const vpBasicFeature &s_star, unsigned int select)
153 {
154  vpColVector e(0), eLine(1);
155  if (dim_s <= 31) {
156  for (unsigned int i = 0; i < dim_s; ++i) {
157  if (FEATURE_LINE[i] & select) {
158  eLine[0] = s[i] - s_star[i];
159  e.stack(eLine);
160  // std::cout << "dim_s <= 31"<<std::endl;
161  }
162  }
163  }
164  else {
165  e.resize(dim_s);
166  vpColVector sd = s_star.get_s();
167  e = s - sd;
168  }
169 
170  return e;
171 }
172 END_VISP_NAMESPACE
173 /*
174  * Local variables:
175  * c-basic-offset: 4
176  * End:
177  */
unsigned int getRows() const
Definition: vpArray2D.h:347
class that defines what is a visual feature
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.
Definition: vpColVector.h:191
void stack(double d)