Visual Servoing Platform  version 3.0.0
vpBasicFeature.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Eric Marchand
35  * Nicolas Mansard
36  *
37  *****************************************************************************/
38 
39 
40 
41 #include <visp3/visual_features/vpBasicFeature.h>
42 
43 const unsigned int vpBasicFeature::FEATURE_LINE [32] =
44  {
45  (unsigned int)(1 << 0), (unsigned int)(1 << 1),
46  (unsigned int)(1 << 2), (unsigned int)(1 << 3),
47  (unsigned int)(1 << 4), (unsigned int)(1 << 5),
48  (unsigned int)(1 << 6), (unsigned int)(1 << 7),
49  (unsigned int)(1 << 8), (unsigned int)(1 << 9),
50  (unsigned int)(1 << 10), (unsigned int)(1 << 11),
51  (unsigned int)(1 << 12), (unsigned int)(1 << 13),
52  (unsigned int)(1 << 14), (unsigned int)(1 << 15),
53  (unsigned int)(1 << 16), (unsigned int)(1 << 17),
54  (unsigned int)(1 << 18), (unsigned int)(1 << 19),
55  (unsigned int)(1 << 20), (unsigned int)(1 << 21),
56  (unsigned int)(1 << 22), (unsigned int)(1 << 23),
57  (unsigned int)(1 << 24), (unsigned int)(1 << 25),
58  (unsigned int)(1 << 26), (unsigned int)(1 << 27),
59  (unsigned int)(1 << 28), (unsigned int)(1 << 29),
60  (unsigned int)(1 << 30), (unsigned int)(1 << 31)
61  };
62 
71  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
72 {
73 }
74 
79 {
80  if (flags != NULL) {
81  delete [] flags;
82  flags = NULL;
83  }
84 }
85 
90  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
91 {
92  *this = f;
93 }
94 
99 {
100  s = f.s;
101  dim_s = f.dim_s;
104  if (flags)
105  delete [] flags;
106  flags = new bool [nbParameters];
107  for (unsigned int i = 0; i < nbParameters; i++)
108  flags[i] = f.flags[i];
109 
110  return (*this);
111 }
112 
114 unsigned int
115 vpBasicFeature::getDimension(unsigned int select) const
116 {
117  unsigned int dim = 0 ;
118  if(dim_s>31)
119  return dim_s;
120  for (unsigned int i=0 ; i < s.getRows() ; i++)
121  {
122  // printf("%x %x %d \n",select, featureLine[i], featureLine[i] & select);
123  if (FEATURE_LINE[i] & select) dim +=1 ;
124  }
125  return dim ;
126 }
127 
130 vpBasicFeature::get_s(const unsigned int select) const
131 {
132  vpColVector state(0), stateLine(1);
133  // if s is higher than the possible selections (photometry), send back the whole vector
134  if(dim_s > 31)
135  return s;
136 
137  for(unsigned int i=0;i<dim_s;++i)
138  {
139  if(FEATURE_LINE[i] & select)
140  {
141  stateLine[0] = s[i];
142  state.stack(stateLine);
143  }
144  }
145  return state ;
146 }
147 
149 {
150  if (flags != NULL)
151  {
152  for (unsigned int i = 0; i < nbParameters; i++)
153  flags[i] = false;
154  }
155 }
156 
159 {
160  if (flags != NULL)
161  {
162  for (unsigned int i = 0; i < nbParameters; i++)
163  flags[i] = true;
164  }
165 }
166 
169  const unsigned int select)
170 {
171  vpColVector e(0),eLine(1);
172  if (dim_s <= 31)
173  {
174  for(unsigned int i=0;i<dim_s;++i){
175  if(FEATURE_LINE[i] & select)
176  {
177  eLine[0] = s[i] - s_star[i];
178  e.stack(eLine);
179  //std::cout << "dim_s <= 31"<<std::endl;
180  }
181  }
182  }
183  else
184  {
185  e.resize(dim_s);
186  vpColVector sd = s_star.get_s();
187  e = s - sd;
188  }
189 
190  return e ;
191 }
192 
193 /*
194  * Local variables:
195  * c-basic-offset: 4
196  * End:
197  */
vpBasicFeature & operator=(const vpBasicFeature &f)
void setFlags()
Set feature flags to true to prevent warning when re-computing the interaction matrix without having ...
bool * flags
Ensure that all the parameters needed to compute the iteraction matrix are set.
void stack(const double &d)
unsigned int getDimension(const unsigned int select=FEATURE_ALL) const
Get the feature vector dimension.
unsigned int dim_s
Dimension of the visual feature.
virtual vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
Compute the error between two visual features from a subset of the possible features.
class that defines what is a visual feature
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
virtual ~vpBasicFeature()
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector s
State of the visual feature.