Skip to content
Snippets Groups Projects
Commit f951799a authored by Fabian Reister's avatar Fabian Reister
Browse files

Merge branch 'feature/Arviz-Path-Visu-update' into 'master'

Feature/arviz path visu update

See merge request ArmarX/RobotAPI!168
parents 7afb8465 c4e24369
No related branches found
No related tags found
No related merge requests found
#include "Path.h" #include "Path.h"
#include <iterator>
#include <ArmarXCore/interface/core/BasicVectorTypes.h>
#include <ArmarXCore/interface/core/BasicVectorTypesHelpers.h>
namespace armarx::viz namespace armarx::viz
{ {
Path& Path::clear() Path& Path::clear()
{ {
data_->points.clear(); data_->points.clear();
return *this;
}
Path& Path::lineColor(Color color)
{
data_->lineColor = color;
return *this; return *this;
} }
Path& Path::lineColorGlasbeyLUT(std::size_t id, int alpha) Path& Path::width(float w)
{
return lineColor(Color::fromRGBA(simox::color::GlasbeyLUT::at(id, alpha)));
}
Path& Path::lineWidth(float w)
{ {
data_->lineWidth = w; data_->lineWidth = w;
...@@ -33,17 +27,21 @@ namespace armarx::viz ...@@ -33,17 +27,21 @@ namespace armarx::viz
auto& points = data_->points; auto& points = data_->points;
points.clear(); points.clear();
points.reserve(ps.size()); points.reserve(ps.size());
for (auto& p : ps)
std::transform(ps.begin(),
ps.end(),
std::back_inserter(points),
[](const auto & e)
{ {
points.push_back(armarx::Vector3f{p.x(), p.y(), p.z()}); return ToBasicVectorType(e);
} });
return *this; return *this;
} }
Path& Path::addPoint(Eigen::Vector3f p) Path& Path::addPoint(Eigen::Vector3f p)
{ {
data_->points.push_back(armarx::Vector3f{p.x(), p.y(), p.z()}); data_->points.emplace_back(ToBasicVectorType(p));
return *this; return *this;
} }
......
...@@ -35,17 +35,7 @@ namespace armarx::viz ...@@ -35,17 +35,7 @@ namespace armarx::viz
Path& clear(); Path& clear();
Path& lineColor(Color color); Path& width(float w);
template<class...Ts>
Path& lineColor(Ts&& ...ts)
{
return lineColor({std::forward<Ts>(ts)...});
}
Path& lineColorGlasbeyLUT(std::size_t id, int alpha = 255);
Path& lineWidth(float w);
Path& points(std::vector<Eigen::Vector3f> const& ps); Path& points(std::vector<Eigen::Vector3f> const& ps);
......
#include "VisualizationPath.h" #include "VisualizationPath.h"
#include <algorithm>
#include <Inventor/SbVec3f.h> #include <Inventor/SbVec3f.h>
#include <Inventor/nodes/SoCoordinate3.h> #include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoDrawStyle.h> #include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoLineSet.h> #include <Inventor/nodes/SoLineSet.h>
#include <Inventor/nodes/SoPointSet.h>
namespace armarx::viz::coin namespace armarx::viz::coin
{ {
...@@ -27,19 +30,36 @@ namespace armarx::viz::coin ...@@ -27,19 +30,36 @@ namespace armarx::viz::coin
node->addChild(coordinate3); node->addChild(coordinate3);
node->addChild(lineSep); node->addChild(lineSep);
// points (use the following, if the points should be drawn in a different color)
// pclMat = new SoMaterial;
// SoMaterialBinding* pclMatBind = new SoMaterialBinding;
// pclMatBind->value = SoMaterialBinding::PER_PART;
pclCoords = new SoCoordinate3;
pclStyle = new SoDrawStyle;
// node->addChild(pclMat);
// node->addChild(pclMatBind);
node->addChild(pclCoords);
node->addChild(pclStyle);
node->addChild(new SoPointSet);
} }
bool VisualizationPath::update(ElementType const& element) bool VisualizationPath::update(ElementType const& element)
{ {
// set position // set position
coordinate3->point.setValuesPointer(element.points.size(), reinterpret_cast<const float*>(element.points.data())); coordinate3->point.setValuesPointer(element.points.size(),
reinterpret_cast<const float*>(element.points.data()));
// set color // set color
const auto lineColor = element.lineColor; const auto lineColor = element.color;
constexpr float toUnit = 1.0F / 255.0F; constexpr float toUnit = 1.0F / 255.0F;
const auto color = SbVec3f(lineColor.r, lineColor.g, lineColor.b) * toUnit; const auto color = SbVec3f(lineColor.r, lineColor.g, lineColor.b) * toUnit;
const float transparency = 1.0F - static_cast<float>(lineColor.a) * toUnit; const float transparency = 1.0F - static_cast<float>(lineColor.a) * toUnit;
lineMaterial->diffuseColor.setValue(color); lineMaterial->diffuseColor.setValue(color);
...@@ -58,6 +78,20 @@ namespace armarx::viz::coin ...@@ -58,6 +78,20 @@ namespace armarx::viz::coin
const int pointSize = static_cast<int>(element.points.size()); const int pointSize = static_cast<int>(element.points.size());
lineSet->numVertices.set1Value(0, pointSize); lineSet->numVertices.set1Value(0, pointSize);
// points at each node
// const std::vector<SbVec3f> colorData(element.points.size(), color);
// pclMat->diffuseColor.setValuesPointer(colorData.size(),
// reinterpret_cast<const float*>(colorData.data()));
// pclMat->ambientColor.setValuesPointer(colorData.size(),
// reinterpret_cast<const float*>(colorData.data()));
// pclMat->transparency = transparency;
pclCoords->point.setValuesPointer(element.points.size(),
reinterpret_cast<const float*>(element.points.data()));
pclStyle->pointSize = element.lineWidth + 5;
return true; return true;
} }
} // namespace armarx::viz::coin } // namespace armarx::viz::coin
\ No newline at end of file
...@@ -39,9 +39,17 @@ namespace armarx::viz::coin ...@@ -39,9 +39,17 @@ namespace armarx::viz::coin
bool update(ElementType const& element); bool update(ElementType const& element);
/// lines
SoCoordinate3* coordinate3; SoCoordinate3* coordinate3;
SoDrawStyle* lineStyle; SoDrawStyle* lineStyle;
SoLineSet* lineSet; SoLineSet* lineSet;
SoMaterial* lineMaterial; SoMaterial* lineMaterial;
/// points
// SoMaterial* pclMat;
SoCoordinate3* pclCoords;
SoDrawStyle* pclStyle;
}; };
} // namespace armarx::viz::coin } // namespace armarx::viz::coin
...@@ -104,7 +104,6 @@ module data ...@@ -104,7 +104,6 @@ module data
{ {
Vector3fSeq points; Vector3fSeq points;
Color lineColor;
float lineWidth = 10.0f; float lineWidth = 10.0f;
}; };
......
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