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);
111 manipulator->removeVisualization();
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();
138 manipulator->removeVisualization();
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);
232 return manipulator->getUserDesiredPose();
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;
281 const std::string s =
"W" + std::to_string(
index);
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();
323 std::vector<float> jointAngles)
327 manipulator->removeVisualization();
330 robot->getRobotNodeSet(kc->getName())->setJointValues(jointAngles);
331 manipulator->setVisualization(
robot, kc);
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());
394CoinRobotViewerAdapter::manipFinishCallback(
void*
data, SoDragger* dragger)
407CoinRobotViewerAdapter::manipMovedCallback(
void*
data, SoDragger* dragger)
412 controller->manipulatorMoved =
true;
415 controller->
observer.lock()->refresh();
421CoinRobotViewerAdapter::autoFollowSensorTimerCB(
void*
data, SoSensor* sensor)
425 if (controller && controller->manipulatorMoved)
429 controller->
observer.lock()->refresh();
435CoinRobotViewerAdapter::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);
447 controller->
observer.lock()->refresh();
453CoinRobotViewerAdapter::unmade_selection(
void*
data, SoPath* path)
456 if (!controller || !controller->
robot)
463CoinRobotViewerAdapter::pickFilterCB(
void*
data,
const SoPickedPoint* pick)
466 if (!controller || !controller->
robot)
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());
483 if (currentName ==
"W" + std::to_string(j))
488 p->truncate(p->getLength() - 1);
494CoinRobotViewerAdapter::refreshSelectedPoint()
496 SoNode* selectedPoint =
static_cast<SoNode*
>(wayPoints.get(this->selectedWaypoint));
497 this->viewer->getRootNode()->deselectAll();
498 this->viewer->getRootNode()->select(selectedPoint);
502CoinRobotViewerAdapter::robotUpdateTimerCB(
void*
data, SoSensor* sensor)
506 if (!controller || !controller->
robot)
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);
521 controller->refreshSelectedPoint();
524 controller->
observer.lock()->refresh();
529 controller->viewer->render();
532 if (controller->startUpCameraPositioningFlag)
534 controller->viewer->cameraViewAll();
535 controller->startUpCameraPositioningFlag =
false;
#define AUTO_FOLLOW_UPDATE
#define ROBOT_UPDATE_TIMER_MS
The CoinRobotViewerAdapter class.
AdvancedVisualizationFactoryPtr createAdvancedVisualizationFactory() override
CoinRobotViewerAdapter(QWidget *widget)
CoinRobotViewerAdapter.
void removeWaypointVisualization(int index) override
removeWaypointVisualization removes the Waypoint with index so that it is no longer visualized
void addRobotVisualization(VirtualRobot::RobotPtr robot, QString selectedChain) override
METHODS FOR VISUALIZATION SETUP.
void clearTrajectory() override
clearTrajectory removes all visualization of waypoints and transitions but keeps the robot and the ma...
void setSelectedWaypoint(int index) override
removeWaypointVisualization removes the Waypoint with index so that it is no longer visualized
void updateRobotVisualization() override
UPDATING OF VISUALIZATION.
void addSceneVisualization(VirtualRobot::ScenePtr scene) override
addSceneVisualization visualizes the whole scene where the robot is placed in
void addWaypointVisualization(int index, PoseBasePtr waypoint, VirtualRobot::EndEffectorPtr tcp) override
METHODS FOR WAYPOINTS.
void addTransitionVisualization(int index, std::vector< PoseBasePtr > transition) override
METHODS FOR TRANSITIONS.
void enableVisualization() override
enableVisualization shows the viewer
Eigen::Matrix4f getManipulatorPose() override
INHERITED BY OBSERVER.
RobotVisualizationPtr reproduce(QWidget *parent) override
UPDATING OF VISUALIZATION.
~CoinRobotViewerAdapter()
void removeTransitionVisualization(int index) override
removeTransitionVisualization removes visualization of a certain transition
int getSelectedWaypoint() override
getSelectedWaypoint
void highlightTransitionVisualization(int index, std::vector< PoseBasePtr > transition) override
highlightTransitionVisualization highlights the transition with index i by changing the color of all ...
void setManipulator(VirtualRobot::RobotNodeSetPtr kc, std::vector< float > jointAngles) override
SETTING MANIPULATOR.
void removeAllWaypointVisualizations() override
removeAllWaypointVisualizations removes all waypoints that are currently visualized
void disableVisualization() override
disableVisualization hides the viewer
void setCamera(const Eigen::VectorXf position, const Eigen::VectorXf pointAtA, const Eigen::VectorXf pointAtB) override
setCamera sets the camera at a certain position
virtual Eigen::Matrix4f toEigen() const
VirtualRobot::RobotPtr robot
VirtualRobot::ScenePtr scene
std::weak_ptr< VisualizationObserver > observer
#define ARMARX_INFO
The normal logging level.
std::shared_ptr< class Robot > RobotPtr
double s(double t, double s0, double v0, double a0, double j)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< AdvancedCoinVisualizationFactory > AdvancedCoinVisualizationFactoryPtr
std::shared_ptr< AdvancedVisualizationFactory > AdvancedVisualizationFactoryPtr
boost::shared_ptr< VirtualRobot::CoinVisualization > CoinVisualizationPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr
constexpr auto n() noexcept