arma::mat Vespucci::Math::Transform::cwt_spdbc_mat(const arma::mat &X, std::string wavelet, arma::uword qscale, double threshold, std::string threshold_method, arma::uword window_size, arma::field<arma::umat> &peak_positions, arma::mat &baselines) { baselines.set_size(X.n_rows, X.n_cols); arma::vec baseline; arma::vec spectrum; arma::vec current_corrected; arma::mat corrected(X.n_rows, X.n_cols); arma::umat current_peakpos; peak_positions.set_size(X.n_cols); arma::uword i; try{ for (i = 0; i < X.n_cols; ++i){ spectrum = X.col(i); current_corrected = Vespucci::Math::Transform::cwt_spdbc(spectrum, wavelet, qscale, threshold, threshold_method, window_size, current_peakpos, baseline); peak_positions(i) = current_peakpos; baselines.col(i) = baseline; corrected.col(i) = current_corrected; } }catch(std::exception e){ std::cerr << std::endl << "exception! cwt_spdbc_mat" << std::endl; std::cerr << "i = " << i << std::endl; std::cerr << e.what(); throw(e); } return corrected; }
bool StayPoppedUpComboBox::eventFilter(QObject* o, QEvent* e) { // The combo box has installed an event filter on the view. // If it catches a valid mouse button release there, it will hide the popup. // Here we prevent this by eating the event ourselves, // and then dispatching it to its destination. if (o == m_view || o == m_view->viewport()) { switch (e->type()) { case QEvent::MouseButtonRelease: { QMouseEvent* m = static_cast<QMouseEvent*>(e); if (m_view->isVisible() && m_view->rect().contains(m->pos())) { if (o == m_view) { o->event(e); } else // Viewport: Calling event() does not work, viewportEvent() is needed. // This is the event that gets redirected to the QTreeView finally! { sendViewportEventToView(e); } // we have dispatched the event privately; we filter it out from the main dispatching return true; } break; } case QEvent::ContextMenu: { if (o != m_view) { // for whatever reason, the position of the event is slightly wrong QContextMenuEvent* m = static_cast<QContextMenuEvent*>(e); QPoint correctPos = m_view->viewport()->mapFromGlobal(m->globalPos()); QContextMenuEvent corrected(m->reason(), correctPos, m->globalPos(), m->modifiers()); sendViewportEventToView(&corrected); return true; } break; } default: break; } } return QComboBox::eventFilter(o, e); }
void exception_assignStringOfLengthOnePlusNull_bufferIndexOneIsNullToken() { //Logic here to make it fail. //This may only fail in release as the debug runtime is nice and may intialise data Yeah! //We can not know what the buffer data will contain for sure. //So we assign a buffer longer than we want, correct the size member //and then copy the data OOLUA::Exception e("DontCare"); e.m_len = 1; OOLUA::Exception corrected(e); char expected_value('\0'); CPPUNIT_ASSERT_EQUAL(expected_value, corrected.m_buffer[1]); }
void EditSpell::misspelling (const QString& original, const QStringList&, unsigned int) { if (!find(original, true, true, true, &nPara, &nIndex)){ string oldWord; oldWord = original.local8Bit(); log(L_DEBUG, "%s not found", oldWord.c_str()); return; } setCursorPosition(nPara, nIndex); for (unsigned i = 0; i < original.length(); i++) moveCursor(MoveForward, true); ensureCursorVisible(); QRect rc = paragraphRect(nPara); QPoint p1 = QPoint(rc.left(), rc.top()); QPoint p2 = QPoint(rc.right(), rc.bottom()); p1 = viewport()->mapToParent(p1); p2 = viewport()->mapToParent(p2); p1.setX(QMAX(p1.x(), 0)); p1.setY(QMAX(p1.y(), 0)); p2.setX(QMIN(p2.x(), width())); p2.setY(QMIN(p2.y(), height())); p1 = mapToGlobal(p1); p2 = mapToGlobal(p2); int yPos = p1.y(); if (p1.y() >= pSpell->heightDlg() - 10){ yPos -= pSpell->heightDlg() + 25; }else{ yPos = p2.y() + 10; } p1.setY(yPos); p1 = mapFromGlobal(p1); pSpell->moveDlg(p1.x(), p1.y()); #else void EditSpell::misspelling (const QString&, const QStringList&, unsigned int) { #endif } void EditSpell::corrected_old(QString original, QString newword, unsigned pos) { corrected((const QString&)original, (const QString&)newword, (unsigned int)pos); }
void TrackWidget::setTrack( lastfm::Track& track ) { disconnect( m_track.signalProxy(), 0, this, 0 ); m_track = track; connect( m_track.signalProxy(), SIGNAL(loveToggled(bool)), SLOT(onLoveToggled(bool)) ); connect( m_track.signalProxy(), SIGNAL(scrobbleStatusChanged(short)), SLOT(onScrobbleStatusChanged())); connect( m_track.signalProxy(), SIGNAL(corrected(QString)), SLOT(onCorrected(QString))); m_movie->stop(); ui->equaliser->hide(); setTrackDetails(); ui->albumArt->setPixmap( QPixmap( ":/meta_album_no_art.png" ) ); ui->albumArt->setHref( track.www() ); m_triedFetchAlbumArt = false; fetchAlbumArt(); }
int main() { // Allocate a BCH codec Galois order 8 (w/ 2^8-1 == 255 bit codeword size), and 2 bits of // correction capacity. This results in a BCH( 255, 239, 2) codec: 255-bit codeword, 239-bit // data payload capacity, hence 255-239 == 16 bits of parity. Define EZPWD_BCH_CLASSIC to use // classic Djelic Linux Kernel API. Otherwise, uses <ezpwd/bch> 'bch<..>' or 'BCH<...>' classes. ezpwd::asserter assert; try { #if defined( EZPWD_BCH_CLASSIC ) ezpwd::bch_control *bch = ezpwd::init_bch( 8, 2, 0 ); if ( ! bch ) throw std::logic_error( "Failed to allocate valid BCH codec" ); ezpwd::bch_control &bch_codec( *bch ); // By Galois order, Correction capacity #else //ezpwd::bch_base bch_codec( 8, 2 ); // By Galois order, Correction capacity, flexibly ezpwd::BCH<255,239,2> bch_codec; // By Codeword, Payload and Correction capacities, exactly #endif #if defined( EZPWD_BCH_FIXED ) typedef std::array<uint8_t,10> codeword_t; // Fixed (parity initialized to 0) #else typedef std::vector<uint8_t> codeword_t; // Variable (parity added by encode) #endif codeword_t codeword= { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF // 8 data }; // 2 ECC parity #if defined( EZPWD_BCH_CLASSIC ) // A BCH codeword's ECC must be zero-initialized for classic Djelic API, and // must be added to variable containers # if ! defined( EZPWD_BCH_FIXED ) codeword.resize( 10 ); # endif codeword[8] = 0; codeword[9] = 0; ezpwd::encode_bch( &bch_codec, &codeword[0], 8, &codeword[8] ); #else // A codeword in a fixed container will not be resized by API; assumes ECC on end. Will // initialize to 0. A variable container will have parity appended by the API. bch_codec.encode( codeword ); #endif // Place random errors in the codeword and correct, up to the capacity of the BCH codec. for ( size_t t = 0; t < 5; ++t ) { for ( size_t e = 0 #if defined( EZPWD_BCH_CLASSIC ) ; e < bch_codec.t #else ; e < bch_codec.t() #endif ; ++e ) { codeword_t corrupted( codeword ); // Randomly corrupt from 0 to bch->t bits for ( size_t be = 0; be < e; ++be ) { unsigned int bl = random_80( randomizer ); corrupted[bl/8] ^= uint8_t( 1 ) << ( bl % 8 ); } codeword_t corrected( corrupted ); #if defined( EZPWD_BCH_CLASSIC ) int corrections = correct_bch( &bch_codec, &corrected[0], 8, &corrected[8] ); #else int corrections = bch_codec.decode( corrected ); #endif if ( assert.ISEQUAL( corrections, int( e ), std::string( "Failed decode of " ) << bch_codec << " codeword w/ " << e << " bit errrors" )) { std::cout << assert << std::endl; continue; } // Success; If differences were found, they better be in the parity data! for ( size_t i = 0; i < 8; ++i ) if ( assert.ISEQUAL( corrected[i], codeword[i], std::string( "Failed recovery of " ) << bch_codec << " codeword w/ " << e << " bit errors" )) std::cout << assert << std::endl; } #if ! defined( EZPWD_BCH_CLASSIC ) // Try the inline versions (only available in C++ API) std::string raw( "abc" ); std::string enc = bch_codec.encoded( raw ); std::string err = enc; err[0] ^= 0x40; err[2] ^= 0x08; std::string dec = bch_codec.decoded( err ); if ( assert.ISEQUAL( dec.substr( 0, 3 ), raw, std::string( "decoded/encoded of " ) << bch_codec << " codeword failed, encoded '0x" << ezpwd::hexstr( raw ) << "' to '0x" << ezpwd::hexstr( enc ) << "', decoded '0x" << ezpwd::hexstr( err ) << "' to '0x" << ezpwd::hexstr( dec ) << "'" )) std::cout << assert << std::endl; #endif } std::cout << bch_codec << ": "; } catch( std::exception &exc ) { assert.FAILURE( "Exception", exc.what() ); std::cout << assert << std::endl; } if ( assert.failures ) std::cout << assert.failures << " tests failed." << std::endl; else std::cout << "All tests passed." << std::endl; return assert.failures ? 1 : 0; }
void CoordinateSystemProvider::update(ImageCoordinateSystem& imageCoordinateSystem) { imageCoordinateSystem.setCameraInfo(theCameraInfo); Geometry::Line horizon = Geometry::calculateHorizon(theCameraMatrix, theCameraInfo); imageCoordinateSystem.origin = horizon.base; imageCoordinateSystem.rotation.col(0) = horizon.direction; imageCoordinateSystem.rotation.col(1) = Vector2f(-horizon.direction.y(), horizon.direction.x()); imageCoordinateSystem.invRotation = imageCoordinateSystem.rotation.transpose(); const CameraMatrix& cmPrev = cameraMatrixPrev[theCameraInfo.camera]; RotationMatrix r(theCameraMatrix.rotation.inverse() * cmPrev.rotation); imageCoordinateSystem.offset = Vector2f(r.getZAngle(), r.getYAngle()); calcScaleFactors(imageCoordinateSystem.a, imageCoordinateSystem.b, theJointSensorData.timestamp - cameraMatrixPrevTimeStamp[theCameraInfo.camera]); cameraMatrixPrev[theCameraInfo.camera] = theCameraMatrix; cameraMatrixPrevTimeStamp[theCameraInfo.camera] = theJointSensorData.timestamp; COMPLEX_IMAGE(corrected) { INIT_DEBUG_IMAGE_BLACK(corrected, theCameraInfo.width, theCameraInfo.height); int yDest = -imageCoordinateSystem.toCorrectedCenteredNeg(0, 0).y(); for(int ySrc = 0; ySrc < theImage.height; ++ySrc) for(int yDest2 = -imageCoordinateSystem.toCorrectedCenteredNeg(0, ySrc).y(); yDest <= yDest2; ++yDest) { int xDest = -imageCoordinateSystem.toCorrectedCenteredNeg(0, ySrc).x(); for(int xSrc = 0; xSrc < theImage.width; ++xSrc) { for(int xDest2 = -imageCoordinateSystem.toCorrectedCenteredNeg(xSrc, ySrc).x(); xDest <= xDest2; ++xDest) { DEBUG_IMAGE_SET_PIXEL_YUV(corrected, xDest + int(theCameraInfo.opticalCenter.x() + 0.5f), yDest + int(theCameraInfo.opticalCenter.y() + 0.5f), theImage[ySrc][xSrc].y, theImage[ySrc][xSrc].cb, theImage[ySrc][xSrc].cr); } } } SEND_DEBUG_IMAGE(corrected); } COMPLEX_IMAGE(horizonAligned) { INIT_DEBUG_IMAGE_BLACK(horizonAligned, theCameraInfo.width, theCameraInfo.height); for(int ySrc = 0; ySrc < theCameraInfo.height; ++ySrc) for(int xSrc = 0; xSrc < theCameraInfo.width; ++xSrc) { Vector2f corrected(imageCoordinateSystem.toCorrected(Vector2i(xSrc, ySrc))); corrected.x() -= theCameraInfo.opticalCenter.x(); corrected.y() -= theCameraInfo.opticalCenter.y(); const Vector2f& horizonAligned(imageCoordinateSystem.toHorizonAligned(corrected)); DEBUG_IMAGE_SET_PIXEL_YUV(horizonAligned, int(horizonAligned.x() + theCameraInfo.opticalCenter.x() + 0.5f), int(horizonAligned.y() + theCameraInfo.opticalCenter.y() + 0.5f), theImage[ySrc][xSrc].y, theImage[ySrc][xSrc].cb, theImage[ySrc][xSrc].cr); } SEND_DEBUG_IMAGE(horizonAligned); } }
RcppExport SEXP correctCafie( SEXP measured_in, SEXP flowOrder_in, SEXP keyFlow_in, SEXP nKeyFlow_in, SEXP cafEst_in, SEXP ieEst_in, SEXP droopEst_in ) { SEXP rl = R_NilValue; // Use this when there is nothing to be returned. char *exceptionMesg = NULL; try { // First do some annoying but necessary type casting on the input parameters. // measured & nFlow RcppMatrix<double> measured_temp(measured_in); int nWell = measured_temp.rows(); int nFlow = measured_temp.cols(); // flowOrder RcppStringVector flowOrder_temp(flowOrder_in); char *flowOrder = strdup(flowOrder_temp(0).c_str()); int flowOrderLen = strlen(flowOrder); // keyFlow RcppVector<int> keyFlow_temp(keyFlow_in); int *keyFlow = new int[keyFlow_temp.size()]; for(int i=0; i<keyFlow_temp.size(); i++) { keyFlow[i] = keyFlow_temp(i); } // nKeyFlow RcppVector<int> nKeyFlow_temp(nKeyFlow_in); int nKeyFlow = nKeyFlow_temp(0); // cafEst, ieEst, droopEst RcppVector<double> cafEst_temp(cafEst_in); double cafEst = cafEst_temp(0); RcppVector<double> ieEst_temp(ieEst_in); double ieEst = ieEst_temp(0); RcppVector<double> droopEst_temp(droopEst_in); double droopEst = droopEst_temp(0); if(flowOrderLen != nFlow) { exceptionMesg = copyMessageToR("Flow order and signal should be of same length"); } else if(nKeyFlow <= 0) { exceptionMesg = copyMessageToR("keyFlow must have length > 0"); } else { double *measured = new double[nFlow]; RcppMatrix<double> predicted(nWell,nFlow); RcppMatrix<double> corrected(nWell,nFlow); CafieSolver solver; solver.SetFlowOrder(flowOrder); solver.SetCAFIE(cafEst, ieEst); for(int well=0; well < nWell; well++) { // Set up the input signal for the well for(int flow=0; flow<nFlow; flow++) { measured[flow] = measured_temp(well,flow); } // Initialize the sovler object and find the best CAFIE solver.SetMeasured(nFlow, measured); solver.Normalize(keyFlow, nKeyFlow, droopEst, false); solver.Solve(3, true); // Store the predicted & corrected signals for(int flow=0; flow<nFlow; flow++) { predicted(well,flow) = solver.GetPredictedResult(flow); corrected(well,flow) = solver.GetCorrectedResult(flow); } // Store the estimated sequence //const double *normalized_ptr = solver.GetMeasured(); //const char *seqEstimate_ptr = solver.GetSequence(); //int seqEstimateLen = strlen(seqEstimate_ptr); } // Build result set to be returned as a list to R. RcppResultSet rs; rs.add("predicted", predicted); rs.add("corrected", corrected); // Get the list to be returned to R. rl = rs.getReturnList(); delete [] measured; } free(flowOrder); delete [] keyFlow; } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }