void DiffHighlighter::setFormats(const QVector<QTextCharFormat> &s) { if (s.size() == Internal::NumDiffFormats) { qCopy(s.constBegin(), s.constEnd(), m_d->m_formats); // Display trailing blanks with colors swapped m_d->m_addedTrailingWhiteSpaceFormat = invertedColorFormat(m_d->m_formats[Internal::DiffInFormat]); } else { qWarning("%s: insufficient setting size: %d", Q_FUNC_INFO, s.size()); } }
/*! Assigns \a stroke to this and returns this. */ QIMPenStroke &QIMPenStroke::operator=( const QIMPenStroke &stroke ) { clear(); startPoint = stroke.startPoint; lastPoint = stroke.lastPoint; qCopy( stroke.links.begin(), stroke.links.end(), this->links.begin() ); // links = stroke.links.copy(); cheight = stroke.cheight; return *this; }
void printQueue(const BoundedQueue& q) { BoundedQueue qCopy(q); int numElements = qCopy.getSize(); int numEmpty = qCopy.getCapacity() - numElements; printf("|"); while (--numElements >= 0) { printf("%d|", qCopy.dequeue()); } while (--numEmpty >= 0) { printf(" |"); } printf("\n"); }
bool ZBTN_100_dump::Init() { for(int i = 0; i < 3; ++i) { QString fileName(m_dumpPath + QDir::separator() + QString("bank%1.bin").arg(i)); if(QFile::exists(fileName)) { QFile file(fileName); if(file.open(QIODevice::ReadOnly)) { QByteArray data(file.read(bankSize)); qCopy(data.begin(), data.end(), m_banks[i].begin()); m_banksLoaded[i] = 1; } } } if(m_banksLoaded[0]) { m_fatPresent = true; } else { QString fileName(m_dumpPath + QDir::separator() + QString("fat.bin")); if(QFile::exists(fileName)) { QFile file(fileName); if(file.open(QIODevice::ReadOnly)) { QByteArray data(file.readAll()); qCopy(data.begin(), data.end(), m_banks[0].begin()); m_fatPresent = true; } } } return true; }
//Plot the GyrZ value void MainWindow::plotGyrZ(uint8_t graph) { int x[plot_len], y[plot_len]; //Generate x index - ToDo optimize for (int i=0; i<plot_len; ++i) { x[i] = i; // x goes from 0 to 1 } //Get new datapoint from Stream: update_plot_buf_gyrz(exec1.imu.z); qCopy(plot_buf_gyrz, plot_buf_gyrz+plot_len, y); refreshPlot(x, y, plot_len, graph); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList List; List << "a" << "b" << "c"; QVector<QString> vect(3); qCopy(List.begin() + 1, List.end(), vect.begin() + 1); foreach (QString itm, vect) { qDebug() << itm; } return a.exec(); }
ExtManager::ExtManager() : Manager(7) { setShowMode(NeverShow); setShowStatistics(true); setShowDrawGamesStatistic(true); const uint RANGE[6] = { 0, 32, 40, 48, 56, 64 }; QVector<uint> s; s.resize(6); qCopy(RANGE, RANGE + 6, s.begin()); setScoreHistogram(s, ScoreBound); QList< const KgDifficultyLevel * > diffList = Kg::difficulty()->levels(); for (int i = 0; i < diffList.size(); i++) m_typeLabels << diffList.at(i)->title(); }
void Mesh::copyFrom(const MShape& shape) { // This will copy vertices. MShape::copyFrom(shape); // Cast to mesh. const Mesh* mesh = static_cast<const Mesh*>(&shape); Q_ASSERT(mesh); _nColumns = mesh->_nColumns; _nRows = mesh->_nRows; // Deep copy vertices2d. _vertices2d.resize(_nColumns); for (int i=0; i<_nColumns; i++) { _vertices2d[i].resize(_nRows); qCopy(mesh->_vertices2d[i].begin(), mesh->_vertices2d[i].end(), _vertices2d[i].begin()); } }
void MainWindow::updateCurrentFilter() { size_t index = ui->filterComboBox->currentIndex(); // Update frequency and phase response double *magnitudes = m_magnitudes[index]; double *phases = m_phases[index]; cr_filter_response(m_cornrow, index, defaultPlotSampleCount, m_frequencies, magnitudes, phases); // Update magnitude plot QVector<double> xM(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xM.begin()); QVector<double> yM(defaultPlotSampleCount); qCopy(magnitudes, magnitudes+defaultPlotSampleCount, yM.begin()); ui->magnitudePlot->graph(index)->setData(xM, yM); ui->magnitudePlot->graph(index)->setVisible(cr_filter_type(m_cornrow,index) != FilterType::None); // Update phase plot QVector<double> xP(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xP.begin()); QVector<double> yP(defaultPlotSampleCount); qCopy(phases, phases+defaultPlotSampleCount, yP.begin()); ui->phasePlot->graph(index)->setData(xP, yP); ui->phasePlot->graph(index)->setVisible(cr_filter_type(m_cornrow,index) != FilterType::None); // Update cascade frequency and phase responses double magnitudeSum[defaultPlotSampleCount]; double phaseSum[defaultPlotSampleCount]; for (int j = 0; j < defaultPlotSampleCount; ++j) { magnitudeSum[j] = m_magnitudeSumExceptCurrent[j] + m_magnitudes[index][j]; phaseSum[j] = m_phaseSumExceptCurrent[j] + m_phases[index][j]; } QVector<double> xMS(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xMS.begin()); QVector<double> yMS(defaultPlotSampleCount); qCopy(magnitudeSum, magnitudeSum+defaultPlotSampleCount, yMS.begin()); m_magnitudeSumGraph->setData(xMS, yMS); QVector<double> xPS(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xPS.begin()); QVector<double> yPS(defaultPlotSampleCount); qCopy(phaseSum, phaseSum+defaultPlotSampleCount, yPS.begin()); m_phaseSumGraph->setData(xPS, yPS); }
SynapticsTouchpad::SynapticsTouchpad(Display *display, int deviceId): XlibTouchpad(display, deviceId), m_resX(1), m_resY(1) { m_capsAtom.intern(m_connection, SYNAPTICS_PROP_CAPABILITIES); m_touchpadOffAtom.intern(m_connection, SYNAPTICS_PROP_OFF); XcbAtom resolutionAtom(m_connection, SYNAPTICS_PROP_RESOLUTION); XcbAtom edgesAtom(m_connection, SYNAPTICS_PROP_EDGES); loadSupportedProperties(synapticsProperties); m_toRadians.append("CircScrollDelta"); PropertyInfo edges(m_display, m_deviceId, edgesAtom, 0); if (edges.i && edges.nitems == 4) { int w = qAbs(edges.i[1] - edges.i[0]); int h = qAbs(edges.i[3] - edges.i[2]); m_resX = w / 90; m_resY = h / 50; qDebug() << "Width: " << w << " height: " << h; qDebug() << "Approx. resX: " << m_resX << " resY: " << m_resY; } PropertyInfo resolution(m_display, m_deviceId, resolutionAtom, 0); if (resolution.i && resolution.nitems == 2 && resolution.i[0] > 1 && resolution.i[1] > 1) { m_resY = qMin(static_cast<unsigned long>(resolution.i[0]), static_cast<unsigned long>(INT_MAX)); m_resX = qMin(static_cast<unsigned long>(resolution.i[1]), static_cast<unsigned long>(INT_MAX)); qDebug() << "Touchpad resolution: x: " << m_resX << " y: " << m_resY; } m_scaleByResX.append("HorizScrollDelta"); m_scaleByResY.append("VertScrollDelta"); m_scaleByResX.append("MaxTapMove"); m_scaleByResY.append("MaxTapMove"); m_resX = qMax(10, m_resX); m_resY = qMax(10, m_resY); qDebug() << "Final resolution x:" << m_resX << " y:" << m_resY; m_negate["HorizScrollDelta"] = "InvertHorizScroll"; m_negate["VertScrollDelta"] = "InvertVertScroll"; m_supported.append(m_negate.values()); m_supported.append("Coasting"); PropertyInfo caps(m_display, m_deviceId, m_capsAtom.atom(), 0); if (!caps.b) { return; } enum TouchpadCapabilitiy { TouchpadHasLeftButton, TouchpadHasMiddleButton, TouchpadHasRightButton, TouchpadTwoFingerDetect, TouchpadThreeFingerDetect, TouchpadPressureDetect, TouchpadPalmDetect, TouchpadCapsCount }; QVector<bool> cap(TouchpadCapsCount, false); qCopy(caps.b, caps.b + qMin(cap.size(), static_cast<int>(caps.nitems)), cap.begin()); if (!cap[TouchpadTwoFingerDetect]) { m_supported.removeAll("HorizTwoFingerScroll"); m_supported.removeAll("VertTwoFingerScroll"); m_supported.removeAll("TwoFingerTapButton"); } if (!cap[TouchpadThreeFingerDetect]) { m_supported.removeAll("ThreeFingerTapButton"); } if (!cap[TouchpadPressureDetect]) { m_supported.removeAll("FingerHigh"); m_supported.removeAll("FingerLow"); m_supported.removeAll("PalmMinZ"); m_supported.removeAll("PressureMotionMinZ"); m_supported.removeAll("PressureMotionMinFactor"); m_supported.removeAll("PressureMotionMaxZ"); m_supported.removeAll("PressureMotionMaxFactor"); m_supported.removeAll("EmulateTwoFingerMinZ"); } if (!cap[TouchpadPalmDetect]) { m_supported.removeAll("PalmDetect"); m_supported.removeAll("PalmMinWidth"); m_supported.removeAll("PalmMinZ"); m_supported.removeAll("EmulateTwoFingerMinW"); } for (QMap<QString, QString>::Iterator i = m_negate.begin(); i != m_negate.end(); ++i) { if (!m_supported.contains(i.key())) { m_supported.removeAll(i.value()); } } m_paramList = synapticsProperties; }
void graphModel::setSamples( const float * _samples ) { qCopy( _samples, _samples + length(), m_samples.begin()); emit samplesChanged( 0, length()-1 ); }
/** * \brief A variant of the Savitzky-Golay algorithm able to handle non-uniformly distributed data. * * In comparison to smoothSavGol(), this method trades proper handling of the X coordinates for * runtime efficiency by abandoning a central idea of Savitzky-Golay algorithm, namely that * polynomial smoothing can be expressed as a convolution. * * TODO: integrate this option into the GUI. */ void SmoothFilter::smoothModifiedSavGol(double *x_in, double *y_inout) { // total number of points in smoothing window int points = d_left_points + d_right_points + 1; if (points < d_polynom_order+1) { QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("The polynomial order must be lower than the number of left points plus the number of right points!")); return; } // allocate memory for the result QVector<double> result(d_n); // allocate memory for the linear algegra computations // Vandermonde matrix for x values of points in the current smoothing window gsl_matrix *vandermonde = gsl_matrix_alloc(points, d_polynom_order+1); // stores part of the QR decomposition of vandermonde gsl_vector *tau = gsl_vector_alloc(qMin(points, d_polynom_order+1)); // coefficients of polynomial approximation computed for each smoothing window gsl_vector *poly = gsl_vector_alloc(d_polynom_order+1); // residual of the (least-squares) approximation (by-product of GSL's algorithm) gsl_vector *residual = gsl_vector_alloc(points); for (int target_index = 0; target_index < d_n; target_index++) { int offset = target_index - d_left_points; // use a fixed number of points; near left/right borders, use offset to change // effective number of left/right points considered if (target_index < d_left_points) offset += d_left_points - target_index; else if (target_index + d_right_points >= d_n) offset += d_n - 1 - (target_index + d_right_points); // fill Vandermonde matrix for (int i = 0; i < points; ++i) { gsl_matrix_set(vandermonde, i, 0, 1.0); for (int j = 1; j <= d_polynom_order; ++j) gsl_matrix_set(vandermonde, i, j, gsl_matrix_get(vandermonde,i,j-1) * x_in[offset + i]); } // Y values within current smoothing window gsl_vector_view y_slice = gsl_vector_view_array(y_inout+offset, points); // compute QR decomposition of Vandermonde matrix if (int error=gsl_linalg_QR_decomp(vandermonde, tau)) QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("Internal error in Savitzky-Golay algorithm: QR decomposition failed.\n") + gsl_strerror(error)); // least-squares-solve vandermonde*poly=y_slice using the QR decomposition now stored in // vandermonde and tau else if (int error=gsl_linalg_QR_lssolve(vandermonde, tau, &y_slice.vector, poly, residual)) QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("Internal error in Savitzky-Golay algorithm: least-squares solution failed.\n") + gsl_strerror(error)); else result[target_index] = gsl_poly_eval(poly->data, d_polynom_order+1, x_in[target_index]); } // deallocate memory gsl_vector_free(residual); gsl_vector_free(poly); gsl_vector_free(tau); gsl_matrix_free(vandermonde); // write result into *y_inout qCopy(result.begin(), result.end(), y_inout); }
/** * \brief Savitzky-Golay smoothing of (uniformly distributed) data. * * When the data is not uniformly distributed, Savitzky-Golay looses its interesting conservation * properties. On the other hand, a central point of the algorithm is that for uniform data, the * operation can be implemented as a convolution. This is considerably more efficient than a more * generic method (see smoothModifiedSavGol()) able to handle non-uniform input data. * * There are at least three possible approaches to handling edges of the data vector (cutting them * off, zero padding and using the left-/rightmost smoothing polynomial for computing smoothed * values near the edges). Zero-padding is a particularly bad choice for signals with a distinctly * non-zero baseline and cutting off edges makes further computations on the original and smoothed * signals more difficult; therefore, deviating from the user-specified number of left/right * adjacent points (by smoothing over a fixed window at the edges) would be the least annoying * alternative; if it were not for the fact that previous versions of SciDAVis had a different * behaviour and such a subtle change to the behaviour would be even more annoying, especially * between bugfix releases. TODO: reconsider issue for next minor release (also: would it help * to add an "edge behaviour" option to the UI?) */ void SmoothFilter::smoothSavGol(double *, double *y_inout) { // total number of points in smoothing window int points = d_left_points + d_right_points + 1; if (points < d_polynom_order+1) { QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("The polynomial order must be lower than the number of left points plus the number of right points!")); return; } if (d_n < points) { QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("Tried to smooth over more points (left+right+1=%1) than given as input (%2).").arg(points).arg(d_n)); return; } // Savitzky-Golay coefficient matrix, y' = H y gsl_matrix *h = gsl_matrix_alloc(points, points); if (int error = savitzkyGolayCoefficients(points, d_polynom_order, h)) { QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"), tr("Internal error in Savitzky-Golay algorithm.\n") + gsl_strerror(error)); gsl_matrix_free(h); return; } // allocate memory for the result (temporary; don't overwrite y_inout while we still read from it) QVector<double> result(d_n); // near left edge: use interpolation of (points) left-most input values // i.e. we deviate from the specified left/right points to use /* for (int i=0; i<d_left_points; i++) { double convolution = 0.0; for (int k=0; k<points; k++) convolution += gsl_matrix_get(h, i, k) * y_inout[k]; result[i] = convolution; } */ // legacy behaviour: handle left edge by zero padding for (int i=0; i<d_left_points; i++) { double convolution = 0.0; for (int k=d_left_points-i; k<points; k++) convolution += gsl_matrix_get(h, d_left_points, k) * y_inout[i-d_left_points+k]; result[i] = convolution; } // central part: convolve with fixed row of h (as given by number of left points to use) for (int i=d_left_points; i<d_n-d_right_points; i++) { double convolution = 0.0; for (int k=0; k<points; k++) convolution += gsl_matrix_get(h, d_left_points, k) * y_inout[i-d_left_points+k]; result[i] = convolution; } // near right edge: use interpolation of (points) right-most input values // i.e. we deviate from the specified left/right points to use /* for (int i=d_n-d_right_points; i<d_n; i++) { double convolution = 0.0; for (int k=0; k<points; k++) convolution += gsl_matrix_get(h, points-d_n+i, k) * y_inout[d_n-points+k]; result[i] = convolution; } */ // legacy behaviour: handle right edge by zero padding for (int i=d_n-d_right_points; i<d_n; i++) { double convolution = 0.0; for (int k=0; i-d_left_points+k < d_n; k++) convolution += gsl_matrix_get(h, d_left_points, k) * y_inout[i-d_left_points+k]; result[i] = convolution; } // deallocate memory gsl_matrix_free(h); // write result into *y_inout qCopy(result.begin(), result.end(), y_inout); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312")); QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312")); QStringList list; list<<"one"<<"two"<<"three"; qDebug()<<QObject::tr("qCopu() methord:"); QVector<QString>vect(3); qCopy(list.begin(),list.end(),vect.begin()); qDebug()<<vect; /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qEqual() methord:"); bool bl=qEqual(list.begin(),list.end(),vect.begin()); qDebug()<<bl; // QList<QString>::iterator i; // i=qFind(list.begin,list.end(),"two"); /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qFind() methord:"); QStringList::const_iterator i= qFind(list.begin(), list.end(), "two"); qDebug()<<*i; /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qFill() methord:"); qFill(list.begin(),list.end(),"eleven"); qDebug()<<list; /****************************************************************************************************/ QList<int>list2; list2<<2<<31<<13<<2<<2<<2<<134<<2<<123<<4<<5<<3<<5<<51; qDebug()<<endl<<QObject::tr("qCount() methord:"); int number=0; qCount(list2.begin(),list2.end(),2,number); qDebug()<<"The number of 2 is:"<<number; qSort(list2); QList<int>::iterator j=qLowerBound(list2.begin(),list2.end(),22); list2.insert(j,22); /****************************************************************************************************/ qDebug()<<list2; qStableSort(list2); qDebug()<<endl<<list2; /****************************************************************************************************/ qSort(list2.begin(),list2.end(),qGreater<int>()); qDebug()<<endl<<list2; /****************************************************************************************************/ qStableSort(list2.begin(),list2.end(),qGreater<int>()); qDebug()<<endl<<list2; /****************************************************************************************************/ double d1=311.3998; double d2=0.231314; qDebug()<<endl<<"before swap:"<<d1<<" "<<d2; qSwap(d1,d2); qDebug()<<"then swap:"<<d1<<" "<<d2; /****************************************************************************************************/ int int_a=qBound(2,49,12); qDebug()<<"int_a="<<int_a; QDateTime time = QDateTime::currentDateTime(); //QString s=time.toString("yyyy-MM-dd hh:mm:ss"); qDebug()<<time.toString(); return a.exec(); }
void MainWindow::timerPlotEvent(void) { uint8_t index = 0; int y[PLOT_BUF_LEN]; //We go through the list and we update the appropriate data: data_to_plot[0] = ui->cBoxvar1->currentIndex(); data_to_plot[1] = ui->cBoxvar2->currentIndex(); data_to_plot[2] = ui->cBoxvar3->currentIndex(); data_to_plot[3] = ui->cBoxvar4->currentIndex(); data_to_plot[4] = ui->cBoxvar5->currentIndex(); data_to_plot[5] = ui->cBoxvar6->currentIndex(); for(index = 0; index < VAR_NUM; index++) { //Update buffers with latest results: switch(data_to_plot[index]) { case 0: //"**Unused**" update_graph_array(index, 0); break; case 1: //"Accel X" update_graph_array(index, exec1.accel.x); break; case 2: //"Accel Y" update_graph_array(index, exec1.accel.y); break; case 3: //"Accel Z" update_graph_array(index, exec1.accel.z); break; case 4: //"Gyro X" update_graph_array(index, exec1.gyro.x); break; case 5: //"Gyro Y" update_graph_array(index, exec1.gyro.y); break; case 6: //"Gyro Z" update_graph_array(index, exec1.gyro.z); break; case 7: //"Encoder" update_graph_array(index, exec1.enc_display); break; case 8: //"Motor current" update_graph_array(index, exec1.current); break; case 9: //"Analog[0]" update_graph_array(index, (int) exec1.analog[0]); break; case 10: //"Strain" update_graph_array(index, exec1.strain); break; case 11: //"+VB" update_graph_array(index, exec1.volt_batt); break; case 12: //"+VG" update_graph_array(index, exec1.volt_int); break; case 13: //"Temp" update_graph_array(index, exec1.temp); break; case 14: //"Fake Data" update_graph_array(index, gen_test_data()); break; case 15: //"Setpoint (square)" update_graph_array(index, ctrl_setpoint); break; case 16: //"Setpoint (trap)" update_graph_array(index, ctrl_setpoint_trap); break; case 17: //"Strain ch1" update_graph_array(index, strain[0].strain_filtered); break; case 18: //"Strain ch2" update_graph_array(index, strain[1].strain_filtered); break; case 19: //"Strain ch3" update_graph_array(index, strain[2].strain_filtered); break; case 20: //"Strain ch4" update_graph_array(index, strain[3].strain_filtered); break; case 21: //"Strain ch5" update_graph_array(index, strain[4].strain_filtered); break; case 22: //"Strain ch6" update_graph_array(index, strain[5].strain_filtered); break; case 23: //"AS5047 (Mot.)" update_graph_array(index, ricnu_1.ex.enc_commut); break; case 24: //"AS5048 (Joint)" update_graph_array(index, ricnu_1.ex.enc_control); break; } //Copy buffers and plot: qCopy(graph_yarray[index], graph_yarray[index] + plot_len, y); refreshPlot(graph_xarray, y, plot_len, index); } }
//makePlot created a plot. We now update its data. void MainWindow::refreshPlot(int *x, int *y, int len, uint8_t plot_index) { static int graph_ylim[2*VAR_NUM] = {0,0,0,0,0,0,0,0,0,0,0,0}; //From array to QVector: QVector<double> xdata(len), ydata(len); qCopy(x, x+len, xdata.begin()); qCopy(y, y+len, ydata.begin()); ui->customPlot->graph(plot_index)->setData(xdata, ydata); //ToDo: Modify this code to take the max of all curves! //In Automatic mode we constantly adjust the axis: if(ui->radioButtonXAuto->isChecked()) { array_minmax(x, len, &plot_xmin, &plot_xmax); ui->customPlot->xAxis->setRange(plot_xmin, plot_xmax); ui->plot_xmin_lineEdit->setText(QString::number(plot_xmin)); ui->plot_xmax_lineEdit->setText(QString::number(plot_xmax)); } else { //X is in manual mode. } if(ui->radioButtonYAuto->isChecked()) { //Unusued channels (index == 0) aren't used for the automatic gain if(data_to_plot[plot_index] == 0) { //qDebug() << "Ch[" << plot_index << "] is Unused."; //Unused channel. We take the min & max from used channels. int u = 0; for(int k= 0; k < VAR_NUM; k++) { //Grab min & max from any used channel if(data_to_plot[k] != 0) { plot_ymin = graph_ylim[k]; plot_ymax = graph_ylim[k+VAR_NUM]; } else { u++; } } if(u == VAR_NUM) { //All unused, force to 0: plot_ymin = -10; plot_ymax = 10; } //qDebug() << "Min/Max =" << plot_ymin << "," << plot_ymax; } else { //Limits for this graph: array_minmax(y, len, &plot_ymin, &plot_ymax); //qDebug() << "Ch[" << plot_index << "] is used."; } //Compare to all others and get max(max(()) graph_ylim[plot_index] = plot_ymin; graph_ylim[plot_index+VAR_NUM] = plot_ymax; //qDebug() << "Min/Max =" << plot_ymin << "," << plot_ymax; array_minmax(graph_ylim, 2*VAR_NUM, &plot_ymin, &plot_ymax); //Add 5%: plot_ymin = (plot_ymin-(abs(plot_ymin)/20)); plot_ymax = (plot_ymax+(abs(plot_ymax)/20)); //Set axis 5% above minimum ui->customPlot->yAxis->setRange(plot_ymin, plot_ymax); ui->plot_ymin_lineEdit->setText(QString::number(plot_ymin)); ui->plot_ymax_lineEdit->setText(QString::number(plot_ymax)); } //qDebug() << "Final Min/Max =" << plot_ymin << "," << plot_ymax; //qDebug() << ""; ui->customPlot->replot(); }
QVector<double> wavelet(EWaveletFamily family, bool lowpass, bool decompose) { static const double Lo_D[] = { -0.010597401784997, 0.032883011666983, 0.030841381835987, -0.187034811718881, -0.027983769416984, 0.630880767929590, 0.714846570552542, 0.230377813308855 }; static const double Hi_D[] = { -0.230377813308855, 0.714846570552542, -0.630880767929590, -0.027983769416984, 0.187034811718881, 0.030841381835987, -0.032883011666983, -0.010597401784997 }; static const double Lo_R[] = { 0.230377813308855, 0.714846570552542, 0.630880767929590, -0.027983769416984, -0.187034811718881, 0.030841381835987, 0.032883011666983, -0.010597401784997 }; static const double Hi_R[] = { -0.010597401784997, -0.032883011666983, 0.030841381835987, 0.187034811718881, -0.027983769416984, -0.630880767929590, 0.714846570552542, -0.230377813308855 }; QVector<double> ret; switch(family) { case Family_Db4: if(decompose) { if(lowpass) { ret.resize(sizeof(Lo_D)/sizeof(double)); qCopy(Lo_D, Lo_D + ret.size(), ret.begin()); } else { ret.resize(sizeof(Hi_D)/sizeof(double)); qCopy(Hi_D, Hi_D + ret.size(), ret.begin()); } } else { if(lowpass) { ret.resize(sizeof(Lo_R)/sizeof(double)); qCopy(Lo_R, Lo_R + ret.size(), ret.begin()); } else { ret.resize(sizeof(Hi_R)/sizeof(double)); qCopy(Hi_R, Hi_R + ret.size(), ret.begin()); } } break; } return ret; }
void QScriptHighlighter::setFormats(const QVector<QTextCharFormat> &s) { qCopy(s.constBegin(), s.constEnd(), m_formats); }
void TauWriter::operate() { try { QFileInfo file_info(GuiMainWindow::pointer()->getFilename()); readOutputFileName(file_info.completeBaseName() + ".grid"); if (isValid()) { QString file_name = getFileName(); NcFile *nc_file = new NcFile(file_name.toAscii(), NcFile::Replace); if (!nc_file->is_valid()) { EG_ERR_RETURN("unable to open NetCFD file for writing"); } // point coordinates size_t Np = m_Grid->GetNumberOfPoints(); vector<double> x(Np),y(Np),z(Np); for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { vec3_t xv; m_Grid->GetPoint(id_node, xv.data()); x[id_node] = xv[0]; y[id_node] = xv[1]; z[id_node] = xv[2]; } NcDim *no_of_points = nc_file->add_dim("no_of_points", Np); NcVar *points_xc = nc_file->add_var("points_xc", ncDouble, no_of_points); NcVar *points_yc = nc_file->add_var("points_yc", ncDouble, no_of_points); NcVar *points_zc = nc_file->add_var("points_zc", ncDouble, no_of_points); points_xc->put(&x[0],Np); points_yc->put(&y[0],Np); points_zc->put(&z[0],Np); // boundary faces size_t Nbe = 0;; size_t Nquad = 0; size_t Ntri = 0; for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, m_Grid)) { ++Nbe; if (m_Grid->GetCellType(id_cell) == VTK_TRIANGLE) { ++Ntri; } else if (m_Grid->GetCellType(id_cell) == VTK_QUAD) { ++Nquad; } else { EG_ERR_RETURN("unsupported boundary element type encountered"); } } } NcDim *no_of_surfaceelements = nc_file->add_dim("no_of_surfaceelements", Nbe); NcVar *boundarymarker_of_surfaces = nc_file->add_var("boundarymarker_of_surfaces", ncInt, no_of_surfaceelements); vector<int> bm(Nbe,0), tri(3*Ntri), quad(4*Nquad); int i_bm = 0; QSet<int> bc_set = getAllBoundaryCodes(m_Grid); QVector<int> bcs(bc_set.size()); qCopy(bc_set.begin(), bc_set.end(), bcs.begin()); EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); if (Ntri) { NcDim *no_of_surfacetriangles = nc_file->add_dim("no_of_surfacetriangles", Ntri); NcDim *points_per_surfacetriangle = nc_file->add_dim("points_per_surfacetriangle", 3); NcVar *points_of_surfacetriangles = nc_file->add_var("points_of_surfacetriangles", ncInt, no_of_surfacetriangles, points_per_surfacetriangle); int i_tri = 0; for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, m_Grid)) { if (m_Grid->GetCellType(id_cell) == VTK_TRIANGLE) { for (int i_bc = 0; i_bc < bcs.size(); ++i_bc) { if (bcs[i_bc] == cell_code->GetValue(id_cell)) { bm[i_bm] = i_bc+1; break; } } vtkIdType N_pts, *pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); tri[i_tri + 0] = pts[0]; tri[i_tri + 1] = pts[1]; tri[i_tri + 2] = pts[2]; ++i_bm; i_tri += 3; } } } points_of_surfacetriangles->put(&tri[0],Ntri,3); } if (Nquad) { NcDim *no_of_surfacequadrilaterals = nc_file->add_dim("no_of_surfacequadrilaterals",Nquad); NcDim *points_per_surfacequadrilateral = nc_file->add_dim("points_per_surfacequadrilateral",4); NcVar *points_of_surfacequadrilaterals = nc_file->add_var("points_of_surfacequadrilaterals",ncInt, no_of_surfacequadrilaterals, points_per_surfacequadrilateral); int i_quad = 0; for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, m_Grid)) { if (m_Grid->GetCellType(id_cell) == VTK_QUAD) { for (int i_bc = 0; i_bc < bcs.size(); ++i_bc) { if (bcs[i_bc] == cell_code->GetValue(id_cell)) { bm[i_bm] = i_bc+1; break; } } vtkIdType N_pts, *pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); quad[i_quad + 0] = pts[0]; quad[i_quad + 1] = pts[1]; quad[i_quad + 2] = pts[2]; quad[i_quad + 3] = pts[3]; ++i_bm; i_quad += 4; } } } points_of_surfacequadrilaterals->put(&quad[0],Nquad,4); } boundarymarker_of_surfaces->put(&bm[0],Nbe); NcDim *no_of_markers = nc_file->add_dim("no_of_markers", bcs.size()); int Ntet = 0; int Npri = 0; int Nhex = 0; int Npyr = 0; for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) == VTK_TETRA) ++Ntet; if (m_Grid->GetCellType(id_cell) == VTK_PYRAMID) ++Npyr; if (m_Grid->GetCellType(id_cell) == VTK_WEDGE) ++Npri; if (m_Grid->GetCellType(id_cell) == VTK_HEXAHEDRON) ++Nhex; } vector<int> tet(Ntet*4),pyr(Npyr*5),pri(Npri*6),hex(Nhex*8); int i_tet = 0; int i_pyr = 0; int i_pri = 0; int i_hex = 0; if (Ntet) { NcDim *no_of_tetraeders = nc_file->add_dim("no_of_tetraeders",Ntet); NcDim *points_per_tetraeder = nc_file->add_dim("points_per_tetraeder",4); NcVar *points_of_tetraeders = nc_file->add_var("points_of_tetraeders",ncInt, no_of_tetraeders, points_per_tetraeder); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) == VTK_TETRA) { vtkIdType *pts, N_pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); tet[i_tet + 0] = pts[0]; tet[i_tet + 1] = pts[1]; tet[i_tet + 2] = pts[2]; tet[i_tet + 3] = pts[3]; i_tet += 4; } } points_of_tetraeders->put(&tet[0],Ntet,4); } if (Npyr) { NcDim *no_of_pyramids = nc_file->add_dim("no_of_pyramids",Npyr); NcDim *points_per_pyramid = nc_file->add_dim("points_per_pyramid",5); NcVar *points_of_pyramids = nc_file->add_var("points_of_pyramids",ncInt, no_of_pyramids, points_per_pyramid); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) == VTK_PYRAMID) { vtkIdType *pts, N_pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); pyr[i_pyr + 0] = pts[0]; pyr[i_pyr + 1] = pts[1]; pyr[i_pyr + 2] = pts[2]; pyr[i_pyr + 3] = pts[3]; pyr[i_pyr + 4] = pts[4]; i_pyr += 5; } } points_of_pyramids->put(&pyr[0],Npyr,5); } if (Npri) { NcDim *no_of_prisms = nc_file->add_dim("no_of_prisms",Npri); NcDim *points_per_prism = nc_file->add_dim("points_per_prism",6); NcVar *points_of_prisms = nc_file->add_var("points_of_prisms",ncInt, no_of_prisms, points_per_prism); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) == VTK_WEDGE) { vtkIdType *pts, N_pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); pri[i_pri + 0] = pts[0]; pri[i_pri + 1] = pts[2]; pri[i_pri + 2] = pts[1]; pri[i_pri + 3] = pts[3]; pri[i_pri + 4] = pts[5]; pri[i_pri + 5] = pts[4]; i_pri += 6; } } points_of_prisms->put(&pri[0],Npri,6); } if (Nhex) { NcDim *no_of_hexaeders = nc_file->add_dim("no_of_hexaeders",Nhex); NcDim *points_per_hexaeder = nc_file->add_dim("points_per_hexaeder",8); NcVar *points_of_hexaeders = nc_file->add_var("points_of_hexaeders",ncInt, no_of_hexaeders, points_per_hexaeder); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) == VTK_HEXAHEDRON) { vtkIdType *pts, N_pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); hex[i_hex + 0] = pts[4]; hex[i_hex + 1] = pts[7]; hex[i_hex + 2] = pts[6]; hex[i_hex + 3] = pts[5]; hex[i_hex + 4] = pts[0]; hex[i_hex + 5] = pts[3]; hex[i_hex + 6] = pts[2]; hex[i_hex + 7] = pts[1]; i_hex += 8; } } points_of_hexaeders->put(&hex[0],Nhex,8); } delete nc_file; } } catch (Error err) { err.display(); } }
// MEMBER FUNCTIONS bool MeshReader::createMeshFromOBJ(Mesh & mesh, const char * objFile) { QFile file(objFile); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug("open file error"); return false; } bool hasFace = false; QVector<QVector3D> vertices; QVector<QVector2D> texCords; QVector<QVector3D> normals; QVector<uint> indices; QStringList strList; QString line; while (!file.atEnd()) { line.clear(); strList.clear(); line.push_back(file.readLine()); strList.append(line.split(" ")); if (line.startsWith("v ")) { vertices.push_back(QVector3D(strList[1].toFloat(), strList[2].toFloat(), strList[3].toFloat())); } else if (line.startsWith("vt ")) { texCords.push_back(QVector2D(strList[1].toFloat(), strList[2].toFloat())); } else if (line.startsWith("vn ")) { normals.push_back(QVector3D(strList[1].toFloat(), strList[2].toFloat(), strList[3].toFloat())); } else if (line.startsWith("f ")) { assert(vertices.empty() == false && "no vertex info has been read in."); qCopy(vertices.begin(), vertices.end(), std::back_inserter(mesh.verts())); if (texCords.empty()) { qDebug() << "no texture corrds info has been read in. line:" << __LINE__; } else { mesh.uvs().fill({}, vertices.size()); } if (normals.empty()) { qDebug() << "no normals info has been read in. line:" << __LINE__; } else { mesh.normals().fill({}, vertices.size()); } hasFace = true; break; } } if (file.atEnd() && hasFace == false) { qDebug() << "no face info has been read in. line:" << __LINE__; } if (vertices.empty()) { qDebug("ERROR WHEN LOADING VERTICES."); return false; } QStringList vList[3]; // 3 verts in one traiangles, describing by face while (!line.isEmpty() && !file.atEnd()) { if (!line.startsWith("f ")) { line.clear(); line.append(file.readLine()); continue; } strList.clear(); strList.append(line.split(" ")); // get current "face" line data and split if (strList.size() != 4) { qDebug() << "only support 3 verts per face for now." << __LINE__; file.close(); return false; } for (int i = 0; i < 3; ++i) { vList[i].clear(); vList[i].append(strList[i + 1].split("/")); // face: vertices/tx/normal // call process helper process(mesh, vList[i], vertices, texCords, normals); } line.clear(); line.append(file.readLine()); // don't forget } file.close(); // don't forget return true; }
void BlenderReader::operate() { try { QFileInfo file_info(GuiMainWindow::pointer()->getFilename()); readInputFileName(file_info.completeBaseName() + ".begc", false); if (isValid()) { // read raw data from exported file QFile file(getFileName()); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream f(&file); QList<vec3_t> rnodes; QList<QVector<int> > rfaces; int num_parts; f >> num_parts; QVector<QString> part_name(num_parts); for (int i_part = 0; i_part < num_parts; ++i_part) { f >> part_name[i_part]; } QVector<QString> sorted_part_name = part_name; qSort(sorted_part_name); QVector<int> part_bc(part_name.size()); for (int i_part = 0; i_part < num_parts; ++i_part) { part_bc[i_part] = sorted_part_name.indexOf(part_name[i_part]) + 1; } for (int i_part = 0; i_part < num_parts; ++i_part) { int num_nodes, num_faces; f >> num_nodes >> num_faces; for (int i = 0; i < num_nodes; ++i) { vec3_t x; f >> x[0] >> x[1] >> x[2]; rnodes.push_back(x); } for (int i = 0; i < num_faces; ++i) { int N; f >> N; QVector<int> face(N+1); face[0] = i_part; for (int j = 0; j < N; ++j) { f >> face[j+1]; } rfaces.push_back(face); } } QVector<vec3_t> nodes(rnodes.size()); qCopy(rnodes.begin(), rnodes.end(), nodes.begin()); QVector<QVector<int> > faces(rfaces.size()); qCopy(rfaces.begin(), rfaces.end(), faces.begin()); // find smallest edge length double L = 1e99; foreach (QVector<int> face, faces) { for (int i = 1; i < face.size(); ++i) { int n1 = face[i]; int n2 = face[1]; if (i < face.size() - 1) { n2 = face[i+1]; } double l = (nodes[n1] - nodes[n2]).abs(); L = min(l, L); } } cout << "smallest edge length is " << L << endl; // delete duplicate nodes PointFinder finder; finder.setPoints(nodes); QList<vec3_t> non_dup; QVector<int> o2n(nodes.size()); int num_non_dup = 0; for (int i = 0; i < nodes.size(); ++i) { o2n[i] = num_non_dup; bool dup = false; QVector<int> close_points; finder.getClosePoints(nodes[i], close_points); foreach (int j, close_points) { if (i > j) { double l = (nodes[i] - nodes[j]).abs(); if (l < m_RelativeTolerance*L || l == 0) { o2n[i] = o2n[j]; dup = true; break; } } } if (!dup) { non_dup.push_back(nodes[i]); ++num_non_dup; } } EG_VTKSP(vtkUnstructuredGrid, new_grid); allocateGrid(new_grid, faces.size(), non_dup.size()); EG_VTKDCC(vtkIntArray, cell_code, new_grid, "cell_code"); EG_VTKDCC(vtkIntArray, orgdir, new_grid, "cell_orgdir"); EG_VTKDCC(vtkIntArray, voldir, new_grid, "cell_voldir"); EG_VTKDCC(vtkIntArray, curdir, new_grid, "cell_curdir"); vtkIdType id_node = 0; foreach (vec3_t x, non_dup) { new_grid->GetPoints()->SetPoint(id_node, x.data()); ++id_node; } foreach (QVector<int> face, faces) { if (face.size() == 4) { vtkIdType pts[3]; pts[0] = o2n[face[1]]; pts[1] = o2n[face[2]]; pts[2] = o2n[face[3]]; vtkIdType id_cell = new_grid->InsertNextCell(VTK_TRIANGLE, 3, pts); cell_code->SetValue(id_cell, part_bc[face[0]]); orgdir->SetValue(id_cell, 0); voldir->SetValue(id_cell, 0); curdir->SetValue(id_cell, 0); } if (face.size() == 5) { vtkIdType pts[4]; pts[0] = o2n[face[1]]; pts[1] = o2n[face[2]]; pts[2] = o2n[face[3]]; pts[3] = o2n[face[4]]; vtkIdType id_cell = new_grid->InsertNextCell(VTK_QUAD, 4, pts); cell_code->SetValue(id_cell, part_bc[face[0]]); orgdir->SetValue(id_cell, 0); voldir->SetValue(id_cell, 0); curdir->SetValue(id_cell, 0); } } if (m_Append) { EG_BUG; MeshPartition new_part(new_grid); new_part.setAllCells(); m_Part.addPartition(new_part); } else { makeCopy(new_grid, m_Grid); } UpdateNodeIndex(m_Grid); UpdateCellIndex(m_Grid); // check and set the boundary names if required int update_required = true; QSet<int> old_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes(); if (old_bcs.size() == part_name.size()) { QSet<QString> old_names; foreach (int bc, old_bcs) { old_names.insert(GuiMainWindow::pointer()->getBC(bc).getName()); } QSet<QString> new_names; foreach (QString name, part_name) { new_names.insert(name); }
bool ScaleDiv::buildLogDiv(int maxMajSteps, int maxMinSteps, double majStep) { double firstTick, lastTick; double lFirst, lLast; double val, sval, minStep, minFactor; int nMaj, nMin, minSize, i, k, k0, kstep, kmax, i0; bool rv = true; double width; QVector<double> buffer; // Parameter range check maxMajSteps = MusECore::qwtMax(1, MusECore::qwtAbs(maxMajSteps)); maxMinSteps = MusECore::qwtMax(0, MusECore::qwtAbs(maxMinSteps)); majStep = MusECore::qwtAbs(majStep); // boundary check limRange(d_hBound, LOG_MIN, LOG_MAX); limRange(d_lBound, LOG_MIN, LOG_MAX); // reset vectors d_minMarks.resize(0); d_majMarks.resize(0); if (d_lBound == d_hBound) return true; // scale width in decades width = log10(d_hBound) - log10(d_lBound); // scale width is less than one decade -> build linear scale if (width < 1.0) { rv = buildLinDiv(maxMajSteps, maxMinSteps, 0.0); // convert step width to decades if (d_majStep > 0) d_majStep = log10(d_majStep); return rv; } // // Set up major scale divisions // if (majStep == 0.0) d_majStep = MusECore::qwtCeil125( width * 0.999999 / double(maxMajSteps)); else d_majStep = majStep; // major step must be >= 1 decade d_majStep = MusECore::qwtMax(d_majStep, 1.0); lFirst = ceil((log10(d_lBound) - step_eps * d_majStep) / d_majStep) * d_majStep; lLast = floor((log10(d_hBound) + step_eps * d_majStep) / d_majStep) * d_majStep; firstTick = pow10(lFirst); lastTick = pow10(lLast); nMaj = MusECore::qwtMin(10000, int(rint(MusECore::qwtAbs(lLast - lFirst) / d_majStep)) + 1); d_majMarks.resize(nMaj); MusECore::qwtLogSpace(d_majMarks.data(), d_majMarks.size(), firstTick, lastTick); // // Set up minor scale divisions // if ((d_majMarks.size() < 1) || (maxMinSteps < 1)) return true; // no minor marks if (d_majStep < 1.1) // major step width is one decade { if (maxMinSteps >= 8) { k0 = 2; kmax = 9; kstep = 1; minSize = (d_majMarks.size() + 1) * 8; } else if (maxMinSteps >= 4) { k0 = 2; kmax = 8; kstep = 2; minSize = (d_majMarks.size() + 1) * 4; } else if (maxMinSteps >= 2) { k0 = 2; kmax = 5; kstep = 3; minSize = (d_majMarks.size() + 1) * 2; } else { k0 = 5; kmax = 5; kstep = 1; minSize = (d_majMarks.size() + 1); } // resize buffer to the max. possible number of minor marks buffer.resize(minSize); // Are there minor ticks below the first major tick? if ( d_lBound < firstTick ) i0 = -1; else i0 = 0; minSize = 0; for (i = i0; i< (int)d_majMarks.size(); i++) { if (i >= 0) val = d_majMarks[i]; else val = d_majMarks[0] / pow10(d_majStep); for (k=k0; k<= kmax; k+=kstep) { sval = val * double(k); if (limRange(sval, d_lBound, d_hBound, border_eps)) { buffer[minSize] = sval; minSize++; } } } // copy values into the minMarks array //d_minMarks.duplicate(buffer.data(), minSize); d_minMarks.resize(minSize); qCopy(buffer.data(), buffer.data() + minSize, d_minMarks.begin()); } else // major step > one decade { // substep width in decades, at least one decade minStep = MusECore::qwtCeil125( (d_majStep - step_eps * (d_majStep / double(maxMinSteps))) / double(maxMinSteps) ); minStep = MusECore::qwtMax(1.0, minStep); // # subticks per interval nMin = int(rint(d_majStep / minStep)) - 1; // Do the minor steps fit into the interval? if ( MusECore::qwtAbs( double(nMin + 1) * minStep - d_majStep) > step_eps * d_majStep) nMin = 0; if (nMin < 1) return true; // no subticks // resize buffer to max. possible number of subticks buffer.resize((d_majMarks.size() + 1) * nMin ); // substep factor = 10^substeps minFactor = MusECore::qwtMax(pow10(minStep), 10.0); // Are there minor ticks below the first major tick? if ( d_lBound < firstTick ) i0 = -1; else i0 = 0; minSize = 0; for (i = i0; i< (int)d_majMarks.size(); i++) { if (i >= 0) val = d_majMarks[i]; else val = firstTick / pow10(d_majStep); for (k=0; k< nMin; k++) { sval = (val *= minFactor); if (limRange(sval, d_lBound, d_hBound, border_eps)) { buffer[minSize] = sval; minSize++; } } } //d_minMarks.duplicate(buffer.data(), minSize); d_minMarks.resize(minSize); qCopy(buffer.data(), buffer.data() + minSize, d_minMarks.begin()); } return rv; }
bool ScaleDiv::buildLinDiv(int maxMajSteps, int maxMinSteps, double step) { int nMaj, nMin, minSize, i0,i,k; double val, mval; double firstTick, lastTick; double minStep; QVector<double> buffer; bool rv = true; // parameter range check maxMajSteps = MusECore::qwtMax(1, maxMajSteps); maxMinSteps = MusECore::qwtMax(0, maxMinSteps); step = MusECore::qwtAbs(step); // reset vectors d_minMarks.resize(0); d_majMarks.resize(0); if (d_lBound == d_hBound) return true; // // Set up major divisions // if (step == 0.0) d_majStep = MusECore::qwtCeil125(MusECore::qwtAbs(d_hBound - d_lBound) * 0.999999 / double(maxMajSteps)); else d_majStep = step; if (d_majStep == 0.0) return true; firstTick = ceil( (d_lBound - step_eps * d_majStep) / d_majStep) * d_majStep; lastTick = floor( (d_hBound + step_eps * d_majStep) / d_majStep) * d_majStep; nMaj = MusECore::qwtMin(10000, int(rint((lastTick - firstTick) / d_majStep)) + 1); d_majMarks.resize(nMaj); MusECore::qwtLinSpace(d_majMarks.data(), d_majMarks.size(), firstTick, lastTick); // // Set up minor divisions // if (maxMinSteps < 1) // no minor divs return true; minStep = MusECore::qwtCeil125( d_majStep / double(maxMinSteps) ); if (minStep == 0.0) return true; nMin = MusECore::qwtAbs(int(rint(d_majStep / minStep))) - 1; // # minor steps per interval // Do the minor steps fit into the interval? if ( MusECore::qwtAbs(double(nMin + 1) * minStep - d_majStep) > step_eps * d_majStep) { nMin = 1; minStep = d_majStep * 0.5; } // Are there minor ticks below the first major tick? if (d_majMarks[0] > d_lBound ) i0 = -1; else i0 = 0; // resize buffer to the maximum possible number of minor ticks buffer.resize(nMin * (nMaj + 1)); // calculate minor ticks if (rv) { minSize = 0; for (i = i0; i < (int)d_majMarks.size(); i++) { if (i >= 0) val = d_majMarks[i]; else val = d_majMarks[0] - d_majStep; for (k=0; k< nMin; k++) { mval = (val += minStep); if (limRange(mval, d_lBound, d_hBound, border_eps)) { buffer[minSize] = mval; minSize++; } } } //d_minMarks.duplicate(buffer.data(), minSize); d_minMarks.resize(minSize); qCopy(buffer.data(), buffer.data() + minSize, d_minMarks.begin()); } return rv; }