void ViewerWidget::stopCameraPath(int id) { if(camera()->keyFrameInterpolator(id) && camera()->keyFrameInterpolator(id)->interpolationIsStarted()) { disconnect(camera()->keyFrameInterpolator(id), SIGNAL(interpolated()), this, SLOT(updateGL())); disconnect(camera()->keyFrameInterpolator(id), SIGNAL(interpolated()), this, SLOT(cameraPathInterpolated())); disconnect(camera()->keyFrameInterpolator(id), SIGNAL(endReached()), this, SLOT(cameraPathFinished())); camera()->keyFrameInterpolator(id)->stopInterpolation(); } }
void ViewerWidget::cameraPathFinished() { if(camera()->keyFrameInterpolator(m_current_camera_path)) { disconnect(camera()->keyFrameInterpolator(m_current_camera_path), SIGNAL(interpolated()), this, SLOT(updateGL())); disconnect(camera()->keyFrameInterpolator(m_current_camera_path), SIGNAL(interpolated()), this, SLOT(cameraPathInterpolated())); disconnect(camera()->keyFrameInterpolator(m_current_camera_path), SIGNAL(endReached()), this, SLOT(cameraPathFinished())); emit cameraPathStopped(m_current_camera_path); } }
void ViewerWidget::deleteCameraPath(int id) { if(camera()->keyFrameInterpolator(id)) { disconnect(camera()->keyFrameInterpolator(id), SIGNAL(interpolated()), this, SLOT(updateGL())); disconnect(camera()->keyFrameInterpolator(id), SIGNAL(interpolated()), this, SLOT(cameraPathInterpolated())); disconnect(camera()->keyFrameInterpolator(id), SIGNAL(endReached()), this, SLOT(cameraPathFinished())); camera()->deletePath(id); } }
void ViewerWidget::playCameraPath(int id, int start_frame) { qglviewer::KeyFrameInterpolator *kfi = camera()->keyFrameInterpolator(id); if(kfi && !kfi->interpolationIsStarted() && start_frame >= 0 && start_frame < kfi->numberOfKeyFrames()) { m_current_camera_path = id; m_current_camera_frame = start_frame; kfi->setInterpolationTime(kfi->keyFrameTime(start_frame)); std::cout << "Playing path of length " << kfi->numberOfKeyFrames() << ", start time " << kfi->keyFrameTime(start_frame) << std::endl; connect(kfi, SIGNAL(interpolated()), this, SLOT(updateGL())); connect(kfi, SIGNAL(interpolated()), this, SLOT(cameraPathInterpolated())); connect(kfi, SIGNAL(endReached()), this, SLOT(cameraPathFinished())); kfi->startInterpolation(); } }
Rate ZeroInflationIndex::forecastFixing(const Date& fixingDate) const { // the term structure is relative to the fixing value at the base date. Date baseDate = zeroInflation_->baseDate(); QL_REQUIRE(!needsForecast(baseDate), name() << " index fixing at base date is not available"); Real baseFixing = fixing(baseDate); Date effectiveFixingDate; if (interpolated()) { effectiveFixingDate = fixingDate; } else { // start of period is the convention // so it's easier to do linear interpolation on fixings effectiveFixingDate = inflationPeriod(fixingDate, frequency()).first; } // no observation lag because it is the fixing for the date // but if index is not interpolated then that fixing is constant // for each period, hence the t uses the effectiveFixingDate // However, it's slightly safe to get the zeroRate with the // fixingDate to avoid potential problems at the edges of periods Time t = zeroInflation_->dayCounter().yearFraction(baseDate, effectiveFixingDate); bool forceLinearInterpolation = false; Rate zero = zeroInflation_->zeroRate(fixingDate, Period(0,Days), forceLinearInterpolation); // Annual compounding is the convention for zero inflation rates (or quotes) return baseFixing * std::pow(1.0 + zero, t); }
GLViewer::GLViewer(QWidget *parent, GLHandler *iGLHandler, MainWindow *iMainWindow) : QGLViewer(parent), _glHandler(iGLHandler), _mainWindow(iMainWindow) { this->setAxisIsDrawn(false); this->setGridIsDrawn(true); this->setSceneRadius(50000.0); this->enableGravity = false; this->camera()->setFlySpeed(0.0093f); this->camera()->setViewDirection(qglviewer::Vec(1.0, 10.0, 8.0)); resetTimer = false; kfi_ = new KeyFrameInterpolator(new Frame()); QObject::connect(kfi_, SIGNAL(interpolated()), this, SLOT(update())); QObject::connect(kfi_, SIGNAL(endReached()), this, SLOT(resetKfi())); this->resetKfi (); if (enableGravity) { this->startTimer(200); } else { this->startTimer (200); } }
Real YoYInflationIndex::forecastFixing(const Date& fixingDate) const { Date d; if (interpolated()) { d = fixingDate; } else { // if the value is not interpolated use the starting value // by internal convention this will be consistent std::pair<Date,Date> lim = inflationPeriod(fixingDate, frequency_); d = lim.first; } return yoyInflation_->yoyRate(d,0*Days); }
GLViewer::GLViewer(QWidget *parent, const QGLWidget* constWidget, Qt::WindowFlags) :QGLViewer(parent, constWidget) { g_display_world_axis_ = true; g_display_vertices_ = false; g_display_wire_frame_ = false; g_display_flat_ = false; g_display_texture_ = false; g_set_key_frame_ = false; g_play_path_ = false; g_texture_id_ = -1; //------------ set the interpolation ------------------------------// // myFrame is the Frame that will be interpolated. qglviewer::Frame* myFrame = new qglviewer::Frame(); // Set myFrame as the KeyFrameInterpolator interpolated Frame. g_kfi_.setFrame(myFrame); g_kfi_.setLoopInterpolation(); connect(&g_kfi_, SIGNAL(interpolated()), SLOT(updateGL())); connect(&g_kfi_, SIGNAL(interpolated()), SLOT(setCamera())); }
int qglviewer::Frame::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: modified(); break; case 1: interpolated(); break; case 2: initFromDOMElement((*reinterpret_cast< const QDomElement(*)>(_a[1]))); break; default: ; } _id -= 3; } return _id; }
int qglviewer::KeyFrameInterpolator::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: interpolated(); break; case 1: endReached(); break; case 2: addKeyFrame((*reinterpret_cast< const Frame(*)>(_a[1]))); break; case 3: addKeyFrame((*reinterpret_cast< const Frame(*)>(_a[1])),(*reinterpret_cast< float(*)>(_a[2]))); break; case 4: addKeyFrame((*reinterpret_cast< const Frame*const(*)>(_a[1]))); break; case 5: addKeyFrame((*reinterpret_cast< const Frame*const(*)>(_a[1])),(*reinterpret_cast< float(*)>(_a[2]))); break; case 6: deletePath(); break; case 7: setFrame((*reinterpret_cast< Frame*const(*)>(_a[1]))); break; case 8: setInterpolationTime((*reinterpret_cast< float(*)>(_a[1]))); break; case 9: setInterpolationSpeed((*reinterpret_cast< float(*)>(_a[1]))); break; case 10: setInterpolationPeriod((*reinterpret_cast< int(*)>(_a[1]))); break; case 11: setLoopInterpolation((*reinterpret_cast< bool(*)>(_a[1]))); break; case 12: setLoopInterpolation(); break; case 13: setClosedPath((*reinterpret_cast< bool(*)>(_a[1]))); break; case 14: setClosedPath(); break; case 15: startInterpolation((*reinterpret_cast< int(*)>(_a[1]))); break; case 16: startInterpolation(); break; case 17: stopInterpolation(); break; case 18: resetInterpolation(); break; case 19: toggleInterpolation(); break; case 20: interpolateAtTime((*reinterpret_cast< float(*)>(_a[1]))); break; case 21: update(); break; case 22: invalidateValues(); break; default: ; } _id -= 23; } return _id; }
Rate YoYInflationIndex::fixing(const Date& fixingDate, bool /*forecastTodaysFixing*/) const { Date today = Settings::instance().evaluationDate(); Date todayMinusLag = today - availabilityLag_; std::pair<Date,Date> lim = inflationPeriod(todayMinusLag, frequency_); Date lastFix = lim.first-1; Date flatMustForecastOn = lastFix+1; Date interpMustForecastOn = lastFix+1 - Period(frequency_); if (interpolated() && fixingDate >= interpMustForecastOn) { return forecastFixing(fixingDate); } if (!interpolated() && fixingDate >= flatMustForecastOn) { return forecastFixing(fixingDate); } // four cases with ratio() and interpolated() const TimeSeries<Real>& ts = timeSeries(); if (ratio()) { if(interpolated()){ // IS ratio, IS interpolated std::pair<Date,Date> lim = inflationPeriod(fixingDate, frequency_); Date fixMinus1Y=NullCalendar().advance(fixingDate, -1*Years, ModifiedFollowing); std::pair<Date,Date> limBef = inflationPeriod(fixMinus1Y, frequency_); Real dp= lim.second + 1 - lim.first; Real dpBef=limBef.second + 1 - limBef.first; Real dl = fixingDate-lim.first; // potentially does not work on 29th Feb Real dlBef = fixMinus1Y - limBef.first; // get the four relevant fixings // recall that they are stored flat for every day Rate limFirstFix = ts[lim.first]; QL_REQUIRE(limFirstFix != Null<Rate>(), "Missing " << name() << " fixing for " << lim.first ); Rate limSecondFix = ts[lim.second+1]; QL_REQUIRE(limSecondFix != Null<Rate>(), "Missing " << name() << " fixing for " << lim.second+1 ); Rate limBefFirstFix = ts[limBef.first]; QL_REQUIRE(limBefFirstFix != Null<Rate>(), "Missing " << name() << " fixing for " << limBef.first ); Rate limBefSecondFix = IndexManager::instance().getHistory(name())[limBef.second+1]; QL_REQUIRE(limBefSecondFix != Null<Rate>(), "Missing " << name() << " fixing for " << limBef.second+1 ); Real linearNow = limFirstFix + (limSecondFix-limFirstFix)*dl/dp; Real linearBef = limBefFirstFix + (limBefSecondFix-limBefFirstFix)*dlBef/dpBef; Rate wasYES = linearNow / linearBef - 1.0; return wasYES; } else { // IS ratio, NOT interpolated Rate pastFixing = ts[fixingDate]; QL_REQUIRE(pastFixing != Null<Rate>(), "Missing " << name() << " fixing for " << fixingDate); Date previousDate = fixingDate - 1*Years; Rate previousFixing = ts[previousDate]; QL_REQUIRE(previousFixing != Null<Rate>(), "Missing " << name() << " fixing for " << previousDate ); return pastFixing/previousFixing - 1.0; } } else { // NOT ratio if (interpolated()) { // NOT ratio, IS interpolated std::pair<Date,Date> lim = inflationPeriod(fixingDate, frequency_); Real dp= lim.second + 1 - lim.first; Real dl = fixingDate-lim.first; Rate limFirstFix = ts[lim.first]; QL_REQUIRE(limFirstFix != Null<Rate>(), "Missing " << name() << " fixing for " << lim.first ); Rate limSecondFix = ts[lim.second+1]; QL_REQUIRE(limSecondFix != Null<Rate>(), "Missing " << name() << " fixing for " << lim.second+1 ); Real linearNow = limFirstFix + (limSecondFix-limFirstFix)*dl/dp; return linearNow; } else { // NOT ratio, NOT interpolated // so just flat Rate pastFixing = ts[fixingDate]; QL_REQUIRE(pastFixing != Null<Rate>(), "Missing " << name() << " fixing for " << fixingDate); return pastFixing; } } // QL_FAIL("YoYInflationIndex::fixing, should never get here"); }
/*! * \brief Save data and interpolation to specified file */ bool Data2D::saveWithInterpolation(const char* fileName) { // Open file and check that we're OK to proceed writing to it LineParser parser(fileName, true); msg.print("Writing datafile '%s'...\n", fileName); if (!parser.ready()) { msg.print("Couldn't open file '%s' for writing.\n", fileName); return false; } for (int n = 0; n<x_.nItems(); ++n) parser.writeLineF("%16.10e %16.10e %16.10e\n", x_.value(n), y_.value(n), interpolated(x_.value(n))); parser.closeFiles(); return true; }
QVariant sipQPropertyAnimation::sipProtectVirt_interpolated(bool sipSelfWasArg,const QVariant& a0,const QVariant& a1,qreal a2) const { return (sipSelfWasArg ? QVariantAnimation::interpolated(a0,a1,a2) : interpolated(a0,a1,a2)); }