ViSP  2.9.0
vpFeatureMoment.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureMoment.cpp 4649 2014-02-07 14:57:11Z 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  * 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 = (unsigned int)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 vpException(vpException::notInitialized,"Moment not found for feature");
158  }
159  nbParameters = 1;
160  if(this->moment!=NULL){
161  dim_s = (unsigned int)this->moment->get().size();
162 
163  s.resize(dim_s);
164 
165  for(unsigned int i=0;i<dim_s;i++)
166  s[i] = this->moment->get()[i];
167 
168  if (flags == NULL)
169  flags = new bool[nbParameters];
170  for (unsigned int i = 0; i < nbParameters; i++)
171  flags[i] = false;
172  }else
173  dim_s = 0;
174 
176 }
177 
194  vpMatrix L(0,0);
195 
196  for(unsigned int i=0;i<dim_s;++i){
197  if(vpBasicFeature::FEATURE_LINE[i] & select){
199  }
200  }
201 
202  return L;
203 }
204 
214 {
217  feat->dim_s = dim_s;
218  feat->nbParameters = nbParameters;
219  // memory allocation
220  feat->s.resize(dim_s) ;
221  for(unsigned int i=0;i<dim_s;i++)
222  feat->s[i] = this->s[i];
223 
224  feat->flags = new bool[(unsigned int)nbParameters];
225  for (unsigned int i = 0; i < (unsigned int)nbParameters; i++)
226  feat->flags[i] = flags[i];
227 
228  return feat;
229 }
230 
237  if (strlen( name() ) >= 255) {
239  "Not enough memory to intialize the moment name"));
240  }
241 
242  std::strcpy(_name,name());
243  this->featureMomentsDataBase=&featureMoments;
244 
245  featureMoments.add(*this,_name);
246 }
247 
248 
250 
251 }
252 
254  delete[] flags;
255 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
bool * flags
Ensure that all the parameters needed to compute the iteraction matrix are set.
virtual const char * name() const =0
const std::vector< double > & get() const
Definition: vpMoment.h:129
const vpMoment * moment
virtual void compute_interaction(void)
void linkTo(vpFeatureMomentDatabase &featureMoments)
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
vpBasicFeature * duplicate() const
unsigned int dim_s
Dimension of the visual feature.
error that can be emited by ViSP classes.
Definition: vpException.h:76
std::vector< vpMatrix > interaction_matrices
int getDimension(unsigned int select=FEATURE_ALL) const
This class defines a generic feature used for moment feature duplication.
virtual ~vpFeatureMoment()
virtual const char * momentName() const =0
class that defines what is a visual feature
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
This class defines shared system methods/attributes for 2D moment features but no functional code...
void print(const unsigned int select=FEATURE_ALL) const
Generic class defining intrinsic camera parameters.
const vpMoment & get(const char *type, bool &found) const
vpMomentDatabase & moments
void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.cpp:3003
void update(double A, double B, double C)
static const unsigned int FEATURE_LINE[32]
vpFeatureMomentDatabase * featureMomentsDataBase
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector s
State of the visual feature.
This class allows to register all feature moments (implemented in vpFeatureMoment... classes) so they can access each other according to their dependencies.
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94