Api improvements: ambience-count-[l|g]t-val and Comparator
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -115,6 +116,25 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Parse an optional integer parameter from a parameter list
|
||||||
|
* @param params The parameter vector to search in
|
||||||
|
* @param paramName The name of the parameter to parse
|
||||||
|
* @param defaultValue The default value to return if no parameter is found
|
||||||
|
* @return The parsed integer value, or defaultValue if none found
|
||||||
|
* @note The lattermost supplied matching param wins if multiple are present
|
||||||
|
*/
|
||||||
|
static int parseOptionalParamAsInt(
|
||||||
|
const std::vector<std::pair<std::string,std::string>>& params,
|
||||||
|
const std::string& paramName,
|
||||||
|
int defaultValue
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const std::string paramNames[] = {paramName};
|
||||||
|
return parseOptionalParamAsIntWithSynonyms(
|
||||||
|
params, paramNames, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parse an optional integer parameter from a parameter list using synonyms
|
* @brief Parse an optional integer parameter from a parameter list using synonyms
|
||||||
* @param params The parameter vector to search in
|
* @param params The parameter vector to search in
|
||||||
@@ -135,9 +155,9 @@ public:
|
|||||||
{
|
{
|
||||||
const auto& [paramName, paramValue] = *paramIt;
|
const auto& [paramName, paramValue] = *paramIt;
|
||||||
auto synonymIt = std::find(
|
auto synonymIt = std::find(
|
||||||
synonymNames.begin(), synonymNames.end(), paramName);
|
std::begin(synonymNames), std::end(synonymNames), paramName);
|
||||||
|
|
||||||
if (synonymIt == synonymNames.end())
|
if (synonymIt == std::end(synonymNames))
|
||||||
{ continue; }
|
{ continue; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -988,19 +988,18 @@ void OpenClCollatingAndMeshingEngine::produceAmbienceStimulusFrame(
|
|||||||
parent.ambienceStimulusBuffer.load(std::memory_order_acquire);
|
parent.ambienceStimulusBuffer.load(std::memory_order_acquire);
|
||||||
if (!ambienceBuff) { return; }
|
if (!ambienceBuff) { return; }
|
||||||
|
|
||||||
uint32_t lowVal = ambienceBuff->ambienceIntensityLowVal;
|
const auto& ambienceCountComparator = ambienceBuff->ambienceCountComparator;
|
||||||
|
|
||||||
// Read average intensity values from averageIntensityBuffer
|
// Read average intensity values from averageIntensityBuffer
|
||||||
float* averageIntensityAverages = reinterpret_cast<float*>(
|
float* averageIntensityAverages = reinterpret_cast<float*>(
|
||||||
averageIntensityBufferPtr);
|
averageIntensityBufferPtr);
|
||||||
|
|
||||||
// Count frames whose average intensity is <= lowVal (postrin only)
|
// Count frames whose average intensity matches the configured comparator.
|
||||||
uint32_t ambienceCount = 0;
|
uint32_t ambienceCount = 0;
|
||||||
for (uint32_t i = 0; i < nSucceeded; ++i)
|
for (uint32_t i = 0; i < nSucceeded; ++i)
|
||||||
{
|
{
|
||||||
float avg = averageIntensityAverages[i];
|
float avg = averageIntensityAverages[i];
|
||||||
if (avg <= static_cast<float>(lowVal))
|
if (ambienceCountComparator(avg)) {
|
||||||
{
|
|
||||||
++ambienceCount;
|
++ambienceCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1223,7 +1222,8 @@ public:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<PcloudAmbienceStimulusBuffer> ambienceBuff =
|
std::shared_ptr<PcloudAmbienceStimulusBuffer> ambienceBuff =
|
||||||
engine.parent.ambienceStimulusBuffer.load(std::memory_order_acquire);
|
engine.parent.ambienceStimulusBuffer.load(std::memory_order_acquire);
|
||||||
uint32_t lowVal = ambienceBuff->ambienceIntensityLowVal;
|
const auto& ambienceCountComparator =
|
||||||
|
ambienceBuff->ambienceCountComparator;
|
||||||
uint32_t postrinThreshold = ambienceBuff->postrinInterestThreshold;
|
uint32_t postrinThreshold = ambienceBuff->postrinInterestThreshold;
|
||||||
|
|
||||||
float* averageIntensityAverages = reinterpret_cast<float*>(
|
float* averageIntensityAverages = reinterpret_cast<float*>(
|
||||||
@@ -1233,8 +1233,7 @@ public:
|
|||||||
for (uint32_t i = 0; i < nSucceeded; ++i)
|
for (uint32_t i = 0; i < nSucceeded; ++i)
|
||||||
{
|
{
|
||||||
float avg = averageIntensityAverages[i];
|
float avg = averageIntensityAverages[i];
|
||||||
if (avg <= static_cast<float>(lowVal))
|
if (ambienceCountComparator(avg)) {
|
||||||
{
|
|
||||||
++framesMetThreshold;
|
++framesMetThreshold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||||
|
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <user/deviceAttachmentSpec.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace stim_buff {
|
||||||
|
|
||||||
|
enum ParamComparatorOp
|
||||||
|
{
|
||||||
|
OP_CMP_GT,
|
||||||
|
OP_CMP_LT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ParamComparator
|
||||||
|
{
|
||||||
|
ParamComparatorOp op;
|
||||||
|
uint32_t value;
|
||||||
|
|
||||||
|
bool operator()(float ambienceVal) const
|
||||||
|
{
|
||||||
|
switch (op)
|
||||||
|
{
|
||||||
|
case OP_CMP_GT:
|
||||||
|
return ambienceVal > static_cast<float>(value);
|
||||||
|
case OP_CMP_LT:
|
||||||
|
return ambienceVal < static_cast<float>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error("Unsupported ParamComparatorOp");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ParamComparator parsePcloudAmbienceParamComparator(
|
||||||
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec)
|
||||||
|
{
|
||||||
|
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
||||||
|
constexpr int kParamNotSpecified = -1;
|
||||||
|
const int gtVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
|
||||||
|
params, "ambience-count-gt-val", kParamNotSpecified);
|
||||||
|
const int ltVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
|
||||||
|
params, "ambience-count-lt-val", kParamNotSpecified);
|
||||||
|
|
||||||
|
if (gtVal != kParamNotSpecified && ltVal != kParamNotSpecified)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Only one of 'ambience-count-gt-val' or 'ambience-count-lt-val' "
|
||||||
|
"may be specified for a pcloudAmbience stim buff instance");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gtVal != kParamNotSpecified)
|
||||||
|
{
|
||||||
|
return ParamComparator{
|
||||||
|
.op = OP_CMP_GT,
|
||||||
|
.value = static_cast<uint32_t>(gtVal),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ltVal != kParamNotSpecified)
|
||||||
|
{
|
||||||
|
return ParamComparator{
|
||||||
|
.op = OP_CMP_LT,
|
||||||
|
.value = static_cast<uint32_t>(ltVal),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParamComparator{
|
||||||
|
.op = OP_CMP_LT,
|
||||||
|
.value = 8U,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace stim_buff
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <user/stagingBuffer.h>
|
#include <user/stagingBuffer.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <user/intrinThresholdParams.h>
|
#include <user/intrinThresholdParams.h>
|
||||||
|
#include "pcloudAmbienceQualeIfaceApi.h"
|
||||||
#include "lg1PcloudAmbienceStencil.h"
|
#include "lg1PcloudAmbienceStencil.h"
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -63,15 +64,8 @@ public:
|
|||||||
: 0U;
|
: 0U;
|
||||||
postrinInterestThreshold = intrin::resolveThresholdValue(
|
postrinInterestThreshold = intrin::resolveThresholdValue(
|
||||||
postrinInterestParam, nDgramsPerFrame_);
|
postrinInterestParam, nDgramsPerFrame_);
|
||||||
|
ambienceCountComparator = parsePcloudAmbienceParamComparator(
|
||||||
// Parse ambienceIntensityLowVal from qualeIfaceApiParams
|
deviceAttachmentSpec);
|
||||||
const std::vector<std::string> ambienceIntensityLowValParamNames = {
|
|
||||||
"ambience-intensity-low-val"
|
|
||||||
};
|
|
||||||
ambienceIntensityLowVal = static_cast<uint32_t>(
|
|
||||||
device::DeviceAttachmentSpec::parseOptionalParamAsIntWithSynonyms(
|
|
||||||
deviceAttachmentSpec->qualeIfaceApiParams,
|
|
||||||
ambienceIntensityLowValParamNames, 8));
|
|
||||||
|
|
||||||
// Construct stencils and add to list (FIFO behavior)
|
// Construct stencils and add to list (FIFO behavior)
|
||||||
for (size_t i = 0; i < nStencils; ++i) {
|
for (size_t i = 0; i < nStencils; ++i) {
|
||||||
@@ -90,7 +84,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
uint32_t postrinInterestPercentage;
|
uint32_t postrinInterestPercentage;
|
||||||
uint32_t postrinInterestThreshold;
|
uint32_t postrinInterestThreshold;
|
||||||
uint32_t ambienceIntensityLowVal;
|
ParamComparator ambienceCountComparator;
|
||||||
size_t nStencils;
|
size_t nStencils;
|
||||||
std::list<LG1PcloudAmbienceStencil> stencils;
|
std::list<LG1PcloudAmbienceStencil> stencils;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user