Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpMomentCommon.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Pre-filled moment database with all commonly used moments.
33  *
34  * Authors:
35  * Filip Novotny
36  *
37  *****************************************************************************/
38 
39 #include <visp3/core/vpMomentCommon.h>
40 #include <visp3/core/vpMomentObject.h>
41 
54 vpMomentCommon::vpMomentCommon(double dstSurface, const std::vector<double> &ref, double refAlpha, double dstZ,
55  bool flg_sxsyfromnormalized)
56  : vpMomentDatabase(), momentBasic(), momentGravity(), momentCentered(), momentGravityNormalized(),
57  momentSurfaceNormalized(dstSurface, dstZ), momentCInvariant(), momentAlpha(ref, refAlpha), momentArea()
58 {
59  momentCInvariant = new vpMomentCInvariant(flg_sxsyfromnormalized);
60 
61  momentBasic.linkTo(*this);
62  momentGravity.linkTo(*this);
63  momentCentered.linkTo(*this);
64  momentGravityNormalized.linkTo(*this);
65  momentSurfaceNormalized.linkTo(*this);
66  momentCInvariant->linkTo(*this);
67  momentAlpha.linkTo(*this);
68  momentArea.linkTo(*this);
69 }
70 
127 {
128  try {
130 
131  momentGravity.compute();
132  momentCentered.compute();
133  momentAlpha.compute();
134  momentCInvariant->compute();
135 
136  momentSurfaceNormalized.compute();
137  momentGravityNormalized.compute();
138  momentArea.compute();
139 
140  } catch (const char *ex) {
141  std::cout << "exception:" << ex << std::endl;
142  }
143 }
144 
150 {
151  vpMomentDatabase moments;
152 
153  vpMomentGravityCenter momentGravity;
154  momentGravity.linkTo(moments);
155  vpMomentCentered momentCentered;
156  momentCentered.linkTo(moments);
157 
158  moments.updateAll(object);
159 
160  momentGravity.compute();
161  momentCentered.compute();
162 
163  double a;
164  if (object.getType() == vpMomentObject::DISCRETE)
165  a = momentCentered.get(2, 0) + momentCentered.get(0, 2);
166  else
167  a = object.get(0, 0);
168 
169  return a;
170 }
171 
177 {
178  vpMomentDatabase moments;
179 
180  vpMomentGravityCenter momentGravity;
181  momentGravity.linkTo(moments);
182  vpMomentCentered momentCentered;
183  momentCentered.linkTo(moments);
184  vpMomentAlpha momentAlpha;
185  momentAlpha.linkTo(moments);
186 
187  moments.updateAll(object);
188  momentGravity.compute();
189  momentCentered.compute();
190  momentAlpha.compute();
191 
192  return momentAlpha.get();
193 }
194 
199 std::vector<double> vpMomentCommon::getMu3(vpMomentObject &object)
200 {
201  vpMomentDatabase moments;
202 
203  vpMomentGravityCenter momentGravity;
204  momentGravity.linkTo(moments);
205  vpMomentCentered momentCentered;
206  momentCentered.linkTo(moments);
207 
208  moments.updateAll(object);
209 
210  momentGravity.compute();
211  momentCentered.compute();
212 
213  std::vector<double> mu(4);
214  unsigned int idx = 0;
215  for (unsigned int j = 0; j < 4; j++) {
216  for (unsigned int i = 0; i < 4; i++) {
217  if (i + j == 3) {
218  mu[idx] = momentCentered.get(i, j);
219  idx++;
220  }
221  }
222  }
223  return mu;
224 }
225 
227 {
228  if (momentCInvariant)
229  delete momentCInvariant;
230 }
double get(unsigned int i, unsigned int j) const
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:98
virtual ~vpMomentCommon()
Class for generic objects.
This class allows to register all vpMoments so they can access each other according to their dependen...
double get() const
static std::vector< double > getMu3(vpMomentObject &object)
virtual void updateAll(vpMomentObject &object)
This class defines the double-indexed centered moment descriptor .
This class defines the orientation of the object inside the plane parallel to the object...
static double getSurface(vpMomentObject &object)
Class describing 2D gravity center moment.
void updateAll(vpMomentObject &object)
static double getAlpha(vpMomentObject &object)
vpMomentCommon(double dstSurface, const std::vector< double > &ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)