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();
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 =
136 std::stringstream svName;
137 svName <<
getName() <<
"_PhysicsWorldVisualization";
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();
303 Eigen::Matrix4f camPose =
cameraNodeL->getGlobalPose();
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
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
Property< PropertyType > getProperty(const std::string &name)
std::string rightNodeName
CByteImage ** resizedImages
VirtualRobot::RobotNodePtr cameraNodeL
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Returns the StereoCalibration as provided in configuration.
bool setupCameraRendering(const std::string &robotName, const std::string &cameraSensorNameLeft, const std::string &cameraSensorNameRight)
VirtualRobot::RobotNodePtr cameraNodeR
std::optional< visionx::StereoCalibration > stereoCalibration
void onStartCapture(float frameRate) override
std::shared_ptr< SoOffscreenRenderer > rendererRight
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Returns whether images are undistorted.
void onStopCapture() override
void onExitCapturingImageProvider() override
ArmarXPhysicsWorldVisualizationPtr simVisu
std::string getReferenceFrame(const ::Ice::Current &=Ice::emptyCurrent) override
void onInitCapturingImageProvider() override
bool updateCameraRendering()
std::shared_ptr< SoOffscreenRenderer > rendererLeft
std::string getName() const
Retrieve name of object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
float frameRate
Required frame rate.
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::SharedMemoryScopedWriteLockPtr getScopedWriteLock()
Retrieve scoped lock for writing to the memory.
armarx::IceSharedMemoryProvider< unsignedchar >::pointer_type sharedMemoryProvider
shared memory provider
ImageFormatInfo getImageFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the entire image format info struct via Ice.
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
int getNumberImages(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve number of images handled by this provider.
void setNumberImages(int numberImages)
Sets the number of images on each capture.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
void * align(size_t alignment, size_t bytes, void *&bufferPlace, size_t &bufferSpace) noexcept