Visual Servoing Platform  version 3.2.0
vpArray2D< Type > Class Template Reference

#include <vpArray2D.h>

Public Member Functions

 vpArray2D ()
 
 vpArray2D (const vpArray2D< Type > &A)
 
 vpArray2D (unsigned int r, unsigned int c)
 
 vpArray2D (unsigned int r, unsigned int c, Type val)
 
virtual ~vpArray2D ()
 

Static Public Member Functions

Inherited I/O from vpArray2D with Static Public Member Functions
static bool load (const std::string &filename, vpArray2D< Type > &A, const bool binary=false, char *header=NULL)
 
static bool loadYAML (const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
 
static bool save (const std::string &filename, const vpArray2D< Type > &A, const bool binary=false, const char *header="")
 
static bool saveYAML (const std::string &filename, const vpArray2D< Type > &A, const char *header="")
 

Public Attributes

Type * data
 

Protected Attributes

unsigned int rowNum
 
unsigned int colNum
 
Type ** rowPtrs
 
unsigned int dsize
 

Related Functions

(Note that these are not member functions.)

enum  vpGEMMmethod
 
void vpGEMM (const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
 

Inherited functionalities from vpArray2D

std::ostream & operator<< (std::ostream &s, const vpArray2D< Type > &A)
 
unsigned int getCols () const
 
Type getMaxValue () const
 
Type getMinValue () const
 
unsigned int getRows () const
 
unsigned int size () const
 
void resize (const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
 
vpArray2D< Type > & operator= (Type x)
 
vpArray2D< Type > & operator= (const vpArray2D< Type > &A)
 
Type * operator[] (unsigned int i)
 
Type * operator[] (unsigned int i) const
 
vpArray2D< Type > hadamard (const vpArray2D< Type > &m) const
 

Detailed Description

template<class Type>
class vpArray2D< Type >

Implementation of a generic 2D array used as vase class of matrices and vectors.

This class implements a 2D array as a template class and all the basic functionalities common to matrices and vectors. More precisely:

Examples
testArray2D.cpp, and testUndistortImage.cpp.

Definition at line 69 of file vpArray2D.h.

Constructor & Destructor Documentation

◆ vpArray2D() [1/4]

template<class Type>
vpArray2D< Type >::vpArray2D ( )
inline

Basic constructor of a 2D array. Number of columns and rows are set to zero.

Definition at line 90 of file vpArray2D.h.

◆ vpArray2D() [2/4]

template<class Type>
vpArray2D< Type >::vpArray2D ( const vpArray2D< Type > &  A)
inline

Copy constructor of a 2D array.

Definition at line 94 of file vpArray2D.h.

◆ vpArray2D() [3/4]

template<class Type>
vpArray2D< Type >::vpArray2D ( unsigned int  r,
unsigned int  c 
)
inline

Constructor that initializes a 2D array with 0.

Parameters
r: Array number of rows.
c: Array number of columns.

Definition at line 105 of file vpArray2D.h.

◆ vpArray2D() [4/4]

template<class Type>
vpArray2D< Type >::vpArray2D ( unsigned int  r,
unsigned int  c,
Type  val 
)
inline

Constructor that initialize a 2D array with val.

Parameters
r: Array number of rows.
c: Array number of columns.
val: Each element of the array is set to val.

Definition at line 116 of file vpArray2D.h.

◆ ~vpArray2D()

template<class Type>
virtual vpArray2D< Type >::~vpArray2D ( )
inlinevirtual

Destructor that desallocate memory.

Definition at line 124 of file vpArray2D.h.

Member Function Documentation

◆ getCols()

template<class Type>
unsigned int vpArray2D< Type >::getCols ( ) const
inline

◆ getMaxValue()

template<class Type >
Type vpArray2D< Type >::getMaxValue ( ) const

Return the array max value.

Definition at line 693 of file vpArray2D.h.

◆ getMinValue()

template<class Type >
Type vpArray2D< Type >::getMinValue ( ) const

Return the array min value.

Definition at line 676 of file vpArray2D.h.

◆ getRows()

◆ hadamard()

template<class Type>
vpArray2D< Type > vpArray2D< Type >::hadamard ( const vpArray2D< Type > &  m) const

Compute the Hadamard product (element wise matrix multiplication).

Parameters
m: Second matrix;
Returns
m1.hadamard(m2) The Hadamard product : $ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} $

Definition at line 713 of file vpArray2D.h.

◆ load()

template<class Type>
static bool vpArray2D< Type >::load ( const std::string &  filename,
vpArray2D< Type > &  A,
const bool  binary = false,
char *  header = NULL 
)
inlinestatic

Load a matrix from a file.

Parameters
filename: Absolute file name.
A: Array to be loaded
binary: If true the matrix is loaded from a binary file, else from a text file.
header: Header of the file is loaded in this parameter.
Returns
Returns true if success.
See also
save()

Definition at line 321 of file vpArray2D.h.

◆ loadYAML()

template<class Type>
static bool vpArray2D< Type >::loadYAML ( const std::string &  filename,
vpArray2D< Type > &  A,
char *  header = NULL 
)
inlinestatic

Load an array from a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be loaded from the file.
header: header of the file is loaded in this parameter.
Returns
Returns true on success.
See also
saveYAML()

Definition at line 433 of file vpArray2D.h.

◆ operator=() [1/2]

template<class Type>
vpArray2D<Type>& vpArray2D< Type >::operator= ( const vpArray2D< Type > &  A)
inline

Copy operator of a 2D array.

Definition at line 255 of file vpArray2D.h.

◆ operator=() [2/2]

template<class Type>
vpArray2D<Type>& vpArray2D< Type >::operator= ( Type  x)
inline

Set all the elements of the array to x.

Definition at line 246 of file vpArray2D.h.

◆ operator[]() [1/2]

template<class Type>
Type* vpArray2D< Type >::operator[] ( unsigned int  i)
inline

Set element $A_{ij} = x$ using A[i][j] = x.

Definition at line 265 of file vpArray2D.h.

◆ operator[]() [2/2]

template<class Type>
Type* vpArray2D< Type >::operator[] ( unsigned int  i) const
inline

Get element $x = A_{ij}$ using x = A[i][j].

Definition at line 267 of file vpArray2D.h.

◆ resize()

template<class Type>
void vpArray2D< Type >::resize ( const unsigned int  nrows,
const unsigned int  ncols,
const bool  flagNullify = true,
const bool  recopy_ = true 
)
inline

Set the size of the array and initialize all the values to zero.

Parameters
nrows: number of rows.
ncols: number of column.
flagNullify: if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
recopy_: if true, will perform an explicit recopy of the old data if needed and if flagNullify is set to false.

Definition at line 170 of file vpArray2D.h.

Referenced by vpServo::computeProjectionOperators(), vpMbDepthDenseTracker::computeVVSInit(), vpMbDepthNormalTracker::computeVVSInit(), vpMbKltMultiTracker::computeVVSInit(), vpMbEdgeMultiTracker::computeVVSInit(), vpMbEdgeKltMultiTracker::computeVVSInit(), vpMbGenericTracker::computeVVSInit(), vpMbKltTracker::computeVVSInit(), vpMbEdgeTracker::computeVVSInit(), vpProjectionDisplay::display(), vpMatrix::eigenValues(), vpProjectionDisplay::init(), vpTemplateTrackerSSDInverseCompositional::initCompInverse(), vpTemplateTrackerMIESM::initCompInverse(), vpMbEdgeKltMultiTracker::initMbtTracking(), vpTemplateTracker::initTracking(), vpIoTools::readConfigVar(), vpTemplateTrackerMI::vpTemplateTrackerMI(), vpTemplateTrackerSSD::vpTemplateTrackerSSD(), vpTemplateTrackerSSDESM::vpTemplateTrackerSSDESM(), vpTemplateTrackerSSDInverseCompositional::vpTemplateTrackerSSDInverseCompositional(), vpTemplateTrackerWarpAffine::vpTemplateTrackerWarpAffine(), vpTemplateTrackerWarpHomography::vpTemplateTrackerWarpHomography(), vpTemplateTrackerWarpHomographySL3::vpTemplateTrackerWarpHomographySL3(), vpTemplateTrackerWarpRT::vpTemplateTrackerWarpRT(), vpTemplateTrackerWarpSRT::vpTemplateTrackerWarpSRT(), vpTemplateTrackerWarpTranslation::vpTemplateTrackerWarpTranslation(), and vpTemplateTrackerZNCC::vpTemplateTrackerZNCC().

◆ save()

template<class Type>
static bool vpArray2D< Type >::save ( const std::string &  filename,
const vpArray2D< Type > &  A,
const bool  binary = false,
const char *  header = "" 
)
inlinestatic

Save a matrix to a file.

Parameters
filename: Absolute file name.
A: Array to be saved.
binary: If true the matrix is saved in a binary file, else a text file.
header: Optional line that will be saved at the beginning of the file.
Returns
Returns true if success.

Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.

See also
load()

Definition at line 518 of file vpArray2D.h.

◆ saveYAML()

template<class Type>
static bool vpArray2D< Type >::saveYAML ( const std::string &  filename,
const vpArray2D< Type > &  A,
const char *  header = "" 
)
inlinestatic

Save an array in a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be saved in the file.
header: optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
Returns
Returns true if success.

Here is an example of outputs.

vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted
header\n - with inner indentation");

Content of matrix.yml:

example: a YAML-formatted header
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]

Content of matrixIndent.yml:

example:
- a YAML-formatted header
- with inner indentation
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
See also
loadYAML()

Definition at line 611 of file vpArray2D.h.

◆ size()

template<class Type>
unsigned int vpArray2D< Type >::size ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

template<class Type>
std::ostream& operator<< ( std::ostream &  s,
const vpArray2D< Type > &  A 
)
friend

Writes the given array to the output stream and returns a reference to the output stream.

Examples
testAprilTag.cpp.

Definition at line 274 of file vpArray2D.h.

◆ vpGEMM()

template<class Type>
void vpGEMM ( const vpArray2D< double > &  A,
const vpArray2D< double > &  B,
const double &  alpha,
const vpArray2D< double > &  C,
const double &  beta,
vpArray2D< double > &  D,
const unsigned int &  ops = 0 
)
related

This function performs generalized matrix multiplication: D = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T. Operation on A, B and C matrices is described by enumeration vpGEMMmethod().

For example, to compute D = alpha*A^T*B^T+beta*C we need to call :

vpGEMM(A, B, alpha, C, beta, D, VP_GEMM_A_T + VP_GEMM_B_T);

If C is not used, vpGEMM must be called using an empty array null. Thus to compute D = alpha*A^T*B, we have to call:

vpGEMM(A, B, alpha, null, 0, D, VP_GEMM_B_T);
Exceptions
vpException::incorrectMatrixSizeErrorif the sizes of the matrices do not allow the operations.
Parameters
A: An array that could be a vpMatrix.
B: An array that could be a vpMatrix.
alpha: A scalar.
C: An array that could be a vpMatrix.
beta: A scalar.
D: The resulting array that could be a vpMatrix.
ops: A scalar describing operation applied on the matrices. Possible values are the one defined in vpGEMMmethod(): VP_GEMM_A_T, VP_GEMM_B_T, VP_GEMM_C_T.
Examples
testMatrix.cpp.

Definition at line 392 of file vpGEMM.h.

◆ vpGEMMmethod

template<class Type>
enum vpGEMMmethod
related

Enumeration of the operations applied on matrices in vpGEMM() function.

Operations are :

  • VP_GEMM_A_T to use the transpose matrix of A instead of the matrix A
  • VP_GEMM_B_T to use the transpose matrix of B instead of the matrix B
  • VP_GEMM_C_T to use the transpose matrix of C instead of the matrix C

Definition at line 56 of file vpGEMM.h.

Member Data Documentation

◆ colNum

template<class Type>
unsigned int vpArray2D< Type >::colNum
protected

Number of columns in the array.

Definition at line 75 of file vpArray2D.h.

Referenced by vpColVector::operator==().

◆ data

template<class Type>
Type* vpArray2D< Type >::data

Address of the first element of the data array.

Definition at line 83 of file vpArray2D.h.

Referenced by vpColVector::operator=(), vpMatrix::operator=(), vpColVector::operator==(), and vpPoseVector::t().

◆ dsize

template<class Type>
unsigned int vpArray2D< Type >::dsize
protected

Current array size (rowNum * colNum)

Definition at line 79 of file vpArray2D.h.

◆ rowNum

template<class Type>
unsigned int vpArray2D< Type >::rowNum
protected

Number of rows in the array.

Definition at line 73 of file vpArray2D.h.

Referenced by vpColVector::operator=(), and vpColVector::operator==().

◆ rowPtrs

template<class Type>
Type** vpArray2D< Type >::rowPtrs
protected

Address of the first element of each rows.

Definition at line 77 of file vpArray2D.h.

Referenced by vpMatrix::operator+=().

vpArray2D::vpGEMM
void vpGEMM(const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
Definition: vpGEMM.h:392
vpArray2D::saveYAML
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:611
vpArray2D< double >
vpArray2D::data
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:83