Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the visualization of labels #879

Merged
merged 10 commits into from
Jun 15, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add the visualization of labels in the visualizer (https://github.com/robotology/idyntree/pull/879)

## [3.2.1] - 2021-06-07

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

cmake_minimum_required(VERSION 3.16)

project(iDynTree VERSION 3.2.1
project(iDynTree VERSION 4.0.0
LANGUAGES C CXX)

# Disable in source build, unless Eclipse is used
Expand Down
2 changes: 2 additions & 0 deletions src/visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if(IDYNTREE_USES_IRRLICHT)
src/Texture.h
src/TexturesHandler.h
src/Light.h
src/Label.h
src/FloorGridSceneNode.h)
set(iDynTree_visualization_private_source src/Camera.cpp
src/CameraAnimator.cpp
Expand All @@ -32,6 +33,7 @@ if(IDYNTREE_USES_IRRLICHT)
src/Texture.cpp
src/TexturesHandler.cpp
src/Light.cpp
src/Label.cpp
src/FloorGridSceneNode.cpp)
endif()

Expand Down
107 changes: 107 additions & 0 deletions src/visualization/include/iDynTree/Visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,81 @@ class IJetsVisualization
virtual bool setJetsIntensity(const VectorDynSize & jetsIntensity) = 0;
};

/**
* The interface to add a label in the visualizer.
*/

class ILabel
{
public:

/**
* Destructor
*/
virtual ~ILabel() = 0;

/**
* @brief Set the text of the label
* @param text The text to be displayed
*/
virtual void setText(const std::string& text) = 0;

/**
* @brief Get the label text
* @return The text shown in the label.
*/
virtual std::string getText() const = 0;

/**
* @brief Set the height of the label. The width is computed automatically
* @param height The height to be set
*/
virtual void setSize(float height) = 0;

/**
* @brief Set the width and the height of the label
* @param width The width of the label
* @param height The height of the label
*/
virtual void setSize(float width, float height) = 0;

/**
* @brief Get the width of the label
* @return The width of the label
*/
virtual float width() const = 0;

/**
* @brief Get the height of the label
* @return The height of the label
*/
virtual float height() const = 0;

/**
* @brief Set the position of the label
* @param position The position of the label
*/
virtual void setPosition(const iDynTree::Position& position) = 0;

/**
* @brief Get the position of the label
* @return The position of the label
*/
virtual iDynTree::Position getPosition() const = 0;

/**
* @brief Set the color of the label
* @param color The color of the label
*/
virtual void setColor(const iDynTree::ColorViz& color) = 0;

/**
* @brief Set the visibility of the label
* @param visible The visibility of the label
*/
virtual void setVisible(bool visible = true) = 0;
};

/**
* Interface to the visualization of vectors.
*/
Expand Down Expand Up @@ -454,6 +529,21 @@ class IVectorsVisualization
* @return true if successfull, false in case of negative numbers.
*/
virtual bool setVectorsAspect(double zeroModulusRadius, double modulusMultiplier, double heightScale) = 0;

/**
* @brief Set the visibility of a given vector
* @param The index of the vector to change the visibility
* @param visible The visibility of the vector
* @return true if successfull, false if the index is out of bounds
*/
virtual bool setVisible(size_t vectorIndex, bool visible = true) = 0;

/**
* @brief Get the label associated to a vector
* @param vectorIndex The index of the vector to get the label
* @return The label associated to the vector. nullptr if the vectorIndex is out of bounds.
*/
virtual ILabel* getVectorLabel(size_t vectorIndex) = 0;
};

/**
Expand Down Expand Up @@ -495,6 +585,13 @@ class IFrameVisualization
* Update Frame
*/
virtual bool updateFrame(size_t frameIndex, const Transform& transformation) = 0;

/**
* Get the label of a frame.
*
* Returns nullptr of the frame index is out of bounds.
*/
virtual ILabel* getFrameLabel(size_t frameIndex) = 0;
};


Expand Down Expand Up @@ -617,6 +714,11 @@ class IModelVisualization
* Get the transformation of given frame with respect to visualizer world \f$ w_H_{frame}\f$
*/
virtual Transform getWorldFrameTransform(const std::string& frameName) = 0;

/**
* Get the label for the model.
*/
virtual ILabel& label() = 0;
};

/**
Expand Down Expand Up @@ -815,6 +917,11 @@ friend class ModelVisualization;
*/
ITexturesHandler& textures();

/**
* Get a label given a name. Note: this does not set the text in the label.
*/
ILabel& getLabel(const std::string& labelName);

/**
* Wrap the run method of the Irrlicht device.
*/
Expand Down
21 changes: 21 additions & 0 deletions src/visualization/src/DummyImplementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ class DummyJetsVisualization : public IJetsVisualization
virtual bool setJetsIntensity(const VectorDynSize & ) { return false; };
};

class DummyLabel : public iDynTree::ILabel
{
public:
virtual ~DummyLabel() override {};
virtual void setText(const std::string& ) override {};
virtual std::string getText() const override {return "";};
virtual void setSize(float ) override {};
virtual void setSize(float , float ) override {};
virtual float width() const override {return 0.0;};
virtual float height() const override {return 0.0;};
virtual void setPosition(const iDynTree::Position& ) override {};
virtual iDynTree::Position getPosition() const override {return iDynTree::Position::Zero();};
virtual void setColor(const iDynTree::ColorViz& ) override {};
virtual void setVisible(bool ) override {};
};

class DummyVectorsVisualization : public IVectorsVisualization {
public:
virtual ~DummyVectorsVisualization() override { }
Expand All @@ -107,6 +123,8 @@ class DummyVectorsVisualization : public IVectorsVisualization {
virtual bool setVectorsAspect(double, double, double) override { return false; }
virtual void setVectorsColor(const ColorViz &) override { return; }
virtual void setVectorsDefaultColor(const ColorViz &) override { return; }
virtual bool setVisible(size_t , bool ) override { return false; }
virtual ILabel* getVectorLabel(size_t ) override {return nullptr;}
};

class DummyFrameVisualization : public IFrameVisualization
Expand All @@ -119,6 +137,7 @@ class DummyFrameVisualization : public IFrameVisualization
virtual size_t getNrOfFrames() const override {return 0; };
virtual bool getFrameTransform(size_t , Transform& ) const override {return false;};
virtual bool updateFrame(size_t, const Transform&) override {return false;};
virtual ILabel* getFrameLabel(size_t) override {return nullptr;};
};

/**
Expand All @@ -128,6 +147,7 @@ class DummyModelVisualization : public IModelVisualization
{
Model m_dummyModel;
DummyJetsVisualization m_dummyJets;
DummyLabel m_dummyLabel;
public:
virtual ~DummyModelVisualization() {};
virtual bool init(const Model& , const std::string , Visualizer &) { return false; }
Expand All @@ -151,6 +171,7 @@ class DummyModelVisualization : public IModelVisualization
virtual Transform getWorldFrameTransform(const FrameIndex &) { return iDynTree::Transform::Identity(); }
virtual Transform getWorldLinkTransform(const std::string &) { return iDynTree::Transform::Identity(); }
virtual Transform getWorldFrameTransform(const std::string &) { return iDynTree::Transform::Identity(); }
virtual ILabel& label() { return m_dummyLabel; };
};

class DummyTexturesHandler : public ITexturesHandler
Expand Down
11 changes: 11 additions & 0 deletions src/visualization/src/FrameVisualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ size_t iDynTree::FrameVisualization::addFrame(const iDynTree::Transform &transfo

m_frames.back().visualizationNode = addFrameAxes(m_smgr, 0, arrowLength);
setFrameTransform(m_frames.size() - 1, transformation);
m_frames.back().label.init(m_smgr, m_frames.back().visualizationNode);

return m_frames.size() - 1;
}
Expand Down Expand Up @@ -76,6 +77,16 @@ bool iDynTree::FrameVisualization::updateFrame(size_t frameIndex, const iDynTree
return true;
}

iDynTree::ILabel *iDynTree::FrameVisualization::getFrameLabel(size_t frameIndex)
{
if (frameIndex >= m_frames.size()) {
reportError("FrameVisualization","getFrameLabel","frameIndex out of bounds.");
return nullptr;
}

return &m_frames[frameIndex].label;
}

iDynTree::FrameVisualization::~FrameVisualization()
{
close();
Expand Down
4 changes: 4 additions & 0 deletions src/visualization/src/FrameVisualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define IDYNTREE_FRAMEVISUALIZATION_H

#include <iDynTree/Visualizer.h>
#include "Label.h"

#include <vector>
#include <irrlicht.h>
Expand All @@ -22,6 +23,7 @@ namespace iDynTree
struct Frame
{
irr::scene::ISceneNode * visualizationNode = nullptr;
Label label;
};

std::vector<Frame> m_frames;
Expand Down Expand Up @@ -53,6 +55,8 @@ namespace iDynTree

virtual bool updateFrame(size_t frameIndex, const Transform& transformation) final;

virtual ILabel* getFrameLabel(size_t frameIndex) final;

};
}

Expand Down
Loading