Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
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 
55 vpMomentCommon::vpMomentCommon(double dstSurface, const std::vector<double> &ref, double refAlpha, double dstZ,
56  bool flg_sxsyfromnormalized)
57  : vpMomentDatabase(), momentBasic(), momentGravity(), momentCentered(), momentGravityNormalized(),
58  momentSurfaceNormalized(dstSurface, dstZ), momentCInvariant(), momentAlpha(ref, refAlpha), momentArea()
59 {
60  momentCInvariant = new vpMomentCInvariant(flg_sxsyfromnormalized);
61 
62  momentBasic.linkTo(*this);
63  momentGravity.linkTo(*this);
64  momentCentered.linkTo(*this);
65  momentGravityNormalized.linkTo(*this);
66  momentSurfaceNormalized.linkTo(*this);
67  momentCInvariant->linkTo(*this);
68  momentAlpha.linkTo(*this);
69  momentArea.linkTo(*this);
70 }
71 
131 {
132  try {
134 
135  momentGravity.compute();
136  momentCentered.compute();
137  momentAlpha.compute();
138  momentCInvariant->compute();
139 
140  momentSurfaceNormalized.compute();
141  momentGravityNormalized.compute();
142  momentArea.compute();
143  }
144  catch (const vpException &e) {
145  std::cout << "Exception in vpMomentCommon:" << e.getStringMessage() << std::endl;
146  }
147 }
148 
154 {
155  vpMomentDatabase moments;
156 
157  vpMomentGravityCenter momentGravity;
158  momentGravity.linkTo(moments);
159  vpMomentCentered momentCentered;
160  momentCentered.linkTo(moments);
161 
162  moments.updateAll(object);
163 
164  momentGravity.compute();
165  momentCentered.compute();
166 
167  double a;
168  if (object.getType() == vpMomentObject::DISCRETE)
169  a = momentCentered.get(2, 0) + momentCentered.get(0, 2);
170  else
171  a = object.get(0, 0);
172 
173  return a;
174 }
175 
181 {
182  vpMomentDatabase moments;
183 
184  vpMomentGravityCenter momentGravity;
185  momentGravity.linkTo(moments);
186  vpMomentCentered momentCentered;
187  momentCentered.linkTo(moments);
188  vpMomentAlpha momentAlpha;
189  momentAlpha.linkTo(moments);
190 
191  moments.updateAll(object);
192  momentGravity.compute();
193  momentCentered.compute();
194  momentAlpha.compute();
195 
196  return momentAlpha.get();
197 }
198 
203 std::vector<double> vpMomentCommon::getMu3(vpMomentObject &object)
204 {
205  vpMomentDatabase moments;
206 
207  vpMomentGravityCenter momentGravity;
208  momentGravity.linkTo(moments);
209  vpMomentCentered momentCentered;
210  momentCentered.linkTo(moments);
211 
212  moments.updateAll(object);
213 
214  momentGravity.compute();
215  momentCentered.compute();
216 
217  std::vector<double> mu(4);
218  unsigned int idx = 0;
219  for (unsigned int j = 0; j < 4; j++) {
220  for (unsigned int i = 0; i < 4; i++) {
221  if (i + j == 3) {
222  mu[idx] = momentCentered.get(i, j);
223  idx++;
224  }
225  }
226  }
227  return mu;
228 }
229 
231 {
232  if (momentCInvariant)
233  delete momentCInvariant;
234 }
235 END_VISP_NAMESPACE
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const std::string & getStringMessage() const
Definition: vpException.cpp:67
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)
void updateAll(vpMomentObject &object) VP_OVERRIDE
static double getAlpha(vpMomentObject &object)
static double getSurface(vpMomentObject &object)
vpMomentCommon(double dstSurface, const std::vector< double > &ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)
virtual ~vpMomentCommon() 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:114