Program Listing for File DataPlotter.h#
↰ Return to documentation for file (include/Karana/KUtils/DataPlotter.h)
/*
*Copyright(c)2024-2026KaranaDynamicsPtyLtd.Allrightsreserved.
*
*NOTICETOUSER:
*
*Thissourcecodeand/ordocumentation(the"LicensedMaterials")is
*theconfidentialandproprietaryinformationofKaranaDynamicsInc.
*UseoftheseLicensedMaterialsisgovernedbythetermsandconditions
*ofaseparatesoftwarelicenseagreementbetweenKaranaDynamicsandthe
*Licensee("LicenseAgreement").Unlessexpresslypermittedunderthat
*agreement,anyreproduction,modification,distribution,ordisclosure
*oftheLicensedMaterials,inwholeorinpart,toanythirdparty
*withoutthepriorwrittenconsentofKaranaDynamicsisstrictlyprohibited.
*
*THELICENSEDMATERIALSAREPROVIDED"ASIS"WITHOUTWARRANTYOFANYKIND.
*KARANADYNAMICSDISCLAIMSALLWARRANTIES,EXPRESSORIMPLIED,INCLUDING
*BUTNOTLIMITEDTOWARRANTIESOFMERCHANTABILITY,NON-INFRINGEMENT,AND
*FITNESSFORAPARTICULARPURPOSE.
*
*INNOEVENTSHALLKARANADYNAMICSBELIABLEFORANYDAMAGESWHATSOEVER,
*INCLUDINGBUTNOTLIMITEDTOLOSSOFPROFITS,DATA,ORUSE,EVENIF
*ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGES,WHETHERINCONTRACT,TORT,
*OROTHERWISEARISINGOUTOFORINCONNECTIONWITHTHELICENSEDMATERIALS.
*
*U.S.GovernmentEndUsers:TheLicensedMaterialsarea"commercialitem"
*asdefinedat48C.F.R.2.101,andareprovidedtotheU.S.Government
*onlyasacommercialenditemunderthetermsofthislicense.
*
*AnyuseoftheLicensedMaterialsinindividualorcommercialsoftwaremust
*include,intheuserdocumentationandinternalsourcecodecomments,
*thisNotice,Disclaimer,andU.S.GovernmentUseProvision.
*/
#include"Karana/KCore/Base.h"
#include"Karana/Math/Defs.h"
#include<boost/asio.hpp>
#include<boost/asio/strand.hpp>
#include<boost/beast/core.hpp>
#include<boost/beast/websocket.hpp>
#include<map>
#include<string>
namespaceKarana::KUtils{
namespacekm=Karana::Math;
usingPlotDataType=std::variant<double,km::Vec3,km::Vec>;
structSinglePlotData{
public:
std::stringtitle;
std::stringx_data_name;
std::function<double()>x_data;
std::vector<std::string>y_data_names;
std::vector<std::function<PlotDataType()>>y_data_fns;
SinglePlotData(std::string_viewtitle,
std::string_viewx_data_name,
std::function<double()>x_data,
std::map<std::string,std::function<PlotDataType()>>y_data);
SinglePlotData(std::string_viewtitle,
std::string_viewx_data_name,
std::function<double()>x_data,
std::vector<std::string>y_data_names,
std::vector<std::function<PlotDataType()>>y_data_fns);
SinglePlotData(constSinglePlotData&other);
SinglePlotData(SinglePlotData&&other)noexcept;
SinglePlotData&operator=(constSinglePlotData&other);
SinglePlotData&operator=(SinglePlotData&&other)noexcept;
private:
SinglePlotData(
std::string_viewtitle,
std::string_viewx_data_name,
std::function<double()>x_data,
std::pair<std::vector<std::string>,std::vector<std::function<PlotDataType()>>>y_data);
};
classWsClient{
public:
WsClient(std::string_viewhost,std::string_viewport,std::string_viewtarget);
voidstart();
voidsend(std::stringmsg);
voidstop();
private:
std::string_host;
std::string_port;
std::string_target;
boost::asio::io_context_ioc;
boost::asio::ip::tcp::resolver_resolver;
boost::beast::websocket::stream<boost::asio::ip::tcp::socket>_ws;
boost::asio::strand<boost::asio::io_context::executor_type>_strand;
bool_running=false;
};
classPlotData:publicKarana::Core::Base{
public:
PlotData(conststd::vector<SinglePlotData>&plot_data,
std::string_viewhost,
std::string_viewport,
std::string_viewtarget);
staticKarana::Core::ks_ptr<PlotData>create(conststd::vector<SinglePlotData>&plot_data,
std::string_viewhost,
std::string_viewport,
std::string_viewtarget);
~PlotData();
voidaddPlot(SinglePlotDataplot_data);
voidremovePlot(size_tindex);
voidupdate();
voidsendWebsocketMessage(conststd::string&msg);
voidshutdown();
std::vector<SinglePlotData>plot_fns;
private:
WsClient_ws;
};
}//namespaceKarana::KUtils