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>
61 } // namespace detail
62
63 template <typename T, size_t D>
67
68 template <>
71 {
72 public:
73 using T = float;
74
75 void
77 {
79
80 auto shape = ndarray->getShape();
81 memberInfo[ndarray->getPath().toString()] = currentIndex;
82
83 VectorType vec;
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
107 {
109 memberInfo[a->getPath().toString()] = currentIndex;
110
111 data.push_back(T(a->getValue()));
112 }
113
114 void
116 {
118 memberInfo[a->getPath().toString()] = currentIndex;
119
120 data.push_back(T(a->getValue()));
121 }
122
123 void
125 {
127 memberInfo[a->getPath().toString()] = currentIndex;
128
129 data.push_back(T(a->getValue()));
130 }
131
132 void
134 {
136 memberInfo[a->getPath().toString()] = currentIndex;
137
138 data.push_back(T(a->getValue()));
139 }
140 };
141
142 template <>
145 {
146 public:
147 using T = char;
148
149 public:
150 void
152 {
154
155 auto shape = ndarray->getShape();
156 memberInfo[ndarray->getPath().toString()] = currentIndex;
157
158 VectorType vec;
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
#define float
Definition 16_Level.h:22
static std::vector< T > ConvertTo1DVector(const data::NDArray &nav)
static std::vector< std::vector< T > > ConvertTo2DVector(const data::NDArray &nav, int dim0size=-1)
armarx::aron::data::RecursiveConstVariantVisitor::Input Input
typename detail::multidimensional_vector< T, D >::type VectorType
typename VisitorBase< const data::VariantPtr >::Input Input
std::vector< typename multidimensional_vector< T, D - 1 >::type > type