void Renderer::drawVectorDataOnGrid(QPainter& p, const Output* output) { int cellx = mCfg.ds.mVectorUserGridCellSize.width(); int celly = mCfg.ds.mVectorUserGridCellSize.height(); const Mesh::Elements& elems = mMesh->elements(); for(int i = 0; i < elems.count(); i++) { const Element& elem = elems[i]; if (elem.isDummy()) continue; // If the element's activity flag is off, ignore it if (!output->isActive(i)) continue; // If the element is outside the view of the canvas, skip it if (elemOutsideView(i)) continue; const BBox& bbox = mMesh->projectedBBox(i); // Get the BBox of the element in pixels int left, right, top, bottom; bbox2rect(bbox, left, right, top, bottom); // Align rect to the grid (e.g. interval <13, 36> with grid cell 10 will be trimmed to <20,30> if (left % cellx != 0) left += cellx - (left % cellx); if (right % cellx != 0) right -= (right % cellx); if (top % celly != 0) top += celly - (top % celly); if (bottom % celly != 0) bottom -= (bottom % celly); for (int y = top; y <= bottom; y += celly) { for (int x = left; x <= right; x += cellx) { QPointF pt = mtp.pixelToReal(x, y); double vx, vy; if (mMesh->vectorValueAt(i, pt.x(), pt.y(), &vx, &vy, output)) { // The supplied point was inside the element drawVectorArrow(p, output, QPointF(x,y), vx, vy, sqrt(vx*vx + vy*vy)); } } } } // for all elements }
void Renderer::drawVectorDataOnNodes(QPainter& p, const NodeOutput* output) { const Mesh::Nodes& nodes = mMesh->nodes(); for(int nodeIndex = 0; nodeIndex < nodes.count(); nodeIndex++) { if (!nodeInsideView(nodeIndex)) continue; float xVal = output->valuesV[nodeIndex].x; float yVal = output->valuesV[nodeIndex].y; float V = output->values[nodeIndex]; // pre-calculated magnitude QPointF lineStart = realToPixelF( nodeIndex ); drawVectorArrow(p, output, lineStart, xVal, yVal, V); } }
void Renderer::drawVectorDataOnElements(QPainter& p, const ElementOutput* output) { const Mesh::Elements& elements = mMesh->elements(); for(int elemIndex = 0; elemIndex < elements.count(); elemIndex++) { if (elemOutsideView(elemIndex)) continue; double cx, cy; mMesh->elementCentroid(elemIndex, cx, cy); float xVal = output->valuesV[elemIndex].x; float yVal = output->valuesV[elemIndex].y; float V = output->values[elemIndex]; // pre-calculated magnitude QPointF lineStart = mtp.realToPixel(cx, cy); drawVectorArrow(p, output, lineStart, xVal, yVal, V); } }
void QgsMeshVectorRenderer::drawVectorDataOnFaces() { const QVector<QgsMeshVertex> ¢roids = mTriangularMesh.centroids(); for ( int i = 0; i < centroids.count(); i++ ) { //if (elemOutsideView(elemIndex)) // continue; QgsPointXY center = centroids.at( i ); double xVal = mDatasetValuesX[i]; double yVal = mDatasetValuesY[i]; if ( nodataValue( xVal, yVal ) ) continue; double V = mDatasetValuesMag[i]; // pre-calculated magnitude QgsPointXY lineStart = mContext.mapToPixel().transform( center.x(), center.y() ); drawVectorArrow( lineStart, xVal, yVal, V ); } }
void QgsMeshVectorRenderer::drawVectorDataOnVertices() { const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices(); // currently expecting that triangulation does not add any new extra vertices on the way Q_ASSERT( mDatasetValuesMag.count() == vertices.count() ); for ( int i = 0; i < vertices.size(); ++i ) { const QgsMeshVertex &vertex = vertices.at( i ); //if (!nodeInsideView(nodeIndex)) // continue; double xVal = mDatasetValuesX[i]; double yVal = mDatasetValuesY[i]; if ( nodataValue( xVal, yVal ) ) continue; double V = mDatasetValuesMag[i]; // pre-calculated magnitude QgsPointXY lineStart = mContext.mapToPixel().transform( vertex.x(), vertex.y() ); drawVectorArrow( lineStart, xVal, yVal, V ); } }