void ossimImageDataHelper::fill(T dummyVariable, const double* values, const ossimPolygon& region, bool clipPoly) { if(clipPoly) { ossimPolyArea2d polyArea(region); ossimPolyArea2d clipArea = polyArea&thePolyImageRectangle; vector<ossimPolygon> clipList; // clipArea.getAllVisiblePolygons(clipList); clipArea.getVisiblePolygons(clipList); int i = 0; for(i = 0; i < (int)clipList.size();++i) { fill(dummyVariable, values, clipList[i]); } } else { fill(dummyVariable, values, region); } }
void ossimImageDataHelper::copyInputToThis(const T* inputBuf, const ossimPolygon& region, bool clipPoly) { if(clipPoly) { ossimPolyArea2d polyArea(region); ossimPolyArea2d clipArea = polyArea&thePolyImageRectangle; vector<ossimPolygon> clipList; // clipArea.getAllVisiblePolygons(clipList); clipArea.getVisiblePolygons(clipList); int i = 0; for(i = 0; i < (int)clipList.size();++i) { copyInputToThis(inputBuf, clipList[i]); } } else { copyInputToThis(inputBuf, region); } }
double computeOverlapPP(double *ix, double *iy, double minX, double maxX, double minY, double maxY, double pixelArea) { int npts; double area; double nx[100]; double ny[100]; double xp[4], yp[4]; /* Clip the input pixel polygon with the */ /* output pixel range */ npts = rectClip(4, ix, iy, nx, ny, minX, minY, maxX, maxY); /* If no points, it may mean that */ /* the output is completely contained */ /* in the input */ if(npts < 3) { xp[0] = minX; yp[0] = minY; xp[1] = maxX; yp[1] = minY; xp[2] = maxX; yp[2] = maxY; xp[3] = minX; yp[3] = maxY; if(ptInPoly(ix[0], iy[0], 4, xp, yp)) { area = pixelArea; return area; } return 0.; } area = polyArea(npts, nx, ny) * pixelArea; return(area); }
void MapWidget::draw(QPainter &painter) { _canvas.setPreviewMode(_isDragging || _isMeasureDragging); _canvas.setGrayScale(!isEnabled() || _forceGrayScale); _canvas.draw(painter); if ( _isMeasuring ) { painter.save(); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::red, 2)); // draw geo line QPoint p; double dist = 0.0; _canvas.projection()->project(p, _measurePoints[0]); #if QT_VERSION >= 0x040400 painter.drawEllipse(QPointF(p), 1.3f, 1.3f); #else painter.drawEllipse(QRectF(p.x()-1.3f, p.y()-1.3f, 2.6f, 2.6f)); #endif for ( int i = 1; i < _measurePoints.size(); ++i ) { _canvas.projection()->project(p, _measurePoints[i]); #if QT_VERSION >= 0x040400 painter.drawEllipse(QPointF(p), 1.3f, 1.3f); #else painter.drawEllipse(QRectF(p.x()-1.3f, p.y()-1.3f, 2.6f, 2.6f)); #endif dist += _canvas.drawGeoLine(painter, _measurePoints[i-1], _measurePoints[i]); } QString aziArea; if ( _measurePoints.size() > 2 ) { painter.save(); QPen pen = QPen(Qt::red, 1, Qt::DashLine); QVector<qreal> dashes; dashes << 3 << 7; pen.setDashPattern(dashes); painter.setPen(pen); _canvas.drawGeoLine(painter, _measurePoints.last(), _measurePoints.first()); painter.restore(); aziArea = QString("Area : %1 km²").arg(polyArea(_measurePoints)); } else { double tmp, azi1, azi2; Math::Geo::delazi(_measurePoints.first().y(), _measurePoints.first().x(), _measurePoints.last().y(), _measurePoints.last().x(), &tmp, &azi1, &azi2); aziArea = QString("AZ / BAZ: %1 ° / %2 °") .arg(azi1, 0, 'f', 1) .arg(azi2, 0, 'f', 1); } int precision = 0; if ( _canvas.projection()->zoom() > 0 ) { precision = (int) log10(_canvas.projection()->zoom()); } ++precision; QString distStr = QString("Distance: %1 km / %2 °") .arg(Math::Geo::deg2km(dist), 0, 'f', precision) .arg(dist, 0, 'f', precision + 2); QFont f = painter.font(); QFont mf = f; mf.setFamily("Monospace"); mf.setStyleHint(QFont::TypeWriter); QFontMetrics mfm(mf); QFontMetrics fm(f); int h = mfm.height() * 4 + fm.height(); int padding = fm.width(" "); QRect r = QRect(0, rect().height() - h, mfm.width(distStr) + 2*padding, h); painter.setPen(QPen(Qt::black)); painter.fillRect(r, QBrush(QColor(255, 255, 255, 140))); r.setLeft(padding); painter.setFont(mf); _measureText = QString("Start : %1 / %2\n" "End : %3 / %4\n" "%5\n" "%6") .arg(lat2String(_measurePoints.first().y(), precision)) .arg(lon2String(_measurePoints.first().x(), precision)) .arg(lat2String(_measurePoints.last().y(), precision)) .arg(lon2String(_measurePoints.last().x(), precision)) .arg(distStr) .arg(aziArea); painter.drawText(r, Qt::AlignLeft, _measureText); r.setTop(rect().height() - fm.height()); r.setRight(r.width()-padding); painter.setFont(f); painter.drawText(r, Qt::AlignRight, "(right click to copy/save)"); painter.restore(); } }
double polyArea(T &v1, T &v2, Ts &&... vertices) { return v2.X() * v1.Y() - v2.Y() * v1.X() + polyArea(v2, std::forward<Ts>(vertices)...); }
int polyTriangulate(const Vert2_list *contour, tri_out_t *cb) { /* allocate and initialize list of Vertices in polygon */ int nv, m, u, v, w, count; int *V; if ( contour->nv < 3 ) return false; V = (int *)malloc(sizeof(int)*contour->nv); if (V == NULL) return false; /* we want a counter-clockwise polygon in V */ if ( 0.0 < polyArea(contour) ) for (v=0; v<contour->nv; v++) V[v] = v; else for(v=0; v<contour->nv; v++) V[v] = (contour->nv-1)-v; nv = contour->nv; /* remove nv-2 Vertices, creating 1 triangle every time */ count = 2*nv; /* error detection */ for(m=0, v=nv-1; nv>2; ) { /* if we loop, it is probably a non-simple polygon */ if (0 >= count--) { /* Triangulate: ERROR - probable bad polygon */ return false; } /* three consecutive vertices in current polygon, <u,v,w> */ u = v ; if (nv <= u) u = 0; /* previous */ v = u+1; if (nv <= v) v = 0; /* new v */ w = v+1; if (nv <= w) w = 0; /* next */ if ( polySnip(contour,u,v,w,nv,V) ) { int a,b,c,s,t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ if (!(*cb)(contour, a, b, c)) return false; m++; /* remove v from remaining polygon */ for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--; /* reset error detection counter */ count = 2*nv; } } free(V); return true; }