-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--[BE] - SensorAttributes/Managers refactor Part 1 (#2502)
* --init * --enum maps to convert sensor enums to/from strings * --better organization; complete AbstractSensorAttr setup * --add audio and abstract visual sensor stubs * --add config support for Vector2i * --Sensor enum maps; AbstractVisualSensorAttributes * --complete audio sensor attributes * --add CameraSensorAttributes * --add CubeMap-based attributes * --use correct class name * --SensorAttributesManager initial commit. * --remove reference to "unique_id" in the attributes. The handle will fulfill this role. * --add attributes for Custom sensors * --rename 'none' to 'unspecified' in SensorType and SensorSubType * --type check for template function * --expanded SensorAttributes creation code * --add 'custom' entry for SensorType along with SensorSubType * --add code to populate attributes from appropriate spec This code will be removed when SensorSpecs are removed. * --give sensorattributes unique handle/registration key. * --verify works for both audio enabled and disabled. * --expand sensor attributes manager functions * --Define CustomSensorAttributes to be held within a subconfig similar to user_defined. * --add bindings for custom sensor-related enums * --add ref to SensorAttributesManager in MM * --fix missing method, incorrect map name; * --hide instantiation temporarily to stop test linking error. * --appropriately mark unused arguments * --remove unused include * --some scene-lib-related refactors * --create sensorAttributesManager in MM * --add sensor attributes and manager filenames to cmakelist * --minor - stub out sensor tests * --test building all types of sensor attributes from sensor specs * --set a 1 cm default fisheye focal length.
- Loading branch information
Showing
29 changed files
with
2,457 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 "AbstractSensorAttributes.h" | ||
namespace esp { | ||
namespace metadata { | ||
namespace attributes { | ||
|
||
AbstractSensorAttributes::AbstractSensorAttributes( | ||
const std::string& attributesClassKey, | ||
const std::string& handle) | ||
: AbstractAttributes(attributesClassKey, handle) { | ||
init("position", Mn::Vector3{0.0, 1.5, 0.0}); | ||
init("orientation", Mn::Vector3{0.0, 0.0, 0.0}); | ||
init("noise_model", "None"); | ||
|
||
initTranslated("sensor_type", | ||
getSensorTypeName(sensor::SensorType::Unspecified)); | ||
initTranslated("sensor_subtype", | ||
getSensorSubTypeName(sensor::SensorSubType::Unspecified)); | ||
} // AbstractSensorAttributes ctor | ||
|
||
void AbstractSensorAttributes::populateWithSensorSpec( | ||
const sensor::SensorSpec::ptr& spec) { | ||
setPosition(spec->position); | ||
setOrientation(spec->orientation); | ||
setNoiseModel(spec->noiseModel); | ||
setSensorTypeEnum(spec->sensorType); | ||
setSensorSubTypeEnum(spec->sensorSubType); | ||
} // AbstractSensorAttributes::populateWithSensorSpec | ||
|
||
void AbstractSensorAttributes::writeValuesToJson( | ||
io::JsonGenericValue& jsonObj, | ||
io::JsonAllocator& allocator) const { | ||
// write AbstractSensorAttributes to JSON | ||
writeValueToJson("position", jsonObj, allocator); | ||
writeValueToJson("orientation", jsonObj, allocator); | ||
writeValueToJson("noise_model", jsonObj, allocator); | ||
writeValueToJson("sensor_type", jsonObj, allocator); | ||
writeValueToJson("sensor_subtype", jsonObj, allocator); | ||
|
||
// call child-class-specific | ||
writeValuesToJsonInternal(jsonObj, allocator); | ||
} // AbstractSensorAttributes::writeValuesToJson | ||
|
||
std::string AbstractSensorAttributes::getObjectInfoHeaderInternal() const { | ||
return "Position XYZ,Orientation XYZ,Noise Model,Sensor " | ||
"Type,Sensor Subtype," + | ||
getAbstractSensorInfoHeaderInternal(); | ||
} // AbstractSensorAttributes::getObjectInfoHeaderInternal | ||
|
||
std::string AbstractSensorAttributes::getObjectInfoInternal() const { | ||
return Cr::Utility::formatString("{},{},{},{},{},{}", getAsString("position"), | ||
getAsString("orientation"), getNoiseModel(), | ||
getSensorTypeName(getSensorType()), | ||
getSensorSubTypeName(getSensorSubType()), | ||
getAbstractSensorInfoInternal()); | ||
} // AbstractSensorAttributes::getObjectInfoInternal | ||
|
||
} // namespace attributes | ||
} // namespace metadata | ||
} // namespace esp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
// 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_METADATA_ATTRIBUTES_ABSTRACTSENSORATTRIBUTES_H_ | ||
#define ESP_METADATA_ATTRIBUTES_ABSTRACTSENSORATTRIBUTES_H_ | ||
|
||
#include "AbstractAttributes.h" | ||
|
||
namespace esp { | ||
namespace metadata { | ||
namespace attributes { | ||
|
||
/** | ||
* @brief Attributes object holding the descriptions of a Sensor object | ||
*/ | ||
class AbstractSensorAttributes : public AbstractAttributes { | ||
public: | ||
AbstractSensorAttributes(const std::string& classKey, | ||
const std::string& handle); | ||
|
||
/** | ||
* @brief Populate this attributes from an appropriate @ref sensor::SensorSpec. | ||
* @todo Remove when SensorSpecs are removed | ||
* | ||
*/ | ||
virtual void populateWithSensorSpec(const sensor::SensorSpec::ptr& spec); | ||
|
||
/** @brief Set the position of the sensor. */ | ||
void setPosition(const Magnum::Vector3& position) { | ||
set("position", position); | ||
} | ||
|
||
/** @brief Get the position of the sensor. */ | ||
Magnum::Vector3 getPosition() const { | ||
return get<Magnum::Vector3>("position"); | ||
} | ||
|
||
/** @brief Set the position of the sensor. */ | ||
void setOrientation(const Magnum::Vector3& orientation) { | ||
set("orientation", orientation); | ||
} | ||
|
||
/** @brief Get the position of the sensor. */ | ||
Magnum::Vector3 getOrientation() const { | ||
return get<Magnum::Vector3>("orientation"); | ||
} | ||
|
||
/** @brief Sets the noise model to use for this sensor. */ | ||
void setNoiseModel(const std::string& noise_model) { | ||
set("noise_model", noise_model); | ||
} | ||
|
||
/** @brief Gets the noise model to use for this sensor. */ | ||
std::string getNoiseModel() const { return get<std::string>("noise_model"); } | ||
|
||
/** | ||
* @brief Set the sensor type for this sensor. | ||
*/ | ||
void setSensorType(const std::string& sensorType) { | ||
// force to lowercase to check if present | ||
const std::string sensorTypeLC = Cr::Utility::String::lowercase(sensorType); | ||
auto mapIter = SensorTypeNamesMap.find(sensorTypeLC); | ||
if (mapIter == SensorTypeNamesMap.end()) { | ||
ESP_ERROR(Mn::Debug::Flag::NoSpace) | ||
<< "'" << sensorType | ||
<< "' is an illegal value for " | ||
"AbstractSensorAttributes::setSensorType, so current value " | ||
<< get<std::string>("sensor_type") << " not changed."; | ||
return; | ||
} | ||
setTranslated("sensor_type", sensorType); | ||
} // setSensorType | ||
|
||
/** | ||
* @brief Set the sensor type for this sensor as specified by given @ref SensorType | ||
*/ | ||
void setSensorTypeEnum(sensor::SensorType sensorTypeEnum) { | ||
// force to lowercase to check if present | ||
const std::string sensorType = getSensorTypeName(sensorTypeEnum); | ||
auto mapIter = SensorTypeNamesMap.find(sensorType); | ||
|
||
ESP_CHECK(mapIter != SensorTypeNamesMap.end(), | ||
"Illegal SensorType enum value given" | ||
<< static_cast<int>(sensorTypeEnum) << ":" << sensorType | ||
<< "attempted to be initialized in AbstractSensorAttributes:" | ||
<< getHandle() << ". Aborting."); | ||
|
||
setTranslated("sensor_type", sensorType); | ||
} // setSensorTypeEnum | ||
|
||
/** | ||
* @brief Get the sensor type for this sensor. | ||
*/ | ||
sensor::SensorType getSensorType() const { | ||
const std::string val = | ||
Cr::Utility::String::lowercase(get<std::string>("sensor_type")); | ||
auto mapIter = SensorTypeNamesMap.find(val); | ||
if (mapIter != SensorTypeNamesMap.end()) { | ||
return mapIter->second; | ||
} | ||
// This should never get to here. It would mean that this field was set | ||
// to an invalid value somehow. | ||
return sensor::SensorType::Unspecified; | ||
} | ||
|
||
/** | ||
* @brief Set the sensor type for this sensor. | ||
*/ | ||
void setSensorSubType(const std::string& sensorSubType) { | ||
// force to lowercase to check if present | ||
const std::string sensorTypeLC = | ||
Cr::Utility::String::lowercase(sensorSubType); | ||
auto mapIter = SensorSubTypeNamesMap.find(sensorTypeLC); | ||
if (mapIter == SensorSubTypeNamesMap.end()) { | ||
ESP_ERROR(Mn::Debug::Flag::NoSpace) | ||
<< "'" << sensorSubType | ||
<< "' is an illegal value for " | ||
"AbstractSensorAttributes::setSensorSubType, so current value " | ||
<< get<std::string>("sensor_subtype") << " not changed."; | ||
return; | ||
} | ||
setTranslated("sensor_subtype", sensorSubType); | ||
} // setSensorSubType | ||
|
||
/** | ||
* @brief Set the sensor subtype for this sensor as specified by given @ref SensorSubType | ||
*/ | ||
void setSensorSubTypeEnum(sensor::SensorSubType sensorSubTypeEnum) { | ||
// force to lowercase to check if present | ||
const std::string sensorSubType = getSensorSubTypeName(sensorSubTypeEnum); | ||
auto mapIter = SensorSubTypeNamesMap.find(sensorSubType); | ||
|
||
ESP_CHECK(mapIter != SensorSubTypeNamesMap.end(), | ||
"Illegal SensorSubType enum value given" | ||
<< static_cast<int>(sensorSubTypeEnum) << ":" << sensorSubType | ||
<< "attempted to be initialized in AbstractSensorAttributes:" | ||
<< getHandle() << ". Aborting."); | ||
|
||
setTranslated("sensor_subtype", sensorSubType); | ||
} // setSensorSubTypeEnum | ||
|
||
/** | ||
* @brief Get the sensor subtype for this sensor. | ||
*/ | ||
sensor::SensorSubType getSensorSubType() const { | ||
const std::string val = | ||
Cr::Utility::String::lowercase(get<std::string>("sensor_subtype")); | ||
auto mapIter = SensorSubTypeNamesMap.find(val); | ||
if (mapIter != SensorSubTypeNamesMap.end()) { | ||
return mapIter->second; | ||
} | ||
// This should never get to here. It would mean that this field was set | ||
// to an invalid value somehow. | ||
return sensor::SensorSubType::Unspecified; | ||
} // getSensorSubType | ||
|
||
/** | ||
* @brief Populate a json object with all the first-level values held in this | ||
* configuration. Default is overridden to handle special cases for | ||
* AbstractSensorAttributes and deriving (i.e. AudioSensorAttributes or | ||
* VisualSensorAttributes) classes. | ||
*/ | ||
void writeValuesToJson(io::JsonGenericValue& jsonObj, | ||
io::JsonAllocator& allocator) const override; | ||
|
||
protected: | ||
/** | ||
* @brief Write child-class-specific values to json object | ||
* | ||
*/ | ||
virtual void writeValuesToJsonInternal( | ||
CORRADE_UNUSED io::JsonGenericValue& jsonObj, | ||
CORRADE_UNUSED io::JsonAllocator& allocator) const {} | ||
|
||
/** | ||
* @brief Retrieve a comma-separated string holding the header values for the | ||
* info returned for this managed object, type-specific. | ||
*/ | ||
|
||
std::string getObjectInfoHeaderInternal() const override; | ||
/** | ||
* @brief get AbstractSensorAttributes-specific info header | ||
*/ | ||
virtual std::string getAbstractSensorInfoHeaderInternal() const { | ||
return ""; | ||
}; | ||
|
||
/** | ||
* @brief Retrieve a comma-separated informational string about the contents | ||
* of this managed object. | ||
*/ | ||
std::string getObjectInfoInternal() const override; | ||
/** | ||
* @brief get AbstractSensorAttributes specific info for csv string | ||
*/ | ||
virtual std::string getAbstractSensorInfoInternal() const { return ""; }; | ||
|
||
public: | ||
ESP_SMART_POINTERS(AbstractSensorAttributes) | ||
}; // class AbstractSensorAttributes | ||
|
||
} // namespace attributes | ||
} // namespace metadata | ||
} // namespace esp | ||
|
||
#endif // ESP_METADATA_ATTRIBUTES_ABSTRACTSENSORATTRIBUTES_H_ |
Oops, something went wrong.