version 2.1.0_beta

Graphic first LOD optimization try, now works only on setGraphicData
This commit is contained in:
2021-03-11 00:25:36 +03:00
parent b2ce43a6ef
commit b14a48da6e
5 changed files with 94 additions and 30 deletions

View File

@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(qad) project(qad)
set(qad_MAJOR 2) set(qad_MAJOR 2)
set(qad_MINOR 0) set(qad_MINOR 1)
set(qad_REVISION 0) set(qad_REVISION 0)
set(qad_SUFFIX alpha) set(qad_SUFFIX beta)
set(qad_COMPANY SHS) set(qad_COMPANY SHS)
set(qad_DOMAIN org.SHS) set(qad_DOMAIN org.SHS)

View File

@@ -117,7 +117,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
icon_pause_f = QImage(":/icons/pause-front.png"); icon_pause_f = QImage(":/icons/pause-front.png");
aupdate = grid = isFit = navigation = true; aupdate = grid = isFit = navigation = true;
aalias = bufferActive = isOGL = cancel = guides = hasLblX = hasLblY = isHover = false; aalias = bufferActive = isOGL = cancel = guides = hasLblX = hasLblY = isHover = false;
pause_ = only_expand_x = only_expand_y = false; pause_ = only_expand_x = only_expand_y = m_LODOptimization = false;
limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX); limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
eminx = eminy = DBL_MAX; eminx = eminy = DBL_MAX;
emaxx = emaxy = DBL_MIN; emaxx = emaxy = DBL_MIN;
@@ -150,6 +150,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
setButtonsPosition(Graphic::Left); setButtonsPosition(Graphic::Left);
setAntialiasing(false); setAntialiasing(false);
setCaption(""); setCaption("");
setBorderInputsVisible(false);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui->layoutButtons->update(); ui->layoutButtons->update();
updateLegend(); updateLegend();
@@ -583,6 +584,8 @@ void Graphic::clear() {
for (int i = 0; i < graphics.size(); ++i) { for (int i = 0; i < graphics.size(); ++i) {
graphics[i].polyline.clear(); graphics[i].polyline.clear();
graphics[i].polyline_pause.clear(); graphics[i].polyline_pause.clear();
graphics[i]._lod.clear();
graphics[i]._lod_pause.clear();
graphics[i].max_x = 0.; graphics[i].max_x = 0.;
graphics[i].cvrect = QRectF(); graphics[i].cvrect = QRectF();
} }
@@ -613,6 +616,8 @@ void Graphic::setPaused(bool yes) {
for (int i = 0; i < graphics.size(); ++i) { for (int i = 0; i < graphics.size(); ++i) {
graphics[i].polyline_pause = graphics[i].polyline; graphics[i].polyline_pause = graphics[i].polyline;
graphics[i].polyline_pause.detach(); graphics[i].polyline_pause.detach();
graphics[i]._lod_pause = graphics[i]._lod;
graphics[i]._lod_pause.detach();
graphics[i].max_x_pause = graphics[i].max_x; graphics[i].max_x_pause = graphics[i].max_x;
} }
timer_pause = startTimer(40); timer_pause = startTimer(40);
@@ -1183,7 +1188,8 @@ void Graphic::drawGraphics() {
ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos)))); ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos))));
QPointF srp = -selrect.topLeft(); QPointF srp = -selrect.topLeft();
double sclx, scly, wid = canvas->width(), hei = canvas->height(); double sclx, scly, wid = canvas->width(), hei = canvas->height();
sclx = (wid - gridborder.x() - margins_.left() - margins_.width()) / selrect.width(); int cwid = (wid - gridborder.x() - margins_.left() - margins_.width());
sclx = cwid / selrect.width();
scly = (hei - gridborder.y() - margins_.top() - margins_.height()) / selrect.height(); scly = (hei - gridborder.y() - margins_.top() - margins_.height()) / selrect.height();
painter->setClipping(true); painter->setClipping(true);
painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y())); painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y()));
@@ -1197,27 +1203,36 @@ void Graphic::drawGraphics() {
QPen pen; QPen pen;
for (int i = 0; i < graphics.size(); ++i) { for (int i = 0; i < graphics.size(); ++i) {
GraphicType & t(graphics[i]); GraphicType & t(graphics[i]);
QPolygonF & rpol(pause_ ? t.polyline_pause : t.polyline); QPolygonF & src_pol(pause_ ? t.polyline_pause : t.polyline);
if (t.visible && !rpol.isEmpty()) { if (!t.visible || src_pol.isEmpty()) continue;
pen = t.pen; QVector<QPolygonF> & src_lod(pause_ ? t._lod_pause : t._lod);
if (qRound(pen.widthF()) == pen.widthF()) pen.setWidth(pen.width()*thick); int lod = 0;
else pen.setWidthF(pen.widthF()*thick); if (m_LODOptimization) {
pen.setCosmetic(true); int gpcnt = src_pol.size();
if (t.lines) { qreal range = src_pol.back().x() - src_pol.front().x();
painter->setPen(pen); qreal ppp = (gpcnt * selrect.width() / qMax(range, 1.E-9) / cwid);
if (t.fill) { lod = qBound<int>(0, qFloor(log2(ppp) - 2), src_lod.size());
cpol = rpol; //qDebug() << "draw lod" << lod;
painter->setBrush(t.fill_color); }
painter->drawPolygon(mat.map(cpol)); QPolygonF & rpol(lod == 0 ? src_pol : src_lod[lod - 1]);
} else pen = t.pen;
painter->drawPolyline(mat.map(rpol)); if (qRound(pen.widthF()) == pen.widthF()) pen.setWidth(pen.width()*thick);
} else pen.setWidthF(pen.widthF()*thick);
if (t.points) { pen.setCosmetic(true);
if (qRound(t.pointWidth) == t.pointWidth) pen.setWidth(qRound(t.pointWidth*thick)); if (t.lines) {
else pen.setWidthF(t.pointWidth*thick); painter->setPen(pen);
painter->setPen(pen); if (t.fill) {
painter->drawPoints(mat.map(rpol)); cpol = rpol;
} painter->setBrush(t.fill_color);
painter->drawPolygon(mat.map(cpol));
} else
painter->drawPolyline(mat.map(rpol));
}
if (t.points) {
if (qRound(t.pointWidth) == t.pointWidth) pen.setWidth(qRound(t.pointWidth*thick));
else pen.setWidthF(t.pointWidth*thick);
painter->setPen(pen);
painter->drawPoints(mat.map(rpol));
} }
} }
painter->setWorldMatrixEnabled(true); painter->setWorldMatrixEnabled(true);
@@ -1524,6 +1539,8 @@ void Graphic::tick(int index, bool slide, bool update_) {
} }
t.polyline.pop_front(); t.polyline.pop_front();
} }
} else {
calcLOD(index);
} }
if (!update_) { if (!update_) {
if (isFit) findGraphicsRect(); if (isFit) findGraphicsRect();
@@ -1538,6 +1555,49 @@ void Graphic::tick(int index, bool slide, bool update_) {
} }
void Graphic::calcLOD(int index) {
if (!m_LODOptimization) return;
GraphicType & t(graphics[index]);
t._lod.clear();
int pcnt = t.polyline.size();
//qDebug() << "calcLOD" << index;
while (pcnt >= 10) {
QPolygonF & pl(t._lod.isEmpty() ? t.polyline : t._lod.back());
t._lod.append(QPolygonF());
QPolygonF & cl(t._lod.back());
cl << pl.front();
int qcnt = (pl.size() + 1) / 4;
pcnt = qcnt * 2 + 2;
int pc = 4;
qreal mx[2] = {0., 0.}, my[2] = {0., 0.}, my_x[2] = {0., 0.}, px, py;
for (int i = 0; i < qcnt; ++i) {
int j = i*4 + 1;
if (i == qcnt - 1) pc = pl.size() - j - 1;
mx[0] = mx[1] = my_x[0] = my_x[1] = pl[j].x(); my[0] = my[1] = pl[j].y();
for (int k = 1; k < pc; ++k) {
px = pl[j + k].x(); py = pl[j + k].y();
mx[0] = qMin(mx[0], px); mx[1] = qMax(mx[1], px);
if (my[0] > py) {
my[0] = py;
my_x[0] = px;
}
if (my[1] < py) {
my[1] = py;
my_x[1] = px;
}
}
qreal dx =(mx[1] - mx[0]) / 4., cx = (mx[1] + mx[0]) / 2.;
if (my_x[1] >= my_x[0])
cl << QPointF(cx - dx, my[0]) << QPointF(cx + dx, my[1]);
else
cl << QPointF(cx - dx, my[1]) << QPointF(cx + dx, my[0]);
}
cl << pl.back();
//qDebug() << "lod" << t._lod.size() << "->" << cl.size();
}
}
void Graphic::on_graphic_buttonAutofit_clicked() { void Graphic::on_graphic_buttonAutofit_clicked() {
isFit = true; isFit = true;
bool isEmpty = true; bool isEmpty = true;

View File

@@ -97,6 +97,7 @@ class QAD_GRAPHIC_EXPORT Graphic: public QFrame
Q_PROPERTY(bool onlyExpandY READ onlyExpandY WRITE setOnlyExpandY) Q_PROPERTY(bool onlyExpandY READ onlyExpandY WRITE setOnlyExpandY)
Q_PROPERTY(bool onlyExpandX READ onlyExpandX WRITE setOnlyExpandX) Q_PROPERTY(bool onlyExpandX READ onlyExpandX WRITE setOnlyExpandX)
Q_PROPERTY(bool gesturesNavigation READ gesturesNavigation WRITE setGesturesNavigation) Q_PROPERTY(bool gesturesNavigation READ gesturesNavigation WRITE setGesturesNavigation)
Q_PROPERTY(bool LODOptimization READ LODOptimization WRITE setLODOptimization)
Q_PROPERTY(double historySize READ historySize WRITE setHistorySize) Q_PROPERTY(double historySize READ historySize WRITE setHistorySize)
Q_PROPERTY(double maxVisibleTime READ maxVisibleTime WRITE setMaxVisibleTime) Q_PROPERTY(double maxVisibleTime READ maxVisibleTime WRITE setMaxVisibleTime)
Q_PROPERTY(double autoXIncrement READ autoXIncrement WRITE setAutoXIncrement) Q_PROPERTY(double autoXIncrement READ autoXIncrement WRITE setAutoXIncrement)
@@ -181,6 +182,7 @@ public:
bool onlyExpandY() const {return only_expand_y;} bool onlyExpandY() const {return only_expand_y;}
bool onlyExpandX() const {return only_expand_x;} bool onlyExpandX() const {return only_expand_x;}
bool gesturesNavigation() const {return gestures;} bool gesturesNavigation() const {return gestures;}
bool LODOptimization() const {return m_LODOptimization;}
bool isAutofitted() const {return isFit;} bool isAutofitted() const {return isFit;}
int currentGraphic() const {return curGraphic;} int currentGraphic() const {return curGraphic;}
int currentTraceGraphic() const {return curTrace;} int currentTraceGraphic() const {return curTrace;}
@@ -262,6 +264,7 @@ public slots:
void setSelectionPen(const QPen & pen) {selpen = pen;} void setSelectionPen(const QPen & pen) {selpen = pen;}
void setSelectionBrush(const QBrush & brush) {selbrush = brush;} void setSelectionBrush(const QBrush & brush) {selbrush = brush;}
void setNavigationEnabled(bool on) {navigation = on;} void setNavigationEnabled(bool on) {navigation = on;}
void setLODOptimization(bool yes) {m_LODOptimization = yes;}
void setOpenGL(bool on); void setOpenGL(bool on);
void setAntialiasing(bool enabled); void setAntialiasing(bool enabled);
void setAutoUpdate(bool enabled) {aupdate = enabled;} void setAutoUpdate(bool enabled) {aupdate = enabled;}
@@ -331,6 +334,7 @@ public slots:
void zoomOut() {zoom(1.2);} void zoomOut() {zoom(1.2);}
void fullscreen(); void fullscreen();
protected: protected:
virtual void changeEvent(QEvent * e); virtual void changeEvent(QEvent * e);
virtual void resizeEvent(QResizeEvent * ); virtual void resizeEvent(QResizeEvent * );
@@ -345,6 +349,7 @@ protected:
void setCurrentAction(GraphicAction action); void setCurrentAction(GraphicAction action);
void findGraphicsRect(double start_x = 0., double end_x = 0., double start_y = 0., double end_y = 0.); void findGraphicsRect(double start_x = 0., double end_x = 0., double start_y = 0., double end_y = 0.);
void tick(int index, bool slide = true, bool update = true); void tick(int index, bool slide = true, bool update = true);
void calcLOD(int index);
void repaintCanvas(bool force = false) {if (tm.elapsed() < min_repaint_int && !force) return; tm.restart(); canvas->update();} void repaintCanvas(bool force = false) {if (tm.elapsed() < min_repaint_int && !force) return; tm.restart(); canvas->update();}
void drawGraphics(); void drawGraphics();
void drawGrid(); void drawGrid();
@@ -401,7 +406,7 @@ protected:
double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10; double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10;
double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle; double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle;
int lastw, lasth, min_repaint_int, timer_pause, thick; int lastw, lasth, min_repaint_int, timer_pause, thick;
bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures; bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures, m_LODOptimization;
bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan; bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan;
protected slots: protected slots:

View File

@@ -49,7 +49,7 @@
<rect> <rect>
<x>-10</x> <x>-10</x>
<y>0</y> <y>0</y>
<width>33</width> <width>35</width>
<height>420</height> <height>420</height>
</rect> </rect>
</property> </property>
@@ -122,9 +122,6 @@
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View File

@@ -54,6 +54,8 @@ struct QAD_GRAPHIC_EXPORT GraphicType {
QString name; QString name;
QPolygonF polyline; QPolygonF polyline;
QPolygonF polyline_pause; QPolygonF polyline_pause;
QVector<QPolygonF> _lod;
QVector<QPolygonF> _lod_pause;
QPen pen; QPen pen;
QColor fill_color; QColor fill_color;
bool lines; bool lines;