ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
vpFeatureMoment.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureMoment.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  * Base for all moment features
36  *
37  * Authors:
38  * Filip Novotny
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpFeatureMoment.h>
43 #include <visp/vpMoment.h>
44 #include <visp/vpFeatureMomentDatabase.h>
45 #include <visp/vpMomentDatabase.h>
46 #include <visp/vpMath.h>
47 
48 #include <visp/vpException.h>
49 #include <visp/vpMatrixException.h>
50 #include <visp/vpFeatureException.h>
51 
52 #include <visp/vpDebug.h>
53 #include <vector>
54 
55 class vpBasicFeature;
56 
61  //feature dimension
62  /*
63  * The dimension of the visual feature is set according to the size of the vpMoment associated to it.
64  * This partly explains why vpFeatureMomentBasic cannot be used directly as a visual feature.
65  */
66  if(this->moment!=NULL)
67  dim_s = this->moment->get().size();
68  else
69  dim_s = 0;
70 
71  nbParameters = 1;
72 
73  // memory allocation
74  s.resize(dim_s) ;
75  for(unsigned int i=0;i<dim_s;i++)
76  s[i] = 0;
77 
78  if (flags == NULL)
79  flags = new bool[nbParameters];
80  for (unsigned int i = 0; i < nbParameters; i++)
81  flags[i] = false;
82 }
83 
84 
88 int vpFeatureMoment::getDimension (unsigned int select) const{
89  int dim=0;
90 
91  for(unsigned int i=0;i<dim_s;++i)
92  if(vpBasicFeature::FEATURE_LINE[i] & select)
93  dim++;
94 
95  return dim;
96 }
97 
98 
102 void vpFeatureMoment::print (unsigned int select) const{
103  for(unsigned int i=0;i<dim_s;++i){
104  if(vpBasicFeature::FEATURE_LINE[i] & select){
105  std::cout << s[i] << ",";
106  }
107  }
108 
109  std::cout << std::endl;
110 }
111 
116  const vpColor &color, unsigned int thickness) const
117 {
118  //visual representation of a moment doesn't often make sense
119  (void)cam;
120  (void)I;
121  (void)color;
122  (void)thickness;
123 }
124 
129  const vpColor &color, unsigned int thickness) const
130 {
131  (void)cam;
132  (void)I;
133  (void)color;
134  (void)thickness;
135 }
136 
149 void vpFeatureMoment::update (double A, double B, double C){
150  this->A = A;
151  this->B = B;
152  this->C = C;
153 
154  if(moment==NULL){
155  bool found;
156  this->moment = &(moments.get(momentName(),found));
157  if(!found) throw ("Moment not found for feature");
158 
159  }
160  nbParameters = 1;
161  if(this->moment!=NULL){
162  dim_s = this->moment->get().size();
163 
164  s.resize(dim_s);
165 
166  for(unsigned int i=0;i<dim_s;i++)
167  s[i] = this->moment->get()[i];
168 
169  if (flags == NULL)
170  flags = new bool[nbParameters];
171  for (unsigned int i = 0; i < nbParameters; i++)
172  flags[i] = false;
173  }else
174  dim_s = 0;
175 
177 }
178 
195  vpMatrix L(0,0);
196 
197  for(unsigned int i=0;i<dim_s;++i){
198  if(vpBasicFeature::FEATURE_LINE[i] & select){
200  }
201  }
202 
203  return L;
204 }
205 
215 {
218  feat->dim_s = dim_s;
219  feat->nbParameters = nbParameters;
220  // memory allocation
221  feat->s.resize(dim_s) ;
222  for(unsigned int i=0;i<dim_s;i++)
223  feat->s[i] = this->s[i];
224 
225  feat->flags = new bool[(unsigned int)nbParameters];
226  for (unsigned int i = 0; i < (unsigned int)nbParameters; i++)
227  feat->flags[i] = flags[i];
228 
229  return feat;
230 }
231 
238  std::strcpy(_name,name());
239  this->featureMomentsDataBase=&featureMoments;
240 
241  featureMoments.add(*this,_name);
242 }
243 
244 
246 
247 }
248 
250  delete[] flags;
251 }