Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpMomentCentered.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
* Centered moment descriptor
32
*/
33
34
#include <cassert>
35
#include <exception>
36
#include <visp3/core/vpMomentCentered.h>
37
#include <visp3/core/vpMomentGravityCenter.h>
38
#include <visp3/core/vpMomentObject.h>
39
40
BEGIN_VISP_NAMESPACE
48
void
vpMomentCentered::set
(
unsigned
int
i,
unsigned
int
j,
double
value)
49
{
50
vpMomentObject
mobj =
getObject
();
51
assert(i + j <= mobj.
getOrder
());
52
if
(i + j > mobj.
getOrder
())
53
throw
vpException
(
vpException::badValue
,
"You cannot set that value."
);
54
values
[j * (mobj.
getOrder
() + 1) + i] = value;
55
}
56
61
void
vpMomentCentered::compute
()
62
{
63
bool
found_moment_gravity;
64
values
.resize((
getObject
().getOrder() + 1) * (
getObject
().getOrder() + 1));
65
66
const
vpMomentGravityCenter
&momentGravity =
67
static_cast<
const
vpMomentGravityCenter
&
>
(
getMoments
().
get
(
"vpMomentGravityCenter"
, found_moment_gravity));
68
if
(!found_moment_gravity)
69
throw
vpException
(
vpException::notInitialized
,
"vpMomentGravityCenter not found"
);
70
71
unsigned
int
order =
getObject
().
getOrder
() + 1;
72
for
(
unsigned
int
j = 0; j < (order); j++) {
73
for
(
unsigned
int
i = 0; i < order - j; i++) {
74
unsigned
int
c = order * j + i;
75
values
[c] = 0;
76
for
(
unsigned
int
k = 0; k <= i; k++) {
77
double
Xg_i_k = pow(-momentGravity.
get
()[0],
static_cast<
int
>
(i - k));
78
double
comb_i_k =
static_cast<
double
>
(
vpMath::comb
(i, k));
79
for
(
unsigned
int
l = 0; l <= j; l++) {
80
values
[c] +=
static_cast<
double
>
(comb_i_k *
vpMath::comb
(j, l) * Xg_i_k *
81
pow(-momentGravity.
get
()[1],
static_cast<
int
>
(j - l)) *
getObject
().
get
(k, l));
82
}
83
}
84
}
85
}
86
}
87
91
vpMomentCentered::vpMomentCentered
() :
vpMoment
() { }
92
99
double
vpMomentCentered::get
(
unsigned
int
i,
unsigned
int
j)
const
100
{
101
unsigned
int
order =
getObject
().
getOrder
();
102
assert(i + j <= order);
103
if
(i + j > order)
104
throw
vpException
(
vpException::badValue
,
"The requested value has not "
105
"been computed, you should "
106
"specify a higher order."
);
107
108
return
values
[j * (order + 1) + i];
109
}
110
114
void
vpMomentCentered::printWithIndices
(std::ostream &os)
const
115
{
116
unsigned
int
orderp1 =
getObject
().
getOrder
() + 1;
117
for
(
unsigned
int
k = 0; k < orderp1; k++) {
118
for
(
unsigned
int
l = 0; l < orderp1 - k; l++) {
119
os <<
"mu["
<< k <<
","
<< l <<
"] = "
<< this->
get
(k, l) <<
"\t"
;
120
}
121
os << std::endl;
122
}
123
os << std::endl;
124
}
125
132
void
vpMomentCentered::printDependencies
(std::ostream &os)
const
133
{
134
os << (__FILE__) << std::endl;
135
/*
136
Retreive the raw moments
137
*/
138
const
vpMomentObject
objt =
getObject
();
139
vpMomentObject::printWithIndices
(objt, os);
140
141
/*
142
Get xg,yg
143
*/
144
bool
found_moment_gravity;
145
const
vpMomentGravityCenter
&momentGravity =
146
static_cast<
const
vpMomentGravityCenter
&
>
(
getMoments
().
get
(
"vpMomentGravityCenter"
, found_moment_gravity));
147
if
(!found_moment_gravity)
148
throw
vpException
(
vpException::notInitialized
,
"vpMomentGravityCenter not found"
);
149
os <<
"Xg = "
<< momentGravity.
getXg
() <<
"\t"
150
<<
"Yg = "
<< momentGravity.
getYg
() << std::endl;
151
}
152
171
VISP_EXPORT std::ostream &
operator<<
(std::ostream &os,
const
vpMomentCentered
&m)
172
{
173
for
(
unsigned
int
i = 0; i < m.
values
.size(); i++) {
174
if
(i % (m.
getObject
().
getOrder
() + 1) == 0)
175
os << std::endl;
176
177
if
((i % (m.
getObject
().
getOrder
() + 1) + i / (m.
getObject
().
getOrder
() + 1)) < m.
getObject
().
getOrder
() + 1)
178
os << m.
values
[i];
179
else
180
os <<
"x"
;
181
182
os <<
"\t"
;
183
}
184
os << std::endl;
185
m.
printWithIndices
(os);
186
return
os;
187
}
188
END_VISP_NAMESPACE
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::badValue
@ badValue
Used to indicate that a value is not in the allowed range.
Definition
vpException.h:73
vpException::notInitialized
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition
vpException.h:74
vpMath::comb
static long double comb(unsigned int n, unsigned int p)
Definition
vpMath.h:398
vpMomentCentered::get
const std::vector< double > & get() const
Definition
vpMomentCentered.h:131
vpMomentCentered::vpMomentCentered
vpMomentCentered()
Definition
vpMomentCentered.cpp:91
vpMomentCentered::compute
void compute() VP_OVERRIDE
Definition
vpMomentCentered.cpp:61
vpMomentCentered::printWithIndices
void printWithIndices(std::ostream &os) const
Definition
vpMomentCentered.cpp:114
vpMomentCentered::operator<<
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpMomentCentered &v)
Definition
vpMomentCentered.cpp:171
vpMomentCentered::printDependencies
void printDependencies(std::ostream &os) const VP_OVERRIDE
Definition
vpMomentCentered.cpp:132
vpMomentCentered::set
void set(unsigned int i, unsigned int j, double value)
Definition
vpMomentCentered.cpp:48
vpMomentDatabase::get
const vpMoment & get(const std::string &moment_name, bool &found) const
Definition
vpMomentDatabase.cpp:63
vpMomentGravityCenter
Class describing 2D gravity center moment.
Definition
vpMomentGravityCenter.h:117
vpMomentGravityCenter::get
const std::vector< double > & get() const
Definition
vpMomentGravityCenter.cpp:60
vpMomentGravityCenter::getYg
double getYg() const
Definition
vpMomentGravityCenter.h:134
vpMomentGravityCenter::getXg
double getXg() const
Definition
vpMomentGravityCenter.h:129
vpMomentObject
Class for generic objects.
Definition
vpMomentObject.h:225
vpMomentObject::printWithIndices
static void printWithIndices(const vpMomentObject &momobj, std::ostream &os)
Definition
vpMomentObject.cpp:577
vpMomentObject::getOrder
unsigned int getOrder() const
Definition
vpMomentObject.h:288
vpMomentObject::get
const std::vector< double > & get() const
Definition
vpMomentObject.cpp:538
vpMoment::getObject
const vpMomentObject & getObject() const
Definition
vpMoment.h:150
vpMoment::values
std::vector< double > values
Definition
vpMoment.h:113
vpMoment::getMoments
vpMomentDatabase & getMoments() const
Definition
vpMoment.h:118
vpMoment::vpMoment
vpMoment(const vpMoment &)=delete
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
tracking
moments
vpMomentCentered.cpp
Generated by
1.17.0