comparison data/model/AlignmentModel.h @ 338:f14e2f7b24f7

* More space and time efficient AlignmentModel
author Chris Cannam
date Thu, 22 Nov 2007 11:09:26 +0000
parents a71dec01c4d3
children 700cd3350391
comparison
equal deleted inserted replaced
336:5cd7f6d10d47 338:f14e2f7b24f7
15 15
16 #ifndef _ALIGNMENT_MODEL_H_ 16 #ifndef _ALIGNMENT_MODEL_H_
17 #define _ALIGNMENT_MODEL_H_ 17 #define _ALIGNMENT_MODEL_H_
18 18
19 #include "Model.h" 19 #include "Model.h"
20 #include "SparseModel.h"
21 #include "base/RealTime.h"
22
23 #include <QString>
24 #include <QStringList>
20 25
21 class SparseTimeValueModel; 26 class SparseTimeValueModel;
22 27
23 class AlignmentModel : public Model 28 class AlignmentModel : public Model
24 { 29 {
58 protected: 63 protected:
59 Model *m_reference; // I don't own this 64 Model *m_reference; // I don't own this
60 Model *m_aligned; // I don't own this 65 Model *m_aligned; // I don't own this
61 66
62 Model *m_inputModel; // I own this 67 Model *m_inputModel; // I own this
63 SparseTimeValueModel *m_path; // I own this 68
64 mutable SparseTimeValueModel *m_reversePath; // I own this 69 struct PathPoint
70 {
71 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
72 PathPoint(long _frame, long _mapframe) :
73 frame(_frame), mapframe(_mapframe) { }
74
75 int getDimensions() const { return 2; }
76
77 long frame;
78 long mapframe;
79
80 QString getLabel() const { return ""; }
81
82 void toXml(QTextStream &stream, QString indent = "",
83 QString extraAttributes = "") const {
84 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
85 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
86 }
87
88 QString toDelimitedDataString(QString delimiter,
89 size_t sampleRate) const {
90 QStringList list;
91 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
92 list << QString("%1").arg(mapframe);
93 return list.join(delimiter);
94 }
95
96 struct Comparator {
97 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
98 if (p1.frame != p2.frame) return p1.frame < p2.frame;
99 return p1.mapframe < p2.mapframe;
100 }
101 };
102
103 struct OrderComparator {
104 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
105 return p1.frame < p2.frame;
106 }
107 };
108 };
109
110 class PathModel : public SparseModel<PathPoint>
111 {
112 public:
113 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
114 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
115 };
116
117 SparseTimeValueModel *m_rawPath; // I own this
118 mutable PathModel *m_path; // I own this
119 mutable PathModel *m_reversePath; // I own this
65 bool m_pathBegun; 120 bool m_pathBegun;
66 bool m_pathComplete; 121 bool m_pathComplete;
67 122
123 void constructPath() const;
68 void constructReversePath() const; 124 void constructReversePath() const;
69 125
70 size_t align(SparseTimeValueModel *path, size_t frame) const; 126 size_t align(PathModel *path, size_t frame) const;
71 }; 127 };
72 128
73 #endif 129 #endif