diff --git a/uppsrc/ScatterDraw/DataSource.cpp b/uppsrc/ScatterDraw/DataSource.cpp index 717df5076..4d7820180 100644 --- a/uppsrc/ScatterDraw/DataSource.cpp +++ b/uppsrc/ScatterDraw/DataSource.cpp @@ -241,6 +241,24 @@ Vector DataSource::Cumulative(Getdatafun getdataY, Getdatafun getdataX) return ret; } +Vector DataSource::CumulativeAverage(Getdatafun getdataY, Getdatafun getdataX) { + Vector ret; + + double acum = 0; + int num = 0; + for (int i = 0; i < GetCount(); ++i) { + double y = Membercall(getdataY)(i); + double x = Membercall(getdataX)(i); + + if (IsNull(x) || IsNull(y)) + continue; + acum += y; + num++; + ret << Pointf(x, acum/num); + } + return ret; +} + Vector DataSource::MovingAverage(Getdatafun getdataY, Getdatafun getdataX, double width) { Vector ret; double width_2 = width/2.; @@ -677,26 +695,6 @@ bool DataSource::SameX(DataSource &data) { return true; } -// | | | -// y2--z12------z22- -// | | | -// y---|---o | -// | | | | -// | | | | -// y1--z11-+----z21- -// | | | | -// ----x1--x----x2-- -// -// y11 = y(x1, y1) y12 = y(x1, y2) y21 = y(x2, y1) y22 = y(x2, y2) -double BilinearInterpolate(double x, double y, double x1, double x2, double y1, double y2, - double z11, double z12, double z21, double z22) { - double x_x1 = x - x1; - double x2_x = x2 - x; - double y_y1 = y - y1; - double y2_y = y2 - y; - return (z11*x2_x*y2_y + z21*x_x1*y2_y + z12*x2_x*y_y1 + z22*x_x1*y_y1)/(x2 - x1)/(y2 - y1); -} - void ExplicitData::Init(Function funz, double minX, double maxX, double minY, double maxY) { ASSERT(maxX >= minX && maxY >= minY); this->funz = funz; @@ -850,7 +848,8 @@ Pointf SegIntersection(Pointf &a, Pointf &b, Pointf &c, Pointf &d) { ((c.x <= inter.x && d.x >= inter.x) || (d.x <= inter.x && c.x >= inter.x)) && ((c.y <= inter.y && d.y >= inter.y) || (d.y <= inter.y && c.y >= inter.y))) return inter; - return Null; + else + return Null; } Vector Intersection(Vector &poly1, Vector &poly2) { diff --git a/uppsrc/ScatterDraw/DataSource.h b/uppsrc/ScatterDraw/DataSource.h index 54d483194..b8d2309c5 100644 --- a/uppsrc/ScatterDraw/DataSource.h +++ b/uppsrc/ScatterDraw/DataSource.h @@ -49,6 +49,7 @@ public: virtual Vector UpperEnvelopeY(double width) {return UpperEnvelope(&DataSource::y, &DataSource::x, width);} virtual Vector LowerEnvelopeY(double width) {return LowerEnvelope(&DataSource::y, &DataSource::x, width);} virtual Vector CumulativeY() {return Cumulative(&DataSource::y, &DataSource::x);} + virtual Vector CumulativeAverageY() {return CumulativeAverage(&DataSource::y, &DataSource::x);} virtual Vector MovingAverageY(double width) {return MovingAverage(&DataSource::y, &DataSource::x, width);} virtual Vector SectorAverageY(double width) {return SectorAverage(&DataSource::y, &DataSource::x, width);} virtual void MaxListY(Vector &id, double width){MaxList(&DataSource::y, &DataSource::x, id, width);} @@ -87,6 +88,7 @@ public: Vector UpperEnvelope(Getdatafun getdataY, Getdatafun getdataX, double width); Vector LowerEnvelope(Getdatafun getdataY, Getdatafun getdataX, double width); Vector Cumulative(Getdatafun getdataY, Getdatafun getdataX); + Vector CumulativeAverage(Getdatafun getdataY, Getdatafun getdataX); Vector MovingAverage(Getdatafun getdataY, Getdatafun getdataX, double width); Vector SectorAverage(Getdatafun getdataY, Getdatafun getdataX, double width); void MaxList(Getdatafun getdataY, Getdatafun getdataX, Vector &id, double width); @@ -652,8 +654,31 @@ private: int key; }; -double BilinearInterpolate(double x, double y, double x1, double x2, double y1, double y2, - double z11, double z12, double z21, double z22); +template +inline T LinearInterpolate(T x, T x0, T x1, T v0, T v1) { + ASSERT(x1 != x0); + return ((x1 - x)/(x1 - x0))*v0 + ((x - x0)/(x1 - x0))*v1; +} + +template +inline T BilinearInterpolate(T x, T y, T x0, T x1, T y0, T y1, T v00, T v01, T v10, T v11) { + T r0 = LinearInterpolate(x, x0, x1, v00, v10); + T r1 = LinearInterpolate(x, x0, x1, v01, v11); + + return LinearInterpolate(y, y0, y1, r0, r1); +} + +template +inline T TrilinearInterpolate(T x, T y, T z, T x0, T x1, T y0, T y1, T z0, T z1, T v000, T v001, T v010, T v011, T v100, T v101, T v110, T v111) { + T x00 = LinearInterpolate(x, x0, x1, v000, v100); + T x10 = LinearInterpolate(x, x0, x1, v010, v110); + T x01 = LinearInterpolate(x, x0, x1, v001, v101); + T x11 = LinearInterpolate(x, x0, x1, v011, v111); + T r0 = LinearInterpolate(y, y0, y1, x00, x01); + T r1 = LinearInterpolate(y, y0, y1, x10, x11); + + return LinearInterpolate(z, z0, z1, r0, r1); +} class TableInterpolate { public: @@ -777,7 +802,6 @@ private: }; - class ExplicitData : public DataSourceSurf { public: ExplicitData() {} diff --git a/uppsrc/ScatterDraw/ScatterDraw.cpp b/uppsrc/ScatterDraw/ScatterDraw.cpp index d1fc94d73..9bd685d63 100644 --- a/uppsrc/ScatterDraw/ScatterDraw.cpp +++ b/uppsrc/ScatterDraw/ScatterDraw.cpp @@ -14,6 +14,7 @@ ScatterDraw::ScatterDraw() { hPlotLeft = hPlotRight = vPlotTop = vPlotBottom = 30; xRange = yRange = yRange2 = 100.0; xMin = yMin = yMin2 = xMinUnit = yMinUnit = yMinUnit2 = 0; + xMinUnit0 = yMinUnit0 = yMinUnit20 = 0; gridColor = SColorDkShadow(); gridWidth = 0.5; gridDash = LINE_DOTTED_FINE; @@ -280,9 +281,9 @@ void ScatterDraw::AdjustMajorUnitY2() { } ScatterDraw &ScatterDraw::SetRange(double rx, double ry, double ry2) { - ASSERT(IsNull(rx) || rx > 0); - ASSERT(IsNull(ry) || ry > 0); - ASSERT(IsNull(ry2) || ry2 > 0); + ASSERT(IsNull(rx) || rx > 0); + ASSERT(IsNull(ry) || ry > 0); + ASSERT(IsNull(ry2)|| ry2 > 0); if (!IsNull(rx)) { xRange = rx; @@ -336,6 +337,7 @@ ScatterDraw &ScatterDraw::SetMajorUnitsNum(int nx, int ny) { } ScatterDraw &ScatterDraw::SetMinUnits(double ux, double uy) { + if (!IsNull(ux)) if (!IsNull(ux)) xMinUnit = xMinUnit0 = ux; if (!IsNull(uy)) { @@ -385,8 +387,12 @@ ScatterDraw &ScatterDraw::DoFitToData(bool horizontal, bool vertical, double fac for (int j = 0; j < series.GetCount(); j++) { if (series[j].opacity == 0 || series[j].PointsData()->IsExplicit()) continue; - minx = min(minx, series[j].PointsData()->MinX()); - maxx = max(maxx, series[j].PointsData()->MaxX()); + double mn = series[j].PointsData()->MinX(); + if (!IsNull(mn)) + minx = min(minx, mn); + double mx = series[j].PointsData()->MaxX(); + if (!IsNull(mx)) + maxx = max(maxx, mx); } if (minx != -DOUBLE_NULL) { double deltaX = (maxx - minx)*factor; @@ -630,6 +636,8 @@ ScatterDraw &ScatterDraw::AddSeries(DataSource &data) { ScatterSeries &s = series.Add(); s.Init(series.GetCount()-1); s.SetDataSource(&data, false); + if (sequentialXAll) + s.sequential = true; Refresh(); return *this; } diff --git a/uppsrc/ScatterDraw/ScatterDraw.h b/uppsrc/ScatterDraw/ScatterDraw.h index 81321a957..cc5bf0416 100644 --- a/uppsrc/ScatterDraw/ScatterDraw.h +++ b/uppsrc/ScatterDraw/ScatterDraw.h @@ -695,7 +695,7 @@ public: ScatterDraw &SetDataSecondaryY(bool secondary = true); bool IsDataPrimaryY(int index); - void SetSequentialX(int index, bool sequential = true); + void SetSequentialX(int index, bool sequential); ScatterDraw &SetSequentialX(bool sequential = true); ScatterDraw &SetSequentialXAll(bool sequential = true); bool GetSequentialX(int index); @@ -1405,7 +1405,7 @@ void ScatterDraw::Plot(T& w) double d1 = xRange/xMajorUnit; double d2 = yRange/yMajorUnit; - double left, top, d = min(plotW, plotH), r = d/2.; + double left, top, d = min(plotW, plotH);//, r = d/2.; if (!isPolar) { if (!surf) w.DrawRect(0, 0, plotW, plotH, plotAreaColor); @@ -1445,8 +1445,8 @@ void ScatterDraw::Plot(T& w) } w.DrawEllipse(fround(left), fround(top), fround(d), fround(d), plotAreaColor); } - double x_c = plotW/2; - double y_c = plotH/2; + //double x_c = plotW/2; + //double y_c = plotH/2; if (drawVGrid) { if (!isPolar) {