DataDisplayVisitor.cpp
Go to the documentation of this file.
1 #include "DataDisplayVisitor.h"
2 
4 
5 namespace 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
armarx::aron::DataDisplayVisitor::visitBool
void visitBool(const data::VariantPtr &b) override
Definition: DataDisplayVisitor.cpp:31
armarx::aron::data::NDArray
Definition: NDArray.h:48
armarx::aron::data::NDArray::getType
std::string getType() const
Definition: NDArray.cpp:163
armarx::aron::StringStreamMixin::setStreamPrecision
void setStreamPrecision()
Definition: StringStreamMixin.cpp:13
armarx::aron::data::NDArray::getShape
std::vector< int > getShape() const
Definition: NDArray.cpp:145
armarx::aron::data::NDArray::DimensionsToString
static std::string DimensionsToString(const std::vector< int > &dimensions)
Return dimensions in a readable string such as "(2, 3, 4)".
Definition: NDArray.cpp:254
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::aron::DataDisplayVisitor::visitList
void visitList(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:24
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::DataDisplayVisitor::visitFloat
void visitFloat(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:52
armarx::aron::DataDisplayVisitor::visitDict
void visitDict(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:17
armarx::aron::DataDisplayVisitor::visitNDArray
void visitNDArray(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:80
armarx::aron
Definition: DataDisplayVisitor.cpp:5
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::StringStreamMixin::value
std::stringstream value
Definition: StringStreamMixin.h:20
All.h
armarx::aron::DataDisplayVisitor
Definition: DataDisplayVisitor.h:12
armarx::aron::DataDisplayVisitor::visitLong
void visitLong(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:66
armarx::aron::StringStreamMixin::eigenIof
const Eigen::IOFormat eigenIof
Definition: StringStreamMixin.h:24
armarx::aron::DataDisplayVisitor::getValue
static std::string getValue(const data::VariantPtr &n)
Definition: DataDisplayVisitor.cpp:9
armarx::aron::DataDisplayVisitor::visitString
void visitString(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:73
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::DataDisplayVisitor::visitInt
void visitInt(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:59
armarx::aron::DataDisplayVisitor::visitDouble
void visitDouble(const data::VariantPtr &n) override
Definition: DataDisplayVisitor.cpp:45
armarx::aron::data::visit
requires isVisitor< VisitorImplementation, typename VisitorImplementation::Input > void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition: Visitor.h:124
DataDisplayVisitor.h