ViSP  2.8.0
vpFeatureMomentGravityCenter.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 
42 #include <visp/vpConfig.h>
43 
44 #ifdef VISP_MOMENTS_COMBINE_MATRICES
45 
46 #include <vector>
47 #include <limits>
48 
49 #include <visp/vpMomentObject.h>
50 #include <visp/vpFeatureMomentGravityCenter.h>
51 #include <visp/vpFeatureMomentBasic.h>
52 #include <visp/vpFeatureMomentDatabase.h>
53 
54 
64  bool found_featuremoment_basic;
65 
66  vpFeatureMomentBasic& featureMomentBasic= (static_cast<vpFeatureMomentBasic&>(featureMoments->get("vpFeatureMomentBasic",found_featuremoment_basic)));
67  vpMomentObject& momentObject = moment->getObject();
68 
69  if(!found_featuremoment_basic) throw vpException(vpException::notInitialized,"vpFeatureMomentBasic not found");
70 
71 
72  interaction_matrices[0].resize(1,6);
73  interaction_matrices[1].resize(1,6);
74 
75  interaction_matrices[0] = featureMomentBasic.interaction(1, 0) / momentObject.get(0, 0) - momentObject.get(1, 0) * pow(momentObject.get(0, 0), -0.2e1) * featureMomentBasic.interaction(0, 0);
76  interaction_matrices[1] = featureMomentBasic.interaction(0, 1) / momentObject.get(0, 0) - momentObject.get(0, 1) * pow(momentObject.get(0, 0), -0.2e1) * featureMomentBasic.interaction(0, 0);
77 
78 
79 }
80 
81 #else
82 
83 #include <vector>
84 #include <limits>
85 
86 #include <visp/vpMomentObject.h>
87 #include <visp/vpMomentDatabase.h>
88 #include <visp/vpMomentGravityCenter.h>
89 #include <visp/vpMomentCentered.h>
90 #include <visp/vpFeatureMomentGravityCenter.h>
91 #include <visp/vpMomentObject.h>
92 
93 
104  bool found_moment_centered;
105  bool found_moment_gravity;
106 
107  vpMomentCentered& momentCentered= (static_cast<vpMomentCentered&>(moments.get("vpMomentCentered",found_moment_centered)));
108  vpMomentGravityCenter& momentGravity = static_cast<vpMomentGravityCenter&>(moments.get("vpMomentGravityCenter",found_moment_gravity));
109 
110 
111  vpMomentObject& momentObject = moment->getObject();
112 
113  if(!found_moment_centered) throw vpException(vpException::notInitialized,"vpMomentCentered not found");
114  if(!found_moment_gravity) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
115 
116 
117  interaction_matrices[0].resize(1,6);
118  interaction_matrices[1].resize(1,6);
119  int epsilon;
120  if (momentObject.getType()==vpMomentObject::DISCRETE) {
121  epsilon=1;
122  } else {
123  epsilon=4;
124  }
125  double n11 = momentCentered.get(1,1)/momentObject.get(0,0);
126  double n20 = momentCentered.get(2,0)/momentObject.get(0,0);
127  double n02 = momentCentered.get(0,2)/momentObject.get(0,0);
128  double Xg = momentGravity.getXg();
129  double Yg = momentGravity.getYg();
130  double Zg_inv = A*Xg+B*Yg+C;
131  double Xgvz = Xg*Zg_inv+A*epsilon*n20+B*epsilon*n11;
132  double Ygvz = Yg*Zg_inv+A*epsilon*n11+B*epsilon*n02;
133  double Xgwx = Xg*Yg+epsilon*n11;
134  double Ygwy = -Xgwx;
135  double Xgwy = -(1+Xg*Xg+epsilon*n20);
136  double Ygwx = 1+Yg*Yg+epsilon*n02;
137 
138  int VX = 0;
139  int VY = 1;
140  int VZ = 2;
141  int WX = 3;
142  int WY = 4;
143  int WZ = 5;
144 
145  interaction_matrices[0][0][VX] = -Zg_inv;
146  interaction_matrices[0][0][VY] = 0;
147  interaction_matrices[0][0][VZ] = Xgvz;
148 
149  interaction_matrices[0][0][WX] = Xgwx;
150  interaction_matrices[0][0][WY] = Xgwy;
151  interaction_matrices[0][0][WZ] = Yg;
152 
153  interaction_matrices[1][0][VX] = 0;
154  interaction_matrices[1][0][VY] = -Zg_inv;
155  interaction_matrices[1][0][VZ] = Ygvz;
156 
157  interaction_matrices[1][0][WX] = Ygwx;
158  interaction_matrices[1][0][WY] = Ygwy;
159  interaction_matrices[1][0][WZ] = -Xg;
160 
161 }
162 
163 #endif
Functionality computation for basic moment feature. Computes the interaction matrix associated with v...
vpMomentObject & getObject() const
Definition: vpMoment.h:119
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)
vpFeatureMoment & get(const char *type, bool &found)