27#include <Ice/Properties.h>
44#include <Calibration/Calibration.h>
45#include <Inventor/SoInteraction.h>
46#include <Inventor/SoOffscreenRenderer.h>
47#include <Inventor/nodes/SoDirectionalLight.h>
48#include <Inventor/nodes/SoUnits.h>
49#include <Math/Math3d.h>
61 VirtualRobot::init(this->
getName());
64 SoInteraction::init();
71 ARMARX_VERBOSE <<
"Camera calibration file: " << calibrationFileName;
73 if (!calibrationFileName.empty())
75 std::string fullCalibrationFileName;
79 ARMARX_ERROR <<
"Could not find camera calibration file in ArmarXDataPath: "
80 << calibrationFileName;
83 setlocale(LC_NUMERIC,
"C");
85 CStereoCalibration ivtStereoCalibration;
87 if (!ivtStereoCalibration.LoadCameraParameters(fullCalibrationFileName.c_str(),
true))
89 ARMARX_ERROR <<
"Error loading camera calibration file: "
90 << fullCalibrationFileName;
108 const visionx::ImageDimension dimensions =
137 std::stringstream svName;
138 svName <<
getName() <<
"_PhysicsWorldVisualization";
189 simVisu->synchronizeVisualizationData();
194 simVisu->synchronizeVisualizationData();
202 const std::string& cameraSensorNameLeft,
203 const std::string& cameraSensorNameRight)
206 auto l =
simVisu->getScopedLock();
208 rendererLeft.reset(VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(
210 rendererRight.reset(VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(
224 copyRenderBufferToByteImage(CByteImage* image, std::uint8_t* renderBuffer)
226 int height = image->height;
227 int width = image->width;
228 std::uint8_t* pixelsRow = image->pixels;
229 std::uint8_t* renderBufferEndOfRow = renderBuffer + 3 * (width - 1);
230 for (
int y = 0; y < height; y++)
232 for (
int x = 0;
x < width;
x++)
234 pixelsRow[
x * 3 + 0] = renderBufferEndOfRow[-
x * 3 + 0];
235 pixelsRow[
x * 3 + 1] = renderBufferEndOfRow[-
x * 3 + 1];
236 pixelsRow[
x * 3 + 2] = renderBufferEndOfRow[-
x * 3 + 2];
238 pixelsRow += width * 3;
239 renderBufferEndOfRow += width * 3;
246 auto l =
simVisu->getScopedLock();
255 unsigned char* renderBuffer = NULL;
256 bool renderOK =
false;
292 VirtualRobot::CoinVisualizationFactory::renderOffscreen(
rendererLeft.get(),
301 SoPerspectiveCamera* cam =
new SoPerspectiveCamera();
304 Eigen::Matrix4f camPose =
cameraNodeL->getGlobalPose();
305 Eigen::Vector3f camPos = MathTools::getTranslation(camPose);
307 cam->position.setValue(camPos[0] * sc, camPos[1] * sc, camPos[2] * sc);
314 (
float)(-
M_PI / 2.0));
316 CoinVisualizationFactory::getSbMatrix(camPose));
317 cam->orientation.setValue(align2 *
align * trans);
320 cam->nearDistance.setValue(0.01f);
321 cam->farDistance.setValue(10000.0f);
324 SoSeparator* root =
new SoSeparator();
326 SoDirectionalLight* light =
new SoDirectionalLight;
327 root->addChild(light);
335 root->addChild(
simVisu->getVisualization());
337 renderOK =
rendererLeft.get()->render(root) == TRUE ? true :
false;
347 if (renderOK && renderBuffer != NULL)
349 copyRenderBufferToByteImage(
images[0], renderBuffer);
355 VirtualRobot::CoinVisualizationFactory::renderOffscreen(
rendererRight.get(),
363 if (renderOK && renderBuffer != NULL)
365 copyRenderBufferToByteImage(
images[1], renderBuffer);
380 bool succeeded =
true;
384 simVisu->synchronizeVisualizationData();
402 ARMARX_WARNING <<
"Shared memory provider is null (possibly shutting down)";
411 memcpy(ppImageBuffers[i],
432 CCalibration leftCalibration;
450 simVisu->synchronizeVisualizationData();
467 CCalibration rightCalibration;
468 Vec3d transRight{-left_P_right.x(), 0, 0};
482 CStereoCalibration ivtStereoCalibration;
483 ivtStereoCalibration.SetSingleCalibrations(leftCalibration, rightCalibration);
487 visionx::StereoCalibration
513 return "ImageProviderDynamicSimulation";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
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)
Image provider captures images from the simulator and broadcasts notifications at a specified frame r...
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
static std::string GetDefaultName()
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