ViSP  2.9.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 - 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  * 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&>(featureMomentsDataBase->get("vpFeatureMomentBasic",found_featuremoment_basic)));
72 
73  const vpMomentCentered& momentCentered = static_cast<const vpMomentCentered&>(moments.get("vpMomentCentered",found_moment_centered));
74  const vpMomentObject& momentObject = moment->getObject();
75  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(moments.get("vpMomentAreaNormalized",found_moment_surface_normalized));
76  vpFeatureMomentCentered& featureMomentCentered = (static_cast<vpFeatureMomentCentered&>(featureMomentsDataBase->get("vpFeatureMomentCentered",found_FeatureMoment_centered)));
77 
78  if(!found_FeatureMoment_centered) throw vpException(vpException::notInitialized, "vpFeatureMomentCentered not found");
79  if(!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
80  if(!found_moment_centered) throw vpException(vpException::notInitialized,"vpMomentCentered not found");
81  if(!found_featuremoment_basic) throw vpException(vpException::notInitialized,"vpFeatureMomentBasic not found");
82  interaction_matrices.resize(1);
83  interaction_matrices[0].resize(1,6);
84  double normalized_multiplier;
85  double a;
86  vpMatrix La;
87  if(momentObject.getType()==vpMomentObject::DISCRETE){
88  a = momentCentered.get(2,0)+momentCentered.get(0,2);
89  La = featureMomentCentered.interaction(2,0)+featureMomentCentered.interaction(0,2);
90  }else{
91  a = momentObject.get(0,0);
92  La = featureMomentBasic.interaction(0,0);
93  }
94 
95  normalized_multiplier = (-momentSurfaceNormalized.getDesiredDepth()/(2*a))*sqrt(momentSurfaceNormalized.getDesiredSurface()/a);
96  interaction_matrices[0] = normalized_multiplier*La;
97 
98 }
99 
100 #else
101 
102 #include <vector>
103 #include <limits>
104 
105 #include <visp/vpMomentObject.h>
106 #include <visp/vpMomentAreaNormalized.h>
107 #include <visp/vpMomentCentered.h>
108 #include <visp/vpMomentCentered.h>
109 #include <visp/vpMomentGravityCenter.h>
110 #include <visp/vpFeatureMomentDatabase.h>
111 #include <visp/vpFeatureMomentAreaNormalized.h>
112 
122  bool found_moment_centered;
123  bool found_moment_surface_normalized;
124  bool found_moment_gravity;
125 
126  const vpMomentCentered& momentCentered = static_cast<const vpMomentCentered&>(moments.get("vpMomentCentered",found_moment_centered));
127  const vpMomentGravityCenter& momentGravity = static_cast<const vpMomentGravityCenter&>(moments.get("vpMomentGravityCenter",found_moment_gravity));
128  const vpMomentObject& momentObject = moment->getObject();
129  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(moments.get("vpMomentAreaNormalized",found_moment_surface_normalized));
130 
131  if (!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
132  if (!found_moment_centered) throw vpException(vpException::notInitialized,"vpMomentCentered not found");
133  if (!found_moment_gravity) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
134  interaction_matrices.resize(1);
135  interaction_matrices[0].resize(1,6);
136  double n11 = momentCentered.get(1,1)/momentObject.get(0,0);
137  double n20 = momentCentered.get(2,0)/momentObject.get(0,0);
138  double n02 = momentCentered.get(0,2)/momentObject.get(0,0);
139  double Xg = momentGravity.getXg();
140  double Yg = momentGravity.getYg();
141 
142  double An=momentSurfaceNormalized.get()[0];
143 
144  double Xn = An*Xg;
145  double Yn = An*Yg;
146 
147  double Anvx,Anvy,Anvz,Anwx,Anwy;
148 
149  if (momentObject.getType()==vpMomentObject::DISCRETE) {
150  double a = momentCentered.get(2,0)+momentCentered.get(0,2);
151 
152  double e01 = momentCentered.get(0,1)/a;
153  double e10 = momentCentered.get(1,0)/a;
154  double e11 = momentCentered.get(1,1)/a;
155  double e02 = momentCentered.get(0,2)/a;
156  double e20 = momentCentered.get(2,0)/a;
157  double e12 = momentCentered.get(1,2)/a;
158  double e21 = momentCentered.get(2,1)/a;
159  double e03 = momentCentered.get(0,3)/a;
160  double e30 = momentCentered.get(3,0)/a;
161 
162  Anvx = An*A*e20+An*B*e11;
163  Anvy = An*A*e11+An*B*e02;
164 
165  Anwx = (n02*e01+n11*e10-e03-e21)*An-Xn*e11+(-1-e02)*Yn;
166  Anwy = (e12+e30-n11*e01-n20*e10)*An+(2-e02)*Xn+Yn*e11;
167 
168  Anvz = -An*C+B*Anwx-A*Anwy;
169 
170  } else {
171  Anvx = A*An/2.;
172  Anvy = B*An/2.;
173  Anvz = -An*C-(3./2.)*A*Xn-(3./2.)*B*Yn;
174 
175  Anwx = -(3./2.)*Yn;
176  Anwy = (3./2.)*Xn;
177  }
178 
179  int VX = 0;
180  int VY = 1;
181  int VZ = 2;
182  int WX = 3;
183  int WY = 4;
184  int WZ = 5;
185 
186  interaction_matrices[0][0][VX] = Anvx;
187  interaction_matrices[0][0][VY] = Anvy;
188  interaction_matrices[0][0][VZ] = Anvz;
189 
190  interaction_matrices[0][0][WX] = Anwx;
191  interaction_matrices[0][0][WY] = Anwy;
192  interaction_matrices[0][0][WZ] = 0.;
193 }
194 
195 
196 #endif
Functionality computation for basic moment feature. Computes the interaction matrix associated with v...
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
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:129
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:76
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:123
vpFeatureMoment & get(const char *type, bool &found)