Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpSubRowVector.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 vpRowVector .
32
*/
33
34
#include <stdlib.h>
35
36
#include <visp3/core/vpException.h>
37
#include <visp3/core/vpSubRowVector.h>
38
39
BEGIN_VISP_NAMESPACE
41
vpSubRowVector::vpSubRowVector
() :
vpRowVector
(),
m_pColNum
(0),
m_parent
(nullptr) { }
42
49
vpSubRowVector::vpSubRowVector
(
vpRowVector
&v,
const
unsigned
int
&offset,
const
unsigned
int
&ncols)
50
:
vpRowVector
(),
m_pColNum
(0),
m_parent
(nullptr)
51
{
52
init
(v, offset, ncols);
53
}
54
61
void
vpSubRowVector::init
(
vpRowVector
&v,
const
unsigned
int
&offset,
const
unsigned
int
&ncols)
62
{
63
if
(!v.data) {
64
throw
(
vpException
(
vpException::fatalError
,
"Cannot initialize a sub-row "
65
"vector from an empty parent row vector"
));
66
}
67
68
if
((offset + ncols) <= v.getCols()) {
69
data
= v.data + offset;
70
71
rowNum
= 1;
72
colNum
= ncols;
73
74
m_pColNum
= v.getCols();
75
m_parent
= &v;
76
77
if
(
rowPtrs
) {
78
free(
rowPtrs
);
79
}
80
81
rowPtrs
= (
double
**)malloc(1 *
sizeof
(
double
*));
82
for
(
unsigned
int
i = 0; i < 1; ++i) {
83
rowPtrs
[i] = v.data + i + offset;
84
}
85
86
dsize
=
colNum
;
87
}
88
else
{
89
throw
(
vpException
(
vpException::dimensionError
,
"Cannot create a sub-row vector that is not completely "
90
"contained in the parent row vector"
));
91
}
92
}
93
97
vpSubRowVector::~vpSubRowVector
() {
data
=
nullptr
; }
98
104
void
vpSubRowVector::checkParentStatus
()
const
105
{
106
if
(!
data
) {
107
throw
(
vpException
(
vpException::fatalError
,
"The parent of the current sub-row vector has been destroyed"
));
108
}
109
if
(
m_pColNum
!=
m_parent
->getCols()) {
110
throw
(
vpException
(
vpException::dimensionError
,
"The size of the parent sub-row vector has changed"
));
111
}
112
}
113
120
vpSubRowVector
&
vpSubRowVector::operator=
(
const
vpSubRowVector
&B)
121
{
122
if
(
colNum
!= B.
getCols
()) {
123
throw
(
vpException
(
vpException::dimensionError
,
"Cannot initialize (1x%d) sub-row vector from (1x%d) sub-row vector"
,
124
colNum
, B.
getCols
()));
125
}
126
m_pColNum
= B.
m_pColNum
;
127
m_parent
= B.
m_parent
;
128
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
129
data
[i] = B[i];
130
}
131
132
return
*
this
;
133
}
134
141
vpSubRowVector
&
vpSubRowVector::operator=
(
const
vpRowVector
&B)
142
{
143
if
(
colNum
!= B.
getCols
()) {
144
throw
(
vpException
(
vpException::dimensionError
,
"Cannot initialize (1x%d) sub-row vector from (1x%d) row vector"
,
145
colNum
, B.
getCols
()));
146
}
147
148
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
149
data
[i] = B[i];
150
}
151
152
return
*
this
;
153
}
154
161
vpSubRowVector
&
vpSubRowVector::operator=
(
const
vpMatrix
&B)
162
{
163
if
((B.
getRows
() != 1) || (
colNum
!= B.
getCols
())) {
164
throw
(
vpException
(
vpException::dimensionError
,
"Cannot initialize (1x%d) sub-column vector from (%dx%d) matrix"
,
165
colNum
, B.
getRows
(), B.
getCols
()));
166
}
167
168
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
169
data
[i] = B[i][1];
170
}
171
return
*
this
;
172
}
173
178
vpSubRowVector
&
vpSubRowVector::operator=
(
const
double
&x)
179
{
180
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
181
data
[i] = x;
182
}
183
return
*
this
;
184
}
185
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
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
vpMatrix
Implementation of a matrix and operations on matrices.
Definition
vpMatrix.h:175
vpRowVector::vpRowVector
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
Definition
vpRowVector.h:127
vpRowVector::init
VP_DEPRECATED void init()
Definition
vpRowVector.h:340
vpSubRowVector::m_parent
vpRowVector * m_parent
Parent vpColVector.
Definition
vpSubRowVector.h:78
vpSubRowVector::operator=
vpSubRowVector & operator=(const vpSubRowVector &B)
Definition
vpSubRowVector.cpp:120
vpSubRowVector::~vpSubRowVector
virtual ~vpSubRowVector() VP_OVERRIDE
Definition
vpSubRowVector.cpp:97
vpSubRowVector::checkParentStatus
void checkParentStatus() const
Definition
vpSubRowVector.cpp:104
vpSubRowVector::vpSubRowVector
vpSubRowVector()
Default constructor that creates an empty vector.
Definition
vpSubRowVector.cpp:41
vpSubRowVector::m_pColNum
unsigned int m_pColNum
Number of row of parent vpColVector at initialization.
Definition
vpSubRowVector.h:76
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
matrix
vpSubRowVector.cpp
Generated by
1.17.0