Visual Servoing Platform  version 3.6.1 under development (2024-04-23)
vpMomentCommon.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 
126 {
127  try {
129 
130  momentGravity.compute();
131  momentCentered.compute();
132  momentAlpha.compute();
133  momentCInvariant->compute();
134 
135  momentSurfaceNormalized.compute();
136  momentGravityNormalized.compute();
137  momentArea.compute();
138  }
139  catch (const vpException &e) {
140  std::cout << "Exception in vpMomentCommon:" << e.getStringMessage() << std::endl;
141  }
142 }
143 
149 {
150  vpMomentDatabase moments;
151 
152  vpMomentGravityCenter momentGravity;
153  momentGravity.linkTo(moments);
154  vpMomentCentered momentCentered;
155  momentCentered.linkTo(moments);
156 
157  moments.updateAll(object);
158 
159  momentGravity.compute();
160  momentCentered.compute();
161 
162  double a;
163  if (object.getType() == vpMomentObject::DISCRETE)
164  a = momentCentered.get(2, 0) + momentCentered.get(0, 2);
165  else
166  a = object.get(0, 0);
167 
168  return a;
169 }
170 
176 {
177  vpMomentDatabase moments;
178 
179  vpMomentGravityCenter momentGravity;
180  momentGravity.linkTo(moments);
181  vpMomentCentered momentCentered;
182  momentCentered.linkTo(moments);
183  vpMomentAlpha momentAlpha;
184  momentAlpha.linkTo(moments);
185 
186  moments.updateAll(object);
187  momentGravity.compute();
188  momentCentered.compute();
189  momentAlpha.compute();
190 
191  return momentAlpha.get();
192 }
193 
198 std::vector<double> vpMomentCommon::getMu3(vpMomentObject &object)
199 {
200  vpMomentDatabase moments;
201 
202  vpMomentGravityCenter momentGravity;
203  momentGravity.linkTo(moments);
204  vpMomentCentered momentCentered;
205  momentCentered.linkTo(moments);
206 
207  moments.updateAll(object);
208 
209  momentGravity.compute();
210  momentCentered.compute();
211 
212  std::vector<double> mu(4);
213  unsigned int idx = 0;
214  for (unsigned int j = 0; j < 4; j++) {
215  for (unsigned int i = 0; i < 4; i++) {
216  if (i + j == 3) {
217  mu[idx] = momentCentered.get(i, j);
218  idx++;
219  }
220  }
221  }
222  return mu;
223 }
224 
226 {
227  if (momentCInvariant)
228  delete momentCInvariant;
229 }
error that can be emitted by ViSP classes.
Definition: vpException.h:59
const std::string & getStringMessage() const
Definition: vpException.cpp:66
This class defines the orientation of the object inside the plane parallel to the object.
double get() const
This class defines the double-indexed centered moment descriptor .
double get(unsigned int i, unsigned int j) const
static std::vector< double > getMu3(vpMomentObject &object)
vpMomentCommon(double dstSurface, const std::vector< double > &ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)
static double getAlpha(vpMomentObject &object)
static double getSurface(vpMomentObject &object)
virtual ~vpMomentCommon() vp_override
void updateAll(vpMomentObject &object) vp_override
This class allows to register all vpMoments so they can access each other according to their dependen...
virtual void updateAll(vpMomentObject &object)
Class describing 2D gravity center moment.
Class for generic objects.
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:95