QuaternionWidget.h
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 
4 #include <QLineEdit>
5 #include <QObject>
6 #include <QVBoxLayout>
7 
9 
10 #include "CustomWidget.h"
11 
12 
13 namespace armarx
14 {
15  // Custom Widget which represents a Quaternion - This class does not normalize the inputs
16  // It can parse its data to NDArray and also handles user edit signals itself. (And also the highlighting if errors occur)
18  {
19  Q_OBJECT
20  public:
21  QuaternionWidget(aron::type::quaternion::ElementType type, QTreeWidgetItem* currentItem);
22 
23  static QuaternionWidget* DynamicCast(QWidget*);
24  static QuaternionWidget* DynamicCastAndCheck(QWidget*);
25 
27  {
28  X = 0,
29  Y,
30  Z,
31  W
32  };
33  void setText(QuaternionComponents col, const std::string& str);
34  std::string getText(QuaternionComponents col);
35  bool hasParseErrors();
36  std::vector<unsigned char> parseAllToNDArray();
37 
38  private:
39  std::vector<QLineEdit*> xyzw_components;
41  bool parseErrors = false;
42 
43  void highlightUnparsableEntries();
44  template <typename T>
45  std::pair<bool, T> parseQuatVals(QuaternionComponents comp);
46 
47  private slots:
48  void quaternionElementChanged();
49  };
50 
51  template <typename T>
52  std::pair<bool, T>
53  QuaternionWidget::parseQuatVals(QuaternionWidget::QuaternionComponents comp)
54  {
55  // size_t data_size = element_type == aron::type::quaternion::ElementType::FLOAT32 ? 4 : 8;
56  try
57  {
58  T val = simox::alg::to_<T>(xyzw_components.at((size_t)comp)->text().toStdString());
59  return {true, val};
60  }
61  catch (const simox::error::SimoxError& err)
62  {
63  return {false, NAN};
64  }
65  }
66 
67 
68 } // namespace armarx
armarx::QuaternionWidget
Definition: QuaternionWidget.h:17
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
Matrix.h
armarx::QuaternionWidget::hasParseErrors
bool hasParseErrors()
Definition: QuaternionWidget.cpp:39
armarx::QuaternionWidget::DynamicCast
static QuaternionWidget * DynamicCast(QWidget *)
Definition: QuaternionWidget.cpp:13
CustomWidget.h
armarx::QuaternionWidget::QuaternionComponents::W
@ W
armarx::QuaternionWidget::QuaternionComponents::Y
@ Y
armarx::QuaternionWidget::setText
void setText(QuaternionComponents col, const std::string &str)
Definition: QuaternionWidget.cpp:31
armarx::QuaternionWidget::getText
std::string getText(QuaternionComponents col)
armarx::QuaternionWidget::QuaternionComponents
QuaternionComponents
Definition: QuaternionWidget.h:26
armarx::QuaternionWidget::QuaternionComponents::X
@ X
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::QuaternionWidget::DynamicCastAndCheck
static QuaternionWidget * DynamicCastAndCheck(QWidget *)
Definition: QuaternionWidget.cpp:19
armarx::QuaternionWidget::parseAllToNDArray
std::vector< unsigned char > parseAllToNDArray()
Definition: QuaternionWidget.cpp:123
armarx::CustomWidget
Definition: CustomWidget.h:9
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::QuaternionWidget::QuaternionWidget
QuaternionWidget(aron::type::quaternion::ElementType type, QTreeWidgetItem *currentItem)
Definition: QuaternionWidget.cpp:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::QuaternionWidget::QuaternionComponents::Z
@ Z