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