ViSP  2.10.0
vpBasicFeature.cpp
1 /****************************************************************************
2  *
3  * $Id: vpBasicFeature.cpp 5237 2015-01-30 13:52:04Z 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 
76  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
77 {
78 }
79 
84 {
85  if (flags != NULL) {
86  delete [] flags;
87  flags = NULL;
88  }
89 }
90 
95  : s(), dim_s(0), flags(NULL), nbParameters(0), deallocate(vpBasicFeature::user)
96 {
97  *this = f;
98 }
99 
104 {
105  s = f.s;
106  dim_s = f.dim_s;
109  if (flags)
110  delete [] flags;
111  flags = new bool [nbParameters];
112  for (unsigned int i = 0; i < nbParameters; i++)
113  flags[i] = f.flags[i];
114 
115  return (*this);
116 }
117 
119 unsigned int
120 vpBasicFeature::getDimension(unsigned int select) const
121 {
122  unsigned int dim = 0 ;
123  if(dim_s>31)
124  return dim_s;
125  for (unsigned int i=0 ; i < s.getRows() ; i++)
126  {
127  // printf("%x %x %d \n",select, featureLine[i], featureLine[i] & select);
128  if (FEATURE_LINE[i] & select) dim +=1 ;
129  }
130  return dim ;
131 }
132 
135  vpBasicFeature::get_s(const unsigned int select) const
136 {
137  vpColVector state(0),stateLine(1);
138  // if s is higher than the possible selections (photometry), send back the whole vector
139  if(dim_s > 31)
140  return s;
141 
142  for(unsigned int i=0;i<dim_s;++i)
143  {
144  if(FEATURE_LINE[i] & select)
145  {
146  stateLine[0] = s[i];
147  state.stackMatrices(stateLine);
148  }
149  }
150  return state ;
151 }
152 
154 {
155  if (flags != NULL)
156  {
157  for (unsigned int i = 0; i < nbParameters; i++)
158  flags[i] = false;
159  }
160 }
161 
164 {
165  if (flags != NULL)
166  {
167  for (unsigned int i = 0; i < nbParameters; i++)
168  flags[i] = true;
169  }
170 }
171 
174  const unsigned int select)
175 {
176  vpColVector e(0),eLine(1);
177  if (dim_s <= 31)
178  {
179  for(unsigned int i=0;i<dim_s;++i){
180  if(FEATURE_LINE[i] & select)
181  {
182  eLine[0] = s[i] - s_star[i];
183  e.stackMatrices(eLine);
184  //std::cout << "dim_s <= 31"<<std::endl;
185  }
186  }
187  }
188  else
189  {
190  e.resize(dim_s);
191  vpColVector sd = s_star.get_s();
192  e = s - sd;
193  }
194 
195  return e ;
196 }
197 
198 /*
199  * Local variables:
200  * c-basic-offset: 4
201  * End:
202  */
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
virtual ~vpBasicFeature()
void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.cpp:3272
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.