Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
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(unsigned int nrows, unsigned int ncols, bool flagNullify = true, bool recopy_ = true)
306  {
307  if ((nrows == rowNum) && (ncols == colNum)) {
308  if (flagNullify && this->data != NULL) {
309  memset(this->data, 0, this->dsize * sizeof(Type));
310  }
311  } else {
312  bool recopy = !flagNullify && recopy_; // priority to flagNullify
313  const bool recopyNeeded = (ncols != this->colNum && this->colNum > 0 && ncols > 0 && (!flagNullify || recopy));
314  Type *copyTmp = NULL;
315  unsigned int rowTmp = 0, colTmp = 0;
316 
317  // Recopy case per case is required if number of cols has changed;
318  // structure of Type array is not the same in this case.
319  if (recopyNeeded && this->data != NULL) {
320  copyTmp = new Type[this->dsize];
321  memcpy(copyTmp, this->data, sizeof(Type) * this->dsize);
322  rowTmp = this->rowNum;
323  colTmp = this->colNum;
324  }
325 
326  // Reallocation of this->data array
327  this->dsize = nrows * ncols;
328  this->data = (Type *)realloc(this->data, this->dsize * sizeof(Type));
329  if ((NULL == this->data) && (0 != this->dsize)) {
330  if (copyTmp != NULL) {
331  delete[] copyTmp;
332  }
333  throw(vpException(vpException::memoryAllocationError, "Memory allocation error when allocating 2D array data"));
334  }
335 
336  this->rowPtrs = (Type **)realloc(this->rowPtrs, nrows * sizeof(Type *));
337  if ((NULL == this->rowPtrs) && (0 != this->dsize)) {
338  if (copyTmp != NULL) {
339  delete[] copyTmp;
340  }
342  "Memory allocation error when allocating 2D array rowPtrs"));
343  }
344 
345  // Update rowPtrs
346  {
347  Type **t_ = rowPtrs;
348  for (unsigned int i = 0; i < dsize; i += ncols) {
349  *t_++ = this->data + i;
350  }
351  }
352 
353  this->rowNum = nrows;
354  this->colNum = ncols;
355 
356  // Recopy of this->data array values or nullify
357  if (flagNullify) {
358  memset(this->data, 0, (size_t)(this->dsize) * sizeof(Type));
359  } else if (recopyNeeded && this->rowPtrs != NULL) {
360  // Recopy...
361  unsigned int minRow = (this->rowNum < rowTmp) ? this->rowNum : rowTmp;
362  unsigned int minCol = (this->colNum < colTmp) ? this->colNum : colTmp;
363  for (unsigned int i = 0; i < this->rowNum; ++i) {
364  for (unsigned int j = 0; j < this->colNum; ++j) {
365  if ((minRow > i) && (minCol > j)) {
366  (*this)[i][j] = copyTmp[i * colTmp + j];
367  } else {
368  (*this)[i][j] = 0;
369  }
370  }
371  }
372  }
373 
374  if (copyTmp != NULL) {
375  delete[] copyTmp;
376  }
377  }
378  }
379 
380  void reshape(unsigned int nrows, unsigned int ncols)
381  {
382  if (dsize == 0) {
383  resize(nrows, ncols);
384  return;
385  }
386 
387  if (nrows * ncols != dsize) {
388  std::ostringstream oss;
389  oss << "Cannot reshape array of total size " << dsize
390  << " 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 
519  vpArray2D<Type> hadamard(const vpArray2D<Type> &m) const;
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  }
548  else {
549  file.open(filename.c_str(), std::fstream::in | std::fstream::binary);
550  }
551 
552  if (!file) {
553  file.close();
554  return false;
555  }
556 
557  if (!binary) {
558  std::string h;
559  bool headerIsDecoded = false;
560  do {
561  std::streampos pos = file.tellg();
562  char line[256];
563  file.getline(line, 256);
564  std::string prefix("# ");
565  std::string line_(line);
566  if (line_.compare(0, 2, prefix.c_str()) == 0) {
567  // Line is a comment
568  // If we are not on the first line, we should add "\n" to the end of
569  // the previous line
570  if (pos) {
571  h += "\n";
572  }
573  h += line_.substr(2); // Remove "# "
574  } else {
575  // rewind before the line
576  file.seekg(pos, file.beg);
577  headerIsDecoded = true;
578  }
579  } while (!headerIsDecoded);
580 
581  if (header != NULL) {
582 #if defined(__MINGW32__) || \
583  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
584  sprintf(header, "%s", h.c_str());
585 #else
586  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
587 #endif
588  }
589 
590  unsigned int rows, cols;
591  file >> rows;
592  file >> cols;
593 
594  if (rows >= (std::numeric_limits<unsigned int>::max)() || cols >= (std::numeric_limits<unsigned int>::max)()) {
595  throw vpException(vpException::badValue, "Array exceed the max size.");
596  }
597 
598  A.resize(rows, cols);
599 
600  Type value;
601  for (unsigned int i = 0; i < rows; i++) {
602  for (unsigned int j = 0; j < cols; j++) {
603  file >> value;
604  A[i][j] = value;
605  }
606  }
607  } else {
608  char c = '0';
609  std::string h;
610  // Decode header until '\0' char that ends the header string
611  while (c != '\0') {
612  file.read(&c, 1);
613  h += c;
614  }
615  if (header != NULL) {
616 #if defined(__MINGW32__) || \
617  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
618  sprintf(header, "%s", h.c_str());
619 #else
620  _snprintf_s(header, h.size() + 1, _TRUNCATE, "%s", h.c_str());
621 #endif
622  }
623 
624  unsigned int rows, cols;
625  file.read((char *)&rows, sizeof(unsigned int));
626  file.read((char *)&cols, sizeof(unsigned int));
627  A.resize(rows, cols);
628 
629  Type value;
630  for (unsigned int i = 0; i < rows; i++) {
631  for (unsigned int j = 0; j < cols; j++) {
632  file.read((char *)&value, sizeof(Type));
633  A[i][j] = value;
634  }
635  }
636  }
637 
638  file.close();
639  return true;
640  }
653  static bool loadYAML(const std::string &filename, vpArray2D<Type> &A, char *header = NULL)
654  {
655  std::fstream file;
656 
657  file.open(filename.c_str(), std::fstream::in);
658 
659  if (!file) {
660  file.close();
661  return false;
662  }
663 
664  unsigned int rows = 0, cols = 0;
665  std::string h;
666  std::string line, subs;
667  bool inheader = true;
668  unsigned int i = 0, j;
669  unsigned int lineStart = 0;
670 
671  while (getline(file, line)) {
672  if (inheader) {
673  if (rows == 0 && line.compare(0, 5, "rows:") == 0) {
674  std::stringstream ss(line);
675  ss >> subs;
676  ss >> rows;
677  } else if (cols == 0 && line.compare(0, 5, "cols:") == 0) {
678  std::stringstream ss(line);
679  ss >> subs;
680  ss >> cols;
681  } else if (line.compare(0, 5, "data:") == 0) {
682  inheader = false;
683  }
684  else {
685  h += line + "\n";
686  }
687  } else {
688  // if i == 0, we just got out of the header: initialize matrix
689  // dimensions
690  if (i == 0) {
691  if (rows == 0 || cols == 0) {
692  file.close();
693  return false;
694  }
695  A.resize(rows, cols);
696  // get indentation level which is common to all lines
697  lineStart = (unsigned int)line.find("[") + 1;
698  }
699  std::stringstream ss(line.substr(lineStart, line.find("]") - lineStart));
700  j = 0;
701  while (getline(ss, subs, ',')) {
702  A[i][j++] = atof(subs.c_str());
703  }
704  i++;
705  }
706  }
707 
708  if (header != NULL) {
709  std::string h_ = h.substr(0, h.size() - 1); // Remove last '\n' char
710 #if defined(__MINGW32__) || \
711  !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
712  sprintf(header, "%s", h_.c_str());
713 #else
714  _snprintf_s(header, h_.size() + 1, _TRUNCATE, "%s", h_.c_str());
715 #endif
716  }
717 
718  file.close();
719  return true;
720  }
721 
738  static bool save(const std::string &filename, const vpArray2D<Type> &A, bool binary = false,
739  const char *header = "")
740  {
741  std::fstream file;
742 
743  if (!binary) {
744  file.open(filename.c_str(), std::fstream::out);
745  }
746  else {
747  file.open(filename.c_str(), std::fstream::out | std::fstream::binary);
748  }
749 
750  if (!file) {
751  file.close();
752  return false;
753  }
754 
755  if (!binary) {
756  unsigned int i = 0;
757  file << "# ";
758  while (header[i] != '\0') {
759  file << header[i];
760  if (header[i] == '\n') {
761  file << "# ";
762  }
763  i++;
764  }
765  file << std::endl;
766  file << A.getRows() << "\t" << A.getCols() << std::endl;
767  file << A << std::endl;
768  } else {
769  int headerSize = 0;
770  while (header[headerSize] != '\0') {
771  headerSize++;
772  }
773  file.write(header, (size_t)headerSize + (size_t)1);
774  unsigned int matrixSize;
775  matrixSize = A.getRows();
776  file.write((char *)&matrixSize, sizeof(unsigned int));
777  matrixSize = A.getCols();
778  file.write((char *)&matrixSize, sizeof(unsigned int));
779  Type value;
780  for (unsigned int i = 0; i < A.getRows(); i++) {
781  for (unsigned int j = 0; j < A.getCols(); j++) {
782  value = A[i][j];
783  file.write((char *)&value, sizeof(Type));
784  }
785  }
786  }
787 
788  file.close();
789  return true;
790  }
831  static bool saveYAML(const std::string &filename, const vpArray2D<Type> &A, const char *header = "")
832  {
833  std::fstream file;
834 
835  file.open(filename.c_str(), std::fstream::out);
836 
837  if (!file) {
838  file.close();
839  return false;
840  }
841 
842  unsigned int i = 0;
843  bool inIndent = false;
844  std::string indent = "";
845  bool checkIndent = true;
846  while (header[i] != '\0') {
847  file << header[i];
848  if (checkIndent) {
849  if (inIndent) {
850  if (header[i] == ' ') {
851  indent += " ";
852  }
853  else if (indent.length() > 0) {
854  checkIndent = false;
855  }
856  }
857  if (header[i] == '\n' || (inIndent && header[i] == ' ')) {
858  inIndent = true;
859  }
860  else {
861  inIndent = false;
862  }
863  }
864  i++;
865  }
866 
867  if (i != 0) {
868  file << std::endl;
869  }
870  file << "rows: " << A.getRows() << std::endl;
871  file << "cols: " << A.getCols() << std::endl;
872 
873  if (indent.length() == 0) {
874  indent = " ";
875  }
876 
877  file << "data: " << std::endl;
878  unsigned int j;
879  for (i = 0; i < A.getRows(); ++i) {
880  file << indent << "- [";
881  for (j = 0; j < A.getCols() - 1; ++j) {
882  file << A[i][j] << ", ";
883  }
884  file << A[i][j] << "]" << std::endl;
885  }
886 
887  file.close();
888  return true;
889  }
891 };
892 
896 template <class Type> Type vpArray2D<Type>::getMinValue() const
897 {
898  Type *dataptr = data;
899  Type min = *dataptr;
900  dataptr++;
901  for (unsigned int i = 0; i < dsize - 1; i++) {
902  if (*dataptr < min) {
903  min = *dataptr;
904  }
905  dataptr++;
906  }
907  return min;
908 }
909 
913 template <class Type> Type vpArray2D<Type>::getMaxValue() const
914 {
915  Type *dataptr = data;
916  Type max = *dataptr;
917  dataptr++;
918  for (unsigned int i = 0; i < dsize - 1; i++) {
919  if (*dataptr > max) {
920  max = *dataptr;
921  }
922  dataptr++;
923  }
924  return max;
925 }
926 
933 template <class Type> vpArray2D<Type> vpArray2D<Type>::hadamard(const vpArray2D<Type> &m) const
934 {
935  if (m.getRows() != rowNum || m.getCols() != colNum) {
936  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
937  }
938 
939  vpArray2D<Type> out;
940  out.resize(rowNum, colNum, false);
941 
942  for (unsigned int i = 0; i < dsize; i++) {
943  out.data[i] = data[i] * m.data[i];
944  }
945 
946  return out;
947 }
948 
949 template <class Type> bool vpArray2D<Type>::operator==(const vpArray2D<Type>& A) const
950 {
951  if (A.rowNum != rowNum || A.colNum != colNum) {
952  return false;
953  }
954 
955  for (unsigned int i = 0; i < A.size(); i++) {
956  if (data[i] != A.data[i]) {
957  return false;
958  }
959  }
960 
961  return true;
962 }
963 
964 template <> inline bool vpArray2D<double>::operator==(const vpArray2D<double>& A) const
965 {
966  if (A.rowNum != rowNum || A.colNum != colNum) {
967  return false;
968  }
969 
970  for (unsigned int i = 0; i < A.size(); i++) {
971  if (fabs(data[i] - A.data[i]) > std::numeric_limits<double>::epsilon()) {
972  return false;
973  }
974  }
975 
976  return true;
977 }
978 
979 template <> inline bool vpArray2D<float>::operator==(const vpArray2D<float>& A) const
980 {
981  if (A.rowNum != rowNum || A.colNum != colNum) {
982  return false;
983  }
984 
985  for (unsigned int i = 0; i < A.size(); i++) {
986  if (fabsf(data[i] - A.data[i]) > std::numeric_limits<float>::epsilon()) {
987  return false;
988  }
989  }
990 
991  return true;
992 }
993 
994 template <class Type> bool vpArray2D<Type>::operator!=(const vpArray2D<Type>& A) const
995 {
996  return !(*this == A);
997 }
998 
999 #endif
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:97
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:831
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:305
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:414
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:653
Type * operator[](unsigned int i) const
Get element using x = A[i][j].
Definition: vpArray2D.h:487
bool operator!=(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:994
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:738
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:433
Type getMaxValue() const
Definition: vpArray2D.h:913
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:896
vpArray2D< Type > & operator=(const vpArray2D< Type > &A)
Definition: vpArray2D.h:423
Memory allocation error.
Definition: vpException.h:88
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:933
bool operator==(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:949
vpArray2D< Type > & operator=(const std::initializer_list< Type > &list)
Definition: vpArray2D.h:455
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:485
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
void reshape(unsigned int nrows, unsigned int ncols)
Definition: vpArray2D.h:380
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:465
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:541