Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpSubMatrix.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 vpMatrix .
32
*/
33
34
#include <stdlib.h>
35
#include <visp3/core/vpDebug.h>
36
#include <visp3/core/vpException.h>
37
#include <visp3/core/vpMatrixException.h>
38
#include <visp3/core/vpSubMatrix.h>
39
40
BEGIN_VISP_NAMESPACE
41
vpSubMatrix::vpSubMatrix
() :
pRowNum
(0),
pColNum
(0),
parent
(nullptr) { }
42
51
vpSubMatrix::vpSubMatrix
(
vpMatrix
&m,
const
unsigned
int
&row_offset,
const
unsigned
int
&col_offset,
52
const
unsigned
int
&nrows,
const
unsigned
int
&ncols)
53
:
pRowNum
(0),
pColNum
(0),
parent
(nullptr)
54
{
55
init
(m, row_offset, col_offset, nrows, ncols);
56
}
57
66
void
vpSubMatrix::init
(
vpMatrix
&m,
const
unsigned
int
&row_offset,
const
unsigned
int
&col_offset,
67
const
unsigned
int
&nrows,
const
unsigned
int
&ncols)
68
{
69
70
if
(!m.
data
) {
71
throw
(
vpMatrixException
(
vpMatrixException::subMatrixError
,
"SubMatrix parent matrix is not allocated"
));
72
}
73
74
if
(((row_offset + nrows) <= m.
getRows
()) && ((col_offset + ncols) <= m.
getCols
())) {
75
data
= m.
data
;
76
parent
= &m;
77
rowNum
= nrows;
78
colNum
= ncols;
79
pRowNum
= m.
getRows
();
80
pColNum
= m.
getCols
();
81
82
if
(
rowPtrs
) {
83
free(
rowPtrs
);
84
}
85
86
rowPtrs
= (
double
**)malloc(nrows *
sizeof
(
double
*));
87
for
(
unsigned
int
r = 0; r < nrows; ++r) {
88
rowPtrs
[r] = m.
data
+ col_offset + ((r + row_offset) *
pColNum
);
89
}
90
91
dsize
=
pRowNum
*
pColNum
;
92
}
93
else
{
94
throw
(
95
vpMatrixException
(
vpMatrixException::incorrectMatrixSizeError
,
"Submatrix cannot be contain in parent matrix"
));
96
}
97
}
98
103
void
vpSubMatrix::checkParentStatus
()
const
104
{
105
if
(!
data
) {
106
throw
(
vpMatrixException
(
vpMatrixException::incorrectMatrixSizeError
,
107
"vpSubMatrix parent vpMatrix has been destroyed"
));
108
}
109
if
((
pRowNum
!=
parent
->getRows()) || (
pColNum
!=
parent
->getCols())) {
110
throw
(
vpMatrixException
(
vpMatrixException::incorrectMatrixSizeError
,
111
"vpSubMatrix size of parent vpMatrix has been changed"
));
112
}
113
}
114
119
vpSubMatrix
&
vpSubMatrix::operator=
(
const
vpMatrix
&B)
120
{
121
122
if
((
colNum
!= B.
getCols
()) || (
rowNum
!= B.
getRows
())) {
123
throw
(
vpMatrixException
(
vpMatrixException::incorrectMatrixSizeError
,
124
"vpSubMatrix mismatch in operator vpSubMatrix=vpMatrix"
));
125
}
126
127
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
128
for
(
unsigned
int
j = 0; j <
colNum
; ++j) {
129
rowPtrs
[i][j] = B[i][j];
130
}
131
}
132
133
return
*
this
;
134
}
135
140
vpSubMatrix
&
vpSubMatrix::operator=
(
const
vpSubMatrix
&B)
141
{
142
143
if
((
colNum
!= B.
getCols
()) || (
rowNum
!= B.
getRows
())) {
144
throw
(
vpMatrixException
(
vpMatrixException::incorrectMatrixSizeError
,
145
"vpSubMatrix mismatch in operator vpSubMatrix=vpMatrix"
));
146
}
147
148
pRowNum
= B.
pRowNum
;
149
pColNum
= B.
pColNum
;
150
parent
= B.
parent
;
151
152
double
**BrowPtrs = B.
rowPtrs
;
153
154
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
155
for
(
unsigned
int
j = 0; j <
colNum
; ++j) {
156
rowPtrs
[i][j] = BrowPtrs[i][j];
157
}
158
}
159
160
return
*
this
;
161
}
162
167
vpSubMatrix
&
vpSubMatrix::operator=
(
const
double
&x)
168
{
169
for
(
unsigned
int
i = 0; i <
rowNum
; ++i) {
170
for
(
unsigned
int
j = 0; j <
colNum
; ++j) {
171
rowPtrs
[i][j] = x;
172
}
173
}
174
175
return
*
this
;
176
}
177
178
vpSubMatrix::~vpSubMatrix
() {
data
=
nullptr
; }
179
END_VISP_NAMESPACE
vpArray2D::getCols
unsigned int getCols() const
Definition
vpArray2D.h:423
vpArray2D::data
Type * data
Address of the first element of the data array.
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
vpMatrixException
error that can be emitted by the vpMatrix class and its derivatives
Definition
vpMatrixException.h:50
vpMatrixException::incorrectMatrixSizeError
@ incorrectMatrixSizeError
Incorrect matrix size.
Definition
vpMatrixException.h:69
vpMatrixException::subMatrixError
@ subMatrixError
Sub operation matrix error.
Definition
vpMatrixException.h:73
vpMatrix::vpMatrix
vpMatrix()
Definition
vpMatrix.h:191
vpMatrix::init
VP_DEPRECATED void init()
Definition
vpMatrix.h:1094
vpSubMatrix::~vpSubMatrix
virtual ~vpSubMatrix() VP_OVERRIDE
Destructor.
Definition
vpSubMatrix.cpp:178
vpSubMatrix::checkParentStatus
void checkParentStatus() const
Check is parent vpRowVector has changed since initialization.
Definition
vpSubMatrix.cpp:103
vpSubMatrix::pRowNum
unsigned int pRowNum
Definition
vpSubMatrix.h:83
vpSubMatrix::parent
vpMatrix * parent
Definition
vpSubMatrix.h:85
vpSubMatrix::vpSubMatrix
vpSubMatrix()
Default constructor.
Definition
vpSubMatrix.cpp:41
vpSubMatrix::pColNum
unsigned int pColNum
Definition
vpSubMatrix.h:84
vpSubMatrix::operator=
vpSubMatrix & operator=(const vpSubMatrix &B)
Operation such as subA = subB.
Definition
vpSubMatrix.cpp:140
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
matrix
vpSubMatrix.cpp
Generated by
1.17.0