VisualizationPath.cpp
Go to the documentation of this file.
1#include "VisualizationPath.h"
2
3#include <algorithm>
4
5#include <Inventor/SbVec3f.h>
6#include <Inventor/nodes/SoCoordinate3.h>
7#include <Inventor/nodes/SoDrawStyle.h>
8#include <Inventor/nodes/SoLineSet.h>
9#include <Inventor/nodes/SoMaterial.h>
10#include <Inventor/nodes/SoPointSet.h>
11
12namespace armarx::viz::coin
13{
14
16 {
17 coordinate3 = new SoCoordinate3;
18
19 // create line around polygon
20 SoSeparator* lineSep = new SoSeparator;
21
22 lineMaterial = new SoMaterial;
23 lineSep->addChild(lineMaterial);
24 lineSep->addChild(coordinate3);
25
26 lineStyle = new SoDrawStyle();
27 lineSep->addChild(lineStyle);
28
29 lineSet = new SoLineSet;
30 lineSep->addChild(lineSet);
31
32 node->addChild(coordinate3);
33 node->addChild(lineSep);
34
35 // points (use the following, if the points should be drawn in a different color)
36
37 // pclMat = new SoMaterial;
38
39 // SoMaterialBinding* pclMatBind = new SoMaterialBinding;
40 // pclMatBind->value = SoMaterialBinding::PER_PART;
41
42 pclCoords = new SoCoordinate3;
43 pclStyle = new SoDrawStyle;
44
45 // node->addChild(pclMat);
46 // node->addChild(pclMatBind);
47 node->addChild(pclCoords);
48 node->addChild(pclStyle);
49 node->addChild(new SoPointSet);
50 }
51
52 bool
54 {
55 // set position
56 coordinate3->point.setValuesPointer(element.points.size(),
57 reinterpret_cast<const float*>(element.points.data()));
58
59 // set color
60 const auto lineColor = element.color;
61
62 constexpr float toUnit = 1.0F / 255.0F;
63
64 const auto color = SbVec3f(lineColor.r, lineColor.g, lineColor.b) * toUnit;
65 const float transparency = 1.0F - static_cast<float>(lineColor.a) * toUnit;
66
67 lineMaterial->diffuseColor.setValue(color);
68 lineMaterial->ambientColor.setValue(color);
69 lineMaterial->transparency.setValue(transparency);
70
71 if (element.lineWidth > 0.0F)
72 {
73 lineStyle->lineWidth.setValue(element.lineWidth);
74 }
75 else
76 {
77 lineStyle->style = SoDrawStyleElement::INVISIBLE;
78 }
79
80 const int pointSize = static_cast<int>(element.points.size());
81 lineSet->numVertices.set1Value(0, pointSize);
82
83 // points at each node
84 // const std::vector<SbVec3f> colorData(element.points.size(), color);
85
86 // pclMat->diffuseColor.setValuesPointer(colorData.size(),
87 // reinterpret_cast<const float*>(colorData.data()));
88 // pclMat->ambientColor.setValuesPointer(colorData.size(),
89 // reinterpret_cast<const float*>(colorData.data()));
90 // pclMat->transparency = transparency;
91
92 pclCoords->point.setValuesPointer(element.points.size(),
93 reinterpret_cast<const float*>(element.points.data()));
94
95 pclStyle->pointSize = element.lineWidth + 5;
96
97 return true;
98 }
99} // namespace armarx::viz::coin
bool update(ElementType const &element)