28 #include <VirtualRobot/XML/RobotIO.h>
29 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
32 #include <Inventor/actions/SoGetMatrixAction.h>
33 #include <Inventor/actions/SoSearchAction.h>
34 #include <Inventor/SbViewportRegion.h>
35 #include <Inventor/nodes/SoCube.h>
59 VirtualRobot::EndEffectorPtr endEffector = robot->getEndEffector(nodeSet->getTCP()->getName());
62 std::vector<VirtualRobot::EndEffectorPtr> eefs;
63 robot->getEndEffectors(eefs);
66 if (eef->getTcp() == nodeSet->getTCP())
73 this->hasEndEffectorVisualizer = endEffector ? true :
false;
76 this->material =
new SoMaterial();
77 this->material->transparency = 0.5;
78 this->material->setOverride(
true);
79 this->addChild(material);
82 if (this->hasEndEffectorVisualizer)
86 this->addChild(endEffectorVisualization->getCoinVisualization());
90 SoCube* cube =
new SoCube();
99 this->manip.reset(
new SoTransformerManip());
105 SoSeparator* nullSep =
new SoSeparator;
108 manip->getDragger()->setPart(
"scale1", nullSep);
109 manip->getDragger()->setPart(
"scale2", nullSep);
110 manip->getDragger()->setPart(
"scale3", nullSep);
111 manip->getDragger()->setPart(
"scale4", nullSep);
112 manip->getDragger()->setPart(
"scale5", nullSep);
113 manip->getDragger()->setPart(
"scale6", nullSep);
114 manip->getDragger()->setPart(
"scale7", nullSep);
115 manip->getDragger()->setPart(
"scale8", nullSep);
120 if (this->hasEndEffectorVisualizer)
123 this->localTransformation = endEffector->getBase()->getTransformationTo(nodeSet->getTCP());
125 globalMat = endEffector->getBase()->getGlobalPose();
130 globalMat(0, 3) /= 1000;
131 globalMat(1, 3) /= 1000;
132 globalMat(2, 3) /= 1000;
133 manip->setMatrix(VirtualRobot::CoinVisualizationFactory::getSbMatrix(globalMat));
135 this->insertChild(manip.get(), 0);
137 this->isVisualizing =
true;
144 this->removeAllChildren();
147 this->isVisualizing =
false;
148 this->hasEndEffectorVisualizer =
false;
156 this->material->ambientColor.setValue(r, g, b);
164 this->manip->getDragger()->addFinishCallback(func,
data);
172 this->manip->getDragger()->addMotionCallback(func,
data);
180 SoGetMatrixAction* action =
new SoGetMatrixAction(SbViewportRegion());
182 sa.setNode(manip.get());
183 sa.setSearchingAll(TRUE);
184 SoBaseKit::setSearchingChildren(TRUE);
187 action->apply(sa.getPath());
189 SbMatrix matrix = action->getMatrix();
192 mat(0, 0) = matrix[0][0];
193 mat(0, 1) = matrix[1][0];
194 mat(0, 2) = matrix[2][0];
195 mat(0, 3) = matrix[3][0] * 1000;
197 mat(1, 0) = matrix[0][1];
198 mat(1, 1) = matrix[1][1];
199 mat(1, 2) = matrix[2][1];
200 mat(1, 3) = matrix[3][1] * 1000;
202 mat(2, 0) = matrix[0][2];
203 mat(2, 1) = matrix[1][2];
204 mat(2, 2) = matrix[2][2];
205 mat(2, 3) = matrix[3][2] * 1000;
207 mat(3, 0) = matrix[0][3];
208 mat(3, 1) = matrix[1][3];
209 mat(3, 2) = matrix[2][3];
210 mat(3, 3) = matrix[3][3];
215 if (this->hasEndEffectorVisualizer)
217 mat = mat * this->localTransformation;
231 std::stringstream buffer;
238 if (this->hasEndEffectorVisualizer)
240 globalPose = globalPose * this->localTransformation.inverse();
242 globalPose(0, 3) /= 1000;
243 globalPose(1, 3) /= 1000;
244 globalPose(2, 3) /= 1000;
245 manip->setMatrix(VirtualRobot::CoinVisualizationFactory::getSbMatrix(globalPose));