diff --git a/src/esp/CMakeLists.txt b/src/esp/CMakeLists.txt index b878364cfd..74a1db58cc 100644 --- a/src/esp/CMakeLists.txt +++ b/src/esp/CMakeLists.txt @@ -457,23 +457,34 @@ set(nav_SOURCES ## sensor set( sensor_SOURCES + sensor/AudioSensor.cpp + sensor/AudioSensor.h + sensor/AudioSensorStubs.h sensor/CameraSensor.cpp sensor/CameraSensor.h sensor/CubeMapSensorBase.cpp sensor/CubeMapSensorBase.h + sensor/EquirectangularSensor.cpp + sensor/EquirectangularSensor.h + sensor/FisheyeSensor.cpp + sensor/FisheyeSensor.h + sensor/sensorManagers/SensorWrapperManager.cpp + sensor/sensorManagers/SensorWrapperManager.h + sensor/sensorManagers/SensorWrapperBaseManager.h + sensor/sensorWrappers/ManagedAudioSensor.h + sensor/sensorWrappers/ManagedCameraSensor.h + sensor/sensorWrappers/ManagedCubeMapSensorBase.h + sensor/sensorWrappers/ManagedEquirectangularSensor.h + sensor/sensorWrappers/ManagedFisheyeSensor.h + sensor/sensorWrappers/ManagedSensorBase.h + sensor/sensorWrappers/ManagedSensorTemplates.h + sensor/sensorWrappers/ManagedVisualSensorBase.h sensor/Sensor.cpp sensor/Sensor.h sensor/SensorFactory.cpp sensor/SensorFactory.h sensor/VisualSensor.cpp sensor/VisualSensor.h - sensor/FisheyeSensor.cpp - sensor/FisheyeSensor.h - sensor/EquirectangularSensor.cpp - sensor/EquirectangularSensor.h - sensor/AudioSensor.cpp - sensor/AudioSensor.h - sensor/AudioSensorStubs.h ) if(BUILD_WITH_CUDA) diff --git a/src/esp/physics/objectWrappers/ManagedArticulatedObject.h b/src/esp/physics/objectWrappers/ManagedArticulatedObject.h index 6c7b88c13d..3e5275e801 100644 --- a/src/esp/physics/objectWrappers/ManagedArticulatedObject.h +++ b/src/esp/physics/objectWrappers/ManagedArticulatedObject.h @@ -21,8 +21,8 @@ class ManagedArticulatedObject public: explicit ManagedArticulatedObject( const std::string& classKey = "ManagedArticulatedObject") - : AbstractManagedPhysicsObject( - classKey) {} + : AbstractManagedPhysicsObject:: + AbstractManagedPhysicsObject(classKey) {} /** * @brief Get a copy of the template attributes describing the initial state diff --git a/src/esp/sensor/AudioSensor.cpp b/src/esp/sensor/AudioSensor.cpp index 91afe8cb86..0f391c943b 100644 --- a/src/esp/sensor/AudioSensor.cpp +++ b/src/esp/sensor/AudioSensor.cpp @@ -78,7 +78,7 @@ void AudioSensor::reset() { impulseResponse_.clear(); } -void AudioSensor::setAudioSourceTransform(const Magnum::Vector3& sourcePos) { +void AudioSensor::setAudioSourceTransform(const Mn::Vector3& sourcePos) { ESP_DEBUG() << logHeader_ << "Setting the audio source position : " << sourcePos << "]"; lastSourcePos_ = sourcePos; @@ -86,9 +86,8 @@ void AudioSensor::setAudioSourceTransform(const Magnum::Vector3& sourcePos) { newSource_ = true; } -void AudioSensor::setAudioListenerTransform( - const Magnum::Vector3& agentPos, - const Magnum::Vector4& agentRotQuat) { +void AudioSensor::setAudioListenerTransform(const Mn::Vector3& agentPos, + const Mn::Vector4& agentRotQuat) { ESP_DEBUG() << logHeader_ << "Setting the agent transform : position [" << agentPos << "], rotQuat[" << agentRotQuat << "]"; diff --git a/src/esp/sensor/AudioSensor.h b/src/esp/sensor/AudioSensor.h index f55a9db740..575fbe29e3 100644 --- a/src/esp/sensor/AudioSensor.h +++ b/src/esp/sensor/AudioSensor.h @@ -68,15 +68,15 @@ class AudioSensor : public Sensor { * @brief Set the audio source transform * @param sourcePos = vec3 source position * */ - void setAudioSourceTransform(const Magnum::Vector3& sourcePos); + void setAudioSourceTransform(const Mn::Vector3& sourcePos); /** * @brief Set the audio listener position and orientation * @param agentPos = vec3 agent position * @param agentRotQuat = vec4 agent rotation quaternion * */ - void setAudioListenerTransform(const Magnum::Vector3& agentPos, - const Magnum::Vector4& agentRotQuat); + void setAudioListenerTransform(const Mn::Vector3& agentPos, + const Mn::Vector4& agentRotQuat); /** * @brief Run the audio simulation. This will run the RLRAudioPropagation code @@ -146,11 +146,11 @@ class AudioSensor : public Sensor { //! track the number of simulations std::int32_t currentSimCount_ = -1; //! track the source position - Magnum::Vector3 lastSourcePos_; + Mn::Vector3 lastSourcePos_; //! track the agent orientation - Magnum::Vector3 lastAgentPos_; + Mn::Vector3 lastAgentPos_; //! track the agent rotation - Magnum::Vector4 lastAgentRot_; + Mn::Vector4 lastAgentRot_; //! audio materials json path std::string audioMaterialsJSON_; diff --git a/src/esp/sensor/CameraSensor.cpp b/src/esp/sensor/CameraSensor.cpp index 9e1f53bd2d..d5812d2229 100644 --- a/src/esp/sensor/CameraSensor.cpp +++ b/src/esp/sensor/CameraSensor.cpp @@ -69,8 +69,8 @@ Mn::Matrix4 CameraSensorSpec::projectionMatrix() const { CameraSensor::CameraSensor(scene::SceneNode& cameraNode, const CameraSensorSpec::ptr& spec) : VisualSensor(cameraNode, spec), - baseProjMatrix_(Magnum::Math::IdentityInit), - zoomMatrix_(Magnum::Math::IdentityInit), + baseProjMatrix_(Mn::Math::IdentityInit), + zoomMatrix_(Mn::Math::IdentityInit), renderCamera_(new gfx::RenderCamera(cameraNode, visualSensorSpec_->semanticTarget)) { // Sanity check @@ -177,8 +177,7 @@ bool CameraSensor::drawObservation(sim::Simulator& sim) { return true; } -Corrade::Containers::Optional CameraSensor::depthUnprojection() - const { +Cr::Containers::Optional CameraSensor::depthUnprojection() const { // projectionMatrix_ is managed by implementation class and is set whenever // quantities change. return {gfx_batch::calculateDepthUnprojection(projectionMatrix_)}; diff --git a/src/esp/sensor/CameraSensor.h b/src/esp/sensor/CameraSensor.h index 307f81ca4f..edfb04faaf 100644 --- a/src/esp/sensor/CameraSensor.h +++ b/src/esp/sensor/CameraSensor.h @@ -21,7 +21,7 @@ struct CameraSensorSpec : public VisualSensorSpec { CameraSensorSpec(); void sanityCheck() const override; bool operator==(const CameraSensorSpec& a) const; - Magnum::Matrix4 projectionMatrix() const; + Mn::Matrix4 projectionMatrix() const; ESP_SMART_POINTERS(CameraSensorSpec) }; @@ -50,8 +50,7 @@ class CameraSensor : public VisualSensor { * perspective projection model. * See @ref gfx::calculateDepthUnprojection */ - Corrade::Containers::Optional depthUnprojection() - const override; + Cr::Containers::Optional depthUnprojection() const override; /** * @brief Draw an observation to the frame buffer using simulator's renderer @@ -66,8 +65,7 @@ class CameraSensor : public VisualSensor { * @param factor Modification amount. */ void modifyZoom(float factor) { - zoomMatrix_ = - Magnum::Matrix4::scaling({factor, factor, 1.0f}) * zoomMatrix_; + zoomMatrix_ = Mn::Matrix4::scaling({factor, factor, 1.0f}) * zoomMatrix_; recomputeProjectionMatrix(); } @@ -76,7 +74,7 @@ class CameraSensor : public VisualSensor { * values. */ void resetZoom() { - zoomMatrix_ = Magnum::Matrix4(Magnum::Math::IdentityInit); + zoomMatrix_ = Mn::Matrix4(Mn::Math::IdentityInit); recomputeProjectionMatrix(); } @@ -197,17 +195,17 @@ class CameraSensor : public VisualSensor { * @brief This camera's projection matrix. Should be recomputed every time * size changes. */ - Magnum::Matrix4 projectionMatrix_; + Mn::Matrix4 projectionMatrix_; /** * @brief A base projection matrix based on camera's type and display size. */ - Magnum::Matrix4 baseProjMatrix_; + Mn::Matrix4 baseProjMatrix_; /** * @brief A matrix to determine the zoom for the projection. */ - Magnum::Matrix4 zoomMatrix_; + Mn::Matrix4 zoomMatrix_; /** @brief size of near plane */ diff --git a/src/esp/sensor/CubeMapSensorBase.cpp b/src/esp/sensor/CubeMapSensorBase.cpp index 45f4f6ab59..4f317c50d6 100644 --- a/src/esp/sensor/CubeMapSensorBase.cpp +++ b/src/esp/sensor/CubeMapSensorBase.cpp @@ -8,9 +8,6 @@ #include #include -namespace Mn = Magnum; -namespace Cr = Corrade; - namespace esp { namespace sensor { @@ -28,11 +25,11 @@ void CubeMapSensorBaseSpec::sanityCheck() const { } } -int computeCubemapSize(const Magnum::Vector2i& resolution, +int computeCubemapSize(const Mn::Vector2i& resolution, const Cr::Containers::Optional& cubemapSize) { int size = (resolution[0] < resolution[1] ? resolution[0] : resolution[1]); // if user sets the size of the cubemap, use it - if (cubemapSize != Corrade::Containers::NullOpt) { + if (cubemapSize != Cr::Containers::NullOpt) { size = *cubemapSize; } return size; diff --git a/src/esp/sensor/CubeMapSensorBase.h b/src/esp/sensor/CubeMapSensorBase.h index eb1beafae1..0c7efdddac 100644 --- a/src/esp/sensor/CubeMapSensorBase.h +++ b/src/esp/sensor/CubeMapSensorBase.h @@ -26,7 +26,7 @@ struct CubeMapSensorBaseSpec : public VisualSensorSpec { /** * @brief the size of the cubemap */ - Corrade::Containers::Optional cubemapSize = Corrade::Containers::NullOpt; + Cr::Containers::Optional cubemapSize = Cr::Containers::NullOpt; /** * @brief Constructor @@ -75,22 +75,22 @@ class CubeMapSensorBase : public VisualSensor { // raw pointer only, we can create it but let magnum to handle the memory // recycling when releasing it. gfx::CubeMapCamera* cubeMapCamera_; - Corrade::Containers::Optional cubeMap_; + Cr::Containers::Optional cubeMap_; // a big triangles that covers the whole screen - Magnum::GL::Mesh mesh_; + Mn::GL::Mesh mesh_; // cubemap shader resource manager, which manages different shaders such as // DoubleSphereCameraShader, FieldOfViewCameraShader (TODO), // EquiRectangularShader ... - Magnum::ResourceManager cubeMapShaderBaseManager_; + Mn::ResourceManager cubeMapShaderBaseManager_; gfx::CubeMapShaderBase::Flags cubeMapShaderBaseFlags_{}; - virtual Magnum::ResourceKey getShaderKey() = 0; + virtual Mn::ResourceKey getShaderKey() = 0; template - Magnum::Resource getShader(); + Mn::Resource getShader(); /** * @brief render the sense into cubemap textures @@ -108,8 +108,8 @@ class CubeMapSensorBase : public VisualSensor { }; template -Magnum::Resource CubeMapSensorBase::getShader() { - Magnum::Resource shader = +Mn::Resource CubeMapSensorBase::getShader() { + Mn::Resource shader = cubeMapShaderBaseManager_.get(getShaderKey()); if (!shader) { cubeMapShaderBaseManager_.set( diff --git a/src/esp/sensor/EquirectangularSensor.cpp b/src/esp/sensor/EquirectangularSensor.cpp index 4853058d37..d32a460273 100644 --- a/src/esp/sensor/EquirectangularSensor.cpp +++ b/src/esp/sensor/EquirectangularSensor.cpp @@ -9,9 +9,6 @@ #include "esp/gfx/EquirectangularShader.h" #include "esp/sim/Simulator.h" -namespace Mn = Magnum; -namespace Cr = Corrade; - namespace esp { namespace sensor { @@ -40,7 +37,7 @@ bool EquirectangularSensor::drawObservation(sim::Simulator& sim) { return false; } renderToCubemapTexture(sim); - Magnum::Resource shader = + Mn::Resource shader = getShader(); (*shader).setViewportSize(equirectangularSensorSpec_->resolution); diff --git a/src/esp/sensor/EquirectangularSensor.h b/src/esp/sensor/EquirectangularSensor.h index 512e68000c..88f242353d 100644 --- a/src/esp/sensor/EquirectangularSensor.h +++ b/src/esp/sensor/EquirectangularSensor.h @@ -73,7 +73,7 @@ class EquirectangularSensor : public CubeMapSensorBase { protected: EquirectangularSensorSpec::ptr equirectangularSensorSpec_ = std::dynamic_pointer_cast(spec_); - Magnum::ResourceKey getShaderKey() override; + Mn::ResourceKey getShaderKey() override; ESP_SMART_POINTERS(EquirectangularSensor) }; diff --git a/src/esp/sensor/FisheyeSensor.cpp b/src/esp/sensor/FisheyeSensor.cpp index 86dc85cdf0..02b040bd17 100644 --- a/src/esp/sensor/FisheyeSensor.cpp +++ b/src/esp/sensor/FisheyeSensor.cpp @@ -8,9 +8,6 @@ #include #include -namespace Mn = Magnum; -namespace Cr = Corrade; - namespace esp { namespace sensor { @@ -48,7 +45,7 @@ void specSanityCheck(FisheyeSensorSpec* spec) { actualSpec->sanityCheck(); } -Magnum::Vector2 computePrincipalPointOffset(const FisheyeSensorSpec& spec) { +Mn::Vector2 computePrincipalPointOffset(const FisheyeSensorSpec& spec) { if (bool(spec.principalPointOffset)) { return *spec.principalPointOffset; } @@ -86,7 +83,7 @@ bool FisheyeSensor::drawObservation(sim::Simulator& sim) { switch (fisheyeSensorSpec_->fisheyeModelType) { case FisheyeSensorModelType::DoubleSphere: { - Magnum::Resource + Mn::Resource shader = getShader(); auto& actualSpec = static_cast(*fisheyeSensorSpec_); diff --git a/src/esp/sensor/FisheyeSensor.h b/src/esp/sensor/FisheyeSensor.h index 9e00f927ac..ed6f74d5d3 100644 --- a/src/esp/sensor/FisheyeSensor.h +++ b/src/esp/sensor/FisheyeSensor.h @@ -24,7 +24,7 @@ class Simulator; namespace sensor { -enum class FisheyeSensorModelType : Magnum::UnsignedInt { +enum class FisheyeSensorModelType : Mn::UnsignedInt { // Vladyslav Usenko, Nikolaus Demmel and Daniel Cremers: The Double Sphere // Camera Model, The International Conference on 3D Vision (3DV), 2018 @@ -46,13 +46,13 @@ struct FisheyeSensorSpec : public CubeMapSensorBaseSpec { * In practice, fx and fy can differ for a number of reasons. See * details here: http://ksimek.github.io/2013/08/13/intrinsic/ */ - Magnum::Vector2 focalLength; + Mn::Vector2 focalLength; /** * @brief Principal Point Offset in pixel, cx, cy, location of the principal * point relative to the image plane's origin. None will place it in the * middle of the image (height/2, width/2). */ - Corrade::Containers::Optional principalPointOffset; + Cr::Containers::Optional principalPointOffset; /** * @brief Constructor @@ -127,7 +127,7 @@ class FisheyeSensor : public CubeMapSensorBase { protected: FisheyeSensorSpec::ptr fisheyeSensorSpec_ = std::dynamic_pointer_cast(spec_); - Magnum::ResourceKey getShaderKey() override; + Mn::ResourceKey getShaderKey() override; ESP_SMART_POINTERS(FisheyeSensor) }; diff --git a/src/esp/sensor/Sensor.cpp b/src/esp/sensor/Sensor.cpp index 366c45ed9a..82b68eab47 100644 --- a/src/esp/sensor/Sensor.cpp +++ b/src/esp/sensor/Sensor.cpp @@ -8,7 +8,6 @@ #include -namespace Mn = Magnum; namespace esp { namespace sensor { @@ -44,7 +43,7 @@ void SensorSpec::sanityCheck() const { } Sensor::Sensor(scene::SceneNode& node, SensorSpec::ptr spec) - : Magnum::SceneGraph::AbstractFeature3D{node}, spec_(std::move(spec)) { + : Mn::SceneGraph::AbstractFeature3D{node}, spec_(std::move(spec)) { CORRADE_ASSERT(node.children().first() == nullptr, "Sensor::Sensor(): Cannot attach a sensor to a non-LEAF node. " "The number of children of this node is not zero.", ); @@ -71,11 +70,11 @@ Sensor::~Sensor() { scene::SceneNode& Sensor::object() { return static_cast( - Magnum::SceneGraph::AbstractFeature3D::object()); + Mn::SceneGraph::AbstractFeature3D::object()); } const scene::SceneNode& Sensor::object() const { return static_cast( - Magnum::SceneGraph::AbstractFeature3D::object()); + Mn::SceneGraph::AbstractFeature3D::object()); } void Sensor::setTransformationFromSpec() { @@ -86,21 +85,21 @@ void Sensor::setTransformationFromSpec() { node().resetTransformation(); node().translate(spec_->position); - node().rotateX(Magnum::Rad(spec_->orientation[0])); - node().rotateY(Magnum::Rad(spec_->orientation[1])); - node().rotateZ(Magnum::Rad(spec_->orientation[2])); + node().rotateX(Mn::Rad(spec_->orientation[0])); + node().rotateY(Mn::Rad(spec_->orientation[1])); + node().rotateZ(Mn::Rad(spec_->orientation[2])); } SensorSuite::SensorSuite(scene::SceneNode& node) - : Magnum::SceneGraph::AbstractFeature3D{node} {} + : Mn::SceneGraph::AbstractFeature3D{node} {} scene::SceneNode& SensorSuite::object() { return static_cast( - Magnum::SceneGraph::AbstractFeature3D::object()); + Mn::SceneGraph::AbstractFeature3D::object()); } const scene::SceneNode& SensorSuite::object() const { return static_cast( - Magnum::SceneGraph::AbstractFeature3D::object()); + Mn::SceneGraph::AbstractFeature3D::object()); } void SensorSuite::add(sensor::Sensor& sensor) { diff --git a/src/esp/sensor/Sensor.h b/src/esp/sensor/Sensor.h index 80d279b635..7545068d7a 100644 --- a/src/esp/sensor/Sensor.h +++ b/src/esp/sensor/Sensor.h @@ -6,12 +6,15 @@ #define ESP_SENSOR_SENSOR_H_ #include +#include #include #include "esp/core/Buffer.h" #include "esp/core/Esp.h" #include "esp/sensor/configure.h" +namespace Mn = Magnum; +namespace Cr = Corrade; namespace esp { namespace scene { class SceneNode; @@ -58,8 +61,8 @@ struct SensorSpec { std::string uuid = ""; SensorType sensorType = SensorType::Unspecified; SensorSubType sensorSubType = SensorSubType::Unspecified; - Magnum::Vector3 position = {0, 1.5, 0}; - Magnum::Vector3 orientation = {0, 0, 0}; + Mn::Vector3 position = {0, 1.5, 0}; + Mn::Vector3 orientation = {0, 0, 0}; std::string noiseModel = "None"; SensorSpec() = default; virtual ~SensorSpec() = default; @@ -86,7 +89,7 @@ struct ObservationSpace { }; // Represents a sensor that provides data from the environment -class Sensor : public Magnum::SceneGraph::AbstractFeature3D { +class Sensor : public Mn::SceneGraph::AbstractFeature3D { public: explicit Sensor(scene::SceneNode& node, SensorSpec::ptr spec); ~Sensor() override; @@ -120,6 +123,16 @@ class Sensor : public Magnum::SceneGraph::AbstractFeature3D { */ void setTransformationFromSpec(); + /** + * @brief The unique handle assigned to this sensor at creation + */ + std::string getSensorHandle() const { return sensorHandle_; } + + /** + * @brief The unique ID assigned to this sensor at creation + */ + int getSensorID() const { return sensorId_; } + /** * @brief Draws an observation to the frame buffer using simulator's renderer, * then reads the observation to the sensor's memory buffer @@ -150,6 +163,11 @@ class Sensor : public Magnum::SceneGraph::AbstractFeature3D { virtual bool displayObservation(sim::Simulator& sim) = 0; protected: + // unique handle for sensor built when sensor is constructed. + std::string sensorHandle_; + + // unique id for sensor set when sensor is built. + int sensorId_ = ID_UNDEFINED; SensorSpec::ptr spec_ = nullptr; core::Buffer::ptr buffer_ = nullptr; @@ -158,7 +176,7 @@ class Sensor : public Magnum::SceneGraph::AbstractFeature3D { // Represents a set of sensors, with each sensor being identified through a // unique id -class SensorSuite : public Magnum::SceneGraph::AbstractFeature3D { +class SensorSuite : public Mn::SceneGraph::AbstractFeature3D { public: explicit SensorSuite(scene::SceneNode& node); diff --git a/src/esp/sensor/VisualSensor.cpp b/src/esp/sensor/VisualSensor.cpp index 7538f548d4..70c5d833e7 100644 --- a/src/esp/sensor/VisualSensor.cpp +++ b/src/esp/sensor/VisualSensor.cpp @@ -110,16 +110,16 @@ void VisualSensor::readObservation(Observation& obs) { // TODO: have different classes for the different types of sensors // TODO: do we need to flip axis? if (visualSensorSpec_->sensorType == SensorType::Semantic) { - renderTarget().readFrameObjectId(Magnum::MutableImageView2D{ - Magnum::PixelFormat::R32UI, renderTarget().framebufferSize(), + renderTarget().readFrameObjectId(Mn::MutableImageView2D{ + Mn::PixelFormat::R32UI, renderTarget().framebufferSize(), obs.buffer->data}); } else if (visualSensorSpec_->sensorType == SensorType::Depth) { - renderTarget().readFrameDepth(Magnum::MutableImageView2D{ - Magnum::PixelFormat::R32F, renderTarget().framebufferSize(), + renderTarget().readFrameDepth(Mn::MutableImageView2D{ + Mn::PixelFormat::R32F, renderTarget().framebufferSize(), obs.buffer->data}); } else { - renderTarget().readFrameRgba(Magnum::MutableImageView2D{ - Magnum::PixelFormat::RGBA8Unorm, renderTarget().framebufferSize(), + renderTarget().readFrameRgba(Mn::MutableImageView2D{ + Mn::PixelFormat::RGBA8Unorm, renderTarget().framebufferSize(), obs.buffer->data}); } } diff --git a/src/esp/sensor/VisualSensor.h b/src/esp/sensor/VisualSensor.h index 4321fa340e..d4bedf5cc3 100644 --- a/src/esp/sensor/VisualSensor.h +++ b/src/esp/sensor/VisualSensor.h @@ -15,9 +15,6 @@ #include "esp/gfx/RenderCamera.h" #include "esp/sensor/Sensor.h" -namespace Mn = Magnum; -namespace Cr = Corrade; - namespace esp { namespace gfx { class RenderTarget; @@ -81,7 +78,7 @@ class VisualSensor : public Sensor { * @brief Return the size of the framebuffer corresponding to the sensor's * resolution as a [W, H] Vector2i */ - Magnum::Vector2i framebufferSize() const { + Mn::Vector2i framebufferSize() const { // NB: The sensor's resolution is in H x W format as that more cleanly // corresponds to the practice of treating images as arrays that is used in // modern CV and DL. However, graphics frameworks expect W x H format for @@ -103,8 +100,7 @@ class VisualSensor : public Sensor { /** * @brief Returns the parameters needed to unproject depth for the sensor. */ - virtual Corrade::Containers::Optional depthUnprojection() - const; + virtual Cr::Containers::Optional depthUnprojection() const; /** * @brief Checks to see if this sensor has a RenderTarget bound or not @@ -173,7 +169,7 @@ class VisualSensor : public Sensor { visualSensorSpec_->resolution = {height, width}; } - void setResolution(const Magnum::Vector2i& resolution) { + void setResolution(const Mn::Vector2i& resolution) { CORRADE_ASSERT(resolution[0] > 0 && resolution[1] > 0, "VisualSensor::setResolution(): resolution height and " "width must be greater than 0", ); @@ -250,8 +246,8 @@ class VisualSensor : public Sensor { protected: VisualSensor& visualSensor_; sim::Simulator& sim_; - Corrade::Containers::Optional relativeTransformBackup_ = - Corrade::Containers::NullOpt; + Cr::Containers::Optional relativeTransformBackup_ = + Cr::Containers::NullOpt; scene::SceneNode* semanticSensorParentNodeBackup_ = nullptr; }; diff --git a/src/esp/sensor/sensorManagers/SensorWrapperBaseManager.h b/src/esp/sensor/sensorManagers/SensorWrapperBaseManager.h new file mode 100644 index 0000000000..eb211ee4bf --- /dev/null +++ b/src/esp/sensor/sensorManagers/SensorWrapperBaseManager.h @@ -0,0 +1,172 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_SENSORWRAPPERBASEMANAGER_H_ +#define ESP_SENSOR_SENSORWRAPPERBASEMANAGER_H_ + +/** @file + * @brief Class Template @ref esp::sensor::SensorWrapperBaseManager + */ + +#include "esp/core/managedContainers/ManagedContainer.h" +#include "esp/sensor/sensorWrappers/ManagedSensorBase.h" + +namespace esp { +namespace core { +namespace managedContainers { +enum class ManagedObjectAccess; +class ManagedContainerBase; +} // namespace managedContainers +} // namespace core +namespace sensor { + +/** + * @brief Class template defining responsibilities and functionality for + * managineg sensor wrappers specializing @ref + * esp::sensor::AbstractManagedSensor template. + * @tparam T the type of managed sensor object wrapper a particular + * specialization of this class works with. Must inherit from @ref + * esp::sensor::AbstractManagedSensor + */ +template +class SensorWrapperBaseManager + : public esp::core::managedContainers::ManagedContainer< + T, + core::managedContainers::ManagedObjectAccess::Copy> { + public: + static_assert(std::is_base_of::value, + "AbstractManagedSensor :: Managed sensor object type must be " + "derived from esp::sensor::Sensor"); + + typedef std::shared_ptr ObjWrapperPtr; + explicit SensorWrapperBaseManager(const std::string& SensorType) + : core::managedContainers::ManagedContainer< + T, + core::managedContainers::ManagedObjectAccess::Copy>:: + ManagedContainer(SensorType) {} + ~SensorWrapperBaseManager() override = default; + + /** + * @brief Creates an empty @ref esp::sensor::AbstractManagedSensor of + * the type managed by this manager. + * + * @param sensorTypeName Class name of the wrapper to create. This will be + * used as a key in @p managedSensorTypeConstructorMap_. + * @param registerObject whether to add this managed object to the + * library or not. If the user is going to edit this managed object, this + * should be false. Defaults to true. If specified as true, then this function + * returns a copy of the registered managed object. + * @return a reference to the desired managed object. + */ + ObjWrapperPtr createObject( + const std::string& sensorTypeName, + CORRADE_UNUSED bool registerObject = false) override; + + protected: + /** + * @brief Any sensor-wrapper-specific resetting that needs to happen + * on reset. + */ + void resetFinalize() override {} + + /** + * @brief Build a shared pointer to a AbstractManagedSensor wrapper around an + * appropriately cast @ref esp::sensor::Sensor. + * @tparam The type of the underlying wrapped object to create + */ + template + ObjWrapperPtr createSensorObjectWrapper() { + return U::create(); + } + + /** + * @brief Used Internally. Create and configure newly-created managed object + * with any default values, before any specific values are set. + * + * @param sensorTypeName Used to determine what kind of Rigid Object wrapper + * to make (either kinematic or dynamic-library-specific) + * @param builtFromConfig Unused for wrapper objects. All wrappers are + * constructed from scratch. + * @return Newly created but unregistered ManagedObject pointer, with only + * default values set. + */ + ObjWrapperPtr initNewObjectInternal( + const std::string& sensorTypeName, + CORRADE_UNUSED bool builtFromConfig) override { + // construct a new wrapper based on the passed object + auto mgdSensorTypeCtorMapIter = + managedSensorTypeConstructorMap_.find(sensorTypeName); + if (mgdSensorTypeCtorMapIter == managedSensorTypeConstructorMap_.end()) { + ESP_ERROR(Mn::Debug::Flag::NoSpace) + << "<" << this->objectType_ << "> Unknown constructor type " + << sensorTypeName << ", so initNewObject aborted."; + return nullptr; + } + auto newWrapper = (*this.*(mgdSensorTypeCtorMapIter->second))(); + + return newWrapper; + } // RigidObjectManager::initNewObjectInternal( + + /** + * @brief Not required for this manager. + * + * This method will perform any essential updating to the managed object + * before registration is performed. If this updating fails, registration will + * also fail. + * @param object the managed object to be registered + * @param objectHandle the name to register the managed object with. + * Expected to be valid. + * @param forceRegistration Will register object even if conditional + * registration checks fail. + * @return Whether the preregistration has succeeded and what handle to use to + * register the object if it has. + */ + core::managedContainers::ManagedObjectPreregistration + preRegisterObjectFinalize(CORRADE_UNUSED ObjWrapperPtr object, + CORRADE_UNUSED const std::string& objectHandle, + CORRADE_UNUSED bool forceRegistration) override { + // No pre-registration conditioning performed + return core::managedContainers::ManagedObjectPreregistration::Success; + } + + /** + * @brief Not required for this manager. + * + * This method will perform any final manager-related handling after + * successfully registering an object. + * + * See @ref esp::attributes::managers::ObjectAttributesManager for an example. + * + * @param objectID the ID of the successfully registered managed object + * @param objectHandle The name of the managed object + */ + void postRegisterObjectHandling( + CORRADE_UNUSED int objectID, + CORRADE_UNUSED const std::string& objectHandle) override {} + + // ====== instance variables ===== + /** @brief Define a map type referencing function pointers to @ref + * createRigidObjectWrapper() keyed by string names of classes being + * instanced + */ + typedef std::map::*)()> + Map_Of_ManagedObjTypeCtors; + + /** @brief Map of function pointers to instantiate a @ref + * esp::sensor::AbstractManagedSensor wrapper object, keyed by the + * wrapper's class name. A ManagedRigidObject wrapper of the appropriate type + * is instanced by accessing the constructor map with the appropriate + * classname. + */ + Map_Of_ManagedObjTypeCtors managedSensorTypeConstructorMap_; + + public: + ESP_SMART_POINTERS(SensorWrapperBaseManager) +}; // class SensorWrapperBaseManager + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_SENSORWRAPPERBASEMANAGER_H_ diff --git a/src/esp/sensor/sensorManagers/SensorWrapperManager.cpp b/src/esp/sensor/sensorManagers/SensorWrapperManager.cpp new file mode 100644 index 0000000000..cf68abdafd --- /dev/null +++ b/src/esp/sensor/sensorManagers/SensorWrapperManager.cpp @@ -0,0 +1,20 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#include "SensorWrapperManager.h" + +namespace esp { +namespace sensor { + +SensorWrapperManager::SensorWrapperManager() + : SensorWrapperBaseManager< + esp::sensor::ManagedSensorBase>::SensorWrapperBaseManager("Sensor") { + this->copyConstructorMap_["ManagedAudioSensor"] = + &SensorWrapperManager::createObjCopyCtorMapEntry< + esp::sensor::ManagedAudioSensor>; + +} // SensorWrapperManager ctor + +} // namespace sensor +} // namespace esp diff --git a/src/esp/sensor/sensorManagers/SensorWrapperManager.h b/src/esp/sensor/sensorManagers/SensorWrapperManager.h new file mode 100644 index 0000000000..5d1d820d36 --- /dev/null +++ b/src/esp/sensor/sensorManagers/SensorWrapperManager.h @@ -0,0 +1,26 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_SENSORWRAPPERMANAGER_H_ +#define ESP_SENSOR_SENSORWRAPPERMANAGER_H_ + +#include "SensorWrapperBaseManager.h" +#include "esp/sensor/sensorWrappers/ManagedAudioSensor.h" +#include "esp/sensor/sensorWrappers/ManagedSensorBase.h" + +namespace esp { +namespace sensor { + +class SensorWrapperManager + : public SensorWrapperBaseManager { + public: + explicit SensorWrapperManager(); + + public: + ESP_SMART_POINTERS(SensorWrapperManager) +}; // class SensorWrapperManager + +} // namespace sensor +} // namespace esp +#endif // ESP_SENSOR_SENSORWRAPPERMANAGER_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedAudioSensor.h b/src/esp/sensor/sensorWrappers/ManagedAudioSensor.h new file mode 100644 index 0000000000..c1b3a90ee5 --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedAudioSensor.h @@ -0,0 +1,52 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDAUDIOSENSOR_H_ +#define ESP_SENSOR_MANAGEDAUDIOSENSOR_H_ + +#include "ManagedSensorTemplates.h" +#include "esp/sensor/AudioSensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class for wrapper for sensor objects of all kinds to + * enable Managed Container access. + */ +class ManagedAudioSensor + : public esp::sensor::AbstractManagedSensor { + public: + explicit ManagedAudioSensor() + : AbstractManagedSensor::AbstractManagedSensor( + "ManagedAudioSensor") {} + + // TODO Add appropriate audio sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed object, type-specific. + */ + + std::string getSensorObjInfoHeaderInternal() const override { + return "Output Directory"; + } + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + std::string getSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) const override { + // TODO provide info stream for sensors + return ""; + } + + public: + ESP_SMART_POINTERS(ManagedAudioSensor) +}; // class ManagedAudioSensor +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDAUDIOSENSOR_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedCameraSensor.h b/src/esp/sensor/sensorWrappers/ManagedCameraSensor.h new file mode 100644 index 0000000000..58a99c4a3c --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedCameraSensor.h @@ -0,0 +1,54 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDCAMERASENSOR_H_ +#define ESP_SENSOR_MANAGEDCAMERASENSOR_H_ + +#include "ManagedVisualSensorBase.h" +#include "esp/sensor/CameraSensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class for wrapper for camera sensor objects + */ +class ManagedCameraSensor : public AbstractManagedVisualSensor { + public: + explicit ManagedCameraSensor( + const std::string& classKey = "ManagedCameraSensor") + : AbstractManagedVisualSensor::AbstractManagedVisualSensor( + classKey) {} + + // TODO Add appropriate camera sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed visual sensor, type-specific. + */ + std::string getVisualSensorObjInfoHeaderInternal() const override { + return ""; + } + + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + + std::string getVisualSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) + const override { + // TODO provide info stream for sensors + return ""; + } + + public: + ESP_SMART_POINTERS(ManagedCameraSensor) +}; // class ManagedCameraSensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDCAMERASENSOR_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedCubeMapSensorBase.h b/src/esp/sensor/sensorWrappers/ManagedCubeMapSensorBase.h new file mode 100644 index 0000000000..a8ba4b86ca --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedCubeMapSensorBase.h @@ -0,0 +1,74 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDCUBEMAPSENSORBASE_H_ +#define ESP_SENSOR_MANAGEDCUBEMAPSENSORBASE_H_ + +#include "ManagedVisualSensorBase.h" +#include "esp/sensor/CubeMapSensorBase.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class Template for wrapper for CubeMap sensor objects + */ +template +class AbstractManagedCubeMapSensorBase + : public esp::sensor::AbstractManagedVisualSensor { + public: + static_assert( + std::is_base_of::value, + "AbstractManagedCubeMapSensorBase :: Managed CubeMap sensor object " + "type must be derived from esp::sensor::CubeMapSensorBase"); + + explicit AbstractManagedCubeMapSensorBase(const std::string& classKey) + : AbstractManagedVisualSensor(classKey) {} + + // TODO Add appropriate camera sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed visual sensor, type-specific. + */ + std::string getVisualSensorObjInfoHeaderInternal() const override { + return "" + getCubeMapSensorObjInfoHeaderInternal(); + } + + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed visual sensor, type-specific. + */ + + virtual std::string getCubeMapSensorObjInfoHeaderInternal() const = 0; + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + + std::string getVisualSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) const override { + // TODO provide info stream for sensors + std::string res = + Cr::Utility::formatString("{},", getCubeMapSensorObjInfoInternal()); + + return res; + } + + /** + * @brief Specialization-specific extension of getSensorObjInfoInternal, comma + * separated info ideal for saving to csv + */ + virtual std::string getCubeMapSensorObjInfoInternal( + std::shared_ptr& sp) const = 0; + + public: + ESP_SMART_POINTERS(AbstractManagedCubeMapSensorBase) +}; // class ManagedCubeMapSensorBase + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDCUBEMAPSENSORBASE_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedEquirectangularSensor.h b/src/esp/sensor/sensorWrappers/ManagedEquirectangularSensor.h new file mode 100644 index 0000000000..da8b67a824 --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedEquirectangularSensor.h @@ -0,0 +1,58 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDEQUIRECTANGULARSENSOR_H_ +#define ESP_SENSOR_MANAGEDEQUIRECTANGULARSENSOR_H_ + +#include "ManagedCubeMapSensorBase.h" +#include "esp/sensor/EquirectangularSensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class for wrapper for sensor objects of all kinds to + * enable Managed Container access. + */ +class ManagedEquirectangularSensor + : public AbstractManagedCubeMapSensorBase { + public: + explicit ManagedEquirectangularSensor( + const std::string& classKey = "ManagedEquirectangularSensor") + : AbstractManagedCubeMapSensorBase< + EquirectangularSensor>::AbstractManagedCubeMapSensorBase(classKey) { + } + + // TODO Add appropriate equirectangular sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed Equirectangular CubeMap sensor, + * type-specific. + */ + std::string getCubeMapSensorObjInfoHeaderInternal() const override { + return ""; + } + + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + + std::string getCubeMapSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) + const override { + // TODO provide info stream for sensors + return ""; + } + + public: + ESP_SMART_POINTERS(ManagedEquirectangularSensor) +}; // namespace sensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDEQUIRECTANGULARSENSOR_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedFisheyeSensor.h b/src/esp/sensor/sensorWrappers/ManagedFisheyeSensor.h new file mode 100644 index 0000000000..5878cd51c4 --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedFisheyeSensor.h @@ -0,0 +1,55 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDFISHEYESENSOR_H_ +#define ESP_SENSOR_MANAGEDFISHEYESENSOR_H_ + +#include "ManagedCubeMapSensorBase.h" +#include "esp/sensor/FisheyeSensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class for wrapper for sensor objects of all kinds to + * enable Managed Container access. + */ +class ManagedFisheyeSensor + : public AbstractManagedCubeMapSensorBase { + public: + explicit ManagedFisheyeSensor( + const std::string& classKey = "ManagedFisheyeSensor") + : AbstractManagedCubeMapSensorBase< + FisheyeSensor>::AbstractManagedCubeMapSensorBase(classKey) {} + + // TODO Add appropriate fisheye sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed visual sensor, type-specific. + */ + std::string getCubeMapSensorObjInfoHeaderInternal() const override { + return ""; + } + + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + + std::string getCubeMapSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) const override { + // TODO provide info stream for sensors + return ""; + } + + public: + ESP_SMART_POINTERS(ManagedFisheyeSensor) +}; // namespace sensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDFISHEYESENSOR_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedSensorBase.h b/src/esp/sensor/sensorWrappers/ManagedSensorBase.h new file mode 100644 index 0000000000..88f293fbd1 --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedSensorBase.h @@ -0,0 +1,125 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDSENSORBASE_H_ +#define ESP_SENSOR_MANAGEDSENSORBASE_H_ + +#include +#include + +#include "esp/core/managedContainers/AbstractManagedObject.h" +#include "esp/sensor/Sensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Base class for wrappers of sensor objects of all kinds to enable + * Managed Container access. + */ +class ManagedSensorBase + : public esp::core::managedContainers::AbstractManagedObject { + public: + explicit ManagedSensorBase(const std::string& classKey) { + ManagedSensorBase::setClassKey(classKey); + } + ~ManagedSensorBase() override = default; + /** + * @brief Get the instancing class of the ManagedSensorBase instance. Should + * only be set from implementer's constructor. Used as key in constructor + * function pointer maps in @ref + * esp::core::managedContainers::ManagedContainer. + */ + std::string getClassKey() const override { return classKey_; } + + /** + * @brief Managed Sensor objects manage their own handles, so this is + * currently unsettable. + */ + void setHandle(CORRADE_UNUSED const std::string& name) override {} + + /** + * @brief Retrieve this Managed Sensor object's unique handle. + */ + std::string getHandle() const override { + if (auto sp = getObjectReferenceInternal()) { + return sp->getSensorHandle(); + } + return ""; + } + + /** + * @brief Managed Sensor objects manage their own IDs, so this is + * unsettable. + */ + void setID(CORRADE_UNUSED int ID) override {} + + /** + * @brief Retrieve this object's unique ID. + */ + int getID() const override { + if (auto sp = getObjectReferenceInternal()) { + return sp->getSensorID(); + } + return ID_UNDEFINED; + } // getID() + + protected: + /** + * @brief Internal use only. Set weak ref as void pointer. All access will + * perform appropriate casting. + */ + + void setObjectRefInternal(const std::shared_ptr& objRef) { + weakObjRef_ = objRef; + } + + /** + * @brief This function accesses the underlying shared pointer of this + * object's @p weakObjRef_ if it exists; if not, it provides a message. + * @return Either a shared pointer of this wrapper's object, or nullptr if + * DNE. + */ + template + std::shared_ptr inline getObjectReferenceInternal() const { + std::shared_ptr sp = weakObjRef_.lock(); + if (!sp) { + // TODO: Verify object is removed from manager here? + ESP_ERROR() + << "This sensor object no longer exists. Please delete any variable " + "references."; + } + return std::static_pointer_cast(sp); + } // getObjectReference + + /** + * @brief Set this managed object's class. Should only be set from + * constructor. Used as key in constructor function pointer maps in Managed + * Container. + * @param classKey the string handle corresponding to the + * constructors used to make copies of this object in copy constructor map. + */ + void setClassKey(const std::string& classKey) override { + classKey_ = classKey; + } + + /** + * @brief Weak ref to object. If user has copy of this wrapper but object + * has been deleted, this will be nullptr. + */ + std::weak_ptr weakObjRef_{}; + + /** + * @brief Name of instancing class responsible for this managed object + */ + std::string classKey_; + + public: + ESP_SMART_POINTERS(ManagedSensorBase) +}; // class AbstractManagedSensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDSENSORBASE_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedSensorTemplates.h b/src/esp/sensor/sensorWrappers/ManagedSensorTemplates.h new file mode 100644 index 0000000000..1a1f3db928 --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedSensorTemplates.h @@ -0,0 +1,101 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDSENSORTEMPLATES_H_ +#define ESP_SENSOR_MANAGEDSENSORTEMPLATES_H_ + +#include +#include + +#include "ManagedSensorBase.h" +#include "esp/sensor/Sensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Base class template for wrapper for sensor objects of all kinds to + * enable Managed Container access. + */ +template +class AbstractManagedSensor : public ManagedSensorBase { + public: + static_assert(std::is_base_of::value, + "AbstractManagedSensor :: Managed sensor object type must be " + "derived from esp::sensor::Sensor"); + + /** + * @brief Alias for weak pointer to the @ref esp::sensor::Sensor this construct wraps. + */ + typedef std::weak_ptr WeakObjRef; + + explicit AbstractManagedSensor(const std::string& classKey) + : ManagedSensorBase(classKey) {} + + void setObjectRef(const std::shared_ptr& objRef) { + setObjectRefInternal(objRef); + } + + /** + * @brief Return whether this is a visual sensor or not + */ + bool isVisualSensor() const { + if (auto sp = this->getObjectReference()) { + return sp->isVisualSensor(); + } + return false; + } + + /** + * @brief Retrieve a comma-separated string holding the header values for the + * info returned for this managed object. + */ + std::string getObjectInfoHeader() const override { + return "Type," + getSensorObjInfoHeaderInternal(); + } + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. + */ + std::string getObjectInfo() const override { + if (auto sp = this->getObjectReference()) { + return Cr::Utility::formatString("{},{},", classKey_, + getSensorObjInfoInternal(sp)); + } + return Cr::Utility::formatString("Unknown classkey {},", classKey_); + } + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed object, type-specific. + */ + + virtual std::string getSensorObjInfoHeaderInternal() const = 0; + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + virtual std::string getSensorObjInfoInternal( + std::shared_ptr& sp) const = 0; + + /** + * @brief This function accesses the underlying shared pointer of this + * object's @p weakObjRef_ if it exists; if not, it provides a message. + * @return Either a shared pointer of this wrapper's object, or nullptr if + * DNE. + */ + std::shared_ptr inline getObjectReference() const { + return getObjectReferenceInternal(); + } // getObjectReference + + public: + ESP_SMART_POINTERS(AbstractManagedSensor) +}; // class AbstractManagedSensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDSENSORTEMPLATES_H_ diff --git a/src/esp/sensor/sensorWrappers/ManagedVisualSensorBase.h b/src/esp/sensor/sensorWrappers/ManagedVisualSensorBase.h new file mode 100644 index 0000000000..f4aa8c43ec --- /dev/null +++ b/src/esp/sensor/sensorWrappers/ManagedVisualSensorBase.h @@ -0,0 +1,76 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_SENSOR_MANAGEDVISUALSENSORBASE_H_ +#define ESP_SENSOR_MANAGEDVISUALSENSORBASE_H_ + +#include +#include + +#include "ManagedSensorTemplates.h" +#include "esp/sensor/VisualSensor.h" + +namespace esp { +namespace sensor { + +/** + * @brief Class template for wrapper for visual sensor objects of all kinds + * that extends AbstractManagedSensorAccess + */ + +template +class AbstractManagedVisualSensor + : public esp::sensor::AbstractManagedSensor { + public: + static_assert(std::is_base_of::value, + "AbstractManagedVisualSensor :: Managed visual sensor object " + "type must be derived from esp::sensor::VisualSensor"); + + explicit AbstractManagedVisualSensor(const std::string& classKey) + : AbstractManagedSensor(classKey) {} + // TODO Add appropriate abstract visual sensor getters/setters here + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed object, type-specific. + */ + + std::string getSensorObjInfoHeaderInternal() const override { + return "" + getVisualSensorObjInfoHeaderInternal(); + } + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed visual sensor, type-specific. + */ + + virtual std::string getVisualSensorObjInfoHeaderInternal() const = 0; + /** + * @brief Specialization-specific extension of getObjectInfo, comma + * separated info ideal for saving to csv + */ + std::string getSensorObjInfoInternal( + CORRADE_UNUSED std::shared_ptr& sp) const override { + // TODO provide info stream for sensors + std::string res = + Cr::Utility::formatString("{},", getVisualSensorObjInfoInternal()); + + return res; + } + + /** + * @brief Specialization-specific extension of getSensorObjInfoInternal, comma + * separated info ideal for saving to csv + */ + virtual std::string getVisualSensorObjInfoInternal( + std::shared_ptr& sp) const = 0; + + public: + ESP_SMART_POINTERS(AbstractManagedVisualSensor) +}; // class AbstractManagedVisualSensor + +} // namespace sensor +} // namespace esp + +#endif // ESP_SENSOR_MANAGEDVISUALSENSORBASE_H_