DataDisplayVisitor.cpp
Go to the documentation of this file.
2
4
5namespace armarx::aron
6{
7
8 std::string
10 {
12 data::visit(v, n);
13 return v.value.str();
14 }
15
16 void
18 {
20 value << x->childrenSize() << " items";
21 }
22
23 void
25 {
27 value << x->childrenSize() << " items";
28 }
29
30 void
32 {
34 if (x->getValue())
35 {
36 value << "true";
37 }
38 else
39 {
40 value << "false";
41 }
42 }
43
44 void
46 {
48 value << x->getValue();
49 }
50
51 void
53 {
55 value << x->getValue();
56 }
57
58 void
60 {
62 value << x->getValue();
63 }
64
65 void
67 {
69 value << x->getValue();
70 }
71
72 void
74 {
76 value << "'" << x->getValue() << "'";
77 }
78
79 void
81 {
83
84 if (d->getType() == "float")
85 {
87 processMatrix<float>(*d);
88 }
89 else if (d->getType() == "double")
90 {
92 processMatrix<double>(*d);
93 }
94 else
95 {
96 printShape(*d);
97 }
98 }
99
100 void
101 DataDisplayVisitor::printShape(const data::NDArray& d)
102 {
103 value << "shape " << aron::data::NDArray::DimensionsToString(d.getShape()) << ", type '"
104 << d.getType() << "'";
105 }
106
107 template <typename ScalarT>
108 void
109 DataDisplayVisitor::processMatrix(const data::NDArray& data)
110 {
111 const int rows = data.getShape().at(0);
112 const int cols = data.getShape().at(1);
113
114 const Eigen::Map<Eigen::Matrix<ScalarT, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> m(
115 reinterpret_cast<ScalarT*>(data.getData()), rows, cols);
116
117 const int maxRows = 10;
118 const int maxCols = 10;
119
120 if (cols > maxCols)
121 {
122 printShape(data);
123 }
124 else if (rows > maxRows)
125 {
126 int shownRows = 2;
127
128 value << "(";
129 printShape(data);
130 value << ")\n"
131 << m.block(0, 0, shownRows, cols) << "\n...\n"
132 << m.block(rows - shownRows, 0, shownRows, cols);
133 }
134 else
135 {
136 value << m.format(eigenIof);
137 }
138 }
139
140
141} // namespace armarx::aron
uint8_t data[1]
void visitDict(const data::VariantPtr &n) override
void visitFloat(const data::VariantPtr &n) override
void visitString(const data::VariantPtr &n) override
void visitInt(const data::VariantPtr &n) override
void visitBool(const data::VariantPtr &b) override
static std::string getValue(const data::VariantPtr &n)
void visitDouble(const data::VariantPtr &n) override
void visitNDArray(const data::VariantPtr &n) override
void visitLong(const data::VariantPtr &n) override
void visitList(const data::VariantPtr &n) override
static std::string DimensionsToString(const std::vector< int > &dimensions)
Return dimensions in a readable string such as "(2, 3, 4)".
Definition NDArray.cpp:257
std::string getType() const
Definition NDArray.cpp:165
std::vector< int > getShape() const
Definition NDArray.cpp:147
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< Variant > VariantPtr
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition Visitor.h:136
This file offers overloads of toIce() and fromIce() functions for STL container types.