ViSP  2.9.0
vpBasicFeature.cpp
1 /****************************************************************************
2  *
3  * $Id: vpBasicFeature.cpp 4632 2014-02-03 17:06:40Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Visual feature.
36  *
37  * Authors:
38  * Eric Marchand
39  * Nicolas Mansard
40  *
41  *****************************************************************************/
42 
43 
44 
45 #include <visp/vpBasicFeature.h>
46 
47 const unsigned int vpBasicFeature::FEATURE_LINE [32] =
48  {
49  (unsigned int)(1 << 0), (unsigned int)(1 << 1),
50  (unsigned int)(1 << 2), (unsigned int)(1 << 3),
51  (unsigned int)(1 << 4), (unsigned int)(1 << 5),
52  (unsigned int)(1 << 6), (unsigned int)(1 << 7),
53  (unsigned int)(1 << 8), (unsigned int)(1 << 9),
54  (unsigned int)(1 << 10), (unsigned int)(1 << 11),
55  (unsigned int)(1 << 12), (unsigned int)(1 << 13),
56  (unsigned int)(1 << 14), (unsigned int)(1 << 15),
57  (unsigned int)(1 << 16), (unsigned int)(1 << 17),
58  (unsigned int)(1 << 18), (unsigned int)(1 << 19),
59  (unsigned int)(1 << 20), (unsigned int)(1 << 21),
60  (unsigned int)(1 << 22), (unsigned int)(1 << 23),
61  (unsigned int)(1 << 24), (unsigned int)(1 << 25),
62  (unsigned int)(1 << 26), (unsigned int)(1 << 27),
63  (unsigned int)(1 << 28), (unsigned int)(1 << 29),
64  (unsigned int)(1 << 30), (unsigned int)(1 << 31)
65  };
66 const unsigned int vpBasicFeature::FEATURE_ALL = 0xffff;
67 
75  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
76 {
77 }
78 
83  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
84 {
85  *this = f;
86 }
87 
92 {
93  s = f.s;
94  dim_s = f.dim_s;
97  if (flags)
98  delete [] flags;
99  flags = new bool [nbParameters];
100  for (unsigned int i = 0; i < nbParameters; i++)
101  flags[i] = f.flags[i];
102 
103  return (*this);
104 }
105 
107 unsigned int
108 vpBasicFeature::getDimension(unsigned int select) const
109 {
110  unsigned int dim = 0 ;
111  if(dim_s>31)
112  return dim_s;
113  for (unsigned int i=0 ; i < s.getRows() ; i++)
114  {
115  // printf("%x %x %d \n",select, featureLine[i], featureLine[i] & select);
116  if (FEATURE_LINE[i] & select) dim +=1 ;
117  }
118  return dim ;
119 }
120 
123  vpBasicFeature::get_s(const unsigned int select) const
124 {
125  vpColVector state(0),stateLine(1);
126  // if s is higher than the possible selections (photometry), send back the whole vector
127  if(dim_s > 31)
128  return s;
129 
130  for(unsigned int i=0;i<dim_s;++i)
131  {
132  if(FEATURE_LINE[i] & select)
133  {
134  stateLine[0] = s[i];
135  state.stackMatrices(stateLine);
136  }
137  }
138  return state ;
139 }
140 
142 {
143  if (flags != NULL)
144  {
145  for (unsigned int i = 0; i < nbParameters; i++)
146  flags[i] = false;
147  }
148 }
149 
152 {
153  if (flags != NULL)
154  {
155  for (unsigned int i = 0; i < nbParameters; i++)
156  flags[i] = true;
157  }
158 }
159 
162  const unsigned int select)
163 {
164  vpColVector e(0),eLine(1);
165  if (dim_s <= 31)
166  {
167  for(unsigned int i=0;i<dim_s;++i){
168  if(FEATURE_LINE[i] & select)
169  {
170  eLine[0] = s[i] - s_star[i];
171  e.stackMatrices(eLine);
172  //std::cout << "dim_s <= 31"<<std::endl;
173  }
174  }
175  }
176  else
177  {
178  e.resize(dim_s);
179  vpColVector sd = s_star.get_s();
180  e = s - sd;
181  }
182 
183  return e ;
184 }
185 
186 /*
187  * Local variables:
188  * c-basic-offset: 4
189  * End:
190  */
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.
static const unsigned int FEATURE_ALL
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
void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.cpp:3003
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
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.