void OscilloscopePlot::updateCurve()
{
    CurveData *data = static_cast<CurveData *>( d_curve->data() );
    data->values().lock();

    const int numPoints = data->size();
    if ( numPoints > d_paintedPoints )
    {
        const bool doClip = !canvas()->testAttribute( Qt::WA_PaintOnScreen );
        if ( doClip )
        {
            /*
                Depending on the platform setting a clip might be an important
                performance issue. F.e. for Qt Embedded this reduces the
                part of the backing store that has to be copied out - maybe
                to an unaccelerated frame buffer device.
            */

            const QwtScaleMap xMap = canvasMap( d_curve->xAxis() );
            const QwtScaleMap yMap = canvasMap( d_curve->yAxis() );

            QRectF br = qwtBoundingRect( *data,
                d_paintedPoints - 1, numPoints - 1 );

            const QRect clipRect = QwtScaleMap::transform( xMap, yMap, br ).toRect();
            d_directPainter->setClipRegion( clipRect );
        }

        d_directPainter->drawSeries( d_curve,
            d_paintedPoints - 1, numPoints - 1 );
        d_paintedPoints = numPoints;
    }

    data->values().unlock();
}
Ejemplo n.º 2
0
boost::shared_ptr<BlackCapFloorEngine> MustCapFloor::setEngineQuantLibBalckFT(){

	CurveData cData;
	// Fill out with some sample market data
	cData.sampleMktData(cData);

	// Build a curve linked to this market data
	boost::shared_ptr<YieldTermStructure> ocurve = (cData.buildCurve(cData));

	// Link the curve to the term structure
	this->forwardingTermStructure.linkTo(ocurve);
	//Date today(6, October, 2014);
	Settings::instance().evaluationDate() = today;

	//Date todaysDate = Date(8, Apr, 2015);
	//capletsVolatilies = buildCurveOptionletAtmVol(cVol);
	//capletsVolatilies = buildOptionletSurfaceVol(cVol);
	//capletsVolatilies = buildOptionletCurveVol(cVol);

	cVol.termStructure.linkTo(ocurve);
	capletsVolatilies = (cVol.buildFlatCurveVol(cVol));

	//capVol->enableExtrapolation();
	return boost::shared_ptr<BlackCapFloorEngine>(new
		BlackCapFloorEngine(forwardingTermStructure, capletsVolatilies));
}
Ejemplo n.º 3
0
void IncrementalPlot::appendPoint( const QPointF &point )
{
    CurveData *data = static_cast<CurveData *>( d_curve->data() );
    data->append( point );

    const bool doClip = !canvas()->testAttribute( Qt::WA_PaintOnScreen );
//    if ( doClip )
//    {
//        /*
//           Depending on the platform setting a clip might be an important
//           performance issue. F.e. for Qt Embedded this reduces the
//           part of the backing store that has to be copied out - maybe
//           to an unaccelerated frame buffer device.
//         */
//        const QwtScaleMap xMap = canvasMap( d_curve->xAxis() );
//        const QwtScaleMap yMap = canvasMap( d_curve->yAxis() );

//        QRegion clipRegion;

//        const QSize symbolSize = d_curve->symbol()->size();
//        QRect r( 0, 0, symbolSize.width() + 2, symbolSize.height() + 2 );

//        const QPointF center =
//            QwtScaleMap::transform( xMap, yMap, point );
//        r.moveCenter( center.toPoint() );
//        clipRegion += r;

//        d_directPainter->setClipRegion( clipRegion );
//    }

    d_directPainter->drawSeries( d_curve,
        data->size() - 1, data->size() - 1 );
}
Ejemplo n.º 4
0
void BrainPlot::clearPoints(int Channel)
{
    CurveData *data = static_cast<CurveData *>( d_curves[Channel]->data() );
    data->clear();

    replot();
}
Ejemplo n.º 5
0
void IncrementalPlot::clearPoints()
{
    CurveData *data = static_cast<CurveData *>( d_curve->data() );
    data->clear();

    replot();
}
void OscilloscopePlot::incrementInterval()
{
    d_interval = QwtInterval( d_interval.maxValue(),
        d_interval.maxValue() + d_interval.width() );

    CurveData *data = static_cast<CurveData *>( d_curve->data() );
    data->values().clearStaleValues( d_interval.minValue() );

    // To avoid, that the grid is jumping, we disable
    // the autocalculation of the ticks and shift them
    // manually instead.

    QwtScaleDiv scaleDiv = axisScaleDiv( QwtPlot::xBottom );
    scaleDiv.setInterval( d_interval );

    for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
    {
        QList<double> ticks = scaleDiv.ticks( i );
        for ( int j = 0; j < ticks.size(); j++ )
            ticks[j] += d_interval.width();
        scaleDiv.setTicks( i, ticks );
    }
    setAxisScaleDiv( QwtPlot::xBottom, scaleDiv );

    d_origin->setValue( d_interval.minValue() + d_interval.width() / 2.0, 0.0 );

    d_paintedPoints = 0;
    replot();
}
Ejemplo n.º 7
0
void Wykres2d::wyczysc()
{
    CurveData *data = static_cast<CurveData *> (plot2dCurve->data()); 
    data->clear();
    punkty.clear();
     plot2d->replot();
    
}
Ejemplo n.º 8
0
// -------------------------------------------------------------------------- //
//
void Test_CurveData::testGetChi2New()
{
    CurveData cd;
    const double chi2_new = 1.1246722311651241;
    cd.chi2_new_ = chi2_new;

    CPPUNIT_ASSERT_DOUBLES_EQUAL( cd.get_chi2_new(), chi2_new, 1.0e-12 );
}
Ejemplo n.º 9
0
void Plot::replot()
{
    CurveData *data = (CurveData *)d_curve->data();
    data->values().lock();

    QwtPlot::replot();
    d_paintedPoints = data->size();

    data->values().unlock();
}
void OscilloscopePlot::replot()
{
    CurveData *data = static_cast<CurveData *>( d_curve->data() );
    data->values().lock();

    QwtPlot::replot();
    d_paintedPoints = data->size();

    data->values().unlock();
}
Ejemplo n.º 11
0
void BrainPlot::appendPoint( QPointF point, int Channel )
{
    /*Adds new point - with proper index and offset - to the data series*/
    CurveData *data = static_cast<CurveData *>( d_curves[Channel]->data() );
    point.setY(minusExpectedAmplitude*(2*Channel+1)+point.y());
    data->replace(sample%plotLength, point);
    setClipRegion(d_curves[Channel], point);

    d_directPainter->drawSeries( d_curves[Channel],
                                 data->size() - 1, data->size() - 1 );
}
Ejemplo n.º 12
0
void Plot::updateCurve()
{
    CurveData *data = (CurveData *)d_curve->data();
    data->values().lock();

    const int numPoints = d_curve->data()->size();
    if ( numPoints > d_paintedPoints )
    {
        d_directPainter->drawSeries(d_curve, 
            d_paintedPoints - 1, numPoints - 1);
        d_paintedPoints = numPoints;
    }

    data->values().unlock();
}
Ejemplo n.º 13
0
void Wykres2d::aktualizuj()
{
    CurveData *data = static_cast<CurveData *> (plot2dCurve->data()); 
    data->clear();
    for (int i = 0; i < punkty.size(); i++) {
        
        data->append(punkty[i]);

    }

      
    
      plot2d->replot();
    
    
}
Ejemplo n.º 14
0
boost::shared_ptr<AnalyticCapFloorEngine> MustCapFloor::setEngineQuantLibLMM(){
	CurveData cData;
	// Fill out with some sample market data
	cData.sampleMktData(cData);
	//Date today(10, October, 2014);
	//Settings::instance().evaluationDate() = today;
	// Build a curve linked to this market data
	boost::shared_ptr<YieldTermStructure> ocurve = (cData.buildCurve(cData));

	// Link the curve to the term structure
	boost::shared_ptr<IborIndex> index = boost::shared_ptr<IborIndex>(new Euribor6M(forwardingTermStructure));
	Date todaysDate =
		myIndex->fixingCalendar().adjust(today);
	Settings::instance().evaluationDate() = todaysDate;

	this->forwardingTermStructure.linkTo(ocurve);

	

	const Size size = floatingLeg.size();
	boost::shared_ptr<LiborForwardModelProcess> process(
		new LiborForwardModelProcess(size, myIndex));

	//// set-up the model
	///*	const Real a = 0.02;
	//const Real b = 0.12;
	//const Real c = 0.1;
	//const Real d = 0.01;*/

	const Real a = 0.025;
	const Real b = 0.12;
	const Real c = 0.1;
	const Real d = 0.01;

	boost::shared_ptr<LmVolatilityModel> volaModel(
		new LmLinearExponentialVolatilityModel(process->fixingTimes(), a, b, c, d));

	boost::shared_ptr<LmCorrelationModel> corrModel(
		new LmLinearExponentialCorrelationModel(size, 0.1, 0.1));

	boost::shared_ptr<LiborForwardModel> liborModel(
		new LiborForwardModel(process, volaModel, corrModel));

return	boost::shared_ptr<AnalyticCapFloorEngine> (
		new AnalyticCapFloorEngine(liborModel, forwardingTermStructure));
}
Ejemplo n.º 15
0
void BrainPlot::timeStep(std::vector<float> data) {
    /*Curves*/
    for(int c = 0; c < nChannels; c++)
        appendPoint(QPointF(sample%plotLength, data[c]), c);

    /*Sweep line*/
    CurveData *sweep = static_cast<CurveData *>( d_sweep->data() );
    sweep->replace(0, QPointF((sample)%plotLength, plotLength));
    sweep->replace(1, QPointF((sample)%plotLength, 2*nChannels*minusExpectedAmplitude));
    setClipRegion(d_sweep, QPointF(0,0));
    d_directPainter->drawSeries( d_sweep, 0, 1);

    /*Time step*/
    sample++;

    /*Refreshes plot*/
    replot();
}
Ejemplo n.º 16
0
void StringToCurve::UpdateCurve()
{
  // Remove any existing curves
  while ( !m_OutCurveList->getCurveList().empty() ) {
    delete m_OutCurveList->getCurveList().back();
    m_OutCurveList->getCurveList().pop_back();
  }

  std::string dataString = f_CurveString->getStringValue();
  dataString.append( f_CurveSeparator->getStringValue() );

  std::string indexString = f_IndexString->getStringValue();
  std::vector< float > indexValues;
  if (indexString.length() != 0 ){
    StringToVector(indexString, indexValues );
  }

  if ( dataString.length() > 0 ){
    // Split string into curves
    std::vector<std::string> curves;
    boost::split(curves, dataString, boost::is_any_of(f_CurveSeparator->getStringValue() ));

    // Iterate over curves
    std::vector<std::string>::iterator stringIt = curves.begin();
    for (;stringIt < curves.end(); ++stringIt ){
      std::string curCurve = *stringIt;
      if (curCurve.length() == 0) {continue;}
      // Remove leading and trailing spaces
      boost::trim( curCurve );
      std::vector< MLfloat > curveValues;
      StringToVector( curCurve, curveValues );
      CurveData *outputCurve = new CurveData;
      outputCurve->setY( curveValues.size(),&curveValues[0], 1 );
      if ( f_IndexString->getStringValue().length() != 0 ){
        outputCurve->setX( indexValues.size(),&indexValues[0], 1 );
      }
      m_OutCurveList->getCurveList().push_back( outputCurve );
    }
  }
}
Ejemplo n.º 17
0
void Plot::appendPoint1(double u)
{
    double elapsed = d_clock.elapsed() / 1000.0;
    qDebug() << "d_clock1: " << elapsed;
    qDebug() << "udouble1: " << u;
    QPointF point(elapsed,(u*5/1024));
    CurveData *data = static_cast<CurveData *>( d_curve1->data() );
    data->append(point);
    RecToFile1(elapsed,u);

    const int numPoints = data->size();
    if ( numPoints > d_paintedPoints1 )
    {
        const bool doClip = !canvas()->testAttribute( Qt::WA_PaintOnScreen );
        if ( doClip )
        {
            /*
                Depending on the platform setting a clip might be an important
                performance issue. F.e. for Qt Embedded this reduces the
                part of the backing store that has to be copied out - maybe
                to an unaccelerated frame buffer device.
            */

            const QwtScaleMap xMap = canvasMap( d_curve1->xAxis() );
            const QwtScaleMap yMap = canvasMap( d_curve1->yAxis() );

            QRectF br = qwtBoundingRect( *data,
                d_paintedPoints1 - 1, numPoints - 1 );

            const QRect clipRect = QwtScaleMap::transform( xMap, yMap, br ).toRect();
            d_directPainter0->setClipRegion( clipRect );
        }

        d_directPainter0->drawSeries(d_curve1,
            d_paintedPoints1 - 1, numPoints - 1);
        d_paintedPoints1 = numPoints;
    }
}
Ejemplo n.º 18
0
BrainPlot::BrainPlot(QWidget *parent, int nChannels, int Length, int Amplitude):
    QwtPlot( parent ),
    d_curves( nChannels ),
    d_zeros( nChannels )
{
    /*Set some attributes*/
    minusExpectedAmplitude = -Amplitude;
    plotLength = Length;
    this->nChannels = nChannels;

    /*Start sample counter*/
    sample = 0;

    /*Painter*/
    d_directPainter = new QwtPlotDirectPainter( this );
    if ( QwtPainter::isX11GraphicsSystem() )
    {
#if QT_VERSION < 0x050000
        canvas()->setAttribute( Qt::WA_PaintOutsidePaintEvent, true );
#endif
        canvas()->setAttribute( Qt::WA_PaintOnScreen, true );
    }

    /*Activates the legend for channel tracking*/
    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode( QwtLegendData::ReadOnly);
    insertLegend( legend, QwtPlot::LeftLegend );

    /*Instantiate the reference lines and the data curves for each channel*/
    int Hfactor = 360/(nChannels+1);//different colors for each curve
    char name[15];

    for(int c = 0; c < nChannels; c++) {
        /*Curve*/
        sprintf(name, "Channel %d", c+1);
        d_curves[c] = new QwtPlotCurve( name);
        d_curves[c]->setData( new CurveData(plotLength,
                                            minusExpectedAmplitude*(2*c+1)) );
        d_curves[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 255));
        d_curves[c]->setStyle( QwtPlotCurve::Lines );
        d_curves[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol));
        d_curves[c]->attach( this );

        /*Reference line*/
        d_zeros[c] = new QwtPlotCurve;
        d_zeros[c]->setData( new CurveData() );
        d_zeros[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 140));
        d_zeros[c]->setStyle( QwtPlotCurve::Lines );
        d_zeros[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol));
        d_zeros[c]->setItemAttribute(QwtPlotItem::Legend, false);
        d_zeros[c]->attach( this );

        /*Draw reference lines*/
        CurveData *data = static_cast<CurveData *>( d_zeros[c]->data() );
        data->append(QPointF(0, minusExpectedAmplitude*(2*c+1)));
        data->append(QPointF(plotLength, minusExpectedAmplitude*(2*c+1)));
        d_directPainter->drawSeries( d_zeros[c], 0, 1);
    }

    /*Sweeping line*/
    d_sweep = new QwtPlotCurve;
    d_sweep->setData( new CurveData() );
    d_sweep->setPen( Qt::black, plotLength/100, Qt::SolidLine);
    d_sweep->setStyle( QwtPlotCurve::Lines );
    d_sweep->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol));
    d_sweep->setItemAttribute(QwtPlotItem::Legend, false);
    d_sweep->attach( this );

    CurveData *data = static_cast<CurveData *>( d_sweep->data() );
    data->append(QPointF(0, plotLength));
    data->append(QPointF(0, 2*nChannels*minusExpectedAmplitude));

    /*Axis*/
    setAxisScale( xBottom, 0, plotLength );
    setAxisScale( yLeft, 2*nChannels*minusExpectedAmplitude, 0 );

    enableAxis(xBottom, false);
    enableAxis(yLeft, false);

    /*Frame*/
    setFrameStyle( QFrame::NoFrame );
    setLineWidth( 0 );

    /*Canvas*/
    plotLayout()->setAlignCanvasToScales( true );
    plotLayout()->setCanvasMargin(100, QwtPlot::xBottom);
    plotLayout()->setCanvasMargin(100, QwtPlot::xTop);
    setCanvasBackground( Qt::black );

    /*Grid*/
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->setMajorPen( Qt::gray, 0, Qt::DotLine );
    grid->setMinorPen( Qt::gray, 0, Qt::DotLine );
    grid->enableYMin(true);
    grid->attach( this );

    /*Optimizaion for real-time data collecting*/
    setAutoReplot( false );

    /*Show*/
    replot();
}
Ejemplo n.º 19
0
void CSODistance::_process()
{   
  ML_TRACE_IN("void CSODistance::_process()");

  _outputXMarkerList->clearList();

  // Delete all created CurveData objects
  while ( !_outputCurveList->getCurveList().empty() ) {
    ML_DELETE( _outputCurveList->getCurveList().back() );
    _outputCurveList->getCurveList().pop_back();
  }

  if (_csoList0 != NULL) {

    int nCSOs = _csoList0->numCSO();

    double minDistance = 0.0;
    double maxDistance = 0.0;
    double avgDistance = 0.0;
    double stdDevDistance = 0.0;

    std::stringstream distances;
    distances << _tableHeader  << std::endl;


    switch ( _modeFld->getEnumValue() ){
      case FIRST2 :
      {
        if ((nCSOs >= 2) && (_csoList0->getCSOAt(0)->getIsFinished()) && (_csoList0->getCSOAt(1)->getIsFinished())) {
          std::vector<vec3>pointSet1;
          std::vector<vec3>pointSet2;
          
          _csoList0->getCSOAt(0)->fillPathPointCoordinatesFlattened(pointSet1);
          _csoList0->getCSOAt(1)->fillPathPointCoordinatesFlattened(pointSet2);

           Vector3 minPoint1,minPoint2,maxPoint1,maxPoint2;

           MinimalDistancePointClouds* pointSetsMinDist = NULL;
           ML_CHECK_NEW(pointSetsMinDist, MinimalDistancePointClouds);
           
           pointSetsMinDist->setPointSets(pointSet1, pointSet2);
           pointSetsMinDist->setNumEntries(200);
           pointSetsMinDist->computeDistance(minPoint1,minPoint2);

           minDistance = sqrt((minPoint1[0]-minPoint2[0])*(minPoint1[0]-minPoint2[0]) + 
                              (minPoint1[1]-minPoint2[1])*(minPoint1[1]-minPoint2[1]) + 
                              (minPoint1[2]-minPoint2[2])*(minPoint1[2]-minPoint2[2]));
                    


          _minimumDistanceFld->setFloatValue( static_cast<float>(minDistance));

          _outputXMarkerList->appendItem(XMarker( vec6(minPoint1[0],minPoint1[1],minPoint1[2],0.5f,0.0f,0.0f),
                                                  vec3(minPoint2[0]-minPoint1[0],minPoint2[1]-minPoint1[1],minPoint2[2]-minPoint1[2]),
                                                  0,""));
          distances << _csoList0->getCSOAt(0)->getId() << "," 
                    << _csoList0->getCSOAt(1)->getId() << "," 
                    << minDistance << "," 
                    << maxDistance << "," 
                    << avgDistance << "," 
                    << stdDevDistance 
                    << std::endl;
        } else {
          _minimumDistancePoint1Fld->setVec3fValue(vec3(0.0,0.0,0.0));
          _minimumDistancePoint2Fld->setVec3fValue(vec3(0.0,0.0,0.0));
          _minimumDistanceFld->setFloatValue(0.0f);
          _distancesFld->setStringValue( _tableHeader );
        }
        break;
      }
      case INPLANE:
      case INDEX:
      {
        CurveData *outputCurve = new CurveData;
        double    *yValues     = new double[ nCSOs ];

        double minDist = ML_DOUBLE_MAX;
        vec3 point1;
        vec3 point2;
        double averageMinDistance = 0.0;
        double averageMeanDistance = 0.0;
        double averageMaxDistance = 0.0;
        for ( int iCSO = 0; iCSO<nCSOs; ++iCSO ){
          CSO* currentCSO = _csoList0->getCSOAt( iCSO );
          CSO* matchingCSO = _findMatchingCSO(iCSO);
          if (!matchingCSO) {continue;}

          std::vector<vec3>pointSet1;
          std::vector<vec3>pointSet2;
          currentCSO->fillPathPointCoordinatesFlattened(pointSet1);
          matchingCSO->fillPathPointCoordinatesFlattened(pointSet2);

          Vector3 minPoint1,minPoint2,maxPoint1,maxPoint2;

          _getDistances( pointSet1, pointSet2,
                         minDistance,maxDistance,avgDistance,stdDevDistance,
                         minPoint1,minPoint2,maxPoint1,maxPoint2);

          averageMinDistance  += minDistance;
          averageMeanDistance += avgDistance;
          averageMaxDistance  += maxDistance;

          distances << currentCSO->getId()  << "," 
                    << matchingCSO->getId() << "," 
                    << minDistance << "," 
                    << maxDistance << "," 
                    << avgDistance << "," 
                    << stdDevDistance 
                    << std::endl;

          if ( minDistance < minDist ){
            minDist = minDistance;
            point1 = minPoint1;
            point2 = minPoint2;
          }

          _outputXMarkerList->appendItem(XMarker( vec6(minPoint1[0],minPoint1[1],minPoint1[2],0.5f,0.0f,0.0f),
                                                  vec3(minPoint2[0]-minPoint1[0],minPoint2[1]-minPoint1[1],minPoint2[2]-minPoint1[2]),
                                                  currentCSO->getId(),""));

          switch ( _curveStatistic->getEnumValue() ){
            case MIN:
              yValues[ iCSO ] = minDistance;
              break;
            case MAX:
              yValues[ iCSO ] = maxDistance;
              break;
            case MEAN:
              yValues[ iCSO ] = avgDistance;
              break;
            case STDEV:
              yValues[ iCSO ] = stdDevDistance;
              break;
            default:
              break;
          } 
        } // iCSO
        averageMinDistance  /= (nCSOs != 0 ? nCSOs : 1.0);
        averageMeanDistance /= (nCSOs != 0 ? nCSOs : 1.0);
        averageMaxDistance  /= (nCSOs != 0 ? nCSOs : 1.0);

        outputCurve->setY( nCSOs, yValues);
        delete[] yValues;
        _outputCurveList->getCurveList().push_back( outputCurve );
        _distancesFld->setStringValue( distances.str() );
        _minimumDistancePoint1Fld->setVec3fValue(point1);
        _minimumDistancePoint2Fld->setVec3fValue(point2);
        _minimumDistanceFld->setFloatValue( static_cast<float>(minDistance) );

        _AverageMinimumDistanceFld->setDoubleValue( averageMinDistance  );
        _AverageMeanDistanceFld->setDoubleValue(    averageMeanDistance );
        _AverageMaxDistanceFld->setDoubleValue(     averageMaxDistance  );



        break;
      }
    default:
      break;
    }

  } else {
    _minimumDistancePoint1Fld->setVec3fValue(vec3(0.0,0.0,0.0));
    _minimumDistancePoint2Fld->setVec3fValue(vec3(0.0,0.0,0.0));
    _minimumDistanceFld->setFloatValue(0.0f);
    _distancesFld->setStringValue( _tableHeader );
  }

  _outputXMarkerListFld->setBaseValue(_outputXMarkerList);
  _outputCurveListFld->touch();

}