|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
28 #define RES(v) ((std::vector<T> *)v)
52 size_t nrows = in.
rows();
53 size_t ncols = in.
cols();
55 for(
size_t r=0; r<nrows; r++)
56 for(
size_t c_in=0,c_out=0;c_in<ncols; c_in++)
60 c_in=c_in+(how_many-1);
63 ret[r][c_out]=(in)[r][c_in];
72 size_t nrows = in.
rows();
73 size_t ncols = in.
cols();
75 for(
size_t c=0; c<ncols; c++)
76 for(
size_t r_in=0, r_out=0; r_in<nrows; r_in++)
80 r_in=r_in+(how_many-1);
83 ret[r_out][c]=(in)[r_in][c];
93 const double *i=in.
data()+in.
cols()*r1+c1;
94 const int offset=in.
cols()-(c2-c1+1);
96 if(i ==
nullptr ||
t ==
nullptr)
99 for(
size_t r=0;r<=(r2-r1);r++)
101 for(
size_t c=0;c<=(c2-c1);c++)
116 bool ok = connection.
expectBlock((
char*)&header,
sizeof(header));
117 if (!ok)
return false;
120 if (header.listLen > 0)
122 if ( r != (
size_t)(header.rows) || c!=(
size_t)(header.cols))
124 resize(header.rows, header.cols);
129 for(l=0;l<header.listLen;l++)
152 connection.
appendBlock((
char*)&header,
sizeof(header));
155 const double *tmp=data();
156 for(l=0;l<header.listLen;l++)
170 std::string spacer((width<0) ?
"\t" :
" ");
173 std::string
ret =
"";
175 const double* src = (*this).data();
180 for (r = 0; r < nrows; r++) {
181 if (r) {
ret += endRowStr; }
182 for (c = 0; c < ncols; c++) {
183 if (c) {
ret += spacer; }
184 sprintf(
buffer,
"% *.*lf", width, precision, *src); src++;
193 void Matrix::updatePointers()
199 matrix=
new double* [nrows];
200 if (nrows>0) matrix[0]=storage;
201 for(r=1;r<nrows; r++)
203 matrix[r]=matrix[r-1]+ncols;
209 if (
this == &r)
return *
this;
211 if(nrows!=r.nrows || ncols!=r.ncols)
219 storage=
new double[ncols*nrows];
220 memcpy(storage, r.storage, ncols*nrows*
sizeof(
double));
226 storage=
new double[ncols*nrows];
227 memcpy(storage, r.storage, ncols*nrows*
sizeof(
double));
235 size_t nelem = nrows*ncols;
236 for(
size_t k=0; k<nelem; k++)
247 if (storage!=
nullptr)
253 if(new_r==nrows && new_c==ncols)
256 auto* new_storage=
new double[new_r*new_c];
258 const size_t copy_r=(new_r<nrows) ? new_r:nrows;
259 const size_t copy_c=(new_c<ncols) ? new_c:ncols;
262 if (storage!=
nullptr)
264 double *tmp_new=new_storage;
265 double *tmp_current=storage;
270 const int stepN=(new_c-copy_c);
271 const int stepC=(ncols-copy_c);
273 for(
int r=0; r<copy_r;r++)
275 for(
int c=0;c<copy_c;c++)
276 *tmp_new++=*tmp_current++;
278 tmp_current=matrix[r];
283 for(
size_t r=0; r<copy_r;r++)
285 tmp_current=matrix[r];
286 memcpy(tmp_new, tmp_current,
sizeof(
double)*copy_c);
296 memset(new_storage, 0,
sizeof(
double)*new_r*new_c);
310 memset(storage, 0,
sizeof(
double)*ncols*nrows);
316 ret.resize(nrows, ncols-how_many);
318 for(
size_t r=0; r<nrows; r++)
319 for(
size_t c_in=0,c_out=0;c_in<ncols; c_in++)
323 c_in=c_in+(how_many-1);
326 ret[r][c_out]=(*this)[r][c_in];
335 storage=
new double[ncols*nrows];
336 memcpy(storage,
ret.storage, ncols*nrows*
sizeof(
double));
344 ret.resize(nrows-how_many, ncols);
346 for(
size_t c=0; c<ncols; c++)
347 for(
size_t r_in=0, r_out=0; r_in<nrows; r_in++)
351 r_in=r_in+(how_many-1);
354 ret[r_out][c]=(*this)[r_in][c];
363 storage=
new double[ncols*nrows];
364 memcpy(storage,
ret.storage, ncols*nrows*
sizeof(
double));
372 ret.resize(ncols, nrows);
374 for(
size_t r=0; r<nrows; r++)
375 for(
size_t c=0;c<ncols; c++)
376 ret[c][r]=(*
this)[r][c];
386 for(
size_t c=0;c<ncols;c++)
387 ret[c]=(*
this)[r][c];
397 for(
size_t r=0;r<nrows;r++)
398 ret[r]=(*
this)[r][c];
405 if(r>=rows() || c+size-1>=cols())
410 for(
size_t i=0;i<size;i++)
411 ret[i]=(*
this)[r][c+i];
418 if(r+size-1>=rows() || c>=cols())
423 for(
size_t i=0;i<size;i++)
424 ret[i]=(*
this)[r+i][c];
437 for(
size_t r=0; r<tmpR; r++,c++)
451 for(
size_t r=0; r<tmpR; r++,c++)
460 if ( (rows()!=r.
rows()) || (cols()!=r.
cols()))
463 const double *tmp1=data();
464 const double *tmp2=r.
data();
466 if(tmp1 ==
nullptr || tmp2 ==
nullptr)
472 if (*tmp1++!=*tmp2++)
481 if((row>=nrows) || (r.
length() != ncols))
484 for(
size_t c=0;c<ncols;c++)
485 (*
this)[row][c]=r[c];
492 if((col>=ncols) || (c.
length() != nrows))
495 for(
size_t r=0;r<nrows;r++)
496 (*
this)[r][col]=c[r];
503 if((c+m.
cols()>ncols) || (r+m.
rows()>nrows))
506 for(
size_t i=0;i<m.
rows();i++)
507 for(
size_t j=0;j<m.
cols();j++)
508 (*
this)[r+i][c+j] = m(i,j);
515 if(r>=nrows || c+s-1>=(
size_t)ncols)
518 for(
size_t i=0;i<s;i++)
519 (*
this)[r][i+c] = v[i];
526 if(r+s-1>=(
size_t)nrows || c>=ncols)
529 for(
size_t i=0;i<s;i++)
530 (*
this)[r+i][c] = v[i];
540 storage=
new double [r*c];
541 memset(storage, 0, r*c*
sizeof(
double));
552 if (m.storage!=
nullptr)
554 storage=
new double [nrows*ncols];
555 memcpy(storage, m.storage, nrows*ncols*
sizeof(
double));
bool removeRows(const Matrix &in, Matrix &out, size_t first_row, size_t how_many)
std::string toString(int precision=-1, int width=-1, const char *endRowStr="\n") const
Print matrix to a string.
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Vector subrow(size_t r, size_t c, size_t size) const
Get a subrow of the matrix as a vector.
contains the definition of a Vector type
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
bool setSubrow(const Vector &v, size_t r, size_t c)
Set a portion of a row of this matrix with the values of the specified vector v.
bool removeCols(const Matrix &in, Matrix &out, size_t first_col, size_t how_many)
Matrix transposed() const
Return the transposed of the matrix.
const Matrix & diagonal(const Vector &d)
Build a diagonal matrix, don't resize.
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.
Matrix removeCols(size_t first_col, size_t how_many)
Modifies the matrix, removing one or more columns from it.
size_t rows() const
Return number of rows.
contains the definition of a Matrix type
bool setSubcol(const Vector &v, size_t r, size_t c)
Set a portion of a column of this matrix with the values of the specified vector v.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
An interface for writing to a network connection.
const Matrix & eye()
Build an identity matrix, don't resize.
bool setCol(size_t col, const Vector &c)
Set a column of the matrix copying the values from a vector: the vector length must be equal to the n...
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
size_t length() const
Get the length of the vector.
size_t cols() const
Return number of columns.
void resize(size_t r, size_t c)
Resize the matrix, if matrix is not empty preserve old content.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
An interface for reading from a network connection.
#define BOTTLE_TAG_FLOAT64
double * data()
Return a pointer to the first element.
Vector subcol(size_t r, size_t c, size_t size) const
Get a subcolumn of the matrix as a vector.
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
VectorOf< double > Vector
An interface to the operating system, including Port based communication.
Vector getCol(size_t c) const
Get a columns of the matrix as a vector.
The main, catch-all namespace for YARP.
bool submatrix(const Matrix &in, Matrix &out, size_t r1, size_t r2, size_t c1, size_t c2)
bool operator==(const yarp::sig::Matrix &r) const
True iff all elements of a match all element of b.
Matrix removeRows(size_t first_row, size_t how_many)
Modifies the matrix, removing one or more rows from it.
void zero()
Zero the matrix.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
Vector getRow(size_t r) const
Get a row of the matrix as a vector.
const Matrix & operator=(const Matrix &r)
Copy operator.
bool setRow(size_t row, const Vector &r)
Set a row of the matrix copying the values from a vector: the vector length must be equal to the numb...
bool setSubmatrix(const Matrix &m, size_t r, size_t c)
Set a portion of this matrix with the values of the specified matrix m.
std::int32_t NetInt32
Definition of the NetInt32 type.