init
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
#include "ovvizCVisualizationContext.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace VisualizationToolkit {
|
||||
|
||||
bool CVisualizationContext::setWidget(Toolkit::TBoxAlgorithm<Plugins::IBoxAlgorithm>& box, GtkWidget* widget)
|
||||
{
|
||||
const CIdentifier boxID = box.getStaticBoxContext().getIdentifier();
|
||||
CIdentifier treeIdentifier = CIdentifier::undefined();
|
||||
|
||||
// When a scenario is created in the designer, the designer creates a visualization tree for it. The box will then need to add
|
||||
// visualization widgets into this tree. The designer can not pass this information directly to a box in a way that can be read
|
||||
// here (for example an Attribute could be written in the designer but then it is not possible to read it here).
|
||||
//
|
||||
// What we do is that we write the visualization tree identifier into the local scenario configuration manager. This manager
|
||||
// can be accessed as long as we have the boxAlgorithm.
|
||||
if (!treeIdentifier.fromString(box.getConfigurationManager().lookUpConfigurationTokenValue("VisualizationContext_VisualizationTreeId"))) { return false; }
|
||||
|
||||
return m_VisualizationManager->setWidget(treeIdentifier, boxID, widget);
|
||||
}
|
||||
|
||||
bool CVisualizationContext::setToolbar(Toolkit::TBoxAlgorithm<Plugins::IBoxAlgorithm>& box, GtkWidget* toolbarWidget)
|
||||
{
|
||||
const CIdentifier boxID = box.getStaticBoxContext().getIdentifier();
|
||||
CIdentifier treeIdentifier = CIdentifier::undefined();
|
||||
|
||||
if (!treeIdentifier.fromString(box.getConfigurationManager().lookUpConfigurationTokenValue("VisualizationContext_VisualizationTreeId"))) { return false; }
|
||||
|
||||
return m_VisualizationManager->setToolbar(treeIdentifier, boxID, toolbarWidget);
|
||||
}
|
||||
|
||||
} // namespace VisualizationToolkit
|
||||
} // namespace OpenViBE
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <openvibe/plugins/ovIPluginObjectDesc.h>
|
||||
#include <visualization-toolkit/ovviz_all.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "ovvizIVisualizationManager.h"
|
||||
#include "ovvizIVisualizationContext.h"
|
||||
|
||||
#define OVP_ClassId_Plugin_VisualizationCtx OpenViBE::CIdentifier(0x05A7171D, 0x78E4FE3C)
|
||||
#define OVP_ClassId_Plugin_VisualizationCtxDesc OpenViBE::CIdentifier(0x35A11438, 0x764F72E8)
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace VisualizationToolkit {
|
||||
/**
|
||||
* @brief The CVisualizationContext class is a singleton used for passing visualization related information between the application
|
||||
* and visualization plugins.
|
||||
*/
|
||||
class CVisualizationContext final : public IVisualizationContext
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The release function is neutralized. The object is only allocated once in the descriptor as a unique_ptr
|
||||
* and will be released at its destruction.
|
||||
*/
|
||||
void release() override { }
|
||||
|
||||
bool setManager(IVisualizationManager* visualizationManager) override
|
||||
{
|
||||
m_VisualizationManager = visualizationManager;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setWidget(Toolkit::TBoxAlgorithm<Plugins::IBoxAlgorithm>& box, GtkWidget* widget) override;
|
||||
|
||||
bool setToolbar(Toolkit::TBoxAlgorithm<Plugins::IBoxAlgorithm>& box, GtkWidget* toolbarWidget) override;
|
||||
|
||||
bool isDerivedFromClass(const CIdentifier& classIdentifier) const override
|
||||
{
|
||||
return ((classIdentifier == OVP_ClassId_Plugin_VisualizationCtx) || IVisualizationContext::isDerivedFromClass(classIdentifier));
|
||||
}
|
||||
|
||||
CIdentifier getClassIdentifier() const override { return OVP_ClassId_Plugin_VisualizationCtx; }
|
||||
|
||||
CVisualizationContext() = default;
|
||||
|
||||
private:
|
||||
IVisualizationManager* m_VisualizationManager = nullptr;
|
||||
};
|
||||
|
||||
class CVisualizationContextDesc final : public Plugins::IPluginObjectDesc
|
||||
{
|
||||
public:
|
||||
|
||||
CVisualizationContextDesc() : m_visualizationCtx(new CVisualizationContext()) {}
|
||||
|
||||
void release() override { }
|
||||
|
||||
CString getName() const override { return CString("Visualization Context"); }
|
||||
CString getAuthorName() const override { return CString("Jozef Legény"); }
|
||||
CString getAuthorCompanyName() const override { return CString("Mensia Technologies"); }
|
||||
CString getShortDescription() const override { return CString(""); }
|
||||
CString getDetailedDescription() const override { return CString(""); }
|
||||
CString getCategory() const override { return CString(""); }
|
||||
CString getVersion() const override { return CString("1.0"); }
|
||||
|
||||
CIdentifier getCreatedClass() const override { return OVP_ClassId_Plugin_VisualizationCtx; }
|
||||
|
||||
/**
|
||||
* The create function usage is different from standard plugins. As we need to be able to pass data between
|
||||
* the application and the plugins, we need a permanent object that can be accessed by both. We achieve this
|
||||
* by saving the object within the plugin descriptor and returning the pointer to the same object to all
|
||||
* plugins.
|
||||
*
|
||||
* @return The singleton visualizationContext object
|
||||
*/
|
||||
Plugins::IPluginObject* create() override { return m_visualizationCtx.get(); }
|
||||
|
||||
bool isDerivedFromClass(const CIdentifier& classIdentifier) const override
|
||||
{
|
||||
return ((classIdentifier == OVP_ClassId_Plugin_VisualizationCtxDesc) || IPluginObjectDesc::isDerivedFromClass(classIdentifier));
|
||||
}
|
||||
|
||||
CIdentifier getClassIdentifier() const override { return OVP_ClassId_Plugin_VisualizationCtxDesc; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<CVisualizationContext> m_visualizationCtx;
|
||||
};
|
||||
} // namespace VisualizationToolkit
|
||||
} // namespace OpenViBE
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
#include "ovvizColorGradient.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace VisualizationToolkit {
|
||||
namespace {
|
||||
typedef struct
|
||||
{
|
||||
double percent, red, green, blue;
|
||||
} SColor;
|
||||
} // namespace
|
||||
|
||||
bool ColorGradient::parse(CMatrix& colorGradient, const CString& string)
|
||||
{
|
||||
const std::string colorString(string.toASCIIString());
|
||||
size_t startPosition = 0;
|
||||
|
||||
std::map<double, SColor> colorGradientVector;
|
||||
|
||||
do
|
||||
{
|
||||
size_t endPosition = colorString.find(OV_Value_EnumeratedStringSeparator, startPosition);
|
||||
if (endPosition == std::string::npos) { endPosition = colorString.length(); }
|
||||
|
||||
std::string colorSubString;
|
||||
colorSubString.assign(colorString, startPosition, endPosition - startPosition);
|
||||
|
||||
int p, r, g, b;
|
||||
if (sscanf(colorSubString.c_str(), "%i:%i,%i,%i", &p, &r, &g, &b) == 4)
|
||||
{
|
||||
SColor color;
|
||||
color.percent = p;
|
||||
color.red = r;
|
||||
color.green = g;
|
||||
color.blue = b;
|
||||
colorGradientVector[color.percent] = color;
|
||||
}
|
||||
|
||||
startPosition = endPosition + 1;
|
||||
} while (startPosition < colorString.length());
|
||||
|
||||
colorGradient.resize(4, colorGradientVector.size());
|
||||
|
||||
size_t i = 0;
|
||||
for (auto it = colorGradientVector.begin(); it != colorGradientVector.end(); ++it, i++)
|
||||
{
|
||||
colorGradient[i * 4] = it->second.percent;
|
||||
colorGradient[i * 4 + 1] = it->second.red;
|
||||
colorGradient[i * 4 + 2] = it->second.green;
|
||||
colorGradient[i * 4 + 3] = it->second.blue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorGradient::format(CString& string, const CMatrix& colorGradient)
|
||||
{
|
||||
if (colorGradient.getDimensionCount() != 2) { return false; }
|
||||
|
||||
if (colorGradient.getDimensionSize(0) != 4) { return false; }
|
||||
|
||||
std::string separator(" ");
|
||||
separator[0] = OV_Value_EnumeratedStringSeparator;
|
||||
|
||||
std::string result;
|
||||
for (size_t i = 0; i < colorGradient.getDimensionSize(1); ++i)
|
||||
{
|
||||
char buffer[1024];
|
||||
sprintf(buffer, "%.0lf:%i,%i,%i", colorGradient[i * 4], int(colorGradient[i * 4 + 1]), int(colorGradient[i * 4 + 2]), int(colorGradient[i * 4 + 3]));
|
||||
result += (i == 0 ? "" : separator);
|
||||
result += buffer;
|
||||
}
|
||||
|
||||
string = result.c_str();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorGradient::interpolate(CMatrix& interpolatedColorGradient, const CMatrix& colorGradient, const size_t steps)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (colorGradient.getDimensionCount() != 2 || colorGradient.getDimensionSize(0) != 4) { return false; }
|
||||
|
||||
if (steps <= 1) { return false; }
|
||||
|
||||
interpolatedColorGradient.resize(4, steps);
|
||||
|
||||
std::map<double, SColor> colors;
|
||||
|
||||
for (i = 0; i < colorGradient.getDimensionSize(1); ++i)
|
||||
{
|
||||
SColor color;
|
||||
color.percent = colorGradient[i * 4];
|
||||
color.red = colorGradient[i * 4 + 1];
|
||||
color.green = colorGradient[i * 4 + 2];
|
||||
color.blue = colorGradient[i * 4 + 3];
|
||||
colors[color.percent] = color;
|
||||
}
|
||||
|
||||
if (colors.find(0) == colors.end())
|
||||
{
|
||||
SColor color = colors.begin()->second;
|
||||
color.percent = 0;
|
||||
colors[0] = color;
|
||||
}
|
||||
|
||||
if (colors.find(100) == colors.end())
|
||||
{
|
||||
SColor color = colors.rbegin()->second;
|
||||
color.percent = 100;
|
||||
colors[100] = color;
|
||||
}
|
||||
|
||||
auto it1 = colors.begin();
|
||||
auto it2 = colors.begin();
|
||||
++it2;
|
||||
|
||||
for (i = 0; i < steps; ++i)
|
||||
{
|
||||
const double t = double(100 * i) / (steps - 1);
|
||||
while (it2->first < t)
|
||||
{
|
||||
++it1;
|
||||
++it2;
|
||||
}
|
||||
|
||||
const double a = it2->first - t;
|
||||
const double b = t - it1->first;
|
||||
const double d = it2->first - it1->first;
|
||||
|
||||
interpolatedColorGradient[i * 4] = t;
|
||||
interpolatedColorGradient[i * 4 + 1] = (it1->second.red * a + it2->second.red * b) / d;
|
||||
interpolatedColorGradient[i * 4 + 2] = (it1->second.green * a + it2->second.green * b) / d;
|
||||
interpolatedColorGradient[i * 4 + 3] = (it1->second.blue * a + it2->second.blue * b) / d;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace VisualizationToolkit
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "visualization-toolkit/ovviz_all.h"
|
||||
#include "ovvizCVisualizationContext.hpp"
|
||||
|
||||
namespace OpenViBE {
|
||||
|
||||
namespace {
|
||||
VisualizationToolkit::CVisualizationContextDesc visualizationContextDesc;
|
||||
} // namespace
|
||||
|
||||
bool VisualizationToolkit::initialize(const Kernel::IKernelContext& ctx)
|
||||
{
|
||||
Kernel::ITypeManager& typeManager = ctx.getTypeManager();
|
||||
Kernel::IPluginManager& pluginManager = ctx.getPluginManager();
|
||||
|
||||
typeManager.registerType(OV_TypeId_Color, "Color");
|
||||
typeManager.registerType(OV_TypeId_ColorGradient, "Color Gradient");
|
||||
|
||||
pluginManager.registerPluginDesc(visualizationContextDesc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VisualizationToolkit::uninitialize(const Kernel::IKernelContext& /*ctx*/) { return true; }
|
||||
|
||||
} // namespace OpenViBE
|
||||
Reference in New Issue
Block a user