Skip to content

Commit b6e068a

Browse files
author
Alexander Duda
committed
update tutorial to the new plugin mechanism
1 parent 2d37d77 commit b6e068a

4 files changed

Lines changed: 31 additions & 25 deletions

File tree

scripts/vizkit.plugin.tutorial.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
require 'vizkit'
2-
require 'Qt4'
3-
require 'vizkittypelib'
4-
include Orocos
52
Orocos.initialize
63

7-
# create an instance of the vizkit main window
8-
# alternatively vizkit::QVizkitWidget could also be used
9-
widget = Vizkit.default_loader.create_widget("vizkit::QVizkitMainWindow")
10-
plugin = widget.createPlugin("vizkit3d_plugin_tutorial", "SphereVisualization")
4+
#register plugin
5+
Vizkit.default_loader.register_3d_plugin 'SphereViz',
6+
'vizkit3d_plugin_tutorial', 'SphereVisualization'
7+
8+
#create plugin
9+
plugin = Vizkit.default_loader.SphereViz
1110

1211
# use a configuration method of the plugin to set the transparency of the sphere
13-
plugin.setTransparency(1.0)
12+
plugin.Transparency = 1.0
1413

1514
# create an instance of the base type Vectro3d
1615
position = Types::Base::Vector3d.new
@@ -31,6 +30,4 @@
3130

3231
# start the timer with a timeout of 10 ms
3332
timer.start(10)
34-
35-
widget.show
3633
Vizkit.exec

viz/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
rock_vizkit_plugin(vizkit3d_plugin_tutorial-viz
22
SphereVisualization.cpp
33
DEPS vizkit3d_plugin_tutorial
4+
MOC SphereVisualization.hpp
45
HEADERS SphereVisualization.hpp)
56

viz/SphereVisualization.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "SphereVisualization.hpp"
22
#include <osg/Geometry>
3-
#include <osg/ShapeDrawable>
43

54
using namespace vizkit;
65

@@ -13,16 +12,8 @@ struct SphereVisualization::Data {
1312

1413

1514
SphereVisualization::SphereVisualization()
16-
: p(new Data), transparency(1.0)
15+
: transparency(1.0),p(new Data)
1716
{
18-
/* Makes a method updatePosition availabe on ruby side, which will call
19-
* the updateData method for the data type base::Vector3d.
20-
* This macro is optional. */
21-
VizPluginRubyAdapter(SphereVisualization, base::Vector3d, Position)
22-
23-
/* This macro makes the method 'setTransparency' with a float attribute
24-
* availabe in ruby, for configuration purposes */
25-
VizPluginRubyConfig(SphereVisualization, float, setTransparency)
2617
}
2718

2819
SphereVisualization::~SphereVisualization()
@@ -34,7 +25,7 @@ osg::ref_ptr<osg::Node> SphereVisualization::createMainNode()
3425
{
3526
// create a sphere with radius 0.5
3627
osg::ref_ptr<osg::Sphere> sp = new osg::Sphere(osg::Vec3d(0,0,0), 0.5);
37-
osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable(sp.get());
28+
sd = new osg::ShapeDrawable(sp.get());
3829
// set a color
3930
sd->setColor(osg::Vec4(0.0f, 0.59f, 0.59f, transparency));
4031
osg::ref_ptr<osg::Geode> spGeode = new osg::Geode();
@@ -58,9 +49,17 @@ void SphereVisualization::updateDataIntern(base::Vector3d const& value)
5849
p->data = value;
5950
}
6051

61-
void SphereVisualization::setTransparency(float f)
52+
void SphereVisualization::setTransparency(double f)
6253
{
6354
transparency = f;
55+
if(sd.valid())
56+
sd->setColor(osg::Vec4(0.0f, 0.59f, 0.59f, transparency));
57+
emit propertyChanged("Transparency");
58+
}
59+
60+
double SphereVisualization::getTransparency()
61+
{
62+
return transparency;
6463
}
6564

6665
//Macro that makes this plugin loadable in ruby, this is optional.

viz/SphereVisualization.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22
#define SphereVisualization_H
33

44
#include <boost/noncopyable.hpp>
5-
#include <vizkit/VizPlugin.hpp>
5+
#include <vizkit/Vizkit3DPlugin.hpp>
66
#include <osg/Geode>
77
#include <osg/PositionAttitudeTransform>
8+
#include <osg/ShapeDrawable>
89
#include <base/eigen.h>
910

1011
namespace vizkit
1112
{
1213
class SphereVisualization
13-
: public vizkit::VizPlugin<base::Vector3d>
14+
: public vizkit::Vizkit3DPlugin<base::Vector3d>
1415
, boost::noncopyable
1516
{
17+
Q_OBJECT
18+
Q_PROPERTY(double Transparency READ getTransparency WRITE setTransparency)
19+
1620
public:
1721
SphereVisualization();
1822
~SphereVisualization();
19-
void setTransparency(float f);
23+
void setTransparency(double f);
24+
double getTransparency();
25+
26+
Q_INVOKABLE void updatePosition(base::Vector3d const &value)
27+
{Vizkit3DPlugin<base::Vector3d>::updateData(value);}
2028

2129
protected:
2230
virtual osg::ref_ptr<osg::Node> createMainNode();
@@ -25,6 +33,7 @@ namespace vizkit
2533

2634
private:
2735
osg::ref_ptr<osg::PositionAttitudeTransform> spherePos;
36+
osg::ref_ptr<osg::ShapeDrawable> sd;
2837
float transparency;
2938
struct Data;
3039
Data* p;

0 commit comments

Comments
 (0)