Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpSubColVector.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 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
* Mask on a vpColVector.
32
*/
33
34
#include <stdlib.h>
35
36
#include <visp3/core/vpException.h>
37
#include <visp3/core/vpSubColVector.h>
38
39
BEGIN_VISP_NAMESPACE
41
vpSubColVector::vpSubColVector
() :
vpColVector
(),
m_pRowNum
(0),
m_parent
(nullptr) { }
42
49
vpSubColVector::vpSubColVector
(
vpColVector
&v,
const
unsigned
int
&offset,
const
unsigned
int
&nrows)
50
:
vpColVector
(),
m_pRowNum
(0),
m_parent
(nullptr)
51
{
52
init
(v, offset, nrows);
53
}
54
61
void
vpSubColVector::init
(
vpColVector
&v,
const
unsigned
int
&offset,
const
unsigned
int
&nrows)
62
{
63
if
(!v.data) {
64
throw
(
vpException
(
vpException::fatalError
,
"Cannot initialize a "
65
"sub-column vector from an "
66
"empty parent column vector"
));
67
}
68
69
if
((offset + nrows) <= v.getRows()) {
70
data
= v.data + offset;
71
72
rowNum
= nrows;
73
colNum
= 1;
74
75
m_pRowNum
= v.getRows();
76
m_parent
= &v;
77
78
if
(
rowPtrs
) {
79
free(
rowPtrs
);
80
}
81
82
rowPtrs
= (
double
**)malloc(
m_parent
->getRows() *
sizeof
(
double
*));
83
for
(
unsigned
int
i = 0; i < nrows; ++i) {
84
rowPtrs
[i] = v.data + (i + offset);
85
}
86
87
dsize
=
rowNum
;
88
}
89
else
{
90
throw
(
vpException
(
vpException::dimensionError
,
"Cannot create a sub-column vector that is not "
91
"completely contained in the parent column vector"
));
92
}
93
}
94
98
vpSubColVector::~vpSubColVector
() {
data
=
nullptr
; }
99
105
void
vpSubColVector::checkParentStatus
()
const
106
{
107
if
(!
data
) {
108
throw
(
vpException
(
vpException::fatalError
,
"The parent of the current sub-column vector has been destroyed"
));
109
}
110
if
(
m_pRowNum
!=
m_parent
->getRows()) {
111
throw
(
vpException
(
vpException::dimensionError
,
"The size of the parent sub-column vector has changed"
));
112
}
113
}
114
121
vpSubColVector
&
vpSubColVector::operator=
(
const
vpSubColVector
&B)
122
{
123
if
(
rowNum
!= B.
getRows
()) {
124
throw
(
vpException
(
vpException::dimensionError
,
125
"Cannot initialize (%dx1) sub-column vector from "
126
"(%dx1) sub-column vector"
,
127
rowNum
, B.
getRows
()));
128
}
129
m_pRowNum
= B.
m_pRowNum
;
130
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
131
data
[i] = B[i];
132
}
133
return
*
this
;
134
}
135
142
vpSubColVector
&
vpSubColVector::operator=
(
const
vpColVector
&B)
143
{
144
if
(
rowNum
!= B.
getRows
()) {
145
throw
(
vpException
(
vpException::dimensionError
,
146
"Cannot initialize (%dx1) sub-column vector from "
147
"(%dx1) column vector"
,
148
rowNum
, B.
getRows
()));
149
}
150
151
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
152
data
[i] = B[i];
153
}
154
155
return
*
this
;
156
}
157
164
vpSubColVector
&
vpSubColVector::operator=
(
const
vpMatrix
&B)
165
{
166
if
((B.
getCols
() != 1) || (
rowNum
!= B.
getRows
())) {
167
throw
(
vpException
(
vpException::dimensionError
,
"Cannot initialize (%dx1) sub-column vector from (%dx%d) matrix"
,
168
rowNum
, B.
getRows
(), B.
getCols
()));
169
}
170
171
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
172
data
[i] = B[i][1];
173
}
174
return
*
this
;
175
}
176
182
vpSubColVector
&
vpSubColVector::operator=
(
const
double
&x)
183
{
184
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
185
data
[i] = x;
186
}
187
return
*
this
;
188
}
189
193
vpSubColVector
&
vpSubColVector::operator=
(
const
vpTranslationVector
&tv)
194
{
195
unsigned
int
k = tv.
getRows
();
196
if
(
rowNum
!= k) {
197
try
{
198
resize
(k);
199
}
200
catch
(...) {
201
throw
;
202
}
203
}
204
205
memcpy(
data
, tv.
data
,
rowNum
*
sizeof
(
double
));
206
return
*
this
;
207
}
208
212
vpSubColVector
&
vpSubColVector::operator=
(
const
vpRotationVector
&rv)
213
{
214
unsigned
int
k = rv.
getRows
();
215
if
(
rowNum
!= k) {
216
try
{
217
resize
(k);
218
}
219
catch
(...) {
220
throw
;
221
}
222
}
223
224
memcpy(
data
, rv.
data
,
rowNum
*
sizeof
(
double
));
225
return
*
this
;
226
}
227
231
vpSubColVector
&
vpSubColVector::operator=
(
const
vpPoseVector
&p)
232
{
233
unsigned
int
k = p.getRows();
234
if
(
rowNum
!= k) {
235
try
{
236
resize
(k);
237
}
238
catch
(...) {
239
throw
;
240
}
241
}
242
243
memcpy(
data
, p.data,
rowNum
*
sizeof
(
double
));
244
return
*
this
;
245
}
246
END_VISP_NAMESPACE
vpArray2D::getCols
unsigned int getCols() const
Definition
vpArray2D.h:423
vpArray2D< double >::data
double * data
Definition
vpArray2D.h:149
vpArray2D< double >::rowPtrs
double ** rowPtrs
Definition
vpArray2D.h:1205
vpArray2D< double >::rowNum
unsigned int rowNum
Definition
vpArray2D.h:1201
vpArray2D< double >::dsize
unsigned int dsize
Definition
vpArray2D.h:1207
vpArray2D::getRows
unsigned int getRows() const
Definition
vpArray2D.h:433
vpArray2D< double >::colNum
unsigned int colNum
Definition
vpArray2D.h:1203
vpColVector::vpMatrix
friend class vpMatrix
Definition
vpColVector.h:192
vpColVector::vpColVector
vpColVector()
Definition
vpColVector.h:198
vpColVector::init
VP_DEPRECATED void init()
Definition
vpColVector.h:1466
vpColVector::resize
void resize(unsigned int i, bool flagNullify=true)
Definition
vpColVector.h:1159
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpException::fatalError
@ fatalError
Fatal error.
Definition
vpException.h:72
vpPoseVector
Implementation of a pose vector and operations on poses.
Definition
vpPoseVector.h:203
vpRotationVector
Implementation of a generic rotation vector.
Definition
vpRotationVector.h:103
vpSubColVector::checkParentStatus
void checkParentStatus() const
Definition
vpSubColVector.cpp:105
vpSubColVector::operator=
vpSubColVector & operator=(const vpSubColVector &B)
Definition
vpSubColVector.cpp:121
vpSubColVector::m_parent
vpColVector * m_parent
Parent vpColVector.
Definition
vpSubColVector.h:82
vpSubColVector::vpSubColVector
vpSubColVector()
Default constructor that creates an empty vector.
Definition
vpSubColVector.cpp:41
vpSubColVector::~vpSubColVector
virtual ~vpSubColVector() VP_OVERRIDE
Definition
vpSubColVector.cpp:98
vpSubColVector::m_pRowNum
unsigned int m_pRowNum
Number of row of parent vpColVector at initialization.
Definition
vpSubColVector.h:80
vpTranslationVector
Class that consider the case of a translation vector.
Definition
vpTranslationVector.h:119
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
matrix
vpSubColVector.cpp
Generated by
1.17.0