init
This commit is contained in:
+198
@@ -0,0 +1,198 @@
|
||||
#include "ovtkCAlgorithmClassifier.h"
|
||||
#include "ovtkCFeatureVector.hpp"
|
||||
#include "ovtkCFeatureVectorSet.hpp"
|
||||
#include "ovtkCVector.hpp"
|
||||
|
||||
#include <xml/IXMLHandler.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
bool CAlgorithmClassifier::initialize()
|
||||
{
|
||||
m_AlgorithmProxy = nullptr;
|
||||
m_ExtraParametersMap = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmClassifier::uninitialize()
|
||||
{
|
||||
if (m_AlgorithmProxy != nullptr)
|
||||
{
|
||||
m_AlgorithmProxy->uninitialize();
|
||||
this->getAlgorithmManager().releaseAlgorithm(*m_AlgorithmProxy);
|
||||
m_AlgorithmProxy = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmClassifier::process()
|
||||
{
|
||||
const Kernel::TParameterHandler<CMatrix*> ip_FeatureVector(this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_FeatureVector));
|
||||
const Kernel::TParameterHandler<CMatrix*> ip_FeatureVectorSet(this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_FeatureVectorSet));
|
||||
const Kernel::TParameterHandler<XML::IXMLNode*> ip_Config(this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_Config));
|
||||
|
||||
Kernel::TParameterHandler<double> op_EstimatedClass(this->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_Class));
|
||||
Kernel::TParameterHandler<CMatrix*> op_ClassificationValues(this->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues));
|
||||
Kernel::TParameterHandler<CMatrix*> op_ProbabilityValues(this->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ProbabilityValues));
|
||||
Kernel::TParameterHandler<XML::IXMLNode*> op_Config(this->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_Config));
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_Classifier_InputTriggerId_Train))
|
||||
{
|
||||
CMatrix* featureVectorSet = ip_FeatureVectorSet;
|
||||
if (!featureVectorSet)
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Feature vector set is NULL", Kernel::ErrorType::BadInput);
|
||||
}
|
||||
const CFeatureVectorSet featureVectorSetAdapter(*featureVectorSet);
|
||||
if (this->train(featureVectorSetAdapter)) { this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true); }
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Training failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_Classifier_InputTriggerId_Classify))
|
||||
{
|
||||
CMatrix* featureVector = ip_FeatureVector;
|
||||
CMatrix* classificationValues = op_ClassificationValues;
|
||||
CMatrix* probabilityValues = op_ProbabilityValues;
|
||||
|
||||
if (!featureVector || !classificationValues || !probabilityValues)
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Classifying failed", (!featureVector) ? Kernel::ErrorType::BadInput : Kernel::ErrorType::BadOutput);
|
||||
}
|
||||
double estimatedClass = 0;
|
||||
const CFeatureVector featureVectorAdapter(*featureVector);
|
||||
CVector classificationValuesAdapter(*classificationValues);
|
||||
CVector probabilityValuesAdapter(*probabilityValues);
|
||||
|
||||
if (this->classify(featureVectorAdapter, estimatedClass, classificationValuesAdapter, probabilityValuesAdapter))
|
||||
{
|
||||
op_EstimatedClass = estimatedClass;
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Classifying failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_Classifier_InputTriggerId_SaveConfig))
|
||||
{
|
||||
XML::IXMLNode* rootNode = this->saveConfig();
|
||||
op_Config = rootNode;
|
||||
if (rootNode) { this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true); }
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Saving configuration failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_Classifier_InputTriggerId_LoadConfig))
|
||||
{
|
||||
XML::IXMLNode* rootNode = ip_Config;
|
||||
if (!rootNode)
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Configuration XML node is NULL", Kernel::ErrorType::BadInput);
|
||||
}
|
||||
if (this->loadConfig(rootNode))
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true);
|
||||
//Now we need to parametrize the two output Matrix for values
|
||||
setMatrixOutputDimension(op_ProbabilityValues, this->getNProbabilities());
|
||||
setMatrixOutputDimension(op_ClassificationValues, this->getNDistances());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Loading configuration failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmClassifier::initializeExtraParameterMechanism()
|
||||
{
|
||||
const Kernel::TParameterHandler<std::map<CString, CString>*> ip_ExtraParameter(
|
||||
this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter));
|
||||
m_ExtraParametersMap = static_cast<std::map<CString, CString>*>(ip_ExtraParameter);
|
||||
|
||||
m_AlgorithmProxy = &this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(this->getClassIdentifier()));
|
||||
|
||||
OV_ERROR_UNLESS_KRF(m_AlgorithmProxy->initialize(), "Failed to initialize algorithm", Kernel::ErrorType::Internal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmClassifier::uninitializeExtraParameterMechanism()
|
||||
{
|
||||
OV_ERROR_UNLESS_KRF(m_AlgorithmProxy->uninitialize(), "Failed to uninitialize algorithm", Kernel::ErrorType::Internal);
|
||||
|
||||
this->getAlgorithmManager().releaseAlgorithm(*m_AlgorithmProxy);
|
||||
|
||||
m_AlgorithmProxy = nullptr;
|
||||
m_ExtraParametersMap = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
CString& CAlgorithmClassifier::getParameterValue(const CIdentifier& parameterID) const
|
||||
{
|
||||
const CString parameterName = m_AlgorithmProxy->getInputParameterName(parameterID);
|
||||
return (*static_cast<std::map<CString, CString>*>(m_ExtraParametersMap))[parameterName];
|
||||
}
|
||||
|
||||
void CAlgorithmClassifier::setMatrixOutputDimension(Kernel::TParameterHandler<CMatrix*>& matrix, const size_t length) { matrix->resize(length); }
|
||||
|
||||
uint64_t CAlgorithmClassifier::getUInt64Parameter(const CIdentifier& parameterID)
|
||||
{
|
||||
Kernel::TParameterHandler<uint64_t> temp(getInputParameter(parameterID));
|
||||
temp = this->getAlgorithmContext().getConfigurationManager().expandAsUInteger(getParameterValue(parameterID));
|
||||
return uint64_t(temp);
|
||||
}
|
||||
|
||||
int64_t CAlgorithmClassifier::getInt64Parameter(const CIdentifier& parameterID)
|
||||
{
|
||||
Kernel::TParameterHandler<int64_t> temp(getInputParameter(parameterID));
|
||||
temp = this->getAlgorithmContext().getConfigurationManager().expandAsInteger(getParameterValue(parameterID));
|
||||
return int64_t(temp);
|
||||
}
|
||||
|
||||
double CAlgorithmClassifier::getDoubleParameter(const CIdentifier& parameterID)
|
||||
{
|
||||
Kernel::TParameterHandler<double> temp(getInputParameter(parameterID));
|
||||
temp = this->getAlgorithmContext().getConfigurationManager().expandAsFloat(getParameterValue(parameterID));
|
||||
return double(temp);
|
||||
}
|
||||
|
||||
bool CAlgorithmClassifier::getBooleanParameter(const CIdentifier& parameterID)
|
||||
{
|
||||
Kernel::TParameterHandler<bool> temp(getInputParameter(parameterID));
|
||||
temp = this->getAlgorithmContext().getConfigurationManager().expandAsBoolean(getParameterValue(parameterID));
|
||||
return bool(temp);
|
||||
}
|
||||
|
||||
CString* CAlgorithmClassifier::getCStringParameter(const CIdentifier& parameterID)
|
||||
{
|
||||
Kernel::TParameterHandler<CString*> temp(getInputParameter(parameterID));
|
||||
temp = &getParameterValue(parameterID);
|
||||
return static_cast<CString*>(temp);
|
||||
}
|
||||
|
||||
uint64_t CAlgorithmClassifier::getEnumerationParameter(const CIdentifier& parameterID, const CIdentifier& enumerationIdentifier)
|
||||
{
|
||||
Kernel::TParameterHandler<uint64_t> temp(getInputParameter(parameterID));
|
||||
temp = this->getTypeManager().getEnumerationEntryValueFromName(enumerationIdentifier, getParameterValue(parameterID));
|
||||
return uint64_t(temp);
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#include "ovtkCAlgorithmClassifierTrainer.h"
|
||||
#include "ovtkCFeatureVectorSet.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
bool CAlgorithmClassifierTrainer::process()
|
||||
{
|
||||
Kernel::TParameterHandler<CMatrix*> ip_featureVectorSet(this->getInputParameter(OVTK_Algorithm_ClassifierTrainer_InputParameterId_FeatureVectorSet));
|
||||
Kernel::TParameterHandler<IMemoryBuffer*> op_config(this->getOutputParameter(OVTK_Algorithm_ClassifierTrainer_OutputParameterId_Config));
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_ClassifierTrainer_InputTriggerId_Train))
|
||||
{
|
||||
CMatrix* featureVectorSet = ip_featureVectorSet;
|
||||
if (!featureVectorSet)
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Feature vector set is NULL", Kernel::ErrorType::BadInput);
|
||||
}
|
||||
const CFeatureVectorSet featureVectorSetAdapter(*featureVectorSet);
|
||||
if (this->train(featureVectorSetAdapter)) { this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Success, true); }
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Training failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_ClassifierTrainer_InputTriggerId_SaveConfig))
|
||||
{
|
||||
IMemoryBuffer* config = op_config;
|
||||
if (!config)
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Configuration memory buffer is NULL", Kernel::ErrorType::BadOutput);
|
||||
}
|
||||
config->setSize(0, true);
|
||||
if (this->saveConfig(*config)) { this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Success, true); }
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_ClassifierTrainer_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Saving configuration failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#include "ovtkCAlgorithmClassifier.h"
|
||||
#include "ovtkCAlgorithmPairingStrategy.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
static std::map<uint64_t, fClassifierComparison> comparisionFunctions;
|
||||
|
||||
void registerClassificationComparisonFunction(const CIdentifier& classID, const fClassifierComparison comparision)
|
||||
{
|
||||
comparisionFunctions[classID.id()] = comparision;
|
||||
}
|
||||
|
||||
fClassifierComparison getClassificationComparisonFunction(const CIdentifier& classID)
|
||||
{
|
||||
if (comparisionFunctions.count(classID.id()) == 0) { return nullptr; }
|
||||
return comparisionFunctions[classID.id()];
|
||||
}
|
||||
|
||||
bool CAlgorithmPairingStrategy::process()
|
||||
{
|
||||
if (this->isInputTriggerActive(OVTK_Algorithm_PairingStrategy_InputTriggerId_DesignArchitecture))
|
||||
{
|
||||
Kernel::TParameterHandler<CIdentifier*>
|
||||
ip_classifierID(this->getInputParameter(OVTK_Algorithm_PairingStrategy_InputParameterId_SubClassifierAlgorithm));
|
||||
Kernel::TParameterHandler<uint64_t> ip_nClass(this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_NClasses));
|
||||
|
||||
const uint64_t nClass = uint64_t(ip_nClass);
|
||||
const CIdentifier classifierID = *static_cast<CIdentifier*>(ip_classifierID);
|
||||
if (this->designArchitecture(classifierID, size_t(nClass))) { this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true); }
|
||||
else
|
||||
{
|
||||
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
|
||||
OV_ERROR_KRF("Designing architecture failed", Kernel::ErrorType::Internal);
|
||||
}
|
||||
}
|
||||
else { return CAlgorithmClassifier::process(); }
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovtkCVector.hpp"
|
||||
#include "../../ovtkIFeatureVector.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
template <class TParent>
|
||||
class TFeatureVector final : public TVector<TParent>
|
||||
{
|
||||
public:
|
||||
|
||||
explicit TFeatureVector(CMatrix& rMatrix) : TVector<TParent>(rMatrix) { }
|
||||
|
||||
double getLabel() const override { return 0; }
|
||||
bool setLabel(const double /*label*/) override { return false; }
|
||||
|
||||
_IsDerivedFromClass_Final_(TVector<TParent>, CIdentifier::undefined())
|
||||
};
|
||||
|
||||
typedef TFeatureVector<IFeatureVector> CFeatureVector;
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#include "ovtkCFeatureVectorSet.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
CFeatureVectorSet::CFeatureVectorSet(const CMatrix& matrix) : m_matrix(matrix)
|
||||
{
|
||||
if (matrix.getDimensionCount() != 2) { throw std::runtime_error("Fetaure vector set matrix must be 2 dimensions"); }
|
||||
|
||||
for (size_t i = 0; i < matrix.getDimensionSize(0); ++i)
|
||||
{
|
||||
m_features[i].m_Matrix = &matrix;
|
||||
m_features[i].m_DimensionIdx = i;
|
||||
m_features[i].m_Size = matrix.getDimensionSize(1) - 1;
|
||||
m_features[i].m_Buffer = matrix.getBuffer() + i * matrix.getDimensionSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
IFeatureVector& CFeatureVectorSet::getFeatureVector(const size_t index) { return m_features.find(index)->second; }
|
||||
|
||||
const IFeatureVector& CFeatureVectorSet::getFeatureVector(const size_t index) const { return m_features.find(index)->second; }
|
||||
|
||||
size_t CFeatureVectorSet::getLabelCount() const
|
||||
{
|
||||
std::map<double, bool> labels;
|
||||
for (auto it = m_features.begin(); it != m_features.end(); ++it) { labels[it->second.getLabel()] = true; }
|
||||
return labels.size();
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../ovtkIFeatureVector.h"
|
||||
#include "../../ovtkIFeatureVectorSet.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
class CInternalFeatureVector final : public IFeatureVector
|
||||
{
|
||||
public:
|
||||
|
||||
CInternalFeatureVector() { }
|
||||
uint32_t getSize() const override { return m_Size; }
|
||||
bool setSize(const uint32_t /*size*/) override { return false; }
|
||||
double* getBuffer() override { return nullptr; }
|
||||
const double* getBuffer() const override { return m_Buffer; }
|
||||
const char* getElementLabel(const uint32_t index) const override { return m_Matrix->getDimensionLabel(m_DimensionIdx, index); }
|
||||
bool setElementLabel(const uint32_t /*index*/, const char* /*elementLabel*/) override { return false; }
|
||||
double getLabel() const override { return m_Buffer[m_Size]; }
|
||||
bool setLabel(const double /*label*/) override { return false; }
|
||||
|
||||
_IsDerivedFromClass_Final_(IFeatureVector, CIdentifier::undefined())
|
||||
|
||||
const CMatrix* m_Matrix = nullptr;
|
||||
uint32_t m_DimensionIdx = 0;
|
||||
uint32_t m_Size = 0;
|
||||
const double* m_Buffer = nullptr;
|
||||
};
|
||||
|
||||
class CFeatureVectorSet final : public IFeatureVectorSet
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CFeatureVectorSet(const CMatrix& matrix);
|
||||
size_t getFeatureVectorCount() const override { return m_matrix.getDimensionSize(0); }
|
||||
bool setFeatureVectorCount(const size_t /*nFeatureVector*/) override { return false; }
|
||||
bool addFeatureVector(const IFeatureVector& /*featureVector*/) override { return false; }
|
||||
IFeatureVector& getFeatureVector(const size_t index) override;
|
||||
const IFeatureVector& getFeatureVector(const size_t index) const override;
|
||||
size_t getLabelCount() const override;
|
||||
|
||||
_IsDerivedFromClass_Final_(IFeatureVectorSet, CIdentifier::undefined())
|
||||
|
||||
protected:
|
||||
|
||||
const CMatrix& m_matrix;
|
||||
std::map<uint32_t, CInternalFeatureVector> m_features;
|
||||
};
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../ovtk_base.h"
|
||||
#include "../../ovtkIVector.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
template <class TParent>
|
||||
class TVector : public TParent
|
||||
{
|
||||
public:
|
||||
|
||||
explicit TVector(CMatrix& matrix) : m_matrix(matrix) { }
|
||||
|
||||
uint32_t getSize() const override { return m_matrix.getBufferElementCount(); }
|
||||
|
||||
bool setSize(const uint32_t size) override
|
||||
{
|
||||
m_matrix.resize(size);
|
||||
return true;
|
||||
}
|
||||
|
||||
double* getBuffer() override { return m_matrix.getBuffer(); }
|
||||
const double* getBuffer() const override { return m_matrix.getBuffer(); }
|
||||
const char* getElementLabel(const uint32_t index) const override { return m_matrix.getDimensionLabel(0, index); }
|
||||
|
||||
bool setElementLabel(const uint32_t index, const char* label) override
|
||||
{
|
||||
m_matrix.setDimensionLabel(0, index, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
_IsDerivedFromClass_Final_(TParent, CIdentifier::undefined())
|
||||
|
||||
protected:
|
||||
|
||||
CMatrix& m_matrix;
|
||||
};
|
||||
|
||||
typedef TVector<IVector> CVector;
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+403
@@ -0,0 +1,403 @@
|
||||
#include "ovtkCAlgorithmScenarioExporter.h"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
namespace {
|
||||
class CAlgorithmScenarioExporterHelper
|
||||
{
|
||||
friend class CAlgorithmScenarioExporter;
|
||||
public:
|
||||
|
||||
CAlgorithmScenarioExporterHelper(Kernel::IAlgorithmContext& context, CAlgorithmScenarioExporter& parent);
|
||||
bool exportBox(IMemoryBuffer& buffer, const Kernel::IBox& box) const;
|
||||
bool exportComment(IMemoryBuffer& buffer, const Kernel::IComment& comment) const;
|
||||
bool exportMetadata(IMemoryBuffer& buffer, const Kernel::IMetadata& metadata) const;
|
||||
bool exportSetting(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, const size_t index) const;
|
||||
bool exportInput(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, size_t index) const;
|
||||
bool exportOutput(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, size_t index) const;
|
||||
bool exportLink(IMemoryBuffer& buffer, const Kernel::ILink& link) const;
|
||||
void exportAttributes(const Kernel::IAttributable& attributable, IMemoryBuffer& buffer, const CIdentifier& idAttributes,
|
||||
const CIdentifier& idAttribute, const CIdentifier& idAttributeID, const CIdentifier& idAttributeValue) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Kernel::IAlgorithmContext& m_algorithmContext;
|
||||
CAlgorithmScenarioExporter& m_parent;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
#define exportAttributesMacro(exporter, attributable, memoryBuffer, AttributableName) \
|
||||
do { \
|
||||
(exporter).exportAttributes(attributable, memoryBuffer, \
|
||||
OVTK_Algorithm_ScenarioExporter_NodeId_##AttributableName##_Attributes, \
|
||||
OVTK_Algorithm_ScenarioExporter_NodeId_##AttributableName##_Attribute, \
|
||||
OVTK_Algorithm_ScenarioExporter_NodeId_##AttributableName##_Attribute_ID, \
|
||||
OVTK_Algorithm_ScenarioExporter_NodeId_##AttributableName##_Attribute_Value); \
|
||||
} while (0)
|
||||
|
||||
void CAlgorithmScenarioExporterHelper::exportAttributes(const Kernel::IAttributable& attributable, IMemoryBuffer& buffer, const CIdentifier& idAttributes,
|
||||
const CIdentifier& idAttribute, const CIdentifier& idAttributeID,
|
||||
const CIdentifier& idAttributeValue) const
|
||||
{
|
||||
if (attributable.getNextAttributeIdentifier(CIdentifier::undefined()) != CIdentifier::undefined())
|
||||
{
|
||||
CIdentifier attributeIdentifier;
|
||||
m_parent.exportStart(buffer, idAttributes);
|
||||
while ((attributeIdentifier = attributable.getNextAttributeIdentifier(attributeIdentifier)) != CIdentifier::undefined())
|
||||
{
|
||||
// do not export attributes that are used only in the designer for bookkeeping
|
||||
if ((attributeIdentifier != OV_AttributeId_Box_ToBeUpdated) && (attributeIdentifier != OV_AttributeId_Box_PendingDeprecatedInterfacors))
|
||||
{
|
||||
m_parent.exportStart(buffer, idAttribute);
|
||||
m_parent.exportIdentifier(buffer, idAttributeID, attributeIdentifier);
|
||||
m_parent.exportString(buffer, idAttributeValue, attributable.getAttributeValue(attributeIdentifier));
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
}
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CAlgorithmScenarioExporter::process()
|
||||
{
|
||||
const CAlgorithmScenarioExporterHelper helper(this->getAlgorithmContext(), *this);
|
||||
CMemoryBuffer tmpBuffer;
|
||||
|
||||
// preallocates 1 Mbytes
|
||||
tmpBuffer.reserve(1024 * 1024);
|
||||
|
||||
Kernel::TParameterHandler<Kernel::IScenario*> ip_scenario(this->getInputParameter(OV_Algorithm_ScenarioExporter_InputParameterId_Scenario));
|
||||
Kernel::IScenario* scenario = ip_scenario;
|
||||
|
||||
OV_ERROR_UNLESS_KRF(scenario, "Input scenario is NULL", Kernel::ErrorType::BadInput);
|
||||
|
||||
Kernel::TParameterHandler<IMemoryBuffer*> op_buffer(this->getOutputParameter(OV_Algorithm_ScenarioExporter_OutputParameterId_MemoryBuffer));
|
||||
IMemoryBuffer* buffer = op_buffer;
|
||||
|
||||
OV_ERROR_UNLESS_KRF(buffer, "Output memory buffer is NULL", Kernel::ErrorType::BadOutput);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_OpenViBEScenario);
|
||||
this->exportString(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_FormatVersion, CString("2"));
|
||||
this->exportString(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Creator, this->getConfigurationManager().expand("${Application_Name}"));
|
||||
this->exportString(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_CreatorVersion, this->getConfigurationManager().expand("${Application_Version}"));
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Settings);
|
||||
for (size_t i = 0; i < scenario->getSettingCount(); ++i) { helper.exportSetting(tmpBuffer, *scenario, i); }
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Inputs);
|
||||
for (size_t i = 0; i < scenario->getInputCount(); ++i) { helper.exportInput(tmpBuffer, *scenario, i); }
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Outputs);
|
||||
for (size_t i = 0; i < scenario->getOutputCount(); ++i) { helper.exportOutput(tmpBuffer, *scenario, i); }
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Boxes);
|
||||
{
|
||||
CIdentifier* listID = nullptr;
|
||||
size_t nbElems = 0;
|
||||
scenario->getBoxIdentifierList(&listID, &nbElems);
|
||||
for (size_t i = 0; i < nbElems; ++i) { helper.exportBox(tmpBuffer, *scenario->getBoxDetails(listID[i])); }
|
||||
scenario->releaseIdentifierList(listID);
|
||||
}
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Links);
|
||||
{
|
||||
CIdentifier* listID = nullptr;
|
||||
size_t nbElems = 0;
|
||||
scenario->getLinkIdentifierList(&listID, &nbElems);
|
||||
for (size_t i = 0; i < nbElems; ++i)
|
||||
{
|
||||
const Kernel::ILink* link = scenario->getLinkDetails(listID[i]);
|
||||
// do not export invalid links
|
||||
if (!link->hasAttribute(OV_AttributeId_Link_Invalid)) { helper.exportLink(tmpBuffer, *link); }
|
||||
}
|
||||
scenario->releaseIdentifierList(listID);
|
||||
}
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Comments);
|
||||
{
|
||||
CIdentifier* listID = nullptr;
|
||||
size_t nbElems = 0;
|
||||
scenario->getCommentIdentifierList(&listID, &nbElems);
|
||||
for (size_t i = 0; i < nbElems; ++i) { helper.exportComment(tmpBuffer, *scenario->getCommentDetails(listID[i])); }
|
||||
scenario->releaseIdentifierList(listID);
|
||||
}
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
this->exportStart(tmpBuffer, OVTK_Algorithm_ScenarioExporter_NodeId_Metadata);
|
||||
{
|
||||
CIdentifier* listID = nullptr;
|
||||
size_t nbElems = 0;
|
||||
scenario->getMetadataIdentifierList(&listID, &nbElems);
|
||||
for (size_t i = 0; i < nbElems; ++i) { helper.exportMetadata(tmpBuffer, *scenario->getMetadataDetails(listID[i])); }
|
||||
scenario->releaseIdentifierList(listID);
|
||||
}
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
exportAttributesMacro(helper, *scenario, tmpBuffer, Scenario);
|
||||
|
||||
this->exportStop(tmpBuffer);
|
||||
|
||||
buffer->setSize(0, true);
|
||||
buffer->append(tmpBuffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CAlgorithmScenarioExporterHelper::CAlgorithmScenarioExporterHelper(Kernel::IAlgorithmContext& context, CAlgorithmScenarioExporter& parent)
|
||||
: m_algorithmContext(context), m_parent(parent) {}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportBox(IMemoryBuffer& buffer, const Kernel::IBox& box) const
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_ID, box.getIdentifier());
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Name, box.getName());
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_AlgorithmClassIdD, box.getAlgorithmClassIdentifier());
|
||||
|
||||
if (box.getInputCount() != 0)
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Inputs);
|
||||
for (size_t i = 0; i < box.getInputCount(); ++i)
|
||||
{
|
||||
CIdentifier inputID;
|
||||
CIdentifier inputTypeID;
|
||||
CString inputName;
|
||||
box.getInputType(i, inputTypeID);
|
||||
box.getInputName(i, inputName);
|
||||
box.getInterfacorIdentifier(Kernel::Input, i, inputID);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input);
|
||||
if (inputID != CIdentifier::undefined()) { m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_ID, inputID); }
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_TypeID, inputTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_Name, inputName);
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
|
||||
if (box.getOutputCount() != 0)
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Outputs);
|
||||
for (size_t i = 0; i < box.getOutputCount(); ++i)
|
||||
{
|
||||
CIdentifier outputID;
|
||||
CIdentifier outputTypeID;
|
||||
CString outputName;
|
||||
box.getOutputType(i, outputTypeID);
|
||||
box.getOutputName(i, outputName);
|
||||
box.getInterfacorIdentifier(Kernel::Output, i, outputID);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output);
|
||||
if (outputID != CIdentifier::undefined()) { m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_ID, outputID); }
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_TypeID, outputTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_Name, outputName);
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
|
||||
if (box.getSettingCount() != 0)
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Settings);
|
||||
for (size_t i = 0; i < box.getSettingCount(); ++i)
|
||||
{
|
||||
CIdentifier settingID;
|
||||
CIdentifier settingTypeID;
|
||||
CString settingName;
|
||||
CString defaultValue;
|
||||
CString value;
|
||||
bool modifiability;
|
||||
box.getInterfacorIdentifier(Kernel::Setting, i, settingID);
|
||||
box.getSettingType(i, settingTypeID);
|
||||
box.getSettingName(i, settingName);
|
||||
box.getSettingDefaultValue(i, defaultValue);
|
||||
box.getSettingValue(i, value);
|
||||
box.getSettingMod(i, modifiability);
|
||||
|
||||
CString str;
|
||||
if (modifiability) { str = CString("true"); }
|
||||
else { str = CString("false"); }
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting);
|
||||
if (settingID != CIdentifier::undefined()) // do not export identifier if not defined
|
||||
{
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_ID, settingID);
|
||||
}
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_TypeID, settingTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Name, settingName);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_DefaultValue, defaultValue);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Value, value);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Modifiability, str);
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
m_parent.exportStop(buffer);
|
||||
}
|
||||
|
||||
exportAttributesMacro((*this), box, buffer, Box);
|
||||
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportComment(IMemoryBuffer& buffer, const Kernel::IComment& comment) const
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Comment);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Comment_ID, comment.getIdentifier());
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Text, comment.getText());
|
||||
|
||||
exportAttributesMacro((*this), comment, buffer, Comment);
|
||||
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportMetadata(IMemoryBuffer& buffer, const Kernel::IMetadata& metadata) const
|
||||
{
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_ID, metadata.getIdentifier());
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_Type, metadata.getType());
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_Data, metadata.getData());
|
||||
m_parent.exportStop(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportLink(IMemoryBuffer& buffer, const Kernel::ILink& link) const
|
||||
{
|
||||
CIdentifier srcBoxID;
|
||||
CIdentifier dstBoxID;
|
||||
size_t srcBoxOutputIdx = size_t(-1);
|
||||
size_t dstBoxInputIdx = size_t(-1);
|
||||
CIdentifier srcBoxOutputID;
|
||||
CIdentifier dstBoxInputID;
|
||||
|
||||
link.getSource(srcBoxID, srcBoxOutputIdx, srcBoxOutputID);
|
||||
link.getTarget(dstBoxID, dstBoxInputIdx, dstBoxInputID);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_ID, link.getIdentifier());
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxID, srcBoxID);
|
||||
if (srcBoxOutputID != CIdentifier::undefined())
|
||||
{
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxOutputID, srcBoxOutputID);
|
||||
}
|
||||
else { m_parent.exportUInteger(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxOutputIdx, srcBoxOutputIdx); }
|
||||
m_parent.exportStop(buffer);
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxID, dstBoxID);
|
||||
if (dstBoxInputID != CIdentifier::undefined())
|
||||
{
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxInputID, dstBoxInputID);
|
||||
}
|
||||
else { m_parent.exportUInteger(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxInputIdx, dstBoxInputIdx); }
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
exportAttributesMacro((*this), link, buffer, Link);
|
||||
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportSetting(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, const size_t index) const
|
||||
{
|
||||
CIdentifier settingID;
|
||||
CIdentifier settingTypeID;
|
||||
CString settingName;
|
||||
CString defaultValue;
|
||||
CString value;
|
||||
|
||||
|
||||
scenario.getSettingName(index, settingName);
|
||||
scenario.getInterfacorIdentifier(Kernel::Setting, index, settingID);
|
||||
scenario.getSettingType(index, settingTypeID);
|
||||
scenario.getSettingValue(index, value);
|
||||
scenario.getSettingDefaultValue(index, defaultValue);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_ID, settingID);
|
||||
m_parent.exportIdentifier(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_TypeID, settingTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_Name, settingName);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_DefaultValue, defaultValue);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_Value, value);
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportInput(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, const size_t index) const
|
||||
{
|
||||
CIdentifier inputID;
|
||||
CIdentifier inputTypeID;
|
||||
CString inputName;
|
||||
CIdentifier linkedBoxID;
|
||||
size_t linkedBoxInputIdx;
|
||||
CIdentifier linkedBoxInputID;
|
||||
|
||||
scenario.getInterfacorIdentifier(Kernel::Input, index, inputID);
|
||||
scenario.getInputType(index, inputTypeID);
|
||||
scenario.getInputName(index, inputName);
|
||||
scenario.getScenarioInputLink(index, linkedBoxID, linkedBoxInputIdx);
|
||||
scenario.getScenarioInputLink(index, linkedBoxID, linkedBoxInputID);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input);
|
||||
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_ID, inputID);
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_TypeID, inputTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_Name, inputName);
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxID, linkedBoxID);
|
||||
if (linkedBoxInputID != CIdentifier::undefined())
|
||||
{
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxInputID, linkedBoxInputID);
|
||||
}
|
||||
else { m_parent.exportUInteger(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxInputIdx, uint64_t(linkedBoxInputIdx)); }
|
||||
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioExporterHelper::exportOutput(IMemoryBuffer& buffer, const Kernel::IScenario& scenario, const size_t index) const
|
||||
{
|
||||
CIdentifier outputID;
|
||||
CIdentifier outputTypeID;
|
||||
CString outputName;
|
||||
CIdentifier linkedBoxID;
|
||||
size_t linkedBoxOutputIdx;
|
||||
CIdentifier linkedBoxOutputID;
|
||||
|
||||
scenario.getInterfacorIdentifier(Kernel::Output, index, outputID);
|
||||
scenario.getOutputType(index, outputTypeID);
|
||||
scenario.getOutputName(index, outputName);
|
||||
scenario.getScenarioOutputLink(index, linkedBoxID, linkedBoxOutputIdx);
|
||||
scenario.getScenarioOutputLink(index, linkedBoxID, linkedBoxOutputID);
|
||||
|
||||
m_parent.exportStart(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output);
|
||||
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_ID, outputID);
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_TypeID, outputTypeID);
|
||||
m_parent.exportString(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_Name, outputName);
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxID, linkedBoxID);
|
||||
if (linkedBoxOutputID != CIdentifier::undefined())
|
||||
{
|
||||
m_parent.exportIdentifier(buffer,OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxOutputID, linkedBoxOutputID);
|
||||
}
|
||||
else { m_parent.exportUInteger(buffer, OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxOutputIdx, uint64_t(linkedBoxOutputIdx)); }
|
||||
|
||||
m_parent.exportStop(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
+509
@@ -0,0 +1,509 @@
|
||||
#include "ovtkCAlgorithmScenarioImporter.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
namespace {
|
||||
typedef struct SScenarioInput
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CIdentifier typeID = CIdentifier::undefined();
|
||||
CString name;
|
||||
CIdentifier linkedBoxID = CIdentifier::undefined();
|
||||
size_t linkedBoxInputIdx = size_t(-1);
|
||||
CIdentifier linkedBoxInputID = CIdentifier::undefined();
|
||||
} scenario_input_t;
|
||||
|
||||
typedef struct SScenarioOutput
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CIdentifier typeID = CIdentifier::undefined();
|
||||
CString name;
|
||||
CIdentifier linkedBoxID = CIdentifier::undefined();
|
||||
size_t linkedBoxOutputIdx = size_t(-1);
|
||||
CIdentifier linkedBoxOutputID = CIdentifier::undefined();
|
||||
} scenario_output_t;
|
||||
|
||||
typedef struct SInput
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CIdentifier typeID = CIdentifier::undefined();
|
||||
CString name;
|
||||
} input_t;
|
||||
|
||||
typedef struct SOutput
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CIdentifier typeID = CIdentifier::undefined();
|
||||
CString name;
|
||||
} output_t;
|
||||
|
||||
typedef struct SSetting
|
||||
{
|
||||
CIdentifier typeID = CIdentifier::undefined();
|
||||
CString name;
|
||||
CString defaultValue;
|
||||
CString value;
|
||||
bool modifiability = false;
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
} setting_t;
|
||||
|
||||
typedef struct SAttribute
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CString value;
|
||||
} attribute_t;
|
||||
|
||||
typedef struct SBox
|
||||
{
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
CIdentifier algorithmClassID = CIdentifier::undefined();
|
||||
CString name;
|
||||
std::vector<input_t> inputs;
|
||||
std::vector<output_t> outputs;
|
||||
std::vector<setting_t> settings;
|
||||
std::vector<attribute_t> attributes;
|
||||
} box_t;
|
||||
|
||||
typedef struct SComment
|
||||
{
|
||||
CIdentifier id;
|
||||
CString text;
|
||||
std::vector<attribute_t> attributes;
|
||||
} comment_t;
|
||||
|
||||
typedef struct SMetadata
|
||||
{
|
||||
CIdentifier identifier;
|
||||
CIdentifier type;
|
||||
CString data;
|
||||
} metadata_t;
|
||||
|
||||
typedef struct SLinkSrc
|
||||
{
|
||||
CIdentifier boxID;
|
||||
size_t boxOutputIdx = size_t(-1);
|
||||
CIdentifier boxOutputID = CIdentifier::undefined();
|
||||
} link_src_t;
|
||||
|
||||
typedef struct SLinkDst
|
||||
{
|
||||
CIdentifier boxID;
|
||||
size_t boxInputIdx = size_t(-1);
|
||||
CIdentifier boxInputID = CIdentifier::undefined();
|
||||
} link_dst_t;
|
||||
|
||||
typedef struct SLink
|
||||
{
|
||||
CIdentifier id;
|
||||
link_src_t linkSrc;
|
||||
link_dst_t linkDst;
|
||||
std::vector<attribute_t> attributes;
|
||||
} link_t;
|
||||
|
||||
typedef struct SScenario
|
||||
{
|
||||
std::vector<setting_t> settings;
|
||||
std::vector<scenario_input_t> iScenarios;
|
||||
std::vector<scenario_output_t> oScenarios;
|
||||
std::vector<box_t> boxes;
|
||||
std::vector<comment_t> comments;
|
||||
std::vector<metadata_t> metadata;
|
||||
std::vector<link_t> links;
|
||||
std::vector<attribute_t> attributes;
|
||||
} scenario_t;
|
||||
} // namespace
|
||||
|
||||
class CAlgorithmScenarioImporterContext final : public Plugins::IAlgorithmScenarioImporterContext
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CAlgorithmScenarioImporterContext(Kernel::IAlgorithmContext& algorithmCtx) : m_AlgorithmContext(algorithmCtx) { }
|
||||
|
||||
bool processStart(const CIdentifier& identifier) override;
|
||||
bool processIdentifier(const CIdentifier& identifier, const CIdentifier& value) override;
|
||||
bool processString(const CIdentifier& identifier, const CString& value) override;
|
||||
bool processUInteger(const CIdentifier& identifier, uint64_t value) override;
|
||||
bool processStop() override { return true; }
|
||||
|
||||
_IsDerivedFromClass_Final_(IAlgorithmScenarioImporterContext, CIdentifier::undefined())
|
||||
|
||||
Kernel::IAlgorithmContext& m_AlgorithmContext;
|
||||
scenario_t m_SymbolicScenario;
|
||||
};
|
||||
|
||||
|
||||
bool CAlgorithmScenarioImporter::process()
|
||||
{
|
||||
Kernel::TParameterHandler<Kernel::IScenario*> op_scenario(this->getOutputParameter(OV_Algorithm_ScenarioImporter_OutputParameterId_Scenario));
|
||||
Kernel::IScenario* scenario = op_scenario;
|
||||
|
||||
OV_ERROR_UNLESS_KRF(scenario, "Output scenario is NULL", Kernel::ErrorType::BadOutput);
|
||||
|
||||
Kernel::TParameterHandler<IMemoryBuffer*> ip_buffer(this->getInputParameter(OV_Algorithm_ScenarioImporter_InputParameterId_MemoryBuffer));
|
||||
IMemoryBuffer* memoryBuffer = ip_buffer;
|
||||
|
||||
OV_ERROR_UNLESS_KRF(memoryBuffer, "Input memory buffer is NULL", Kernel::ErrorType::BadInput);
|
||||
|
||||
std::map<CIdentifier, CIdentifier> boxIdMapping;
|
||||
|
||||
CAlgorithmScenarioImporterContext context(this->getAlgorithmContext());
|
||||
|
||||
OV_ERROR_UNLESS_KRF(this->import(context, *memoryBuffer), "Import failed", Kernel::ErrorType::Internal);
|
||||
|
||||
scenario_t& symbolicScenario = context.m_SymbolicScenario;
|
||||
|
||||
// Now build the scenario according to what has been loaded
|
||||
|
||||
for (auto s = symbolicScenario.settings.begin(); s != symbolicScenario.settings.end(); ++s)
|
||||
{
|
||||
CIdentifier settingID = s->id;
|
||||
// compute identifier only if it does not exists
|
||||
if (settingID == CIdentifier::undefined()) { settingID = scenario->getUnusedSettingIdentifier(); }
|
||||
scenario->addSetting(s->name, s->typeID, s->defaultValue, size_t(-1), false, settingID);
|
||||
scenario->setSettingValue(scenario->getSettingCount() - 1, s->value);
|
||||
}
|
||||
|
||||
|
||||
for (auto b = symbolicScenario.boxes.begin(); b != symbolicScenario.boxes.end(); ++b)
|
||||
{
|
||||
Kernel::IBox* box = nullptr;
|
||||
CIdentifier newBoxID;
|
||||
|
||||
scenario->addBox(newBoxID, b->id);
|
||||
box = scenario->getBoxDetails(newBoxID);
|
||||
if (box)
|
||||
{
|
||||
box->setName(b->name);
|
||||
|
||||
for (auto i = b->inputs.begin(); i != b->inputs.end(); ++i) { box->addInput(i->name, i->typeID, i->id); }
|
||||
|
||||
for (auto o = b->outputs.begin(); o != b->outputs.end(); ++o) { box->addOutput(o->name, o->typeID, o->id); }
|
||||
for (auto s = b->settings.begin(); s != b->settings.end(); ++s)
|
||||
{
|
||||
const CIdentifier& type = s->typeID;
|
||||
if (!this->getTypeManager().isRegistered(type) && !(this->getTypeManager().isEnumeration(type)) && (!this->getTypeManager().isBitMask(type)))
|
||||
{
|
||||
const std::string msg = std::string("The type of the setting ") + s->name.toASCIIString() + " (" + type.str() + ") from box "
|
||||
+ b->name.toASCIIString() + " cannot be recognized.";
|
||||
|
||||
if (this->getConfigurationManager().expandAsBoolean("${Kernel_AbortScenarioImportOnUnknownSetting}", true))
|
||||
{
|
||||
OV_ERROR_KRF(msg, Kernel::ErrorType::BadSetting);
|
||||
}
|
||||
OV_WARNING_K(msg);
|
||||
}
|
||||
|
||||
box->addSetting(s->name, s->typeID, s->defaultValue, size_t(-1), s->modifiability, s->id);
|
||||
box->setSettingValue(box->getSettingCount() - 1, s->value);
|
||||
}
|
||||
for (auto a = b->attributes.begin(); a != b->attributes.end(); ++a) { box->addAttribute(a->id, a->value); }
|
||||
|
||||
// it is important to set box algorithm at
|
||||
// last so the box listener is never called
|
||||
box->setAlgorithmClassIdentifier(b->algorithmClassID);
|
||||
}
|
||||
boxIdMapping[b->id] = newBoxID;
|
||||
}
|
||||
|
||||
for (auto c = symbolicScenario.comments.begin(); c != symbolicScenario.comments.end(); ++c)
|
||||
{
|
||||
Kernel::IComment* comment = nullptr;
|
||||
CIdentifier newCommentID;
|
||||
|
||||
scenario->addComment(newCommentID, c->id);
|
||||
comment = scenario->getCommentDetails(newCommentID);
|
||||
if (comment)
|
||||
{
|
||||
comment->setText(c->text);
|
||||
|
||||
for (auto a = c->attributes.begin(); a != c->attributes.end(); ++a) { comment->addAttribute(a->id, a->value); }
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& symbolicMetadata : symbolicScenario.metadata)
|
||||
{
|
||||
CIdentifier newMetadataIdentifier;
|
||||
scenario->addMetadata(newMetadataIdentifier, symbolicMetadata.identifier);
|
||||
Kernel::IMetadata* metadata = scenario->getMetadataDetails(newMetadataIdentifier);
|
||||
if (metadata)
|
||||
{
|
||||
metadata->setType(symbolicMetadata.type);
|
||||
metadata->setData(symbolicMetadata.data);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto l = symbolicScenario.links.begin(); l != symbolicScenario.links.end(); ++l)
|
||||
{
|
||||
Kernel::ILink* link = nullptr;
|
||||
CIdentifier newLinkID;
|
||||
|
||||
size_t srcBoxOutputIdx = l->linkSrc.boxOutputIdx;
|
||||
size_t dstBoxInputIdx = l->linkDst.boxInputIdx;
|
||||
|
||||
CIdentifier srcBoxOutputID = l->linkSrc.boxOutputID;
|
||||
CIdentifier dstBoxInputID = l->linkDst.boxInputID;
|
||||
|
||||
if (srcBoxOutputID != CIdentifier::undefined()) { scenario->getSourceBoxOutputIndex(boxIdMapping[l->linkSrc.boxID], srcBoxOutputID, srcBoxOutputIdx); }
|
||||
|
||||
OV_ERROR_UNLESS_KRF(srcBoxOutputIdx != size_t(-1), "Output index of the source box could not be found", Kernel::ErrorType::BadOutput);
|
||||
|
||||
if (dstBoxInputID != CIdentifier::undefined()) { scenario->getTargetBoxInputIndex(boxIdMapping[l->linkDst.boxID], dstBoxInputID, dstBoxInputIdx); }
|
||||
|
||||
OV_ERROR_UNLESS_KRF(dstBoxInputIdx != size_t(-1), "Input index of the target box could not be found", Kernel::ErrorType::BadOutput);
|
||||
|
||||
scenario->connect(newLinkID, boxIdMapping[l->linkSrc.boxID], srcBoxOutputIdx, boxIdMapping[l->linkDst.boxID], dstBoxInputIdx, l->id);
|
||||
|
||||
link = scenario->getLinkDetails(newLinkID);
|
||||
if (link) { for (auto a = l->attributes.begin(); a != l->attributes.end(); ++a) { link->addAttribute(a->id, a->value); } }
|
||||
}
|
||||
|
||||
size_t scenarioInputIdx = 0;
|
||||
for (auto symbolicScenarioInput : symbolicScenario.iScenarios)
|
||||
{
|
||||
CIdentifier scenarioInputID = symbolicScenarioInput.id;
|
||||
// compute identifier only if it does not exists
|
||||
if (scenarioInputID == CIdentifier::undefined()) { scenarioInputID = scenario->getUnusedInputIdentifier(); }
|
||||
scenario->addInput(symbolicScenarioInput.name, symbolicScenarioInput.typeID, scenarioInputID);
|
||||
if (symbolicScenarioInput.linkedBoxID != CIdentifier::undefined())
|
||||
{
|
||||
// Only try to set scenario output links from boxes that actually exist
|
||||
// This enables the usage of header-only importers
|
||||
if (symbolicScenario.boxes.end() != std::find_if(symbolicScenario.boxes.begin(), symbolicScenario.boxes.end(),
|
||||
[&symbolicScenarioInput](const box_t& box) { return box.id == symbolicScenarioInput.linkedBoxID; })
|
||||
)
|
||||
{
|
||||
CIdentifier linkedBoxInputIdentifier = symbolicScenarioInput.linkedBoxInputID;
|
||||
size_t linkedBoxInputIndex = symbolicScenarioInput.linkedBoxInputIdx;
|
||||
|
||||
if (linkedBoxInputIdentifier != CIdentifier::undefined())
|
||||
{
|
||||
scenario->getTargetBoxInputIndex(symbolicScenarioInput.linkedBoxID, linkedBoxInputIdentifier, linkedBoxInputIndex);
|
||||
}
|
||||
|
||||
OV_ERROR_UNLESS_KRF(linkedBoxInputIndex != size_t(-1), "Input index of the target box could not be found",
|
||||
Kernel::ErrorType::BadOutput);
|
||||
|
||||
scenario->setScenarioInputLink(scenarioInputIdx, symbolicScenarioInput.linkedBoxID, linkedBoxInputIndex);
|
||||
}
|
||||
}
|
||||
scenarioInputIdx++;
|
||||
}
|
||||
|
||||
size_t scenarioOutputIdx = 0;
|
||||
for (auto symbolicScenarioOutput : symbolicScenario.oScenarios)
|
||||
{
|
||||
CIdentifier scenarioOutputID = symbolicScenarioOutput.id;
|
||||
// compute identifier only if it does not exists
|
||||
if (scenarioOutputID == CIdentifier::undefined()) { scenarioOutputID = scenario->getUnusedOutputIdentifier(); }
|
||||
scenario->addOutput(symbolicScenarioOutput.name, symbolicScenarioOutput.typeID, scenarioOutputID);
|
||||
if (symbolicScenarioOutput.linkedBoxID != CIdentifier::undefined())
|
||||
{
|
||||
// Only try to set scenario output links from boxes that actually exist
|
||||
// This enables the usage of header-only importers
|
||||
if (std::any_of(symbolicScenario.boxes.begin(), symbolicScenario.boxes.end(), [&symbolicScenarioOutput](const box_t& box)
|
||||
{
|
||||
return box.id == symbolicScenarioOutput.linkedBoxID;
|
||||
}))
|
||||
{
|
||||
CIdentifier linkedBoxOutputIdentifier = symbolicScenarioOutput.linkedBoxOutputID;
|
||||
size_t linkedBoxOutputIndex = symbolicScenarioOutput.linkedBoxOutputIdx;
|
||||
|
||||
if (linkedBoxOutputIdentifier != CIdentifier::undefined())
|
||||
{
|
||||
scenario->getSourceBoxOutputIndex(symbolicScenarioOutput.linkedBoxID, linkedBoxOutputIdentifier, linkedBoxOutputIndex);
|
||||
}
|
||||
|
||||
OV_ERROR_UNLESS_KRF(linkedBoxOutputIndex != size_t(-1), "Output index of the target box could not be found",
|
||||
Kernel::ErrorType::BadOutput);
|
||||
scenario->setScenarioOutputLink(scenarioOutputIdx, symbolicScenarioOutput.linkedBoxID, linkedBoxOutputIndex);
|
||||
}
|
||||
}
|
||||
scenarioOutputIdx++;
|
||||
}
|
||||
|
||||
for (auto a = symbolicScenario.attributes.begin(); a != symbolicScenario.attributes.end(); ++a) { scenario->addAttribute(a->id, a->value); }
|
||||
|
||||
if (scenario->checkOutdatedBoxes())
|
||||
{
|
||||
CIdentifier* listID = nullptr;
|
||||
size_t nbElems = 0;
|
||||
scenario->getOutdatedBoxIdentifierList(&listID, &nbElems);
|
||||
for (size_t i = 0; i < nbElems; ++i)
|
||||
{
|
||||
const Kernel::IBox* box = scenario->getBoxDetails(listID[i]);
|
||||
OV_WARNING_K(std::string("Box ") + box->getName().toASCIIString() + " [" + box->getAlgorithmClassIdentifier().str() + "] should be updated");
|
||||
}
|
||||
scenario->releaseIdentifierList(listID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioImporterContext::processStart(const CIdentifier& identifier)
|
||||
{
|
||||
if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_OpenViBEScenario) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Settings) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting) { m_SymbolicScenario.settings.push_back(setting_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Inputs) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input) { m_SymbolicScenario.iScenarios.push_back(scenario_input_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Outputs) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output) { m_SymbolicScenario.oScenarios.push_back(scenario_output_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Creator) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_CreatorVersion) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attributes) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attribute) { m_SymbolicScenario.attributes.push_back(attribute_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Attributes) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Attribute) { m_SymbolicScenario.boxes.back().attributes.push_back(attribute_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Attributes) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Attribute) { m_SymbolicScenario.links.back().attributes.push_back(attribute_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Boxes) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box) { m_SymbolicScenario.boxes.push_back(box_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comments) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment) { m_SymbolicScenario.comments.push_back(comment_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Attributes) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Attribute) { m_SymbolicScenario.comments.back().attributes.push_back(attribute_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Metadata) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry) { m_SymbolicScenario.metadata.push_back(metadata_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Links) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link) { m_SymbolicScenario.links.push_back(link_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Inputs) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input) { m_SymbolicScenario.boxes.back().inputs.push_back(input_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Outputs) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output) { m_SymbolicScenario.boxes.back().outputs.push_back(output_t()); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Settings) { }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting) { m_SymbolicScenario.boxes.back().settings.push_back(setting_t()); }
|
||||
//
|
||||
else
|
||||
{
|
||||
OV_ERROR("(start) Unexpected node identifier " << identifier.str(), Kernel::ErrorType::BadArgument, false,
|
||||
m_AlgorithmContext.getErrorManager(), m_AlgorithmContext.getLogManager());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioImporterContext::processIdentifier(const CIdentifier& identifier, const CIdentifier& value)
|
||||
{
|
||||
if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_ID) { m_SymbolicScenario.settings.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_TypeID) { m_SymbolicScenario.settings.back().typeID = value; }
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_ID) { m_SymbolicScenario.iScenarios.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_TypeID) { m_SymbolicScenario.iScenarios.back().typeID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxID) { m_SymbolicScenario.iScenarios.back().linkedBoxID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxInputID)
|
||||
{
|
||||
m_SymbolicScenario.iScenarios.back().linkedBoxInputID = value;
|
||||
}
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_ID) { m_SymbolicScenario.oScenarios.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_TypeID) { m_SymbolicScenario.oScenarios.back().typeID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxID) { m_SymbolicScenario.oScenarios.back().linkedBoxID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxOutputID)
|
||||
{
|
||||
m_SymbolicScenario.oScenarios.back().linkedBoxOutputID = value;
|
||||
}
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Attribute_ID) { m_SymbolicScenario.boxes.back().attributes.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_ID) { m_SymbolicScenario.boxes.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_AlgorithmClassIdD) { m_SymbolicScenario.boxes.back().algorithmClassID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_ID) { m_SymbolicScenario.boxes.back().inputs.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_TypeID) { m_SymbolicScenario.boxes.back().inputs.back().typeID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_ID) { m_SymbolicScenario.boxes.back().outputs.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_TypeID) { m_SymbolicScenario.boxes.back().outputs.back().typeID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_ID) { m_SymbolicScenario.boxes.back().settings.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_TypeID) { m_SymbolicScenario.boxes.back().settings.back().typeID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_ID) { m_SymbolicScenario.comments.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Attribute_ID) { m_SymbolicScenario.comments.back().attributes.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_ID) { m_SymbolicScenario.metadata.back().identifier = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_Type) { m_SymbolicScenario.metadata.back().type = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Attribute_ID) { m_SymbolicScenario.links.back().attributes.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_ID) { m_SymbolicScenario.links.back().id = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxID) { m_SymbolicScenario.links.back().linkSrc.boxID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxOutputID) { m_SymbolicScenario.links.back().linkSrc.boxOutputID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxID) { m_SymbolicScenario.links.back().linkDst.boxID = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxInputID) { m_SymbolicScenario.links.back().linkDst.boxInputID = value; }
|
||||
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attribute_ID) { m_SymbolicScenario.attributes.back().id = value; }
|
||||
else
|
||||
{
|
||||
OV_ERROR("(id) Unexpected node identifier " << identifier.str(),
|
||||
Kernel::ErrorType::BadArgument, false, m_AlgorithmContext.getErrorManager(), m_AlgorithmContext.getLogManager());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioImporterContext::processString(const CIdentifier& identifier, const CString& value)
|
||||
{
|
||||
if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Attribute_Value) { m_SymbolicScenario.boxes.back().attributes.back().value = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Name) { m_SymbolicScenario.boxes.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Input_Name) { m_SymbolicScenario.boxes.back().inputs.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Output_Name) { m_SymbolicScenario.boxes.back().outputs.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Name) { m_SymbolicScenario.boxes.back().settings.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_DefaultValue)
|
||||
{
|
||||
m_SymbolicScenario.boxes.back().settings.back().defaultValue = value;
|
||||
}
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Value) { m_SymbolicScenario.boxes.back().settings.back().value = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Box_Setting_Modifiability)
|
||||
{
|
||||
m_SymbolicScenario.boxes.back().settings.back().modifiability = (value == CString("true")) ? true : false;
|
||||
}
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Text) { m_SymbolicScenario.comments.back().text = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Comment_Attribute_Value)
|
||||
{
|
||||
m_SymbolicScenario.comments.back().attributes.back().value = value;
|
||||
}
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_MetadataEntry_Data) { m_SymbolicScenario.metadata.back().data = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Attribute_Value) { m_SymbolicScenario.links.back().attributes.back().value = value; }
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attribute_Value) { m_SymbolicScenario.attributes.back().value = value; }
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_Name) { m_SymbolicScenario.settings.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_DefaultValue) { m_SymbolicScenario.settings.back().defaultValue = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Setting_Value) { m_SymbolicScenario.settings.back().value = value; }
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_Name) { m_SymbolicScenario.iScenarios.back().name = value; }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_Name) { m_SymbolicScenario.oScenarios.back().name = value; }
|
||||
|
||||
else
|
||||
{
|
||||
OV_ERROR("(string) Unexpected node identifier " << identifier.str(), Kernel::ErrorType::BadArgument,
|
||||
false, m_AlgorithmContext.getErrorManager(), m_AlgorithmContext.getLogManager());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlgorithmScenarioImporterContext::processUInteger(const CIdentifier& identifier, const uint64_t value)
|
||||
{
|
||||
if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Source_BoxOutputIdx) { m_SymbolicScenario.links.back().linkSrc.boxOutputIdx = size_t(value); }
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Link_Target_BoxInputIdx)
|
||||
{
|
||||
m_SymbolicScenario.links.back().linkDst.boxInputIdx = size_t(value);
|
||||
}
|
||||
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Input_LinkedBoxInputIdx)
|
||||
{
|
||||
m_SymbolicScenario.iScenarios.back().linkedBoxInputIdx = size_t(value);
|
||||
}
|
||||
else if (identifier == OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Output_LinkedBoxOutputIdx)
|
||||
{
|
||||
m_SymbolicScenario.oScenarios.back().linkedBoxOutputIdx = size_t(value);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
OV_ERROR("(uint) Unexpected node identifier " << identifier.str(), Kernel::ErrorType::BadArgument, false,
|
||||
m_AlgorithmContext.getErrorManager(), m_AlgorithmContext.getLogManager());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,261 @@
|
||||
#include "toolkit/ovtk_all.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
// ********************************************************************************************************************
|
||||
// *
|
||||
// VIM Replace string to easily add enumeration values : *
|
||||
// *
|
||||
// :%s/#define \([A-Za-z0-9_]\+\).*/ typeManager.registerEnumerationEntry(OV_TypeId_Stimulation, "\1", \1);/g *
|
||||
// *
|
||||
// ********************************************************************************************************************
|
||||
|
||||
bool initialize(const Kernel::IKernelContext& ctx)
|
||||
{
|
||||
Kernel::ITypeManager& typeManager = ctx.getTypeManager();
|
||||
|
||||
initializeStimulationList(ctx);
|
||||
|
||||
// Register measurement units. See ovtk_defines.h for details.
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "?", OVTK_UNIT_Unspecified);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "-", OVTK_UNIT_Dimensionless);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "%", OVTK_UNIT_10_2_Percent);
|
||||
// typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "percent", OVTK_UNIT_10_2_Percent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ppht", OVTK_UNIT_10_3_Parts_Per_Thousand);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ppm", OVTK_UNIT_10_6_Parts_Per_Million);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ppmd", OVTK_UNIT_10_9_Parts_Per_Milliard);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ppb", OVTK_UNIT_10_12_Parts_Per_Billion);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ppt", OVTK_UNIT_10_18_Parts_Per_Trillion);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "degree", OVTK_UNIT_Angle_Degree);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "rad", OVTK_UNIT_Angle_Radian);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g g-1", OVTK_UNIT_Grams_Per_Gram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g kg-1", OVTK_UNIT_Grams_Per_Kilogram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol mol-1", OVTK_UNIT_Moles_Per_Mole);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l l-1", OVTK_UNIT_Litres_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m m-3", OVTK_UNIT_Cubic_Metres_Per_Cubic_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m cm-3", OVTK_UNIT_Cubic_Metres_Per_Cubic_Centimetre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "vol %", OVTK_UNIT_Volume_Percent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "pH", OVTK_UNIT_Ph);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "drop", OVTK_UNIT_Drop);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "rbc", OVTK_UNIT_Red_Blood_Cells);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "beat", OVTK_UNIT_Beat);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "breath", OVTK_UNIT_Breath);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cell", OVTK_UNIT_Cell);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cough", OVTK_UNIT_Cough);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "sigh", OVTK_UNIT_Sigh);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "%PCV", OVTK_UNIT_Percent_Of_Packed_Cell_Volume);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m", OVTK_UNIT_Metres);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "yd", OVTK_UNIT_Yard);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ft", OVTK_UNIT_Foot);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "in", OVTK_UNIT_Inch);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "lm-2", OVTK_UNIT_Litres_Per_Square_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m-1", OVTK_UNIT_Per_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m2", OVTK_UNIT_Square_Metres);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "in2", OVTK_UNIT_Square_Inch);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m-2", OVTK_UNIT_Per_Square_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3", OVTK_UNIT_Cubic_Metres);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l", OVTK_UNIT_Litres);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l_breath-1", OVTK_UNIT_Litres_Per_Breath);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l_beat-1", OVTK_UNIT_Litres_Per_Beat);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m-3", OVTK_UNIT_Per_Cubic_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l-1", OVTK_UNIT_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g", OVTK_UNIT_Gram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "lb", OVTK_UNIT_Pound);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "oz", OVTK_UNIT_Ounce);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g-1", OVTK_UNIT_Per_Gram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "gm", OVTK_UNIT_Gram_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g m m-2", OVTK_UNIT_Grams_Meter_Per_Square_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "kg m2", OVTK_UNIT_Gram_Metre_Squared);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "kg m-2", OVTK_UNIT_Kilograms_Per_Square_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g m-3", OVTK_UNIT_Grams_Per_Cubic_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g cm-3", OVTK_UNIT_Grams_Per_Cubic_Centimetre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g l-1", OVTK_UNIT_Grams_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g cl-3", OVTK_UNIT_Grams_Per_Centilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g dl-3", OVTK_UNIT_Grams_Per_Decilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g ml-3", OVTK_UNIT_Grams_Per_Millilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "s", OVTK_UNIT_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "min", OVTK_UNIT_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "h", OVTK_UNIT_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "d", OVTK_UNIT_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "weeks", OVTK_UNIT_Weeks);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mth", OVTK_UNIT_Months);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "y", OVTK_UNIT_Year);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "TOD", OVTK_UNIT_Time_Of_Day_Hh_Mm_Ss);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "DATE", OVTK_UNIT_Date_Yyyy_Mm_Dd);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "s-1", OVTK_UNIT_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Hz", OVTK_UNIT_Hertz);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "min-1", OVTK_UNIT_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "h-1", OVTK_UNIT_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "d-1", OVTK_UNIT_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "week-1", OVTK_UNIT_Per_Week);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mth-1", OVTK_UNIT_Per_Month);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "y-1", OVTK_UNIT_Per_Year);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "bpm", OVTK_UNIT_Beat_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "puls min-1", OVTK_UNIT_Puls_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "resp min-1", OVTK_UNIT_Respirations_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m s-1", OVTK_UNIT_Metres_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l min-1 m-2", OVTK_UNIT_Litres_Per_Minute_Per_Square_Meter);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m2 s-1", OVTK_UNIT_Square_Metres_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3 s-1", OVTK_UNIT_Cubic_Metres_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3 min-1", OVTK_UNIT_Cubic_Metres_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3 h-1", OVTK_UNIT_Cubic_Metres_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3 d-1", OVTK_UNIT_Cubic_Metres_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l s-1", OVTK_UNIT_Litres_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l min-1", OVTK_UNIT_Litres_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l h-1", OVTK_UNIT_Litres_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l d-1", OVTK_UNIT_Litres_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l kg-1", OVTK_UNIT_Litres_Per_Kilogram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m3 kg-1", OVTK_UNIT_Cubic_Metres_Per_Kilogram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m Pa-1s-1", OVTK_UNIT_Meter_Per_Pascal_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l min-1 mmHG-1", OVTK_UNIT_Litre_Per_Min_Per_Millimetre_Of_Mercury);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g s-1", OVTK_UNIT_Grams_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g m-1", OVTK_UNIT_Grams_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g h-1", OVTK_UNIT_Grams_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g d-1", OVTK_UNIT_Grams_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g kg-1 s-1", OVTK_UNIT_Grams_Per_Kilogram_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g kg-1 m-1", OVTK_UNIT_Grams_Per_Kilogram_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g kg-1 h-1", OVTK_UNIT_Grams_Per_Kilogram_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g kg-1 d-1", OVTK_UNIT_Grams_Per_Kilogram_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g l-1_s-1", OVTK_UNIT_Grams_Per_Litre_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g l-1 m-1", OVTK_UNIT_Grams_Per_Litre_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g l-1 h-1", OVTK_UNIT_Grams_Per_Litre_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g l-1 d-1", OVTK_UNIT_Grams_Per_Litre_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g m-1 s-1", OVTK_UNIT_Grams_Per_Meter_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "gm s-1", OVTK_UNIT_Gram_Metres_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Ns", OVTK_UNIT_Newton_Seconds);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "N", OVTK_UNIT_Newton);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "dyn", OVTK_UNIT_Dyne);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Pa", OVTK_UNIT_Pascal);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mmHg", OVTK_UNIT_Millimetres_Of_Mercury);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cm H2O", OVTK_UNIT_Centimetre_Of_Water);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "bar", OVTK_UNIT_Bar);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "J", OVTK_UNIT_Joules);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eV", OVTK_UNIT_Electronvolts);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "W", OVTK_UNIT_Watts);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Pa_s_m-3", OVTK_UNIT_Pascal_Second_Per_Cubic_Meter);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Pa_s_l-1", OVTK_UNIT_Pascal_Second_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "dyne s cm-5", OVTK_UNIT_Dyne_Second_Per_Cm5);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l cmH2O-1", OVTK_UNIT_Litre_Per_Centimetre_Of_Water);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l mmHg-1", OVTK_UNIT_Litre_Per_Millimetre_Of_Mercury);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l Pa-1", OVTK_UNIT_Litre_Per_Pascal);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cmH2O l-1", OVTK_UNIT_Centimetre_Of_Water_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mmHg l-1", OVTK_UNIT_Millimetre_Of_Mercury_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Pa l-1", OVTK_UNIT_Pascal_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "A", OVTK_UNIT_Amperes);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "C", OVTK_UNIT_Coulombs);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Ah", OVTK_UNIT_Amperes_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "A m-1", OVTK_UNIT_Amperes_Per_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "V", OVTK_UNIT_Volts);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Ohm", OVTK_UNIT_Ohms);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Wm", OVTK_UNIT_Ohm_Metres);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "F", OVTK_UNIT_Farads);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "K", OVTK_UNIT_Kelvin);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "degC", OVTK_UNIT_Degree_Celcius);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "degF", OVTK_UNIT_Degree_Fahrenheit);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "K W-1", OVTK_UNIT_Kelvins_Per_Watt);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cd", OVTK_UNIT_Candelas);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "osmole", OVTK_UNIT_Osmoles);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol", OVTK_UNIT_Moles);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq", OVTK_UNIT_Equivalent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "osmol l-1", OVTK_UNIT_Osmoles_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol cm-3", OVTK_UNIT_Moles_Per_Cubic_Centimetre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol m-3", OVTK_UNIT_Moles_Per_Cubic_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol l-1", OVTK_UNIT_Moles_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol ml-1", OVTK_UNIT_Moles_Per_Millilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq cm-3", OVTK_UNIT_Equivalents_Per_Cubic_Centimetre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq m-3", OVTK_UNIT_Equivalents_Per_Cubic_Metre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq l-1", OVTK_UNIT_Equivalents_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq ml-1", OVTK_UNIT_Equivalents_Per_Millilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "osmol kg-1", OVTK_UNIT_Osmoles_Per_Kilogram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol kg-1", OVTK_UNIT_Moles_Per_Kilogram);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol s-1", OVTK_UNIT_Moles_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol min-1", OVTK_UNIT_Moles_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol h-1", OVTK_UNIT_Moles_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol d-1", OVTK_UNIT_Moles_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq s-1", OVTK_UNIT_Equivalents_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq min-1", OVTK_UNIT_Equivalents_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq h-1", OVTK_UNIT_Equivalents_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq d-1", OVTK_UNIT_Equivalents_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol kg-1 s-1", OVTK_UNIT_Moles_Per_Kilogram_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol kg-1 min-1", OVTK_UNIT_Moles_Per_Kilogram_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol kg-1 h-1", OVTK_UNIT_Moles_Per_Kilogram_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol kg-1 d-1", OVTK_UNIT_Moles_Per_Kilogram_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq kg-1 s-1", OVTK_UNIT_Equivalents_Per_Kilogram_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq kg-1 min-1", OVTK_UNIT_Equivalents_Per_Kilogram_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq kg-1 h-1", OVTK_UNIT_Equivalents_Per_Kilogram_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "eq kg-1 d-1", OVTK_UNIT_Equivalents_Per_Kilogram_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u.", OVTK_UNIT_International_Unit);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. cm-3", OVTK_UNIT_International_Units_Per_Cubic_Centimetre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. m-3", OVTK_UNIT_International_Units_Per_Cubic_Meter);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. l-1", OVTK_UNIT_International_Units_Per_Litre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. ml-1", OVTK_UNIT_International_Units_Per_Millilitre);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. s-1", OVTK_UNIT_International_Units_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. min-1", OVTK_UNIT_International_Units_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. h-1", OVTK_UNIT_International_Units_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. d-1", OVTK_UNIT_International_Units_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. kg-1_s-1", OVTK_UNIT_International_Units_Per_Kilogram_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. kg-1_min-1", OVTK_UNIT_International_Units_Per_Kilogram_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. kg-1_h-1", OVTK_UNIT_International_Units_Per_Kilogram_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "i.u. kg-1_d-1", OVTK_UNIT_International_Units_Per_Kilogram_Per_Day);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cmH2O l-1s-1", OVTK_UNIT_Centimetre_Of_Water_Per_Litre_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l2s-1", OVTK_UNIT_Litre_Squared_Per_Second);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "cmH2O %-1", OVTK_UNIT_Centimetre_Of_Water_Per_Percent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "dyne s m-2 cm-5",
|
||||
OVTK_UNIT_Dyne_Seconds_Per_Square_Meter_Per_Centimetre_To_The_Power_Of_5);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mmHg %-1", OVTK_UNIT_Millimetres_Of_Mercury_Per_Percent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "Pa %-1", OVTK_UNIT_Pascal_Per_Percent);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "B", OVTK_UNIT_Relative_Power_Decibel);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m s-2", OVTK_UNIT_Meter_Per_Second_Squared);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "rad s2-2", OVTK_UNIT_Radians_Per_Second_Squared);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "ft min-1", OVTK_UNIT_Foot_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "in min-1", OVTK_UNIT_Inch_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "step min-1", OVTK_UNIT_Step_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "kcal", OVTK_UNIT_Kilocalories);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "rpm", OVTK_UNIT_Revolution_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "V s-1", OVTK_UNIT_V_Per_S);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "m m-1", OVTK_UNIT_M_Per_M);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "km/h", OVTK_UNIT_Velocity_Kilometer_Per_Hour);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g_s-2", OVTK_UNIT_Left_Stroke_Work_Index_Lswi);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "g_s-3", OVTK_UNIT_Indexed_Left_Cardiac_Work_Lcwi);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mHg_s-1", OVTK_UNIT_Mhg_Per_S);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "mol l-1 mm", OVTK_UNIT_Millimol_Per_Liter_X_Millimeter);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "r.p.m", OVTK_UNIT_Rotations_Per_Minute);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "dyne*s*m*m cm-5", OVTK_UNIT_Dyne_Seconds_Square_Meter_Per_Centimetre_To_The_Power_Of_5);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "l m-2", OVTK_UNIT_Litres_Per_Square_Meter);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "T", OVTK_UNIT_Tesla);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_MeasurementUnit, "deg/s", OVTK_UNIT_Degree_Per_Second);
|
||||
|
||||
// Register measurement factors
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+24", OVTK_FACTOR_Yotta);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+21", OVTK_FACTOR_Zetta);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+18", OVTK_FACTOR_Exa);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+15", OVTK_FACTOR_Peta);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+12", OVTK_FACTOR_Tera);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+09", OVTK_FACTOR_Giga);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+06", OVTK_FACTOR_Mega);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+03", OVTK_FACTOR_Kilo);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+02", OVTK_FACTOR_Hecto);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+01", OVTK_FACTOR_Deca);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e+00", OVTK_FACTOR_Base);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-01", OVTK_FACTOR_Deci);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-02", OVTK_FACTOR_Centi);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-03", OVTK_FACTOR_Milli);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-06", OVTK_FACTOR_Micro);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-09", OVTK_FACTOR_Nano);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-12", OVTK_FACTOR_Pico);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-15", OVTK_FACTOR_Femto);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-18", OVTK_FACTOR_Atto);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-21", OVTK_FACTOR_Zepto);
|
||||
typeManager.registerEnumerationEntry(OV_TypeId_Factor, "1e-24", OVTK_FACTOR_Yocto);
|
||||
|
||||
typeManager.registerEnumerationType(OVTK_TypeId_ClassificationAlgorithm, "Classification algorithm");
|
||||
typeManager.registerEnumerationType(OVTK_TypeId_ClassificationStrategy, "Classification strategy");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uninitialize(const Kernel::IKernelContext& ctx) { return true; }
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,417 @@
|
||||
#include "ovtkMatrix.h"
|
||||
|
||||
#include <fs/Files.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
|
||||
// for save/load
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <locale> // std::isspace
|
||||
#include <sstream>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
namespace Matrix {
|
||||
|
||||
enum class EParsingStatus { Nothing, ParsingHeader, ParsingHeaderDimension, ParsingHeaderLabel, ParsingBuffer, ParsingBufferValue };
|
||||
|
||||
// tokens in the ascii matrix format
|
||||
const char CONSTANT_LEFT_SQUARE_BRACKET = '[';
|
||||
const char CONSTANT_RIGHT_SQUARE_BRACKET = ']';
|
||||
const char CONSTANT_HASHTAG = '#';
|
||||
const char CONSTANT_DOUBLE_QUOTE = '"';
|
||||
const char CONSTANT_TAB = '\t';
|
||||
const char CONSTANT_CARRIAGE_RETURN = '\r';
|
||||
const char CONSTANT_EOL = '\n';
|
||||
const char CONSTANT_SPACE = ' ';
|
||||
|
||||
bool fromString(CMatrix& matrix, const CString& str)
|
||||
{
|
||||
std::stringstream buffer;
|
||||
|
||||
buffer << str.toASCIIString();
|
||||
|
||||
const std::locale locale("C");
|
||||
//current string to parse
|
||||
std::string what;
|
||||
//current parsing status
|
||||
EParsingStatus status = EParsingStatus::Nothing;
|
||||
//current element index (incremented every time a value is stored in matrix)
|
||||
size_t curElementIdx = 0;
|
||||
//current dimension index
|
||||
size_t curDimIdx = size_t(-1);
|
||||
//vector keeping track of dimension sizes
|
||||
std::vector<size_t> dimSize;
|
||||
//vector keeping track of number of values found in each dimension
|
||||
std::vector<size_t> nValue;
|
||||
// Dim labels
|
||||
std::vector<std::string> labels;
|
||||
//current quote-delimited string
|
||||
std::string curString;
|
||||
|
||||
do
|
||||
{
|
||||
//read current line
|
||||
std::getline(buffer, what, CONSTANT_EOL);
|
||||
|
||||
//is line empty?
|
||||
if (what.length() == 0) { continue; } //skip it
|
||||
|
||||
//output line to be parsed in debug level
|
||||
// getLogManager() << Kernel::LogLevel_Debug << what << "\n";
|
||||
|
||||
//remove ending carriage return (if any) for windows / linux compatibility
|
||||
if (what[what.length() - 1] == CONSTANT_CARRIAGE_RETURN) { what.erase(what.length() - 1, 1); }
|
||||
|
||||
//start parsing current line
|
||||
auto it = what.begin();
|
||||
|
||||
//parse current line
|
||||
while (it != what.end())
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
//initial parsing status
|
||||
case EParsingStatus::Nothing:
|
||||
|
||||
//comments starting
|
||||
if (*it == CONSTANT_HASHTAG) { it = what.end() - 1; } // ignore rest of line by skipping to last character
|
||||
//header starting
|
||||
else if (*it == CONSTANT_LEFT_SQUARE_BRACKET) { status = EParsingStatus::ParsingHeader; } // update status
|
||||
else if (!std::isspace(*it, locale)) { return false; }
|
||||
break;
|
||||
|
||||
//parse header
|
||||
case EParsingStatus::ParsingHeader:
|
||||
|
||||
//comments starting
|
||||
if (*it == CONSTANT_HASHTAG) { it = what.end() - 1; } //ignore rest of line by skipping to last character
|
||||
//new dimension opened
|
||||
else if (*it == CONSTANT_LEFT_SQUARE_BRACKET)
|
||||
{
|
||||
dimSize.resize(dimSize.size() + 1); //increment dimension count
|
||||
curDimIdx++; //update current dimension index
|
||||
status = EParsingStatus::ParsingHeaderDimension; //update status
|
||||
}
|
||||
//finished parsing header
|
||||
else if (*it == CONSTANT_RIGHT_SQUARE_BRACKET)
|
||||
{
|
||||
if (dimSize.empty()) { return false; } //ensure at least one dimension was found
|
||||
matrix.resize(dimSize); //resize matrix
|
||||
nValue.resize(matrix.getDimensionCount());
|
||||
|
||||
// set labels now that we know the matrix size
|
||||
size_t idx = 0;
|
||||
for (size_t i = 0; i < matrix.getDimensionCount(); ++i)
|
||||
{
|
||||
for (size_t j = 0; j < matrix.getDimensionSize(i); ++j) { matrix.setDimensionLabel(i, j, labels[idx++].c_str()); }
|
||||
}
|
||||
|
||||
//reset current dimension index
|
||||
curDimIdx = size_t(-1);
|
||||
//update status
|
||||
status = EParsingStatus::ParsingBuffer;
|
||||
}
|
||||
else if (!std::isspace(*it, locale)) { return false; }
|
||||
break;
|
||||
|
||||
case EParsingStatus::ParsingHeaderDimension:
|
||||
|
||||
//comments starting
|
||||
if (*it == CONSTANT_HASHTAG) { it = what.end() - 1; } //ignore rest of line by skipping to last character
|
||||
//new label found
|
||||
else if (*it == CONSTANT_DOUBLE_QUOTE)
|
||||
{
|
||||
//new element found in current dimension
|
||||
dimSize[curDimIdx]++;
|
||||
//update status
|
||||
status = EParsingStatus::ParsingHeaderLabel;
|
||||
}
|
||||
//finished parsing current dimension header
|
||||
else if (*it == CONSTANT_RIGHT_SQUARE_BRACKET) { status = EParsingStatus::ParsingHeader; } //update status
|
||||
else if (!std::isspace(*it, locale)) { return false; }
|
||||
break;
|
||||
|
||||
//look for end of label (first '"' char not preceded by the '\' escape char)
|
||||
case EParsingStatus::ParsingHeaderLabel:
|
||||
|
||||
//found '"' char not preceded by escape char : end of label reached
|
||||
if (*it == CONSTANT_DOUBLE_QUOTE && *(it - 1) != '\\')
|
||||
{
|
||||
// We can only attach the label later after we know the size
|
||||
labels.push_back(curString);
|
||||
|
||||
// std::cout << " lab " << curDimensionIdx << " " << dimSize[curDimensionIdx]-1 << " : " << curString << "\n";
|
||||
|
||||
//clear current string
|
||||
curString.erase();
|
||||
|
||||
//update status
|
||||
status = EParsingStatus::ParsingHeaderDimension;
|
||||
}
|
||||
//otherwise, keep parsing current label
|
||||
else { curString.append(1, *it); }
|
||||
break;
|
||||
|
||||
case EParsingStatus::ParsingBuffer:
|
||||
|
||||
//comments starting
|
||||
if (*it == CONSTANT_HASHTAG) { it = what.end() - 1; } //ignore rest of line by skipping to last character
|
||||
//going down one dimension
|
||||
else if (*it == CONSTANT_LEFT_SQUARE_BRACKET)
|
||||
{
|
||||
//update dimension index
|
||||
curDimIdx++;
|
||||
//ensure dimension count remains in allocated range
|
||||
if (curDimIdx == matrix.getDimensionCount()) { return false; }
|
||||
//ensure values count remains in allocated range
|
||||
if (nValue[curDimIdx] == matrix.getDimensionSize(curDimIdx)) { return false; }
|
||||
//increment values count for current dimension, if it is not the innermost
|
||||
if (curDimIdx < matrix.getDimensionCount() - 1) { nValue[curDimIdx]++; }
|
||||
}
|
||||
//going up one dimension
|
||||
else if (*it == CONSTANT_RIGHT_SQUARE_BRACKET)
|
||||
{
|
||||
//if we are not in innermost dimension
|
||||
if (curDimIdx < matrix.getDimensionCount() - 1)
|
||||
{
|
||||
//ensure the right number of values was parsed in lower dimension
|
||||
if (nValue[curDimIdx + 1] != matrix.getDimensionSize(curDimIdx + 1)) { return false; }
|
||||
//reset values count of lower dimension to 0
|
||||
nValue[curDimIdx + 1] = 0;
|
||||
}
|
||||
//ensure dimension count is correct
|
||||
else if (curDimIdx == size_t(-1)) { return false; }
|
||||
|
||||
//go up one dimension
|
||||
curDimIdx--;
|
||||
}
|
||||
//non whitespace character found
|
||||
else if (!std::isspace(*it, locale))
|
||||
{
|
||||
//if we are in innermost dimension, assume a value is starting here
|
||||
if (curDimIdx == matrix.getDimensionCount() - 1)
|
||||
{
|
||||
//ensure values parsed so far in current dimension doesn't exceed current dimension size
|
||||
if (nValue.back() == matrix.getDimensionSize(curDimIdx)) { return false; }
|
||||
|
||||
//increment values count found in innermost dimension
|
||||
nValue[curDimIdx]++;
|
||||
|
||||
//append current character to current string
|
||||
curString.append(1, *it);
|
||||
|
||||
//update status
|
||||
status = EParsingStatus::ParsingBufferValue;
|
||||
}
|
||||
else { return false; }
|
||||
}
|
||||
break;
|
||||
|
||||
//look for end of value (first '"' char not preceded by the '\' escape char)
|
||||
case EParsingStatus::ParsingBufferValue:
|
||||
|
||||
//values end at first whitespace character or ']' character
|
||||
if (std::isspace(*it, locale) == true || *it == CONSTANT_RIGHT_SQUARE_BRACKET)
|
||||
{
|
||||
//if dimension closing bracket is found
|
||||
if (*it == CONSTANT_RIGHT_SQUARE_BRACKET)
|
||||
{
|
||||
//move back iterator by one character so that closing bracket is taken into account in EParsingStatus::ParsingBuffer case
|
||||
--it;
|
||||
}
|
||||
|
||||
//retrieve value
|
||||
errno = 0;
|
||||
char* end;
|
||||
const double value = strtod(curString.c_str(), &end);
|
||||
#if defined TARGET_OS_Windows
|
||||
//string couldn't be converted to a double
|
||||
if (errno == ERANGE) { return false; }
|
||||
#endif
|
||||
//store value in matrix
|
||||
(matrix.getBuffer())[curElementIdx] = value;
|
||||
//update element index
|
||||
curElementIdx++;
|
||||
//reset current string
|
||||
curString.erase();
|
||||
//update status
|
||||
status = EParsingStatus::ParsingBuffer;
|
||||
}
|
||||
//otherwise, append current character to current string
|
||||
else { curString.append(1, *it); }
|
||||
break;
|
||||
} // switch(status)
|
||||
|
||||
//increment iterator
|
||||
++it;
|
||||
} // while(it != what.end()) (read each character of current line)
|
||||
} while (buffer.good()); //read each line in turn
|
||||
|
||||
//If the file is empty or other (like directory)
|
||||
if (nValue.empty()) { return false; }
|
||||
//ensure the right number of values were parsed in first dimension
|
||||
if (nValue[0] != matrix.getDimensionSize(0)) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// A recursive helper function to spool matrix contents to a txt stringstream.
|
||||
bool dumpMatrixBuffer(const CMatrix& matrix, std::stringstream& buffer, const size_t index1, size_t& index2)
|
||||
{
|
||||
//are we in innermost dimension?
|
||||
if (index1 == matrix.getDimensionCount() - 1)
|
||||
{
|
||||
//dimension start
|
||||
for (size_t j = 0; j < index1; ++j) { buffer << CONSTANT_TAB; }
|
||||
buffer << CONSTANT_LEFT_SQUARE_BRACKET;
|
||||
|
||||
//dump current cell contents
|
||||
for (size_t j = 0; j < matrix.getDimensionSize(index1); j++, index2++) { buffer << CONSTANT_SPACE << matrix.getBuffer()[index2]; }
|
||||
|
||||
//dimension end
|
||||
buffer << CONSTANT_SPACE << CONSTANT_RIGHT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
//dump all entries in current dimension
|
||||
for (size_t i = 0; i < matrix.getDimensionSize(index1); ++i)
|
||||
{
|
||||
//dimension start
|
||||
for (size_t j = 0; j < index1; ++j) { buffer << CONSTANT_TAB; }
|
||||
buffer << CONSTANT_LEFT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
|
||||
dumpMatrixBuffer(matrix, buffer, index1 + 1, index2);
|
||||
|
||||
//dimension end
|
||||
for (size_t j = 0; j < index1; ++j) { buffer << CONSTANT_TAB; }
|
||||
buffer << CONSTANT_RIGHT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool toString(const CMatrix& matrix, CString& str, const size_t precision /* = 6 */)
|
||||
{
|
||||
std::stringstream buffer;
|
||||
|
||||
buffer << std::scientific;
|
||||
buffer.precision(std::streamsize(precision));
|
||||
|
||||
// Dump header
|
||||
|
||||
//header start
|
||||
buffer << CONSTANT_LEFT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
|
||||
//dump labels for each dimension
|
||||
for (size_t i = 0; i < matrix.getDimensionCount(); ++i)
|
||||
{
|
||||
buffer << CONSTANT_TAB << CONSTANT_LEFT_SQUARE_BRACKET;
|
||||
|
||||
for (size_t j = 0; j < matrix.getDimensionSize(i); ++j)
|
||||
{
|
||||
buffer << CONSTANT_SPACE << CONSTANT_DOUBLE_QUOTE << matrix.getDimensionLabel(i, j) << CONSTANT_DOUBLE_QUOTE;
|
||||
}
|
||||
|
||||
buffer << CONSTANT_SPACE << CONSTANT_RIGHT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
}
|
||||
|
||||
//header end
|
||||
buffer << CONSTANT_RIGHT_SQUARE_BRACKET << CONSTANT_EOL;
|
||||
|
||||
// Dump buffer using a recursive algorithm
|
||||
size_t idx = 0;
|
||||
dumpMatrixBuffer(matrix, buffer, 0, idx);
|
||||
|
||||
str = buffer.str().c_str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadFromTextFile(CMatrix& matrix, const CString& filename)
|
||||
{
|
||||
std::ifstream dataFile;
|
||||
FS::Files::openIFStream(dataFile, filename.toASCIIString(), std::ios_base::in);
|
||||
if (!dataFile.is_open()) { return false; }
|
||||
|
||||
std::stringstream buffer;
|
||||
|
||||
buffer << dataFile.rdbuf();
|
||||
|
||||
const bool res = fromString(matrix, CString(buffer.str().c_str()));
|
||||
|
||||
dataFile.close();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool saveToTextFile(const CMatrix& matrix, const CString& filename, const size_t precision /* = 6 */)
|
||||
{
|
||||
std::ofstream dataFile;
|
||||
FS::Files::openOFStream(dataFile, filename.toASCIIString(), std::ios_base::out | std::ios_base::trunc);
|
||||
if (!dataFile.is_open()) { return false; }
|
||||
|
||||
CString str;
|
||||
|
||||
if (!toString(matrix, str, precision)) { return false; }
|
||||
|
||||
dataFile << str.toASCIIString();
|
||||
dataFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool copy(CMatrix& dst, const CMatrix& src)
|
||||
{
|
||||
if (&dst == &src) { return true; }
|
||||
dst.copy(src);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool copyDescription(CMatrix& dst, const CMatrix& src)
|
||||
{
|
||||
if (&dst == &src) { return true; }
|
||||
dst.copyDescription(src);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool copyContent(CMatrix& dst, const CMatrix& src)
|
||||
{
|
||||
if (&dst == &src) { return true; }
|
||||
const size_t nElementIn = src.getBufferElementCount();
|
||||
const size_t nElementOut = dst.getBufferElementCount();
|
||||
if (nElementOut != nElementIn) { return false; }
|
||||
dst.copyContent(src);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool clearContent(CMatrix& matrix)
|
||||
{
|
||||
matrix.resetBuffer();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isDescriptionSimilar(const CMatrix& src1, const CMatrix& src2, const bool checkLabels)
|
||||
{
|
||||
if (&src1 == &src2) { return true; }
|
||||
return src1.isDescriptionEqual(src2, checkLabels);
|
||||
}
|
||||
|
||||
bool isContentSimilar(const CMatrix& src1, const CMatrix& src2)
|
||||
{
|
||||
if (&src1 == &src2) { return true; }
|
||||
return src1.isBufferEqual(src2);
|
||||
}
|
||||
|
||||
bool isContentValid(const CMatrix& src, const bool checkNotANumber, const bool checkInfinity) { return src.isBufferValid(checkNotANumber, checkInfinity); }
|
||||
|
||||
} // namespace Matrix
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "ovtkStimulationSet.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
namespace StimulationSet {
|
||||
|
||||
bool shift(IStimulationSet& stimSet, const uint64_t timeShift)
|
||||
{
|
||||
const size_t count = stimSet.getStimulationCount();
|
||||
for (size_t i = 0; i < count; ++i) { stimSet.setStimulationDate(i, stimSet.getStimulationDate(i) + timeShift); }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool copy(IStimulationSet& dst, const IStimulationSet& src, const uint64_t timeShift)
|
||||
{
|
||||
dst.clear();
|
||||
return append(dst, src, timeShift);
|
||||
}
|
||||
|
||||
bool append(IStimulationSet& dst, const IStimulationSet& src, const uint64_t timeShift)
|
||||
{
|
||||
const size_t count = src.getStimulationCount();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
dst.appendStimulation(src.getStimulationIdentifier(i), src.getStimulationDate(i) + timeShift, src.getStimulationDuration(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool appendRange(IStimulationSet& dst, const IStimulationSet& src, const uint64_t srcStartTime, const uint64_t srcEndTime, const uint64_t timeShift)
|
||||
{
|
||||
const size_t count = src.getStimulationCount();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
const uint64_t date = src.getStimulationDate(i);
|
||||
if (srcStartTime <= date && date < srcEndTime)
|
||||
{
|
||||
dst.appendStimulation(src.getStimulationIdentifier(i), src.getStimulationDate(i) + timeShift, src.getStimulationDuration(i));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeRange(IStimulationSet& stimSet, const uint64_t startTime, const uint64_t endTime)
|
||||
{
|
||||
for (size_t i = 0; i < stimSet.getStimulationCount(); ++i)
|
||||
{
|
||||
const uint64_t date = stimSet.getStimulationDate(i);
|
||||
if (startTime <= date && date < endTime) { stimSet.removeStimulation(i--); }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace StimulationSet
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "ovtkString.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cctype>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
namespace String {
|
||||
|
||||
static bool isSeparator(const uint8_t value, const uint8_t* separator, const size_t nSeparator)
|
||||
{
|
||||
for (size_t i = 0; i < nSeparator; ++i) { if (value == separator[i]) { return true; } }
|
||||
return false;
|
||||
}
|
||||
|
||||
// because std::tolower has multiple signatures,
|
||||
// it can not be easily used in std::transform
|
||||
// this workaround is taken from http://www.gcek.net/ref/books/sw/cpp/ticppv2/
|
||||
template <class T>
|
||||
static T ToLower(T c) { return std::tolower(c); }
|
||||
|
||||
size_t split(const CString& str, const ISplitCallback& splitCB, uint8_t separator) { return split(str, splitCB, &separator, 1); }
|
||||
|
||||
size_t split(const CString& str, const ISplitCallback& splitCB, uint8_t* separator, const size_t nSeparator)
|
||||
{
|
||||
if (nSeparator == 0 || separator == nullptr) { return 0; }
|
||||
|
||||
size_t n = 0;
|
||||
std::string tmp(str.toASCIIString());
|
||||
size_t i = 0;
|
||||
while (i < tmp.length())
|
||||
{
|
||||
size_t j = i;
|
||||
while (j < tmp.length() && !isSeparator(tmp[j], separator, nSeparator)) { j++; }
|
||||
//if(i!=j)
|
||||
{
|
||||
splitCB.setToken(std::string(tmp, i, j - i).c_str());
|
||||
n++;
|
||||
}
|
||||
i = j + 1;
|
||||
}
|
||||
if (tmp.length() != 0 && isSeparator(tmp[tmp.length() - 1], separator, nSeparator))
|
||||
{
|
||||
splitCB.setToken("");
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
bool isAlmostEqual(const CString& str1, const CString& str2, const bool caseSensitive, const bool removeStartSpaces, const bool removeEndSpaces)
|
||||
{
|
||||
const char* str1Start = str1.toASCIIString();
|
||||
const char* str1End = str1Start + strlen(str1Start) - 1;
|
||||
|
||||
const char* str2Start = str2.toASCIIString();
|
||||
const char* str2End = str2Start + strlen(str2Start) - 1;
|
||||
|
||||
if (removeStartSpaces)
|
||||
{
|
||||
while (*str1Start == ' ') { str1Start++; }
|
||||
while (*str2Start == ' ') { str2Start++; }
|
||||
}
|
||||
|
||||
if (removeEndSpaces)
|
||||
{
|
||||
while (str1Start < str1End && *str1End == ' ') { str1End--; }
|
||||
while (str2Start < str2End && *str2End == ' ') { str2End--; }
|
||||
}
|
||||
|
||||
std::string tmp1(str1Start, str1End - str1Start + 1);
|
||||
std::string tmp2(str2Start, str2End - str2Start + 1);
|
||||
|
||||
if (!caseSensitive)
|
||||
{
|
||||
std::transform(tmp1.begin(), tmp1.end(), tmp1.begin(), ToLower<std::string::value_type>);
|
||||
std::transform(tmp2.begin(), tmp2.end(), tmp2.begin(), ToLower<std::string::value_type>);
|
||||
}
|
||||
|
||||
return tmp1 == tmp2;
|
||||
}
|
||||
|
||||
} // namespace String
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "ovtkCSignalTrial.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
bool CSignalTrial::setSamplingRate(const size_t sampling)
|
||||
{
|
||||
m_sampling = sampling;
|
||||
return m_sampling != 0;
|
||||
}
|
||||
|
||||
bool CSignalTrial::setChannelCount(const size_t count)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < count; ++i) { if (m_channelSamples.find(i) == m_channelSamples.end()) { m_channelSamples[i] = new double[m_nSampleReserved]; } }
|
||||
for (i = count; i < m_nChannel; ++i)
|
||||
{
|
||||
delete [] m_channelSamples[i];
|
||||
m_channelSamples.erase(m_channelSamples.find(i));
|
||||
}
|
||||
|
||||
m_nChannel = count;
|
||||
m_nSample = 0;
|
||||
m_channelNames.clear();
|
||||
return m_nChannel != 0;
|
||||
}
|
||||
|
||||
bool CSignalTrial::setChannelName(const size_t index, const char* name)
|
||||
{
|
||||
if (index < m_nChannel)
|
||||
{
|
||||
m_channelNames[index] = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSignalTrial::setLabelIdentifier(const CIdentifier& labelID)
|
||||
{
|
||||
m_labelID = labelID;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSignalTrial::setSampleCount(const size_t count, const bool preserve)
|
||||
{
|
||||
const size_t nSampleRounding = 0x00000fff;
|
||||
|
||||
if (count > m_nSampleReserved)
|
||||
{
|
||||
const size_t nSampleReserved = (count + nSampleRounding + 1) & (~nSampleRounding);
|
||||
for (auto it = m_channelSamples.begin(); it != m_channelSamples.end(); ++it)
|
||||
{
|
||||
double* sample = new double[nSampleReserved];
|
||||
if (preserve) { memcpy(sample, it->second, (count < m_nSample ? count : m_nSample) * sizeof(double)); }
|
||||
delete [] it->second;
|
||||
it->second = sample;
|
||||
}
|
||||
m_nSampleReserved = nSampleReserved;
|
||||
}
|
||||
m_nSample = count;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
const char* CSignalTrial::getChannelName(const size_t index) const
|
||||
{
|
||||
const auto it = m_channelNames.find(index);
|
||||
if (it != m_channelNames.end()) { return it->second.c_str(); }
|
||||
return "";
|
||||
}
|
||||
|
||||
double* CSignalTrial::getChannelSampleBuffer(const size_t index) const
|
||||
{
|
||||
const auto it = m_channelSamples.find(index);
|
||||
if (it != m_channelSamples.end()) { return it->second; }
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
ISignalTrial* createSignalTrial() { return new CSignalTrial(); }
|
||||
void releaseSignalTrial(ISignalTrial* trial) { delete trial; }
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovtkISignalTrial.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
class CSignalTrial final : public ISignalTrial
|
||||
{
|
||||
public:
|
||||
|
||||
CSignalTrial() {}
|
||||
~CSignalTrial() override { for (auto& s : m_channelSamples) { delete [] s.second; } }
|
||||
bool setSamplingRate(size_t sampling) override;
|
||||
bool setChannelCount(size_t count) override;
|
||||
bool setChannelName(size_t index, const char* name) override;
|
||||
bool setLabelIdentifier(const CIdentifier& labelID) override;
|
||||
bool setSampleCount(size_t count, bool preserve) override;
|
||||
size_t getSamplingRate() const override { return m_sampling; }
|
||||
size_t getChannelCount() const override { return m_nChannel; }
|
||||
const char* getChannelName(const size_t index) const override;
|
||||
CIdentifier getLabelIdentifier() const override { return m_labelID; }
|
||||
size_t getSampleCount() const override { return m_nSample; }
|
||||
uint64_t getDuration() const override { return (m_sampling ? CTime(m_sampling, m_nSample).time() : 0); }
|
||||
double* getChannelSampleBuffer(size_t index) const override;
|
||||
|
||||
_IsDerivedFromClass_Final_(ISignalTrial, OVTK_ClassId_)
|
||||
|
||||
protected:
|
||||
|
||||
std::map<size_t, std::string> m_channelNames;
|
||||
std::map<size_t, double*> m_channelSamples;
|
||||
size_t m_nChannel = 0;
|
||||
size_t m_nSample = 0;
|
||||
size_t m_nSampleReserved = 0;
|
||||
size_t m_sampling = 0;
|
||||
CIdentifier m_labelID = CIdentifier::undefined();
|
||||
};
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "ovtkCSignalTrialSet.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
bool CSignalTrialSet::addSignalTrial(ISignalTrial& rSignalTrial)
|
||||
{
|
||||
m_signalTrials.push_back(&rSignalTrial);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSignalTrialSet::clear()
|
||||
{
|
||||
m_signalTrials.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
ISignalTrialSet* createSignalTrialSet() { return new CSignalTrialSet(); }
|
||||
void releaseSignalTrialSet(ISignalTrialSet* signalTrialSet) { delete signalTrialSet; }
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovtkISignalTrialSet.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
class CSignalTrialSet final : public ISignalTrialSet
|
||||
{
|
||||
public:
|
||||
bool addSignalTrial(ISignalTrial& rSignalTrial) override;
|
||||
bool clear() override;
|
||||
size_t getSignalTrialCount() const override { return m_signalTrials.size(); }
|
||||
ISignalTrial& getSignalTrial(const size_t index) const override { return *m_signalTrials[index]; }
|
||||
|
||||
_IsDerivedFromClass_Final_(ISignalTrialSet, OVTK_ClassId_)
|
||||
|
||||
protected:
|
||||
|
||||
mutable std::vector<ISignalTrial*> m_signalTrials;
|
||||
};
|
||||
|
||||
extern OVTK_API ISignalTrialSet* createSignalTrialSet();
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,127 @@
|
||||
#include "ovtkISignalTrial.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Toolkit {
|
||||
|
||||
ISignalTrial& copyHeader(ISignalTrial& trial, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
|
||||
if (srcTrial != &trial)
|
||||
{
|
||||
const size_t nChannel = srcTrial->getChannelCount();
|
||||
trial.setChannelCount(nChannel);
|
||||
for (size_t i = 0; i < nChannel; ++i) { trial.setChannelName(i, srcTrial->getChannelName(i)); }
|
||||
trial.setSamplingRate(srcTrial->getSamplingRate());
|
||||
}
|
||||
|
||||
return trial;
|
||||
}
|
||||
|
||||
ISignalTrial& copy(ISignalTrial& trial, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
|
||||
// copyHeader(trial, srcTrial);
|
||||
|
||||
if (srcTrial != &trial)
|
||||
{
|
||||
const size_t nChannel = srcTrial->getChannelCount();
|
||||
const size_t nSample = srcTrial->getSampleCount();
|
||||
trial.setSampleCount(nSample, false);
|
||||
for (size_t i = 0; i < nChannel; ++i) { memcpy(trial.getChannelSampleBuffer(i), srcTrial->getChannelSampleBuffer(i), nSample * sizeof(double)); }
|
||||
}
|
||||
|
||||
return trial;
|
||||
}
|
||||
|
||||
ISignalTrial& selectSamples(ISignalTrial& trial, const size_t sampleStart, const size_t sampleEnd, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
if (srcTrial == &trial) { return trial; } // $$$ NOT YET IMPLEMENTED
|
||||
|
||||
// copyHeader(trial, srcTrial);
|
||||
|
||||
const size_t nChannel = srcTrial->getChannelCount();
|
||||
const size_t nSample = sampleEnd - sampleStart;
|
||||
|
||||
trial.setSampleCount(nSample, false);
|
||||
for (size_t i = 0; i < nChannel; ++i)
|
||||
{
|
||||
memcpy(trial.getChannelSampleBuffer(i), srcTrial->getChannelSampleBuffer(i) + sampleStart, nSample * sizeof(double));
|
||||
}
|
||||
|
||||
return trial;
|
||||
}
|
||||
|
||||
ISignalTrial& selectTime(ISignalTrial& trial, const uint64_t timeStart, const uint64_t timeEnd, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
if (srcTrial == &trial) { return trial; } // $$$ NOT YET IMPLEMENTED
|
||||
|
||||
const size_t sampleStart = size_t((timeStart * srcTrial->getSamplingRate()) >> 32);
|
||||
const size_t sampleEnd = size_t((timeEnd * srcTrial->getSamplingRate()) >> 32);
|
||||
return selectSamples(trial, sampleStart, sampleEnd, srcTrial);
|
||||
}
|
||||
|
||||
ISignalTrial& removeSamples(ISignalTrial& trial, const size_t sampleStart, const size_t sampleEnd, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
if (srcTrial == &trial) { return trial; } // $$$ NOT YET IMPLEMENTED
|
||||
|
||||
// copyHeader(trial, srcTrial);
|
||||
|
||||
const size_t srcNChannel = srcTrial->getChannelCount();
|
||||
const size_t srcNSample = srcTrial->getSampleCount() - (sampleEnd - sampleStart);
|
||||
|
||||
trial.setSampleCount(srcNSample, false);
|
||||
for (size_t i = 0; i < srcNChannel; ++i)
|
||||
{
|
||||
memcpy(trial.getChannelSampleBuffer(i), srcTrial->getChannelSampleBuffer(i), sampleStart * sizeof(double));
|
||||
memcpy(trial.getChannelSampleBuffer(i) + sampleStart, srcTrial->getChannelSampleBuffer(i) + sampleEnd, (srcNSample - sampleStart) * sizeof(double));
|
||||
}
|
||||
|
||||
return trial;
|
||||
}
|
||||
|
||||
ISignalTrial& removeTime(ISignalTrial& trial, const uint64_t timeStart, const uint64_t timeEnd, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
if (srcTrial == &trial) { return trial; } // $$$ NOT YET IMPLEMENTED
|
||||
|
||||
const size_t sampleStart = size_t((timeStart * srcTrial->getSamplingRate()) >> 32);
|
||||
const size_t sampleEnd = size_t((timeEnd * srcTrial->getSamplingRate()) >> 32);
|
||||
return removeSamples(trial, sampleStart, sampleEnd, srcTrial);
|
||||
}
|
||||
|
||||
ISignalTrial& insertBufferSamples(ISignalTrial& trial, const size_t sampleStart, const size_t nSample, const double* buffer, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
|
||||
// copyHeader(trial, srcTrial);
|
||||
|
||||
const size_t srcNChannel = srcTrial->getChannelCount();
|
||||
const size_t srcNSample = srcTrial->getSampleCount();
|
||||
|
||||
trial.setSampleCount(srcNSample + nSample, true);
|
||||
for (size_t i = 0; i < srcNChannel; ++i)
|
||||
{
|
||||
if (&trial != srcTrial) { memcpy(trial.getChannelSampleBuffer(i), srcTrial->getChannelSampleBuffer(i), sampleStart * sizeof(double)); }
|
||||
|
||||
memcpy(trial.getChannelSampleBuffer(i) + sampleStart + nSample, srcTrial->getChannelSampleBuffer(i), (srcNSample - sampleStart) * sizeof(double));
|
||||
memcpy(trial.getChannelSampleBuffer(i) + sampleStart, buffer + nSample * i, nSample * sizeof(double));
|
||||
}
|
||||
|
||||
return trial;
|
||||
}
|
||||
|
||||
ISignalTrial& insertBufferTime(ISignalTrial& trial, const uint64_t timeStart, const size_t nSample, const double* buffer, const ISignalTrial* srcTrial)
|
||||
{
|
||||
if (srcTrial == nullptr) { srcTrial = &trial; }
|
||||
|
||||
const size_t sampleStart = size_t((timeStart * srcTrial->getSamplingRate()) >> 32);
|
||||
return insertBufferSamples(trial, sampleStart, nSample, buffer, srcTrial);
|
||||
}
|
||||
|
||||
} // namespace Toolkit
|
||||
} // namespace OpenViBE
|
||||
Reference in New Issue
Block a user