Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::Window Class Reference

Open Scene Graph GUI for DART visualization. More...

#include <gui.h>

+ Inheritance diagram for robowflex::darts::Window:

Classes

struct  DnDReturn
 Return from creating a movable frame. More...
 
struct  InteractiveOptions
 Options for creating an interactive marker. More...
 
struct  InteractiveReturn
 Return from creating an interactive marker. More...
 

Public Member Functions

 Window (const WorldPtr &world)
 Constructor. More...
 
void customPreRefresh () override
 
void customPostRefresh () override
 
void run (std::function< void()> thread={})
 Run the GUI. Blocks. More...
 
WindowWidgetPtr getWidget ()
 Get the IMGUI configurable widget. More...
 
void addWidget (const WidgetPtr &widget)
 Add a new IMGUI widget. More...
 
WorldPtr getWorld ()
 Get world used for visualization. More...
 
const WorldPtrgetWorldConst () const
 Get world used for visualization. More...
 
Animation
void animatePath (const StateSpacePtr &space, const ompl::geometric::PathGeometric &path, std::size_t times=1, double fps=60, bool block=true)
 Animate a motion plan using the world. More...
 
void animatePath (const PlanBuilder &builder, const ompl::geometric::PathGeometric &path, std::size_t times=1, double fps=60, bool block=true)
 Animate a motion plan using the world. This version of the call will automatically visualize either constrained or unconstrained paths. More...
 

Private Attributes

friend TSREditWidget
 
WorldPtr world_
 World to visualize. More...
 
WindowWidgetPtr widget_
 IMGUI widget. More...
 
std::vector< WidgetPtr > widgets_
 Other widgets;. More...
 
std::shared_ptr< std::threadanimation_ {nullptr}
 Animation thread. More...
 
::osg::ref_ptr< Windownode_
 OSG Node. More...
 
Viewer viewer_
 Viewer. More...
 

GUI Interaction

using InteractiveCallback = std::function< void(const dart::gui::osg::InteractiveFrame *)>
 Callback function on an interactive frame moving. More...
 
using DnDCallback = std::function< void(const dart::dynamics::BodyNode *)>
 Callback function on a drag 'n drop frame moving. More...
 
InteractiveReturn createInteractiveMarker (const InteractiveOptions &options)
 Create a new interactive marker in the GUI. More...
 
DnDReturn enableNodeDragNDrop (dart::dynamics::BodyNode *node, const DnDCallback &callback={})
 Enable drag 'n drop functionality on a body node being visualized. With DnD, the body node will automatically use IK to move wherever dragged. More...
 

Detailed Description

Open Scene Graph GUI for DART visualization.

Definition at line 66 of file gui.h.

Member Typedef Documentation

◆ DnDCallback

using robowflex::darts::Window::DnDCallback = std::function<void(const dart::dynamics::BodyNode *)>

Callback function on a drag 'n drop frame moving.

Definition at line 135 of file gui.h.

◆ InteractiveCallback

using robowflex::darts::Window::InteractiveCallback = std::function<void(const dart::gui::osg::InteractiveFrame *)>

Callback function on an interactive frame moving.

Definition at line 83 of file gui.h.

Constructor & Destructor Documentation

◆ Window()

Window::Window ( const WorldPtr world)

Constructor.

Parameters
[in]worldWorld to visualize.

Definition at line 76 of file gui.cpp.

77  : dart::gui::osg::WorldNode(world->getSim()), world_(world), viewer_(world)
78 {
79  node_ = this;
80  viewer_.addWorldNode(node_);
81  viewer_.setUpViewInWindow(0, 0, 1080, 720);
82  auto *cm = viewer_.getCameraManipulator();
83  cm->setHomePosition( //
84  ::osg::Vec3(5.00, 5.00, 2.00), //
85  ::osg::Vec3(0.00, 0.00, 0.00), //
86  ::osg::Vec3(-0.24, -0.25, 0.94));
87  viewer_.setCameraManipulator(cm);
88  viewer_.setVerticalFieldOfView(15);
89 
90  widget_ = std::make_shared<WindowWidget>();
92 }
Viewer viewer_
Viewer.
Definition: gui.h:213
WindowWidgetPtr widget_
IMGUI widget.
Definition: gui.h:207
::osg::ref_ptr< Window > node_
OSG Node.
Definition: gui.h:212
void addWidget(const WidgetPtr &widget)
Add a new IMGUI widget.
Definition: gui.cpp:106
WorldPtr world_
World to visualize.
Definition: gui.h:206

Member Function Documentation

◆ addWidget()

void Window::addWidget ( const WidgetPtr &  widget)

Add a new IMGUI widget.

Parameters
[in]widgetWidget to add.

Definition at line 106 of file gui.cpp.

107 {
108  widgets_.emplace_back(widget);
109  widget->initialize(const_cast<Window *>(this));
110  viewer_.getImGuiHandler()->addWidget(widget);
111 }
Open Scene Graph GUI for DART visualization.
Definition: gui.h:67
std::vector< WidgetPtr > widgets_
Other widgets;.
Definition: gui.h:208
T emplace_back(T... args)

◆ animatePath() [1/2]

void Window::animatePath ( const PlanBuilder builder,
const ompl::geometric::PathGeometric &  path,
std::size_t  times = 1,
double  fps = 60,
bool  block = true 
)

Animate a motion plan using the world. This version of the call will automatically visualize either constrained or unconstrained paths.

Parameters
[in]builderPlan builder structure.
[in]pathThe plan to visualize.
[in]timesNumber of times to loop through animation.
[in]fpsUpdate rate.
[in]blockIf true, blocks until animation is done. Otherwise, immediately returns.

Definition at line 206 of file gui.cpp.

208 {
209  ompl::geometric::PathGeometric extract(builder.rinfo);
210  for (std::size_t i = 0; i < path.getStateCount(); ++i)
211  extract.append(builder.toStateConst(path.getState(i)));
212 
213  animatePath(builder.rspace, extract, times, fps, block);
214 }
const StateSpace::StateType * toStateConst(const ompl::base::State *state) const
Extract underlying state from a base state.
StateSpacePtr rspace
Underlying Robot State Space.
ompl::base::SpaceInformationPtr rinfo
Underlying Space Information.
void animatePath(const StateSpacePtr &space, const ompl::geometric::PathGeometric &path, std::size_t times=1, double fps=60, bool block=true)
Animate a motion plan using the world.
Definition: gui.cpp:160

◆ animatePath() [2/2]

void Window::animatePath ( const StateSpacePtr space,
const ompl::geometric::PathGeometric &  path,
std::size_t  times = 1,
double  fps = 60,
bool  block = true 
)

Animate a motion plan using the world.

Parameters
[in]spaceState space of the plan.
[in]pathThe plan to visualize.
[in]timesNumber of times to loop through animation.
[in]fpsUpdate rate.
[in]blockIf true, blocks until animation is done. Otherwise, immediately returns.

Definition at line 160 of file gui.cpp.

162 {
163  bool active = true;
164 
165  std::mutex m;
167 
168  if (animation_)
169  {
170  animation_->join();
171  animation_.reset();
172  }
173  auto thread = std::make_shared<std::thread>([&] {
174  std::size_t n = path.getStateCount();
175  std::size_t i = times;
176 
178  while ((times == 0) ? true : i--)
179  {
180  space->setWorldState(world_, path.getState(0));
182 
183  for (std::size_t j = 0; j < n; ++j)
184  {
185  space->setWorldState(world_, path.getState(j));
186 
187  std::this_thread::sleep_for(std::chrono::milliseconds((unsigned int)(1000 / fps)));
188  }
189 
191  }
192 
193  active = false;
194  cv.notify_one();
195  });
196 
197  animation_ = thread;
198 
199  if (block)
200  {
202  cv.wait(lk, [&] { return not active; });
203  }
204 }
std::shared_ptr< std::thread > animation_
Animation thread.
Definition: gui.h:210
T reset(T... args)
T sleep_for(T... args)

◆ createInteractiveMarker()

Window::InteractiveReturn Window::createInteractiveMarker ( const InteractiveOptions options)

Create a new interactive marker in the GUI.

Parameters
[in]optionsOptions for creating marker.
Returns
The new marker.

Definition at line 113 of file gui.cpp.

114 {
115  InteractiveReturn r;
116  r.target = std::make_shared<dart::gui::osg::InteractiveFrame>( //
117  options.parent, options.name, options.pose, options.size, options.thickness);
118  world_->getSim()->addSimpleFrame(r.target);
119 
120  for (std::size_t i = 0; i < 3; ++i)
121  {
122  auto *lt = r.target->getTool(dart::gui::osg::InteractiveTool::Type::LINEAR, i);
123  lt->setEnabled(options.linear[i]);
124  auto *rt = r.target->getTool(dart::gui::osg::InteractiveTool::Type::ANGULAR, i);
125  rt->setEnabled(options.rotation[i]);
126  auto *pt = r.target->getTool(dart::gui::osg::InteractiveTool::Type::PLANAR, i);
127  pt->setEnabled(options.planar[i]);
128  }
129 
130  r.dnd = viewer_.enableDragAndDrop(r.target.get());
131  r.dnd->setObstructable(options.obstructable);
132 
133  auto callback = options.callback;
134  r.signal = r.target->onTransformUpdated.connect([callback](const dart::dynamics::Entity *entity) {
135  if (entity)
136  {
137  const auto *cast = dynamic_cast<const dart::gui::osg::InteractiveFrame *>(entity);
138  if (cast and callback)
139  callback(cast);
140  }
141  });
142 
143  return r;
144 }
void callback(movegroup::MoveGroupHelper::Action &action)
Definition: tapedeck.cpp:20

◆ customPostRefresh()

void Window::customPostRefresh ( )
override

Definition at line 101 of file gui.cpp.

102 {
103  // world_->unlock();
104 }

◆ customPreRefresh()

void Window::customPreRefresh ( )
override

Definition at line 94 of file gui.cpp.

95 {
96  // world_->lock();
97  for (const auto &widget : widgets_)
98  widget->prerefresh();
99 }

◆ enableNodeDragNDrop()

Window::DnDReturn Window::enableNodeDragNDrop ( dart::dynamics::BodyNode *  node,
const DnDCallback callback = {} 
)

Enable drag 'n drop functionality on a body node being visualized. With DnD, the body node will automatically use IK to move wherever dragged.

Parameters
[in]nodeNode to enable Drag 'n Drop on.
[in]callbackCallback function to call when node is dragged.
Returns
The new drag 'n drop node.

Definition at line 146 of file gui.cpp.

147 {
148  DnDReturn r;
149  auto *dnd = viewer_.enableDragAndDrop(node, true, true);
150  r.dnd = dnd;
151 
152  r.signal = node->onTransformUpdated.connect([dnd, callback](const dart::dynamics::Entity *entity) {
153  if (dnd->isMoving())
154  callback(dynamic_cast<const dart::dynamics::BodyNode *>(entity));
155  });
156 
157  return r;
158 }

◆ getWidget()

WindowWidgetPtr Window::getWidget ( )

Get the IMGUI configurable widget.

Definition at line 216 of file gui.cpp.

217 {
218  return widget_;
219 }

◆ getWorld()

WorldPtr Window::getWorld ( )

Get world used for visualization.

Returns
World used by window.

Definition at line 221 of file gui.cpp.

222 {
223  return world_;
224 }

◆ getWorldConst()

const WorldPtr & Window::getWorldConst ( ) const

Get world used for visualization.

Returns
World used by window.

Definition at line 226 of file gui.cpp.

227 {
228  return world_;
229 }

◆ run()

void Window::run ( std::function< void()>  thread = {})

Run the GUI. Blocks.

Parameters
[in]threadFunction to run in a separate thread from the GUI's visualization.

Definition at line 231 of file gui.cpp.

232 {
233  if (thread)
234  {
235  std::thread t(thread);
236  viewer_.run();
237  }
238  else
239  viewer_.run();
240 }

Member Data Documentation

◆ animation_

std::shared_ptr<std::thread> robowflex::darts::Window::animation_ {nullptr}
private

Animation thread.

Definition at line 210 of file gui.h.

◆ node_

::osg::ref_ptr<Window> robowflex::darts::Window::node_
private

OSG Node.

Definition at line 212 of file gui.h.

◆ TSREditWidget

friend robowflex::darts::Window::TSREditWidget
private

Definition at line 68 of file gui.h.

◆ viewer_

Viewer robowflex::darts::Window::viewer_
private

Viewer.

Definition at line 213 of file gui.h.

◆ widget_

WindowWidgetPtr robowflex::darts::Window::widget_
private

IMGUI widget.

Definition at line 207 of file gui.h.

◆ widgets_

std::vector<WidgetPtr> robowflex::darts::Window::widgets_
private

Other widgets;.

Definition at line 208 of file gui.h.

◆ world_

WorldPtr robowflex::darts::Window::world_
private

World to visualize.

Definition at line 206 of file gui.h.


The documentation for this class was generated from the following files: