Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureMomentAreaNormalized.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  * Implementation for all supported moment features.
32  *
33  * Authors:
34  * Filip Novotny
35  *
36  *****************************************************************************/
37 #include <visp3/core/vpConfig.h>
38 
39 #ifdef VISP_MOMENTS_COMBINE_MATRICES
40 #include <vector>
41 #include <limits>
42 
43 #include <visp3/core/vpMomentObject.h>
44 #include <visp3/visual_features/vpFeatureMomentAreaNormalized.h>
45 #include <visp3/visual_features/vpFeatureMomentBasic.h>
46 #include <visp3/core/vpMomentCentered.h>
47 #include <visp3/core/vpMomentAreaNormalized.h>
48 #include <visp3/visual_features/vpFeatureMomentCentered.h>
49 #include <visp3/visual_features/vpFeatureMomentDatabase.h>
50 
51 
62  bool found_moment_centered;
63  bool found_moment_surface_normalized;
64  bool found_FeatureMoment_centered;
65 
66  bool found_featuremoment_basic;
67  vpFeatureMomentBasic& featureMomentBasic= (static_cast<vpFeatureMomentBasic&>(featureMomentsDataBase->get("vpFeatureMomentBasic",found_featuremoment_basic)));
68 
69  const vpMomentCentered& momentCentered = static_cast<const vpMomentCentered&>(moments.get("vpMomentCentered",found_moment_centered));
70  const vpMomentObject& momentObject = moment->getObject();
71  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(moments.get("vpMomentAreaNormalized",found_moment_surface_normalized));
72  vpFeatureMomentCentered& featureMomentCentered = (static_cast<vpFeatureMomentCentered&>(featureMomentsDataBase->get("vpFeatureMomentCentered",found_FeatureMoment_centered)));
73 
74  if(!found_FeatureMoment_centered) throw vpException(vpException::notInitialized, "vpFeatureMomentCentered not found");
75  if(!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
76  if(!found_moment_centered) throw vpException(vpException::notInitialized,"vpMomentCentered not found");
77  if(!found_featuremoment_basic) throw vpException(vpException::notInitialized,"vpFeatureMomentBasic not found");
78  interaction_matrices.resize(1);
79  interaction_matrices[0].resize(1,6);
80  double normalized_multiplier;
81  double a;
82  vpMatrix La;
83  if(momentObject.getType()==vpMomentObject::DISCRETE){
84  a = momentCentered.get(2,0)+momentCentered.get(0,2);
85  La = featureMomentCentered.interaction(2,0)+featureMomentCentered.interaction(0,2);
86  }else{
87  a = momentObject.get(0,0);
88  La = featureMomentBasic.interaction(0,0);
89  }
90 
91  normalized_multiplier = (-momentSurfaceNormalized.getDesiredDepth()/(2*a))*sqrt(momentSurfaceNormalized.getDesiredSurface()/a);
92  interaction_matrices[0] = normalized_multiplier*La;
93 
94 }
95 
96 #else
97 
98 #include <vector>
99 #include <limits>
100 
101 #include <visp3/core/vpMomentObject.h>
102 #include <visp3/core/vpMomentAreaNormalized.h>
103 #include <visp3/core/vpMomentCentered.h>
104 #include <visp3/core/vpMomentCentered.h>
105 #include <visp3/core/vpMomentGravityCenter.h>
106 #include <visp3/visual_features/vpFeatureMomentDatabase.h>
107 #include <visp3/visual_features/vpFeatureMomentAreaNormalized.h>
108 
118  bool found_moment_centered;
119  bool found_moment_surface_normalized;
120  bool found_moment_gravity;
121 
122  const vpMomentCentered& momentCentered = static_cast<const vpMomentCentered&>(moments.get("vpMomentCentered",found_moment_centered));
123  const vpMomentGravityCenter& momentGravity = static_cast<const vpMomentGravityCenter&>(moments.get("vpMomentGravityCenter",found_moment_gravity));
124  const vpMomentObject& momentObject = moment->getObject();
125  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(moments.get("vpMomentAreaNormalized",found_moment_surface_normalized));
126 
127  if (!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
128  if (!found_moment_centered) throw vpException(vpException::notInitialized,"vpMomentCentered not found");
129  if (!found_moment_gravity) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
130  interaction_matrices.resize(1);
131  interaction_matrices[0].resize(1,6);
132  double n11 = momentCentered.get(1,1)/momentObject.get(0,0);
133  double n20 = momentCentered.get(2,0)/momentObject.get(0,0);
134  double n02 = momentCentered.get(0,2)/momentObject.get(0,0);
135  double Xg = momentGravity.getXg();
136  double Yg = momentGravity.getYg();
137 
138  double An=momentSurfaceNormalized.get()[0];
139 
140  double Xn = An*Xg;
141  double Yn = An*Yg;
142 
143  double Anvx,Anvy,Anvz,Anwx,Anwy;
144 
145  if (momentObject.getType()==vpMomentObject::DISCRETE) {
146  double a = momentCentered.get(2,0)+momentCentered.get(0,2);
147 
148  double e01 = momentCentered.get(0,1)/a;
149  double e10 = momentCentered.get(1,0)/a;
150  double e11 = momentCentered.get(1,1)/a;
151  double e02 = momentCentered.get(0,2)/a;
152  double e20 = momentCentered.get(2,0)/a;
153  double e12 = momentCentered.get(1,2)/a;
154  double e21 = momentCentered.get(2,1)/a;
155  double e03 = momentCentered.get(0,3)/a;
156  double e30 = momentCentered.get(3,0)/a;
157 
158  Anvx = An*A*e20+An*B*e11;
159  Anvy = An*A*e11+An*B*e02;
160 
161  Anwx = (n02*e01+n11*e10-e03-e21)*An-Xn*e11+(-1-e02)*Yn;
162  Anwy = (e12+e30-n11*e01-n20*e10)*An+(2-e02)*Xn+Yn*e11;
163 
164  Anvz = -An*C+B*Anwx-A*Anwy;
165 
166  } else {
167  Anvx = A*An/2.;
168  Anvy = B*An/2.;
169  Anvz = -An*C-(3./2.)*A*Xn-(3./2.)*B*Yn;
170 
171  Anwx = -(3./2.)*Yn;
172  Anwy = (3./2.)*Xn;
173  }
174 
175  int VX = 0;
176  int VY = 1;
177  int VZ = 2;
178  int WX = 3;
179  int WY = 4;
180  int WZ = 5;
181 
182  interaction_matrices[0][0][VX] = Anvx;
183  interaction_matrices[0][0][VY] = Anvy;
184  interaction_matrices[0][0][VZ] = Anvz;
185 
186  interaction_matrices[0][0][WX] = Anwx;
187  interaction_matrices[0][0][WY] = Anwy;
188  interaction_matrices[0][0][WZ] = 0.;
189 }
190 
191 
192 #endif
Functionality computation for basic moment feature. Computes the interaction matrix associated with v...
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
Class handling the normalized surface moment that is invariant in scale and used to estimate depth...
const std::vector< double > & get() const
Definition: vpMoment.h:150
const vpMoment * moment
Functionality computation for centered moment feature. Computes the interaction matrix associated wit...
error that can be emited by ViSP classes.
Definition: vpException.h:73
Class for generic objects.
const std::vector< double > & get() const
std::vector< vpMatrix > interaction_matrices
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
const vpMoment & get(const char *type, bool &found) const
vpMomentDatabase & moments
This class defines the double-indexed centered moment descriptor .
double get(unsigned int i, unsigned int j) const
Class describing 2D gravity center moment.
vpObjectType getType() const
vpFeatureMomentDatabase * featureMomentsDataBase
const vpMomentObject & getObject() const
Definition: vpMoment.h:145
vpFeatureMoment & get(const char *type, bool &found)