AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
NeoCamera.h
Go to the documentation of this file.
1/*
2Copyright 2007-2026. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
18#include <agxOSG/export.h>
19
20#include <agxSDK/Simulation.h>
21
22#include <agx/Referenced.h>
23#include <agx/Vec2.h>
24
25#include <osg/Camera>
26#include <osg/Texture2D>
27#include <osg/View>
28
29#include <array>
30#include <optional>
31#include <unordered_map>
32
33namespace agxOSG
34{
35 using OptionalExposureCompensation = std::optional<agx::Real>;
36 using OptionalDynamicRange = std::optional<agx::Real>;
37 using OptionalFocusDistance = std::optional<agx::Real>;
38 using OptionalFocusMinimumDistance = std::optional<agx::Real>;
39 using DistortionModelParameters = std::array<agx::Real, 5>;
40 using OptionalFramerate = std::optional<agx::Real>;
41
49
56 {
57 public:
62 static bool isSupported();
63
71 static void addPreviewTo(
72 agxOSG::SceneDecorator* sceneDecorator, NeoCameraColorTextureOutput* output, const agx::Vec2& position,
73 const agx::Vec2& size);
74
81
82 public:
87
92
97
103 bool add(NeoCameraOutput* output);
104
110 bool remove(NeoCameraOutput* output);
111
118 void registerToSceneGraph(osg::Group* sceneGraph, osg::Node* sceneNode);
119
124 void setViewMatrix(const osg::Matrixd& viewMatrix);
125
134
139
145
150
151 public:
152 friend class NeoCameraLens;
153 friend class NeoCameraSensor;
154 friend class NeoCameraOutput;
157
158 class Pipeline;
159
161
162 private:
163 static std::unordered_map<NeoCameraOutput*, osg::Geometry*>& previews();
164
165 private:
166 bool m_parametersUpdated;
167 NeoCameraLensRef m_lens;
168 NeoCameraSensorRef m_sensor;
169 NeoCameraOutputRefVector m_outputs;
170 agx::Real m_referenceIlluminance;
171 agxSDK::SimulationObserver m_simulation;
172
173 private:
174 std::unique_ptr<Pipeline> m_pipeline;
175 osg::Matrixd m_viewMatrix;
176 };
177
182 {
183 public:
184 enum DistortionModel : std::uint8_t
185 {
187 DISTORTION_BROWN_CONRADY
188 };
189
190 public:
196
201 void setFocalLength(agx::Real focalLength);
202
207
212 void setFStop(agx::Real fStop);
213
218
224 void setAutofocus(agx::Real minimumFocusDistance);
225
231 void setFocusDistance(agx::Real focusDistance);
232
236 bool isAutofocusEnabled() const;
237
242
247
252
262
267
272
273 private:
274 NeoCameraObserver m_camera;
275
276 agx::Real m_focalLength;
277 agx::Real m_fStop;
278
279 union
280 {
283 } m_focus;
284 bool m_autofocus;
285
286 DistortionModelParameters m_distortionModelParameters;
287 DistortionModel m_distortionModel;
288 };
289
294 {
295 public:
301
306 void setSize(const agx::Vec2& size);
307
312
317 void setResolution(const agx::Vec2i& resolution);
318
323
328 void setISO(agx::Real iso);
329
334
339 void setShutterSpeed(agx::Real shutterSpeed);
340
345
350 void setCircleOfConfusion(agx::Real circleOfConfusion);
351
356
362 void setManualExposureCompensation(agx::Real exposureCompensation);
363
369 void setAutoExposure(agx::Real dynamicRange);
370
375
380
385
386 private:
387 NeoCameraObserver m_camera;
388
390 agx::Vec2i m_resolution;
391 agx::Real m_iso;
392 agx::Real m_shutterSpeed;
393 agx::Real m_circleOfConfusion;
394
395 union
396 {
399 } m_exposure;
400 bool m_autoExposure;
401 };
402
407 {
408 public:
413
418
423
429
434
439
443 void capture();
444
452 bool hasUnreadData(bool markAsRead = true);
453
454 public:
455 friend class NeoCamera;
456
457 private:
458 void setLinkedCamera(NeoCamera* camera);
459
460 private:
461 NeoCameraObserver m_camera;
462
463 union
464 {
467 } m_capture;
468 bool m_constantCapture;
469 };
470
475 {
476 public:
481
486 void setTextureSize(const agx::Vec2i& size);
487
492
497 void setGamma(agx::Real gamma);
498
503
507 osg::Texture* getTexture() const;
508
509 private:
510 osg::ref_ptr<osg::Texture2D> m_texture;
511 agx::Real m_gamma;
512 };
513
518 {
519 public:
523 enum ChannelElementType : uint8_t
524 {
535 F64
536 };
537
538 public:
543 static size_t sizeOf(ChannelElementType type);
544
545 public:
550
555 void setImageSize(const agx::Vec2i& size);
556
560 const agx::Vec2i& getImageSize() const;
561
566 void setGamma(agx::Real gamma);
567
572
577 void setColorMappingMatrix(const osg::Matrixd& colorMapping);
578
582 const osg::Matrixd& getColorMappingMatrix() const;
583
589
594
600
605
609 size_t getElementSize() const;
610
616 void setExternalData(void* externalAddress = nullptr);
617
621 size_t getDataSize() const;
622
626 const void* getData() const;
627
631 template <typename T>
632 const T* viewData() const;
633
634 private:
635 void ensureDataSize();
636
637 private:
639 void* m_externalData;
641 agx::Real m_gamma;
642 osg::Matrixd m_colorMapping;
643 ChannelElementType m_type;
644 agx::UInt8 m_channels;
645 };
646
647 template <typename T>
649 {
650 if (sizeof(T) == getElementSize())
651 return reinterpret_cast<const T*>(getData());
652 else
653 return nullptr;
654 }
655}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXOSG_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
#define m_size
Definition: agx/Vector.h:429
Outputs the NeoCamera color feed to an image buffer of the specified format and color mapping matrix.
Definition: NeoCamera.h:518
ChannelElementType
Available per-channel type.
Definition: NeoCamera.h:524
static size_t sizeOf(ChannelElementType type)
const void * getData() const
void setImageSize(const agx::Vec2i &size)
Set the size of the output image.
const osg::Matrixd & getColorMappingMatrix() const
void setOutputChannels(agx::UInt8 channels)
Set the number of active output channels in the image.
void setExternalData(void *externalAddress=nullptr)
Set the color image output to write to the given external data instead of the internal buffer.
const agx::Vec2i & getImageSize() const
void setColorMappingMatrix(const osg::Matrixd &colorMapping)
Set the matrix mapping input colors into each output channel.
void setOutputChannelType(ChannelElementType type)
Set the element type for the channels.
NeoCameraColorImageOutput()
Initializes a color image output with a set of default parameters and an internal memory buffer.
ChannelElementType getOutputChannelType() const
agx::UInt8 getOutputChannels() const
void setGamma(agx::Real gamma)
Set the value for gamma correction of the post-mapping output.
Outputs the NeoCamera color feed to an OpenSceneGraph texture.
Definition: NeoCamera.h:475
NeoCameraColorTextureOutput()
Initializes a color texture output writing to an internal texture.
osg::Texture * getTexture() const
void setTextureSize(const agx::Vec2i &size)
Set the size of the output texture.
void setGamma(agx::Real gamma)
Set the value for gamma correction of the output.
Lens parameter specification for the NeoCamera.
Definition: NeoCamera.h:182
OptionalFocusMinimumDistance getMinimumFocusDistance() const
void setDistortionModelBrownConrady(agx::Real k1, agx::Real k2, agx::Real k3, agx::Real p1, agx::Real p2)
Set the distortion model to the five parameter Brown-Conrady model.
void setFocusDistance(agx::Real focusDistance)
Set the focus distance for manual focus control.
agx::Real getFStop() const
void setAutofocus(agx::Real minimumFocusDistance)
Set the minimum focus distance for lens autofocus.
void setFStop(agx::Real fStop)
Set the lens-aperture f-stop value.
void setFocalLength(agx::Real focalLength)
Set the lens focal length.
NeoCameraLens(NeoCamera *camera)
Initializes a camera lens with a default configuration of parameters.
OptionalFocusDistance getFocusDistance() const
const DistortionModelParameters & getDistortionModelParameters() const
DistortionModel getDistortionModel() const
agx::Real getFocalLength() const
void setDistortionModelNone()
Set the distortion model to no distortion.
agx::Real miniumDistance
Definition: NeoCamera.h:282
bool isAutofocusEnabled() const
Base type for the outputs of the NeoCamera.
Definition: NeoCamera.h:407
bool hasUnreadData(bool markAsRead=true)
NeoCamera * getCamera() const
void setConstantCapture(agx::Real framerate)
Set the output to constantly capture as a stream.
bool isConstantlyCapturing() const
void capture()
Tell the output to capture a frame.
OptionalFramerate getFramerate() const
NeoCameraOutput()
Default initialization of an output.
void setManualCapture()
Set the output to use manual frame-by-frame capture.
Sensor parameter specification for the NeoCamera.
Definition: NeoCamera.h:294
agx::Real getShutterSpeed() const
void setAutoExposure(agx::Real dynamicRange)
Set the sensor to use automatic exposure control.
void setResolution(const agx::Vec2i &resolution)
Set the sensor resolution.
OptionalExposureCompensation getExposureCompensation() const
agx::Vec2 getSize() const
void setCircleOfConfusion(agx::Real circleOfConfusion)
Set the acceptable circle of confusion for the sensor.
agx::Real getCircleOfConfusion() const
agx::Real getISO() const
void setShutterSpeed(agx::Real shutterSpeed)
Set the shutter speed of the sensor electronic shutter.
agx::Vec2i getResolution() const
void setManualExposureCompensation(agx::Real exposureCompensation)
Set the exposure compensation value for manual exposure control.
OptionalDynamicRange getDynamicRange() const
void setSize(const agx::Vec2 &size)
Set the sensor rectangular (physical) size.
bool hasAutoExposureEnabled() const
void setISO(agx::Real iso)
Set the amplifier ISO value for the sensor.
NeoCameraSensor(NeoCamera *camera)
Initializes a camera sensor with a set of default parameters.
A new (as of 2026) extended camera type, allowing for more "cinematic"-like effects.
Definition: NeoCamera.h:56
void setConnectedSimulation(agxSDK::Simulation *simulation)
Set the simulation to which this camera is connected and will sample the time from.
static void addPreviewTo(agxOSG::SceneDecorator *sceneDecorator, NeoCameraColorTextureOutput *output, const agx::Vec2 &position, const agx::Vec2 &size)
Add a preview of the given camera output in the given scene decorator.
bool add(NeoCameraOutput *output)
Add the given output to the camera.
void setReferenceIlluminance(agx::Real illuminance)
Set the reference illuminance value that a fully white pixel will correspond to.
NeoCameraLens * getLens() const
static void removePreviewFrom(agxOSG::SceneDecorator *sceneDecorator, NeoCameraColorTextureOutput *output)
Removes the preview of the given output from the given scene decorator.
agxSDK::Simulation * getConnectedSimulation() const
void registerToSceneGraph(osg::Group *sceneGraph, osg::Node *sceneNode)
Registers this camera to the given scene graph for processing.
NeoCamera()
Initializes the camera with a set of default parameters.
NeoCameraSensor * getSensor() const
agx::Real getReferenceIlluminance() const
void setViewMatrix(const osg::Matrixd &viewMatrix)
Set the view matrix of the camera.
bool remove(NeoCameraOutput *output)
Remove the given output from the camera.
static bool isSupported()
Decorates a scene with a specific AGX Rendering Style.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Base class providing referencing counted objects.
Definition: Referenced.h:120
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
std::optional< agx::Real > OptionalFramerate
Definition: NeoCamera.h:40
std::optional< agx::Real > OptionalFocusDistance
Definition: NeoCamera.h:37
std::optional< agx::Real > OptionalExposureCompensation
Definition: NeoCamera.h:35
std::optional< agx::Real > OptionalDynamicRange
Definition: NeoCamera.h:36
std::array< agx::Real, 5 > DistortionModelParameters
Definition: NeoCamera.h:39
std::optional< agx::Real > OptionalFocusMinimumDistance
Definition: NeoCamera.h:38
double Real
Definition: Real.h:41
uint8_t UInt8
Definition: Integer.h:30