2026-04-03 23:54:22 -04:00
|
|
|
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
|
|
|
|
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
|
|
|
|
|
2026-04-18 14:54:14 -04:00
|
|
|
#include <algorithm>
|
2026-04-03 23:54:22 -04:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <stdexcept>
|
2026-04-12 04:06:47 -04:00
|
|
|
#include <string>
|
2026-04-18 14:54:14 -04:00
|
|
|
#include <string_view>
|
2026-04-03 23:54:22 -04:00
|
|
|
#include <user/deviceAttachmentSpec.h>
|
2026-04-18 14:54:14 -04:00
|
|
|
#include <user/intrin.h>
|
|
|
|
|
#include <user/intrinThresholdParams.h>
|
2026-04-03 23:54:22 -04:00
|
|
|
|
|
|
|
|
namespace smo {
|
|
|
|
|
namespace stim_buff {
|
|
|
|
|
|
|
|
|
|
enum ParamComparatorOp
|
|
|
|
|
{
|
|
|
|
|
OP_CMP_GT,
|
|
|
|
|
OP_CMP_LT,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ParamComparator
|
|
|
|
|
{
|
|
|
|
|
ParamComparatorOp op;
|
|
|
|
|
uint32_t value;
|
|
|
|
|
|
2026-04-12 04:06:47 -04:00
|
|
|
bool operator()(float passbandMetricVal) const
|
2026-04-03 23:54:22 -04:00
|
|
|
{
|
|
|
|
|
switch (op)
|
|
|
|
|
{
|
|
|
|
|
case OP_CMP_GT:
|
2026-04-12 04:06:47 -04:00
|
|
|
return passbandMetricVal > static_cast<float>(value);
|
2026-04-03 23:54:22 -04:00
|
|
|
case OP_CMP_LT:
|
2026-04-12 04:06:47 -04:00
|
|
|
return passbandMetricVal < static_cast<float>(value);
|
2026-04-03 23:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error("Unsupported ParamComparatorOp");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-18 14:54:14 -04:00
|
|
|
inline bool paramsContain(
|
|
|
|
|
const std::vector<std::pair<std::string, std::string>>& params,
|
|
|
|
|
const std::string& name)
|
2026-04-18 12:02:27 -04:00
|
|
|
{
|
2026-04-18 14:54:14 -04:00
|
|
|
return std::any_of(
|
|
|
|
|
params.begin(), params.end(),
|
|
|
|
|
[&name](const auto& p) { return p.first == name; });
|
|
|
|
|
}
|
2026-04-18 12:02:27 -04:00
|
|
|
|
2026-04-18 14:54:14 -04:00
|
|
|
/* pcloudLightAmbience requires exactly one `passband-count-gt-val` on its
|
|
|
|
|
* qualeIfaceApi params; `passband-count-lt-val` is a hard error. Feeds a
|
|
|
|
|
* negtrin(...) segment (scene is "unbearably much, get away").
|
2026-04-18 12:02:27 -04:00
|
|
|
*/
|
2026-04-18 14:54:14 -04:00
|
|
|
inline ParamComparator parsePcloudLightAmbienceGtComparator(
|
2026-04-03 23:54:22 -04:00
|
|
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec)
|
|
|
|
|
{
|
|
|
|
|
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
2026-04-18 14:54:14 -04:00
|
|
|
|
|
|
|
|
if (paramsContain(params, "passband-count-lt-val"))
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"pcloudLightAmbience qualeIfaceApi does not accept "
|
|
|
|
|
"'passband-count-lt-val'; use pcloudDarkAmbience for lt-val "
|
|
|
|
|
"pipelines.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 23:54:22 -04:00
|
|
|
constexpr int kParamNotSpecified = -1;
|
|
|
|
|
const int gtVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
|
2026-04-12 04:06:47 -04:00
|
|
|
params, "passband-count-gt-val", kParamNotSpecified);
|
2026-04-03 23:54:22 -04:00
|
|
|
|
2026-04-18 14:54:14 -04:00
|
|
|
if (gtVal == kParamNotSpecified)
|
2026-04-03 23:54:22 -04:00
|
|
|
{
|
2026-04-18 14:54:14 -04:00
|
|
|
throw std::runtime_error(
|
|
|
|
|
"pcloudLightAmbience qualeIfaceApi requires "
|
|
|
|
|
"'passband-count-gt-val' on its params.");
|
2026-04-03 23:54:22 -04:00
|
|
|
}
|
2026-04-18 14:54:14 -04:00
|
|
|
|
|
|
|
|
return ParamComparator{
|
|
|
|
|
.op = OP_CMP_GT,
|
|
|
|
|
.value = static_cast<uint32_t>(gtVal),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* pcloudDarkAmbience requires exactly one `passband-count-lt-val` on its
|
|
|
|
|
* qualeIfaceApi params; `passband-count-gt-val` is a hard error. Feeds a
|
|
|
|
|
* postrin(...) segment (scene is "too good, stay here").
|
|
|
|
|
*/
|
|
|
|
|
inline ParamComparator parsePcloudDarkAmbienceLtComparator(
|
|
|
|
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec)
|
|
|
|
|
{
|
|
|
|
|
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
|
|
|
|
|
|
|
|
|
if (paramsContain(params, "passband-count-gt-val"))
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"pcloudDarkAmbience qualeIfaceApi does not accept "
|
|
|
|
|
"'passband-count-gt-val'; use pcloudLightAmbience for gt-val "
|
|
|
|
|
"pipelines.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr int kParamNotSpecified = -1;
|
|
|
|
|
const int ltVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
|
|
|
|
|
params, "passband-count-lt-val", kParamNotSpecified);
|
|
|
|
|
|
|
|
|
|
if (ltVal == kParamNotSpecified)
|
2026-04-03 23:54:22 -04:00
|
|
|
{
|
2026-04-18 14:54:14 -04:00
|
|
|
throw std::runtime_error(
|
|
|
|
|
"pcloudDarkAmbience qualeIfaceApi requires "
|
|
|
|
|
"'passband-count-lt-val' on its params.");
|
2026-04-03 23:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 14:54:14 -04:00
|
|
|
return ParamComparator{
|
|
|
|
|
.op = OP_CMP_LT,
|
|
|
|
|
.value = static_cast<uint32_t>(ltVal),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shared parser used by both pcloudLightAmbience and pcloudDarkAmbience
|
|
|
|
|
* stimbuffs to decode a postrin(...) / negtrin(...) segment's threshold
|
|
|
|
|
* params into an IntrinConfig. Kept with the qualeIfaceApi helpers because
|
|
|
|
|
* it's ambience-specific (nDgramsPerFrame is the percentage base).
|
|
|
|
|
*/
|
|
|
|
|
inline intrin::IntrinConfig parseAmbienceIntrinConfigFromParams(
|
|
|
|
|
std::string_view intrinKind,
|
|
|
|
|
const std::vector<std::pair<std::string, std::string>>& params,
|
|
|
|
|
size_t nDgramsPerFrame)
|
|
|
|
|
{
|
|
|
|
|
intrin::validateIntrinSegmentParams(intrinKind, params);
|
|
|
|
|
|
|
|
|
|
const auto threshold = intrin::parseOptionalThresholdParam(
|
|
|
|
|
params,
|
|
|
|
|
intrin::kIntrinInterestPcNames,
|
|
|
|
|
intrin::kIntrinInterestThrNames,
|
|
|
|
|
/*defaultValue=*/0,
|
|
|
|
|
/*defaultUnit=*/intrin::ThresholdUnit::Absolute);
|
|
|
|
|
|
|
|
|
|
return intrin::IntrinConfig{
|
|
|
|
|
.percentage =
|
|
|
|
|
threshold.unit == intrin::ThresholdUnit::Percentage
|
|
|
|
|
? static_cast<uint32_t>(threshold.value)
|
|
|
|
|
: 0U,
|
|
|
|
|
.threshold = intrin::resolveThresholdValue(
|
|
|
|
|
threshold, nDgramsPerFrame),
|
|
|
|
|
};
|
2026-04-03 23:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace stim_buff
|
|
|
|
|
} // namespace smo
|
|
|
|
|
|
|
|
|
|
#endif // _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|