void Spectrogram::updateLabels(QPainter *p, const QwtScaleMap &, const QwtScaleMap &, const QwtRasterData::ContourLines &contourLines) const { QwtValueList levels = contourLevels(); const int numLevels = levels.size(); int x_axis = xAxis(); int y_axis = yAxis(); for (int l = 0; l < numLevels; l++){ const double level = levels[l]; const QPolygonF &lines = contourLines[level]; if (lines.isEmpty()) continue; PlotMarker *mrk = d_labels_list[l]; if (!mrk) return; QSize size = mrk->label().textSize(); int dx = int((d_labels_x_offset + mrk->xLabelOffset())*0.01*size.height()); int dy = -int(((d_labels_y_offset + mrk->yLabelOffset())*0.01 + 0.5)*size.height()); int i = (int)lines.size()/2; double x = lines[i].x(); double y = lines[i].y(); int x2 = d_graph->transform(x_axis, x) + dx; int y2 = d_graph->transform(y_axis, y) + dy; if (p->device()->logicalDpiX() == plot()->logicalDpiX() || p->device()->logicalDpiY() == plot()->logicalDpiY()) mrk->setValue(d_graph->invTransform(x_axis, x2), d_graph->invTransform(y_axis, y2)); } }
void Spectrogram::drawContourLines (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtRasterData::ContourLines &contourLines) const { //QwtPlotSpectrogram::drawContourLines(p, xMap, yMap, contourLines); QwtValueList levels = contourLevels(); const int numLevels = (int)levels.size(); for (int l = 0; l < numLevels; l++){ const double level = levels[l]; QPen pen = defaultContourPen(); if ( pen.style() == Qt::NoPen ) pen = contourPen(level); if ( pen.style() == Qt::NoPen ) continue; p->setPen(QwtPainter::scaledPen(pen)); const QPolygonF &lines = contourLines[level]; for ( int i = 0; i < (int)lines.size(); i += 2 ){ const QPointF p1( xMap.xTransform(lines[i].x()), yMap.transform(lines[i].y()) ); const QPointF p2( xMap.xTransform(lines[i + 1].x()), yMap.transform(lines[i + 1].y()) ); p->drawLine(p1, p2); } } if (d_show_labels) updateLabels(p, xMap, yMap, contourLines); }
void Spectrogram::createLabels() { clearLabels(); QwtValueList levels = contourLevels(); const int numLevels = levels.size(); for (int l = 0; l < numLevels; l++){ PlotMarker *m = new PlotMarker(l, d_labels_angle); QwtText t = QwtText(QString::number(levels[l])); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); if (d_graph && d_show_labels) m->attach(d_graph); d_labels_list << m; } }
Spectrogram* Spectrogram::copy(Graph *g) { Spectrogram *new_s = new Spectrogram(g, matrix()); new_s->setDisplayMode(QwtPlotSpectrogram::ImageMode, testDisplayMode(QwtPlotSpectrogram::ImageMode)); new_s->setDisplayMode(QwtPlotSpectrogram::ContourMode, testDisplayMode(QwtPlotSpectrogram::ContourMode)); new_s->setCustomColorMap(color_map); new_s->setAxis(xAxis(), yAxis()); new_s->setDefaultContourPen(defaultContourPen()); new_s->color_map_policy = color_map_policy; new_s->d_show_labels = d_show_labels; new_s->d_labels_angle = d_labels_angle; new_s->d_labels_color = d_labels_color; new_s->d_white_out_labels = d_white_out_labels; new_s->d_labels_font = d_labels_font; new_s->d_labels_x_offset = d_labels_x_offset; new_s->d_labels_y_offset = d_labels_y_offset; new_s->setContourLevels(contourLevels()); if (defaultContourPen().style() == Qt::NoPen && !d_color_map_pen) new_s->setContourPenList(d_pen_list); else new_s->d_color_map_pen = d_color_map_pen; QList <PlotMarker *> lst = new_s->labelsList(); int count = lst.size(); for(int i = 0; i < count; i++){ PlotMarker *m = lst[i]; PlotMarker *mrk = d_labels_list[i]; if (m && mrk) m->setLabelOffset(mrk->xLabelOffset(), mrk->yLabelOffset()); } return new_s; }
void scribe3D (nvMapGL *map, OPTIONS *options, MISC *misc, NV_FLOAT32 *ar, NV_INT32 ncc, NV_INT32 nrr, NV_FLOAT64 xorig, NV_FLOAT64 yorig) { NV_INT32 index_contour, num_points, i, num_interp, bytes, width; NV_FLOAT64 dcontour_x[CONTOUR_POINTS], dcontour_y[CONTOUR_POINTS], dcontour_z[CONTOUR_POINTS], dx, dy, cell_diag_length, segment_length; NV_FLOAT32 level, half_gridx, half_gridy, *contour_x, *contour_y, x[2], y[2], z[2], *xyz_x, *xyz_y, *xyz_z; void contourMinMax (NV_FLOAT32, NV_FLOAT32); void contourEmphasis (NV_INT32); void contourMaxDensity (NV_INT32); void contourMaxPoints (NV_INT32); void contourLevels (NV_INT32 numLevels, NV_FLOAT32 *); NV_INT32 initContour (NV_FLOAT32, NV_INT32, NV_INT32, NV_FLOAT32 *); NV_INT32 getContour (NV_FLOAT32 *, NV_INT32 *, NV_INT32 *, NV_FLOAT32 *, NV_FLOAT32 *); // Check the smoothing factor range and get the number of interpolation // points per unsmoothed contour segment if (options->smoothing_factor < 0) options->smoothing_factor = 0; if (options->smoothing_factor > 10) options->smoothing_factor = 10; dcontour_x[0] = xorig + (misc->x_grid_size * ncc) * 0.5; dcontour_y[0] = yorig + (misc->y_grid_size * nrr) * 0.5; dcontour_x[1] = dcontour_x[0] + misc->x_grid_size; dcontour_y[1] = dcontour_y[0] + misc->y_grid_size; map->map_to_screen (2, dcontour_x, dcontour_y, dcontour_z, x, y, z); dx = x[1] - x[0]; dy = y[1] - y[0]; cell_diag_length = sqrt (pow (dx, 2) + pow (dy, 2)); segment_length = DEFAULT_SEGMENT_LENGTH / options->smoothing_factor; if (cell_diag_length > segment_length) { num_interp = (NV_INT32) ((cell_diag_length / segment_length) + 0.5); } else { num_interp = 1; } /* allocate memory for contour arrays */ if (options->smoothing_factor > 0) { bytes = (((num_interp * (CONTOUR_POINTS - 1)) + 1) * sizeof (NV_FLOAT64)); } else { bytes = (CONTOUR_POINTS * sizeof (NV_FLOAT64)); } contour_x = (NV_FLOAT32 *) malloc (bytes / 2); contour_y = (NV_FLOAT32 *) malloc (bytes / 2); xyz_x = (NV_FLOAT32 *) malloc (bytes); xyz_y = (NV_FLOAT32 *) malloc (bytes); if ((xyz_z = (NV_FLOAT32 *) malloc (bytes)) == NULL) { perror (__FILE__); exit (-1); } // Set the min and max contours, the index contour interval, the // maximum contour density, and the number of points to be returned // by the package. contourMinMax (misc->min_z * options->z_factor + options->z_offset, misc->max_z * options->z_factor + options->z_offset); contourMaxDensity (misc->maxd); contourMaxPoints (CONTOUR_POINTS); // If the contour interval is set to 0.0 use the user defined levels. if (misc->abe_share->cint == 0.0) contourLevels (misc->abe_share->num_levels, misc->abe_share->contour_levels); // Pass the grid array (arranged 1D) to the contouring package. initContour (misc->abe_share->cint, nrr, ncc, ar); // Compute half of a grid cell in degrees. half_gridx = misc->x_grid_size * 0.5; half_gridy = misc->y_grid_size * 0.5; // Get the contours from the package until all are drawn. while (getContour (&level, &index_contour, &num_points, contour_x, contour_y)) { // Convert from grid points (returned contours) to position. for (i = 0 ; i < num_points ; i++) { dcontour_x[i] = xorig + (contour_x[i] * misc->x_grid_size) + half_gridx; dcontour_y[i] = yorig + (contour_y[i] * misc->y_grid_size) + half_gridy; dcontour_z[i] = -level; } // Convert from position to pixels. map->map_to_screen (num_points, dcontour_x, dcontour_y, dcontour_z, xyz_x, xyz_y, xyz_z); // smooth out the contour (don't do this sooner for the sake of efficiency -- smooth in xy plot space) if (options->smoothing_factor > 0) smooth_contour (num_interp, &num_points, xyz_x, xyz_y); // If this is the zero contour, thicken the line. width = options->contour_width; if (level == 0.0) { switch (width) { case 1: width = 3; break; case 2: width = 4; break; case 3: width = 5; break; } } // Draw the contours. for (i = 0 ; i < num_points ; i++) map->setLines (xyz_x[i], xyz_y[i], xyz_z[i], options->contour_color, width, Qt::SolidLine, i, NVFalse); // Check the event queue to see if the user wants to interrupt the contouring. if (qApp->hasPendingEvents ()) { qApp->processEvents (); if (misc->drawing_canceled) break; } } free (contour_x); free (contour_y); free (xyz_x); free (xyz_y); free (xyz_z); map->setLines (0.0, 0.0, 0.0, Qt::black, 1, Qt::SolidLine, 0, NVTrue); map->flush (); }
QString Spectrogram::saveToString() { QString s = "<spectrogram>\n"; s += "\t<matrix>" + QString(d_matrix->objectName()) + "</matrix>\n"; s += "\t<useMatrixFormula>" + QString::number(d_use_matrix_formula) + "</useMatrixFormula>\n"; s += "\t<xAxis>" + QString::number(xAxis()) + "</xAxis>\n"; s += "\t<yAxis>" + QString::number(yAxis()) + "</yAxis>\n"; if (color_map_policy != Custom) s += "\t<ColorPolicy>" + QString::number(color_map_policy) + "</ColorPolicy>\n"; else s += ColorMapEditor::saveToXmlString(color_map); s += "\t<Image>"+QString::number(testDisplayMode(QwtPlotSpectrogram::ImageMode))+"</Image>\n"; bool contourLines = testDisplayMode(QwtPlotSpectrogram::ContourMode); s += "\t<ContourLines>"+QString::number(contourLines)+"</ContourLines>\n"; if (contourLines){ QwtValueList levels = contourLevels(); s += "\t\t<Levels>" + QString::number(levels.size()) + "</Levels>\n"; for (int i = 0; i < levels.size(); i++) s += "\t\t<z>" + QString::number(levels[i]) + "</z>\n"; bool defaultPen = defaultContourPen().style() != Qt::NoPen; s += "\t\t<DefaultPen>" + QString::number(defaultPen) + "</DefaultPen>\n"; if (defaultPen){ s += "\t\t\t<PenColor>" + defaultContourPen().color().name() + "</PenColor>\n"; s += "\t\t\t<PenWidth>" + QString::number(defaultContourPen().widthF()) + "</PenWidth>\n"; s += "\t\t\t<PenStyle>" + QString::number(defaultContourPen().style() - 1) + "</PenStyle>\n"; } else if (!d_color_map_pen && !d_pen_list.isEmpty()){ s += "\t\t<PenList>\n"; for (int i = 0; i < d_pen_list.size(); i++){ QPen pen = d_pen_list[i]; s += "\t\t\t<pen>" + pen.color().name () + "," + QString::number(pen.widthF()) + ","; s += QString::number(PenStyleBox::styleIndex(pen.style())) + "</pen>\n"; } s += "\t\t</PenList>\n"; } if (d_show_labels){ s += "\t\t<Labels>\n"; s += "\t\t\t<Color>" + d_labels_color.name() + "</Color>\n"; s += "\t\t\t<WhiteOut>" + QString::number(d_white_out_labels) +"</WhiteOut>\n"; s += "\t\t\t<Angle>" + QString::number(d_labels_angle) + "</Angle>\n"; s += "\t\t\t<xOffset>" + QString::number(d_labels_x_offset) + "</xOffset>\n"; s += "\t\t\t<yOffset>" + QString::number(d_labels_y_offset) + "</yOffset>\n"; s += "\t\t\t<Font>" + d_labels_font.toString() + "</Font>\n"; foreach(PlotMarker *m, d_labels_list){ if (m->xLabelOffset() != 0.0 || m->xLabelOffset() != 0.0){ s += "\t\t\t<offset>" + QString::number(m->index()) + ","; s += QString::number(m->xLabelOffset()) + ","; s += QString::number(m->yLabelOffset()) + "</offset>\n"; } } s += "\t\t</Labels>\n"; } } QwtScaleWidget *colorAxis = d_graph->axisWidget(color_axis); if (colorAxis && colorAxis->isColorBarEnabled()){ s += "\t<ColorBar>\n\t\t<axis>" + QString::number(color_axis) + "</axis>\n"; s += "\t\t<width>" + QString::number(colorAxis->colorBarWidth()) + "</width>\n"; s += "\t</ColorBar>\n"; } s += "\t<Visible>"+ QString::number(isVisible()) + "</Visible>\n"; return s+"</spectrogram>\n"; }