C++ (Qt)union { double value; double coordinate[3]; float color[4];};
template<typename T> Curve { template <typename T>struct Value<T>{T data, in, out; float someOptions[];} QMap<double,Value> }
C++ (Qt)Зачем, зачем ты торопился?Зачем свою лошадку гнал?Али урядника боялсяАли в контору задолжал?
C++ (Qt)QImage<format_ARGB32> QImage<format_GrayScale>...
#include <typeinfo>class Base{ static const QStringList typeId;public: enum TYPE { NO = -1, INT, STR, DBL } type = NO; int getData(double, int &data); int getData(double, QString &data); int getData(double, double &data);};template <typename T> class BaseChild: public Base{ friend Base;protected: T data;public: BaseChild(T data) : data(data) { type = (TYPE)typeId.indexOf(typeid(data).name()); }};const QStringList Base::typeId {"i", "7QString", "d"};int Base::getData(double, int &data) { if(type == (int)INT) data = static_cast<BaseChild<int>*>(this)->data; }int Base::getData(double, QString &data) { if(type == (int)STR) data = static_cast<BaseChild<QString>*>(this)->data; }int Base::getData(double, double &data) { if(type == (int)DBL) data = static_cast<BaseChild<double>*>(this)->data; }int main(int argc, char *argv[]){ QList<Base*> list; list << new BaseChild<int>(5); list << new BaseChild<QString>("5"); list << new BaseChild<double>(5); for(auto i: list) qDebug() << i->type; int a1; QString a2; double a3; list[0]->getData(1, a1); list[1]->getData(1, a2); list[2]->getData(1, a3); qDebug() << a1 << a2 << a3; return 0;}
C++ (Qt)#include <iostream>#include <any>#include <variant>#include <vector>#include <array>#include <chrono> using namespace std; using Vector3D = array<double, 3>;using Color = array<int, 4>;using TimePoint = chrono::system_clock::time_point; struct RatioOption{ double inRatioVector; double outRatioVector;}; struct WeightOption{ int inWeight; int outWeight;}; struct Curve{ using Key = variant<double, TimePoint>; using Point = variant<double, Vector3D, Color>; using Option = any; struct Data { Key key; Point point; Option option; }; using Container = vector<Data>; Container data;}; int main(){ Curve curve; curve.data.push_back( { 1.5, Color{24,32,64,128}, RatioOption{5.4, 8.7} } ); curve.data.push_back( { TimePoint::clock::now(), Vector3D{1.2, 3.4, 5.6}, WeightOption{2,6} } ); for (const auto & data : curve.data) { cout << "key = " << data.key // ?? << "point = " << data.point // ?? << "option = " << data.option // ?? << endl; } return 0;}
C++ (Qt)struct RatioOption{ double inRatioVector; double outRatioVector;};
C++ (Qt)template <T>struct RatioOption{ T inRatioVector; T outRatioVector;};
class Spline {QMap<Time,QVariant> data;QList<IdData,Qvarint> inData, outData; Qvariant getData(Time time, SplineType st); //сюда можно вообще callback засунуть например, или разные сплайны будут требовать разные вспомогательные данные}
Spline{ QList<UnionData> data; QList<UnionSplineData> dataForSpline; void(*splineFunction)();}
C++ (Qt)#include <iostream>#include <vector>#include <array>#include <chrono>#include <memory> using namespace std; using Vector3D = array<double, 3>;using Color = array<int, 4>;using TimePoint = chrono::system_clock::time_point; struct EmptyOption{}; template <class T>struct RatioOption{ T inRatioVector; T outRatioVector;}; template <class T>struct WeightOption{ T inWeight; T outWeight;}; struct AbstractCurve{public: virtual ~AbstractCurve(){} virtual void printTo(ostream & stream) const = 0;}; template <class Key, class Point, class Option = EmptyOption>struct Curve final : public AbstractCurve{ struct Data { Key key; Point point; Option option; }; using Container = vector<Data>; Container data; void printTo(ostream & stream) const override { stream << "Generic curve [" << endl; for (const auto & i : data) { stream << " [" << " key = " << i.key << ", point = " << i.point << ", option = " << i.option << " ]" << endl; } stream << "]" << endl; }}; int main(){ auto coord_curve = make_unique<Curve<TimePoint, Vector3D>>(); coord_curve->data.push_back({TimePoint(1s), Vector3D{1.2, 3.4, 5.6}, EmptyOption()}); coord_curve->data.push_back({TimePoint(2s), {5.6, 3.4, 1.2}, {}}); auto color_curve = make_unique<Curve<double, Color>>(); color_curve->data.push_back({1.7, Color{1, 2, 3, 4}, {}}); color_curve->data.push_back({2.5, {5, 6, 7, 8}}); auto coord_ratio_curve = make_unique<Curve<TimePoint, Vector3D, RatioOption<double>>>(); coord_ratio_curve->data.push_back({TimePoint(1h), {1.2, 3.4, 5.6}, {1.4, 4.1}}); coord_ratio_curve->data.push_back({TimePoint(2h), {5.6, 3.4, 1.2}, {2.3, 5.7}}); auto color_weight_curve = make_unique<Curve<double, Color, WeightOption<int>>>(); color_weight_curve->data.push_back({5.8, Color{1, 2, 3, 4}, {1, 2}}); color_weight_curve->data.push_back({7.2, {5, 6, 7, 8}, {3, 4}}); vector<unique_ptr<AbstractCurve>> curves; curves.push_back(move(coord_curve)); curves.push_back(move(color_curve)); curves.push_back(move(coord_ratio_curve)); curves.push_back(move(color_weight_curve)); for (const auto & curve : curves) curve->printTo(cout); return 0;}
C++ (Qt)struct Curve {... QVector<Key *> mKeys; ... }; struct Key { ... virtual MyVariant GetValue( void ); virtual void SetValue( const MyVariant & ); ...}; template <class DataType, class SplineType>struct CTypedKey : public Key {... virtual MyVariant GetValue( void ) { return mData; } virtual void SetValue( const MyVariant & v ) { mData = v; }... DataType mData; SplineType mSpline;};
C++ (Qt)double InterpolateValue( Curve * curve, double t ){// проверяем частные случаи if (t >= MaxTime(curve)) ... if (t <= MinTime(curve)) ... switch (curve->splineType) { case SPLINE_LINEAR: return InterpolateLinear(curve, t); case SPLINE_RATIO: return InterpolateRatio(curve, t); ..... }}
C++ (Qt)double InterpolateLinear( Curve * curve, double t ){ Key * key1 = FindUpperKey(curve, t); // находим первый ключ с временем больше t Key * key0 = GetPreviousKey(key1); // и предыдущий // интерполируем double relativeT = (t - key0->keyTime) / (key1->keyTime - key0->keyTime); return key0->keyData * (1 - relativeT) + key1->keyData * relativeT;}
C++ (Qt)// спец случай - постоянное значение до след ключа if (TestFlag(key0->spline.ratio.flag, BIT_HOLD)) return key0->keyData; // спец случай - линейное значение до след ключа if (TestFlag(key0->spline.ratio.flag, BIT_LINEAR)) return ... // интерполируем double relativeT = (t - key0->keyTime) / (key1->keyTime - key0->keyTime); double k[4]; CalcCoefficients(t, k); return key0->keyData * k[0] + key1->keyData * k[1] + key0->spline.ratio.outRatioVector * k[2] + key1->spline.ratio.inRatioVector * k[3];
C++ (Qt) QImage * image = new QImage(100, 100, QImage::Format_ARGB32);
C++ (Qt) QImage * image = new QFormattedImage<Format_ARGB32>(100, 100);