VisualizationPose.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ElementVisualizer.h"
4 
5 #include <RobotAPI/interface/ArViz/Elements.h>
6 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
7 #include <Inventor/nodes/SoAsciiText.h>
8 #include <Inventor/nodes/SoCube.h>
9 #include <Inventor/nodes/SoSeparator.h>
10 #include <Inventor/nodes/SoTransform.h>
11 #include <Inventor/nodes/SoTranslation.h>
12 
13 namespace armarx::viz::coin
14 {
16  {
17  using ElementType = data::ElementPose;
18 
19  static const int NumberOfBlocks = 3;
20 
22  {
23  for (int i = 0; i < 3; i++)
24  {
25  SoTransform* t = new SoTransform();
26  SoMaterial* m = new SoMaterial();
27  t_[i] = t;
28  m_[i] = m;
29 
30  SoCube* c = new SoCube();
31  SoCube* c2 = new SoCube();
32  SoTransform* t2 = new SoTransform();
33  c_[i] = c;
34  c2_[i] = c2;
35  t2_[i] = t2;
36 
37  SoSeparator* tmp1 = new SoSeparator();
38  tmp1->addChild(m);
39  tmp1->addChild(t);
40  tmp1->addChild(c);
41  node->addChild(tmp1);
42 
43  SoSeparator* tmp2 = new SoSeparator();
44  SoMaterial* m2 = new SoMaterial();
45  m2->diffuseColor.setValue(1.0f, 1.0f, 1.0f);
46  tmp2->addChild(m2);
47 
48  for (int j = 0; j < NumberOfBlocks; j++)
49  {
50  tmp2->addChild(t2);
51  tmp2->addChild(c2);
52  }
53 
54  node->addChild(tmp2);
55  }
56 
57  SoSeparator* textSep = new SoSeparator();
58  SoTranslation* moveT = new SoTranslation();
59  moveT->translation.setValue(2.0f, 2.0f, 0.0f);
60  textSep->addChild(moveT);
61  textNode = new SoAsciiText();
62  textSep->addChild(textNode);
63 
64  node->addChild(textSep);
65  }
66 
67  bool update(ElementType const& element)
68  {
69  const float axisSize = 3.0f;
70  const float axisLength = 100.0f;
71  const int numberOfBlocks = NumberOfBlocks;
72 
73  float scaling = 1.0f;
74 
75  float blockSize = axisSize + 0.5f;
76  float blockWidth = 0.1f;
77 
78  if (axisSize > 10.0f)
79  {
80  blockSize += axisSize / 10.0f;
81  blockWidth += axisSize / 10.0f;
82  }
83 
84  float axisBlockTranslation = axisLength / numberOfBlocks;
85 
86  for (int i = 0; i < 3; i++)
87  {
88  SoTransform* t = t_[i];
89  SoMaterial* m = m_[i];
90 
91  float translation = (axisLength / 2.0f + axisSize / 2.0f) * scaling;
92  if (i == 0)
93  {
94  m->diffuseColor.setValue(1.0f, 0, 0);
95  t->translation.setValue(translation, 0, 0);
96  }
97  else if (i == 1)
98  {
99  m->diffuseColor.setValue(0, 1.0f, 0);
100  t->translation.setValue(0, translation, 0);
101  }
102  else
103  {
104  m->diffuseColor.setValue(0, 0, 1.0f);
105  t->translation.setValue(0, 0, translation);
106  }
107 
108  SoCube* c = c_[i];
109  SoCube* c2 = c2_[i];
110  SoTransform* t2 = t2_[i];
111 
112  if (i == 0)
113  {
114  c->width = axisLength * scaling;
115  c->height = axisSize * scaling;
116  c->depth = axisSize * scaling;
117  c2->width = blockWidth * scaling;
118  c2->height = blockSize * scaling;
119  c2->depth = blockSize * scaling;
120  t2->translation.setValue(axisBlockTranslation * scaling, 0, 0);
121  }
122  else if (i == 1)
123  {
124  c->height = axisLength * scaling;
125  c->width = axisSize * scaling;
126  c->depth = axisSize * scaling;
127  c2->width = blockSize * scaling;
128  c2->height = blockWidth * scaling;
129  c2->depth = blockSize * scaling;
130  t2->translation.setValue(0, axisBlockTranslation * scaling, 0);
131  }
132  else
133  {
134  c->depth = axisLength * scaling;
135  c->height = axisSize * scaling;
136  c->width = axisSize * scaling;
137  c2->width = blockSize * scaling;
138  c2->height = blockSize * scaling;
139  c2->depth = blockWidth * scaling;
140  t2->translation.setValue(0, 0, axisBlockTranslation * scaling);
141  }
142  }
143 
144  textNode->string.setValue(element.id.c_str());
145 
146  return true;
147  }
148 
149  SoAsciiText* textNode;
150  std::array<SoTransform*, 3> t_;
151  std::array<SoMaterial*, 3> m_;
152  std::array<SoCube*, 3> c_;
153  std::array<SoCube*, 3> c2_;
154  std::array<SoTransform*, 3> t2_;
155  };
156 }
ElementVisualizer.h
armarx::viz::coin::TypedElementVisualization
Definition: ElementVisualizer.h:53
armarx::viz::coin::VisualizationPose::update
bool update(ElementType const &element)
Definition: VisualizationPose.h:67
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::viz::coin::VisualizationPose::c_
std::array< SoCube *, 3 > c_
Definition: VisualizationPose.h:152
armarx::viz::coin::VisualizationPose::c2_
std::array< SoCube *, 3 > c2_
Definition: VisualizationPose.h:153
armarx::viz::coin::TypedElementVisualization< SoSeparator >::node
NodeType * node
Definition: ElementVisualizer.h:68
armarx::viz::coin::VisualizationPose
Definition: VisualizationPose.h:15
armarx::viz::coin::VisualizationPose::m_
std::array< SoMaterial *, 3 > m_
Definition: VisualizationPose.h:151
armarx::viz::coin::VisualizationPose::t_
std::array< SoTransform *, 3 > t_
Definition: VisualizationPose.h:150
armarx::viz::coin::VisualizationPose::NumberOfBlocks
static const int NumberOfBlocks
Definition: VisualizationPose.h:19
armarx::viz::coin
Definition: ElementVisualizer.cpp:11
armarx::viz::coin::VisualizationPose::VisualizationPose
VisualizationPose()
Definition: VisualizationPose.h:21
armarx::viz::coin::VisualizationPose::ElementType
data::ElementPose ElementType
Definition: VisualizationPose.h:17
armarx::viz::coin::VisualizationPose::t2_
std::array< SoTransform *, 3 > t2_
Definition: VisualizationPose.h:154
armarx::viz::coin::VisualizationPose::textNode
SoAsciiText * textNode
Definition: VisualizationPose.h:149