Matrix.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 // Header
25 #include "Matrix.h"
26 
27 // Simox
28 #include <SimoxUtility/algorithm/vector.hpp>
29 
30 namespace armarx::aron::type
31 {
32  const std::map<matrix::ElementType, std::string> Matrix::Elementtype2String{
33  {matrix::ElementType::INT16, "INT16"},
34  {matrix::ElementType::INT32, "INT32"},
35  {matrix::ElementType::INT64, "INT64"},
36  {matrix::ElementType::FLOAT32, "FLOAT32"},
37  {matrix::ElementType::FLOAT64, "FLOAT64"}};
38 
39  const std::map<std::string, matrix::ElementType> Matrix::String2Elementtype =
40  conversion::util::InvertMap(Elementtype2String);
41 
42  // constructors
43  Matrix::Matrix(const Path& path) :
44  detail::NDArrayVariant<type::dto::Matrix, Matrix>(type::Descriptor::MATRIX, path)
45  {
46  }
47 
48  Matrix::Matrix(const type::dto::Matrix& o, const Path& path) :
49  detail::NDArrayVariant<type::dto::Matrix, Matrix>(o, type::Descriptor::MATRIX, path)
50  {
51  }
52 
53  int
55  {
56  return this->aron->rows;
57  }
58 
59  int
61  {
62  return this->aron->cols;
63  }
64 
65  void
66  Matrix::setRows(const int w)
67  {
68  if (w == 0 || w < -1)
69  {
71  __PRETTY_FUNCTION__, "The rows cannot be 0 or < -1", getPath());
72  }
73  this->aron->rows = w;
74  }
75 
76  void
77  Matrix::setCols(const int h)
78  {
79  if (h == 0 || h < -1)
80  {
82  __PRETTY_FUNCTION__, "The cols cannot be 0 or < -1", getPath());
83  }
84  this->aron->cols = h;
85  }
86 
89  {
90  return this->aron->elementType;
91  }
92 
93  void
95  {
96  this->aron->elementType = u;
97  }
98 
101  {
102  return this->aron;
103  }
104 
105  // virtual implementations
106  std::string
108  {
109  return "Matrix";
110  }
111 
112  std::string
114  {
115  std::string rows = std::to_string(aron->rows);
116  std::string cols = std::to_string(aron->cols);
117 
118  if (aron->rows == -1)
119  {
120  rows = "Dynamic";
121  }
122 
123  if (aron->cols == -1)
124  {
125  cols = "Dynamic";
126  }
127 
128  return "armarx::aron::type::Matrix<" + rows + ", " + cols + ", " +
129  Elementtype2String.at(this->aron->elementType) + ">";
130  }
131 } // namespace armarx::aron::type
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::aron::type::Matrix::String2Elementtype
static const std::map< std::string, matrix::ElementType > String2Elementtype
Definition: Matrix.h:61
armarx::aron::type::MatrixPtr
std::shared_ptr< class Matrix > MatrixPtr
Definition: forward_declarations.h:20
armarx::aron::type::Matrix::setElementType
void setElementType(const type::matrix::ElementType)
Definition: Matrix.cpp:94
Matrix
Eigen::Matrix< T, 3, 3 > Matrix
Definition: UnscentedKalmanFilterTest.cpp:37
armarx::aron::type::Matrix::getFullName
std::string getFullName() const override
get the full name of this specific type
Definition: Matrix.cpp:113
Matrix.h
detail
Definition: OpenCVUtil.cpp:127
armarx::aron::type::Matrix::getCols
int getCols() const
Definition: Matrix.cpp:60
armarx::aron::type::Matrix::setRows
void setRows(const int)
Definition: Matrix.cpp:66
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::conversion::util::InvertMap
std::map< T2, T1 > InvertMap(const std::map< T1, T2 > &m)
Definition: Descriptor.h:42
armarx::aron::type::Matrix::toMatrixDTO
type::dto::MatrixPtr toMatrixDTO() const
Definition: Matrix.cpp:100
armarx::aron::type::detail::SpecializedVariantBase< type::dto::Matrix, Matrix >::aron
type::dto::Matrix ::PointerType aron
Definition: SpecializedVariant.h:137
armarx::aron::type::Descriptor::MATRIX
@ MATRIX
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::aron::type::Matrix::setCols
void setCols(const int)
Definition: Matrix.cpp:77
armarx::aron::type::Matrix::Matrix
Matrix(const Path &path=Path())
Definition: Matrix.cpp:43
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::type::Matrix::getElementType
type::matrix::ElementType getElementType() const
Definition: Matrix.cpp:88
armarx::aron::type::Matrix::getShortName
std::string getShortName() const override
get a short name of this specific type
Definition: Matrix.cpp:107
armarx::aron::type::Matrix::Elementtype2String
static const std::map< matrix::ElementType, std::string > Elementtype2String
Definition: Matrix.h:60
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::Matrix::getRows
int getRows() const
Definition: Matrix.cpp:54
armarx::aron::type::Matrix
The Matrix class.
Definition: Matrix.h:39
armarx::aron::type::Variant::getPath
Path getPath() const
Definition: Variant.h:99