Visual Servoing Platform  version 3.0.0
vpMomentGravityCenterNormalized.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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  * 2D normalized gravity center moment descriptor (usually described by the pair Xn,Yn)
32  *
33  * Authors:
34  * Filip Novotny
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpMomentGravityCenterNormalized.h>
39 #include <visp3/core/vpMomentObject.h>
40 #include <visp3/core/vpMomentGravityCenter.h>
41 #include <visp3/core/vpMomentAreaNormalized.h>
42 
48  bool found_moment_gravity;
49  bool found_moment_surface_normalized;
50 
51  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(getMoments().get("vpMomentAreaNormalized",found_moment_surface_normalized));
52  const vpMomentGravityCenter& momentGravity = static_cast<const vpMomentGravityCenter&>(getMoments().get("vpMomentGravityCenter",found_moment_gravity));
53 
54  if(!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
55  if(!found_moment_gravity) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
56 
57  double Xn = momentGravity.get()[0]*momentSurfaceNormalized.get()[0];
58  double Yn = momentGravity.get()[1]*momentSurfaceNormalized.get()[0];
59 
60  values[0] = Xn;
61  values[1] = Yn;
62 
63 }
64 
69 
73 VISP_EXPORT std::ostream & operator<<(std::ostream & os, const vpMomentGravityCenterNormalized& m){
74  os << (__FILE__) << std::endl;
75  os << "(Xn,Yn) = (" << m.values[0] << ", " << m.values[1] << ")" << std::endl;
76  return os;
77 }
78 
85  os << (__FILE__) << std::endl;
86  bool found_moment_gravity;
87  bool found_moment_surface_normalized;
88 
89  const vpMomentAreaNormalized& momentSurfaceNormalized = static_cast<const vpMomentAreaNormalized&>(getMoments().get("vpMomentAreaNormalized",found_moment_surface_normalized));
90  const vpMomentGravityCenter& momentGravity = static_cast<const vpMomentGravityCenter&>(getMoments().get("vpMomentGravityCenter",found_moment_gravity));
91 
92  if(!found_moment_surface_normalized) throw vpException(vpException::notInitialized,"vpMomentAreaNormalized not found");
93  if(!found_moment_gravity) throw vpException(vpException::notInitialized,"vpMomentGravityCenter not found");
94  os << "Xg = " << momentGravity.get()[0] << "\t" << "Yg = " << momentGravity.get()[1] << std::endl;
95  os << "An = " << momentSurfaceNormalized.get()[0] << std::endl;
96 }
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:148
Class describing 2D normalized gravity center moment.
error that can be emited by ViSP classes.
Definition: vpException.h:73
const vpMoment & get(const char *type, bool &found) const
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
Class describing 2D gravity center moment.
vpMomentDatabase & getMoments() const
Definition: vpMoment.h:119
const std::vector< double > & get() const
void printDependencies(std::ostream &os) const
std::vector< double > values
Definition: vpMoment.h:114