Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMomentCommon.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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 * Pre-filled moment database with all commonly used moments.
32 *
33 * Authors:
34 * Filip Novotny
35 */
36
37#include <visp3/core/vpMomentCommon.h>
38#include <visp3/core/vpMomentObject.h>
39
53vpMomentCommon::vpMomentCommon(double dstSurface, const std::vector<double> &ref, double refAlpha, double dstZ,
54 bool flg_sxsyfromnormalized)
55 : vpMomentDatabase(), momentBasic(), momentGravity(), momentCentered(), momentGravityNormalized(),
56 momentSurfaceNormalized(dstSurface, dstZ), momentCInvariant(), momentAlpha(ref, refAlpha), momentArea()
57{
58 momentCInvariant = new vpMomentCInvariant(flg_sxsyfromnormalized);
59
60 momentBasic.linkTo(*this);
61 momentGravity.linkTo(*this);
62 momentCentered.linkTo(*this);
63 momentGravityNormalized.linkTo(*this);
64 momentSurfaceNormalized.linkTo(*this);
65 momentCInvariant->linkTo(*this);
66 momentAlpha.linkTo(*this);
67 momentArea.linkTo(*this);
68}
69
129{
130 try {
132
133 momentGravity.compute();
134 momentCentered.compute();
135 momentAlpha.compute();
136 momentCInvariant->compute();
137
138 momentSurfaceNormalized.compute();
139 momentGravityNormalized.compute();
140 momentArea.compute();
141 }
142 catch (const vpException &e) {
143 std::cout << "Exception in vpMomentCommon:" << e.getStringMessage() << std::endl;
144 }
145}
146
152{
153 vpMomentDatabase moments;
154
155 vpMomentGravityCenter momentGravity;
156 momentGravity.linkTo(moments);
157 vpMomentCentered momentCentered;
158 momentCentered.linkTo(moments);
159
160 moments.updateAll(object);
161
162 momentGravity.compute();
163 momentCentered.compute();
164
165 double a;
166 if (object.getType() == vpMomentObject::DISCRETE)
167 a = momentCentered.get(2, 0) + momentCentered.get(0, 2);
168 else
169 a = object.get(0, 0);
170
171 return a;
172}
173
179{
180 vpMomentDatabase moments;
181
182 vpMomentGravityCenter momentGravity;
183 momentGravity.linkTo(moments);
184 vpMomentCentered momentCentered;
185 momentCentered.linkTo(moments);
186 vpMomentAlpha momentAlpha;
187 momentAlpha.linkTo(moments);
188
189 moments.updateAll(object);
190 momentGravity.compute();
191 momentCentered.compute();
192 momentAlpha.compute();
193
194 return momentAlpha.get();
195}
196
201std::vector<double> vpMomentCommon::getMu3(vpMomentObject &object)
202{
203 vpMomentDatabase moments;
204
205 vpMomentGravityCenter momentGravity;
206 momentGravity.linkTo(moments);
207 vpMomentCentered momentCentered;
208 momentCentered.linkTo(moments);
209
210 moments.updateAll(object);
211
212 momentGravity.compute();
213 momentCentered.compute();
214
215 std::vector<double> mu(4);
216 unsigned int idx = 0;
217 for (unsigned int j = 0; j < 4; j++) {
218 for (unsigned int i = 0; i < 4; i++) {
219 if (i + j == 3) {
220 mu[idx] = momentCentered.get(i, j);
221 idx++;
222 }
223 }
224 }
225 return mu;
226}
227
229{
230 if (momentCInvariant)
231 delete momentCInvariant;
232}
233END_VISP_NAMESPACE
error that can be emitted by ViSP classes.
Definition vpException.h:60
This class defines the orientation of the object inside the plane parallel to the object.
This class defines the double-indexed centered moment descriptor .
static std::vector< double > getMu3(vpMomentObject &object)
void updateAll(vpMomentObject &object) VP_OVERRIDE
static double getAlpha(vpMomentObject &object)
static double getSurface(vpMomentObject &object)
virtual ~vpMomentCommon() VP_OVERRIDE
virtual void updateAll(vpMomentObject &object)
Class describing 2D gravity center moment.
Class for generic objects.
void linkTo(vpMomentDatabase &moments)
Definition vpMoment.cpp:114