Visual Servoing Platform  version 3.5.1 under development (2022-07-05)
vpArray2D.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * This class implements an 2D array as a template class.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 #ifndef _vpArray2D_h_
39 #define _vpArray2D_h_
40 
41 #include <fstream>
42 #include <iostream>
43 #include <limits>
44 #include <math.h>
45 #include <ostream>
46 #include <sstream>
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #include <visp3/core/vpConfig.h>
51 #include <visp3/core/vpException.h>
52 
131 template <class Type> class vpArray2D
132 {
133 protected:
135  unsigned int rowNum;
137  unsigned int colNum;
139  Type **rowPtrs;
141  unsigned int dsize;
142 
143 public:
145  Type *data;
146 
147 public:
152  vpArray2D<Type>() : rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL) {}
153 
158  :
159 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
160  vpArray2D<Type>()
161 #else
162  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
163 #endif
164  {
165  resize(A.rowNum, A.colNum, false, false);
166  memcpy(data, A.data, (size_t)rowNum * (size_t)colNum * sizeof(Type));
167  }
168 
175  vpArray2D<Type>(unsigned int r, unsigned int c)
176  :
177 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
178  vpArray2D<Type>()
179 #else
180  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
181 #endif
182  {
183  resize(r, c);
184  }
185 
193  vpArray2D<Type>(unsigned int r, unsigned int c, Type val)
194  :
195 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
196  vpArray2D<Type>()
197 #else
198  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
199 #endif
200  {
201  resize(r, c, false, false);
202  *this = val;
203  }
204 
205 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
206  vpArray2D<Type>(vpArray2D<Type> &&A) noexcept
207  {
208  rowNum = A.rowNum;
209  colNum = A.colNum;
210  rowPtrs = A.rowPtrs;
211  dsize = A.dsize;
212  data = A.data;
213 
214  A.rowNum = 0;
215  A.colNum = 0;
216  A.rowPtrs = NULL;
217  A.dsize = 0;
218  A.data = NULL;
219  }
220 
221  explicit vpArray2D<Type>(const std::initializer_list<Type> &list) : vpArray2D<Type>()
222  {
223  resize(1, static_cast<unsigned int>(list.size()), false, false);
224  std::copy(list.begin(), list.end(), data);
225  }
226 
227  explicit vpArray2D<Type>(unsigned int nrows, unsigned int ncols, const std::initializer_list<Type> &list)
228  : rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
229  {
230  if (nrows * ncols != static_cast<unsigned int>(list.size())) {
231  std::ostringstream oss;
232  oss << "Cannot create a vpArray2D of size (" << nrows << ", " << ncols << ") with a list of size " << list.size();
233  throw vpException(vpException::dimensionError, oss.str());
234  }
235 
236  resize(nrows, ncols, false, false);
237  std::copy(list.begin(), list.end(), data);
238  }
239 
240  explicit vpArray2D<Type>(const std::initializer_list<std::initializer_list<Type> > &lists) : vpArray2D<Type>()
241  {
242  unsigned int nrows = static_cast<unsigned int>(lists.size()), ncols = 0;
243  for (auto &l : lists) {
244  if (static_cast<unsigned int>(l.size()) > ncols) {
245  ncols = static_cast<unsigned int>(l.size());
246  }
247  }
248 
249  resize(nrows, ncols, false, false);
250  auto it = lists.begin();
251  for (unsigned int i = 0; i < rowNum; i++, ++it) {
252  std::copy(it->begin(), it->end(), rowPtrs[i]);
253  }
254  }
255 #endif
256 
260  virtual ~vpArray2D<Type>()
261  {
262  if (data != NULL) {
263  free(data);
264  data = NULL;
265  }
266 
267  if (rowPtrs != NULL) {
268  free(rowPtrs);
269  rowPtrs = NULL;
270  }
271  rowNum = colNum = dsize = 0;
272  }
273 
276 
281  inline unsigned int getCols() const { return colNum; }
282 
283  Type getMaxValue() const;
284 
285  Type getMinValue() const;
286 
291  inline unsigned int getRows() const { return rowNum; }
293  inline unsigned int size() const { return colNum * rowNum; }
294 
306  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true, bool recopy_ = true)
307  {
308  if ((nrows == rowNum) && (ncols == colNum)) {
309  if (flagNullify && this->data != NULL) {
310  memset(this->data, 0, this->dsize * sizeof(Type));
311  }
312  } else {
313  bool recopy = !flagNullify && recopy_; // priority to flagNullify
314  const bool recopyNeeded = (ncols != this->colNum && this->colNum > 0 && ncols > 0 && (!flagNullify || recopy));
315  Type *copyTmp = NULL;
316  unsigned int rowTmp = 0, colTmp = 0;
317 
318  // Recopy case per case is required if number of cols has changed;
319  // structure of Type array is not the same in this case.
320  if (recopyNeeded && this->data != NULL) {
321  copyTmp = new Type[this->dsize];
322  memcpy(copyTmp, this->data, sizeof(Type) * this->dsize);
323  rowTmp = this->rowNum;
324  colTmp = this->colNum;
325  }
326 
327  // Reallocation of this->data array
328  this->dsize = nrows * ncols;
329  this->data = (Type *)realloc(this->data, this->dsize * sizeof(Type));
330  if ((NULL == this->data) && (0 != this->dsize)) {
331  if (copyTmp != NULL) {
332  delete[] copyTmp;
333  }
334  throw(vpException(vpException::memoryAllocationError, "Memory allocation error when allocating 2D array data"));
335  }
336 
337  this->rowPtrs = (Type **)realloc(this->rowPtrs, nrows * sizeof(Type *));
338  if ((NULL == this->rowPtrs) && (0 != this->dsize)) {
339  if (copyTmp != NULL) {
340  delete[] copyTmp;
341  }
343  "Memory allocation error when allocating 2D array rowPtrs"));
344  }
345 
346  // Update rowPtrs
347  {
348  Type **t_ = rowPtrs;
349  for (unsigned int i = 0; i < dsize; i += ncols) {
350  *t_++ = this->data + i;
351  }
352  }
353 
354  this->rowNum = nrows;
355  this->colNum = ncols;
356 
357  // Recopy of this->data array values or nullify
358  if (flagNullify) {
359  memset(this->data, 0, (size_t)(this->dsize) * sizeof(Type));
360  } else if (recopyNeeded && this->rowPtrs != NULL) {
361  // Recopy...
362  unsigned int minRow = (this->rowNum < rowTmp) ? this->rowNum : rowTmp;
363  unsigned int minCol = (this->colNum < colTmp) ? this->colNum : colTmp;
364  for (unsigned int i = 0; i < this->rowNum; ++i) {
365  for (unsigned int j = 0; j < this->colNum; ++j) {
366  if ((minRow > i) && (minCol > j)) {
367  (*this)[i][j] = copyTmp[i * colTmp + j];
368  } else {
369  (*this)[i][j] = 0;
370  }
371  }
372  }
373  }
374 
375  if (copyTmp != NULL) {
376  delete[] copyTmp;
377  }
378  }
379  }
380 
381  void reshape(unsigned int nrows, unsigned int ncols)
382  {
383  if (dsize == 0) {
384  resize(nrows, ncols);
385  return;
386  }
387 
388  if (nrows * ncols != dsize) {
389  std::ostringstream oss;
390  oss << "Cannot reshape array of total size " << dsize << " into shape (" << nrows << ", " << ncols << ")";
391  throw vpException(vpException::dimensionError, oss.str());
392  }
393 
394  rowNum = nrows;
395  colNum = ncols;
396  rowPtrs = reinterpret_cast<Type **>(realloc(rowPtrs, nrows * sizeof(Type *)));
397  // Update rowPtrs
398  Type **t_ = rowPtrs;
399  for (unsigned int i = 0; i < dsize; i += ncols) {
400  *t_++ = data + i;
401  }
402  }
403 
407  bool operator==(const vpArray2D<Type> &A) const;
411  bool operator!=(const vpArray2D<Type> &A) const;
412 
415  {
416  std::fill(data, data + dsize, x);
417  return *this;
418  }
419 
424  {
425  resize(A.rowNum, A.colNum, false, false);
426  if (data != NULL && A.data != NULL && data != A.data) {
427  memcpy(data, A.data, (size_t)rowNum * (size_t)colNum * sizeof(Type));
428  }
429  return *this;
430  }
431 
432 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
434  {
435  if (this != &other) {
436  free(data);
437  free(rowPtrs);
438 
439  rowNum = other.rowNum;
440  colNum = other.colNum;
441  rowPtrs = other.rowPtrs;
442  dsize = other.dsize;
443  data = other.data;
444 
445  other.rowNum = 0;
446  other.colNum = 0;
447  other.rowPtrs = NULL;
448  other.dsize = 0;
449  other.data = NULL;
450  }
451 
452  return *this;
453  }
454 
455  vpArray2D<Type> &operator=(const std::initializer_list<Type> &list)
456  {
457  if (dsize != static_cast<unsigned int>(list.size())) {
458  resize(1, static_cast<unsigned int>(list.size()), false, false);
459  }
460  std::copy(list.begin(), list.end(), data);
461 
462  return *this;
463  }
464 
465  vpArray2D<Type> &operator=(const std::initializer_list<std::initializer_list<Type> > &lists)
466  {
467  unsigned int nrows = static_cast<unsigned int>(lists.size()), ncols = 0;
468  for (auto &l : lists) {
469  if (static_cast<unsigned int>(l.size()) > ncols) {
470  ncols = static_cast<unsigned int>(l.size());
471  }
472  }
473 
474  resize(nrows, ncols, false, false);
475  auto it = lists.begin();
476  for (unsigned int i = 0; i < rowNum; i++, ++it) {
477  std::copy(it->begin(), it->end(), rowPtrs[i]);
478  }
479 
480  return *this;
481  }
482 #endif
483 
485  inline Type *operator[](unsigned int i) { return rowPtrs[i]; }
487  inline Type *operator[](unsigned int i) const { return rowPtrs[i]; }
488 
494  friend std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A)
495  {
496  if (A.data == NULL || A.size() == 0) {
497  return s;
498  }
499  std::ios_base::fmtflags original_flags = s.flags();
500 
501  s.precision(10);
502  for (unsigned int i = 0; i < A.getRows(); i++) {
503  for (unsigned int j = 0; j < A.getCols() - 1; j++) {
504  s << A[i][j] << " ";
505  }
506  // We don't add " " after the last row element
507  s << A[i][A.getCols() - 1];
508  // We don't add a \n char on the end of the last array line
509  if (i < A.getRows() - 1) {
510  s << std::endl;
511  }
512  }
513 
514  s.flags(original_flags); // restore s to standard state
515 
516  return s;
517  }
518 
521 
522  //---------------------------------
523  // Inherited array I/O Static Public Member Functions
524  //---------------------------------
541  static bool load(const std::string &filename, vpArray2D<Type> &A, bool binary = false, char *header = NULL)
542  {
543  std::fstream file;
544 
545  if (!binary) {
546  file.open(filename.c_str(), std::fstream::in);
547  } else {
548  file.open(filename.c_str(), std::fstream::in | std::fstream::binary);
549  }
550 
551  if (!file) {
552  file.close();
553  return false;
554  }
555 
556  if (!binary) {
557  std::string h;
558  bool headerIsDecoded = false;
559  do {
560  std::streampos pos = file.tellg();
561  char line[256];
562  file.getline(line, 256);
563  std::string prefix("# ");
564  std::string line_(line);
565  if (line_.compare(0, 2, prefix.c_str()) == 0) {
566  // Line is a comment
567  // If we are not on the first line, we should add "\n" to the end of
568  // the previous line
569  if (pos) {
570  h += "\n";
571  }
572  h += line_.substr(2); // Remove "# "
573  } else {
574  // rewind before the line
575  file.seekg(pos, file.beg);
576  headerIsDecoded = true;
577  }
578  } while (!headerIsDecoded);
579 
580  if (header != NULL) {
581 #if defined(__MINGW32__) || \
582  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
583  sprintf(header, "%s", h.c_str());
584 #else
585  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
586 #endif
587  }
588 
589  unsigned int rows, cols;
590  file >> rows;
591  file >> cols;
592 
593  if (rows >= (std::numeric_limits<unsigned int>::max)() || cols >= (std::numeric_limits<unsigned int>::max)()) {
594  throw vpException(vpException::badValue, "Array exceed the max size.");
595  }
596 
597  A.resize(rows, cols);
598 
599  Type value;
600  for (unsigned int i = 0; i < rows; i++) {
601  for (unsigned int j = 0; j < cols; j++) {
602  file >> value;
603  A[i][j] = value;
604  }
605  }
606  } else {
607  char c = '0';
608  std::string h;
609  // Decode header until '\0' char that ends the header string
610  while (c != '\0') {
611  file.read(&c, 1);
612  h += c;
613  }
614  if (header != NULL) {
615 #if defined(__MINGW32__) || \
616  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
617  sprintf(header, "%s", h.c_str());
618 #else
619  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
620 #endif
621  }
622 
623  unsigned int rows, cols;
624  file.read((char *)&rows, sizeof(unsigned int));
625  file.read((char *)&cols, sizeof(unsigned int));
626  A.resize(rows, cols);
627 
628  Type value;
629  for (unsigned int i = 0; i < rows; i++) {
630  for (unsigned int j = 0; j < cols; j++) {
631  file.read((char *)&value, sizeof(Type));
632  A[i][j] = value;
633  }
634  }
635  }
636 
637  file.close();
638  return true;
639  }
652  static bool loadYAML(const std::string &filename, vpArray2D<Type> &A, char *header = NULL)
653  {
654  std::fstream file;
655 
656  file.open(filename.c_str(), std::fstream::in);
657 
658  if (!file) {
659  file.close();
660  return false;
661  }
662 
663  unsigned int rows = 0, cols = 0;
664  std::string h;
665  std::string line, subs;
666  bool inheader = true;
667  unsigned int i = 0, j;
668  unsigned int lineStart = 0;
669 
670  while (getline(file, line)) {
671  if (inheader) {
672  if (rows == 0 && line.compare(0, 5, "rows:") == 0) {
673  std::stringstream ss(line);
674  ss >> subs;
675  ss >> rows;
676  } else if (cols == 0 && line.compare(0, 5, "cols:") == 0) {
677  std::stringstream ss(line);
678  ss >> subs;
679  ss >> cols;
680  } else if (line.compare(0, 5, "data:") == 0) {
681  inheader = false;
682  } else {
683  h += line + "\n";
684  }
685  } else {
686  // if i == 0, we just got out of the header: initialize matrix
687  // dimensions
688  if (i == 0) {
689  if (rows == 0 || cols == 0) {
690  file.close();
691  return false;
692  }
693  A.resize(rows, cols);
694  // get indentation level which is common to all lines
695  lineStart = (unsigned int)line.find("[") + 1;
696  }
697  std::stringstream ss(line.substr(lineStart, line.find("]") - lineStart));
698  j = 0;
699  while (getline(ss, subs, ',')) {
700  A[i][j++] = atof(subs.c_str());
701  }
702  i++;
703  }
704  }
705 
706  if (header != NULL) {
707  std::string h_ = h.substr(0, h.size() - 1); // Remove last '\n' char
708 #if defined(__MINGW32__) || \
709  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
710  sprintf(header, "%s", h_.c_str());
711 #else
712  _snprintf_s(header, h_.size() + 1, _TRUNCATE, "%s", h_.c_str());
713 #endif
714  }
715 
716  file.close();
717  return true;
718  }
719 
736  static bool save(const std::string &filename, const vpArray2D<Type> &A, bool binary = false, const char *header = "")
737  {
738  std::fstream file;
739 
740  if (!binary) {
741  file.open(filename.c_str(), std::fstream::out);
742  } else {
743  file.open(filename.c_str(), std::fstream::out | std::fstream::binary);
744  }
745 
746  if (!file) {
747  file.close();
748  return false;
749  }
750 
751  if (!binary) {
752  unsigned int i = 0;
753  file << "# ";
754  while (header[i] != '\0') {
755  file << header[i];
756  if (header[i] == '\n') {
757  file << "# ";
758  }
759  i++;
760  }
761  file << std::endl;
762  file << A.getRows() << "\t" << A.getCols() << std::endl;
763  file << A << std::endl;
764  } else {
765  int headerSize = 0;
766  while (header[headerSize] != '\0') {
767  headerSize++;
768  }
769  file.write(header, (size_t)headerSize + (size_t)1);
770  unsigned int matrixSize;
771  matrixSize = A.getRows();
772  file.write((char *)&matrixSize, sizeof(unsigned int));
773  matrixSize = A.getCols();
774  file.write((char *)&matrixSize, sizeof(unsigned int));
775  Type value;
776  for (unsigned int i = 0; i < A.getRows(); i++) {
777  for (unsigned int j = 0; j < A.getCols(); j++) {
778  value = A[i][j];
779  file.write((char *)&value, sizeof(Type));
780  }
781  }
782  }
783 
784  file.close();
785  return true;
786  }
827  static bool saveYAML(const std::string &filename, const vpArray2D<Type> &A, const char *header = "")
828  {
829  std::fstream file;
830 
831  file.open(filename.c_str(), std::fstream::out);
832 
833  if (!file) {
834  file.close();
835  return false;
836  }
837 
838  unsigned int i = 0;
839  bool inIndent = false;
840  std::string indent = "";
841  bool checkIndent = true;
842  while (header[i] != '\0') {
843  file << header[i];
844  if (checkIndent) {
845  if (inIndent) {
846  if (header[i] == ' ') {
847  indent += " ";
848  } else if (indent.length() > 0) {
849  checkIndent = false;
850  }
851  }
852  if (header[i] == '\n' || (inIndent && header[i] == ' ')) {
853  inIndent = true;
854  } else {
855  inIndent = false;
856  }
857  }
858  i++;
859  }
860 
861  if (i != 0) {
862  file << std::endl;
863  }
864  file << "rows: " << A.getRows() << std::endl;
865  file << "cols: " << A.getCols() << std::endl;
866 
867  if (indent.length() == 0) {
868  indent = " ";
869  }
870 
871  file << "data: " << std::endl;
872  unsigned int j;
873  for (i = 0; i < A.getRows(); ++i) {
874  file << indent << "- [";
875  for (j = 0; j < A.getCols() - 1; ++j) {
876  file << A[i][j] << ", ";
877  }
878  file << A[i][j] << "]" << std::endl;
879  }
880 
881  file.close();
882  return true;
883  }
885 };
886 
890 template <class Type> Type vpArray2D<Type>::getMinValue() const
891 {
892  Type *dataptr = data;
893  Type min = *dataptr;
894  dataptr++;
895  for (unsigned int i = 0; i < dsize - 1; i++) {
896  if (*dataptr < min) {
897  min = *dataptr;
898  }
899  dataptr++;
900  }
901  return min;
902 }
903 
907 template <class Type> Type vpArray2D<Type>::getMaxValue() const
908 {
909  Type *dataptr = data;
910  Type max = *dataptr;
911  dataptr++;
912  for (unsigned int i = 0; i < dsize - 1; i++) {
913  if (*dataptr > max) {
914  max = *dataptr;
915  }
916  dataptr++;
917  }
918  return max;
919 }
920 
927 template <class Type> vpArray2D<Type> vpArray2D<Type>::hadamard(const vpArray2D<Type> &m) const
928 {
929  if (m.getRows() != rowNum || m.getCols() != colNum) {
930  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
931  }
932 
933  vpArray2D<Type> out;
934  out.resize(rowNum, colNum, false);
935 
936  for (unsigned int i = 0; i < dsize; i++) {
937  out.data[i] = data[i] * m.data[i];
938  }
939 
940  return out;
941 }
942 
943 template <class Type> bool vpArray2D<Type>::operator==(const vpArray2D<Type> &A) const
944 {
945  if (A.rowNum != rowNum || A.colNum != colNum) {
946  return false;
947  }
948 
949  for (unsigned int i = 0; i < A.size(); i++) {
950  if (data[i] != A.data[i]) {
951  return false;
952  }
953  }
954 
955  return true;
956 }
957 
961 template <> inline bool vpArray2D<double>::operator==(const vpArray2D<double> &A) const
962 {
963  if (A.rowNum != rowNum || A.colNum != colNum) {
964  return false;
965  }
966 
967  for (unsigned int i = 0; i < A.size(); i++) {
968  if (fabs(data[i] - A.data[i]) > std::numeric_limits<double>::epsilon()) {
969  return false;
970  }
971  }
972 
973  return true;
974 }
975 
976 template <> inline bool vpArray2D<float>::operator==(const vpArray2D<float> &A) const
977 {
978  if (A.rowNum != rowNum || A.colNum != colNum) {
979  return false;
980  }
981 
982  for (unsigned int i = 0; i < A.size(); i++) {
983  if (fabsf(data[i] - A.data[i]) > std::numeric_limits<float>::epsilon()) {
984  return false;
985  }
986  }
987 
988  return true;
989 }
990 
991 template <class Type> bool vpArray2D<Type>::operator!=(const vpArray2D<Type> &A) const { return !(*this == A); }
992 
993 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:132
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:541
unsigned int getCols() const
Definition: vpArray2D.h:281
vpArray2D< Type > & operator=(const std::initializer_list< Type > &list)
Definition: vpArray2D.h:455
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
bool operator!=(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:991
Type ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139
vpArray2D< Type > & operator=(const vpArray2D< Type > &A)
Definition: vpArray2D.h:423
Type getMinValue() const
Definition: vpArray2D.h:890
Type * operator[](unsigned int i)
Set element using A[i][j] = x.
Definition: vpArray2D.h:485
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:306
vpArray2D< Type > & operator=(vpArray2D< Type > &&other) noexcept
Definition: vpArray2D.h:433
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:827
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:494
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:293
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:652
unsigned int getRows() const
Definition: vpArray2D.h:291
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:414
vpArray2D< Type > & operator=(const std::initializer_list< std::initializer_list< Type > > &lists)
Definition: vpArray2D.h:465
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:927
Type getMaxValue() const
Definition: vpArray2D.h:907
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:736
void reshape(unsigned int nrows, unsigned int ncols)
Definition: vpArray2D.h:381
Type * operator[](unsigned int i) const
Get element using x = A[i][j].
Definition: vpArray2D.h:487
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:137
bool operator==(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:943
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ badValue
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:97
@ dimensionError
Bad dimension.
Definition: vpException.h:95
@ memoryAllocationError
Memory allocation error.
Definition: vpException.h:88