-
Notifications
You must be signed in to change notification settings - Fork 44
Rbs se3 viz #153
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
Open
mmaurus
wants to merge
5
commits into
rock-core:master
Choose a base branch
from
mmaurus:RBS_SE3_viz
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,331
−82
Open
Rbs se3 viz #153
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67bd987
added visualizer for RigidBodyStateSE3 and Wrench
mmaurus ae55026
using osgviz PrimitivesFactory for displaying arrow and circular arro…
mmaurus e6b0c18
added test script vor wrench visualization
mmaurus 3374a61
fixed intendation and empty lines
mmaurus 3b0eaea
addded test for WrenchVisualization
mmaurus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
require_relative 'helpers' | ||
require 'orocos' | ||
Orocos.load_typekit 'base' | ||
|
||
module Vizkit | ||
describe 'WrenchVisualization' do | ||
include TestHelpers | ||
|
||
before do | ||
register_widget(@vizkit3d_widget = | ||
Vizkit.default_loader.create_plugin("vizkit3d::Vizkit3DWidget")) | ||
@viz = @vizkit3d_widget.createPlugin('base', 'WrenchVisualization') | ||
|
||
@wrench = Types.base.samples.Wrench.new | ||
@wrench.frame_id = "test_frame" | ||
@wrench.force = Types.base.Vector3d.new(1,1,1) | ||
@wrench.torque = Types.base.Vector3d.new(-1,-1,1) | ||
@viz.updateData(@wrench) | ||
|
||
@viz.setResolution(1.0) | ||
|
||
@vizkit3d_widget.setCameraEye(5, 4, 5) | ||
@vizkit3d_widget.setCameraLookAt(0, 0, 0) | ||
@vizkit3d_widget.show | ||
end | ||
|
||
# describe "updateData(Wrench)" do | ||
# @wrench = Types.base.samples.Wrench.new | ||
# @wrench.frame_id = "test_frame" | ||
# @wrench.force = Types.base.Vector3d.new(1,1,1) | ||
# @wrench.torque = Types.base.Vector3d.new(-1,-1,1) | ||
|
||
# it "updates wrench" do | ||
# @viz.updateData(@wrench) | ||
# confirm 'Force should be displayed as a red arrow from (0,0,0) to (1,1,1) and torque as a green arrow from (0,0,0) to (-1,-1,1) with a circular arrow rotating counter-clockwise around axis' | ||
# end | ||
|
||
# it "updates wrench" do | ||
# @wrench.force = Types.base.Vector3d.new(1,0,0) | ||
# @wrench.torque = Types.base.Vector3d.new(0,1,0) | ||
# @viz.updateData(@wrench) | ||
# confirm 'Force should be displayed as a red arrow from (0,0,0) to (1,0,0) and torque as a green arrow from (0,0,0) to (0,1,0) with a circular arrow rotating counter-clockwise around axis' | ||
# end | ||
|
||
# it "updates wrench" do | ||
# @wrench.force = Types.base.Vector3d.new(0,1,0) | ||
# @wrench.torque = Types.base.Vector3d.new(0,0,1) | ||
# @viz.updateData(@wrench) | ||
# confirm 'Force should be displayed as a red arrow from (0,0,0) to (0,1,0) and torque as a green arrow from (0,0,0) to (0,0,1) with a circular arrow rotating counter-clockwise around axis' | ||
# end | ||
|
||
# it "updates wrench" do | ||
# @wrench.force = Types.base.Vector3d.new(0,0,1) | ||
# @wrench.torque = Types.base.Vector3d.new(1,0,0) | ||
# @viz.updateData(@wrench) | ||
# confirm 'Force should be displayed as a red arrow from (0,0,0) to (0,0,1) and torque as a green arrow from (0,0,0) to (1,0,0) with a circular arrow rotating counter-clockwise around axis' | ||
# end | ||
|
||
# it "updates wrench" do | ||
# @wrench.force = Types.base.Vector3d.new(0,0,0) | ||
# @wrench.torque = Types.base.Vector3d.new(0,0,0) | ||
# @viz.updateData(@wrench) | ||
# confirm 'Nothing should be displayed' | ||
# end | ||
|
||
# it "updates wrench" do | ||
# @wrench.force = Types.base.Vector3d.new(0.1,0,0) | ||
# @wrench.torque = Types.base.Vector3d.new(0.3,0,0) | ||
# @viz.updateData(@wrench) | ||
# confirm 'Force should be displayed as a red arrow from (0,0,0) to (0,0,0.1) and torque as a green arrow from (0,0,0) to (0.3,0,0) with a circular arrow rotating counter-clockwise around axis. Both arrows should be displayed without the arrow head' | ||
# end | ||
# end | ||
|
||
describe "setSeperateAxesTorque" do | ||
it "displays torque axis component" do | ||
torque = Types.base.Vector3d.new(1,1,1) | ||
@viz.setTorque(torque) | ||
@viz.setSeperateAxesTorque(true) | ||
confirm 'Torque should be displayed as three arrows along axes each with length 1 and a circular arrow rotating counter-clockwise' | ||
|
||
end | ||
|
||
it "displays torque" do | ||
torque = Types.base.Vector3d.new(1,1,1) | ||
@viz.setTorque(torque) | ||
@viz.setSeperateAxesTorque(false) | ||
confirm 'Torque should be displayed as one arrows starting from (0,0,0) to (1,1,1) with circular arrow rotating counter-clockwise' | ||
end | ||
end | ||
|
||
describe "setSeperateAxesForce" do | ||
it "displays force axis component" do | ||
force = Types.base.Vector3d.new(1,1,1) | ||
@viz.setForce(force) | ||
@viz.setSeperateAxesForce(true) | ||
confirm 'Force should be displayed as three arrows along axes each with length 1' | ||
end | ||
|
||
it "displays force" do | ||
force = Types.base.Vector3d.new(1,1,1) | ||
@viz.setForce(force) | ||
@viz.setSeperateAxesForce(false) | ||
confirm 'Force should be displayed as one arrows starting from (0,0,0) to (1,1,1)' | ||
end | ||
end | ||
|
||
# describe "setResolution" do | ||
# wrench = Types.base.samples.Wrench.new | ||
# wrench.frame_id = "test_frame" | ||
# wrench.force = Types.base.Vector3d.new(1,0,0) | ||
# wrench.torque = Types.base.Vector3d.new(0,1,0) | ||
|
||
# it "sets resolution to 1" do | ||
# @viz.updateData(wrench) | ||
# @viz.setResolution(1.0) | ||
# confirm "Force and torque will be displayed as arrows from (0,0,0) to (1,0,0) / (0,1,0)" | ||
# end | ||
# it "it sets resolution to 0.1" do | ||
# @viz.updateData(wrench) | ||
# @viz.setResolution(0.1) | ||
# confirm "Force and torque will be displayed as arrows from (0,0,0) to (0.1,0,0) / (0,0.1,0) without arrow head" | ||
# end | ||
# end | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#ifndef __RIGID_BODY_STATE_SE3_VISUALIZATION_HPP__ | ||
#define __RIGID_BODY_STATE_SE3_VISUALIZATION_HPP__ | ||
|
||
#include <vizkit3d/Vizkit3DPlugin.hpp> | ||
#include <Eigen/Geometry> | ||
#include <base/samples/RigidBodyStateSE3.hpp> | ||
#include <osgViz/OsgViz.hpp> | ||
#include <osgViz/modules/viz/Primitives/PrimitivesFactory.h> | ||
|
||
#include <osg/Image> | ||
#include <osg/Texture2D> | ||
#include <osg/MatrixTransform> | ||
#include "WrenchModel.hpp" | ||
|
||
namespace osgFX | ||
{ | ||
class BumpMapping; | ||
} | ||
|
||
namespace vizkit3d | ||
{ | ||
|
||
class RigidBodyStateSE3Visualization : public Vizkit3DPlugin<base::samples::RigidBodyStateSE3> | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(double size READ getSize WRITE setSize) | ||
Q_PROPERTY(double sphereSize READ getMainSphereSize WRITE setMainSphereSize) | ||
Q_PROPERTY(double textSize READ getTextSize WRITE setTextSize) | ||
Q_PROPERTY(bool forcePositionDisplay READ isPositionDisplayForced WRITE setPositionDisplayForceFlag) | ||
Q_PROPERTY(bool forceOrientationDisplay READ isOrientationDisplayForced WRITE setOrientationDisplayForceFlag) | ||
Q_PROPERTY(QString modelPath READ getModelPath WRITE loadModel) | ||
Q_PROPERTY(bool showPose READ isPoseDisplayed WRITE setPoseDisplayed) | ||
Q_PROPERTY(bool showVelocity READ isVelocityDisplayed WRITE setVelocityDisplayed) | ||
Q_PROPERTY(bool showAcceleration READ isAccelerationDisplayed WRITE setAccelerationDisplayed) | ||
Q_PROPERTY(bool showWrench READ isWrenchDisplayed WRITE setWrenchDisplayed) | ||
Q_PROPERTY(bool showSeperateAxes READ isSeperateAxes WRITE setSeperateAxes) | ||
Q_PROPERTY(double resolution READ getResolution WRITE setResolution) | ||
|
||
public: | ||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
RigidBodyStateSE3Visualization(QObject* parent = NULL); | ||
virtual ~RigidBodyStateSE3Visualization(); | ||
|
||
Q_INVOKABLE void updateData( const base::samples::RigidBodyStateSE3& state ) | ||
{ return Vizkit3DPlugin<base::samples::RigidBodyStateSE3>::updateData(state); } | ||
Q_INVOKABLE void updateRigidBodyStateSE3( const base::samples::RigidBodyStateSE3& state ) | ||
{ return updateData(state); } | ||
|
||
protected: | ||
virtual osg::ref_ptr<osg::Node> createMainNode(); | ||
virtual void updateMainNode(osg::Node* node); | ||
void updateDataIntern( const base::samples::RigidBodyStateSE3& state ); | ||
base::samples::RigidBodyStateSE3 state; | ||
|
||
public slots: | ||
bool isPositionDisplayForced() const; | ||
void setPositionDisplayForceFlag(bool flag); | ||
bool isOrientationDisplayForced() const; | ||
void setOrientationDisplayForceFlag(bool flag); | ||
|
||
bool isPoseDisplayed() const; | ||
void setPoseDisplayed(bool flag); | ||
|
||
bool isVelocityDisplayed() const; | ||
void setVelocityDisplayed(bool flag); | ||
|
||
bool isAccelerationDisplayed() const; | ||
void setAccelerationDisplayed(bool flag); | ||
|
||
bool isWrenchDisplayed() const; | ||
void setWrenchDisplayed(bool flag); | ||
|
||
double getSize() const; | ||
void setSize(double size); | ||
|
||
void resetModel(double size); | ||
void resetModelSphere(double size); | ||
void updateModel(double size); | ||
|
||
QString getModelPath() const; | ||
void loadModel(std::string const& path); | ||
void loadModel(QString const& path); | ||
|
||
/** When using the default body, sets the size of the main sphere, | ||
* relative to the size of the complete object | ||
* | ||
* The default is 0.1 | ||
*/ | ||
void setMainSphereSize(double size); | ||
|
||
/** When using one of the default bodies, returns the size of the main | ||
* sphere, relative to the size of the complete object | ||
* | ||
* The default is 0.1 | ||
*/ | ||
double getMainSphereSize() const; | ||
|
||
/** Sets the text size relative to the size of the complete object. | ||
* If text size is positive, the name of the source frame is rendered in the visualization. | ||
* The default is 0.0 | ||
*/ | ||
void setTextSize(double size); | ||
double getTextSize() const; | ||
|
||
/** Sets the color of the default body model in R, G, B | ||
* | ||
* Values must be between 0 and 1 | ||
* | ||
* If you call it after the plugin got attached, call resetModel to | ||
* apply the new color | ||
*/ | ||
void setColor(base::Vector3d const& color); | ||
|
||
void setColor(const osg::Vec4d& color, osg::Geode* geode); | ||
|
||
void setTexture(QString const& path); | ||
void setTexture(std::string const& path); | ||
void clearTexture(); | ||
void addBumpMapping( | ||
QString const& diffuse_color_map_path, | ||
QString const& normal_map_path); | ||
void addBumpMapping( | ||
std::string const& diffuse_color_map_path, | ||
std::string const& normal_map_path); | ||
void removeBumpMapping(); | ||
|
||
QVector3D getTranslation() const; | ||
void setTranslation(QVector3D const& v); | ||
void setRotation(QQuaternion const& q); | ||
|
||
void setSeperateAxes(bool val = true) { | ||
show_seperate_axes = val; | ||
emit propertyChanged("showSeperateAxes"); | ||
updateModel(total_size); | ||
} | ||
bool isSeperateAxes() const { | ||
return show_seperate_axes; | ||
} | ||
void setResolution(double res) { | ||
resolution = res; | ||
emit propertyChanged("resolution"); | ||
updateModel(total_size); | ||
} | ||
double getResolution() const { | ||
return resolution; | ||
} | ||
|
||
private: | ||
base::Vector3d color; | ||
double total_size; | ||
double main_size; | ||
double text_size; | ||
|
||
osg::Vec3 translation; | ||
osg::Quat rotation; | ||
|
||
enum BODY_TYPES | ||
{ BODY_NONE, BODY_SIMPLE, BODY_SPHERE, BODY_CUSTOM_MODEL }; | ||
|
||
BODY_TYPES body_type; | ||
osg::ref_ptr<osg::Node> body_model; | ||
osg::ref_ptr<osg::Group> createSimpleBody(double size); | ||
osg::ref_ptr<osg::Group> createSimpleSphere(double size); | ||
|
||
osg::ref_ptr<osg::Image> image; | ||
osg::ref_ptr<osg::Texture2D> texture; | ||
bool texture_dirty; | ||
void updateTexture(); | ||
|
||
osg::ref_ptr<osg::Image> diffuse_image; | ||
osg::ref_ptr<osg::Image> normal_image; | ||
osg::ref_ptr<osg::Texture2D> diffuse_texture; | ||
osg::ref_ptr<osg::Texture2D> normal_texture; | ||
osg::ref_ptr<osgFX::BumpMapping> bump_mapping; | ||
bool bump_mapping_dirty; | ||
void updateBumpMapping(); | ||
|
||
osg::ref_ptr<osg::PositionAttitudeTransform> linear_vel_transform, angular_vel_transform; | ||
osg::ref_ptr<osg::PositionAttitudeTransform> linear_acc_transform, angular_acc_transform; | ||
osg::ref_ptr<WrenchModel> wrench_model; | ||
|
||
bool forcePositionDisplay; | ||
bool forceOrientationDisplay; | ||
|
||
bool showPose; | ||
bool showVelocity; | ||
bool showAcceleration; | ||
bool showWrench; | ||
bool show_seperate_axes; | ||
double resolution; | ||
|
||
QString model_path; | ||
|
||
std::shared_ptr<osgviz::PrimitivesFactory> primitivesfactory; | ||
|
||
}; | ||
|
||
} | ||
#endif // ROBOT_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include "WrenchModel.hpp" | ||
|
||
WrenchModel::WrenchModel(double resolution) | ||
: show_seperate_axes_force(false) | ||
, show_seperate_axes_torque(false) | ||
, resolution(resolution) | ||
{ | ||
primitivesfactory = osgviz::OsgViz::getModuleInstance<osgviz::PrimitivesFactory>("PrimitivesFactory"); | ||
if (!primitivesfactory) { | ||
std::cerr << "Could not load PrimitivesFactory" << std::endl; | ||
return; | ||
} | ||
buildGeometry(); | ||
} | ||
|
||
osg::ref_ptr<osg::PositionAttitudeTransform> WrenchModel::createCircularArrow(const osg::Vec4f& color) { | ||
osg::ref_ptr<osg::PositionAttitudeTransform> arr = primitivesfactory->createCircularArrow(0.1, 0.02, 12, 32, 1.5*M_PI, 2.0, color); | ||
return arr; | ||
} | ||
|
||
|
||
void WrenchModel::buildGeometry() { | ||
// force | ||
force_node = primitivesfactory->createArrow(osg::Vec4f(1, 0, 0, 1.0), true); | ||
addChild(force_node, true); // child 0 | ||
|
||
// torque | ||
torque_group = new osg::Group; | ||
|
||
torque_group->addChild(primitivesfactory->createArrow(osg::Vec4f(0, 1, 0, 1.0), true)); | ||
torque_group->addChild(createCircularArrow(osg::Vec4f(0, 1, 0, 1.0))); | ||
addChild(torque_group, true); // child 1 | ||
|
||
// seperated along axes | ||
force_axes_group = new osg::Switch; | ||
torque_axes_group = new osg::Switch; | ||
|
||
for (unsigned int i=0; i<3; ++i) { | ||
//add force axis | ||
force_axes_group->addChild(primitivesfactory->createArrow(osg::Vec4f(1, 0, 0, 1.0), true), true); | ||
|
||
//add torque axis | ||
osg::ref_ptr<osg::Group> torque_axis_group = new osg::Group; | ||
torque_axis_group->addChild(primitivesfactory->createArrow(osg::Vec4f(0, 1, 0, 1.0), true)); | ||
torque_axis_group->addChild(createCircularArrow(osg::Vec4f(0, 1, 0, 1.0))); | ||
torque_axes_group->addChild(torque_axis_group, true); | ||
} | ||
|
||
addChild(force_axes_group, false); // child 2 | ||
addChild(torque_axes_group, false); // child 3 | ||
} | ||
|
||
void WrenchModel::update(const base::Wrench& wrench) { | ||
osg::Matrixd R, S; | ||
osg::Quat Q; | ||
|
||
if (show_seperate_axes_force) { | ||
// for all axes | ||
for (unsigned int i=0; i<3; ++i) { | ||
if (wrench.force[i] == 0) { | ||
// if component is zero, disable | ||
force_axes_group->setValue(i, false); | ||
} | ||
else { | ||
//update transform | ||
osg::PositionAttitudeTransform* force_transform = dynamic_cast<osg::PositionAttitudeTransform*>(force_axes_group->getChild(i)); | ||
osg::Vec3d force(0,0,0); | ||
force[i] = wrench.force[i]; | ||
Q.makeRotate(osg::Vec3d(0,0,1), force); | ||
force_transform->setScale(osg::Vec3f(resolution, resolution, resolution*force.length())); | ||
force_transform->setAttitude(Q); | ||
force_axes_group->setChildValue(force_transform, true); | ||
} | ||
} | ||
} | ||
else { | ||
if (wrench.force.isZero()) { | ||
// if force is zero vector, disable | ||
setChildValue(force_node, false); | ||
} | ||
else { | ||
// update transform | ||
osg::Vec3d force(wrench.force.x(), wrench.force.y(), wrench.force.z()); | ||
Q.makeRotate(osg::Vec3d(0,0,1), force); | ||
//force_node->setScale(osg::Vec3f(resolution, resolution, resolution*force.length())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't commit commented-out code. If it is commented out, it's not part of the implementation and just adds noise. |
||
|
||
osgviz::ArrowNode* f_node = dynamic_cast<osgviz::ArrowNode*>(force_node.get()); | ||
f_node->setLength(resolution*force.length()); | ||
force_node->setAttitude(Q); | ||
|
||
setChildValue(force_node, true); | ||
} | ||
} | ||
|
||
if (show_seperate_axes_torque) { | ||
for (unsigned int i=0; i<3; ++i) { | ||
if (wrench.torque[i] == 0) { | ||
torque_axes_group->setValue(i, false); | ||
} | ||
else { | ||
osg::Group* group = dynamic_cast<osg::Group*>(torque_axes_group->getChild(i)); | ||
osg::PositionAttitudeTransform* torque_vec_transform = dynamic_cast<osg::PositionAttitudeTransform*>(group->getChild(0)); | ||
osg::Vec3d torque(0,0,0); | ||
torque[i] = wrench.torque[i]; | ||
Q.makeRotate(osg::Vec3d(0,0,1), torque); | ||
torque_vec_transform->setScale(osg::Vec3f(resolution, resolution, resolution * torque.length())); | ||
torque_vec_transform->setAttitude(Q); | ||
|
||
osg::PositionAttitudeTransform* torque_transform = dynamic_cast<osg::PositionAttitudeTransform*>(group->getChild(1)); | ||
torque_transform->setAttitude(Q); | ||
torque_transform->setPosition(torque * 0.4 * resolution); | ||
//torque_transform->setScale(osg::Vec3f(resolution,resolution,resolution)); | ||
torque_axes_group->setValue(i, true); | ||
} | ||
} | ||
} | ||
else { | ||
if (wrench.torque.isZero()) { | ||
// if torque is zero vector, disable | ||
setChildValue(torque_group, false); | ||
} | ||
else { | ||
// update transform | ||
osgviz::ArrowNode* torque_vec_transform = dynamic_cast<osgviz::ArrowNode*>(torque_group->getChild(0)); | ||
osg::Vec3d torque(wrench.torque.x(), wrench.torque.y(), wrench.torque.z()); | ||
Q.makeRotate(osg::Vec3d(0,0,1), torque); | ||
torque_vec_transform->setLength(resolution*torque.length()); | ||
torque_vec_transform->setAttitude(Q); | ||
|
||
osg::PositionAttitudeTransform* torque_transform = dynamic_cast<osg::PositionAttitudeTransform*>(torque_group->getChild(1)); | ||
torque_transform->setAttitude(Q); | ||
torque_transform->setPosition(torque * 0.4 * resolution); | ||
setChildValue(torque_group, true); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef WRENCHMODEL_HPP | ||
#define WRENCHMODEL_HPP | ||
|
||
#include <osg/Switch> | ||
#include <base/samples/Wrench.hpp> | ||
|
||
#include <osgViz/OsgViz.hpp> | ||
#include <osgViz/modules/viz/Primitives/PrimitivesFactory.h> | ||
#include <osgViz/modules/viz/Primitives/Primitives/ArrowNode.h> | ||
|
||
class WrenchModel : public osg::Switch { | ||
|
||
public: | ||
WrenchModel(double resolution = 1.0); | ||
~WrenchModel() {} | ||
|
||
void update(const base::Wrench& wrench); | ||
|
||
void seperateAxes(bool val = true) { | ||
seperateAxesForce(val); | ||
seperateAxesTorque(val); | ||
} | ||
void seperateAxesForce(bool val=true) { | ||
show_seperate_axes_force = val; | ||
setChildValue(force_node, !val); | ||
setChildValue(force_axes_group, val); | ||
} | ||
void seperateAxesTorque(bool val=true) { | ||
show_seperate_axes_torque = val; | ||
setChildValue(torque_group, !val); | ||
setChildValue(torque_axes_group, val); | ||
} | ||
void setResolution(double res) { | ||
resolution = res; | ||
} | ||
|
||
protected: | ||
//osg::ref_ptr<osg::Switch> model; | ||
|
||
osg::ref_ptr<osg::PositionAttitudeTransform> createCircularArrow(const osg::Vec4f& color); | ||
void buildGeometry(); | ||
|
||
bool show_seperate_axes_force; | ||
bool show_seperate_axes_torque; | ||
double resolution; | ||
|
||
osg::ref_ptr<osgviz::Object> force_node; | ||
osg::ref_ptr<osg::Group> torque_group; | ||
osg::ref_ptr<osg::Switch> force_axes_group, torque_axes_group; | ||
|
||
std::shared_ptr<osgviz::PrimitivesFactory> primitivesfactory; | ||
|
||
private: | ||
|
||
|
||
}; | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <iostream> | ||
#include "WrenchVisualization.hpp" | ||
|
||
using namespace vizkit3d; | ||
|
||
WrenchVisualization::WrenchVisualization() | ||
: text_size(0.1) | ||
, show_seperate_axes_force(false) | ||
, show_seperate_axes_torque(false) | ||
, resolution(1.0) | ||
{ | ||
wrench_model = new WrenchModel(resolution); | ||
} | ||
|
||
WrenchVisualization::~WrenchVisualization() | ||
{ | ||
} | ||
|
||
osg::ref_ptr<osg::Node> WrenchVisualization::createMainNode() | ||
{ | ||
return wrench_model; | ||
} | ||
|
||
double WrenchVisualization::getTextSize() const | ||
{ | ||
return text_size; | ||
} | ||
|
||
void WrenchVisualization::setTextSize(double size) | ||
{ | ||
text_size = size; | ||
text->setCharacterSize(text_size); | ||
emit propertyChanged("textSize"); | ||
setDirty(); | ||
} | ||
|
||
void WrenchVisualization::updateMainNode ( osg::Node* node ) | ||
{ | ||
// WrenchModel* wrench_model = dynamic_cast<WrenchModel*>(node); | ||
// if (wrench_model) { | ||
// wrench_model->seperateAxes(show_seperate_axes); | ||
// wrench_model->setResolution(resolution); | ||
// wrench_model->update(state); | ||
// } | ||
if (state.isValid()) | ||
wrench_model->update(state); | ||
} | ||
|
||
void WrenchVisualization::updateDataIntern(const base::Wrench& value) | ||
{ | ||
state.force = value.force; | ||
state.torque = value.torque; | ||
} | ||
|
||
void WrenchVisualization::updateDataIntern(const base::samples::Wrench& value) | ||
{ | ||
state = value; | ||
} | ||
|
||
//Macro that makes this plugin loadable in ruby, this is optional. | ||
//VizkitQtPlugin(WrenchVisualization) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef teleop_mapping_WrenchVisualization_H | ||
#define teleop_mapping_WrenchVisualization_H | ||
|
||
#include <boost/noncopyable.hpp> | ||
#include <vizkit3d/Vizkit3DPlugin.hpp> | ||
#include <osg/Geode> | ||
#include <base/samples/Wrench.hpp> | ||
#include <osgText/Text> | ||
#include <osg/Switch> | ||
#include <osg/AnimationPath> | ||
#include "WrenchModel.hpp" | ||
|
||
namespace vizkit3d | ||
{ | ||
class WrenchVisualization | ||
: public vizkit3d::Vizkit3DPlugin<base::samples::Wrench> | ||
, public vizkit3d::VizPluginAddType<base::Wrench> | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(double textSize READ getTextSize WRITE setTextSize) | ||
Q_PROPERTY(bool showForceSeperateAxes READ isSeperateAxesForce WRITE setSeperateAxesForce) | ||
Q_PROPERTY(bool showTorqueSeperateAxes READ isSeperateAxesTorque WRITE setSeperateAxesTorque) | ||
Q_PROPERTY(double resolution READ getResolution WRITE setResolution) | ||
public: | ||
WrenchVisualization(); | ||
~WrenchVisualization(); | ||
|
||
Q_INVOKABLE void updateData(base::samples::Wrench const &sample) | ||
{vizkit3d::Vizkit3DPlugin<base::samples::Wrench>::updateData(sample);} | ||
|
||
Q_INVOKABLE void updateData(base::Wrench const &sample) | ||
{vizkit3d::Vizkit3DPlugin<base::samples::Wrench>::updateData(sample);} | ||
|
||
Q_INVOKABLE void setForce(const base::Vector3d& f) { | ||
state.force = f; | ||
} | ||
|
||
Q_INVOKABLE void setTorque(const base::Vector3d& t) { | ||
state.torque = t; | ||
} | ||
|
||
public slots: | ||
/** Sets the text size relative to the size of the complete object. | ||
* If text size is positive, the name of the source frame is rendered in the visualization. | ||
* The default is 0.0 | ||
*/ | ||
void setTextSize(double size); | ||
double getTextSize() const; | ||
|
||
void setSeperateAxesForce(bool val = true) { | ||
show_seperate_axes_force = val; | ||
emit propertyChanged("showForceSeperateAxes"); | ||
wrench_model->seperateAxesForce(val); | ||
setDirty(); | ||
} | ||
bool isSeperateAxesForce() const { | ||
return show_seperate_axes_force; | ||
} | ||
void setSeperateAxesTorque(bool val = true) { | ||
show_seperate_axes_torque = val; | ||
emit propertyChanged("showTorqueSeperateAxes"); | ||
wrench_model->seperateAxesTorque(val); | ||
setDirty(); | ||
} | ||
bool isSeperateAxesTorque() const { | ||
return show_seperate_axes_torque; | ||
} | ||
void setResolution(double res) { | ||
resolution = res; | ||
emit propertyChanged("resolution"); | ||
wrench_model->setResolution(res); | ||
setDirty(); | ||
} | ||
double getResolution() const { | ||
return resolution; | ||
} | ||
|
||
protected: | ||
virtual osg::ref_ptr<osg::Node> createMainNode(); | ||
virtual void updateMainNode(osg::Node* node); | ||
virtual void updateDataIntern( const base::Wrench& wrench ); | ||
virtual void updateDataIntern( const base::samples::Wrench& wrench ); | ||
|
||
private: | ||
base::samples::Wrench state; | ||
osg::ref_ptr<WrenchModel> wrench_model; | ||
osg::ref_ptr<osgText::Text> text; | ||
double text_size; | ||
bool show_seperate_axes_force; | ||
bool show_seperate_axes_torque; | ||
double resolution; | ||
|
||
// public slots: | ||
// void setForce(const base::Vector3d& f) { | ||
// state.force = f; | ||
// } | ||
|
||
// void setTorque(const base::Vector3d& t) { | ||
// state.torque = t; | ||
// } | ||
|
||
}; | ||
} | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really believe we should consider other alternatives before adding
osgViz
as a "hard" dependency inbase/types
.This is also breaking rock-core's build.
@doudou
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, base/types already depends on
gui/vizkit3d
which depends on osgViz. The (optional) dependency should definitely be explicitly added to the manifest, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that will be a problem in constrained environments (i.e embedded computers running iodrivers_base based drivers). Can we please don't do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keyword was optional ;-). The dependency on osgViz that this PR adds is also optional as the whole
viz/
folder is disabled by the Rock CMake macros if vizkit3d is not available or if ROCK_VIZ_ENABLED is set to OFF.base/types already depends optionally on
gui/vizkit3d
. In constrained environments, you usually excludegui/.*
which removes that particular dependencyUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that, sorry. I guess I was misled by the breaking build (which is probably breaking for some other reason I didn't look into). Did this pass on your CI?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is when building
base/types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what PrimitivesFactory is or where it comes from. I was looking at osgViz since it was what you mentioned in your comment.
Didn't check CI yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrimitivesFactory is a module in osgViz