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/SoPointSet.h>
10 #include <Inventor/nodes/SoMaterial.h>
11 
12 namespace 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 
53  {
54  // set position
55  coordinate3->point.setValuesPointer(element.points.size(),
56  reinterpret_cast<const float*>(element.points.data()));
57 
58  // set color
59  const auto lineColor = element.color;
60 
61  constexpr float toUnit = 1.0F / 255.0F;
62 
63  const auto color = SbVec3f(lineColor.r, lineColor.g, lineColor.b) * toUnit;
64  const float transparency = 1.0F - static_cast<float>(lineColor.a) * toUnit;
65 
66  lineMaterial->diffuseColor.setValue(color);
67  lineMaterial->ambientColor.setValue(color);
68  lineMaterial->transparency.setValue(transparency);
69 
70  if (element.lineWidth > 0.0F)
71  {
72  lineStyle->lineWidth.setValue(element.lineWidth);
73  }
74  else
75  {
76  lineStyle->style = SoDrawStyleElement::INVISIBLE;
77  }
78 
79  const int pointSize = static_cast<int>(element.points.size());
80  lineSet->numVertices.set1Value(0, pointSize);
81 
82  // points at each node
83  // const std::vector<SbVec3f> colorData(element.points.size(), color);
84 
85  // pclMat->diffuseColor.setValuesPointer(colorData.size(),
86  // reinterpret_cast<const float*>(colorData.data()));
87  // pclMat->ambientColor.setValuesPointer(colorData.size(),
88  // reinterpret_cast<const float*>(colorData.data()));
89  // pclMat->transparency = transparency;
90 
91  pclCoords->point.setValuesPointer(element.points.size(),
92  reinterpret_cast<const float*>(element.points.data()));
93 
94  pclStyle->pointSize = element.lineWidth + 5;
95 
96  return true;
97  }
98 } // namespace armarx::viz::coin
VisualizationPath.h
armarx::viz::coin::VisualizationPath::update
bool update(ElementType const &element)
Definition: VisualizationPath.cpp:52
armarx::viz::coin::VisualizationPath::lineSet
SoLineSet * lineSet
Definition: VisualizationPath.h:45
armarx::viz::coin::VisualizationPath::ElementType
data::ElementPath ElementType
Definition: VisualizationPath.h:36
armarx::viz::coin::VisualizationPath::lineMaterial
SoMaterial * lineMaterial
Definition: VisualizationPath.h:46
armarx::viz::coin::TypedElementVisualization< SoSeparator >::node
NodeType * node
Definition: ElementVisualizer.h:68
armarx::viz::coin::VisualizationPath::VisualizationPath
VisualizationPath()
Definition: VisualizationPath.cpp:15
armarx::viz::coin::VisualizationPath::pclCoords
SoCoordinate3 * pclCoords
points
Definition: VisualizationPath.h:51
armarx::viz::coin
Definition: ElementVisualizer.cpp:11
armarx::viz::coin::VisualizationPath::coordinate3
SoCoordinate3 * coordinate3
lines
Definition: VisualizationPath.h:43
armarx::viz::coin::VisualizationPath::pclStyle
SoDrawStyle * pclStyle
Definition: VisualizationPath.h:52
armarx::viz::coin::VisualizationPath::lineStyle
SoDrawStyle * lineStyle
Definition: VisualizationPath.h:44