StdVectorConverterVisitor.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 // ArmarX
27 
28 #include "StdVectorConverter.h"
29 
31 {
32  namespace detail
33  {
34  template <typename T, size_t D>
36  {
37  static_assert(D > 0, "matrix dimensions must be positive");
38  typedef std::vector<typename multidimensional_vector<T, D - 1>::type> type;
39  };
40 
41  template <typename T>
43  {
44  typedef std::vector<T> type;
45  };
46 
47  template <typename T, size_t D>
50  {
51  public:
54 
56  std::map<std::string, int> memberInfo;
57 
58  protected:
59  int currentIndex = 0;
60  };
61  } // namespace detail
62 
63  template <typename T, size_t D>
65  {
66  };
67 
68  template <>
71  {
72  public:
73  using T = float;
74 
75  void
76  visitNDArray(Input& aron) override
77  {
79 
80  auto shape = ndarray->getShape();
81  memberInfo[ndarray->getPath().toString()] = currentIndex;
82 
83  VectorType vec;
84  vec = AronVectorConverter::ConvertTo1DVector<T>(ndarray);
85  shape = {shape.empty() ? 0
86  : std::accumulate(std::begin(shape),
87  std::prev(std::end(shape)),
88  1,
89  std::multiplies<int>())};
90  shape.push_back(sizeof(T));
91 
92  data.insert(data.end(), vec.begin(), vec.end());
93  currentIndex += shape.at(0);
94  }
95 
96  void
97  visitInt(Input& aron) override
98  {
100  memberInfo[a->getPath().toString()] = currentIndex;
101 
102  data.push_back(T(a->getValue()));
103  }
104 
105  void
106  visitLong(Input& aron) override
107  {
109  memberInfo[a->getPath().toString()] = currentIndex;
110 
111  data.push_back(T(a->getValue()));
112  }
113 
114  void
115  visitFloat(Input& aron) override
116  {
118  memberInfo[a->getPath().toString()] = currentIndex;
119 
120  data.push_back(T(a->getValue()));
121  }
122 
123  void
124  visitDouble(Input& aron) override
125  {
127  memberInfo[a->getPath().toString()] = currentIndex;
128 
129  data.push_back(T(a->getValue()));
130  }
131 
132  void
133  visitBool(Input& aron) override
134  {
136  memberInfo[a->getPath().toString()] = currentIndex;
137 
138  data.push_back(T(a->getValue()));
139  }
140  };
141 
142  template <>
143  class AronVectorConverterVisitor<char, 2> :
145  {
146  public:
147  using T = char;
148 
149  public:
150  void
151  visitNDArray(Input& aron) override
152  {
154 
155  auto shape = ndarray->getShape();
156  memberInfo[ndarray->getPath().toString()] = currentIndex;
157 
158  VectorType vec;
159  vec = AronVectorConverter::ConvertTo2DVector<T>(ndarray);
160  shape.push_back(1);
161 
162  data.insert(data.end(), vec.begin(), vec.end());
163  currentIndex += shape.at(0);
164  }
165  };
166 
167 } // namespace armarx::aron::data::converter
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitInt
void visitInt(Input &aron) override
Definition: StdVectorConverterVisitor.h:97
detail
Definition: OpenCVUtil.cpp:127
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase
Definition: StdVectorConverterVisitor.h:48
armarx::aron::data::RecursiveVisitor< const data::VariantPtr >::Input
typename VisitorBase< const data::VariantPtr >::Input Input
Definition: RecursiveVisitor.h:39
armarx::aron::data::converter::AronVectorConverterVisitor< char, 2 >::visitNDArray
void visitNDArray(Input &aron) override
Definition: StdVectorConverterVisitor.h:151
StdVectorConverter.h
armarx::aron::data::converter::detail::multidimensional_vector< float, D >::type
std::vector< typename multidimensional_vector< float, D - 1 >::type > type
Definition: StdVectorConverterVisitor.h:37
armarx::aron::data::detail::SpecializedVariantBase< data::dto::NDArray, NDArray >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitBool
void visitBool(Input &aron) override
Definition: StdVectorConverterVisitor.h:133
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitNDArray
void visitNDArray(Input &aron) override
Definition: StdVectorConverterVisitor.h:76
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::T
float T
Definition: StdVectorConverterVisitor.h:73
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase::data
VectorType data
Definition: StdVectorConverterVisitor.h:55
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase< char, 2 >::VectorType
typename detail::multidimensional_vector< char, D >::type VectorType
Definition: StdVectorConverterVisitor.h:52
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase::memberInfo
std::map< std::string, int > memberInfo
Definition: StdVectorConverterVisitor.h:56
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::aron::data::converter::AronVectorConverterVisitor
Definition: StdVectorConverterVisitor.h:64
armarx::aron::data::converter::AronVectorConverterVisitor< char, 2 >::T
char T
Definition: StdVectorConverterVisitor.h:147
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitDouble
void visitDouble(Input &aron) override
Definition: StdVectorConverterVisitor.h:124
All.h
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase< char, 2 >::Input
armarx::aron::data::RecursiveConstVariantVisitor::Input Input
Definition: StdVectorConverterVisitor.h:53
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitFloat
void visitFloat(Input &aron) override
Definition: StdVectorConverterVisitor.h:115
armarx::aron::data::converter::detail::AronVectorConverterVisitorBase::currentIndex
int currentIndex
Definition: StdVectorConverterVisitor.h:59
float
#define float
Definition: 16_Level.h:22
VariantVisitor.h
armarx::aron::data::RecursiveConstVariantVisitor
Definition: VariantVisitor.h:120
armarx::aron::data::converter::detail::multidimensional_vector< T, 1 >::type
std::vector< T > type
Definition: StdVectorConverterVisitor.h:44
armarx::aron::data::converter::detail::multidimensional_vector
Definition: StdVectorConverterVisitor.h:35
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::aron::data::converter::AronVectorConverterVisitor< float, 1 >::visitLong
void visitLong(Input &aron) override
Definition: StdVectorConverterVisitor.h:106
armarx::aron::data::converter
Definition: aron_conversions.cpp:3