27 #include <VirtualRobot/RobotNodeSet.h>
28 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
29 #include <VirtualRobot/XML/RobotIO.h>
36 #include <Inventor/SbViewportRegion.h>
37 #include <Inventor/actions/SoGetMatrixAction.h>
38 #include <Inventor/actions/SoSearchAction.h>
39 #include <Inventor/nodes/SoCube.h>
43 hasEndEffectorVisualizer(false),
58 VirtualRobot::RobotNodeSetPtr nodeSet)
65 VirtualRobot::EndEffectorPtr endEffector = robot->getEndEffector(nodeSet->getTCP()->getName());
68 std::vector<VirtualRobot::EndEffectorPtr> eefs;
69 robot->getEndEffectors(eefs);
72 if (eef->getTcp() == nodeSet->getTCP())
79 this->hasEndEffectorVisualizer = endEffector ? true :
false;
82 this->material =
new SoMaterial();
83 this->material->transparency = 0.5;
84 this->material->setOverride(
true);
85 this->addChild(material);
88 if (this->hasEndEffectorVisualizer)
92 endEffectorRobot->getVisualization();
93 this->addChild(endEffectorVisualization->getCoinVisualization());
97 SoCube* cube =
new SoCube();
102 this->addChild(cube);
106 this->manip.reset(
new SoTransformerManip());
112 SoSeparator* nullSep =
new SoSeparator;
115 manip->getDragger()->setPart(
"scale1", nullSep);
116 manip->getDragger()->setPart(
"scale2", nullSep);
117 manip->getDragger()->setPart(
"scale3", nullSep);
118 manip->getDragger()->setPart(
"scale4", nullSep);
119 manip->getDragger()->setPart(
"scale5", nullSep);
120 manip->getDragger()->setPart(
"scale6", nullSep);
121 manip->getDragger()->setPart(
"scale7", nullSep);
122 manip->getDragger()->setPart(
"scale8", nullSep);
127 if (this->hasEndEffectorVisualizer)
130 this->localTransformation = endEffector->getBase()->getTransformationTo(nodeSet->getTCP());
132 globalMat = endEffector->getBase()->getGlobalPose();
137 globalMat(0, 3) /= 1000;
138 globalMat(1, 3) /= 1000;
139 globalMat(2, 3) /= 1000;
140 manip->setMatrix(VirtualRobot::CoinVisualizationFactory::getSbMatrix(globalMat));
142 this->insertChild(manip.get(), 0);
144 this->isVisualizing =
true;
152 this->removeAllChildren();
155 this->isVisualizing =
false;
156 this->hasEndEffectorVisualizer =
false;
165 this->material->ambientColor.setValue(r, g, b);
174 this->manip->getDragger()->addFinishCallback(func,
data);
183 this->manip->getDragger()->addMotionCallback(func,
data);
192 SoGetMatrixAction* action =
new SoGetMatrixAction(SbViewportRegion());
194 sa.setNode(manip.get());
195 sa.setSearchingAll(TRUE);
196 SoBaseKit::setSearchingChildren(TRUE);
199 action->apply(sa.getPath());
201 SbMatrix matrix = action->getMatrix();
204 mat(0, 0) = matrix[0][0];
205 mat(0, 1) = matrix[1][0];
206 mat(0, 2) = matrix[2][0];
207 mat(0, 3) = matrix[3][0] * 1000;
209 mat(1, 0) = matrix[0][1];
210 mat(1, 1) = matrix[1][1];
211 mat(1, 2) = matrix[2][1];
212 mat(1, 3) = matrix[3][1] * 1000;
214 mat(2, 0) = matrix[0][2];
215 mat(2, 1) = matrix[1][2];
216 mat(2, 2) = matrix[2][2];
217 mat(2, 3) = matrix[3][2] * 1000;
219 mat(3, 0) = matrix[0][3];
220 mat(3, 1) = matrix[1][3];
221 mat(3, 2) = matrix[2][3];
222 mat(3, 3) = matrix[3][3];
227 if (this->hasEndEffectorVisualizer)
229 mat = mat * this->localTransformation;
244 std::stringstream buffer;
252 if (this->hasEndEffectorVisualizer)
254 globalPose = globalPose * this->localTransformation.inverse();
256 globalPose(0, 3) /= 1000;
257 globalPose(1, 3) /= 1000;
258 globalPose(2, 3) /= 1000;
259 manip->setMatrix(VirtualRobot::CoinVisualizationFactory::getSbMatrix(globalPose));