ViSP  2.8.0
vpFeatureMomentArea.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureMomentArea.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 of vpFeatureMomentArea associated to vpMomentArea
36  *
37  * Authors:
38  * Manikandan Bakthavatchalam
39  *
40  *****************************************************************************/
41 #include <visp/vpConfig.h>
42 #include <vector>
43 #include <limits>
44 #include <cassert>
45 #include <limits> // numeric_limits
46 
47 #include <visp/vpFeatureMomentArea.h>
48 #include <visp/vpMomentObject.h>
49 #include <visp/vpMomentGravityCenter.h>
50 #include <visp/vpMomentArea.h>
51 #include <visp/vpFeatureMomentDatabase.h>
52 
61 
62  interaction_matrices.resize(1);
63  interaction_matrices[0].resize(1,6);
64 
65  // Retreive the moment object associated with this feature
67  if (mobj.getType()==vpMomentObject::DISCRETE) {
68  /*
69  * The interaction matrix for the discrete case is zero
70  * since the feature m00 is constant.
71  * Refer thesis of Omar Tahri 2005 [Section 3.4.22]
72  */
73  interaction_matrices[0][0][0] = 0.;
74  interaction_matrices[0][0][1] = 0.;
75  interaction_matrices[0][0][2] = 0.;
76  interaction_matrices[0][0][3] = 0.;
77  interaction_matrices[0][0][4] = 0.;
78  interaction_matrices[0][0][5] = 0.;
79  }
80  else {
81  // Get Xg and Yg
82  bool found_xgyg;
83  vpMomentGravityCenter& momentGravity = static_cast<vpMomentGravityCenter&>(moments.get("vpMomentGravityCenter",found_xgyg));
84  if (!found_xgyg) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
85 
86  bool found_m00;
87  vpMomentArea& areamoment = static_cast<vpMomentArea&>(moments.get("vpMomentArea", found_m00));
88  if (!found_m00) throw vpException(vpException::notInitialized,"vpMomentArea not found");
89 
90  double Xg = momentGravity.getXg();
91  double Yg = momentGravity.getYg();
92 
93  double a = areamoment.get()[0]; // Area scalar
94  //assert(a==mobj.get(0,0));
95  assert(std::fabs(a-mobj.get(0,0)) < a*std::numeric_limits<double>::epsilon());
96 
97  interaction_matrices[0][0][0] = -a*A;
98  interaction_matrices[0][0][1] = -a*B;
99  interaction_matrices[0][0][2] = (3*a)*(A*Xg+B*Yg)+(2*C*a);
100  interaction_matrices[0][0][3] = 3*a*Yg;
101  interaction_matrices[0][0][4] = -3*a*Xg;
102  interaction_matrices[0][0][5] = 0.;
103  }
104 }
vpMomentObject & getObject() const
Definition: vpMoment.h:119
error that can be emited by ViSP classes.
Definition: vpException.h:75
Class for generic objects.
std::vector< vpMatrix > interaction_matrices
Class handling the surface moment.
Definition: vpMomentArea.h:57
vpMoment & get(const char *type, bool &found)
std::vector< double > & get()
vpMomentDatabase & moments
Class describing 2D gravity center moment.
vpObjectType getType() const
std::vector< double > & get()
Definition: vpMoment.h:125