Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions modules/core/include/visp3/core/vpColVector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
* Copyright (C) 2005 - 2026 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -195,24 +195,24 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
/*!
* Basic constructor that creates an empty 0-size column vector.
*/
vpColVector() : vpArray2D<double>() { }
vpColVector() : vpArray2D<double>() {}

/*!
* Construct a column vector of size n.
* \warning Elements are not initialized. If you want to set an initial value use
* vpColVector(unsigned int, double).
*/
VP_EXPLICIT vpColVector(unsigned int n) : vpArray2D<double>(n, 1) { }
VP_EXPLICIT vpColVector(unsigned int n) : vpArray2D<double>(n, 1) {}

/*!
* Construct a column vector of size n. Each element is set to \e val.
*/
vpColVector(unsigned int n, double val) : vpArray2D<double>(n, 1, val) { }
vpColVector(unsigned int n, double val) : vpArray2D<double>(n, 1, val) {}

/*!
* Copy constructor that allows to construct a column vector from an other one.
*/
vpColVector(const vpColVector &v) : vpArray2D<double>(v) { }
vpColVector(const vpColVector &v) : vpArray2D<double>(v) {}

/*!
* Construct a column vector from a part of an input column vector \e v.
Expand Down Expand Up @@ -904,27 +904,51 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
vpTranslationVector operator+(const vpTranslationVector &t) const;

/*!
* Operator that allows to add two column vectors.
* In-place addition of a column vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e v.
*
* \param v The vector to add.
* \return A reference to the current vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpColVector &operator+=(const vpColVector &v);

/*!
* Operator that allows to add a 3-dim translation vector to a 3-dim column vector.
* In-place addition of a translation vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e t.
*
* \param t The 3-dim translation vector to add.
* \return A reference to the current vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpColVector &operator+=(const vpTranslationVector &t);

/*!
* Operator subtraction of two vectors this = this - v
* Subtraction of two vectors: result = this - v.
*
* \param v The vector to subtract.
* \return A new vector containing the result of the subtraction.
* \exception vpException::dimensionError If the dimensions do not match.
*/
vpColVector operator-(const vpColVector &v) const;

/*!
* Operator that allows to subtract two column vectors.
* In-place subtraction of a column vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e v.
*
* \param v The vector to subtract.
* \return A reference to the current vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpColVector &operator-=(const vpColVector &v);

/*!
* Operator that allows to subtract a 3-dim translation vector to a 3-dim column vector.
* In-place subtraction of a translation vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e t.
*
* \param t The 3-dim translation vector to suntract.
* \return A reference to the current vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpColVector &operator-=(const vpTranslationVector &t);

Expand Down Expand Up @@ -1467,7 +1491,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* \deprecated Provided only for compat with previous releases.
* This function does nothing.
*/
VP_DEPRECATED void init() { }
VP_DEPRECATED void init() {}

/*!
* \deprecated Provided only for compat with previous releases. Use rather
Expand Down
18 changes: 9 additions & 9 deletions modules/core/include/visp3/core/vpRowVector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
* Copyright (C) 2005 - 2026 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -124,23 +124,23 @@ class VISP_EXPORT vpRowVector : public vpArray2D<double>
{
public:
//! Basic constructor that creates an empty 0-size row vector.
vpRowVector() : vpArray2D<double>() { }
vpRowVector() : vpArray2D<double>() {}
//! Construct a row vector of size n. All the elements are initialized to
//! zero.
VP_EXPLICIT vpRowVector(unsigned int n) : vpArray2D<double>(1, n) { }
VP_EXPLICIT vpRowVector(unsigned int n) : vpArray2D<double>(1, n) {}
//! Construct a row vector of size n. Each element is set to \e val.
vpRowVector(unsigned int n, double val) : vpArray2D<double>(1, n, val) { }
vpRowVector(unsigned int n, double val) : vpArray2D<double>(1, n, val) {}
//! Copy constructor that allows to construct a row vector from an other
//! one.
vpRowVector(const vpRowVector &v) : vpArray2D<double>(v) { }
vpRowVector(const vpRowVector &v) : vpArray2D<double>(v) {}
vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols);
VP_EXPLICIT vpRowVector(const vpMatrix &M);
vpRowVector(const vpMatrix &M, unsigned int i);
VP_EXPLICIT vpRowVector(const std::vector<double> &v);
VP_EXPLICIT vpRowVector(const std::vector<float> &v);
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
vpRowVector(vpRowVector &&v);
VP_EXPLICIT vpRowVector(const std::initializer_list<double> &list) : vpArray2D<double>(list) { }
VP_EXPLICIT vpRowVector(const std::initializer_list<double> &list) : vpArray2D<double>(list) {}
#endif

static vpRowVector view(double *raw_data, unsigned int ncols);
Expand Down Expand Up @@ -259,10 +259,10 @@ class VISP_EXPORT vpRowVector : public vpArray2D<double>
vpRowVector &operator/=(double x);

vpRowVector operator+(const vpRowVector &v) const;
vpRowVector &operator+=(vpRowVector v);
vpRowVector &operator+=(const vpRowVector &v);

vpRowVector operator-(const vpRowVector &v) const;
vpRowVector &operator-=(vpRowVector v);
vpRowVector &operator-=(const vpRowVector &v);
vpRowVector operator-() const;

vpRowVector &operator<<(const vpRowVector &v);
Expand Down Expand Up @@ -337,7 +337,7 @@ class VISP_EXPORT vpRowVector : public vpArray2D<double>
\deprecated Provided only for compat with previous releases.
This function does nothing.
*/
VP_DEPRECATED void init() { }
VP_DEPRECATED void init() {}
/*!
\deprecated You should rather use stack(const vpRowVector &)
*/
Expand Down
22 changes: 17 additions & 5 deletions modules/core/src/math/matrix/vpColVector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
* Copyright (C) 2005 - 2026 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -89,7 +89,10 @@ vpTranslationVector vpColVector::operator+(const vpTranslationVector &t) const

vpColVector &vpColVector::operator+=(const vpColVector &v)
{
if (getRows() != v.getRows()) {
if (getRows() == 0) {
resize(v.getRows(), true);
}
else if (getRows() != v.getRows()) {
throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
v.getRows()));
}
Expand All @@ -102,7 +105,10 @@ vpColVector &vpColVector::operator+=(const vpColVector &v)

vpColVector &vpColVector::operator+=(const vpTranslationVector &t)
{
if (getRows() != t.getRows()) {
if (getRows() == 0) {
resize(t.getRows(), true);
}
else if (getRows() != t.getRows()) {
throw(vpException(vpException::dimensionError, "Cannot add (%dx1) translation vector to (%dx1) column vector",
getRows(), t.getRows()));
}
Expand All @@ -115,7 +121,10 @@ vpColVector &vpColVector::operator+=(const vpTranslationVector &t)

vpColVector &vpColVector::operator-=(const vpColVector &v)
{
if (getRows() != v.getRows()) {
if (getRows() == 0) {
resize(v.getRows(), true);
}
else if (getRows() != v.getRows()) {
throw(vpException(vpException::dimensionError, "Cannot subtract (%dx1) column vector to (%dx1) column vector",
getRows(), v.getRows()));
}
Expand All @@ -128,7 +137,10 @@ vpColVector &vpColVector::operator-=(const vpColVector &v)

vpColVector &vpColVector::operator-=(const vpTranslationVector &t)
{
if (getRows() != t.getRows()) {
if (getRows() == 0) {
resize(t.getRows(), true);
}
else if (getRows() != t.getRows()) {
throw(vpException(vpException::dimensionError, "Cannot subtract (%dx1) translation vector to (%dx1) column vector",
getRows(), t.getRows()));
}
Expand Down
36 changes: 24 additions & 12 deletions modules/core/src/math/matrix/vpRowVector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
* Copyright (C) 2005 - 2026 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -448,13 +448,19 @@ vpRowVector vpRowVector::operator+(const vpRowVector &v) const
}

/*!
Operator that allows to add two row vectors that have the same size.
\exception vpException::dimensionError If the size of the two vectors
differ.
* In-place addition of a row vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e v.
*
* \param v The row vector to add.
* \return A reference to the current row vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpRowVector &vpRowVector::operator+=(vpRowVector v)
vpRowVector &vpRowVector::operator+=(const vpRowVector &v)
{
if (getCols() != v.getCols()) {
if (getCols() == 0) {
resize(v.getCols(), true);
}
else if (getCols() != v.getCols()) {
throw(vpException(vpException::dimensionError, "Cannot add (1x%d) row vector to (1x%d) row vector", getCols(),
v.getCols()));
}
Expand All @@ -466,13 +472,19 @@ vpRowVector &vpRowVector::operator+=(vpRowVector v)
}

/*!
Operator that allows to subtract two row vectors that have the same size.
\exception vpException::dimensionError If the size of the two vectors
differ.
* In-place subtraction of a row vector.
* If the current vector is empty, it is automatically resized to the dimensions of \e v.
*
* \param v The row vector to subtract.
* \return A reference to the current row vector.
* \exception vpException::dimensionError If the dimensions do not match and the vector is not empty.
*/
vpRowVector &vpRowVector::operator-=(vpRowVector v)
vpRowVector &vpRowVector::operator-=(const vpRowVector &v)
{
if (getCols() != v.getCols()) {
if (getCols() == 0) {
resize(v.getCols(), true);
}
else if (getCols() != v.getCols()) {
throw(vpException(vpException::dimensionError, "Cannot subtract (1x%d) row vector to (1x%d) row vector", getCols(),
v.getCols()));
}
Expand Down Expand Up @@ -621,7 +633,7 @@ vpRowVector::vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncol

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
vpRowVector::vpRowVector(vpRowVector &&v) : vpArray2D<double>(std::move(v))
{ }
{}
#endif

/*!
Expand Down
Loading
Loading