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 
28 #include <ArmarXCore/interface/observers/Matrix.h>
29 
30 #include <Eigen/Core>
31 //#include <Eigen/Geometry>
32 
33 namespace armarx::VariantType
34 {
35  // Variant types
36  const VariantTypeId MatrixFloat = Variant::addTypeName("::armarx::MatrixFloatBase");
37  const VariantTypeId MatrixDouble = Variant::addTypeName("::armarx::MatrixDoubleBase");
38 }
39 
40 
41 namespace 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  protected:
53  MatrixFloat();
54  public:
55  MatrixFloat(int rows, int cols);
56  MatrixFloat(const Eigen::MatrixXf&);
57  MatrixFloat(int rows, int cols, const std::vector<float>& entries);
58 
59  //void setMatrix(int width, int height, const std::vector<float> &entries);
60 
61  virtual Eigen::MatrixXf toEigen() const;
62 
63  std::vector<float> toVector() const;
64 
65  // inherited from VariantDataClass
66  Ice::ObjectPtr ice_clone() const override
67  {
68  return this->clone();
69  }
70  VariantDataClassPtr clone(const Ice::Current& c = Ice::emptyCurrent) const override
71  {
72  return new MatrixFloat(*this);
73  }
74  std::string output(const Ice::Current& c = Ice::emptyCurrent) const override
75  {
76  std::stringstream s;
77  s << toEigen();
78  return s.str();
79  }
80  VariantTypeId getType(const Ice::Current& c = Ice::emptyCurrent) const override
81  {
83  }
84  bool validate(const Ice::Current& c = Ice::emptyCurrent) override
85  {
86  return true;
87  }
88 
89  float& operator()(const int x, const int y);
90 
91  std::string toJsonRowMajor();
92 
93  friend std::ostream& operator<<(std::ostream& stream, const MatrixFloat& rhs)
94  {
95  stream << "MatrixFloat: " << std::endl << rhs.output() << std::endl;
96  return stream;
97  }
98 
99  public:
100  // serialization
101  void serialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) const override;
102  void deserialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) override;
103  };
104 
106 
107 
108 
109  /**
110  * @class MatrixDouble
111  * @ingroup VariantsGrp
112  * @brief The MatrixDouble class
113  */
114  class MatrixDouble : virtual public MatrixDoubleBase
115  {
116  template <class BaseClass, class VariantClass>
117  friend class GenericFactory;
118  protected:
119  MatrixDouble();
120  public:
121  MatrixDouble(int rows, int cols);
122  MatrixDouble(const Eigen::MatrixXd&);
123  MatrixDouble(int rows, int cols, const std::vector<double>& entries);
124 
125  //void setMatrix(int width, int height, const std::vector<double> &entries);
126 
127  virtual Eigen::MatrixXd toEigen() const;
128 
129  // inherited from VariantDataClass
130  Ice::ObjectPtr ice_clone() const override
131  {
132  return this->clone();
133  }
134  VariantDataClassPtr clone(const Ice::Current& c = Ice::emptyCurrent) const override
135  {
136  return new MatrixDouble(*this);
137  }
138  std::string output(const Ice::Current& c = Ice::emptyCurrent) const override
139  {
140  std::stringstream s;
141  s << toEigen();
142  return s.str();
143  }
144  VariantTypeId getType(const Ice::Current& c = Ice::emptyCurrent) const override
145  {
147  }
148  bool validate(const Ice::Current& c = Ice::emptyCurrent) override
149  {
150  return true;
151  }
152 
153  double& operator()(const int x, const int y);
154 
155  std::string toJsonRowMajor();
156 
157 
158  friend std::ostream& operator<<(std::ostream& stream, const MatrixDouble& rhs)
159  {
160  stream << "MatrixDouble: " << std::endl << rhs.output() << std::endl;
161  return stream;
162  }
163 
164  public:
165  // serialization
166  void serialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) const override;
167  void deserialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) override;
168  };
169 
171 }
armarx::MatrixDouble::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: MatrixVariant.cpp:282
armarx::MatrixDouble
The MatrixDouble class.
Definition: MatrixVariant.h:114
armarx::MatrixDouble::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:144
armarx::MatrixFloat::operator()
float & operator()(const int x, const int y)
Definition: MatrixVariant.cpp:104
armarx::MatrixFloat::toVector
std::vector< float > toVector() const
Definition: MatrixVariant.cpp:99
armarx::MatrixDouble::MatrixDouble
MatrixDouble()
Definition: MatrixVariant.cpp:192
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::MatrixFloat::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:74
armarx::MatrixDouble::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:138
armarx::MatrixFloat::toEigen
virtual Eigen::MatrixXf toEigen() const
Definition: MatrixVariant.cpp:82
armarx::MatrixDouble::toEigen
virtual Eigen::MatrixXd toEigen() const
Definition: MatrixVariant.cpp:237
armarx::MatrixDouble::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:134
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MatrixFloat::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: MatrixVariant.cpp:132
armarx::MatrixFloat
The MatrixFloat class.
Definition: MatrixVariant.h:48
armarx::MatrixDouble::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: MatrixVariant.h:130
armarx::MatrixDouble::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: MatrixVariant.cpp:305
armarx::VariantType
Definition: ChannelRef.h:160
armarx::MatrixFloat::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:80
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::MatrixFloat::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MatrixVariant.h:70
armarx::MatrixFloat::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: MatrixVariant.h:66
armarx::MatrixDouble::operator<<
friend std::ostream & operator<<(std::ostream &stream, const MatrixDouble &rhs)
Definition: MatrixVariant.h:158
armarx::VariantType::MatrixFloat
const VariantTypeId MatrixFloat
Definition: MatrixVariant.h:36
armarx::MatrixDouble::operator()
double & operator()(const int x, const int y)
Definition: MatrixVariant.cpp:254
armarx::GenericFactory
Definition: FactoryCollectionBase.h:51
armarx::MatrixFloat::MatrixFloat
MatrixFloat()
Definition: MatrixVariant.cpp:37
armarx::MatrixFloat::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: MatrixVariant.h:84
armarx::MatrixDouble::toJsonRowMajor
std::string toJsonRowMajor()
Definition: MatrixVariant.cpp:259
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::MatrixFloat::toJsonRowMajor
std::string toJsonRowMajor()
Definition: MatrixVariant.cpp:109
armarx::MatrixFloat::operator<<
friend std::ostream & operator<<(std::ostream &stream, const MatrixFloat &rhs)
Definition: MatrixVariant.h:93
Variant.h
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Variant::addTypeName
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
Definition: Variant.cpp:751
armarx::MatrixFloat::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: MatrixVariant.cpp:155
armarx::VariantType::MatrixDouble
const VariantTypeId MatrixDouble
Definition: MatrixVariant.h:37
armarx::MatrixDouble::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: MatrixVariant.h:148