MatrixVariant.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::Core
19 * @author Peter Kaiser <peter.kaiser@kit.edu>
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <Eigen/Core>
28
29#include <ArmarXCore/interface/observers/Matrix.h>
31
32//#include <Eigen/Geometry>
33
34namespace armarx::VariantType
35{
36 // Variant types
37 const VariantTypeId MatrixFloat = Variant::addTypeName("::armarx::MatrixFloatBase");
38 const VariantTypeId MatrixDouble = Variant::addTypeName("::armarx::MatrixDoubleBase");
39} // namespace armarx::VariantType
40
41namespace armarx
42{
43 /**
44 * @class MatrixFloat
45 * @ingroup VariantsGrp
46 * @brief The MatrixFloat class
47 */
48 class MatrixFloat : virtual public MatrixFloatBase
49 {
50 template <class BaseClass, class VariantClass>
51 friend class GenericFactory;
52
53 protected:
55
56 public:
57 MatrixFloat(int rows, int cols);
58 MatrixFloat(const Eigen::MatrixXf&);
59 MatrixFloat(int rows, int cols, const std::vector<float>& entries);
60
61 //void setMatrix(int width, int height, const std::vector<float> &entries);
62
63 virtual Eigen::MatrixXf toEigen() const;
64
65 std::vector<float> toVector() const;
66
67 // inherited from VariantDataClass
68 Ice::ObjectPtr
69 ice_clone() const override
70 {
71 return this->clone();
72 }
73
74 VariantDataClassPtr
75 clone(const Ice::Current& c = Ice::emptyCurrent) const override
76 {
77 return new MatrixFloat(*this);
78 }
79
80 std::string
81 output(const Ice::Current& c = Ice::emptyCurrent) const override
82 {
83 std::stringstream s;
84 s << toEigen();
85 return s.str();
86 }
87
89 getType(const Ice::Current& c = Ice::emptyCurrent) const override
90 {
92 }
93
94 bool
95 validate(const Ice::Current& c = Ice::emptyCurrent) override
96 {
97 return true;
98 }
99
100 float& operator()(const int x, const int y);
101
102 std::string toJsonRowMajor();
103
104 friend std::ostream&
105 operator<<(std::ostream& stream, const MatrixFloat& rhs)
106 {
107 stream << "MatrixFloat: " << std::endl << rhs.output() << std::endl;
108 return stream;
109 }
110
111 public:
112 // serialization
113 void serialize(const armarx::ObjectSerializerBasePtr& serializer,
114 const ::Ice::Current& = Ice::emptyCurrent) const override;
115 void deserialize(const armarx::ObjectSerializerBasePtr& serializer,
116 const ::Ice::Current& = Ice::emptyCurrent) override;
117 };
118
120
121 /**
122 * @class MatrixDouble
123 * @ingroup VariantsGrp
124 * @brief The MatrixDouble class
125 */
126 class MatrixDouble : virtual public MatrixDoubleBase
127 {
128 template <class BaseClass, class VariantClass>
129 friend class GenericFactory;
130
131 protected:
132 MatrixDouble();
133
134 public:
135 MatrixDouble(int rows, int cols);
136 MatrixDouble(const Eigen::MatrixXd&);
137 MatrixDouble(int rows, int cols, const std::vector<double>& entries);
138
139 //void setMatrix(int width, int height, const std::vector<double> &entries);
140
141 virtual Eigen::MatrixXd toEigen() const;
142
143 // inherited from VariantDataClass
144 Ice::ObjectPtr
145 ice_clone() const override
146 {
147 return this->clone();
148 }
149
150 VariantDataClassPtr
151 clone(const Ice::Current& c = Ice::emptyCurrent) const override
152 {
153 return new MatrixDouble(*this);
154 }
155
156 std::string
157 output(const Ice::Current& c = Ice::emptyCurrent) const override
158 {
159 std::stringstream s;
160 s << toEigen();
161 return s.str();
162 }
163
165 getType(const Ice::Current& c = Ice::emptyCurrent) const override
166 {
168 }
169
170 bool
171 validate(const Ice::Current& c = Ice::emptyCurrent) override
172 {
173 return true;
174 }
175
176 double& operator()(const int x, const int y);
177
178 std::string toJsonRowMajor();
179
180 friend std::ostream&
181 operator<<(std::ostream& stream, const MatrixDouble& rhs)
182 {
183 stream << "MatrixDouble: " << std::endl << rhs.output() << std::endl;
184 return stream;
185 }
186
187 public:
188 // serialization
189 void serialize(const armarx::ObjectSerializerBasePtr& serializer,
190 const ::Ice::Current& = Ice::emptyCurrent) const override;
191 void deserialize(const armarx::ObjectSerializerBasePtr& serializer,
192 const ::Ice::Current& = Ice::emptyCurrent) override;
193 };
194
196} // namespace armarx
constexpr T c
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
friend class GenericFactory
friend std::ostream & operator<<(std::ostream &stream, const MatrixDouble &rhs)
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
double & operator()(const int x, const int y)
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Ice::ObjectPtr ice_clone() const override
std::string toJsonRowMajor()
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
virtual Eigen::MatrixXd toEigen() const
friend std::ostream & operator<<(std::ostream &stream, const MatrixFloat &rhs)
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
friend class GenericFactory
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
std::vector< float > toVector() const
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Ice::ObjectPtr ice_clone() const override
std::string toJsonRowMajor()
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
virtual Eigen::MatrixXf toEigen() const
float & operator()(const int x, const int y)
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
Definition Variant.cpp:869
const VariantTypeId MatrixFloat
const VariantTypeId MatrixDouble
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< MatrixFloat > MatrixFloatPtr
Ice::Int VariantTypeId
Definition Variant.h:43
IceInternal::Handle< MatrixDouble > MatrixDoublePtr