void QtMinimalWidget::paintGL() { ++m_benchmarkFrameCount; SceniXQGLSceneRendererWidget::paintGL(); if ( getContinuousUpdate() && ( m_orbitRadians != 0.0f ) ) { DP_ASSERT( getViewState() && getViewState()->getCamera() ); getViewState()->getCamera()->orbitY( getViewState()->getCamera()->getFocusDistance(), m_orbitRadians ); } // fps counter if ( m_showFPS ) { if ( m_benchmarkFrameCount == 1 ) { m_frameRateTimer.start(); } else { DP_ASSERT( 1 < m_benchmarkFrameCount ); double elapsedSeconds = m_frameRateTimer.getTime(); ++m_frameCount; if ( elapsedSeconds > 1.0 ) { double fps = double(m_frameCount) / elapsedSeconds; m_benchmarkTime += elapsedSeconds; std::ostringstream windowTitle; windowTitle.precision(2); windowTitle.setf( std::ios::fixed, std::ios::floatfield ); windowTitle << m_windowTitle << ", " << fps << " FPS"; if ( m_benchmarkFrames != ~0 ) { windowTitle << " Benchmark " << m_benchmarkFrameCount-1 << "/" << m_benchmarkFrames; } else if ( 0.0 < m_benchmarkDuration ) { windowTitle << " Benchmark " << m_benchmarkTime << "/" << m_benchmarkDuration; } setWindowTitle( windowTitle.str().c_str() ); m_frameCount = 0; m_frameRateTimer.restart(); } } } if ( ( ( m_benchmarkFrames != ~0 ) && ( m_benchmarkFrames == m_benchmarkFrameCount-1 ) ) || ( ( 0.0 < m_benchmarkDuration ) && ( m_benchmarkDuration <= m_benchmarkTime ) ) ) { m_frameRateTimer.stop(); QCoreApplication::instance()->exit( int(100 * double(m_benchmarkFrameCount-1) / m_benchmarkTime) ); } }
bool TrackballTransformManipulator::updateFrame( float dt ) { bool result = false; if( m_transformPath && getViewState() && getRenderTarget() ) { switch( m_mode ) { case Mode::ROTATE: result = rotate(); break; case Mode::PAN: result = pan(); break; case Mode::DOLLY: result = dolly(); break; default: break; } } return result; }
void QtMinimalWidget::keyPressEvent( QKeyEvent *event ) { SceniXQGLWidget::keyPressEvent( event ); if ( ( event->text().compare( " " ) == 0 ) && ! getContinuousUpdate() ) { repaint(); } else if ( event->text().compare( "d" ) == 0 ) { dp::sg::renderer::rix::gl::SceneRendererSharedPtr const& renderer = getSceneRenderer().staticCast<dp::sg::renderer::rix::gl::SceneRenderer>(); renderer->setDepthPass( ! renderer->getDepthPass() ); } else if ( event->text().compare("s") == 0 ) { screenshot(); } else if ( event->text().compare( "o" ) == 0 ) { dp::sg::algorithm::optimizeScene( getViewState()->getScene(), true, true , dp::sg::algorithm::CombineTraverser::CT_ALL_TARGETS_MASK , dp::sg::algorithm::EliminateTraverser::ET_ALL_TARGETS_MASK , dp::sg::algorithm::UnifyTraverser::UT_ALL_TARGETS_MASK , FLT_EPSILON ); } else if ( event->text().compare("x") == 0 ) { dp::gl::RenderContextFormat format = getFormat(); format.setStereo( !format.isStereo() ); setFormat( format ); } }
bool TrackballTransformManipulator::dolly() { int dyScreen = getLastY() - getCurrentY(); if( !dyScreen ) { dyScreen = getWheelTicksDelta(); } if ( dyScreen ) { DP_ASSERT( getViewState()->getCamera().isPtrTo<FrustumCamera>() ); TransformSharedPtr transform = m_transformPath->getTail().staticCast<Transform>(); FrustumCameraSharedPtr const& camera = getViewState()->getCamera().staticCast<FrustumCamera>(); if ( camera && transform ) { unsigned int rtWidth = getRenderTarget()->getWidth(); unsigned int rtHeight = getRenderTarget()->getHeight(); Vec2f camWinSize = camera->getWindowSize(); if ( ( 0 < rtHeight ) && ( 0 < rtWidth ) && ( FLT_EPSILON < fabs( camWinSize[0] ) ) && ( FLT_EPSILON < fabs( camWinSize[1] ) ) ) { // get all the matrices needed here Mat44f m2w, w2m, w2v, v2w; m_transformPath->getModelToWorldMatrix(m2w, w2m); // model->world and world->model w2v = camera->getWorldToViewMatrix(); // world->view v2w = camera->getViewToWorldMatrix(); // view->world // transfer mouse delta into view space float dyView = camWinSize[1]/rtHeight * dyScreen; // transfer the mouse delta vector into the model space Vec4f modelDelta = Vec4f( 0.0f, 0.0f, dyView, 0.0f ) * v2w * w2m; // minus the delta to the translation of the transform // minus, because we want mouse down to move the object into the direction of the user Trafo trafo = transform->getTrafo(); trafo.setTranslation( trafo.getTranslation() - Vec3f( modelDelta ) ); transform->setTrafo( trafo ); return true; } } } return false; }
void MycosmosController::downloadFinished(QNetworkReply *reply){ QUrl url = reply->url(); if(reply->error() == QNetworkReply::NoError) { // Get the http status code int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (v >= 200 && v < 300){ // Success } else if (v >= 300 && v < 400) {// Redirection // Get the redirection url QUrl newUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); // Because the redirection url can be relative, // we have to use the previous one to resolve it newUrl = reply->url().resolved(newUrl); // QNetworkAccessManager *manager = nReply->manager(); // QNetworkRequest redirection(newUrl); // QNetworkReply *newReply = manager->get(redirection); return; // to keep the manager for the next request } // Here we got the final reply htmlReplyText = QString::fromUtf8(reply->readAll()); // get view state string viewStateString = getViewState(htmlReplyText); QList<QNetworkCookie> cookies = nManager->cookieJar()->cookiesForUrl(url); for(int i=0; i<cookies.count(); i++){ printf("COOKIE %d Name:%s Value:%s\n" ,i,qPrintable(QString::fromUtf8(cookies.at(i).name())),qPrintable(QString::fromUtf8(cookies.at(i).value())) ); } printf("COOKIES for %s\n%s\n" ,qPrintable(url.host()) ,qPrintable(QString::number(cookies.count()))); // save cookies inside a QVariant cookieData.setValue(cookies); emit successfulResponse(); } else { // Error printf("Download of %s failed: %s\n",url.toEncoded().constData(),qPrintable(reply->errorString())); } printf("Url encoded Νένα 1:%s\n" ,qPrintable(QUrl::toPercentEncoding("Νένα 1",0,0))); // We receive ownership of the reply object // and therefore need to handle deletion. // delete reply; }
bool TrackballTransformManipulator::rotate() { if ( ( getCurrentX() != getLastX() ) || ( getCurrentY() != getLastY() ) ) { DP_ASSERT( getViewState()->getCamera().isPtrTo<FrustumCamera>() ); TransformSharedPtr transform = m_transformPath->getTail().staticCast<Transform>(); FrustumCameraSharedPtr const& camera = getViewState()->getCamera().staticCast<FrustumCamera>(); if ( camera && transform ) { unsigned int rtWidth = getRenderTarget()->getWidth(); unsigned int rtHeight = getRenderTarget()->getHeight(); Vec2f camWinSize = camera->getWindowSize(); if ( ( 0 < rtHeight ) && ( 0 < rtWidth ) && ( FLT_EPSILON < fabs( camWinSize[0] ) ) && ( FLT_EPSILON < fabs( camWinSize[1] ) ) ) { // get all the matrices needed here Mat44f m2w, w2m, w2v, v2w, v2s, m2v; m_transformPath->getModelToWorldMatrix( m2w, w2m ); // model->world and world->model w2v = camera->getWorldToViewMatrix(); // world->view v2w = camera->getViewToWorldMatrix(); // view->world v2s = camera->getProjection(); // view->screen (normalized) m2v = m2w * w2v; const Sphere3f& bs = transform->getBoundingSphere(); // center of the object in view coordinates Vec4f centerV = Vec4f( bs.getCenter(), 1.0f ) * m2v; DP_ASSERT( fabs( centerV[3] - 1.0f ) < FLT_EPSILON ); // center of the object in normalized screen coordinates Vec4f centerNS = centerV * v2s; DP_ASSERT( centerNS[3] != 0.0f ); centerNS /= centerNS[3]; // center of the object in screen space Vec2f centerS( rtWidth * ( 1 + centerNS[0] ) / 2, rtHeight * ( 1 - centerNS[1] ) / 2 ); // move the input points relative to the center // move the input points absolutely //Vec2f last( m_orbitCursor ); Vec2f last( getLastCursorPosition() ); Vec2f p0( last[0] - centerS[0], centerS[1] - last[1] ); Vec2f p1( getCurrentX() - centerS[0], centerS[1] - getCurrentY() ); DP_ASSERT( p0[0] != p1[0] || p0[1] != p1[1] ); // get the scaling (from model to view) Vec3f scaling, translation; Quatf orientation, scaleOrientation; decompose( m2v, translation, orientation, scaling, scaleOrientation ); float maxScale = std::max( scaling[0], std::max( scaling[1], scaling[2] ) ); DP_ASSERT( FLT_EPSILON < fabs( maxScale ) ); // determine the radius in screen space (in the centers depth) Vec2f centerWindowSize = - centerV[2] / getViewState()->getTargetDistance() * camWinSize; float radius = bs.getRadius() * maxScale * rtWidth / centerWindowSize[0]; // with p0, p1, and the radius determine the axis and angle of rotation via the Trackball utility // => axis is in view space then Vec3f axis; float angle; m_trackball.setSize( radius ); m_trackball.apply( p0, p1, axis, angle ); float dx = p1[0]-p0[0]; float dy = p1[1]-p0[1]; checkLockAxis(dx, dy); if ( m_activeLockAxis[static_cast<size_t>(Axis::X)] ) { if ( dx < 0 ) axis = Vec3f(0.f, -1.f, 0.f); else if ( dx > 0) axis = Vec3f(0.f, 1.f, 0.f); else return false; } else if ( m_activeLockAxis[static_cast<size_t>(Axis::Y)] ) { if ( dy < 0 ) axis = Vec3f(1.f, 0.f, 0.f); else if ( dy > 0) axis = Vec3f(-1.f, 0.f, 0.f); else return false; } // transform axis back into model space axis = Vec3f( Vec4f( axis, 0.0f ) * v2w * w2m ); axis.normalize(); // create the rotation around the center (in model space) Trafo trafo; trafo.setCenter( bs.getCenter() ); trafo.setOrientation( Quatf( axis, angle ) ); // concatenate this rotation with the current transformation trafo.setMatrix( transform->getTrafo().getMatrix() * trafo.getMatrix() ); // concatenate this rotation with the original transformation //trafo.setMatrix( m_matrix * trafo.getMatrix() ); // set the current transform transform->setTrafo( trafo ); return true; } } } return false; }
bool TrackballTransformManipulator::pan() { int dxScreen = getCurrentX() - getLastX(); int dyScreen = getLastY() - getCurrentY(); if ( dxScreen || dyScreen ) { DP_ASSERT( getViewState()->getCamera().isPtrTo<FrustumCamera>() ); TransformSharedPtr transform = m_transformPath->getTail().staticCast<Transform>(); FrustumCameraSharedPtr const& camera = getViewState()->getCamera().staticCast<FrustumCamera>(); if ( camera && transform ) { unsigned int rtWidth = getRenderTarget()->getWidth(); unsigned int rtHeight = getRenderTarget()->getHeight(); Vec2f camWinSize = camera->getWindowSize(); if ( ( 0 < rtHeight ) && ( 0 < rtWidth ) && ( FLT_EPSILON < fabs( camWinSize[0] ) ) && ( FLT_EPSILON < fabs( camWinSize[1] ) ) ) { // get all the matrices needed here Mat44f m2w, w2m; m_transformPath->getModelToWorldMatrix(m2w, w2m); // model->world and world->model Mat44f w2v = camera->getWorldToViewMatrix(); // world->view Mat44f v2w = camera->getViewToWorldMatrix(); // view->world // center of the object in view coordinates Vec4f center = Vec4f( transform->getBoundingSphere().getCenter(), 1.0f ) * m2w * w2v; // window size at distance of the center of the object Vec2f centerWindowSize = - center[2] / getViewState()->getTargetDistance() * camWinSize; checkLockAxis(dxScreen, dyScreen); if ( m_activeLockAxis[static_cast<size_t>(Axis::X)] ) { if ( dxScreen != 0 ) { dyScreen = 0; } else { return false; } } else if ( m_activeLockAxis[static_cast<size_t>(Axis::Y)] ) { if ( dyScreen != 0) { dxScreen = 0; } else { return false; } } // delta in model coordinates Vec4f viewCenter( centerWindowSize[0] * dxScreen / rtWidth , centerWindowSize[1] * dyScreen / rtHeight, 0.f, 0.f ); Vec4f modelDelta = viewCenter * v2w * w2m; // add the delta to the translation of the transform Trafo trafo = transform->getTrafo(); trafo.setTranslation( trafo.getTranslation() + Vec3f( modelDelta ) ); transform->setTrafo( trafo ); return true; } } } return false; }
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { tex_update.lock(); wxPaintDC dc(this); const wxSize ClientSize = GetClientSize(); long double currentZoom = zoom; if (mouseZoom != 1) { currentZoom = mouseZoom; mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2; if (fabs(mouseZoom-1.0)<0.01) { mouseZoom = 1; } } if (scaleMove != 0) { SpectrumVisualProcessor *sp = wxGetApp().getSpectrumProcessor(); FFTVisualDataThread *wdt = wxGetApp().getAppFrame()->getWaterfallDataThread(); SpectrumVisualProcessor *wp = wdt->getProcessor(); float factor = sp->getScaleFactor(); factor += scaleMove * 0.02; if (factor < 0.25) { factor = 0.25; } if (factor > 10.0) { factor = 10.0; } sp->setScaleFactor(factor); wp->setScaleFactor(factor); } if (freqMove != 0.0) { long long newFreq = getCenterFrequency() + (long long)((long double)getBandwidth()*freqMove) * 0.01; long long minFreq = bandwidth/2; if (newFreq < minFreq) { newFreq = minFreq; } updateCenterFrequency(newFreq); if (!freqMoving) { freqMove -= (freqMove * 0.2); if (fabs(freqMove) < 0.01) { freqMove = 0.0; } } } long long bw; if (currentZoom != 1) { long long freq = wxGetApp().getFrequency(); bw = getBandwidth(); double mpos = 0; float mouseInView = false; if (mouseTracker.mouseInView()) { mpos = mouseTracker.getMouseX(); mouseInView = true; } else if (spectrumCanvas && spectrumCanvas->getMouseTracker()->mouseInView()) { mpos = spectrumCanvas->getMouseTracker()->getMouseX(); mouseInView = true; } if (currentZoom < 1) { bw = (long long) ceil((long double) bw * currentZoom); if (bw < minBandwidth) { bw = minBandwidth; } if (mouseInView) { long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth()); long long mfreqB = getFrequencyAt(mpos, centerFreq, bw); centerFreq += mfreqA - mfreqB; } setView(centerFreq, bw); } else { if (isView) { bw = (long long) ceil((long double) bw * currentZoom); if (bw >= wxGetApp().getSampleRate()) { disableView(); if (spectrumCanvas) { spectrumCanvas->disableView(); } bw = wxGetApp().getSampleRate(); centerFreq = wxGetApp().getFrequency(); } else { if (mouseInView) { long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth()); long long mfreqB = getFrequencyAt(mpos, centerFreq, bw); centerFreq += mfreqA - mfreqB; setBandwidth(bw); } else { setBandwidth(bw); } } } } if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) { centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2; } if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) { centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2; } if (spectrumCanvas) { if ((spectrumCanvas->getCenterFrequency() != centerFreq) || (spectrumCanvas->getBandwidth() != bw)) { if (getViewState()) { spectrumCanvas->setView(centerFreq,bw); } else { spectrumCanvas->disableView(); spectrumCanvas->setCenterFrequency(centerFreq); spectrumCanvas->setBandwidth(bw); } } } } glContext->SetCurrent(*this); initGLExtensions(); glViewport(0, 0, ClientSize.x, ClientSize.y); if (fft_size_changed.load()) { fft_size = new_fft_size; waterfallPanel.setup(fft_size, waterfall_lines); fft_size_changed.store(false); } glContext->BeginDraw(0,0,0); waterfallPanel.calcTransform(CubicVR::mat4::identity()); waterfallPanel.draw(); std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators(); DemodulatorInstance *activeDemodulator = wxGetApp().getDemodMgr().getActiveDemodulator(); DemodulatorInstance *lastActiveDemodulator = wxGetApp().getDemodMgr().getLastActiveDemodulator(); bool isNew = shiftDown || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); int currentBandwidth = getBandwidth(); long long currentCenterFreq = getCenterFrequency(); ColorTheme *currentTheme = ThemeMgr::mgr.currentTheme; std::string last_type = wxGetApp().getDemodMgr().getLastDemodulatorType(); if (mouseTracker.mouseInView() || wxGetApp().getDemodMgr().getActiveDemodulator()) { hoverAlpha += (1.0f-hoverAlpha)*0.1f; if (hoverAlpha > 1.5f) { hoverAlpha = 1.5f; } glContext->setHoverAlpha(hoverAlpha); if (nextDragState == WF_DRAG_RANGE) { float width = (1.0 / (float) ClientSize.x); float rangeWidth = mouseTracker.getOriginDeltaMouseX(); float centerPos; if (mouseTracker.mouseDown()) { if (rangeWidth) { width = rangeWidth; } centerPos = mouseTracker.getOriginMouseX() + width / 2.0; } else { centerPos = mouseTracker.getMouseX(); } glContext->DrawDemod(lastActiveDemodulator, isNew?currentTheme->waterfallHighlight:currentTheme->waterfallDestroy, currentCenterFreq, currentBandwidth); if ((last_type == "LSB" || last_type == "USB") && mouseTracker.mouseDown()) { centerPos = mouseTracker.getMouseX(); glContext->DrawRangeSelector(centerPos, centerPos-width, isNew?currentTheme->waterfallNew:currentTheme->waterfallHover); } else { glContext->DrawFreqSelector(centerPos, isNew?currentTheme->waterfallNew:currentTheme->waterfallHover, width, currentCenterFreq, currentBandwidth); } } else { if (lastActiveDemodulator) { glContext->DrawDemod(lastActiveDemodulator, ((isNew && activeDemodulator == NULL) || (activeDemodulator != NULL))?currentTheme->waterfallHighlight:currentTheme->waterfallDestroy, currentCenterFreq, currentBandwidth); } if (activeDemodulator == NULL) { glContext->DrawFreqSelector(mouseTracker.getMouseX(), ((isNew && lastActiveDemodulator) || (!lastActiveDemodulator) )?currentTheme->waterfallNew:currentTheme->waterfallHover, 0, currentCenterFreq, currentBandwidth); } else { glContext->DrawDemod(activeDemodulator, currentTheme->waterfallHover, currentCenterFreq, currentBandwidth); } } } else { hoverAlpha += (0.0f-hoverAlpha)*0.05f; if (hoverAlpha < 1.0e-5f) { hoverAlpha = 0; } glContext->setHoverAlpha(hoverAlpha); if (activeDemodulator) { glContext->DrawDemod(activeDemodulator, currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth); } if (lastActiveDemodulator) { glContext->DrawDemod(lastActiveDemodulator, currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth); } } glContext->setHoverAlpha(0); for (int i = 0, iMax = demods.size(); i < iMax; i++) { if (activeDemodulator == demods[i] || lastActiveDemodulator == demods[i]) { continue; } glContext->DrawDemod(demods[i], currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth); } glContext->EndDraw(); SwapBuffers(); tex_update.unlock(); }