bugfixed optimized line-drawing

This commit is contained in:
jkriege2 2022-08-25 22:32:34 +02:00
parent c3afee2c1f
commit 064f01d0b0
3 changed files with 25 additions and 6 deletions

View File

@ -446,7 +446,7 @@ QList<QPolygonF > JKQTPClipPolyLines(const QList<QPolygonF > &polylines_in, cons
} else if (l==lclipped) { } else if (l==lclipped) {
if (out.last().size()==0) { if (out.last().size()==0) {
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} if (out.last().last()!=lclipped.p1()) { } else if (out.last().last()!=lclipped.p1()) {
out<<QPolygonF(); out<<QPolygonF();
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} }
@ -454,7 +454,7 @@ QList<QPolygonF > JKQTPClipPolyLines(const QList<QPolygonF > &polylines_in, cons
} else if (l.p1()==lclipped.p1() && l.p2()!=lclipped.p2()) { } else if (l.p1()==lclipped.p1() && l.p2()!=lclipped.p2()) {
if (out.last().size()==0) { if (out.last().size()==0) {
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} if (out.last().last()!=lclipped.p1()) { } else if (out.last().last()!=lclipped.p1()) {
out<<QPolygonF(); out<<QPolygonF();
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} }
@ -463,7 +463,7 @@ QList<QPolygonF > JKQTPClipPolyLines(const QList<QPolygonF > &polylines_in, cons
} else if (l.p1()!=lclipped.p1() && l.p2()==lclipped.p2()) { } else if (l.p1()!=lclipped.p1() && l.p2()==lclipped.p2()) {
if (out.last().size()==0) { if (out.last().size()==0) {
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} if (out.last().last()!=lclipped.p1()) { } else if (out.last().last()!=lclipped.p1()) {
out<<QPolygonF(); out<<QPolygonF();
out.last()<<lclipped.p1(); out.last()<<lclipped.p1();
} }
@ -481,3 +481,12 @@ QList<QPolygonF > JKQTPClipPolyLines(const QList<QPolygonF > &polylines_in, cons
} }
return out; return out;
} }
QList<QPolygonF> JKQTPSimplifyPolyLines(const QList<QPolygonF> &lines_in, double maxDeltaXY)
{
QList<QPolygonF> l;
for (const QPolygonF& p: lines_in) {
l<<JKQTPSimplifyPolyLines(p, maxDeltaXY);
}
return l;
}

View File

@ -400,6 +400,15 @@ JKQTCOMMON_LIB_EXPORT QList<QPolygonF> JKQTPClipPolyLines(const QList<QPolygonF>
*/ */
JKQTCOMMON_LIB_EXPORT QList<QPolygonF> JKQTPClipPolyLine(const QPolygonF & polyline_in, const QRectF& clipRect); JKQTCOMMON_LIB_EXPORT QList<QPolygonF> JKQTPClipPolyLine(const QPolygonF & polyline_in, const QRectF& clipRect);
/*! \brief tries to reduce the complexity of the given list of poly-lines \a lines_in, but keeping the appearance as if all lines were drawn
\ingroup jkqtptools_drawing
\param lines_in list of poly-lines to be simplified
\param maxDeltaXY a group has to be either less wide or less high than this, typically equals the linewidth of the poly-line
\return a simplified version of lines_in
*/
JKQTCOMMON_LIB_EXPORT QList<QPolygonF> JKQTPSimplifyPolyLines(const QList<QPolygonF>& lines_in, double maxDeltaXY=1.0);
/*! \brief tries to reduce the complexity of the given poly-line \a lines_in, but keeping the appearance as if all lines were drawn /*! \brief tries to reduce the complexity of the given poly-line \a lines_in, but keeping the appearance as if all lines were drawn
\ingroup jkqtptools_drawing \ingroup jkqtptools_drawing

View File

@ -124,11 +124,12 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
if (drawLine) { if (drawLine) {
//qDebug()<<"JKQTPXYLineGraph::draw(): vec_linesP.size()=="<<vec_linesP.size(); //qDebug()<<"JKQTPXYLineGraph::draw(): vec_linesP.size()=="<<vec_linesP.size();
const QList<QPolygonF> linesToDraw=JKQTPClipPolyLines(vec_linesP, cliprect); QList<QPolygonF> linesToDraw;
if (getUseNonvisibleLineCompression()) linesToDraw=JKQTPClipPolyLines(JKQTPSimplifyPolyLines(vec_linesP, p.widthF()*getNonvisibleLineCompressionAgressiveness()), cliprect);
else linesToDraw=JKQTPClipPolyLines(vec_linesP, cliprect);
//qDebug()<<"JKQTPXYLineGraph::draw(): linesToDraw.size()=="<<linesToDraw.size()<<", clip: x="<<xmin<<".."<<xmax<<", y="<<ymin<<".."<<ymax; //qDebug()<<"JKQTPXYLineGraph::draw(): linesToDraw.size()=="<<linesToDraw.size()<<", clip: x="<<xmin<<".."<<xmax<<", y="<<ymin<<".."<<ymax;
for (const auto &linesPFromV : linesToDraw) { for (const auto &linesP : linesToDraw) {
//qDebug()<<"JKQTPXYLineGraph::draw(): linesPFromV.size()=="<<linesPFromV.size()<<" useNonvisibleLineCompression="<<getUseNonvisibleLineCompression(); //qDebug()<<"JKQTPXYLineGraph::draw(): linesPFromV.size()=="<<linesPFromV.size()<<" useNonvisibleLineCompression="<<getUseNonvisibleLineCompression();
const QPolygonF linesP=getUseNonvisibleLineCompression()?QPolygonF(JKQTPSimplifyPolyLines(linesPFromV, p.widthF()*getNonvisibleLineCompressionAgressiveness())):QPolygonF(linesPFromV);
//qDebug()<<"JKQTPXYLineGraph::draw(): --> linesP.size()=="<<linesP.size(); //qDebug()<<"JKQTPXYLineGraph::draw(): --> linesP.size()=="<<linesP.size();
if (linesP.size()>0) { if (linesP.size()>0) {
if (isHighlighted()) { if (isHighlighted()) {