29 #include "../Util/OrientationConversion.h"
30 #include "Inventor/draggers/SoDragger.h"
31 #include "Inventor/nodes/SoSeparator.h"
32 #include "VirtualRobot/Scene.h"
33 #include "VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h"
34 #include "VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h"
35 #include <Inventor/Qt/SoQt.h>
36 #include <Inventor/SoFullPath.h>
37 #include <Inventor/SoInteraction.h>
38 #include <Inventor/actions/SoLineHighlightRenderAction.h>
39 #include <Inventor/misc/SoContextHandler.h>
40 #include <Inventor/nodes/SoCube.h>
41 #include <Inventor/nodes/SoPickStyle.h>
42 #include <Inventor/nodes/SoTranslation.h>
43 #include <Inventor/sensors/SoTimerSensor.h>
45 #define ROBOT_UPDATE_TIMER_MS 333
47 #define AUTO_FOLLOW_UPDATE 50
58 robotUpdateSensor = NULL;
59 this->selectedWaypoint = 0;
60 this->wayPointCounter = 0;
61 this->viewer = std::shared_ptr<RobotViewer>(
new RobotViewer(widget));
62 camera = viewer->getCamera();
65 SoInteraction::init();
66 viewer->setGLRenderAction(
new SoLineHighlightRenderAction);
67 viewer->getRootNode()->addChild((SoNode*)manipulator);
68 manipulatorMoved =
false;
69 startUpCameraPositioningFlag =
true;
70 selected =
new SoSelection();
75 viewer->getRootNode()->addSelectionCallback(made_selection, viewer.get());
76 viewer->getRootNode()->addDeselectionCallback(unmade_selection, viewer.get());
77 viewer->getRootNode()->setPickFilterCallback(pickFilterCB, viewer.get(),
true);
78 viewer->getRootNode()->policy = SoSelection::SINGLE;
79 manipulator->addManipFinishCallback(manipFinishCallback,
this);
80 manipulator->addManipMovedCallback(manipMovedCallback,
this);
81 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
82 autoFollowSensor =
new SoTimerSensor(autoFollowSensorTimerCB,
this);
84 sensor_mgr->insertTimerSensor(autoFollowSensor);
85 viewer->getRootNode()->addChild((SoNode*)manipulator);
86 manipFinishCallback(
this, NULL);
96 while (transitions.getLength() != 0)
98 transitions.remove(0);
100 while (wayPoints.getLength() != 0)
104 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
105 sensor_mgr->removeTimerSensor(robotUpdateSensor);
106 sensor_mgr->removeTimerSensor(autoFollowSensor);
107 this->viewer->getRootNode()->removeAllChildren();
109 manipulator->addManipFinishCallback(NULL, NULL);
110 manipulator->addManipMovedCallback(NULL, NULL);
114 robotUpdateSensor = NULL;
115 autoFollowSensor = NULL;
131 if ((
robot) && (this->robot) && this->robot->getName() !=
robot->getName())
133 this->viewer->getRootNode()->removeAllChildren();
136 this->selectedWaypoint = 0;
137 viewer->getRootNode()->deselectAll();
139 manipulatorMoved =
false;
140 viewer->getRootNode()->addChild((SoNode*)manipulator);
142 SoPickStyle* unpickable =
new SoPickStyle();
143 unpickable->style = SoPickStyle::UNPICKABLE;
144 SoPickStyle* pickable =
new SoPickStyle();
145 pickable->style = SoPickStyle::SHAPE;
146 viewer->getRootNode()->addChild(unpickable);
148 this->robot->getVisualization<VirtualRobot::CoinVisualization>();
149 this->viewer->getRootNode()->addChild(robotViewerVisualization->getCoinVisualization());
150 RobotNodeSetPtr nodeset =
robot->getRobotNodeSet(selectedChain.toStdString());
152 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
153 sensor_mgr->removeTimerSensor(robotUpdateSensor);
154 robotUpdateSensor =
new SoTimerSensor(robotUpdateTimerCB,
this);
156 sensor_mgr->insertTimerSensor(robotUpdateSensor);
158 viewer->getRootNode()->addChild(pickable);
159 viewer->getRootNode()->addChild((SoNode*)manipulator);
160 manipulator->addManipFinishCallback(manipFinishCallback,
this);
161 manipulator->addManipMovedCallback(manipMovedCallback,
this);
170 scene->getVisualization<VirtualRobot::CoinVisualization>();
171 this->viewer->getRootNode()->addChild(sceneVisualization->getCoinVisualization());
176 Eigen::VectorXf pointAtA,
177 Eigen::VectorXf pointAtB)
179 camera->position.setValue(position[0], position[1], position[2]);
180 camera->pointAt(SbVec3f(pointAtA[0], pointAtA[1], pointAtA[2]),
181 SbVec3f(pointAtB[0], pointAtB[1], pointAtB[2]));
182 camera->viewAll(viewer->getRootNode(), SbViewportRegion());
191 VisualizationNodePtr node = this->factory->createCurve(transition,
false);
192 CoinVisualizationNodePtr visu = boost::dynamic_pointer_cast<CoinVisualizationNode>(node);
193 SoNode* newTransition = visu->getCoinVisualization();
194 viewer->getRootNode()->addChild(newTransition);
195 transitions.insert(newTransition,
index);
201 SoNode* toDelete = transitions[
index];
202 viewer->getRootNode()->removeChild(toDelete);
203 transitions.remove(
index);
208 std::vector<PoseBasePtr> transition)
211 VisualizationNodePtr node = this->factory->createCurve(transition,
true);
212 CoinVisualizationNodePtr visu = boost::dynamic_pointer_cast<CoinVisualizationNode>(node);
213 SoNode* newTransition = visu->getCoinVisualization();
214 viewer->getRootNode()->addChild(newTransition);
215 transitions.insert(newTransition,
index);
239 return this->selectedWaypoint;
250 PoseBasePtr waypoint,
258 Pose p =
Pose(waypoint->position, waypoint->orientation);
259 EndEffectorPtr eef = endEffectorRobot->getEndEffectors()[0];
260 endEffectorRobot->setGlobalPoseForRobotNode(eef->getTcp(), p.
toEigen());
261 eef->getTcp()->setGlobalPoseNoChecks(p.
toEigen());
263 newWaypoint = CoinVisualizationFactory::getCoinVisualization(
264 endEffectorRobot, SceneObject::VisualizationType::Full,
true);
268 SoCube* cube =
new SoCube();
272 SoTranslation* cubePoint =
new SoTranslation();
273 cubePoint->translation.setValue(waypoint->position->x / 1000.0,
274 waypoint->position->y / 1000.0,
275 waypoint->position->z / 1000.0);
276 SoSeparator* parent =
new SoSeparator();
277 parent->addChild(cubePoint);
278 parent->addChild(cube);
279 newWaypoint = parent;
282 const char*
c =
s.c_str();
283 newWaypoint->setName(SbName(
c));
284 std::string st = std::string(newWaypoint->getName().getString());
285 viewer->getRootNode()->addChild(newWaypoint);
286 viewer->getRootNode()->select(newWaypoint);
287 wayPoints.insert(newWaypoint,
index);
289 viewer->getRootNode()->deselectAll();
295 SoNode* toDelete = wayPoints[
index];
296 viewer->getRootNode()->removeChild(toDelete);
297 wayPoints.remove(
index);
298 viewer->getRootNode()->deselectAll();
304 while (wayPoints.getLength() != 0)
314 this->selectedWaypoint =
index;
315 refreshSelectedPoint();
332 manipulator->addManipFinishCallback(manipFinishCallback,
this);
333 manipulator->addManipMovedCallback(manipMovedCallback,
this);
360 while (transitions.getLength() != 0)
364 while (wayPoints.getLength() != 0)
373 std::shared_ptr<CoinRobotViewerAdapter> reproduction =
374 std::make_shared<CoinRobotViewerAdapter>(parent);
375 reproduction->viewer->getRootNode()->addChild(this->viewer->getRootNode());
376 reproduction->camera = reproduction->viewer->getCamera();
377 Eigen::Vector3f position;
378 Eigen::Vector3f pointAtA = Eigen::Vector3f(0, 0, 0);
379 Eigen::Vector3f pointAtB;
380 position = Eigen::Vector3f(0, 2, 3.5);
381 pointAtB = Eigen::Vector3f(0, 0, 5);
382 reproduction->setCamera(position, pointAtA, pointAtB);
383 reproduction->viewer->getCamera()->viewAll(this->viewer->getRootNode(), SbViewportRegion());
394 CoinRobotViewerAdapter::manipFinishCallback(
void*
data, SoDragger* dragger)
407 CoinRobotViewerAdapter::manipMovedCallback(
void*
data, SoDragger* dragger)
421 CoinRobotViewerAdapter::autoFollowSensorTimerCB(
void*
data, SoSensor* sensor)
435 CoinRobotViewerAdapter::made_selection(
void*
data, SoPath* path)
441 std::string
s = path->getTail()->getName().getString();
442 std::string number =
s.substr(1);
443 controller->selectedWaypoint = std::stoi(number);
453 CoinRobotViewerAdapter::unmade_selection(
void*
data, SoPath* path)
463 CoinRobotViewerAdapter::pickFilterCB(
void*
data,
const SoPickedPoint* pick)
471 SoFullPath* p = (SoFullPath*)pick->getPath();
473 for (
int i = 0; i < p->getLength();)
475 SoNode*
n = p->getNode(p->getLength() - 1);
478 for (
int j = 0; j < 50; j++)
480 std::string currentName = std::string(
n->getName().getString());
488 p->truncate(p->getLength() - 1);
494 CoinRobotViewerAdapter::refreshSelectedPoint()
496 SoNode* selectedPoint =
static_cast<SoNode*
>(wayPoints.get(this->selectedWaypoint));
497 this->viewer->getRootNode()->deselectAll();
498 this->viewer->getRootNode()->select(selectedPoint);
502 CoinRobotViewerAdapter::robotUpdateTimerCB(
void*
data, SoSensor* sensor)
511 if (
controller->viewer->getRootNode()->getList()->getLength() != 0)
513 SoPath* p = (SoPath*)
controller->viewer->getRootNode()->getList()->get(0);
516 std::string
s = p->getTail()->getName().getString();
519 std::string number =
s.substr(1);
520 controller->selectedWaypoint = std::stoi(number);
535 controller->startUpCameraPositioningFlag =
false;