Skip to content
Snippets Groups Projects
Commit 62aac7d3 authored by Fabian Paus's avatar Fabian Paus
Browse files

Refactor...

parent 22fbc12e
No related branches found
No related tags found
No related merge requests found
Showing
with 56 additions and 59 deletions
......@@ -19,16 +19,31 @@ namespace armarx
transform = new SoTransform;
material = new SoMaterial;
seperator = new SoSeparator;
seperator->addChild(units);
seperator->addChild(transform);
seperator->addChild(material);
separator = new SoSeparator;
separator->addChild(units);
separator->addChild(transform);
separator->addChild(material);
}
void ElementVisualization::updateBase(Element const& element)
{
auto& p = element.pose;
transform->translation.setValue(p.x, p.y, p.z);
transform->rotation.setValue(p.qx, p.qy, p.qz, p.qw);
transform->scaleFactor.setValue(element.scale, element.scale, element.scale);
auto color = element.color;
const float conv = 1.0f / 255.0f;
SbColor coinColor(conv * color.r, conv * color.g, conv * color.b);
material->ambientColor.setValue(coinColor);
material->diffuseColor.setValue(coinColor);
material->transparency.setValue(1.0f - conv * color.a);
}
std::unique_ptr<ElementVisualization> ElementVisualizer::create(const Element& element)
{
std::unique_ptr<ElementVisualization> result(createElement_());
result->seperator->addChild(result->getNode());
std::unique_ptr<ElementVisualization> result(createDerived());
update(element, result.get());
return result;
......@@ -36,24 +51,8 @@ namespace armarx
bool ElementVisualizer::update(Element const& element, ElementVisualization* visu)
{
if (visu->transform)
{
auto& p = element.pose;
visu->transform->translation.setValue(p.x, p.y, p.z);
visu->transform->rotation.setValue(p.qx, p.qy, p.qz, p.qw);
visu->transform->scaleFactor.setValue(element.scale, element.scale, element.scale);
}
if (visu->material)
{
auto color = element.color;
const float conv = 1.0f / 255.0f;
SbColor coinColor(conv * color.r, conv * color.g, conv * color.b);
visu->material->ambientColor.setValue(coinColor);
visu->material->diffuseColor.setValue(coinColor);
visu->material->transparency.setValue(1.0f - conv * color.a);
}
return updateElement_(element, visu);
visu->updateBase(element);
return updateDerived(element, visu);
}
}
}
......
......@@ -22,12 +22,12 @@ namespace armarx
virtual ~ElementVisualization() = default;
virtual SoNode* getNode() = 0;
void updateBase(Element const& element);
SoSeparator* seperator = nullptr;
SoUnits* units = nullptr;
SoTransform* transform = nullptr;
SoMaterial* material = nullptr;
SoSeparator* separator;
SoUnits* units;
SoTransform* transform;
SoMaterial* material;
};
template <typename NodeT>
......@@ -40,11 +40,6 @@ namespace armarx
node = new NodeType;
}
NodeType* getNode() final
{
return node;
}
NodeType* node;
};
......@@ -53,31 +48,34 @@ namespace armarx
public:
virtual ~ElementVisualizer() = default;
virtual std::unique_ptr<ElementVisualization> create(Element const& element) final;
virtual bool update(Element const& element, ElementVisualization* visu) final;
std::unique_ptr<ElementVisualization> create(Element const& element);
bool update(Element const& element, ElementVisualization* visu);
virtual ElementVisualization* createElement_() = 0;
virtual bool updateElement_(Element const& element, ElementVisualization* data) = 0;
virtual ElementVisualization* createDerived() = 0;
virtual bool updateDerived(Element const& element, ElementVisualization* data) = 0;
};
template <typename DataT>
class TypedElementVisualizer2 : public ElementVisualizer
class TypedElementVisualizer : public ElementVisualizer
{
public:
using DataType = DataT;
using ElementType = typename DataType::ElementType;
DataType* createElement_() override
DataType* createDerived() final
{
return new DataType;
DataType* result = new DataType;
result->separator->addChild(result->node);
return result;
}
bool updateElement_(Element const& element_, ElementVisualization* data_) override
bool updateDerived(Element const& element_, ElementVisualization* data_) final
{
auto const& element = static_cast<ElementType const&>(element_);
auto* data = dynamic_cast<DataType*>(data_);
if (data)
{
// We want to call update with the correctly downcasted arguments
return data->update(element);
}
return false;
......
......@@ -155,7 +155,7 @@ namespace armarx
case Element_ADD:
{
// Remove old element and create a new one below
layer.node->removeChild(oldElement.seperator);
layer.node->removeChild(oldElement.separator);
}
break;
case Element_UPDATE:
......@@ -168,14 +168,14 @@ namespace armarx
else
{
// Types are different, so we delete the old element and create a new one
layer.node->removeChild(oldElement.seperator);
layer.node->removeChild(oldElement.separator);
}
}
break;
case Element_DELETE:
{
layer.elements.erase(oldElementIter);
layer.node->removeChild(oldElement.seperator);
layer.node->removeChild(oldElement.separator);
continue;
}
break;
......@@ -193,9 +193,9 @@ namespace armarx
continue;
}
auto elementVisu = visualizer.create(updatedElement);
if (elementVisu->seperator)
if (elementVisu->separator)
{
layer.node->addChild(elementVisu->seperator);
layer.node->addChild(elementVisu->separator);
layer.elements[updatedElement.id] = std::move(elementVisu);
}
else
......
......@@ -53,7 +53,7 @@ namespace armarx::viz::coin
SoCone* cone;
};
struct VisualizerArrow : TypedElementVisualizer2<VisualizationArrow>
struct VisualizerArrow : TypedElementVisualizer<VisualizationArrow>
{
};
}
......@@ -66,7 +66,7 @@ namespace armarx::viz::coin
}
};
struct VisualizerArrowCircle: TypedElementVisualizer2<VisualizationArrowCircle>
struct VisualizerArrowCircle: TypedElementVisualizer<VisualizationArrowCircle>
{
};
}
......@@ -21,7 +21,7 @@ namespace armarx::viz::coin
}
};
class VisualizerBox : public TypedElementVisualizer2<VisualizationBox>
class VisualizerBox : public TypedElementVisualizer<VisualizationBox>
{
};
}
......@@ -20,7 +20,7 @@ namespace armarx::viz::coin
}
};
class VisualizerCylinder : public TypedElementVisualizer2<VisualizationCylinder>
class VisualizerCylinder : public TypedElementVisualizer<VisualizationCylinder>
{
};
}
......@@ -43,7 +43,7 @@ namespace armarx::viz::coin
SoCoordinate3* coordinate3;
};
struct VisualizerLine: TypedElementVisualizer2<VisualizationLine>
struct VisualizerLine: TypedElementVisualizer<VisualizationLine>
{
};
}
......@@ -131,7 +131,7 @@ namespace armarx::viz::coin
std::vector<int32_t> matInx;
};
struct VisualizerMesh: TypedElementVisualizer2<VisualizationMesh>
struct VisualizerMesh: TypedElementVisualizer<VisualizationMesh>
{
};
}
......@@ -69,7 +69,7 @@ namespace armarx::viz::coin
std::vector<SbVec3f> coords;
};
struct VisualizerPointCloud: TypedElementVisualizer2<VisualizationPointCloud>
struct VisualizerPointCloud: TypedElementVisualizer<VisualizationPointCloud>
{
};
......
......@@ -93,7 +93,7 @@ namespace armarx::viz::coin
SoMaterial* lineMaterial;
};
struct VisualizerPolygon : TypedElementVisualizer2<VisualizationPolygon>
struct VisualizerPolygon : TypedElementVisualizer<VisualizationPolygon>
{
};
}
......@@ -154,7 +154,7 @@ namespace armarx::viz::coin
std::array<SoTransform*, 3> t2_;
};
struct VisualizerPose: TypedElementVisualizer2<VisualizationPose>
struct VisualizerPose: TypedElementVisualizer<VisualizationPose>
{
};
......
......@@ -23,7 +23,7 @@ namespace armarx::viz::coin
}
};
struct VisualizerRobot: TypedElementVisualizer2<VisualizationRobot>
struct VisualizerRobot: TypedElementVisualizer<VisualizationRobot>
{
};
}
......@@ -19,7 +19,7 @@ namespace armarx::viz::coin
}
};
struct VisualizerSphere: TypedElementVisualizer2<VisualizationSphere>
struct VisualizerSphere: TypedElementVisualizer<VisualizationSphere>
{
};
......
......@@ -20,7 +20,7 @@ namespace armarx::viz::coin
}
};
struct VisualizerText: TypedElementVisualizer2<VisualizationText>
struct VisualizerText: TypedElementVisualizer<VisualizationText>
{
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment