Creator::Creator(QWidget *parent) : QWidget(parent) { _modifier = 0; qRegisterMetaType<MessageLevel>("MessageLevel"); qRegisterMetaType<cv::Mat>("cv::Mat"); qRegisterMetaType<CalibrationSet>("CalibrationSet"); qRegisterMetaType<QMatrix4x4>("QMatrix4x4"); qRegisterMetaType<PositionDesc>("PositionDesc"); ui.setupUi(this); // populate values to comboboxes ui.modifierCombo->addItem("None", QVariant(NoneModifier)); ui.modifierCombo->addItem("Canny", QVariant(CannyModifier)); // connections // Global application // shortcuts _shortcuts.push_back(new QShortcut(QKeySequence("Ctrl+s"), this)); _shortcuts.push_back(new QShortcut(QKeySequence("Alt+a"), this)); _shortcuts.push_back(new QShortcut(QKeySequence("Alt+n"), this)); connect(_shortcuts[0], SIGNAL(activated()), this, SLOT(SaveSettings())); connect(_shortcuts[1], SIGNAL(activated()), this, SLOT(AddPoint())); connect(_shortcuts[2], SIGNAL(activated()), this, SLOT(AddNewPoint())); // worker connects connect(this, SIGNAL(modeChangedSignal(int)), _capturer.GetWorker(), SLOT(SetMode(int))); connect(ui.renderer, SIGNAL( DescChangedSignal(PositionDesc&)), this, SLOT(FillActive(PositionDesc&))); // rendered connects connect(ui.renderGroup, SIGNAL(buttonClicked(int)), ui.renderer, SLOT(ChangeRenderStyle(int))); ui.renderGroup->setId(ui.renderPointsButton, RenderPoints); ui.renderGroup->setId(ui.renderWireframeButton, RenderWireframe); ui.renderGroup->setId(ui.renderFullButton, RenderComplete); connect(ui.loadButton, SIGNAL(clicked()), this, SLOT(LoadModel())); connect(ui.renderer, SIGNAL(reportSignal(MessageLevel, const QString &)), ui.infobox, SLOT(Report(MessageLevel, const QString&))); connect(ui.reloadShadersButton, SIGNAL(clicked()), ui.renderer, SLOT(ChangeShaders())); connect(ui.lockGroup, SIGNAL(buttonClicked(int)), ui.renderer, SLOT(ChangeActiveKeyPos(int))); ui.lockGroup->setId(ui.cameraRadioButton, PositionCamera); ui.lockGroup->setId(ui.modelRadioButton, PositionModel); ui.lockGroup->setId(ui.lightRadioButton, PositionLight); // videorender connections connect(ui.applyDescButton, SIGNAL(clicked()), this, SLOT(ChangeActiveDesc())); connect(ui.saveSettingsButton, SIGNAL(clicked(void)), this, SLOT(SaveSettings())); connect(ui.playButton, SIGNAL(clicked(void)), this, SLOT(PlayVideo())); connect(ui.pauseButton, SIGNAL(clicked(void)), this, SLOT(Pause(void))); connect(ui.cloudPoints, SIGNAL(Finished(void)), this, SLOT(EnablePlay())); connect(ui.cloudPoints, SIGNAL(reportSignal(MessageLevel, const QString &)), ui.infobox, SLOT(Report(MessageLevel, const QString&))); connect(ui.createMeshButton, SIGNAL(clicked()),this, SLOT(StartCreating())); //connect(ui.nextFrameButton, SIGNAL(clicked(void)), ui.cloudPoints, SLOT(RequestNextFrame())); //connect(ui.prevFrameButton, SIGNAL(clicked(void)), ui.cloudPoints, SLOT(RequestPrevFrame())); ui.nextFrameButton->setDisabled(true); ui.prevFrameButton->setDisabled(true); connect(ui.stopButton, SIGNAL(clicked(void)), this, SLOT(Stop(void))); connect(ui.featuresCheckbox, SIGNAL(clicked(void)), this, SLOT(FeaturesFromFrame())); connect(ui.stopButton, SIGNAL(clicked(void)), this, SLOT(Stop())); connect(ui.greyCheckBox, SIGNAL(clicked(void)), this, SLOT(ShowGreyFrame(void))); connect(ui.newButton, SIGNAL(clicked(void)), this, SLOT(CreateNew(void))); //calibration connects connect(ui.loadCalibrationButton, SIGNAL(clicked()), this, SLOT(LoadCalibration(void))); connect(ui.runCalibrationButton, SIGNAL(clicked()), this, SLOT(RunCalibration(void))); connect(ui.calibrationFolderButton, SIGNAL(clicked()), this, SLOT(LoadCalibrationImages())); connect(ui.applyCalibrationButton, SIGNAL(clicked()), this, SLOT(SendParameters())); connect(ui.playUndistortedButton, SIGNAL(clicked()), this, SLOT(ShowUndistorted())); connect(ui.saveCalibrationButton, SIGNAL(clicked()), this, SLOT(SaveCalibration())); connect(&_capturer, SIGNAL(imageReadySignal(cv::Mat)), ui.cloudPoints, SLOT(setImage(cv::Mat))); connect(&_capturer, SIGNAL(reportSignal(MessageLevel, const QString &)), ui.cloudPoints, SLOT(Report(MessageLevel, const QString &))); connect(_capturer.GetWorker(), SIGNAL(camParametersSignal(cv::Mat, cv::Mat)), ui.cloudPoints, SLOT(ShowParameters(cv::Mat, cv::Mat))); connect(ui.cloudPoints, SIGNAL(setCalibrationSignal(CalibrationSet)), _capturer.GetWorker(), SLOT(ChangeCalibration(CalibrationSet))); // comparer connects connect(ui.compareNext, SIGNAL(clicked()), this, SLOT(GetNextImagePair())); connect(this, SIGNAL(PreparePairSignal(int, int)), _capturer.GetWorker(), SLOT(PreparePair(int,int))); connect(_capturer.GetWorker(), SIGNAL(imagePairSignal(cv::Mat, cv::Mat)), this, SLOT(SetCompare(cv::Mat, cv::Mat))); connect(ui.applyModifierButton, SIGNAL(clicked()), this, SLOT(SetModifier())); //connect(ui.comparePrev, SIGNAL(clicked()), this, SLOT(GetPrevImagePair())); // rest of the initialization LoadSettings(); }
/* * Compute Gradient of I */ int Lgm_Grad_I( Lgm_Vector *v0, Lgm_Vector *GradI, Lgm_MagModelInfo *mInfo ) { Lgm_Vector u, Pa, Pb; double rat, H, h, a, b, SS, Sa, Sb, I, f[6], r; int i, N; /* * We want to compute the gradient of I at the point v0. * This requires 3 derivatives: one each in x, y and z directions. * We will try a fairly acurate difference scehme: * * f_0^(1) = 1/(60h) ( f_3 - 9f_2 + 45f_1 - 45f_-1 + 9f_-2 - f_-3 ) * See page 450 of CRC standard Math tables 28th edition. */ /* * Set h to a smallish value */ // h = 5e-2; h = 0.1; // h = 0.2; switch ( DIFF_SCHEME ) { case USE_SIX_POINT: N = 3; break; case USE_FOUR_POINT: N = 2; break; case USE_TWO_POINT: N = 1; break; } // User should set these? mInfo->Lgm_I_Integrator = DQAGS; mInfo->Lgm_I_Integrator_epsabs = 0.0; mInfo->Lgm_I_Integrator_epsrel = 1e-5; /* X-component */ mInfo->UseInterpRoutines = 1; if (mInfo->VerbosityLevel > 0) printf("\t\tComputing dIdx: h = %g\n", h); for (i=-N; i<=N; ++i){ if (i!=0) { // dont need the center value in our difference scheme u = *v0; H = (double)i*h; u.x += H; /* * Trace to southern mirror point */ if ( Lgm_TraceToMirrorPoint( &u, &Pa, &Sa, mInfo->Bm, -1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { /* * Trace to northern mirror point */ if ( Lgm_TraceToMirrorPoint( &Pa, &Pb, &SS, mInfo->Bm, 1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { r = Lgm_Magnitude( &Pb ); //mInfo->Hmax = SS/200.0; mInfo->Hmax = SS/(double)mInfo->nDivs; Lgm_TraceLine2( &Pa, &Pb, (r-1.0)*Re, 0.5*SS-mInfo->Hmax, 1.0, 1e-7, FALSE, mInfo ); ReplaceFirstPoint( 0.0, mInfo->Bm, &Pa, mInfo ); AddNewPoint( SS, mInfo->Bm, &Pb, mInfo ); InitSpline( mInfo ); mInfo->Lgm_I_integrand_S = 0.0; mInfo->Lgm_I_integrand_FirstCall = TRUE; mInfo->Lgm_n_I_integrand_Calls = 0; mInfo->Sm_South = 0.0; mInfo->Sm_North = SS; if ( SS <= 1e-5 ) { // if FL length is small, use an approx expression for I rat = mInfo->Bmin/mInfo->Bm; if ((1.0-rat) < 0.0) { I = 0.0; } else { // Eqn 2.66b in Roederer I = SS*sqrt(1.0 - rat); printf("HEREEEEEEEEEEEEEEEEEEEEEEe\n"); } } else { I = Iinv_interped( mInfo ); } if (mInfo->VerbosityLevel > 2) printf("I = %g Lgm_n_I_integrand_Calls = %d\n", I, mInfo->Lgm_n_I_integrand_Calls ); FreeSpline( mInfo ); } else { printf("\t\tMirror point below %g km in Southern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } } else { printf("\t\tMirror point below %g km in Northern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } f[i+N] = I; } } if (DIFF_SCHEME == USE_SIX_POINT){ GradI->x = (f[6] - 9.0*f[5] + 45.0*f[4] - 45.0*f[2] + 9.0*f[1] - f[0])/(60.0*h); } else if (DIFF_SCHEME == USE_FOUR_POINT){ GradI->x = (-f[4] + 8.0*f[3] - 8.0*f[1] + f[0])/(12.0*h); } else if (DIFF_SCHEME == USE_TWO_POINT){ GradI->x = (f[2] - f[0])/(2.0*h); } /* Y-component */ if (mInfo->VerbosityLevel > 0) printf("\t\tComputing dIdy: h = %g\n", h); for (i=-N; i<=N; ++i){ if (i!=0) { // dont need the center value in our difference scheme u = *v0; H = (double)i*h; u.y += H; /* * Trace to southern mirror point */ if ( Lgm_TraceToMirrorPoint( &u, &Pa, &Sa, mInfo->Bm, -1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { /* * Trace to northern mirror point */ if ( Lgm_TraceToMirrorPoint( &Pa, &Pb, &SS, mInfo->Bm, 1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { r = Lgm_Magnitude( &Pb ); //mInfo->Hmax = SS/200.0; mInfo->Hmax = SS/(double)mInfo->nDivs; Lgm_TraceLine2( &Pa, &Pb, (r-1.0)*Re, 0.5*SS-mInfo->Hmax, 1.0, 1e-7, FALSE, mInfo ); ReplaceFirstPoint( 0.0, mInfo->Bm, &Pa, mInfo ); AddNewPoint( SS, mInfo->Bm, &Pb, mInfo ); InitSpline( mInfo ); mInfo->Lgm_I_integrand_S = 0.0; mInfo->Lgm_I_integrand_FirstCall = TRUE; mInfo->Lgm_n_I_integrand_Calls = 0; mInfo->Sm_South = 0.0; mInfo->Sm_North = SS; if ( SS <= 1e-5 ) { // if FL length is small, use an approx expression for I rat = mInfo->Bmin/mInfo->Bm; if ((1.0-rat) < 0.0) { I = 0.0; } else { // Eqn 2.66b in Roederer I = SS*sqrt(1.0 - rat); } } else { I = Iinv_interped( mInfo ); } if (mInfo->VerbosityLevel > 2) printf("I = %g Lgm_n_I_integrand_Calls = %d\n", I, mInfo->Lgm_n_I_integrand_Calls ); FreeSpline( mInfo ); } else { printf("\t\tMirror point below %g km in Southern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } } else { printf("\t\tMirror point below %g km in Northern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } f[i+N] = I; } } if (DIFF_SCHEME == USE_SIX_POINT){ GradI->y = (f[6] - 9.0*f[5] + 45.0*f[4] - 45.0*f[2] + 9.0*f[1] - f[0])/(60.0*h); } else if (DIFF_SCHEME == USE_FOUR_POINT){ GradI->y = (-f[4] + 8.0*f[3] - 8.0*f[1] + f[0])/(12.0*h); } else if (DIFF_SCHEME == USE_TWO_POINT){ GradI->y = (f[2] - f[0])/(2.0*h); } /* Z-component */ if (mInfo->VerbosityLevel > 0) printf("\t\tComputing dIdz: h = %g\n", h); for (i=-N; i<=N; ++i){ if (i!=0) { // dont need the center value in our difference scheme u = *v0; H = (double)i*h; u.z += H; /* * Trace to southern mirror point */ if ( Lgm_TraceToMirrorPoint( &u, &Pa, &Sa, mInfo->Bm, -1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { /* * Trace to northern mirror point */ if ( Lgm_TraceToMirrorPoint( &Pa, &Pb, &SS, mInfo->Bm, 1.0, mInfo->Lgm_TraceToMirrorPoint_Tol, mInfo ) > 0 ) { r = Lgm_Magnitude( &Pb ); //mInfo->Hmax = SS/200.0; mInfo->Hmax = SS/(double)mInfo->nDivs; Lgm_TraceLine2( &Pa, &Pb, (r-1.0)*Re, 0.5*SS-mInfo->Hmax, 1.0, 1e-7, FALSE, mInfo ); ReplaceFirstPoint( 0.0, mInfo->Bm, &Pa, mInfo ); AddNewPoint( SS, mInfo->Bm, &Pb, mInfo ); InitSpline( mInfo ); mInfo->Lgm_I_integrand_S = 0.0; mInfo->Lgm_I_integrand_FirstCall = TRUE; mInfo->Lgm_n_I_integrand_Calls = 0; mInfo->Sm_South = 0.0; mInfo->Sm_North = SS; if ( SS <= 1e-5 ) { // if FL length is small, use an approx expression for I rat = mInfo->Bmin/mInfo->Bm; if ((1.0-rat) < 0.0) { I = 0.0; } else { // Eqn 2.66b in Roederer I = SS*sqrt(1.0 - rat); } } else { I = Iinv_interped( mInfo ); } if (mInfo->VerbosityLevel > 2) printf("I = %g Lgm_n_I_integrand_Calls = %d\n", I, mInfo->Lgm_n_I_integrand_Calls ); FreeSpline( mInfo ); } else { printf("\t\tMirror point below %g km in Southern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } } else { printf("\t\tMirror point below %g km in Northern Hemisphere\n", mInfo->Lgm_LossConeHeight); exit(0); } f[i+N] = I; } } if (DIFF_SCHEME == USE_SIX_POINT){ GradI->z = (f[6] - 9.0*f[5] + 45.0*f[4] - 45.0*f[2] + 9.0*f[1] - f[0])/(60.0*h); } else if (DIFF_SCHEME == USE_FOUR_POINT){ GradI->z = (-f[4] + 8.0*f[3] - 8.0*f[1] + f[0])/(12.0*h); } else if (DIFF_SCHEME == USE_TWO_POINT){ GradI->z = (f[2] - f[0])/(2.0*h); } return(0); }
void ActiveTrack::AddPointNow( bool do_add_point ) { wxDateTime now = wxDateTime::Now(); if( m_prev_dist < 0.0005 ) // avoid zero length segs if( !do_add_point ) return; if( m_prev_time.IsValid() ) if( m_prev_time == now ) // avoid zero time segs if( !do_add_point ) return; vector2D gpsPoint( gLon, gLat ); // The dynamic interval algorithm will gather all track points in a queue, // and analyze the cross track errors for each point before actually adding // a point to the track. switch( trackPointState ) { case firstPoint: { TrackPoint *pTrackPoint = AddNewPoint( gpsPoint, now.ToUTC() ); m_lastStoredTP = pTrackPoint; trackPointState = secondPoint; do_add_point = false; break; } case secondPoint: { vector2D pPoint( gLon, gLat ); skipPoints.push_back( pPoint ); skipTimes.push_back( now.ToUTC() ); trackPointState = potentialPoint; break; } case potentialPoint: { if( gpsPoint == skipPoints[skipPoints.size()-1] ) break; unsigned int xteMaxIndex = 0; double xteMax = 0; // Scan points skipped so far and see if anyone has XTE over the threshold. for( unsigned int i=0; i<skipPoints.size(); i++ ) { double xte = GetXTE( m_lastStoredTP->m_lat, m_lastStoredTP->m_lon, gLat, gLon, skipPoints[i].lat, skipPoints[i].lon ); if( xte > xteMax ) { xteMax = xte; xteMaxIndex = i; } } if( xteMax > m_allowedMaxXTE ) { TrackPoint *pTrackPoint = AddNewPoint( skipPoints[xteMaxIndex], skipTimes[xteMaxIndex] ); pSelect->AddSelectableTrackSegment( m_lastStoredTP->m_lat, m_lastStoredTP->m_lon, pTrackPoint->m_lat, pTrackPoint->m_lon, m_lastStoredTP, pTrackPoint, this ); m_prevFixedTP = m_fixedTP; m_fixedTP = m_removeTP; m_removeTP = m_lastStoredTP; m_lastStoredTP = pTrackPoint; for( unsigned int i=0; i<=xteMaxIndex; i++ ) { skipPoints.pop_front(); skipTimes.pop_front(); } // Now back up and see if we just made 3 points in a straight line and the middle one // (the next to last) point can possibly be eliminated. Here we reduce the allowed // XTE as a function of leg length. (Half the XTE for very short legs). if( GetnPoints() > 2 ) { double dist = DistGreatCircle( m_fixedTP->m_lat, m_fixedTP->m_lon, m_lastStoredTP->m_lat, m_lastStoredTP->m_lon ); double xte = GetXTE( m_fixedTP, m_lastStoredTP, m_removeTP ); if( xte < m_allowedMaxXTE / wxMax(1.0, 2.0 - dist*2.0) ) { TrackPoints.pop_back(); TrackPoints.pop_back(); TrackPoints.push_back( m_lastStoredTP ); pSelect->DeletePointSelectableTrackSegments( m_removeTP ); pSelect->AddSelectableTrackSegment( m_fixedTP->m_lat, m_fixedTP->m_lon, m_lastStoredTP->m_lat, m_lastStoredTP->m_lon, m_fixedTP, m_lastStoredTP, this ); delete m_removeTP; m_removeTP = m_fixedTP; m_fixedTP = m_prevFixedTP; } } } skipPoints.push_back( gpsPoint ); skipTimes.push_back( now.ToUTC() ); break; } } // Check if this is the last point of the track. if( do_add_point ) { TrackPoint *pTrackPoint = AddNewPoint( gpsPoint, now.ToUTC() ); pSelect->AddSelectableTrackSegment( m_lastStoredTP->m_lat, m_lastStoredTP->m_lon, pTrackPoint->m_lat, pTrackPoint->m_lon, m_lastStoredTP, pTrackPoint, this ); } m_prev_time = now; }