18 #include "xlistnode.h"
19 #include "xitemnode.h"
25 #define clWhite (unsigned int)QColor(Qt::white).rgb()
26 #define clRed (unsigned int)QColor(Qt::red).rgb()
27 #define clLime (unsigned int)QColor(Qt::darkYellow).rgb()
28 #define clAqua (unsigned int)QColor(Qt::cyan).rgb()
29 #define clBlack (unsigned int)QColor(Qt::black).rgb()
30 #define clGreen (unsigned int)QColor(Qt::green).rgb()
31 #define clBlue (unsigned int)QColor(Qt::blue).rgb()
35 Vector4() : x(0), y(0), z(0), w(1) {}
37 Vector4(T nx, T ny, T nz = 0, T nw = 1) : x(nx), y(ny), z(nz), w(nw) {}
40 bool operator==(
const Vector4 &s1)
const {
return ((x == s1.x) && (y == s1.y) && (z == s1.z));}
42 x += s1.x; y += s1.y; z += s1.z;
46 x -= s1.x; y -= s1.y; z -= s1.z;
50 x *= k; y *= k; z *= k;
58 return x1*x1 + y1*y1 + z1*z1;
68 T zbab = x1*x2 + y1*y2 + z1*z2;
69 T ab2 = x2*x2 + y2*y2 + z2*z2;
70 T zb2 = x1*x1 + y1*y1 + z1*z1;
71 return (zb2*ab2 - zbab*zbab) / ab2;
74 T ir = (T)1.0 / sqrtf(x*x + y*y + z*z);
75 x *= ir; y *= ir; z *= ir;
79 s2.x = y * s1.z - z * s1.y;
80 s2.y = z * s1.x - x * s1.z;
81 s2.z = x * s1.y - y * s1.x;
85 T innerProduct(
const Vector4 &s1)
const {
86 return x * s1.x + y * s1.y + z * s1.z;
103 XGraph(
const char *name,
bool runtime);
106 typedef float SFloat;
107 static const SFloat SFLOAT_MAX;
108 typedef float GFloat;
109 static const GFloat GFLOAT_MAX;
110 typedef double VFloat;
111 static const VFloat VFLOAT_MAX;
118 void setupRedraw(
Transaction &tr,
float resolution);
120 void zoomAxes(
Transaction &tr,
float resolution, XGraph::SFloat zoomscale,
123 const shared_ptr<XAxisList> &axes()
const {
return m_axes;}
124 const shared_ptr<XPlotList> &plots()
const {
return m_plots;}
126 const shared_ptr<XStringNode> &label()
const {
return m_label;}
127 const shared_ptr<XHexNode> &backGround()
const {
return m_backGround;}
128 const shared_ptr<XHexNode> &titleColor()
const {
return m_titleColor;}
130 const shared_ptr<XBoolNode> &drawLegends()
const {
return m_drawLegends;}
132 const shared_ptr<XDoubleNode> &persistence()
const {
return m_persistence;}
134 const shared_ptr<XListener> &lsnPropertyChanged()
const {
return m_lsnPropertyChanged;}
147 const shared_ptr<XStringNode> m_label;
148 const shared_ptr<XAxisList> m_axes;
149 const shared_ptr<XPlotList> m_plots;
150 const shared_ptr<XHexNode> m_backGround;
151 const shared_ptr<XHexNode> m_titleColor;
152 const shared_ptr<XBoolNode> m_drawLegends;
153 const shared_ptr<XDoubleNode> m_persistence;
155 shared_ptr<XListener> m_lsnPropertyChanged;
160 XPlot(
const char *name,
bool runtime,
Transaction &tr_graph,
const shared_ptr<XGraph> &graph);
169 XGraph::SFloat scr_prec = -1);
174 const shared_ptr<XStringNode> &label()
const {
return m_label;}
176 const shared_ptr<XUIntNode> &maxCount()
const {
return m_maxCount;}
177 const shared_ptr<XBoolNode> &displayMajorGrid()
const {
return m_displayMajorGrid;}
178 const shared_ptr<XBoolNode> &displayMinorGrid()
const {
return m_displayMinorGrid;}
179 const shared_ptr<XBoolNode> &drawLines()
const {
return m_drawLines;}
180 const shared_ptr<XBoolNode> &drawBars()
const {
return m_drawBars;}
181 const shared_ptr<XBoolNode> &drawPoints()
const {
return m_drawPoints;}
182 const shared_ptr<XBoolNode> &colorPlot()
const {
return m_colorPlot;}
183 const shared_ptr<XHexNode> &majorGridColor()
const {
return m_majorGridColor;}
184 const shared_ptr<XHexNode> &minorGridColor()
const {
return m_minorGridColor;}
185 const shared_ptr<XHexNode> &pointColor()
const {
return m_pointColor;}
186 const shared_ptr<XHexNode> &lineColor()
const {
return m_lineColor;}
187 const shared_ptr<XHexNode> &barColor()
const {
return m_barColor;}
188 const shared_ptr<XHexNode> &colorPlotColorHigh()
const {
return m_colorPlotColorHigh;}
189 const shared_ptr<XHexNode> &colorPlotColorLow()
const {
return m_colorPlotColorLow;}
190 const shared_ptr<XTouchableNode> &clearPoints()
const {
return m_clearPoints;}
191 const shared_ptr<XItemNode<XAxisList, XAxis> > &axisX()
const {
return m_axisX;}
192 const shared_ptr<XItemNode<XAxisList, XAxis> > &axisY()
const {
return m_axisY;}
193 const shared_ptr<XItemNode<XAxisList, XAxis> > &axisZ()
const {
return m_axisZ;}
194 const shared_ptr<XItemNode<XAxisList, XAxis> > &axisW()
const {
return m_axisW;}
196 const shared_ptr<XDoubleNode> &
zwoAxisZ()
const {
return m_zwoAxisZ;}
197 const shared_ptr<XDoubleNode> &intensity()
const {
return m_intensity;}
200 virtual int validateAutoScale(
const Snapshot &shot);
209 virtual void snapshot(
const Snapshot &shot) = 0;
221 const weak_ptr<XGraph> m_graph;
222 shared_ptr<XAxis> m_curAxisX, m_curAxisY, m_curAxisZ, m_curAxisW;
226 std::vector<XGraph::ValPoint> m_ptsSnapped;
233 const shared_ptr<XStringNode> m_label;
235 const shared_ptr<XUIntNode> m_maxCount;
236 const shared_ptr<XBoolNode> m_displayMajorGrid;
237 const shared_ptr<XBoolNode> m_displayMinorGrid;
238 const shared_ptr<XBoolNode> m_drawLines;
239 const shared_ptr<XBoolNode> m_drawBars;
240 const shared_ptr<XBoolNode> m_drawPoints;
241 const shared_ptr<XBoolNode> m_colorPlot;
242 const shared_ptr<XHexNode> m_majorGridColor;
243 const shared_ptr<XHexNode> m_minorGridColor;
244 const shared_ptr<XHexNode> m_pointColor;
245 const shared_ptr<XHexNode> m_lineColor;
246 const shared_ptr<XHexNode> m_barColor;
247 const shared_ptr<XHexNode> m_colorPlotColorHigh;
248 const shared_ptr<XHexNode> m_colorPlotColorLow;
249 const shared_ptr<XTouchableNode> m_clearPoints;
250 const shared_ptr<XItemNode<XAxisList, XAxis> > m_axisX;
251 const shared_ptr<XItemNode<XAxisList, XAxis> > m_axisY;
252 const shared_ptr<XItemNode<XAxisList, XAxis> > m_axisZ;
253 const shared_ptr<XItemNode<XAxisList, XAxis> > m_axisW;
256 const shared_ptr<XDoubleNode> m_intensity;
258 shared_ptr<XListener> m_lsnClearPoints;
264 bool blendcolor,
unsigned int *color1,
unsigned int *color2,
float *alpha1,
float *alpha2);
268 XQGraphPainter *painter, shared_ptr<XAxis> &axis1, shared_ptr<XAxis> &axis2);
270 std::vector<tCanvasPoint> m_canvasPtsSnapped;
273 inline unsigned int blendColor(
unsigned int c1,
unsigned int c2,
float t);
278 enum AxisDirection {DirAxisX, DirAxisY, DirAxisZ, AxisWeight};
279 enum Tic {MajorTic, MinorTic, NoTics};
281 XAxis(
const char *name,
bool runtime,
282 AxisDirection dir,
bool rightOrTop,
Transaction &tr_graph,
const shared_ptr<XGraph> &graph);
289 XGraph::GFloat valToAxis(XGraph::VFloat value);
293 XGraph::VFloat axisToVal(XGraph::GFloat pos, XGraph::GFloat axis_prec = -1);
302 XString valToString(XGraph::VFloat val);
304 const shared_ptr<XStringNode> &label()
const {
return m_label;}
306 const shared_ptr<XDoubleNode> &x()
const {
return m_x;}
307 const shared_ptr<XDoubleNode> &y()
const {
return m_y;}
308 const shared_ptr<XDoubleNode> &z()
const {
return m_z;}
309 const shared_ptr<XDoubleNode> &length()
const {
return m_length;}
310 const shared_ptr<XDoubleNode> &majorTicScale()
const {
return m_majorTicScale;}
311 const shared_ptr<XDoubleNode> &minorTicScale()
const {
return m_minorTicScale;}
312 const shared_ptr<XBoolNode> &displayMajorTics()
const {
return m_displayMajorTics;}
313 const shared_ptr<XBoolNode> &displayMinorTics()
const {
return m_displayMinorTics;}
314 const shared_ptr<XDoubleNode> &maxValue()
const {
return m_max;}
315 const shared_ptr<XDoubleNode> &minValue()
const {
return m_min;}
316 const shared_ptr<XBoolNode> &rightOrTopSided()
const {
return m_rightOrTopSided;}
318 const shared_ptr<XStringNode> &ticLabelFormat()
const {
return m_ticLabelFormat;}
319 const shared_ptr<XBoolNode> &displayLabel()
const {
return m_displayLabel;}
320 const shared_ptr<XBoolNode> &displayTicLabels()
const {
return m_displayTicLabels;}
321 const shared_ptr<XHexNode> &ticColor()
const {
return m_ticColor;}
322 const shared_ptr<XHexNode> &labelColor()
const {
return m_labelColor;}
323 const shared_ptr<XHexNode> &ticLabelColor()
const {
return m_ticLabelColor;}
324 const shared_ptr<XBoolNode> &autoFreq()
const {
return m_autoFreq;}
325 const shared_ptr<XBoolNode> &autoScale()
const {
return m_autoScale;}
326 const shared_ptr<XBoolNode> &logScale()
const {
return m_logScale;}
328 void zoom(
bool minchange,
bool maxchange, XGraph::GFloat zoomscale,
329 XGraph::GFloat center = 0.5);
332 Tic queryTic(
int length,
int pos, XGraph::VFloat *ticnum);
335 void startAutoscale(
const Snapshot &shot,
float resolution,
bool clearscale =
false);
337 void fixScale(
Transaction &tr,
float resolution,
bool suppressupdate =
false);
339 XGraph::VFloat
fixedMin()
const {
return m_minFixed;}
340 XGraph::VFloat fixedMax()
const {
return m_maxFixed;}
342 inline bool isIncluded(XGraph::VFloat x);
343 inline void tryInclude(XGraph::VFloat x);
345 const AxisDirection &direction()
const {
return m_direction;}
353 AxisDirection m_direction;
356 const weak_ptr<XGraph> m_graph;
358 void startAutoscale_(
const Snapshot &shot,
bool clearscale);
360 void performAutoFreq(
const Snapshot &shot,
float resolution);
362 const shared_ptr<XStringNode> m_label;
364 const shared_ptr<XDoubleNode> m_x;
365 const shared_ptr<XDoubleNode> m_y;
366 const shared_ptr<XDoubleNode> m_z;
367 const shared_ptr<XDoubleNode> m_length;
368 const shared_ptr<XDoubleNode> m_majorTicScale;
369 const shared_ptr<XDoubleNode> m_minorTicScale;
370 const shared_ptr<XBoolNode> m_displayMajorTics;
371 const shared_ptr<XBoolNode> m_displayMinorTics;
372 const shared_ptr<XDoubleNode> m_max;
373 const shared_ptr<XDoubleNode> m_min;
374 const shared_ptr<XBoolNode> m_rightOrTopSided;
376 const shared_ptr<XStringNode> m_ticLabelFormat;
377 const shared_ptr<XBoolNode> m_displayLabel;
378 const shared_ptr<XBoolNode> m_displayTicLabels;
379 const shared_ptr<XHexNode> m_ticColor;
380 const shared_ptr<XHexNode> m_labelColor;
381 const shared_ptr<XHexNode> m_ticLabelColor;
382 const shared_ptr<XBoolNode> m_autoFreq;
383 const shared_ptr<XBoolNode> m_autoScale;
384 const shared_ptr<XBoolNode> m_logScale;
386 XGraph::VFloat m_minFixed, m_maxFixed;
387 XGraph::VFloat m_majorFixed, m_minorFixed;
388 XGraph::VFloat m_invLogMaxOverMinFixed, m_invMaxMinusMinFixed;
389 bool m_bLogscaleFixed;
390 bool m_bAutoscaleFixed;
395 XXYPlot(
const char *name,
bool runtime,
Transaction &tr_graph,
const shared_ptr<XGraph> &graph) :
396 XPlot(name, runtime, tr_graph, graph) {}
401 XGraph::VFloat x, XGraph::VFloat y, XGraph::VFloat z = 0.0, XGraph::VFloat weight = 1.0);
405 std::vector<XGraph::ValPoint> &points() {
return m_points;}
406 const std::vector<XGraph::ValPoint> &points()
const {
return m_points;}
407 unsigned int m_startPos;
409 std::vector<XGraph::ValPoint> m_points;
418 XFuncPlot(
const char *name,
bool runtime,
Transaction &tr_graph,
const shared_ptr<XGraph> &graph);
422 virtual double func(
double x)
const = 0;