diff --git a/source/RobotAPI/components/ArViz/CMakeLists.txt b/source/RobotAPI/components/ArViz/CMakeLists.txt index 23bc568751839f9758cd09597b2b4f58b8b5e419..9a5a3adcbfedd3a756b8231b61db7591ad66047b 100644 --- a/source/RobotAPI/components/ArViz/CMakeLists.txt +++ b/source/RobotAPI/components/ArViz/CMakeLists.txt @@ -15,12 +15,16 @@ set(SOURCES Client/elements/Mesh.cpp Client/elements/Robot.cpp Client/elements/RobotHand.cpp + Client/elements/Line.cpp + Client/elements/Path.cpp + Client/drawer/ArVizDrawerBase.cpp Client/ScopedClient.cpp Coin/ElementVisualizer.cpp Coin/VisualizationRobot.cpp + Coin/VisualizationPath.cpp Coin/VisualizationObject.cpp Coin/Visualizer.cpp @@ -49,6 +53,7 @@ set(HEADERS Coin/VisualizationEllipsoid.h Coin/VisualizationSphere.h Coin/VisualizationPose.h + Coin/VisualizationPath.h Coin/VisualizationLine.h Coin/VisualizationText.h Coin/VisualizationArrow.h @@ -77,6 +82,8 @@ set(HEADERS Client/elements/PointCloud.h Client/elements/Robot.h Client/elements/RobotHand.h + Client/elements/Line.h + Client/elements/Path.h Client/drawer/ArVizDrawerBase.h diff --git a/source/RobotAPI/components/ArViz/Client/elements/Line.cpp b/source/RobotAPI/components/ArViz/Client/elements/Line.cpp new file mode 100644 index 0000000000000000000000000000000000000000..985162f1726a66c88c4a310e6b287641294fa9f9 --- /dev/null +++ b/source/RobotAPI/components/ArViz/Client/elements/Line.cpp @@ -0,0 +1,20 @@ +#include "Line.h" + +#include "ArmarXCore/interface/core/BasicVectorTypesHelpers.h" + +namespace armarx::viz +{ + Line& Line::lineWidth(float w) + { + data_->lineWidth = w; + + return *this; + } + Line& Line::fromTo(Eigen::Vector3f from, Eigen::Vector3f to) + { + data_->from = ToBasicVectorType(from); + data_->to = ToBasicVectorType(to); + + return *this; + } +} // namespace armarx::viz \ No newline at end of file diff --git a/source/RobotAPI/components/ArViz/Client/elements/Line.h b/source/RobotAPI/components/ArViz/Client/elements/Line.h new file mode 100644 index 0000000000000000000000000000000000000000..6f6d9427e05b9d91606e8ecdfa8a2164f4847515 --- /dev/null +++ b/source/RobotAPI/components/ArViz/Client/elements/Line.h @@ -0,0 +1,38 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include "RobotAPI/components/ArViz/Client/elements/ElementOps.h" +#include <RobotAPI/interface/ArViz/Elements.h> + +namespace armarx::viz +{ + class Line : public ElementOps<Line, data::ElementLine> + { + public: + using ElementOps::ElementOps; + + Line& lineWidth(float w); + + Line& fromTo(Eigen::Vector3f from, Eigen::Vector3f to); + }; +} // namespace armarx::viz diff --git a/source/RobotAPI/components/ArViz/Client/elements/Path.cpp b/source/RobotAPI/components/ArViz/Client/elements/Path.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a88d089382eebb915104c24ee41339a18dd2f29 --- /dev/null +++ b/source/RobotAPI/components/ArViz/Client/elements/Path.cpp @@ -0,0 +1,51 @@ +#include "Path.h" + +namespace armarx::viz +{ + + Path& Path::clear() + { + data_->points.clear(); + return *this; + } + + Path& Path::lineColor(Color color) + { + data_->lineColor = color; + + return *this; + } + + Path& Path::lineColorGlasbeyLUT(std::size_t id, int alpha) + { + return lineColor(Color::fromRGBA(simox::color::GlasbeyLUT::at(id, alpha))); + } + + Path& Path::lineWidth(float w) + { + data_->lineWidth = w; + + return *this; + } + + Path& Path::points(std::vector<Eigen::Vector3f> const& ps) + { + auto& points = data_->points; + points.clear(); + points.reserve(ps.size()); + for (auto& p : ps) + { + points.push_back(armarx::Vector3f{p.x(), p.y(), p.z()}); + } + + return *this; + } + + Path& Path::addPoint(Eigen::Vector3f p) + { + data_->points.push_back(armarx::Vector3f{p.x(), p.y(), p.z()}); + + return *this; + } + +} // namespace armarx::viz \ No newline at end of file diff --git a/source/RobotAPI/components/ArViz/Client/elements/Path.h b/source/RobotAPI/components/ArViz/Client/elements/Path.h new file mode 100644 index 0000000000000000000000000000000000000000..50eec6abe454bbf56bc45053c4d35f5e41ca5bc6 --- /dev/null +++ b/source/RobotAPI/components/ArViz/Client/elements/Path.h @@ -0,0 +1,59 @@ + + +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include "RobotAPI/components/ArViz/Client/elements/ElementOps.h" +#include <RobotAPI/interface/ArViz/Elements.h> + +namespace armarx::viz +{ + class Path : public ElementOps<Path, data::ElementPath> + { + public: + using ElementOps::ElementOps; + + Path& clear(); + + Path& lineColor(Color color); + + 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& addPoint(Eigen::Vector3f p); + }; +} // namespace armarx::viz + + + + + diff --git a/source/RobotAPI/components/ArViz/Coin/RegisterVisualizationTypes.cpp b/source/RobotAPI/components/ArViz/Coin/RegisterVisualizationTypes.cpp index 33febe24be91fd428f06762cbcfc6d7e48f101a0..5ca14001aff6c7be187ad4c7736e86fd3ab6b3c6 100644 --- a/source/RobotAPI/components/ArViz/Coin/RegisterVisualizationTypes.cpp +++ b/source/RobotAPI/components/ArViz/Coin/RegisterVisualizationTypes.cpp @@ -15,13 +15,14 @@ #include "VisualizationMesh.h" #include "VisualizationRobot.h" #include "VisualizationObject.h" +#include "VisualizationPath.h" void armarx::viz::CoinVisualizer::registerVisualizationTypes() { using namespace armarx::viz::coin; - elementVisualizers.reserve(15); + elementVisualizers.reserve(16); registerVisualizerFor<VisualizationBox>(); registerVisualizerFor<VisualizationCylinder>(); @@ -38,4 +39,5 @@ void armarx::viz::CoinVisualizer::registerVisualizationTypes() registerVisualizerFor<VisualizationMesh>(); registerVisualizerFor<VisualizationRobot>(); registerVisualizerFor<VisualizationObject>(); + registerVisualizerFor<VisualizationPath>(); } diff --git a/source/RobotAPI/components/ArViz/Coin/VisualizationPath.cpp b/source/RobotAPI/components/ArViz/Coin/VisualizationPath.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3018a3af51e25222b97c0c60ed06fea65a8c5822 --- /dev/null +++ b/source/RobotAPI/components/ArViz/Coin/VisualizationPath.cpp @@ -0,0 +1,63 @@ +#include "VisualizationPath.h" + +#include <Inventor/SbVec3f.h> +#include <Inventor/nodes/SoCoordinate3.h> +#include <Inventor/nodes/SoDrawStyle.h> +#include <Inventor/nodes/SoLineSet.h> + +namespace armarx::viz::coin +{ + + VisualizationPath::VisualizationPath() + { + coordinate3 = new SoCoordinate3; + + // create line around polygon + SoSeparator* lineSep = new SoSeparator; + + lineMaterial = new SoMaterial; + lineSep->addChild(lineMaterial); + lineSep->addChild(coordinate3); + + lineStyle = new SoDrawStyle(); + lineSep->addChild(lineStyle); + + lineSet = new SoLineSet; + lineSep->addChild(lineSet); + + node->addChild(coordinate3); + node->addChild(lineSep); + } + + bool VisualizationPath::update(ElementType const& element) + { + // set position + coordinate3->point.setValuesPointer(element.points.size(), reinterpret_cast<const float*>(element.points.data())); + + // set color + const auto lineColor = element.lineColor; + + constexpr float toUnit = 1.0F / 255.0F; + + const auto color = SbVec3f(lineColor.r, lineColor.g, lineColor.b) * toUnit; + const float transparency = 1.0F - static_cast<float>(lineColor.a) * toUnit; + + lineMaterial->diffuseColor.setValue(color); + lineMaterial->ambientColor.setValue(color); + lineMaterial->transparency.setValue(transparency); + + if (element.lineWidth > 0.0F) + { + lineStyle->lineWidth.setValue(element.lineWidth); + } + else + { + lineStyle->style = SoDrawStyleElement::INVISIBLE; + } + + const int pointSize = static_cast<int>(element.points.size()); + lineSet->numVertices.set1Value(0, pointSize); + + return true; + } +} // namespace armarx::viz::coin \ No newline at end of file diff --git a/source/RobotAPI/components/ArViz/Coin/VisualizationPath.h b/source/RobotAPI/components/ArViz/Coin/VisualizationPath.h new file mode 100644 index 0000000000000000000000000000000000000000..e1e446bbe66bc49a6d0c4bdf1999c7f0615f06ec --- /dev/null +++ b/source/RobotAPI/components/ArViz/Coin/VisualizationPath.h @@ -0,0 +1,47 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include "ElementVisualizer.h" + +#include <RobotAPI/interface/ArViz/Elements.h> + +class SoCoordinate3; +class SoDrawStyle; +class SoLineSet; + +namespace armarx::viz::coin +{ + struct VisualizationPath : TypedElementVisualization<SoSeparator> + { + using ElementType = data::ElementPath; + + VisualizationPath(); + + bool update(ElementType const& element); + + SoCoordinate3* coordinate3; + SoDrawStyle* lineStyle; + SoLineSet* lineSet; + SoMaterial* lineMaterial; + }; +} // namespace armarx::viz::coin diff --git a/source/RobotAPI/interface/ArViz/Elements.ice b/source/RobotAPI/interface/ArViz/Elements.ice index 0adf0413b30d5985851b86dab12580d0a314acbe..1c00dd4e630208a79852ea3d18d96da8a501f7d0 100644 --- a/source/RobotAPI/interface/ArViz/Elements.ice +++ b/source/RobotAPI/interface/ArViz/Elements.ice @@ -100,6 +100,14 @@ module data float lineWidth = 0.0f; }; + class ElementPath extends Element + { + Vector3fSeq points; + + Color lineColor; + float lineWidth = 10.0f; + }; + class ElementArrow extends Element { float length = 100.0f;