2 #include <openrave/openrave.h>
3 #include <osg/Geometry>
4 #include <osgViewer/Viewer>
5 #include <boost/function.hpp>
6 #include <osgGA/TrackballManipulator>
8 typedef OpenRAVE::RaveVector<float> RaveVectorf;
13 class TRAJOPT_API
OSGViewer :
public OpenRAVE::ViewerBase {
16 static boost::shared_ptr<OSGViewer> GetOrCreate(OpenRAVE::EnvironmentBasePtr env);
17 OSGViewer(OpenRAVE::EnvironmentBasePtr env);
19 virtual int main(
bool bShow =
true);
20 virtual void quitmainloop() {}
21 void RemoveKinBody(OpenRAVE::KinBodyPtr pbody);
24 void UpdateSceneData();
25 const std::string& GetName()
const {
return m_name;}
26 void SetBkgndColor(
const RaveVectorf &) {printf(
"warning: SetBkgndColor not implemented\n");}
30 typedef boost::function<bool(const osgGA::GUIEventAdapter &)> MouseCallback;
31 void AddMouseCallback(
const MouseCallback& cb);
32 typedef boost::function<void(const osgGA::GUIEventAdapter &)> KeyCallback;
33 void AddKeyCallback(
int key,
const KeyCallback& cb,
const std::string& help=
"");
36 OpenRAVE::GraphHandlePtr drawarrow(
const RaveVectorf& p1,
const RaveVectorf& p2,
float fwidth,
const RaveVectorf& color);
37 OpenRAVE::GraphHandlePtr drawtrimesh (
const float *ppoints,
int stride,
const int *pIndices,
int numTriangles,
const RaveVectorf &color);
39 OpenRAVE::GraphHandlePtr plot3 (
const float *ppoints,
int numPoints,
int stride,
float fPointSize,
const OpenRAVE::RaveVector< float > &color,
int drawstyle=0);
40 OpenRAVE::GraphHandlePtr plot3(
const float* ppoints,
int numPoints,
int stride,
float pointsize,
const float* colors,
int drawstyle=0,
bool bhasalpha=
false);
41 OpenRAVE::GraphHandlePtr drawlinelist(
const float *ppoints,
int numPoints,
int stride,
float fwidth,
const RaveVectorf &color);
42 OpenRAVE::GraphHandlePtr drawlinestrip(
const float *ppoints,
int numPoints,
int stride,
float fwidth,
const RaveVectorf &color);
43 OpenRAVE::GraphHandlePtr _drawlines(osg::PrimitiveSet::Mode mode,
const float *ppoints,
int numPoints,
int stride,
float fwidth,
const RaveVectorf &color);
44 OpenRAVE::GraphHandlePtr drawtext(
const std::string& text,
float x,
float y,
float fontsize,
const OpenRAVE::Vector& color);
46 void SetAllTransparency(
float alpha);
47 void SetTransparency(OpenRAVE::KinBodyPtr,
float alpha);
49 OpenRAVE::GraphHandlePtr PlotAxes(
const OpenRAVE::Transform& T,
float size);
50 OpenRAVE::GraphHandlePtr PlotSphere(
const OpenRAVE::Vector& x,
float radius);
53 OpenRAVE::GraphHandlePtr PlotKinBody(
const OpenRAVE::KinBodyPtr);
54 OpenRAVE::GraphHandlePtr PlotLink(
const OpenRAVE::KinBody::LinkPtr);
57 typedef std::map<int, OSGViewer::KeyCallback> KeyCallbackMap;
58 std::vector<MouseCallback> event_cbs;
59 KeyCallbackMap key_cbs;
60 typedef std::map<int, std::string> Key2Desc;
62 bool handle(
const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa);
66 osg::ref_ptr<EventHandler> m_handler;
67 osg::ref_ptr<osg::Group> m_root;
71 osg::ref_ptr<osg::Camera> m_cam, m_hudcam;
72 osgViewer::Viewer m_viewer;
73 bool m_idling, m_request_stop_idling;
78 typedef boost::shared_ptr<OSGViewer> OSGViewerPtr;
81 void TRAJOPT_API SetColor(OpenRAVE::GraphHandlePtr handle,
const osg::Vec4& color);
82 void TRAJOPT_API SetTransparency(OpenRAVE::GraphHandlePtr handle,
float alpha);