Esempio n. 1
0
void Plugin14CRefView::setDate(const Date& d, const ProjectSettings& settings)
{
    QLocale locale=QLocale();
    GraphViewRefAbstract::setDate(d, settings);
    Date date = d;
    
    mGraph->removeAllCurves();
    mGraph->clearInfos();
    mGraph->showInfos(true);
    mGraph->setRangeX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setCurrentX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setFormatFunctX(mFormatFuncX);
    
    if(!date.isNull())
    {
        double age = date.mData.value(DATE_14C_AGE_STR).toDouble();
        double error = date.mData.value(DATE_14C_ERROR_STR).toDouble();
        double delta_r = date.mData.value(DATE_14C_DELTA_R_STR).toDouble();
        double delta_r_error = date.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble();
        QString ref_curve = date.mData.value(DATE_14C_REF_CURVE_STR).toString().toLower();
        
        // ----------------------------------------------
        //  Reference curve
        // ----------------------------------------------
        
        QColor color2(150, 150, 150);
        
        Plugin14C* plugin = (Plugin14C*)date.mPlugin;

        const QMap<QString, QMap<double, double> >& curves = plugin->getRefData(ref_curve);
        
        
        QMap<double, double> curveG;
        QMap<double, double> curveG95Sup;
        QMap<double, double> curveG95Inf;
        
        double yMin = curves["G95Inf"][mSettings.mTmin];
        double yMax = curves["G95Sup"][mSettings.mTmin];
        
        double tMinGraph=curves["G"].firstKey()>mSettings.mTmin ? curves["G"].firstKey(): mSettings.mTmin;
        double tMaxGraph=curves["G"].lastKey()<mSettings.mTmax ?  curves["G"].lastKey() : mSettings.mTmax;
        
        for(double t=tMinGraph; t<=tMaxGraph; ++t) {
            curveG[t] = curves["G"][t];
            curveG95Sup[t] = curves["G95Sup"][t];
            curveG95Inf[t] = curves["G95Inf"][t];
            
            yMin = qMin(yMin, curveG95Inf[t]);
            yMax = qMax(yMax, curveG95Sup[t]);
        }
        
        GraphCurve graphCurveG;
        graphCurveG.mName = "G";
        graphCurveG.mData = curveG;
        graphCurveG.mPen.setColor(Qt::blue);
        graphCurveG.mIsHisto = false;
        mGraph->addCurve(graphCurveG);
        
        GraphCurve graphCurveG95Sup;
        graphCurveG95Sup.mName = "G95Sup";
        graphCurveG95Sup.mData = curveG95Sup;
        graphCurveG95Sup.mPen.setColor(QColor(180, 180, 180));
        graphCurveG95Sup.mIsHisto = false;
        mGraph->addCurve(graphCurveG95Sup);
        
        GraphCurve graphCurveG95Inf;
        graphCurveG95Inf.mName = "G95Inf";
        graphCurveG95Inf.mData = curveG95Inf;
        graphCurveG95Inf.mPen.setColor(QColor(180, 180, 180));
        graphCurveG95Inf.mIsHisto = false;
        mGraph->addCurve(graphCurveG95Inf);
        
        // Display reference curve name
        mGraph->addInfo(tr("Ref : ") + ref_curve);
        
        // -------------------------------------------
        
        yMin = qMin(yMin, age);
        yMin = floor(yMin/10)*10;
        
        yMax = qMax(yMax, age);
        yMax = ceil(yMax/10)*10;
        
        mGraph->setRangeY(yMin, yMax);
        
        // ----------------------------------------------
        //  Measure curve
        // ----------------------------------------------
        GraphCurve curveMeasure;
        curveMeasure.mName = "Measure";
        
        QColor penColor(mMeasureColor);
        QColor brushColor(mMeasureColor);
        
        // Lower opacity in case of delta r not null
        if(delta_r != 0 && delta_r_error != 0){
            penColor.setAlpha(100);
            brushColor.setAlpha(15);
        }else{
            penColor.setAlpha(255);
            brushColor.setAlpha(50);
        }
        curveMeasure.mPen = penColor;
        curveMeasure.mBrush = brushColor;
        
        curveMeasure.mIsVertical = true;
        curveMeasure.mIsHisto = false;
        
        // 5000 pts are used on vertical measure
        // because the y scale auto adjusts depending on x zoom.
        // => the visible part of the measure may be very reduced !
        double step = (yMax - yMin) / 5000.;
        for(double t=yMin; t<yMax; t += step)
        {
            double v = exp(-0.5 * pow((age - t) / error, 2));
            curveMeasure.mData[t] = v;
        }
        curveMeasure.mData = normalize_map(curveMeasure.mData);
        mGraph->addCurve(curveMeasure);
        
        // Infos to write :
        QString info = tr("Age BP : ") + locale.toString(age) + " ± " + locale.toString(error);
        
        // ----------------------------------------------
        //  Delta R curve
        // ----------------------------------------------
        if(delta_r != 0 && delta_r_error != 0)
        {
            // Apply reservoir effect
            age = (age - delta_r);
            error = sqrt(error * error + delta_r_error * delta_r_error);
            
            GraphCurve curveDeltaR;
            curveDeltaR.mName = "Delta R";
            
            penColor = mMeasureColor;
            brushColor = mMeasureColor;
            brushColor.setAlpha(50);
            
            curveDeltaR.mPen = penColor;
            curveDeltaR.mBrush = brushColor;
            
            curveDeltaR.mIsVertical = true;
            curveDeltaR.mIsHisto = false;
            
            // 5000 pts are used on vertical measure
            // because the y scale auto adjusts depending on x zoom.
            // => the visible part of the measure may be very reduced !
            step = (yMax - yMin) / 5000.;
            for(double t=yMin; t<yMax; t += step)
            {
                double v = exp(-0.5 * pow((age - t) / error, 2));
                curveDeltaR.mData[t] = v;
            }
            curveDeltaR.mData = normalize_map(curveDeltaR.mData);
            mGraph->addCurve(curveDeltaR);
            
            info += tr(", ΔR : ") + locale.toString(delta_r) + " ± " + locale.toString(delta_r_error);
        }
        
        // ----------------------------------------------
        //  Sub-dates curves (combination)
        // ----------------------------------------------
        for(int i=0; i<date.mSubDates.size(); ++i){
            const Date& d = date.mSubDates[i];
            
            GraphCurve curveSubMeasure;
            curveSubMeasure.mName = "Sub-Measure " + QString::number(i);
            
            QColor penColor = QColor(167, 126, 73);
            QColor brushColor = QColor(167, 126, 73);
            
            double sub_age = d.mData.value(DATE_14C_AGE_STR).toDouble();
            double sub_error = d.mData.value(DATE_14C_ERROR_STR).toDouble();
            double sub_delta_r = d.mData.value(DATE_14C_DELTA_R_STR).toDouble();
            double sub_delta_r_error = d.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble();
            
            // Apply reservoir effect
            sub_age = (sub_age - sub_delta_r);
            sub_error = sqrt(sub_error * sub_error + sub_delta_r_error * sub_delta_r_error);
            
            penColor.setAlpha(255);
            brushColor.setAlpha(50);
            
            curveSubMeasure.mPen = penColor;
            curveSubMeasure.mBrush = brushColor;
            
            curveSubMeasure.mIsVertical = true;
            curveSubMeasure.mIsHisto = false;
            
            // 5000 pts are used on vertical measure
            // because the y scale auto adjusts depending on x zoom.
            // => the visible part of the measure may be very reduced !
            double step = (yMax - yMin) / 5000.;
            for(double t=yMin; t<yMax; t += step)
            {
                double v = exp(-0.5 * pow((sub_age - t) / sub_error, 2));
                curveSubMeasure.mData[t] = v;
            }
            curveSubMeasure.mData = normalize_map(curveSubMeasure.mData);
            mGraph->addCurve(curveSubMeasure);
        }

        // ----------------------------------------------
        //  Textual info
        // ----------------------------------------------
        
        mGraph->addInfo(info);
        
        // ----------------------------------------------
        //  Error on measure (horizontal lines)
        // ----------------------------------------------
        
        GraphCurve curveMeasureAvg;
        curveMeasureAvg.mName = "MeasureAvg";
        curveMeasureAvg.mPen.setColor(mMeasureColor);
        curveMeasureAvg.mPen.setStyle(Qt::SolidLine);
        curveMeasureAvg.mIsHorizontalLine = true;
        
        GraphCurve curveMeasureSup;
        curveMeasureSup.mName = "MeasureSup";
        curveMeasureSup.mPen.setColor(mMeasureColor);
        curveMeasureSup.mPen.setStyle(Qt::DashLine);
        curveMeasureSup.mIsHorizontalLine = true;
        
        GraphCurve curveMeasureInf;
        curveMeasureInf.mName = "MeasureInf";
        curveMeasureInf.mPen.setColor(mMeasureColor);
        curveMeasureInf.mPen.setStyle(Qt::DashLine);
        curveMeasureInf.mIsHorizontalLine = true;
        
        curveMeasureAvg.mHorizontalValue = age;
        curveMeasureSup.mHorizontalValue = age + error;
        curveMeasureInf.mHorizontalValue = age - error;
        
        mGraph->addCurve(curveMeasureAvg);
        mGraph->addCurve(curveMeasureSup);
        mGraph->addCurve(curveMeasureInf);
    }
}
void PluginGaussRefView::setDate(const Date& d, const ProjectSettings& settings)
{
    QLocale locale=QLocale();
    GraphViewRefAbstract::setDate(d, settings);
    
    Date date = d;
    
    mGraph->removeAllCurves();
    mGraph->clearInfos();
    mGraph->showInfos(true);
    mGraph->setRangeX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setCurrentX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setFormatFunctX(mFormatFuncX);
    
    if(!date.isNull())
    {
        double age = date.mData.value(DATE_GAUSS_AGE_STR).toDouble();
        double error = date.mData.value(DATE_GAUSS_ERROR_STR).toDouble();
        double a = date.mData.value(DATE_GAUSS_A_STR).toDouble();
        double b = date.mData.value(DATE_GAUSS_B_STR).toDouble();
        double c = date.mData.value(DATE_GAUSS_C_STR).toDouble();
        QString mode = date.mData.value(DATE_GAUSS_MODE_STR).toString();
        QString ref_curve = date.mData.value(DATE_GAUSS_CURVE_STR).toString();
        
        // ----------------------------------------------
        //  Reference curve
        // ----------------------------------------------
        
        GraphCurve curve;
        curve.mName = "Reference";
        curve.mPen.setColor(Qt::blue);
        curve.mIsHisto = false;
        
        double yMin;
        double yMax;
        
        if(mode == DATE_GAUSS_MODE_NONE)
        {
            /*for(double t=mSettings.mTmin; t<=mSettings.mTmax; t+=mSettings.mStep)
                curve.mData[t] = t;
            mGraph->addCurve(curve);
            
            // Adjust scale :
            yMin = mSettings.mTmin;
            yMax = mSettings.mTmax;
            
            yMin = qMin(yMin, age);
            yMax = qMax(yMax, age);
            
            mGraph->setRangeY(yMin, yMax);
            */
        }
        else if(mode == DATE_GAUSS_MODE_EQ)
        {
            for(double t=mSettings.mTmin; t<=mSettings.mTmax; t+=mSettings.mStep)
                curve.mData[t] = a * t * t + b * t + c;
            mGraph->addCurve(curve);
            
            // Adjust scale :
            yMin = map_min_value(curve.mData);
            yMax = map_max_value(curve.mData);
            
            yMin = qMin(yMin, age);
            yMax = qMax(yMax, age);
            
            mGraph->setRangeY(yMin, yMax);
        }
        else if(mode == DATE_GAUSS_MODE_CURVE)
        {
            PluginGauss* plugin = (PluginGauss*)date.mPlugin;
            
            const QMap<QString, QMap<double, double> >& curves = plugin->getRefData(ref_curve);
            
            
            QMap<double, double> curveG;
            QMap<double, double> curveG95Sup;
            QMap<double, double> curveG95Inf;
            
            yMin = curves["G95Inf"][mSettings.mTmin];
            yMax = curves["G95Sup"][mSettings.mTmin];
            
            double tMinGraph=curves["G"].firstKey()>mSettings.mTmin ? curves["G"].firstKey(): mSettings.mTmin;
            double tMaxGraph=curves["G"].lastKey()<mSettings.mTmax  ? curves["G"].lastKey() : mSettings.mTmax;
            
            for(double t=tMinGraph; t<=tMaxGraph; ++t) {
                curveG[t] = curves["G"][t];
                curveG95Sup[t] = curves["G95Sup"][t];
                curveG95Inf[t] = curves["G95Inf"][t];
                
                yMin = qMin(yMin, curveG95Inf[t]);
                yMax = qMax(yMax, curveG95Sup[t]);
            }
            
            GraphCurve graphCurveG;
            graphCurveG.mName = "G";
            graphCurveG.mData = curveG;
            graphCurveG.mPen.setColor(Qt::blue);
            graphCurveG.mIsHisto = false;
            mGraph->addCurve(graphCurveG);
            
            GraphCurve graphCurveG95Sup;
            graphCurveG95Sup.mName = "G95Sup";
            graphCurveG95Sup.mData = curveG95Sup;
            graphCurveG95Sup.mPen.setColor(QColor(180, 180, 180));
            graphCurveG95Sup.mIsHisto = false;
            mGraph->addCurve(graphCurveG95Sup);
            
            GraphCurve graphCurveG95Inf;
            graphCurveG95Inf.mName = "G95Inf";
            graphCurveG95Inf.mData = curveG95Inf;
            graphCurveG95Inf.mPen.setColor(QColor(180, 180, 180));
            graphCurveG95Inf.mIsHisto = false;
            mGraph->addCurve(graphCurveG95Inf);
            
            // Display reference curve name
            mGraph->addInfo(tr("Ref : ") + ref_curve);
            
            // Adjust scale :
            yMin = qMin(yMin, age);
            yMin = floor(yMin/10)*10;
            
            yMax = qMax(yMax, age);
            yMax = ceil(yMax/10)*10;
            
            mGraph->setRangeY(yMin, yMax);
        }
        
        if(mode != DATE_GAUSS_MODE_NONE)
        {
            // ----------------------------------------------
            //  Measure curve
            // ----------------------------------------------

            GraphCurve curveMeasure;
            curveMeasure.mName = "Measure";

            curveMeasure.mPen.setColor(mMeasureColor);
            QColor curveColor(mMeasureColor);
            curveColor.setAlpha(50);
            curveMeasure.mBrush = curveColor;

            curveMeasure.mIsVertical = true;
            curveMeasure.mIsHisto = false;

            // 5000 pts are used on vertical measure
            // because the y scale auto adjusts depending on x zoom.
            // => the visible part of the measure may be very reduced !
            double step = (yMax - yMin) / 5000.;
            for(double t=yMin; t<yMax; t += step)
            {
                double v = exp(-0.5 * pow((t - age) / error, 2));
                curveMeasure.mData[t] = v;
            }
            curveMeasure.mData = normalize_map(curveMeasure.mData);
            mGraph->addCurve(curveMeasure);

            // Write measure value :
            mGraph->addInfo(tr("Measure : ") + locale.toString(age) + " ± " + locale.toString(error));

            // ----------------------------------------------
            //  Error on measure
            // ----------------------------------------------

            GraphCurve curveMeasureAvg;
            curveMeasureAvg.mName = "MeasureAvg";
            curveMeasureAvg.mPen.setColor(mMeasureColor);
            curveMeasureAvg.mPen.setStyle(Qt::SolidLine);
            curveMeasureAvg.mIsHorizontalLine = true;

            GraphCurve curveMeasureSup;
            curveMeasureSup.mName = "MeasureSup";
            curveMeasureSup.mPen.setColor(mMeasureColor);
            curveMeasureSup.mPen.setStyle(Qt::DashLine);
            curveMeasureSup.mIsHorizontalLine = true;

            GraphCurve curveMeasureInf;
            curveMeasureInf.mName = "MeasureInf";
            curveMeasureInf.mPen.setColor(mMeasureColor);
            curveMeasureInf.mPen.setStyle(Qt::DashLine);
            curveMeasureInf.mIsHorizontalLine = true;

            curveMeasureAvg.mHorizontalValue = age;
            curveMeasureSup.mHorizontalValue = age + error;
            curveMeasureInf.mHorizontalValue = age - error;

            mGraph->addCurve(curveMeasureAvg);
            mGraph->addCurve(curveMeasureSup);
            mGraph->addCurve(curveMeasureInf);
        }
    }
}
Esempio n. 3
0
void EventKnownItem::setEvent(const QJsonObject& event, const QJsonObject& settings)
{
    prepareGeometryChange();
    
    mData = event;
    
    // ----------------------------------------------
    //  Update item position and selection
    // ----------------------------------------------
    setSelected(mData[STATE_IS_SELECTED].toBool());
    setPos(mData[STATE_ITEM_X].toDouble(),
           mData[STATE_ITEM_Y].toDouble());
    
    // ----------------------------------------------
    //  Check if item should be greyed out
    // ----------------------------------------------
    //updateGreyedOut();
    
    // ----------------------------------------------
    //  Recreate thumb
    // ----------------------------------------------
    double tmin = settings[STATE_SETTINGS_TMIN].toDouble();
    double tmax = settings[STATE_SETTINGS_TMAX].toDouble();
    double step = settings[STATE_SETTINGS_STEP].toDouble();
    
    EventKnown bound = EventKnown::fromJson(event);
    bound.updateValues(tmin, tmax, step);
    
    /*QRectF rect = boundingRect();
    double side = 40.f;
    double top = 25.f;
    QRectF thumbRect(rect.x() + side, rect.y() + top + mEltsMargin + mTitleHeight, rect.width() - 2*side, mThumbH);*/
    
    GraphView* graph = new GraphView();
    //graph->setFixedSize(thumbRect.width(), thumbRect.height());
    graph->setFixedSize(200, 50);
    graph->setMargins(0, 0, 0, 0);
    
    graph->setRangeX(tmin, tmax);
    graph->setCurrentX(tmin, tmax);
    graph->setRangeY(0, 1.1f);
    
    graph->showXAxisArrow(false);
    graph->showXAxisTicks(false);
    graph->showXAxisSubTicks(false);
    graph->showXAxisValues(false);
    
    graph->showYAxisArrow(false);
    graph->showYAxisTicks(false);
    graph->showYAxisSubTicks(false);
    graph->showYAxisValues(false);
    
    graph->setXAxisMode(GraphView::eHidden);
    graph->setYAxisMode(GraphView::eHidden);
    
    GraphCurve curve;
    curve.mData = normalize_map(bound.mValues);
    curve.mName = "Bound";
    
    curve.mPen = QPen(Painting::mainColorLight, 2.f);
    curve.mBrush = Painting::mainColorLight;
    
    curve.mIsRectFromZero = true;
    curve.mIsHisto = (bound.knownType() == EventKnown::eUniform);
    
    graph->addCurve(curve);
    graph->setFormatFunctX(DateUtils::convertToAppSettingsFormatStr);
    graph->mLegendX = DateUtils::getAppSettingsFormat();
    
    mThumb = QPixmap(graph->size());
    graph->render(&mThumb);
    delete graph;
    
    // ----------------------------------------------
    //  Repaint based on mEvent
    // ----------------------------------------------
    update();
}
Esempio n. 4
0
/*
 * Force maps map[0 ... n-1] to be all distinct by updating them.
 * - store = particle store to create fresh indices
 * - f = type descriptor for all the maps in the array
 * - n must be positive
 *
 * Technique used:
 * - create fresh indices i_1,..,i_k in the domain of f
 * - create c values a_1,..., a_c in the range of f
 * such that (c ^ k) >= n.
 * Update map[t] by adding [i_1 -> a_t1, ..., i_k -> a_tk]
 * in such a way that (t1, ...., tk) differ from (u1, ..., uk) when u/=t.
 *
 * Return false if that's not possible (i.e., the number of functions
 * of the type f is finite and smaller than n).
 */
bool force_maps_to_differ(pstore_t *store, function_type_t *f, uint32_t n, map_t **map) {
  type_table_t *types;
  particle_t *idx;
  particle_t *a;
  uint32_t *tuple;
  type_t tau;
  uint32_t i, j, k, c;

  types = store->types;
  tau = f->range;

  if (is_unit_type(types, tau)) {
    return false;
  }

  if (is_finite_type(types, tau)) {
    c = type_card(types, tau);
    k = ceil_log(c, n);
  } else {
    c = n;
    k = 1;
  }

  assert(k>0 && c>0 && upower32(c, k) >= n);

  // tuple + index array are of size k
  // a is of size c
  tuple = (uint32_t *) safe_malloc(k * sizeof(uint32_t));
  idx = (particle_t *) safe_malloc(k * sizeof(particle_t));
  a = (particle_t *) safe_malloc(c * sizeof(particle_t));

  // initialize the idx array with fresh values
  if (f->ndom == 1) {
    for (i=0; i<k; i++) {
      idx[i] = get_new_particle(store, f->domain[0]);
      if (idx[i] == null_particle) goto failed;
    }
  } else {
    for (i=0; i<k; i++) {
      idx[i] = get_new_tuple(store, f->ndom, f->domain);
      if (idx[i] == null_particle) goto failed;
    }
  }

  // fill-in a with c distinct values of type tau
  for (i=0; i<c; i++) {
    a[i] = get_distinct_particle(store, tau, i, a);
    assert(a[i] != null_particle);
  }

  // initialize tuple = (0,...,0)
  for (i=0; i<k; i++) {
    tuple[i] = 0;
  }

  // update then normalize the maps
  i = 0;
  for (;;) {
    assert(i < n);
    for (j=0; j<k; j++) {
      assert(tuple[j] < c);
      add_elem_to_map(map[i], idx[j], a[tuple[j]]);
    }
    normalize_map(map[i]);
    i ++;
    if (i == n) break;
    tuple_successor(tuple, k, c);
  }

  safe_free(a);
  safe_free(idx);
  safe_free(tuple);
  return true;


 failed:
  safe_free(a);
  safe_free(idx);
  safe_free(tuple);
  return false;
}