32namespace ag = arviz_interactive_project::components::arviz_interactive;
42 defs->defineOptionalProperty<
float>(
"FrameRate", 30.0f,
"Frames per second")
45 defs->defineOptionalProperty<visionx::ImageDimension>(
46 "ImageSize", visionx::ImageDimension(640, 480),
"Resolution of the rendered image.")
47 .setCaseInsensitive(
true)
48 .map(
"320x240", visionx::ImageDimension(320, 240))
49 .map(
"640x480", visionx::ImageDimension(640, 480))
50 .map(
"800x600", visionx::ImageDimension(800, 600))
51 .map(
"1024x768", visionx::ImageDimension(1024, 768))
52 .map(
"1280x960", visionx::ImageDimension(1280, 960));
53 defs->defineOptionalProperty<std::string>(
56 "Robot node whose pose is used as the virtual camera.");
57 defs->defineOptionalProperty<std::string>(
60 "Reference frame reported for the provided images.");
61 defs->defineOptionalProperty<
float>(
62 "focalLength", 600.0f,
"Focal length in pixels (used to derive the field of view).");
63 defs->defineOptionalProperty<
float>(
64 "NearClip", 0.01f,
"Near clipping plane distance in meters.");
65 defs->defineOptionalProperty<
float>(
66 "FarClip", 100.0f,
"Far clipping plane distance in meters.");
67 defs->defineOptionalProperty<std::string>(
68 "ArVizGodotName",
"arviz_godot",
"Name of the arviz_godot component to render with.");
69 defs->defineOptionalProperty<std::string>(
70 "RobotStateComponentName",
71 "RobotStateComponent",
72 "Name of the RobotStateComponent providing the robot pose.");
73 defs->defineOptionalProperty<
float>(
76 "Roll of the camera-node -> OpenGL-camera alignment (rotation about local X), in "
77 "degrees. Defaults to 180 (camera node +Z optical axis -> Godot -Z forward).");
78 defs->defineOptionalProperty<
float>(
79 "CameraAlignPitchDeg", 0.0f,
"Pitch of the camera-node alignment (about local Y).");
80 defs->defineOptionalProperty<
float>(
81 "CameraAlignYawDeg", 0.0f,
"Yaw of the camera-node alignment (about local Z).");
82 defs->defineOptionalProperty<
int>(
83 "RenderTimeoutMs", 2000,
"Timeout in ms for a single render request to arviz_godot.");
84 defs->defineOptionalProperty<std::string>(
87 "Comma-separated list of ArViz layers to render. Each entry is either a component "
88 "name (renders all of its layers, e.g. 'ObjectMemory') or a fully-qualified "
89 "'component::layer'. Leave empty to render the whole scene.");
100 const visionx::ImageDimension dimensions =
102 renderWidth_ = dimensions.width;
103 renderHeight_ = dimensions.height;
114 renderLayers_.clear();
116 for (std::size_t
start = 0;
start < renderLayersStr.size() ||
start == 0;)
118 const std::size_t comma = renderLayersStr.find(
',',
start);
119 std::string token = renderLayersStr.substr(
120 start, comma == std::string::npos ? std::string::npos : comma -
start);
122 const std::size_t first = token.find_first_not_of(
" \t");
123 const std::size_t last = token.find_last_not_of(
" \t");
124 if (first != std::string::npos)
126 renderLayers_.push_back(token.substr(first, last - first + 1));
128 if (comma == std::string::npos)
134 if (!renderLayers_.empty())
136 ARMARX_INFO <<
"Restricting rendering to " << renderLayers_.size()
137 <<
" ArViz layer selector(s).";
140 const float deg2rad =
static_cast<float>(
M_PI) / 180.0f;
143 Eigen::Vector3f::UnitX()) *
145 Eigen::Vector3f::UnitY()) *
147 Eigen::Vector3f::UnitZ());
149 setImageFormat(visionx::ImageDimension(renderWidth_, renderHeight_), visionx::eRgb);
165 ImageProviderGodotSimulation::ensureConnected()
171 arvizGodot_ = ag::ArVizInteractiveInterfacePrx::uncheckedCast(
173 ->ice_timeout(renderTimeoutMs_ + 1000));
176 if (!sharedRobot_ || !localRobot_)
178 auto robotStateComponent =
180 sharedRobot_ = robotStateComponent->getSynchronizedRobot();
183 if (localRobot_ && !localRobot_->hasRobotNode(cameraNodeName_))
185 ARMARX_ERROR <<
"Configured camera node '" << cameraNodeName_
186 <<
"' is not part of the robot model.";
195 return arvizGodot_ && localRobot_ && sharedRobot_;
214 std::unique_lock<std::mutex> lock(captureMutex_);
215 arvizGodot_ =
nullptr;
216 sharedRobot_ =
nullptr;
223 std::unique_lock<std::mutex> lock(captureMutex_);
225 if ((!arvizGodot_ || !localRobot_ || !sharedRobot_) && !ensureConnected())
235 VirtualRobot::RobotNodePtr cameraNode = localRobot_->getRobotNode(cameraNodeName_);
239 <<
"' not found in robot model.";
244 const Eigen::Matrix4f globalPose = cameraNode->getGlobalPose();
245 const Eigen::Matrix3f nodeRotation = globalPose.block<3, 3>(0, 0);
249 ag::CameraRenderPose pose;
250 pose.px = globalPose(0, 3);
251 pose.py = globalPose(1, 3);
252 pose.pz = globalPose(2, 3);
253 pose.qx = cameraRotation.x();
254 pose.qy = cameraRotation.y();
255 pose.qz = cameraRotation.z();
256 pose.qw = cameraRotation.w();
258 const float verticalFovRad = 2.0f * std::atan(renderHeight_ / (2.0f * focalLength_));
260 const ag::StringSeq layerNames(renderLayers_.begin(), renderLayers_.end());
261 const ag::RenderedFrame frame = arvizGodot_->renderCameraImage(pose,
275 if (frame.width != renderWidth_ || frame.height != renderHeight_)
278 << frame.height <<
" differs from expected " << renderWidth_ <<
"x"
279 << renderHeight_ <<
".";
283 const std::size_t pixelCount =
284 static_cast<std::size_t
>(renderWidth_) *
static_cast<std::size_t
>(renderHeight_);
285 if (frame.rgba.size() < pixelCount * 4)
293 ARMARX_WARNING <<
"Shared memory provider is null (possibly shutting down).";
298 auto* dst =
reinterpret_cast<std::uint8_t*
>(ppImageBuffers[0]);
299 const auto& src = frame.rgba;
300 for (std::size_t i = 0; i < pixelCount; ++i)
302 dst[i * 3 + 0] = src[i * 4 + 0];
303 dst[i * 3 + 1] = src[i * 4 + 1];
304 dst[i * 3 + 2] = src[i * 4 + 2];
316 visionx::MonocularCalibration
319 visionx::MonocularCalibration calibration;
320 visionx::CameraParameters& params = calibration.cameraParam;
321 params.width = renderWidth_;
322 params.height = renderHeight_;
323 params.principalPoint = {renderWidth_ / 2.0f, renderHeight_ / 2.0f};
324 params.focalLength = {focalLength_, focalLength_};
325 params.distortion = {0.0f, 0.0f, 0.0f, 0.0f};
326 params.rotation = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
327 params.translation = {0.0f, 0.0f, 0.0f};
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
A monocular image provider that renders the simulated scene using arviz_godot.
void onStartCapture(float frameRate) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onStartCapturingImageProvider() override
visionx::MonocularCalibration getCalibration(const Ice::Current &c=Ice::emptyCurrent) override
void onStopCapture() override
void onExitCapturingImageProvider() override
static std::string GetDefaultName()
void onInitCapturingImageProvider() override
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
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
void start(const Ice::Current &c) override
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
void setNumberImages(int numberImages)
Sets the number of images on each capture.
#define ARMARX_INFO
The normal logging level.
#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.
Quaternion< float, 0 > Quaternionf
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.