23 #include "../Util/OrientationConversion.h"
26 #include "Inventor/draggers/SoDragger.h"
28 #include "Inventor/nodes/SoSeparator.h"
30 #include <Inventor/sensors/SoTimerSensor.h>
32 #include "VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h"
34 #include "VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h"
36 #include "VirtualRobot/Scene.h"
42 #include <Inventor/SoInteraction.h>
44 #include <Inventor/actions/SoLineHighlightRenderAction.h>
46 #include <Inventor/Qt/SoQt.h>
48 #include <Inventor/SoFullPath.h>
50 #include <Inventor/nodes/SoPickStyle.h>
52 #include <Inventor/nodes/SoCube.h>
54 #include <Inventor/nodes/SoTranslation.h>
56 #include <Inventor/misc/SoContextHandler.h>
58 #define ROBOT_UPDATE_TIMER_MS 333
60 #define AUTO_FOLLOW_UPDATE 50
72 robotUpdateSensor = NULL;
73 this->selectedWaypoint = 0;
74 this->wayPointCounter = 0;
75 this->viewer = std::shared_ptr<RobotViewer>(
new RobotViewer(widget));
76 camera = viewer->getCamera();
79 SoInteraction::init();
80 viewer->setGLRenderAction(
new SoLineHighlightRenderAction);
81 viewer->getRootNode()->addChild((SoNode*)manipulator);
82 manipulatorMoved =
false;
83 startUpCameraPositioningFlag =
true;
84 selected =
new SoSelection();
89 viewer->getRootNode()->addSelectionCallback(made_selection, viewer.get());
90 viewer->getRootNode()->addDeselectionCallback(unmade_selection, viewer.get());
91 viewer->getRootNode()->setPickFilterCallback(pickFilterCB, viewer.get(),
true);
92 viewer->getRootNode()->policy = SoSelection::SINGLE;
93 manipulator->addManipFinishCallback(manipFinishCallback,
this);
94 manipulator->addManipMovedCallback(manipMovedCallback,
this);
95 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
96 autoFollowSensor =
new SoTimerSensor(autoFollowSensorTimerCB,
this);
98 sensor_mgr->insertTimerSensor(autoFollowSensor);
99 viewer->getRootNode()->addChild((SoNode*)manipulator);
100 manipFinishCallback(
this, NULL);
110 while (transitions.getLength() != 0)
112 transitions.remove(0);
114 while (wayPoints.getLength() != 0)
118 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
119 sensor_mgr->removeTimerSensor(robotUpdateSensor);
120 sensor_mgr->removeTimerSensor(autoFollowSensor);
121 this->viewer->getRootNode()->removeAllChildren();
123 manipulator->addManipFinishCallback(NULL, NULL);
124 manipulator->addManipMovedCallback(NULL, NULL);
128 robotUpdateSensor = NULL;
129 autoFollowSensor = NULL;
144 if ((
robot) && (this->robot) && this->robot->getName() !=
robot->getName())
146 this->viewer->getRootNode()->removeAllChildren();
149 this->selectedWaypoint = 0;
150 viewer->getRootNode()->deselectAll();
152 manipulatorMoved =
false;
153 viewer->getRootNode()->addChild((SoNode*)manipulator);
155 SoPickStyle* unpickable =
new SoPickStyle();
156 unpickable->style = SoPickStyle::UNPICKABLE;
157 SoPickStyle* pickable =
new SoPickStyle();
158 pickable->style = SoPickStyle::SHAPE;
159 viewer->getRootNode()->addChild(unpickable);
160 CoinVisualizationPtr robotViewerVisualization = this->robot->getVisualization<VirtualRobot::CoinVisualization>();
161 this->viewer->getRootNode()->addChild(robotViewerVisualization->getCoinVisualization());
162 RobotNodeSetPtr nodeset =
robot->getRobotNodeSet(selectedChain.toStdString());
164 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
165 sensor_mgr->removeTimerSensor(robotUpdateSensor);
166 robotUpdateSensor =
new SoTimerSensor(robotUpdateTimerCB,
this);
168 sensor_mgr->insertTimerSensor(robotUpdateSensor);
170 viewer->getRootNode()->addChild(pickable);
171 viewer->getRootNode()->addChild((SoNode*)manipulator);
172 manipulator->addManipFinishCallback(manipFinishCallback,
this);
173 manipulator->addManipMovedCallback(manipMovedCallback,
this);
181 this->viewer->getRootNode()->addChild(sceneVisualization->getCoinVisualization());
186 camera->position.setValue(position[0], position[1], position[2]);
187 camera->pointAt(SbVec3f(pointAtA[0], pointAtA[1], pointAtA[2]), SbVec3f(pointAtB[0], pointAtB[1], pointAtB[2]));
188 camera->viewAll(viewer->getRootNode(), SbViewportRegion());
196 VisualizationNodePtr node = this->factory->createCurve(transition,
false);
197 CoinVisualizationNodePtr visu = boost::dynamic_pointer_cast<CoinVisualizationNode>(node);
198 SoNode* newTransition = visu->getCoinVisualization();
199 viewer->getRootNode()->addChild(newTransition);
200 transitions.insert(newTransition,
index);
205 SoNode* toDelete = transitions[
index];
206 viewer->getRootNode()->removeChild(toDelete);
207 transitions.remove(
index);
213 VisualizationNodePtr node = this->factory->createCurve(transition,
true);
214 CoinVisualizationNodePtr visu = boost::dynamic_pointer_cast<CoinVisualizationNode>(node);
215 SoNode* newTransition = visu->getCoinVisualization();
216 viewer->getRootNode()->addChild(newTransition);
217 transitions.insert(newTransition,
index);
239 return this->selectedWaypoint;
254 Pose p =
Pose(waypoint->position, waypoint->orientation);
255 EndEffectorPtr eef = endEffectorRobot->getEndEffectors()[0];
256 endEffectorRobot->setGlobalPoseForRobotNode(eef->getTcp(), p.
toEigen());
257 eef->getTcp()->setGlobalPoseNoChecks(p.
toEigen());
259 newWaypoint = CoinVisualizationFactory::getCoinVisualization(endEffectorRobot, SceneObject::VisualizationType::Full,
true);
263 SoCube* cube =
new SoCube();
267 SoTranslation* cubePoint =
new SoTranslation();
268 cubePoint->translation.setValue(waypoint->position->x / 1000.0, waypoint->position->y / 1000.0, waypoint->position->z / 1000.0);
269 SoSeparator* parent =
new SoSeparator();
270 parent->addChild(cubePoint);
271 parent->addChild(cube);
272 newWaypoint = parent;
275 const char*
c =
s.c_str();
276 newWaypoint->setName(SbName(
c));
277 std::string st = std::string(newWaypoint->getName().getString());
278 viewer->getRootNode()->addChild(newWaypoint);
279 viewer->getRootNode()->select(newWaypoint);
280 wayPoints.insert(newWaypoint,
index);
282 viewer->getRootNode()->deselectAll();
287 SoNode* toDelete = wayPoints[
index];
288 viewer->getRootNode()->removeChild(toDelete);
289 wayPoints.remove(
index);
290 viewer->getRootNode()->deselectAll();
295 while (wayPoints.getLength() != 0)
304 this->selectedWaypoint =
index;
305 refreshSelectedPoint();
320 manipulator->addManipFinishCallback(manipFinishCallback,
this);
321 manipulator->addManipMovedCallback(manipMovedCallback,
this);
344 while (transitions.getLength() != 0)
348 while (wayPoints.getLength() != 0)
357 std::shared_ptr<CoinRobotViewerAdapter> reproduction = std::make_shared<CoinRobotViewerAdapter>(parent);
358 reproduction->viewer->getRootNode()->addChild(this->viewer->getRootNode());
359 reproduction->camera = reproduction->viewer->getCamera();
360 Eigen::Vector3f position;
361 Eigen::Vector3f pointAtA = Eigen::Vector3f(0, 0, 0);
362 Eigen::Vector3f pointAtB;
363 position = Eigen::Vector3f(0, 2, 3.5);
364 pointAtB = Eigen::Vector3f(0, 0, 5);
365 reproduction->setCamera(position, pointAtA, pointAtB);
366 reproduction->viewer->getCamera()->viewAll(this->viewer->getRootNode(), SbViewportRegion());
378 void CoinRobotViewerAdapter::manipFinishCallback(
void*
data, SoDragger* dragger)
390 void CoinRobotViewerAdapter::manipMovedCallback(
void*
data, SoDragger* dragger)
403 void CoinRobotViewerAdapter::autoFollowSensorTimerCB(
void*
data, SoSensor* sensor)
416 void CoinRobotViewerAdapter::made_selection(
void*
data, SoPath* path)
422 std::string
s = path->getTail()->getName().getString();
423 std::string number =
s.substr(1);
424 controller->selectedWaypoint = std::stoi(number);
433 void CoinRobotViewerAdapter::unmade_selection(
void*
data, SoPath* path)
442 SoPath* CoinRobotViewerAdapter::pickFilterCB(
void*
data,
const SoPickedPoint* pick)
450 SoFullPath* p = (SoFullPath*)pick->getPath();
452 for (
int i = 0; i < p->getLength();)
454 SoNode* n = p->getNode(p->getLength() - 1);
457 for (
int j = 0; j < 50; j++)
459 std::string currentName = std::string(n->getName().getString());
467 p->truncate(p->getLength() - 1);
472 void CoinRobotViewerAdapter::refreshSelectedPoint()
474 SoNode* selectedPoint =
static_cast<SoNode*
>(wayPoints.get(this->selectedWaypoint));
475 this->viewer->getRootNode()->deselectAll();
476 this->viewer->getRootNode()->select(selectedPoint);
479 void CoinRobotViewerAdapter::robotUpdateTimerCB(
void*
data, SoSensor* sensor)
488 if (
controller->viewer->getRootNode()->getList()->getLength() != 0)
490 SoPath* p = (SoPath*)
controller->viewer->getRootNode()->getList()->get(0);
493 std::string
s = p->getTail()->getName().getString();
496 std::string number =
s.substr(1);
497 controller->selectedWaypoint = std::stoi(number);
513 controller->startUpCameraPositioningFlag =
false;