Skip to content

Commit

Permalink
--test building all types of sensor attributes from sensor specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Dec 9, 2024
1 parent 0ff331c commit 29f0d22
Show file tree
Hide file tree
Showing 5 changed files with 430 additions and 34 deletions.
17 changes: 7 additions & 10 deletions src/esp/metadata/attributes/CubeMapSensorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ AbstractCubeMapSensorAttributes::AbstractCubeMapSensorAttributes(
const std::string& handle)
: AbstractVisualSensorAttributes(classKey, handle) {
setHidden("__useSpecifiedCubeMapSize", false);
// Replacing nullopt field - -1 means to ignore
init("cubemap_size", -1);
// Replacing nullopt field - 0 means to ignore
init("cubemap_size", 0);
} // AbstractCubeMapSensorAttributes ctor

void AbstractCubeMapSensorAttributes::populateWithSensorSpec(
Expand Down Expand Up @@ -44,7 +44,7 @@ void AbstractCubeMapSensorAttributes::writeVisualSensorValuesToJsonInternal(
std::string
AbstractCubeMapSensorAttributes::getAbstractVisualSensorInfoHeaderInternal()
const {
return "User-specified CubeMap Size (-1 means unspecified)" +
return "User-specified CubeMap Size (0 : use min dim of resolution)" +
getCubeMapSensorInfoHeaderInternal();
} // AbstractCubeMapSensorAttributes::getAbstractVisualSensorInfoHeaderInternal()

Expand Down Expand Up @@ -108,16 +108,13 @@ void FisheyeSensorAttributes::populateWithSensorSpec(
// Call Parent class version
AbstractCubeMapSensorAttributes::populateWithSensorSpec(spec);
// Appropriately cast to get FisheyeSensorDoubleSphereSpec-spec data if exists
const esp::sensor::FisheyeSensorSpec::ptr& fisheyeSpec =
std::dynamic_pointer_cast<esp::sensor::FisheyeSensorSpec>(spec);
setFocalLength(fisheyeSpec->focalLength);
if (fisheyeSpec->principalPointOffset != Cr::Containers::NullOpt) {
setPrincipalPointOffset(*fisheyeSpec->principalPointOffset);
}
// Doublesphere Fisheye
const esp::sensor::FisheyeSensorDoubleSphereSpec::ptr& fisheyeDSSpec =
std::dynamic_pointer_cast<esp::sensor::FisheyeSensorDoubleSphereSpec>(
spec);
setFocalLength(fisheyeDSSpec->focalLength);
if (fisheyeDSSpec->principalPointOffset != Cr::Containers::NullOpt) {
setPrincipalPointOffset(*fisheyeDSSpec->principalPointOffset);
}
setDoubleSphereXi(fisheyeDSSpec->xi);
setDoubleSphereAlpha(fisheyeDSSpec->alpha);
// Currently no other Fisheye algorithm is implemented
Expand Down
39 changes: 31 additions & 8 deletions src/esp/metadata/attributes/CubeMapSensorAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,38 @@ class AbstractCubeMapSensorAttributes : public AbstractVisualSensorAttributes {
}

/**
* @brief Set user-specified CubeMap Size. -1 means ignore this field and use
* the max dimension of the resolution as the size
* @brief Set user-specified CubeMap Size. 0 means ignore this field and use
* the min dimension of the resolution as the size
*/
void setCubeMapSize(int cubemap_size) {
set("cubemap_size", cubemap_size);
setUseSpecifiedCubeMapSize(true);
}

void clearCubeMapSize() {
set("cubemap_size", -1);
set("cubemap_size", 0);
setUseSpecifiedCubeMapSize(false);
}

/**
* @brief Get user-specified CubeMap Size. -1 means ignore this field and use
* @brief Get user-specified CubeMap Size. 0 means ignore this field and use
* the max dimension of the resolution as the size
*/
int getCubeMapSize() const { return get<int>("cubemap_size"); }

/**
* @brief Get the actual cube map size to use when constructing the cube map -
* either the user's specified value or the minimum resolution dimension. This
* should not be saved, and is just offered as a convenience accessor.
*/
int getCubeMapSizeToUse() const {
if (getUseSpecifiedCubeMapSize()) {
return get<int>("cubemap_size");
}
// If no cubemap size is specified, use the minimum resolution dimension
return getResolution().min();
}

protected:
/**
* @brief Write CubeMap Sensor-specific values to json object
Expand Down Expand Up @@ -190,6 +203,7 @@ class FisheyeSensorAttributes : public AbstractCubeMapSensorAttributes {
* principal point relative to the image plane's origin.
*/
void setPrincipalPointOffset(const Magnum::Vector2& principle_point_offset) {
// TODO both values should always be > 0
set<Magnum::Vector2>("principle_point_offset", principle_point_offset);
setUsePrincipalPointOffset(true);
}
Expand All @@ -199,16 +213,25 @@ class FisheyeSensorAttributes : public AbstractCubeMapSensorAttributes {
* set.
*/
void clearPrincipalPointOffset() {
set<Magnum::Vector2>("principle_point_offset",
Magnum::Vector2(getResolution()) * 0.5);
set<Magnum::Vector2>("principle_point_offset", Magnum::Vector2(0.0, 0.0));
setUsePrincipalPointOffset(false);
}
/**
* @brief Get the Principal Point Offset in pixel, cx, cy, location of the
* @brief Get the Principal Point Offset - the pixel, cx, cy, location of the
* principal point relative to the image plane's origin. If not specified use
* center of image.
* center of the sensor image.
*/
Magnum::Vector2 getPrincipalPointOffset() const {
return get<Magnum::Vector2>("principle_point_offset");
}
/**
* @brief Get the Actual Principal Point Offset to use; pixel, cx, cy,
* location of the principal point relative to the image plane's origin. This
* value is what should be used to create the sensor - if not specified, use
* the halfway point of the resolution specified (i.e. the center of the
* sensor image).
*/
Magnum::Vector2 getPrincipalPointOffsetToUse() const {
if (getUsePrincipalPointOffset()) {
return get<Magnum::Vector2>("principle_point_offset");
}
Expand Down
2 changes: 1 addition & 1 deletion src/esp/metadata/managers/SensorAttributesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SensorAttributesManager::SensorAttributesManager()
} // SensorAttributesManager ctor

AbstractSensorAttributes::ptr
SensorAttributesManager::createAttributesFromSensorSpec(
SensorAttributesManager::createAttributesFromSensorSpecInternal(
const sensor::SensorSpec::ptr& sensorSpec,
bool registerTemplate) {
// Get attributes class name from sensorSpec
Expand Down
48 changes: 38 additions & 10 deletions src/esp/metadata/managers/SensorAttributesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

#include "AbstractAttributesManager.h"
#include "esp/metadata/attributes/AbstractSensorAttributes.h"
#include "esp/metadata/attributes/AudioSensorAttributes.h"
#include "esp/metadata/attributes/CameraSensorAttributes.h"
#include "esp/metadata/attributes/CubeMapSensorAttributes.h"
#include "esp/metadata/attributes/CustomSensorAttributes.h"

namespace esp {
namespace metadata {
namespace attributes {
class AudioSensorAttributes;
class CameraSensorAttributes;
class CustomSensorAttributes;
class EquirectangularSensorAttributes;
class FisheyeSensorAttributes;
} // namespace attributes

namespace managers {

class SensorAttributesManager
Expand Down Expand Up @@ -51,9 +47,22 @@ class SensorAttributesManager
* template.
* @return a reference to the desired template.
*/
attributes::AbstractSensorAttributes::ptr createAttributesFromSensorSpec(

template <typename T>
std::shared_ptr<T> createAttributesFromSensorSpec(
const sensor::SensorSpec::ptr& sensorSpec,
bool registerTemplate = true);
bool registerTemplate = true) {
static_assert(
std::is_base_of<attributes::AbstractSensorAttributes, T>::value,
"AbstractSensorAttributes must be the base type of the requested new "
"SensorSpec-based attributes");

attributes::AbstractSensorAttributes::ptr attrs =
this->createAttributesFromSensorSpecInternal(sensorSpec,
registerTemplate);

return std::static_pointer_cast<T>(attrs);
}

/**
* @brief Should only be called internally. Creates an instance of a sensor
Expand Down Expand Up @@ -110,6 +119,25 @@ class SensorAttributesManager
attributes) const override {}

protected:
/**
* @brief Internal only. Create an attributes from a SensorSpec.
*
* TODO : Once SensorSpecs are removed, this should be removed as well.
*
* @param sensorSpec The SensorSpec holding the values to use to create a
* sensor.
* @param registerTemplate whether to add this template to the library.
* If the user is going to edit this template, this should be false - any
* subsequent editing will require re-registration. Defaults to true. If
* specified as true, then this function returns a copy of the registered
* template.
* @return a reference to the desired template.
*/
attributes::AbstractSensorAttributes::ptr
createAttributesFromSensorSpecInternal(
const sensor::SensorSpec::ptr& sensorSpec,
bool registerTemplate);

/**
* @brief Used Internally. Create and configure newly-created attributes with
* any default values, before any specific values are set.
Expand Down
Loading

0 comments on commit 29f0d22

Please sign in to comment.