Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureMoment.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  * Base for all moment features
32  *
33  * Authors:
34  * Filip Novotny
35  *
36  *****************************************************************************/
37 
38 #include <visp3/visual_features/vpFeatureMoment.h>
39 #include <visp3/core/vpMoment.h>
40 #include <visp3/visual_features/vpFeatureMomentDatabase.h>
41 #include <visp3/core/vpMomentDatabase.h>
42 #include <visp3/core/vpMath.h>
43 
44 #include <visp3/core/vpException.h>
45 #include <visp3/visual_features/vpFeatureException.h>
46 
47 #include <visp3/core/vpDebug.h>
48 #include <vector>
49 
50 class vpBasicFeature;
51 
56  //feature dimension
57  /*
58  * The dimension of the visual feature is set according to the size of the vpMoment associated to it.
59  * This partly explains why vpFeatureMomentBasic cannot be used directly as a visual feature.
60  */
61  if(this->moment!=NULL)
62  dim_s = (unsigned int)this->moment->get().size();
63  else
64  dim_s = 0;
65 
66  nbParameters = 1;
67 
68  // memory allocation
69  s.resize(dim_s) ;
70  for(unsigned int i=0;i<dim_s;i++)
71  s[i] = 0;
72 
73  if (flags == NULL)
74  flags = new bool[nbParameters];
75  for (unsigned int i = 0; i < nbParameters; i++)
76  flags[i] = false;
77 }
78 
79 
83 int vpFeatureMoment::getDimension (unsigned int select) const{
84  int dim=0;
85 
86  for(unsigned int i=0;i<dim_s;++i)
87  if(vpBasicFeature::FEATURE_LINE[i] & select)
88  dim++;
89 
90  return dim;
91 }
92 
93 
97 void vpFeatureMoment::print (unsigned int select) const{
98  for(unsigned int i=0;i<dim_s;++i){
99  if(vpBasicFeature::FEATURE_LINE[i] & select){
100  std::cout << s[i] << ",";
101  }
102  }
103 
104  std::cout << std::endl;
105 }
106 
111  const vpColor &color, unsigned int thickness) const
112 {
113  //visual representation of a moment doesn't often make sense
114  (void)cam;
115  (void)I;
116  (void)color;
117  (void)thickness;
118 }
119 
124  const vpColor &color, unsigned int thickness) const
125 {
126  (void)cam;
127  (void)I;
128  (void)color;
129  (void)thickness;
130 }
131 
144 void vpFeatureMoment::update (double A_, double B_, double C_){
145  this->A = A_;
146  this->B = B_;
147  this->C = C_;
148 
149  if(moment==NULL){
150  bool found;
151  this->moment = &(moments.get(momentName(),found));
152  if(!found) throw vpException(vpException::notInitialized,"Moment not found for feature");
153  }
154  nbParameters = 1;
155  if(this->moment!=NULL){
156  dim_s = (unsigned int)this->moment->get().size();
157 
158  s.resize(dim_s);
159 
160  for(unsigned int i=0;i<dim_s;i++)
161  s[i] = this->moment->get()[i];
162 
163  if (flags == NULL)
164  flags = new bool[nbParameters];
165  for (unsigned int i = 0; i < nbParameters; i++)
166  flags[i] = false;
167  }else
168  dim_s = 0;
169 
171 }
172 
189  vpMatrix L(0,0);
190 
191  for(unsigned int i=0;i<dim_s;++i){
192  if(vpBasicFeature::FEATURE_LINE[i] & select){
194  }
195  }
196 
197  return L;
198 }
199 
209 {
212  feat->dim_s = dim_s;
213  feat->nbParameters = nbParameters;
214  // memory allocation
215  feat->s.resize(dim_s) ;
216  for(unsigned int i=0;i<dim_s;i++)
217  feat->s[i] = this->s[i];
218 
219  feat->flags = new bool[(unsigned int)nbParameters];
220  for (unsigned int i = 0; i < (unsigned int)nbParameters; i++)
221  feat->flags[i] = flags[i];
222 
223  return feat;
224 }
225 
232  if (strlen( name() ) >= 255) {
234  "Not enough memory to intialize the moment name"));
235  }
236 
237  std::strcpy(_name,name());
238  this->featureMomentsDataBase=&featureMoments;
239 
240  featureMoments.add(*this,_name);
241 }
242 
243 
245 
246 }
247 
249 }
250 
251 VISP_EXPORT std::ostream& operator<<(std::ostream & os, const vpFeatureMoment& featM) {
252  /*
253  A const_cast is forced here since interaction() defined in vpBasicFeature() is not const
254  But introducing const in vpBasicFeature() can break a lot of client code
255  */
256  vpMatrix Lcomplete((unsigned int)featM.getDimension(), 6); // 6 corresponds to 6velocities in standard interaction matrix
257  Lcomplete = const_cast<vpFeatureMoment&>(featM).interaction(vpBasicFeature::FEATURE_ALL);
258  Lcomplete.matlabPrint(os);
259  return os;
260 }
261 
268 void
269 vpFeatureMoment::printDependencies(std::ostream& os) const{
270  os << " WARNING : Falling back to base class version of printDependencies() in vpFeatureMoment. To prevent that, this has to be implemented in the derived classes!" << std::endl;
271 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
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:150
const vpMoment * moment
virtual void compute_interaction(void)
void linkTo(vpFeatureMomentDatabase &featureMoments)
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:2981
vpBasicFeature * duplicate() const
unsigned int dim_s
Dimension of the visual feature.
error that can be emited by ViSP classes.
Definition: vpException.h:73
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
virtual vpMatrix interaction(const unsigned int select=FEATURE_ALL)=0
Compute the interaction matrix from a subset of the possible features.
Generic class defining intrinsic camera parameters.
const vpMoment & get(const char *type, bool &found) const
vpMomentDatabase & moments
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
void update(double A, double B, double C)
static const unsigned int FEATURE_LINE[32]
vpFeatureMomentDatabase * featureMomentsDataBase
virtual void printDependencies(std::ostream &os) const
std::ostream & matlabPrint(std::ostream &os) const
Definition: vpMatrix.cpp:2756
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:225