Visual Servoing Platform  version 3.6.1 under development (2024-05-21)
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 
39 #include <visp3/visual_features/vpBasicFeature.h>
40 
41 const unsigned int vpBasicFeature::FEATURE_LINE[32] = {
42  (unsigned int)(1 << 0), (unsigned int)(1 << 1), (unsigned int)(1 << 2), (unsigned int)(1 << 3),
43  (unsigned int)(1 << 4), (unsigned int)(1 << 5), (unsigned int)(1 << 6), (unsigned int)(1 << 7),
44  (unsigned int)(1 << 8), (unsigned int)(1 << 9), (unsigned int)(1 << 10), (unsigned int)(1 << 11),
45  (unsigned int)(1 << 12), (unsigned int)(1 << 13), (unsigned int)(1 << 14), (unsigned int)(1 << 15),
46  (unsigned int)(1 << 16), (unsigned int)(1 << 17), (unsigned int)(1 << 18), (unsigned int)(1 << 19),
47  (unsigned int)(1 << 20), (unsigned int)(1 << 21), (unsigned int)(1 << 22), (unsigned int)(1 << 23),
48  (unsigned int)(1 << 24), (unsigned int)(1 << 25), (unsigned int)(1 << 26), (unsigned int)(1 << 27),
49  (unsigned int)(1 << 28), (unsigned int)(1 << 29), (unsigned int)(1 << 30), (unsigned int)(1 << 31)};
50 
58 vpBasicFeature::vpBasicFeature() : s(), dim_s(0), flags(nullptr), nbParameters(0), deallocate(vpBasicFeature::user) {}
59 
64 {
65  if (flags != nullptr) {
66  delete[] flags;
67  flags = nullptr;
68  }
69 }
70 
75  : s(), dim_s(0), flags(nullptr), nbParameters(0), deallocate(vpBasicFeature::user)
76 {
77  *this = f;
78 }
79 
84 {
85  s = f.s;
86  dim_s = f.dim_s;
89  if (flags)
90  delete[] flags;
91  flags = new bool[nbParameters];
92  for (unsigned int i = 0; i < nbParameters; i++)
93  flags[i] = f.flags[i];
94 
95  return (*this);
96 }
97 
99 unsigned int vpBasicFeature::getDimension(unsigned int select) const
100 {
101  unsigned int dim = 0;
102  if (dim_s > 31)
103  return dim_s;
104  for (unsigned int i = 0; i < s.getRows(); i++) {
105  if (FEATURE_LINE[i] & select)
106  dim += 1;
107  }
108  return dim;
109 }
110 
112 vpColVector vpBasicFeature::get_s(unsigned int select) const
113 {
114  vpColVector state(0), stateLine(1);
115  // if s is higher than the possible selections (photometry), send back the
116  // whole vector
117  if (dim_s > 31)
118  return s;
119 
120  for (unsigned int i = 0; i < dim_s; ++i) {
121  if (FEATURE_LINE[i] & select) {
122  stateLine[0] = s[i];
123  state.stack(stateLine);
124  }
125  }
126  return state;
127 }
128 
130 {
131  if (flags != nullptr) {
132  for (unsigned int i = 0; i < nbParameters; i++)
133  flags[i] = false;
134  }
135 }
136 
140 {
141  if (flags != nullptr) {
142  for (unsigned int i = 0; i < nbParameters; i++)
143  flags[i] = true;
144  }
145 }
146 
149 vpColVector vpBasicFeature::error(const vpBasicFeature &s_star, unsigned int select)
150 {
151  vpColVector e(0), eLine(1);
152  if (dim_s <= 31) {
153  for (unsigned int i = 0; i < dim_s; ++i) {
154  if (FEATURE_LINE[i] & select) {
155  eLine[0] = s[i] - s_star[i];
156  e.stack(eLine);
157  // std::cout << "dim_s <= 31"<<std::endl;
158  }
159  }
160  } else {
161  e.resize(dim_s);
162  vpColVector sd = s_star.get_s();
163  e = s - sd;
164  }
165 
166  return e;
167 }
168 
169 /*
170  * Local variables:
171  * c-basic-offset: 4
172  * End:
173  */
unsigned int getRows() const
Definition: vpArray2D.h:339
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.
static const unsigned int FEATURE_LINE[32]
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.
vpBasicFeatureDeallocatorType deallocate
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
void stack(double d)