Visual Servoing Platform  version 3.2.1 under development (2019-11-19)
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  #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
160  #else
161  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
162  #endif
163  {
164  resize(A.rowNum, A.colNum, false, false);
165  memcpy(data, A.data, (size_t)rowNum * (size_t)colNum * sizeof(Type));
166  }
167 
174  vpArray2D<Type>(unsigned int r, unsigned int c) :
175  #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
177  #else
178  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
179  #endif
180  {
181  resize(r, c);
182  }
183 
191  vpArray2D<Type>(unsigned int r, unsigned int c, Type val) :
192  #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
194  #else
195  rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
196  #endif
197  {
198  resize(r, c, false, false);
199  *this = val;
200  }
201 
202 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
204  {
205  rowNum = A.rowNum;
206  colNum = A.colNum;
207  rowPtrs = A.rowPtrs;
208  dsize = A.dsize;
209  data = A.data;
210 
211  A.rowNum = 0;
212  A.colNum = 0;
213  A.rowPtrs = NULL;
214  A.dsize = 0;
215  A.data = NULL;
216  }
217 
218  explicit vpArray2D<Type>(const std::initializer_list<Type> &list) : vpArray2D<Type>()
219  {
220  resize(1, static_cast<unsigned int>(list.size()), false, false);
221  std::copy(list.begin(), list.end(), data);
222  }
223 
224  explicit vpArray2D<Type>(unsigned int nrows, unsigned int ncols, const std::initializer_list<Type> &list)
225  : rowNum(0), colNum(0), rowPtrs(NULL), dsize(0), data(NULL)
226  {
227  if (nrows * ncols != static_cast<unsigned int>(list.size())) {
228  std::ostringstream oss;
229  oss << "Cannot create a vpArray2D of size (" << nrows << ", " << ncols
230  << ") with a list of size " << list.size();
231  throw vpException(vpException::dimensionError, oss.str());
232  }
233 
234  resize(nrows, ncols, false, false);
235  std::copy(list.begin(), list.end(), data);
236  }
237 
238  explicit vpArray2D<Type>(const std::initializer_list<std::initializer_list<Type> > &lists) : vpArray2D<Type>()
239  {
240  unsigned int nrows = static_cast<unsigned int>(lists.size()), ncols = 0;
241  for (auto& l : lists) {
242  if (static_cast<unsigned int>(l.size()) > ncols) {
243  ncols = static_cast<unsigned int>(l.size());
244  }
245  }
246 
247  resize(nrows, ncols, false, false);
248  auto it = lists.begin();
249  for (unsigned int i = 0; i < rowNum; i++, ++it) {
250  std::copy(it->begin(), it->end(), rowPtrs[i]);
251  }
252  }
253 #endif
254 
258  virtual ~vpArray2D<Type>()
259  {
260  if (data != NULL) {
261  free(data);
262  data = NULL;
263  }
264 
265  if (rowPtrs != NULL) {
266  free(rowPtrs);
267  rowPtrs = NULL;
268  }
269  rowNum = colNum = dsize = 0;
270  }
271 
274 
279  inline unsigned int getCols() const { return colNum; }
280 
281  Type getMaxValue() const;
282 
283  Type getMinValue() const;
284 
289  inline unsigned int getRows() const { return rowNum; }
291  inline unsigned int size() const { return colNum * rowNum; }
292 
305  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify = true,
306  const 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  const unsigned int minRow = (this->rowNum < rowTmp) ? this->rowNum : rowTmp;
363  const 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
391  << " into shape (" << nrows << ", " << ncols << ")";
392  throw vpException(vpException::dimensionError, oss.str());
393  }
394 
395  rowNum = nrows;
396  colNum = ncols;
397  rowPtrs = reinterpret_cast<Type **>(realloc(rowPtrs, nrows * sizeof(Type *)));
398  // Update rowPtrs
399  Type **t_ = rowPtrs;
400  for (unsigned int i = 0; i < dsize; i += ncols) {
401  *t_++ = data + i;
402  }
403  }
404 
408  bool operator==(const vpArray2D<Type>& A) const;
412  bool operator!=(const vpArray2D<Type>& A) const;
413 
416  {
417  std::fill(data, data + dsize, x);
418  return *this;
419  }
420 
425  {
426  resize(A.rowNum, A.colNum, false, false);
427  if (data != NULL && A.data != NULL && data != A.data) {
428  memcpy(data, A.data, (size_t)rowNum * (size_t)colNum * sizeof(Type));
429  }
430  return *this;
431  }
432 
433 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
435  {
436  if (this != &other) {
437  free(data);
438  free(rowPtrs);
439 
440  rowNum = other.rowNum;
441  colNum = other.colNum;
442  rowPtrs = other.rowPtrs;
443  dsize = other.dsize;
444  data = other.data;
445 
446  other.rowNum = 0;
447  other.colNum = 0;
448  other.rowPtrs = NULL;
449  other.dsize = 0;
450  other.data = NULL;
451  }
452 
453  return *this;
454  }
455 
456  vpArray2D<Type> &operator=(const std::initializer_list<Type> &list)
457  {
458  if (dsize != static_cast<unsigned int>(list.size())) {
459  resize(1, static_cast<unsigned int>(list.size()), false, false);
460  }
461  std::copy(list.begin(), list.end(), data);
462 
463  return *this;
464  }
465 
466  vpArray2D<Type> &operator=(const std::initializer_list<std::initializer_list<Type> > &lists)
467  {
468  unsigned int nrows = static_cast<unsigned int>(lists.size()), ncols = 0;
469  for (auto& l : lists) {
470  if (static_cast<unsigned int>(l.size()) > ncols) {
471  ncols = static_cast<unsigned int>(l.size());
472  }
473  }
474 
475  resize(nrows, ncols, false, false);
476  auto it = lists.begin();
477  for (unsigned int i = 0; i < rowNum; i++, ++it) {
478  std::copy(it->begin(), it->end(), rowPtrs[i]);
479  }
480 
481  return *this;
482  }
483 #endif
484 
486  inline Type *operator[](unsigned int i) { return rowPtrs[i]; }
488  inline Type *operator[](unsigned int i) const { return rowPtrs[i]; }
489 
495  friend std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A)
496  {
497  if (A.data == NULL || A.size() == 0) {
498  return s;
499  }
500  std::ios_base::fmtflags original_flags = s.flags();
501 
502  s.precision(10);
503  for (unsigned int i = 0; i < A.getRows(); i++) {
504  for (unsigned int j = 0; j < A.getCols() - 1; j++) {
505  s << A[i][j] << " ";
506  }
507  // We don't add " " after the last row element
508  s << A[i][A.getCols() - 1];
509  // We don't add a \n char on the end of the last array line
510  if (i < A.getRows() - 1) {
511  s << std::endl;
512  }
513  }
514 
515  s.flags(original_flags); // restore s to standard state
516 
517  return s;
518  }
519 
520  vpArray2D<Type> hadamard(const vpArray2D<Type> &m) const;
522 
523  //---------------------------------
524  // Inherited array I/O Static Public Member Functions
525  //---------------------------------
542  static bool load(const std::string &filename, vpArray2D<Type> &A, const bool binary = false, char *header = NULL)
543  {
544  std::fstream file;
545 
546  if (!binary) {
547  file.open(filename.c_str(), std::fstream::in);
548  }
549  else {
550  file.open(filename.c_str(), std::fstream::in | std::fstream::binary);
551  }
552 
553  if (!file) {
554  file.close();
555  return false;
556  }
557 
558  if (!binary) {
559  std::string h;
560  bool headerIsDecoded = false;
561  do {
562  std::streampos pos = file.tellg();
563  char line[256];
564  file.getline(line, 256);
565  std::string prefix("# ");
566  std::string line_(line);
567  if (line_.compare(0, 2, prefix.c_str()) == 0) {
568  // Line is a comment
569  // If we are not on the first line, we should add "\n" to the end of
570  // the previous line
571  if (pos) {
572  h += "\n";
573  }
574  h += line_.substr(2); // Remove "# "
575  } else {
576  // rewind before the line
577  file.seekg(pos, file.beg);
578  headerIsDecoded = true;
579  }
580  } while (!headerIsDecoded);
581 
582  if (header != NULL) {
583 #if defined(__MINGW32__) || \
584  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
585  sprintf(header, "%s", h.c_str());
586 #else
587  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
588 #endif
589  }
590 
591  unsigned int rows, cols;
592  file >> rows;
593  file >> cols;
594 
595  if (rows >= (std::numeric_limits<unsigned int>::max)() || cols >= (std::numeric_limits<unsigned int>::max)()) {
596  throw vpException(vpException::badValue, "Array exceed the max size.");
597  }
598 
599  A.resize(rows, cols);
600 
601  Type value;
602  for (unsigned int i = 0; i < rows; i++) {
603  for (unsigned int j = 0; j < cols; j++) {
604  file >> value;
605  A[i][j] = value;
606  }
607  }
608  } else {
609  char c = '0';
610  std::string h;
611  // Decode header until '\0' char that ends the header string
612  while (c != '\0') {
613  file.read(&c, 1);
614  h += c;
615  }
616  if (header != NULL) {
617 #if defined(__MINGW32__) || \
618  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
619  sprintf(header, "%s", h.c_str());
620 #else
621  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
622 #endif
623  }
624 
625  unsigned int rows, cols;
626  file.read((char *)&rows, sizeof(unsigned int));
627  file.read((char *)&cols, sizeof(unsigned int));
628  A.resize(rows, cols);
629 
630  Type value;
631  for (unsigned int i = 0; i < rows; i++) {
632  for (unsigned int j = 0; j < cols; j++) {
633  file.read((char *)&value, sizeof(Type));
634  A[i][j] = value;
635  }
636  }
637  }
638 
639  file.close();
640  return true;
641  }
654  static bool loadYAML(const std::string &filename, vpArray2D<Type> &A, char *header = NULL)
655  {
656  std::fstream file;
657 
658  file.open(filename.c_str(), std::fstream::in);
659 
660  if (!file) {
661  file.close();
662  return false;
663  }
664 
665  unsigned int rows = 0, cols = 0;
666  std::string h;
667  std::string line, subs;
668  bool inheader = true;
669  unsigned int i = 0, j;
670  unsigned int lineStart = 0;
671 
672  while (getline(file, line)) {
673  if (inheader) {
674  if (rows == 0 && line.compare(0, 5, "rows:") == 0) {
675  std::stringstream ss(line);
676  ss >> subs;
677  ss >> rows;
678  } else if (cols == 0 && line.compare(0, 5, "cols:") == 0) {
679  std::stringstream ss(line);
680  ss >> subs;
681  ss >> cols;
682  } else if (line.compare(0, 5, "data:") == 0) {
683  inheader = false;
684  }
685  else {
686  h += line + "\n";
687  }
688  } else {
689  // if i == 0, we just got out of the header: initialize matrix
690  // dimensions
691  if (i == 0) {
692  if (rows == 0 || cols == 0) {
693  file.close();
694  return false;
695  }
696  A.resize(rows, cols);
697  // get indentation level which is common to all lines
698  lineStart = (unsigned int)line.find("[") + 1;
699  }
700  std::stringstream ss(line.substr(lineStart, line.find("]") - lineStart));
701  j = 0;
702  while (getline(ss, subs, ',')) {
703  A[i][j++] = atof(subs.c_str());
704  }
705  i++;
706  }
707  }
708 
709  if (header != NULL) {
710  std::string h_ = h.substr(0, h.size() - 1); // Remove last '\n' char
711 #if defined(__MINGW32__) || \
712  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
713  sprintf(header, "%s", h_.c_str());
714 #else
715  _snprintf_s(header, h_.size() + 1, _TRUNCATE, "%s", h_.c_str());
716 #endif
717  }
718 
719  file.close();
720  return true;
721  }
722 
739  static bool save(const std::string &filename, const vpArray2D<Type> &A, const bool binary = false,
740  const char *header = "")
741  {
742  std::fstream file;
743 
744  if (!binary) {
745  file.open(filename.c_str(), std::fstream::out);
746  }
747  else {
748  file.open(filename.c_str(), std::fstream::out | std::fstream::binary);
749  }
750 
751  if (!file) {
752  file.close();
753  return false;
754  }
755 
756  if (!binary) {
757  unsigned int i = 0;
758  file << "# ";
759  while (header[i] != '\0') {
760  file << header[i];
761  if (header[i] == '\n') {
762  file << "# ";
763  }
764  i++;
765  }
766  file << std::endl;
767  file << A.getRows() << "\t" << A.getCols() << std::endl;
768  file << A << std::endl;
769  } else {
770  int headerSize = 0;
771  while (header[headerSize] != '\0') {
772  headerSize++;
773  }
774  file.write(header, (size_t)headerSize + (size_t)1);
775  unsigned int matrixSize;
776  matrixSize = A.getRows();
777  file.write((char *)&matrixSize, sizeof(unsigned int));
778  matrixSize = A.getCols();
779  file.write((char *)&matrixSize, sizeof(unsigned int));
780  Type value;
781  for (unsigned int i = 0; i < A.getRows(); i++) {
782  for (unsigned int j = 0; j < A.getCols(); j++) {
783  value = A[i][j];
784  file.write((char *)&value, sizeof(Type));
785  }
786  }
787  }
788 
789  file.close();
790  return true;
791  }
832  static bool saveYAML(const std::string &filename, const vpArray2D<Type> &A, const char *header = "")
833  {
834  std::fstream file;
835 
836  file.open(filename.c_str(), std::fstream::out);
837 
838  if (!file) {
839  file.close();
840  return false;
841  }
842 
843  unsigned int i = 0;
844  bool inIndent = false;
845  std::string indent = "";
846  bool checkIndent = true;
847  while (header[i] != '\0') {
848  file << header[i];
849  if (checkIndent) {
850  if (inIndent) {
851  if (header[i] == ' ') {
852  indent += " ";
853  }
854  else if (indent.length() > 0) {
855  checkIndent = false;
856  }
857  }
858  if (header[i] == '\n' || (inIndent && header[i] == ' ')) {
859  inIndent = true;
860  }
861  else {
862  inIndent = false;
863  }
864  }
865  i++;
866  }
867 
868  if (i != 0) {
869  file << std::endl;
870  }
871  file << "rows: " << A.getRows() << std::endl;
872  file << "cols: " << A.getCols() << std::endl;
873 
874  if (indent.length() == 0) {
875  indent = " ";
876  }
877 
878  file << "data: " << std::endl;
879  unsigned int j;
880  for (i = 0; i < A.getRows(); ++i) {
881  file << indent << "- [";
882  for (j = 0; j < A.getCols() - 1; ++j) {
883  file << A[i][j] << ", ";
884  }
885  file << A[i][j] << "]" << std::endl;
886  }
887 
888  file.close();
889  return true;
890  }
892 };
893 
897 template <class Type> Type vpArray2D<Type>::getMinValue() const
898 {
899  Type *dataptr = data;
900  Type min = *dataptr;
901  dataptr++;
902  for (unsigned int i = 0; i < dsize - 1; i++) {
903  if (*dataptr < min) {
904  min = *dataptr;
905  }
906  dataptr++;
907  }
908  return min;
909 }
910 
914 template <class Type> Type vpArray2D<Type>::getMaxValue() const
915 {
916  Type *dataptr = data;
917  Type max = *dataptr;
918  dataptr++;
919  for (unsigned int i = 0; i < dsize - 1; i++) {
920  if (*dataptr > max) {
921  max = *dataptr;
922  }
923  dataptr++;
924  }
925  return max;
926 }
927 
934 template <class Type> vpArray2D<Type> vpArray2D<Type>::hadamard(const vpArray2D<Type> &m) const
935 {
936  if (m.getRows() != rowNum || m.getCols() != colNum) {
937  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
938  }
939 
940  vpArray2D<Type> out;
941  out.resize(rowNum, colNum, false);
942 
943  for (unsigned int i = 0; i < dsize; i++) {
944  out.data[i] = data[i] * m.data[i];
945  }
946 
947  return out;
948 }
949 
950 template <class Type> bool vpArray2D<Type>::operator==(const vpArray2D<Type>& A) const
951 {
952  if (A.rowNum != rowNum || A.colNum != colNum) {
953  return false;
954  }
955 
956  for (unsigned int i = 0; i < A.size(); i++) {
957  if (data[i] != A.data[i]) {
958  return false;
959  }
960  }
961 
962  return true;
963 }
964 
965 template <> inline bool vpArray2D<double>::operator==(const vpArray2D<double>& A) const
966 {
967  if (A.rowNum != rowNum || A.colNum != colNum) {
968  return false;
969  }
970 
971  for (unsigned int i = 0; i < A.size(); i++) {
972  if (fabs(data[i] - A.data[i]) > std::numeric_limits<double>::epsilon()) {
973  return false;
974  }
975  }
976 
977  return true;
978 }
979 
980 template <> inline bool vpArray2D<float>::operator==(const vpArray2D<float>& A) const
981 {
982  if (A.rowNum != rowNum || A.colNum != colNum) {
983  return false;
984  }
985 
986  for (unsigned int i = 0; i < A.size(); i++) {
987  if (fabsf(data[i] - A.data[i]) > std::numeric_limits<float>::epsilon()) {
988  return false;
989  }
990  }
991 
992  return true;
993 }
994 
995 template <class Type> bool vpArray2D<Type>::operator!=(const vpArray2D<Type>& A) const
996 {
997  return !(*this == A);
998 }
999 
1000 #endif
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:97
static bool save(const std::string &filename, const vpArray2D< Type > &A, const bool binary=false, const char *header="")
Definition: vpArray2D.h:739
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:832
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:415
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:654
Type * operator[](unsigned int i) const
Get element using x = A[i][j].
Definition: vpArray2D.h:488
bool operator!=(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:995
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:305
error that can be emited by ViSP classes.
Definition: vpException.h:71
unsigned int getRows() const
Definition: vpArray2D.h:289
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
Implementation of a generic 2D array used as base class for matrices and vectors. ...
Definition: vpArray2D.h:131
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
vpArray2D< Type > & operator=(vpArray2D< Type > &&other)
Definition: vpArray2D.h:434
Type getMaxValue() const
Definition: vpArray2D.h:914
unsigned int getCols() const
Definition: vpArray2D.h:279
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
Type getMinValue() const
Definition: vpArray2D.h:897
vpArray2D< Type > & operator=(const vpArray2D< Type > &A)
Definition: vpArray2D.h:424
static bool load(const std::string &filename, vpArray2D< Type > &A, const bool binary=false, char *header=NULL)
Definition: vpArray2D.h:542
Memory allocation error.
Definition: vpException.h:88
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:934
bool operator==(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:950
vpArray2D< Type > & operator=(const std::initializer_list< Type > &list)
Definition: vpArray2D.h:456
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:137
Type * operator[](unsigned int i)
Set element using A[i][j] = x.
Definition: vpArray2D.h:486
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
void reshape(unsigned int nrows, unsigned int ncols)
Definition: vpArray2D.h:381
Type ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139
vpArray2D< Type > & operator=(const std::initializer_list< std::initializer_list< Type > > &lists)
Definition: vpArray2D.h:466