void ExcavaROBOdometry::update() { if (!isInputValid()) { if (verbose_) debug_publisher_->msg_.input_valid = false; ROS_DEBUG("Odometry: Input velocities are invalid"); return; } else { if (verbose_) debug_publisher_->msg_.input_valid = true; } current_time_ = base_kin_.robot_state_->getTime(); ros::Time update_start = ros::Time::now(); updateOdometry(); // double update_time = (ros::Time::now()-update_start).toSec(); ros::Time publish_start = ros::Time::now(); if (publish_odom_) publishOdometry(); if (publish_odometer_) publishOdometer(); if (publish_state_odometry_) publishStateOdometry(); if (publish_tf_) publishTransform(); last_r_wheel_rotation_ = current_r_wheel_rotation_; last_l_wheel_rotation_ = current_l_wheel_rotation_; last_time_ = current_time_; sequence_ ++; }
char* HashStrategy::genHash(const char* str) { if (!isInputValid(str)) return NULL; return hash(str); }
void MarkovRunManager::runWithoutDebug(QString input_word) { _stop_on_next_step = false; _terminate_on_next_step = false; _steps_made = 0; _steps_history.clear(); _input_word = input_word; _word_after_last_step = input_word; _is_debug_mode = false; emit runWithoutDebugStarted(input_word); QCoreApplication::processEvents(); if(isInputValid(input_word)) { QTime time; time.start(); while(findAndApplyNextRule()) { int difference = time.elapsed(); if(difference > 100) { emit runStepsMade(_steps_made); QCoreApplication::processEvents(); time.start(); } } } }
/* Main program */ int main(int argc, char *argv[]) { // Check for correct usage if (!isInputValid(argc, argv)) return -1; // Open compressed file for reading ifstream ifs; ifs.open(argv[1], ios::binary); BitInputStream* istream = new BitInputStream(ifs); // Read the file header & get frequencies getFrequencies(istream); // Build a tree from the frequencies huffman = new HCTree(); huffman->build(freqs); // Open output file ofstream ofs; ofs.open(argv[2], ios::binary); // Write symbols to out file decode(istream, ofs); // Close & delete all allocated objects ifs.close(); ofs.close(); delete(huffman); delete(istream); return 0; }
BYTE Receiver::getValue( BYTE channel ) { if( isInputValid( channel ) ) { if( channel < RECEIVER_CHANNELS ) { return ch[channel].bValue; } } return 0; }
void IngredientInput::signalIngredient() { //validate input; if successful, emit signal if ( isHeader() ) { if ( header().isEmpty() ) return; } else { if ( !isInputValid() ) return; } emit addIngredient(); }
/* function to handle files string operation */ int strops_files(void *arg){ int rc = 0; struct strops_args *ptr = (struct strops_args *)arg; struct strops_args *kptr = NULL; /*check validation of input */ rc = isInputValid(ptr); if(rc < 0) goto out; /*copy_from_user into kernel */ kptr = (struct strops_args *)kmalloc(sizeof(struct strops_args), GFP_KERNEL); if(IS_ERR(kptr)){ rc = -ENOMEM; goto out; } if(copy_from_user(kptr, ptr, sizeof(struct strops_args))){ rc = -EFAULT; goto free_kptr; } /* begin file strings operation mode*/ rc = search_pat(kptr); if(rc < 0) goto free_kptr; if(kptr->flag == 1 || kptr->flag == 2){ if(kptr->res_len == 0){ printk("No found pattern; Operation quit.\n"); goto free_kptr; } rc = write_pat(kptr, 0); if(rc < 0) goto free_kptr; } if(copy_to_user(ptr, kptr, sizeof(struct strops_args))){ rc = -EFAULT; goto free_kptr; } free_kptr: kfree(kptr); out: return rc; }
void Receiver::setChannelMode( BYTE inChannel, BYTE mode ) { if( !isInputValid( inChannel )) { mode= 2; } BYTE mask; mode &= 3; inChannel &= 3; inChannel <<= 1; mode = (BYTE)(((BYTE)mode) << (BYTE)inChannel); mask = (BYTE)(((BYTE)3) << (BYTE)inChannel); channelReverse &= ~mask; channelReverse |= mode; }
void MarkovRunManager::doStartDebug(QString input_word, bool stop_at_first_step) { _stop_on_next_step = stop_at_first_step; _terminate_on_next_step = false; _steps_made = 0; _steps_history.clear(); _input_word = input_word; _word_after_last_step = input_word; _is_debug_mode = true; emit debugStarted(input_word); QCoreApplication::processEvents(); if(isInputValid(input_word)) { while(findAndApplyNextRule()) { } } }
void VncViewerConfigDialog::onOkButtonClick() { if (!isInputValid()) { return ; } VncViewerConfig *config = VncViewerConfig::getInstance(); StringStorage text; int intVal; m_listenPort.getText(&text); StringParser::parseInt(text.getString(), &intVal); config->setListenPort(intVal); m_logLevel.getText(&text); StringParser::parseInt(text.getString(), &intVal); config->setLogLevel(intVal); int oldLimit = config->getHistoryLimit(); m_historyLimit.getText(&text); StringParser::parseInt(text.getString(), &intVal); config->setHistoryLimit(intVal); if (config->getHistoryLimit() < oldLimit) { config->getConnectionHistory()->truncate(); } config->showToolbar(m_showToolbar.isChecked()); config->promptOnFullscreen(m_promptOnFullscreen.isChecked()); SettingsManager *sm = VncViewerSettingsManager::getInstance(); config->saveToStorage(sm); kill(IDOK); }
int LEVELSELECT::Select() { const char noDirectoryName[] = "[kein Verzeichnis]"; BUTTON prevDirButton ({{10, windY - 100}, {90, windY - 50}}, 0, 3, 10, CYAN, "<", 20, YELLOW); BUTTON nextDirButton ({{windX - 100, windY - 100}, {windX - 10, windY - 50}}, 0, 3, 10, CYAN, ">", 20, YELLOW); BUTTON dirCaption ({{100, windY - 100}, {windX - 110, windY - 50}}, 3, 3, 10, CYAN, "(Directory)", 20, YELLOW); BUTTON prevButton ({{10, windY - 180}, {90, windY - 130}}, 0, 3, 10, CYAN, "<", 20, YELLOW); BUTTON nextButton ({{windX - 100, windY - 180}, {windX - 10, windY - 130}}, 0, 3, 10, CYAN, ">", 20, YELLOW); BUTTON selectButton ({{windX - 200, 10}, {windX - 10, 60}}, 0, 3, 10, CYAN, "Spiel starten", 20, YELLOW); BUTTON cancelButton ({{10, 10}, {190, 60}}, 0, 3, 10, CYAN, "Zurück", 20, YELLOW); BUTTON levelCaption ({{100, windY - 180}, {windX - 110, windY - 130}}, 3, 3, 10, CYAN, "(Levelname)", 20, YELLOW); AREA highscoreOutput {{100, 140}, {windX / 2 - 100, windY - 240}}; prevDirButton.assignKeyboardButton(0,'Q'); nextDirButton.assignKeyboardButton(0,'E'); prevButton .assignKeyboardButton(0,GLFW_KEY_LEFT ,'A'); nextButton .assignKeyboardButton(0,GLFW_KEY_RIGHT,'D'); levelCaption .assignKeyboardButton(0,'S'); cancelButton .assignKeyboardButton(0,GLFW_KEY_ESC); selectButton .assignKeyboardButton(0,GLFW_KEY_ENTER,GLFW_KEY_SPACE); ReloadHighscore(); prepare_GameLoop(); do { prepare_graphics(); char levelText[MAX_PATH]; if (GetLevel() != NULL) sprintf(levelText, "%s (%d/%d)", GetLevel()->name, GetLevel()->index + 1, GetLevelCount()); else strcpy(levelText, "[Kein Level vorhanden]"); levelCaption.setText(levelText); const char* directoryName; if (strlen(GetDirectory()->name) > 0) directoryName = GetDirectory()->name; else directoryName = noDirectoryName; char directoryText[strlen(directoryName) + 9]; sprintf(directoryText, "%s (%d/%d)", directoryName, GetDirectory()->index + 1, GetDirectoryCount()); dirCaption.setText(directoryText); //handle clicks if (cancelButton.clicked()) break; else if (selectButton.clicked() && isInputValid()) { currentLevel->score.setTimesPlayed(currentLevel->score.getTimesPlayed() + 1); return true; } else if (prevButton.clicked() || levelCaption.clicked() == 2) SwitchLevel(-1); else if (nextButton.clicked() || levelCaption.clicked() == 1) SwitchLevel(1); else if (prevDirButton.clicked() || dirCaption.clicked() == 2) SwitchDirectory(-1); else if (nextDirButton.clicked() || dirCaption.clicked() == 1) SwitchDirectory(1); //output prevDirButton.print(); nextDirButton.print(); dirCaption.print(); prevButton.print(); nextButton.print(); selectButton.print(); cancelButton.print(); levelCaption.print(); if (currentLevel != NULL) { drawBox({{windX/2 + 80, 140}, {windX - 110, windY - 240}}, 10, 3, WHITE); currentLevel->level->printPreview(); TIME time = currentLevel->score.getTime(); drawBox(highscoreOutput,10,3,WHITE); normalFont.printf({highscoreOutput.a.x + 20, highscoreOutput.b.y - 40}, taLEFT, "Highscore"); normalFont.printf({highscoreOutput.a.x + 20, highscoreOutput.b.y - 80}, taLEFT, "Züge: %d", currentLevel->score.getMoves()); normalFont.printf({highscoreOutput.a.x + 20, highscoreOutput.b.y - 120}, taLEFT, "Zeit: %02d:%02d:%05.2f", time.Hours, time.Minutes, time.Seconds); normalFont.printf({highscoreOutput.a.x + 20, highscoreOutput.b.y - 160}, taLEFT, "%d mal gespielt", currentLevel->score.getTimesPlayed()); } } while (complete_graphics()); logger(true, "LEVELSELECT: Cancelled, Returning false."); return false; }
/** * Start fitting process. */ void MuonSequentialFitDialog::startFit() { if ( m_state != Stopped ) throw std::runtime_error("Couln't start: already running"); setState(Preparing); // Explicitly run the file search. This might be needed when Start is clicked straigh after // editing the run box. In that case, lost focus event might not be processed yet and search // might not have been started yet. Otherwise, search is not done as the widget sees that it // has not been changed. Taken from LoadDialog.cpp:124. m_ui.runs->findFiles(); // Wait for file search to finish. while ( m_ui.runs->isSearching() ) { QApplication::processEvents(); } // To process events from the finished thread QApplication::processEvents(); // Validate input fields if ( ! isInputValid() ) { QMessageBox::critical(this, "Input is not valid", "One or more input fields are invalid.\n\nInvalid fields are marked with a '*'."); setState(Stopped); return; } QStringList runFilenames = m_ui.runs->getFilenames(); const std::string label = m_ui.labelInput->text().toStdString(); const std::string labelGroupName = SEQUENTIAL_PREFIX + label; AnalysisDataServiceImpl& ads = AnalysisDataService::Instance(); if ( ads.doesExist(labelGroupName) ) { QMessageBox::StandardButton answer = QMessageBox::question(this, "Label already exists", "Label you specified was used for one of the previous fits. Do you want to overwrite it?", QMessageBox::Yes | QMessageBox::Cancel); if ( answer != QMessageBox::Yes ) { setState(Stopped); return; } ads.deepRemoveGroup(labelGroupName); } // Create a group for label ads.add(labelGroupName, boost::make_shared<WorkspaceGroup>()); // Tell progress bar how many iterations we will need to make and reset it m_ui.progress->setRange( 0, runFilenames.size() ); m_ui.progress->setFormat("%p%"); m_ui.progress->setValue(0); // Clear diagnosis table for new fit m_ui.diagnosisTable->setRowCount(0); // Get fit function as specified by user in the fit browser IFunction_sptr fitFunction = FunctionFactory::Instance().createInitialized( m_fitPropBrowser->getFittingFunction()->asString() ); // Whether we should use initial function for every fit bool useInitFitFunction = (m_ui.paramTypeGroup->checkedButton() == m_ui.paramTypeInitial); setState(Running); m_stopRequested = false; for ( auto fileIt = runFilenames.constBegin(); fileIt != runFilenames.constEnd(); ++fileIt ) { // Process events (so that Stop button press is processed) QApplication::processEvents(); // Stop if requested by user if ( m_stopRequested ) break; MatrixWorkspace_sptr ws; try { auto load = AlgorithmManager::Instance().create("MuonLoad"); load->initialize(); load->setChild(true); load->setRethrows(true); load->updatePropertyValues(*m_loadAlg); load->setPropertyValue("Filename", fileIt->toStdString()); load->setPropertyValue("OutputWorkspace", "__YouDontSeeMeIAmNinja"); if (m_fitPropBrowser->rawData()) // TODO: or vice verca? load->setPropertyValue("RebinParams", ""); load->execute(); ws = load->getProperty("OutputWorkspace"); } catch (...) { QMessageBox::critical( this, "Loading failed", "Unable to load one of the files.\n\nCheck log for details"); break; } const std::string runTitle = getRunTitle(ws); const std::string wsBaseName = labelGroupName + "_" + runTitle; IFunction_sptr functionToFit; if ( useInitFitFunction ) // Create a copy so that the original function is not changed functionToFit = FunctionFactory::Instance().createInitialized( fitFunction->asString() ); else // Use the same function over and over, so that previous fitted params are used for the next fit functionToFit = fitFunction; IAlgorithm_sptr fit = AlgorithmManager::Instance().create("Fit"); fit->setRethrows(true); try { // Set function. Gets updated when fit is done. fit->setProperty("Function", functionToFit); fit->setProperty("InputWorkspace", ws); fit->setProperty("Output", wsBaseName); // We should have one spectra only in the workspace, so use the first one. fit->setProperty("WorkspaceIndex", 0); // Various properties from the fit prop. browser fit->setProperty("StartX", m_fitPropBrowser->startX()); fit->setProperty("EndX", m_fitPropBrowser->endX()); fit->setProperty("Minimizer", m_fitPropBrowser->minimizer()); fit->setProperty("CostFunction", m_fitPropBrowser->costFunction()); fit->execute(); } catch(...) { QMessageBox::critical(this, "Fitting failed", "Unable to fit one of the files.\n\nCheck log for details"); break; } // Make sure created fit workspaces end-up in the group // TODO: this really should use loop ads.addToGroup(labelGroupName, wsBaseName + "_NormalisedCovarianceMatrix"); ads.addToGroup(labelGroupName, wsBaseName + "_Parameters"); ads.addToGroup(labelGroupName, wsBaseName + "_Workspace"); // Copy log values auto fitWs = ads.retrieveWS<MatrixWorkspace>(wsBaseName + "_Workspace"); fitWs->copyExperimentInfoFrom(ws.get()); // Add information about the fit to the diagnosis table addDiagnosisEntry(runTitle, fit->getProperty("OutputChi2OverDof"), functionToFit); // Update progress m_ui.progress->setFormat("%p% - " + QString::fromStdString(runTitle) ); m_ui.progress->setValue( m_ui.progress->value() + 1 ); } setState(Stopped); }