Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureMomentArea.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 * Implementation of vpFeatureMomentArea associated to vpMomentArea
32 *
33 * Authors:
34 * Manikandan Bakthavatchalam
35 */
36#include <cassert>
37#include <limits> // numeric_limits
38#include <vector>
39#include <visp3/core/vpConfig.h>
40
41#include <visp3/core/vpMomentArea.h>
42#include <visp3/core/vpMomentGravityCenter.h>
43#include <visp3/core/vpMomentObject.h>
44#include <visp3/visual_features/vpFeatureMomentArea.h>
45#include <visp3/visual_features/vpFeatureMomentCentered.h>
46#include <visp3/visual_features/vpFeatureMomentDatabase.h>
47
60{
61
62 interaction_matrices.resize(1);
63 interaction_matrices[0].resize(1, 6);
64
65 // Retreive the moment object associated with this feature
66 vpMomentObject mobj = moment->getObject();
67 if (mobj.getType() == vpMomentObject::DISCRETE) {
68 // Get centered moments
69 bool found_centered;
70 const vpFeatureMomentCentered &momentCentered = static_cast<const vpFeatureMomentCentered &>(
71 featureMomentsDataBase->get("vpFeatureMomentCentered", found_centered));
72 if (!found_centered)
73 throw vpException(vpException::notInitialized, "vpFeatureMomentCentered not found");
74 interaction_matrices[0] = momentCentered.interaction(2, 0) + momentCentered.interaction(0, 2);
75 }
76 else {
77 // Get Xg and Yg
78 bool found_xgyg;
79 const vpMomentGravityCenter &momentGravity =
80 static_cast<const vpMomentGravityCenter &>(moments.get("vpMomentGravityCenter", found_xgyg));
81 if (!found_xgyg)
82 throw vpException(vpException::notInitialized, "vpMomentGravityCenter not found");
83
84 bool found_m00;
85 const vpMomentArea &areamoment = static_cast<const vpMomentArea &>(moments.get("vpMomentArea", found_m00));
86 if (!found_m00)
87 throw vpException(vpException::notInitialized, "vpMomentArea not found");
88
89 double Xg = momentGravity.getXg();
90 double Yg = momentGravity.getYg();
91
92 double a = areamoment.get()[0]; // Area scalar
93
94 assert(std::fabs(a - mobj.get(0, 0)) < a * std::numeric_limits<double>::epsilon());
95
96 interaction_matrices[0][0][0] = -a * A;
97 interaction_matrices[0][0][1] = -a * B;
98 interaction_matrices[0][0][2] = (3 * a) * (A * Xg + B * Yg) + (2 * C * a);
99 interaction_matrices[0][0][3] = 3 * a * Yg;
100 interaction_matrices[0][0][4] = -3 * a * Xg;
101 interaction_matrices[0][0][5] = 0.;
102 }
103}
104END_VISP_NAMESPACE
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition vpException.h:74
void compute_interaction() VP_OVERRIDE
Functionality computation for centered moment feature. Computes the interaction matrix associated wit...
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
std::vector< vpMatrix > interaction_matrices
vpFeatureMomentDatabase * featureMomentsDataBase
vpMomentDatabase & moments
const vpMoment * moment
Class handling the surface moment.
Class describing 2D gravity center moment.
Class for generic objects.
const std::vector< double > & get() const
vpObjectType getType() const
const std::vector< double > & get() const
Definition vpMoment.h:155