ElementVisualizer.cpp
Go to the documentation of this file.
1 #include "ElementVisualizer.h"
2 
4 
5 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
6 
7 #include <Inventor/nodes/SoUnits.h>
8 #include <Inventor/nodes/SoTransform.h>
9 #include <Inventor/nodes/SoMaterial.h>
10 
12 {
14  {
15  // We do everything in millimeters...
16  units = new SoUnits();
17  units->units = SoUnits::MILLIMETERS;
18 
19  transform = new SoTransform;
20  material = new SoMaterial;
21 
22  switch_ = new SoSwitch;
23  switch_->whichChild = SO_SWITCH_ALL;
24 
25  separator = new SoSeparator;
26  separator->addChild(units);
27  separator->addChild(transform);
28  separator->addChild(material);
29  separator->addChild(switch_);
30  }
31 
32  void ElementVisualization::updateBase(data::Element const& element)
33  {
34  auto& p = element.pose;
35  transform->translation.setValue(p.x, p.y, p.z);
36  transform->rotation.setValue(p.qx, p.qy, p.qz, p.qw);
37  transform->scaleFactor.setValue(element.scale.e0, element.scale.e1, element.scale.e2);
38 
39  auto color = element.color;
40  const float conv = 1.0f / 255.0f;
41  SbColor coinColor(conv * color.r, conv * color.g, conv * color.b);
42  material->ambientColor.setValue(coinColor);
43  material->diffuseColor.setValue(coinColor);
44  material->transparency.setValue(1.0f - conv * color.a);
45 
46  // This enables textured meshes to be displayed with transparency
47  bool overrideMaterial = (element.flags & data::ElementFlags::OVERRIDE_MATERIAL);
48  material->setOverride(overrideMaterial);
49  }
50 
51  std::unique_ptr<ElementVisualization> ElementVisualizer::create(const data::Element& element)
52  {
53  std::unique_ptr<ElementVisualization> result(createDerived());
54  update(element, result.get());
55 
56  return result;
57  }
58 
59  bool ElementVisualizer::update(data::Element const& element, ElementVisualization* visu)
60  {
61  visu->updateBase(element);
62  return updateDerived(element, visu);
63  }
64 }
65 
armarx::viz::coin::ElementVisualization
Definition: ElementVisualizer.h:21
armarx::viz::coin::ElementVisualizer::createDerived
virtual ElementVisualization * createDerived()=0
ElementVisualizer.h
IceConversions.h
armarx::viz::coin::ElementVisualizer::update
bool update(data::Element const &element, ElementVisualization *visu)
Definition: ElementVisualizer.cpp:59
armarx::viz::coin::ElementVisualization::updateBase
void updateBase(data::Element const &element)
Definition: ElementVisualizer.cpp:32
armarx::viz::coin::ElementVisualization::switch_
SoSwitch * switch_
Definition: ElementVisualizer.h:33
armarx::viz::coin::ElementVisualization::transform
SoTransform * transform
Definition: ElementVisualizer.h:31
armarx::viz::coin::ElementVisualization::material
SoMaterial * material
Definition: ElementVisualizer.h:32
armarx::viz::coin::ElementVisualizer::updateDerived
virtual bool updateDerived(data::Element const &element, ElementVisualization *data)=0
armarx::viz::coin::ElementVisualization::units
SoUnits * units
Definition: ElementVisualizer.h:30
armarx::viz::coin
Definition: ElementVisualizer.cpp:11
armarx::viz::coin::ElementVisualizer::create
std::unique_ptr< ElementVisualization > create(data::Element const &element)
Definition: ElementVisualizer.cpp:51
armarx::viz::coin::ElementVisualization::separator
SoSeparator * separator
Definition: ElementVisualizer.h:29
armarx::viz::coin::ElementVisualization::ElementVisualization
ElementVisualization()
Definition: ElementVisualizer.cpp:13