27 #include <Ice/Properties.h>
43 #include <Calibration/Calibration.h>
44 #include <Inventor/SoInteraction.h>
45 #include <Inventor/SoOffscreenRenderer.h>
46 #include <Inventor/nodes/SoDirectionalLight.h>
47 #include <Inventor/nodes/SoUnits.h>
48 #include <Math/Math3d.h>
60 VirtualRobot::init(this->
getName());
63 SoInteraction::init();
67 frameRate = getProperty<float>(
"FrameRate").getValue();
69 std::string calibrationFileName = getProperty<std::string>(
"CalibrationFile").getValue();
70 ARMARX_VERBOSE <<
"Camera calibration file: " << calibrationFileName;
72 if (!calibrationFileName.empty())
74 std::string fullCalibrationFileName;
78 ARMARX_ERROR <<
"Could not find camera calibration file in ArmarXDataPath: "
79 << calibrationFileName;
82 setlocale(LC_NUMERIC,
"C");
84 CStereoCalibration ivtStereoCalibration;
86 if (!ivtStereoCalibration.LoadCameraParameters(fullCalibrationFileName.c_str(),
true))
88 ARMARX_ERROR <<
"Error loading camera calibration file: "
89 << fullCalibrationFileName;
107 const visionx::ImageDimension dimensions =
108 getProperty<visionx::ImageDimension>(
"ImageSize").getValue();
136 std::stringstream svName;
137 svName <<
getName() <<
"_PhysicsWorldVisualization";
139 Component::create<ArmarXPhysicsWorldVisualization>(
getIceProperties(), svName.str());
180 robotName = getProperty<std::string>(
"RobotName").getValue();
181 leftNodeName = getProperty<std::string>(
"RobotNodeLeftCamera").getValue();
182 rightNodeName = getProperty<std::string>(
"RobotNodeRightCamera").getValue();
183 focalLength = getProperty<float>(
"focalLength").getValue();
188 simVisu->synchronizeVisualizationData();
193 simVisu->synchronizeVisualizationData();
201 const std::string& cameraSensorNameLeft,
202 const std::string& cameraSensorNameRight)
205 auto l =
simVisu->getScopedLock();
207 rendererLeft.reset(VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(
209 rendererRight.reset(VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(
223 copyRenderBufferToByteImage(CByteImage* image, std::uint8_t* renderBuffer)
225 int height = image->height;
226 int width = image->width;
227 std::uint8_t* pixelsRow = image->pixels;
228 std::uint8_t* renderBufferEndOfRow = renderBuffer + 3 * (width - 1);
229 for (
int y = 0; y < height; y++)
231 for (
int x = 0; x < width; x++)
233 pixelsRow[x * 3 + 0] = renderBufferEndOfRow[-x * 3 + 0];
234 pixelsRow[x * 3 + 1] = renderBufferEndOfRow[-x * 3 + 1];
235 pixelsRow[x * 3 + 2] = renderBufferEndOfRow[-x * 3 + 2];
237 pixelsRow += width * 3;
238 renderBufferEndOfRow += width * 3;
245 auto l =
simVisu->getScopedLock();
254 unsigned char* renderBuffer = NULL;
255 bool renderOK =
false;
291 VirtualRobot::CoinVisualizationFactory::renderOffscreen(
rendererLeft.get(),
300 SoPerspectiveCamera* cam =
new SoPerspectiveCamera();
304 Eigen::Vector3f camPos = MathTools::getTranslation(camPose);
306 cam->position.setValue(camPos[0] * sc, camPos[1] * sc, camPos[2] * sc);
313 (
float)(-
M_PI / 2.0));
315 CoinVisualizationFactory::getSbMatrix(camPose));
316 cam->orientation.setValue(align2 *
align * trans);
319 cam->nearDistance.setValue(0.01f);
320 cam->farDistance.setValue(10000.0f);
323 SoSeparator* root =
new SoSeparator();
325 SoDirectionalLight* light =
new SoDirectionalLight;
326 root->addChild(light);
334 root->addChild(
simVisu->getVisualization());
336 renderOK =
rendererLeft.get()->render(root) == TRUE ? true :
false;
346 if (renderOK && renderBuffer != NULL)
348 copyRenderBufferToByteImage(
images[0], renderBuffer);
354 VirtualRobot::CoinVisualizationFactory::renderOffscreen(
rendererRight.get(),
362 if (renderOK && renderBuffer != NULL)
364 copyRenderBufferToByteImage(
images[1], renderBuffer);
379 bool succeeded =
true;
383 simVisu->synchronizeVisualizationData();
401 ARMARX_WARNING <<
"Shared memory provider is null (possibly shutting down)";
410 memcpy(ppImageBuffers[i],
431 CCalibration leftCalibration;
449 simVisu->synchronizeVisualizationData();
466 CCalibration rightCalibration;
467 Vec3d transRight{-left_P_right.x(), 0, 0};
481 CStereoCalibration ivtStereoCalibration;
482 ivtStereoCalibration.SetSingleCalibrations(leftCalibration, rightCalibration);
486 visionx::StereoCalibration
506 return getProperty<std::string>(
"ReferenceFrame").getValue();