Skip to content

Commit

Permalink
do not re-draw everything when plotting marks
Browse files Browse the repository at this point in the history
  • Loading branch information
by408 committed Nov 12, 2023
1 parent d227e3d commit 6ec4686
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
58 changes: 44 additions & 14 deletions gui/polyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,27 +633,32 @@ void polyView::displayData(QPainter *paint) {
// This draws the polygon being created if in that mode
drawPolyBeingPlotted(m_currPolyX, m_currPolyY, paint);

// Draw the marks if there
if (m_markX.size() > 0) {
for (unsigned i = 0; i < m_markX.size(); i++){
int x0, y0;
worldToPixelCoords(m_markX[i], m_markY[i], // inputs
x0, y0 ); // outputs
drawMark(x0, y0, QColor(m_prefs.fgColor.c_str()),
m_prefs.lineWidth, paint);
}
}

// If in diff mode
plotDistBwPolyClips(paint);

// Draw the marks if there
drawMarks(paint);

// Wipe this temporary data now that the display changed
m_snappedPoints.clear();
m_nonSnappedPoints.clear();

return;
}

void polyView::drawMarks(QPainter *paint){
// Draw the marks if there
if (m_markX.size() > 0) {
for (unsigned i = 0; i < m_markX.size(); i++){
int x0, y0;
worldToPixelCoords(m_markX[i], m_markY[i], // inputs
x0, y0 ); // outputs
drawMark(x0, y0, QColor(m_prefs.fgColor.c_str()),
m_prefs.lineWidth, paint);
}
}
}

// Plot a given dPoly with given options.
// The viewing window in world coordinates corresponding to current
// drawing region on screen is:
Expand Down Expand Up @@ -2475,8 +2480,9 @@ void polyView::getOnePointShape(int x0, int y0,
void polyView::drawMark(int x0, int y0, QColor color, int lineWidth,
QPainter * paint) {

int len = 6;
int len = 8;

lineWidth = std::max(lineWidth, 2);
paint->setBrush(Qt::NoBrush);
paint->setPen(QPen(color, lineWidth));

Expand Down Expand Up @@ -2954,6 +2960,7 @@ void polyView::addAnno() {
}

void polyView::markAcute() {
bool need_to_refresh = m_markX.size() > 0;
m_markX.clear();
m_markY.clear();

Expand All @@ -2964,7 +2971,20 @@ void polyView::markAcute() {
m_markY.push_back(pt.y);
}
}
refreshPixmap();

if (m_markX.empty()){
cout <<"No acute angles"<<endl;
return;
}

if (need_to_refresh){
refreshPixmap();
} else {
QPainter paint(&m_pixmap);

drawMarks(&paint);
update();
}

}

Expand Down Expand Up @@ -3091,10 +3111,20 @@ void polyView::saveMark() {
}

void polyView::plotMark(double x, double y) {
bool need_to_refresh = m_markX.size() > 0;
cout << "mark " << x << ' ' << y << endl;
m_markX.resize(1); m_markX[0] = x;
m_markY.resize(1); m_markY[0] = y;
refreshPixmap();

if (need_to_refresh){
refreshPixmap();
} else {
QPainter paint(&m_pixmap);

drawMarks(&paint);
update();
}

return;
}

Expand Down
2 changes: 2 additions & 0 deletions gui/polyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public slots:
bool hasSelectedPolygons() const;

void displayData( QPainter *paint );
void drawMarks(QPainter *paint);

void plotDPoly(bool plotPoints, bool plotEdges,
bool plotFilled, bool showAnno,
bool scatter_annotation,
Expand Down

0 comments on commit 6ec4686

Please sign in to comment.