CString DLRacerInterface::parseResult(CString strCommand, CString strResult) { if (strResult[1] == _T('o')) { CString strWarning = getWarningFromOK(strResult); if (strWarning != _T("")) printWarning(strWarning); return _T("null"); } else if (strResult[1] == _T('e')) { CString strError = getError(strResult); return strError; } else if (strResult[1] == _T('a')) { vector<CString> strAnsAndWar = getResultAndWarningFromAnswer(strResult); if (strAnsAndWar[1] != _T("")) { printWarning(strAnsAndWar[1]); } return strAnsAndWar[0]; } else { msgbox(_T("parseResult")); return _T("parseResult"); } }
void EoBCoreEngine::castSpell(int spell, int weaponSlot) { EoBSpell *s = &_spells[spell]; EoBCharacter *c = &_characters[_openBookChar]; _activeSpell = spell; if ((s->flags & 0x100) && (c->effectFlags & 0x40)) // remove invisibility effect removeCharacterEffect(_flags.gameID == GI_EOB1 ? 8 : 10, _openBookChar, 1); int ci = _openBookChar; if (ci > 3) ci -= 2; _activeSpellCharacterPos = _dropItemDirIndex[(_currentDirection << 2) + ci]; if (s->flags & 0x400) { if (c->inventory[0] && c->inventory[1]) { printWarning(_magicStrings1[2]); return; } if (isMagicEffectItem(c->inventory[0]) || isMagicEffectItem(c->inventory[1])) { printWarning(_magicStrings1[3]); return; } } if (!(_flags.gameID == GI_EOB2 && _activeSpell == 62)) { if (!_castScrollSlot) { int8 tmp = _openBookAvailableSpells[_openBookSpellLevel * 10 + _openBookSpellListOffset + _openBookSpellSelectedItem]; if (_openBookSpellListOffset + _openBookSpellSelectedItem < 8) memmove(&_openBookAvailableSpells[_openBookSpellLevel * 10 + _openBookSpellListOffset + _openBookSpellSelectedItem], &_openBookAvailableSpells[_openBookSpellLevel * 10 + _openBookSpellListOffset + _openBookSpellSelectedItem + 1], 8 - (_openBookSpellListOffset + _openBookSpellSelectedItem)); _openBookAvailableSpells[_openBookSpellLevel * 10 + 8] = -tmp; if (_openBookAvailableSpells[_openBookSpellLevel * 10 + _openBookSpellListOffset + _openBookSpellSelectedItem] < 0) { if (--_openBookSpellSelectedItem == -1) { if (_openBookSpellListOffset) { _openBookSpellListOffset = 0; _openBookSpellSelectedItem = 5; } else { _openBookSpellSelectedItem = 6; } } } } else if (weaponSlot != -1) { updateUsedCharacterHandItem(_openBookChar, weaponSlot); } } _txt->printMessage(_magicStrings1[4], -1, c->name, s->name); if (s->flags & 0x20) { castOnWhomDialogue(); return; } _activeSpellCharId = _openBookChar; startSpell(spell); }
int SC2Map::readArchiveFile( const HANDLE archive, const char* strFilename, int* bufferOutSize, u8** bufferOut ) { HANDLE hFile; if( !SFileOpenFileEx( archive, strFilename, 0, &hFile ) ) { //printWarning( "Could not open %s for reading.\n", strFilename ); return -1; } DWORD fileSizeBytes = SFileGetFileSize( hFile, NULL ); if( fileSizeBytes == SFILE_INVALID_SIZE || fileSizeBytes <= 0 ) { printWarning( "%s is empty or invalid.\n", strFilename ); return -1; } u8* buffer = new u8[fileSizeBytes]; DWORD numBytesRead; // initialize buffer to easily recognized values, // after a successful read all of them are overwritten memset( buffer, 'q', fileSizeBytes ); if( !SFileReadFile( hFile, (void*)buffer, fileSizeBytes, &numBytesRead, NULL ) ) { delete buffer; printWarning( "Could not read %s from archive.\n", strFilename ); return -1; } if( numBytesRead != fileSizeBytes ) { delete buffer; printWarning( "Could not read %s from archive. [NOT EXPECTING TO SEE THIS WARNING!]\n", strFilename ); return -1; } *bufferOutSize = fileSizeBytes; *bufferOut = buffer; SFileCloseFile( hFile ); return 0; }
void operativeMachine::addAttrInStmt (void) { string msg; // warning message bool setted = true; // true if attr will be set nast_code code = c_nnp->getCode (); // code of the nast_node long id = c_nnp->getId (); // id of the nast_node string name = c_ga.getName (); // attr's name string value = c_ga.getStringValue (); // attr's value stmt_n *stmt_np = dynamic_cast < stmt_n * >(c_nnp); // Set one common attribute : line if (name == "line") stmt_np->setLine (c_ga.getIntValue ()); else // Set private attribute switch (code) { case SCOPE_STMT: { scope_stmt_n *sc_stmt_np = dynamic_cast < scope_stmt_n * >(c_nnp); // Set private attribute : unsigned if (name == "flag") { if (value == "begin") sc_stmt_np->setBegin (); else if (value == "end") sc_stmt_np->setEnd (); else if (value == "no_variable") sc_stmt_np->setVariables (); else { msg = "Unknown attribute for SCOPE_STMT : "; setted = false; } } else { msg = "Unknown attribute for SCOPE_STMT : "; setted = false; } } break; default: msg = "Impossibile to set the attr : "; setted = false; } // Isn't the attribute set ? if (!setted) printWarning ("operativeMachine", msg + name + "=" + value ); // astVerbosity output if (astVerbosity) cout << "Adding attribute (" << name << "=" << value << ") to node " << id << "...\n"; return; }
void operativeMachine::addAttrInNode (void) { /* NOTE : constant nodes and expression nodes (unary, binary, ternary, reference, others) haven't any attributes */ nast_code code = c_nnp->getCode (); // The code of the nast_node // What node class belong to ? // declaration nodes if (isDecl (code) || isOthrDecl (code)) addAttrInDecl (); // type nodes else if (isType (code) || isOthrType (code)) addAttrInType (); // statement nodes else if (isStmt (code) || isOthrStmt (code)) addAttrInStmt (); // other nodes else if (isOthr (code)) addAttrInOthr (); else printWarning ("operativeMachine", "The attribute doesn't belong to any node"); return; }
double SimpleSearch::find_root(double f(double x)) { double f0 = f(x0); double f_of_x = f0; int step = 0; if ( verbose ) { printHead("Simple Search with Step-Halving", accuracy, *os); printStep(step, x0, dx, f_of_x, *os); } while ( abs(dx) > accuracy && f_of_x != 0 && ++step <= max_steps ) { x0 += dx; // take a step f_of_x = f(x0); if ( f0 * f_of_x < 0 ) { // jumped past root x0 -= dx; // backup dx /= 2; // halve the step size } if ( verbose ) printStep(step, x0, dx, f_of_x, *os); } if ( step > max_steps ) printWarning(max_steps); steps = step; return x0; }
/********************************************************************** *%FUNCTION: rp_fatal *%ARGUMENTS: * str -- error message *%RETURNS: * Nothing *%DESCRIPTION: * Prints a message to stderr and syslog and exits. ***********************************************************************/ void rp_fatal(char const *str) { printWarning(str); sendPADTf(conn, "RP-PPPoE: %.256s", str); exit(1); }
void Transformer::printRules(int mode) { hash_map<string, vector<Rule> >* rules; if (mode == 2) { rules = &rules2; } else if (mode == 3) { rules = &rules3plus; } else { printWarning("illegal rule mode specified"); } for (hash_map<string, vector<Rule> >::iterator it = rules->begin(); it != rules->end(); it++) { cout << it->first << ": " << it->second.size() << endl; } // for (hash_map<string, vector<Rule> >::iterator it = rules->begin(); it != rules->end(); it++) // { // cout << "-- " << it->first << " --" << endl; // for (vector<Rule>::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++) // { // printRule(*it2); // } // } }
void operativeMachine::warning (const SAXParseException & e) { printWarning("operativeMachine at file " + a2b::XMLChar2string (e.getSystemId ()), a2b::XMLChar2string(e.getMessage ())); }
double BisectionSearch::find_root(double f(double x)) { double f0 = f(x0); double f1 = f(x1); if ( f0 * f1 > 0 ) { cerr << " BisectionSearch: sorry, root not bracketed!\n" << " f(" << x0 << ") = " << f0 << endl << " f(" << x1 << ") = " << f1 << endl << " Trying to bracket the root using bracket_root ..." << flush; double save_x0 = x0; double save_x1 = x1; if ( bracket_root(f) ) { cerr << " Bracketing succeeded !\n" << " x0 = " << x0 << " x1 = " << x1 << " continuing ..." << endl; f0 = f(x0); f1 = f(x1); } else { cerr << " Sorry, bracketing attempt failed" << endl; x0 = save_x0; x1 = save_x1; return abs(f0) < abs(f1) ? x0 : x1; } } if ( f0 == 0 ) return x0; if ( f1 == 0 ) return x1; double xHalf, fHalf = 0.5 * (f0 + f1); int step = 0; if ( verbose ) { printHead("Bisection Search", accuracy, *os); printStep(step, x0, x1 - x0, fHalf, *os); } do { // iteration loop if ( ++step > max_steps ) break; xHalf = 0.5 * (x0 + x1); // bisection point fHalf = f(xHalf); if ( f0 * fHalf > 0 ) { // x0 and xHalf on same side of root x0 = xHalf; // replace x0 by xHalf f0 = fHalf; } else { // x1 and xHalf on same side of root x1 = xHalf; // replace x1 by xHalf f1 = fHalf; } if ( verbose ) printStep(step, x0, x1 - x0, fHalf, *os); } while ( abs(x1 - x0) > accuracy && fHalf != 0); if ( step > max_steps ) printWarning(max_steps); steps = step; return xHalf; }
int CArduinoDevice::write(const char* message, int length) { int n = ::write(fd_, message, length); if (n<=0){ printWarning("write error. disconnecting"); disconnect(); } return n; }
int CArduinoDevice::read(char* message) { int n = ::read(fd_, message, buffer_size_); if (n<=0) { printWarning("read error. disconnecting."); disconnect(); } return n; }
MStatus read(double iFrame, const Alembic::AbcGeom::IPoints & iNode, MObject & iObject) { MStatus status = MS::kSuccess; printWarning("Reading animated particle data not supported."); return status; }
QT_BEGIN_NAMESPACE HelpGenerator::HelpGenerator() { generator = new QHelpGenerator(this); connect(generator, SIGNAL(statusChanged(QString)), this, SLOT(printStatus(QString))); connect(generator, SIGNAL(warning(QString)), this, SLOT(printWarning(QString))); }
bool PdmsFileSession::moveForward() { int car; unsigned n; bool tokenFilled; n=0; if(PdmsLexer::moveForward()) return true; m_eol = false; tokenFilled = false; while(!tokenFilled) { car = getc(m_file); switch(car) { case '\n': if(n>0) { tokenFilled = true; m_eol = true; } m_currentLine++; break; case ' ': case '\t': if(n>0) tokenFilled = true; break; case EOF: tokenFilled = true; m_eof = true; break; default: if(n >= c_max_buff_size) { printWarning("Buffer overflow"); return false; } tokenBuffer[n] = car; n++; break; } } tokenBuffer[n] = '\0'; if(tokenBuffer[0] != '/') upperStr(tokenBuffer); return (n>0); }
void PMXMLParser::topParse( ) { if( initDocument( ) ) { QDomElement e = m_pDoc->documentElement( ); // read the format number // assume 1.0 on error QString fstring = e.attribute( "majorFormat", "1" ); bool ok = true; int format = fstring.toInt( &ok ); if( !ok || ( format < 1 ) ) format = 1; m_majorDocumentFormat = format; fstring = e.attribute( "minorFormat", "0" ); ok = true; format = fstring.toInt( &ok ); if( !ok || ( format < 0 ) ) format = 0; m_minorDocumentFormat = format; if( ( m_majorDocumentFormat > c_majorDocumentFormat ) || ( m_majorDocumentFormat == c_majorDocumentFormat ) && ( m_minorDocumentFormat > c_minorDocumentFormat ) ) printWarning( i18n( "This document was created with a newer version of KPovModeler. " "The whole document may not be loaded correctly." ) ); if( e.tagName( ) == "objects" ) { parseChildObjects( e, 0 ); } else if( e.tagName( ) == "scene" ) { PMScene* scene = new PMScene( m_pPart ); insertChild( scene, 0 ); PMXMLHelper hlp( e, m_pPart, this, m_majorDocumentFormat, m_minorDocumentFormat ); scene->readAttributes( hlp ); parseChildObjects( e, scene ); } else { printError( i18n( "Wrong top level tag" ) ); setFatalError( ); } } }
void Transformer::loadRule(const string raw, int mode) { stringstream ss(raw); vector<string> tokensLHS, tokensRHS; string buffer; bool isLHS = true; while (ss >> buffer) { if (buffer == "->") // assuming wellformedness (only one "->" divider in rule) { isLHS = false; } else { if (isLHS) { tokensLHS.push_back(buffer); } else { tokensRHS.push_back(buffer); } } } Tree trLHS = getTTETree(tokensLHS); Tree trRHS = getTTETree(tokensRHS); string id = getID(trLHS, trLHS.begin()); if (mode == 3) { rules3plus[id].push_back(Rule(trLHS, trRHS)); } else if (mode == 2) { rules2[id].push_back(Rule(trLHS, trRHS)); } else { printWarning("illegal rule mode specified"); } ruleCount++; }
void EoBCoreEngine::removeCharacterEffect(int spell, int charIndex, int showWarning) { assert(spell >= 0); EoBCharacter *c = &_characters[charIndex]; EoBSpell *s = &_spells[spell]; if (showWarning) { int od = _screen->curDimIndex(); Screen::FontId of = _screen->setFont(Screen::FID_6_FNT); _screen->setScreenDim(7); printWarning(Common::String::format(_magicStrings3[_flags.gameID == GI_EOB1 ? 3 : 2], c->name, s->name).c_str()); _screen->setScreenDim(od); _screen->setFont(of); } if (s->endCallback) (this->*s->endCallback)(c); if (s->flags & 1) c->effectFlags &= ~s->effectFlags; if (s->flags & 4) _partyEffectFlags &= ~s->effectFlags; if (s->flags & 0x200) { for (int i = 0; i < 6; i++) { if (!testCharacter(i, 1)) continue; if (!testCharacter(i, 2) && !(s->flags & 0x800)) continue; _characters[i].effectFlags &= ~s->effectFlags; } } if (s->flags & 0x2) recalcArmorClass(_activeSpellCharId); if (showWarning) { if (s->flags & 0x20A0) gui_drawCharPortraitWithStats(charIndex); else if (s->flags & 0x40) gui_drawAllCharPortraitsWithStats(); } }
void operativeMachine::addAttrInOthr (void) { string msg; // warning message bool setted = true; // true if attr will be set nast_code code = c_nnp->getCode (); // code of the nast_node long id = c_nnp->getId (); // id of the nast_node string name = c_ga.getName (); // attr's name string value = c_ga.getStringValue (); // attr's value // Set private attribute if (code == IDENTIFIER_NODE) { identifier_n *id_np = dynamic_cast < identifier_n * >(c_nnp); // Set private attribute : string if (name == "string") id_np->setString (value); else { msg = "Unknown attribute for IDENTIFIER_NODE : "; setted = false; } } else { msg = "Impossibile to set the attr : "; setted = false; } // CASE_LABEL IS default: ONLY IF IT HASN'T ANY EDGES // Isn't the attribute set ? if (!setted) printWarning ("operativeMachine", msg + name + "=" + value ); // astVerbosity output if (astVerbosity) cout << "Adding attribute (" << name << "=" << value << ") to node " << id << "...\n"; return; }
void Transformer::loadConfigProperty(string property, string value) { if (property == "baseDir") { baseDir = value; if (baseDir[baseDir.length() - 1] == '/') // remove final '/' baseDir = baseDir.substr(0, baseDir.length() - 1); } else if (property == "rules-3+") { rules3plusFilename = value; } else if (property == "rules-2") { rules2Filename = value; } else { printWarning("property `" + property + "' in configuration file not recognized"); } }
void SC2Map::makeMapNameValidForFilenames() { mapNameInOutputFiles.assign( mapName ); // remove invalid filename characters removeChars( "\\<>:\"/|?*\t\r\n ", &mapNameInOutputFiles ); // gotta start with an alpha character if( !isalpha( mapNameInOutputFiles[0] ) ) { string prefix( "sc2map" ); prefix.append( mapNameInOutputFiles ); mapNameInOutputFiles.assign( prefix ); } set<string>::iterator sItr = mapFilenamesUsed.find( mapNameInOutputFiles ); if( sItr != mapFilenamesUsed.end() ) { int number = 2; string alternateName; do { char alt[FILENAME_LENGTH]; sprintf( alt, "%s%d", mapNameInOutputFiles.data(), number ); alternateName.assign( alt ); ++number; sItr = mapFilenamesUsed.find( alternateName ); } while( sItr != mapFilenamesUsed.end() ); printWarning( "Map name %s already used, using %s instead.\n", mapNameInOutputFiles.data(), alternateName.data() ); mapNameInOutputFiles.assign( alternateName ); } mapFilenamesUsed.insert( mapNameInOutputFiles ); }
double TangentSearch::find_root(double f(double x), double f_prime(double x)) { double f0 = f(x0); double f_prime0 = f_prime(x0); if ( f0 == 0 ) return x0; if ( f_prime0 != 0 ) dx = - f0 / f_prime0; int step = 0; if ( verbose ) { printHead("Tangent Search", accuracy, *os); printStep(step, x0, dx, f0, *os); } do { if ( ++step > max_steps ) break; if ( f_prime0 == 0 ) { cerr << " Tangent Search: f'(x0) = 0, algorithm fails!\n" << " f(" << x0 << ") = " << f0 << endl << " f'(" << x0 << ") = " << f_prime0 << endl; break; } dx = - f0 / f_prime0; x0 += dx; f0 = f(x0); f_prime0 = f_prime(x0); if ( verbose ) printStep(step, x0, dx, f0, *os); } while ( abs(dx) > accuracy && f0 != 0); if ( step > max_steps ) printWarning(max_steps); steps = step; return x0; }
double SecantSearch::find_root(double f(double x)) { double f0 = f(x0); double f1 = f(x1); if ( f0 == 0 ) return x0; if ( f1 == 0 ) return x1; int step = 0; if ( verbose ) { printHead("Secant Search", accuracy, *os); printStep(step, x0, x1 - x0, f1, *os); } do { if ( ++step > max_steps ) break; if ( f0 == f1 ) { cerr << " Secant Search: f(x0) = f(x1), algorithm fails!\n" << " f(" << x0 << ") = " << f0 << endl << " f(" << x1 << ") = " << f1 << endl; break; } dx *= - f1 / ( f1 - f0 ); x0 = x1; f0 = f1; x1 += dx; f1 = f(x1); if ( verbose ) printStep(step, x0, dx, f1, *os); } while ( abs(dx) > accuracy && f1 != 0); if ( step > max_steps ) printWarning(max_steps); steps = step; return x1; }
void RS_ActionPrintPreview::fit() { if (graphic) { RS_Vector&& paperSize=RS_Units::convert(graphic->getPaperSize(), RS2::Millimeter, getUnit()); if(fabs(paperSize.x)<10.|| fabs(paperSize.y)<10.) printWarning("Warning:: Paper size less than 10mm." " Paper is too small for fitting to page\n" "Please set paper size by Menu: Edit->Current Drawing Preferences->Paper"); // double f0=graphic->getPaperScale(); if( graphic->fitToPage()==false && RS_DIALOGFACTORY) { RS_DIALOGFACTORY->commandMessage( tr("RS_ActionPrintPreview::fit(): Invalid paper size") ); } // if(fabs(f0-graphic->getPaperScale())>RS_TOLERANCE){ //only zoomPage when scale changed // } graphic->centerToPage(); graphicView->zoomPage(); graphicView->redraw(); } }
bool RootFinder::bracket_root(double f(double x)) { // This function will attempt to bracket the root of a function // starting with the RootFinder data values x0 and x1, by // geometrically expanding the interval [x0, x1] until the root // is bracketed, or the number of steps exceeds max_steps // a convenient expansion factor const double expansionFactor = 1.6; if ( x0 == x1 ) { cerr << "\n RootFinder::bracket_root: sorry, x0 = x1!\n" << " x0 = " << x0 << endl << " x1 = " << x1 << endl; return false; } int step = 0; double f0 = f(x0); double f1 = f(x1); while ( ++step <= max_steps ) { if ( f0 * f1 <= 0 ) return true; // success .. root is bracketed if ( abs(f0) < abs(f1) ) { // x0 probably closer to root x0 -= expansionFactor * dx; f0 = f(x0); } else { // x1 probably closer to the root x1 += expansionFactor * dx; f1 = f(x1); } dx = x1 - x0; // also adjust dx } printWarning(max_steps); // max_steps has been exceeded return false; }
Tree Transformer::getTree(const string raw) { Tree tr; if (raw == "0" || raw == "") return tr; // if Radu parser does not parse, it outputs 0 stringstream ss(raw); vector<string> tokens; int lrbCount = 0; // ( count int rrbCount = 0; // ) count string buffer; while (ss >> buffer) { if (buffer[0] == '(' && buffer != "()") lrbCount++; // ignore special case of (-LRB- () if (buffer == ")" || buffer[buffer.length() - 1] == ')') rrbCount++; tokens.push_back(buffer); } if (lrbCount != rrbCount) { printWarning("incomplete tree"); return tr; } return getTree(tokens); }
MStatus AbcImport::doIt(const MArgList & args) { MStatus status; MArgParser argData(syntax(), args, &status); MString filename(""); MString connectRootNodes(""); MString filterString(""); MString excludeFilterString(""); MObject reparentObj = MObject::kNullObj; bool swap = false; bool createIfNotFound = false; bool removeIfNoUpdate = false; bool debugOn = false; if (argData.isFlagSet("help")) { MGlobal::displayInfo(usage); return status; } if (argData.isFlagSet("debug")) debugOn = true; if (argData.isFlagSet("reparent")) { MString parent(""); MDagPath reparentDagPath; status = argData.getFlagArgument("reparent", 0, parent); if (status == MS::kSuccess && getDagPathByName(parent, reparentDagPath) == MS::kSuccess) { reparentObj = reparentDagPath.node(); } else { MString theWarning = parent; theWarning += MString(" is not a valid DagPath"); printWarning(theWarning); } } if (!argData.isFlagSet("connect") && argData.isFlagSet("mode")) { MString modeStr; argData.getFlagArgument("mode", 0, modeStr); if (modeStr == "replace") deleteCurrentSelection(); else if (modeStr == "open") { MFileIO fileIo; fileIo.newFile(true); } } else if (argData.isFlagSet("connect")) { swap = true; argData.getFlagArgument("connect", 0, connectRootNodes); if (argData.isFlagSet("createIfNotFound")) { createIfNotFound = true; } if (argData.isFlagSet("removeIfNoUpdate")) removeIfNoUpdate = true; } if (argData.isFlagSet("filterObjects")) { argData.getFlagArgument("filterObjects", 0, filterString); } if (argData.isFlagSet("excludeFilterObjects")) { argData.getFlagArgument("excludeFilterObjects", 0, excludeFilterString); } // if the flag isn't specified we'll only do stuff marked with the Maya // meta data bool recreateColorSets = false; if (argData.isFlagSet("recreateAllColorSets")) { recreateColorSets = true; } status = argData.getCommandArgument(0, filename); MString abcNodeName; if (status == MS::kSuccess) { { MString fileRule, expandName; MString alembicFileRule = "alembicCache"; MString alembicFilePath = "cache/alembic"; MString queryFileRuleCmd; queryFileRuleCmd.format("workspace -q -fre \"^1s\"", alembicFileRule); MString queryFolderCmd; queryFolderCmd.format("workspace -en `workspace -q -fre \"^1s\"`", alembicFileRule); // query the file rule for alembic cache MGlobal::executeCommand(queryFileRuleCmd, fileRule); if (fileRule.length() > 0) { // we have alembic file rule, query the folder MGlobal::executeCommand(queryFolderCmd, expandName); } // resolve the expanded file rule if (expandName.length() == 0) { expandName = alembicFilePath; } // get the path to the alembic file rule MFileObject directory; directory.setRawFullName(expandName); MString directoryName = directory.resolvedFullName(); // resolve the relative path MFileObject absoluteFile; absoluteFile.setRawFullName(filename); absoluteFile.setResolveMethod(MFileObject::kInputFile); #if MAYA_API_VERSION < 201300 if (absoluteFile.resolvedFullName() != absoluteFile.expandedFullName()) { #else if (!MFileObject::isAbsolutePath(filename)) { #endif // this is a relative path MString absoluteFileName = directoryName + "/" + filename; absoluteFile.setRawFullName(absoluteFileName); filename = absoluteFile.resolvedFullName(); } else { filename = absoluteFile.resolvedFullName(); } } MFileObject fileObj; status = fileObj.setRawFullName(filename); if (status == MS::kSuccess && fileObj.exists()) { ArgData inputData(filename, debugOn, reparentObj, swap, connectRootNodes, createIfNotFound, removeIfNoUpdate, recreateColorSets, filterString, excludeFilterString); abcNodeName = createScene(inputData); if (inputData.mSequenceStartTime != inputData.mSequenceEndTime && inputData.mSequenceStartTime != -DBL_MAX && inputData.mSequenceEndTime != DBL_MAX) { if (argData.isFlagSet("fitTimeRange")) { MTime sec(1.0, MTime::kSeconds); setPlayback( inputData.mSequenceStartTime * sec.as(MTime::uiUnit()), inputData.mSequenceEndTime * sec.as(MTime::uiUnit()) ); } if (argData.isFlagSet("setToStartFrame")) { MTime sec(1.0, MTime::kSeconds); MGlobal::viewFrame( inputData.mSequenceStartTime * sec.as(MTime::uiUnit()) ); } } } else { MString theError("In AbcImport::doIt(), "); theError += filename; theError += MString(" doesn't exist"); printError(theError); } } MPxCommand::setResult(abcNodeName); return status; }
int main(int argc, char **argv) { /*** command line arguments ***/ BasicAppOptions appopt(argc, argv); if (!appopt.gotCalibStorageDir) { pcl::console::print_error( "No calibration storage provided. --calibstorage <path>\n"); exit(1); } if (!appopt.gotRigConfigFile) { pcl::console::print_error( "No rig config provided. --rigconfig <file>\n"); exit(1); } /* 3d marker properties */ float boardWidth, boardHeight; if (pcl::console::parse(argc, argv, "-bw", boardWidth) == -1) { print_usage(); exit(1); } if (pcl::console::parse(argc, argv, "-bh", boardHeight) == -1) { print_usage(); exit(1); } /* 2d marker properties */ int patternWidth, patternHeight; float squareSize; if (pcl::console::parse(argc, argv, "-pw", patternWidth) == -1) { print_usage(); exit(1); } if (pcl::console::parse(argc, argv, "-ph", patternHeight) == -1) { print_usage(); exit(1); } if (pcl::console::parse(argc, argv, "-ps", squareSize) == -1) { print_usage(); exit(1); } /* tolerance for the 3d marker */ float boardSigma = 0.05; pcl::console::parse(argc, argv, "-bs", boardSigma); /* confirm */ bool doConfirm = true; doConfirm = !pcl::console::find_switch(argc, argv, "-nc"); bool storeResults = true; storeResults = !pcl::console::find_switch(argc, argv, "-nosave"); /* help */ if (pcl::console::find_switch(argc, argv, "-h") || pcl::console::find_switch(argc, argv, "--help")) { print_usage(); exit(0); } /*****************************/ /* the calibdation storage */ CalibStorageContract calibStorage(appopt.calibStorageDir); /* the rig config */ RigConfig rigConfig; rigConfig.loadFromFile(appopt.rigConfigFile); /* setup visualizer */ CalibVisualizer visualizer; visualizer.start(); /* image windows */ cv::namedWindow("camera", CV_WINDOW_NORMAL|CV_GUI_EXPANDED); /* the captured file pairs */ std::vector<CalibStorageContract::FilePair> pairPaths; pairPaths = calibStorage.getExtrinsicFiles(); int pairCounter = 0; for (auto fpair : pairPaths) { /* print loop information */ std::stringstream ss; ss << "[Find Pairs] ==== PROCESSING PAIR " << ++pairCounter << "/" << pairPaths.size() << " ====" << std::endl; printSimpleInfo(ss.str()); /* load image from file */ cv::Mat img = cv::imread(fpair.first, CV_LOAD_IMAGE_COLOR); /* load cloud from file */ Cloud::Ptr cloud( new Cloud); pcl::io::loadPCDFile<PointT>(fpair.second, *cloud); /* display image */ cv::imshow("camera", img); // spin once cv::waitKey(1); /* dispaly cloud */ visualizer.setMainCloud(cloud); visualizer.setDrawMarker(false); /*** extract points from pattern ***/ cv::Size patternSize(patternWidth, patternHeight); std::vector<cv::Point2f> patternCorners; bool found2d = cv::findChessboardCorners (img, patternSize, patternCorners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE); /* display results on image */ if (found2d) { printSimpleInfo("[Chessboard] ", "found.\n"); /* draw center point */ cv::Point2f patternCenter = patternCorners[patternCorners.size()/2]; cv::circle(img, patternCenter, 15.0, cv::Scalar(0, 255, 0), -1); } else { printWarning("[Chessboard] ", "not found.\n"); } /* draw the 2d pattern */ cv::drawChessboardCorners(img, patternSize, patternCorners, found2d); cv::imshow("camera", img); cv::waitKey(1); /*** extract 3d marker ***/ PointT bPoint; PlaneMarker<PointT> planeMarker(boardWidth, boardHeight, boardSigma); bool found3d = planeMarker.computeMarkerCenter(cloud, bPoint); pcl::PointXYZ boardPoint = pointRGBAtoXYZ(bPoint); /* display results in cloud viewer */ if (found3d) { printSimpleInfo("[BoardMarker] ", "found.\n"); /* draw the 3d marker */ visualizer.setMarkerCenter(boardPoint, true); visualizer.setDrawMarker(true); } else { printWarning("[BoardMarker] ", "not found.\n"); visualizer.setMarkerCenter(boardPoint, false); } /* a marker pair was found */ if (found2d && found3d) { printBrightInfo("[Marker Pair] ", "found.\n"); /* set the center point of the 3d marker */ cv::Point3f point3d; point3d.x = boardPoint.x; point3d.y = boardPoint.y; point3d.z = boardPoint.z; /* get the middle point from 2d pattern */ cv::Point2f point2d = patternCorners[patternCorners.size()/2]; /* get the transformation of the pattern * and it's middle point in 3d */ cv::Mat patternTvec, patternRvec; getPatternTransform(patternSize, squareSize, patternCorners, rigConfig.cameraMatrix, rigConfig.cameraDistortionCoefficients, patternTvec, patternRvec); //FIXME transform point properly // center point of the marker in object space cv::Point3f objectPoint(0.0, 0.0, 0.0); // point in camera space cv::Point3f patternPoint3d; cv::Point3f t; t.x = patternTvec.at<double>(0,0); t.y = patternTvec.at<double>(1,0); t.z = patternTvec.at<double>(2,0); cv::Mat rmat; cv::Rodrigues(patternRvec, rmat); cv::Matx33f rotation_matrix = rmat; //pre rotation // -> FIXME check again // at the moment this looks correct. // also float/double convertion is correct patternPoint3d = (rotation_matrix * objectPoint) + t; std::stringstream ss; ss << "Chessboard at tvec:" << patternTvec << " rvec: "; ss << patternRvec << std::endl; printSimpleInfo("[Chessboard 3D] ", ss.str()); /* query the user if the sample should be stored */ bool doAddPointPair = true; if (doConfirm) { printBrightInfo("[Add Marker Pair] ", "store? [y]/[n]\n"); for (;;) { int key = cv::waitKey(1); if (key == KEY_y) { doAddPointPair = true; break; } else if (key == KEY_n) { doAddPointPair = false; break; } else if (key > 0) { printBrightInfo("[Add Marker Pair] ", "store? [y]/[n]\n"); } } } /* store point pair */ if (doAddPointPair) { calibStorage.addExtrinsicPointPair(point3d, point2d); calibStorage.addExtrinsicPointPair3d( point3d, patternPoint3d); //FIXME don't store every time, only on exit if (storeResults) { calibStorage.saveExtrinsicPointPairs(); calibStorage.saveExtrinsicPointPairs3d(); } } } else { // no marker pair printWarning("[Marker Pair] ", "not found.\n"); cv::waitKey(1); /* confirm before next iteration */ if (doConfirm) { printWarning("[Continue] ", "Hit any key.\n"); while (true) { int key = cv::waitKey(1); if (key > 0) { break; } } } } } // for all pairs /* finaly save to calibration storage */ if (storeResults) { calibStorage.saveExtrinsicPointPairs(); calibStorage.saveExtrinsicPointPairs3d(); } }
void OpenSteer::OpenSteerDemo::printWarning (const std::ostringstream& message) { printWarning (message.str().c_str()); }
void SC2Map::locateChokes() { for( list<StartLoc*>::const_iterator itr1 = startLocs.begin(); itr1 != startLocs.end(); ++itr1 ) { StartLoc* sl1 = *itr1; list<point> possibleChokes; for( list<StartLoc*>::const_iterator itr2 = startLocs.begin(); itr2 != startLocs.end(); ++itr2 ) { StartLoc* sl2 = *itr2; if( sl1 == sl2 ) { continue; } Node* src = getPathNode( &(sl2->loc), pathTypeLocateChokes ); Node* u = getPathNode( &(sl1->loc), pathTypeLocateChokes ); if( src == NULL ) { printError( "Start location %s is in an unpathable cell.\n", sl2->name ); exit( -1 ); } if( u == NULL ) { printError( "Start location %s is in an unpathable cell.\n", sl1->name ); exit( -1 ); } Node* v = getShortestPathPredecessor( src, u, pathTypeLocateChokes ); if( v == NULL ) { // no path, just skip this pairing continue; } // The choke should be closer than 50% of the distance // from a start location to any other start location float dTotal = getShortestPathDistance( src, u, pathTypeLocateChokes ); float dTest = dTotal; point pBest; pBest.mSet( -1000.0f + sl2->loc.mx, -1000.0f + sl2->loc.my ); float dChokeMin = infinity; bool trippedThreshold = false; while( v != NULL && dTest > 0.5f*dTotal ) { float dChoke = chokeDistance( &(v->loc), pathTypeLocateChokes ); if( trippedThreshold && dChoke > dChokeMin ) { // we just got a worse result, kick out break; } if( dChoke < getfConstant( "chokeDetectionThreshold" ) ) { trippedThreshold = true; dChokeMin = dChoke; pBest.set( &(v->loc) ); } u = v; v = getShortestPathPredecessor( src, u, pathTypeLocateChokes ); dTest = getShortestPathDistance ( src, u, pathTypeLocateChokes ); } possibleChokes.push_back( pBest ); } // if the best choke from this location to all others // is reasonably close, take the average bool chokesAgree = true; float xTotal = 0.0f; float yTotal = 0.0f; for( list<point>::iterator itr1 = possibleChokes.begin(); chokesAgree && itr1 != possibleChokes.end(); ++itr1 ) { point c1; c1.pcSet( (*itr1).pcx, (*itr1).pcy ); list<point>::iterator itr2 = itr1; ++itr2; for( ; itr2 != possibleChokes.end(); ++itr2 ) { point c2; c2.pcSet( (*itr2).pcx, (*itr2).pcy ); if( p2pDistance( &c1, &c2 ) > getfConstant( "chokeDetectionAgreement" ) ) { chokesAgree = false; break; } } xTotal += c1.mx; yTotal += c1.my; } if( chokesAgree ) { float xAvg = xTotal / (float)possibleChokes.size(); float yAvg = yTotal / (float)possibleChokes.size(); sl1->mainChoke.mSet( xAvg, yAvg ); } else { printWarning( "Could not locate main choke for start location %s.\n", sl1->name ); sl1->mainChoke.mSet( -1.0f, -1.0f ); } } }