void ReadAndWriteXML::save(const QString namefile, const QDomDocument * doc) { QFile _file(namefile,this); _file.open(QFile::ReadWrite); QTextStream _out(&_file); doc->save(_out, indentation); _file.close(); }
std::vector<cv::Matx34d> load_poses(const char *filename){ std::vector<cv::Matx34d> _resp; std::ifstream _file(filename); std::string _line; if ( !_file ){ fprintf(stderr, "Pose File : %s doesn't exist", filename); } else { while (std::getline(_file, _line)){ std::vector<double> _nums; double _num; std::istringstream iss(_line); while (!iss.eof()){ iss >> _num; _nums.push_back(_num); } if (_nums.size() >= 12){ cv::Matx34d _tmat; for ( unsigned int _i = 0; _i < 12; ++_i ){ unsigned int _c = _i % 4; unsigned int _r = _i / 4; _tmat(_r, _c) = _nums[_i]; } _resp.push_back(_tmat); } } _file.close(); } return _resp; }
std::vector<double> getData(std::string filename){ std::string tmp = filename; filename = this->name + "/Tables/" + filename; //std::cout << filename << std::endl; // cout << (this->name).substr((this->name).size() - 4, 4) << endl; std::string line; std::vector<std::string> array; std::vector<double> data; std::fstream _file ((filename).c_str()); if (!(_file.is_open()) && (this->name).substr((this->name).size() - 4, 4) != ".000") { this->name += ".000"; return getData(tmp); } getline (_file,line); getline (_file,line); split(line, " \t", array); for(std::vector<std::string>::iterator it = array.begin()+1; it != array.end(); ++it) { data.push_back(atof((*it).c_str())); } return data; }
//-------------------------------------------------------------- vector<Orbit> ofApp::setupOrbits(string _s) { vector<Orbit> _oV; ofFile _file(_s); int _counter = 0; if (_file.exists()) { _file >> json; _oV.resize( json.size() ); Orbit _orbitE; for (auto & stroke : json) { // double _a = stroke["a"]; // double _ad = stroke["ad"]; // double _e = stroke["e"]; // double _q = stroke["q"]; double _i = stroke["i"]; double _om = stroke["om"]; _orbitE.path = circlePath(stroke); _orbitE.inclination = _i; _orbitE.omega = _om; _orbitE.mVbo = circleMesh(stroke); _orbitE.per_y = stroke["per_y"]; _oV[_counter] = _orbitE; _counter++; } } else {
std::unique_ptr<CreationFile> Anaglyph::renderRight(){ std::unique_ptr<QImage> _right = this->getColorMap(0.0, 0.0, 1.0, QVector2D(-mTranslation / 2, 0.0)); std::unique_ptr<CreationFile> _file( new CreationFile(CreationFile::Type::IMAGE)); _file->pushImage(std::move(_right)); return _file; }
void MultizoneSelectFilesDialog::on_meshFileToolButton_clicked() { // Launch dialog for getting the files to import _fullMeshFilePath = QFileDialog::getOpenFileName(this, "Select the Mesh File to import", QCoreApplication::applicationDirPath(), "Mesh Files (*.su2)"); if (_fullMeshFilePath.isEmpty()) return; QFileInfo _file(_fullMeshFilePath); ui->meshFileLineEdit->setText(_file.fileName()); }
static int _parse_config_file(struct parser *p, struct config_tree *cft) { p->tb = p->te = p->fb; p->line = 1; _get_token(p, TOK_SECTION_E); if (!(cft->root = _file(p))) return_0; return 1; }
void Parse::processPML(QString type,QString pmlFileName) { QFile _file(pmlFileName); _file.open(QIODevice::ReadOnly); QByteArray _ba = _file.readAll(); _file.close(); postPML( type,"Titre", "Description", _ba); }
// ------------------------------------------------------- vector<byte> read_bytes(string _file_path) { vector<byte> _bytes; std::fstream _file(_file_path, std::ios::in | std::ios::ate | std::ios::binary); if(_file.is_open()){ _bytes.resize(_file.tellg()); _file.seekg(0 , std::ios::beg); _file.read(reinterpret_cast<char*>(&_bytes[0]), _bytes.size()); _file.close(); } return _bytes; }
void ReadAndWriteXML::load(const QString namefile, QDomDocument *doc) { QFile _file(namefile,this); _file.open(QFile::ReadWrite); QString errorStr; int errorLine; int errorColumn; if (!doc->setContent(&_file, true, &errorStr, &errorLine, &errorColumn) || !_file.isOpen()) { QMessageBox::warning(0, QObject::tr("DOM Parser"), QObject::tr("Parse error at line %1, " "column %2:\n%3").arg(errorLine).arg(errorColumn).arg(errorStr)); } if (_file.isOpen()) _file.close(); }
// Entry::shelter_storm() calculates shelter and storm penalties for the file // the king is on, as well as the two adjacent files. Value Entry::shelter_storm (const Position &pos, Square k_sq) { const Color C_ = ((WHITE == C) ? BLACK : WHITE); Value safety = MaxSafetyBonus; Bitboard front_pawns = pos.pieces (PAWN) & (front_ranks_bb (C, _rank (k_sq)) | rank_bb (k_sq)); Bitboard pawns[CLR_NO] = { front_pawns & pos.pieces (C ), front_pawns & pos.pieces (C_), }; File kf = max (F_B, min (F_G, _file (k_sq))); for (File f = kf - 1; f <= kf + 1; ++f) { Bitboard mid_pawns; mid_pawns = pawns[1] & file_bb (f); Rank b_rk = mid_pawns ? rel_rank (C, scan_rel_frntmost_sq (C_, mid_pawns)) : R_1; if ((MID_EDGE_bb & (f | b_rk)) && _file (k_sq) == f && rel_rank (C, k_sq) == b_rk - 1) { safety += Value (200); } else { mid_pawns = pawns[0] & file_bb (f); Rank w_rk = mid_pawns ? rel_rank (C, scan_rel_backmost_sq (C , mid_pawns)) : R_1; int8_t danger = (w_rk != R_1) ? ((b_rk == w_rk + 1) ? 2 : 1) : 0; safety -= ShelterWeakness[w_rk] + StormDanger[danger][b_rk]; } } return safety; }
void save_poses(const char *filename, const std::vector<cv::Matx34d> &_poses){ std::ofstream _file(filename); if ( !_file ) fprintf(stderr, "Cannot write pose to file : %s\n", filename); else { _file << std::scientific ; for ( std::vector<cv::Matx34d>::const_iterator itr = _poses.begin(); itr < _poses.end(); ++itr ){ for ( unsigned int _i = 0; _i < 12; ++_i ){ unsigned int _c = _i % 4; unsigned int _r = _i / 4; _file << (*itr)(_r, _c) << " "; } _file << std::endl; } } _file.close(); }
int main( int argc, char * argv[]) { #ifdef _DIST_ CnC::dist_cnc_init< cw_context > _dc; #endif if( argc < 3 ) { std::cerr << "expected arguments: <file> <word1> [<word2>...]\n"; exit(1); } // create the context cw_context ctxt; std::ifstream _file( argv[1] ); std::string _block; int _id = 0; // read line line while( std::getline( _file, _block ) ) { ctxt.blocks.put( _id, _block ); int i = 1; // for each line, put control for each searched string while( ++i < argc ) { ctxt.tags.put( std::make_pair( _id, argv[i] ) ); } ++_id; } // reduction needs number of reduced items // as we always put a number in the step, we know its #blocks // _id holds #blocks int i = 1; while( ++i < argc ) ctxt.red_counts.put( argv[i], _id ); ctxt.wait(); std::cout << "done" << std::endl; std::cout << ctxt.counts.size() << " " << ctxt.blocks.size() << std::endl; // iterate and write out all keys/value pairs for( auto i = ctxt.counts.begin(); i != ctxt.counts.end(); ++i ) { std::cout << i->first << " \t " << *i->second << std::endl; } ctxt.wait(); std::cout << ctxt.counts.size() << " " << ctxt.blocks.size() << std::endl; return 0; }
bool KCCodeEditor::saveAs(const QString &fileName) { QFile _file(fileName); if(_file.open(QIODevice::WriteOnly |QIODevice::Text)) { QTextStream _textOut(&_file); _textOut<<editor->toPlainText()<<flush; fileInfoChanged(_file); return true; } else { fileError=_file.error(); return false; } }
void __svc_soundfx::__load_soundfxlist(const string &filename) { ifstream _file(filename); console() << MSG__LOAD << "soundfx list \"" << filename << "\"..."; if (_file) { console() << MSG__OK; str _line; while(getline(_file, _line)) if (_line[0] != '#') __load_soundfx(_line); } else error(E__FILE_NOT_FOUND); }
int dm_config_parse(struct dm_config_tree *cft, const char *start, const char *end) { /* TODO? if (start == end) return 1; */ struct parser *p; if (!(p = dm_pool_alloc(cft->mem, sizeof(*p)))) return_0; p->mem = cft->mem; p->fb = start; p->fe = end; p->tb = p->te = p->fb; p->line = 1; _get_token(p, TOK_SECTION_E); if (!(cft->root = _file(p))) return_0; return 1; }
void MeshInfoFileWriter::writeMeshFileWriter(MeshInfoVO * _meshData) { QString _filePath = _meshData->getMeshDetailsFileName(); QFile _file(_filePath); if (_file.exists()) _file.remove(); bool _fileCreated = _file.open(QIODevice::ReadWrite | QIODevice::Text); if (_fileCreated) { QXmlStreamWriter xmlWriter(&_file); xmlWriter.setAutoFormatting(true); xmlWriter.writeStartDocument(); xmlWriter.writeStartElement(XML_MESH_ROOT); xmlWriter.writeStartElement(XML_MESH_3D_NATURE_NODE); if (_meshData->is3DMesh()) xmlWriter.writeCharacters("YES"); else xmlWriter.writeCharacters("NO"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement(XML_MESH_BND_LIST); saveBndValues(&xmlWriter,_meshData->getBoundaryNameList()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement(XML_MESH_FILE_NAME); xmlWriter.writeCharacters(_meshData->getMeshFileName()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement(XML_MESH_PATH); xmlWriter.writeCharacters(_meshData->getMeshPath()); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); } _file.close(); }
bool KCCodeEditor::open(const QString &fileName) { QFile _file(fileName); if(_file.open(QIODevice::ReadOnly |QIODevice::Text)) { QTextStream _textIn(&_file); editor->clear(); editor->setPlainText(QString(_textIn.readAll())); fileInfoChanged(_file); KCHistoryConfigure::getInstance()->addRecentFileRecord(filePath); return true; } else { fileError=_file.error(); return false; } }
void MultizoneSelectFilesDialog::on_importedConfigNameToolButton_clicked() { if (!ui->newConfigNameLineEdit->text().isEmpty()) { ShowMessageHelper _showMessage; bool _removeManualConfigLine = _showMessage.showWarningMessage("Warning! New configuration name has been previously entered!", "Warning message: You have entered the name for creating a new configuration file. If you import an existent one, the previous one will be lost. Do you want to continue?"); if (_removeManualConfigLine) ui->newConfigNameLineEdit->text().clear(); else return; } // Launch dialog for getting the files to import _fullConfigFilePath = QFileDialog::getOpenFileName(this, "Select the Configuration File to import", QCoreApplication::applicationDirPath(), "BBIPED Configuration Files (*.cfg)"); if (_fullConfigFilePath.isEmpty()) return; QFileInfo _file(_fullConfigFilePath); ui->importedConfigNameLineEdit->setText(_file.fileName()); }
bool Setting_STELA::on_line_soft_location_editingFinished() { QString line_return = ui->line_soft_location->text(); if (!line_return.isEmpty()) { QFileInfo _file(line_return + "/bin/stela.sh"); if(!_file.exists()) { ui->line_soft_location->blockSignals(true); QMessageBox::critical(0, "error", "STELA exe file not found"); ui->line_soft_location->blockSignals(false); ui->line_soft_location->setText(""); return false; } else { QDir _dir(line_return); ui->line_soft_location->setText(_dir.absolutePath()); return true; } } }
/** * @brief Main function to parse the file * */ void MeshFileParser::parseFileProcess() { QString _path = this->getFilePath(); QFile _file(_path); bool _fileCreated = false; if (_file.exists()) { _fileCreated = _file.open(QIODevice::ReadOnly); if (_fileCreated ) { QTextStream _reader(&_file); QString _line = _reader.readLine(); while(!_line.isNull()) { analyseLine(_line); _line = _reader.readLine(); } setParsedValues(_currentParsedValues); } _file.close(); } }
void Setting_STELA::on_PB_soft_location_clicked() { QString _software_dir = QFileDialog::getExistingDirectory( this, tr("Select STELA soft location"), this->software_location, QFileDialog::ShowDirsOnly ); if (!_software_dir.isEmpty()) { QFileInfo _file(_software_dir + "/bin/stela.sh"); if(!_file.exists()) { QMessageBox::critical(0, "error", "STELA exe file not found !!"); ui->line_soft_location->setText(""); } else { ui->line_soft_location->setText(_software_dir); this->software_location = _software_dir; } } }
OptionsProvider::OptionsProvider(const QString& file, QObject* parent):QObject(parent) { options.insert("*", new AnalyzerOptions()); // default QDir dir = QDir::current(); QFile _file(dir.absoluteFilePath(file)); if(_file.open(QIODevice::ReadOnly)){ QDomDocument document("options"); if(!document.setContent(&_file)){ _file.close(); return; } QDomNodeList nodes = document.elementsByTagName("option"); for(int i=0;i < nodes.count();i++){ QDomElement el = nodes.at(i).toElement(); QString key = el.attribute("url", "*"); if(!options.contains(key)){ options.insert(key, new AnalyzerOptions()); } options[key]->loadFromXml(&el); } _file.close(); } }
void CMainFrame::OnFileSave() { CFileDialog dlg( FALSE, _T("UI state"), _T(".\\Default.UI state"), OFN_ENABLESIZING|OFN_EXPLORER |OFN_LONGNAMES|OFN_PATHMUSTEXIST |OFN_NOCHANGEDIR|OFN_NODEREFERENCELINKS , _T("UI state files (*.UI state)|*.UI state|All files (*.*)|*.*||"), this ); dlg.m_ofn.lpstrTitle = _T("Save UI state to file"); if( dlg.DoModal() != IDOK ) return; ASSERT( dlg.m_ofn.lpstrFile != NULL ); try { CFile _file( dlg.m_ofn.lpstrFile, CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive ); CArchive ar( &_file, CArchive::store); CWinApp * pApp = ::AfxGetApp(); ASSERT( pApp != NULL ); ASSERT( pApp->m_pszRegistryKey != NULL ); ASSERT( pApp->m_pszRegistryKey[0] != _T('\0') ); ASSERT( pApp->m_pszProfileName != NULL ); ASSERT( pApp->m_pszProfileName[0] != _T('\0') ); VERIFY( CExtControlBar::ProfileBarStateSerialize( ar, this ) ); VERIFY( g_CmdManager->SerializeState( pApp->m_pszProfileName, ar ) ); } // try catch( CException * pXept ) { CString sErrorDescription; VERIFY( pXept->GetErrorMessage( sErrorDescription.GetBuffer(8192), 8192 ) ); sErrorDescription.ReleaseBuffer(); ASSERT( !sErrorDescription.IsEmpty() ); pXept->Delete(); MessageBox( LPCTSTR(sErrorDescription), _T("State save failed"), MB_ICONERROR ); } // catch( CException * pXept ) catch( ... ) { MessageBox( _T("Unknown exception caught"), _T("State save failed"), MB_ICONERROR ); } // catch( ... ) }
int VEditDLL::EDITFile( editstring filename , editstring helpfile ) { if( _file == NULL ) return( TRUE ); return( _file( filename, helpfile ) ); }
void MainWindow::save() { QString currentDirSave = ""; if((Canvas *)ui->tabWidget->currentWidget()) { QRect currentRect = ((Canvas*)ui->tabWidget->currentWidget())->viewport()->rect(); ((Canvas*)ui->tabWidget->currentWidget())->adjustSize(); QRect rect = ((Canvas*)ui->tabWidget->currentWidget())->drawRect().toRect(); QPixmap pixmap(rect.width(), rect.height()); QPainter painter(&pixmap); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); ((Canvas*)ui->tabWidget->currentWidget())->render(&painter, rect, rect); painter.end(); ((Canvas*)ui->tabWidget->currentWidget())->resize(currentRect.width(), currentRect.height()); QString selfilter = tr("JPEG (*.jpg *.jpeg)"); QString fileName = QFileDialog::getSaveFileName( this, tr("Save Dialog"), currentDirSave, tr("All files (*.*);;JPEG (*.jpg *.jpeg);;PNG (*.png);;XML (*.xml)" ), &selfilter ); if(!fileName.isEmpty()) { if(selfilter == "JPEG (*.jpg *.jpeg)" || selfilter == "PNG (*.png)") { if(selfilter == "JPEG (*.jpg *.jpeg)") { fileName += ".jpg"; } else { fileName += ".png"; } QStringList list = fileName.split("/"); for(int i = 0; i < list.size() - 1; ++i) { currentDirSave += list.at(i) + "/"; } QStringList listFormat = fileName.split("."); const char * format = listFormat.at(listFormat.size() - 1).toStdString().c_str(); pixmap.save(fileName, format); ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), list.at(list.size() - 1)); } else if(selfilter == "XML (*.xml)") { fileName += ".xml"; QFile _file(fileName); _file.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter writer(&_file); writer.setAutoFormatting(true); writer.writeStartDocument("1.0"); writer.writeComment("I am a good old rebel"); Canvas * current = (Canvas *)ui->tabWidget->currentWidget(); Scene * tmpScene = current->getCurrentScene(); if(tmpScene) { writer.writeStartElement("scene"); writer.writeStartElement("rect"); writer.writeStartElement("topLeft"); writer.writeAttribute("x", QString::number(currentRect.topLeft().x())); writer.writeAttribute("y", QString::number(currentRect.topLeft().y())); writer.writeEndElement(); writer.writeStartElement("bottomRight"); writer.writeAttribute("x", QString::number(currentRect.bottomRight().x())); writer.writeAttribute("y", QString::number(currentRect.bottomRight().y())); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); for(auto &i : tmpScene->shapes) { writer.writeStartElement("shape"); writer.writeStartElement("rect"); writer.writeStartElement("topLeft"); writer.writeAttribute("x", QString::number(i->boundingRect().topLeft().x())); writer.writeAttribute("y", QString::number(i->boundingRect().topLeft().y())); writer.writeEndElement(); writer.writeStartElement("bottomRight"); writer.writeAttribute("x", QString::number(i->boundingRect().bottomRight().x())); writer.writeAttribute("y", QString::number(i->boundingRect().bottomRight().y())); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("brush"); writer.writeAttribute("color", QString::number(i->brush().color().value())); writer.writeEndElement(); writer.writeStartElement("pen"); writer.writeAttribute("color", QString::number(i->pen().color().value())); writer.writeAttribute("width", QString::number(i->pen().width())); writer.writeEndElement(); writer.writeTextElement("ShapeType", QString::number(i->type())); writer.writeEndElement(); writer.writeEndDocument(); } for(auto &i : tmpScene->lines) { writer.writeStartElement("shape"); writer.writeStartElement("rect"); writer.writeStartElement("topLeft"); writer.writeAttribute("x", QString::number(i->boundingRect().topLeft().x())); writer.writeAttribute("y", QString::number(i->boundingRect().topLeft().y())); writer.writeEndElement(); writer.writeStartElement("bottomRight"); writer.writeAttribute("x", QString::number(i->boundingRect().bottomRight().x())); writer.writeAttribute("y", QString::number(i->boundingRect().bottomRight().y())); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("brush"); writer.writeAttribute("color", QString::number(i->brush().color().value())); writer.writeEndElement(); writer.writeStartElement("pen"); writer.writeAttribute("color", QString::number(i->pen().color().value())); writer.writeAttribute("width", QString::number(i->pen().width())); writer.writeEndElement(); writer.writeTextElement("ShapeType", QString::number(i->type())); writer.writeEndElement(); writer.writeEndDocument(); } } } } } }
FAT::FAT(){ vector<string> _regionsTXT; vector<string> _lineTXT; vector<string> _rowTXT; vector<string>::iterator it; initialize(); string line; ifstream _file("OS.fat"); if( _file.is_open() ){ getline(_file, line); _file.close(); _regionsTXT.clear(); Tokenize(line, _regionsTXT, "$"); _lineTXT.clear(); Tokenize(_regionsTXT[0], _lineTXT, ";"); for( int i = 0; i < 512; i++ ){ _rowTXT.clear(); Tokenize(_lineTXT[i], _rowTXT, ","); if( strcmp( _rowTXT[0].c_str(), "0x000000" ) == 0 ) _root[i]._free = true; else{ _root[i]._free = false; strcpy( _root[i].name, B_to_A( _rowTXT[1] ).c_str() ); if( strcmp(_rowTXT[2].c_str(), "0x000010" ) == 0 ) _root[i]._dir = true; else _root[i]._dir = false; _root[i]._cDate = atol( B_to_A( _rowTXT[3] ).c_str() ); _root[i]._cluster = static_cast<short>(atoi(B_to_A( _rowTXT[4]).c_str())); _root[i]._size = bitset<32>(_rowTXT[5]).to_ulong(); strcpy( _root[i].reserved, B_to_A( _rowTXT[6] ).c_str() ); } } _lineTXT.clear(); Tokenize(_regionsTXT[1], _lineTXT, ","); for( int i = 0; i < 65535; i++ ) _FAT[i] = static_cast<short>(atoi(_lineTXT[i].c_str())); _lineTXT.clear(); Tokenize(_regionsTXT[3], _lineTXT, ";"); int cont = 0; for( auto it = _lineTXT.begin(); it != _lineTXT.end(); it++ ){ if( strcmp( (*it).substr(0,2).c_str(), "0x" ) == 0 ){ _rowTXT.clear(); Tokenize( (*it), _rowTXT, "#"); for( int i = 0; i < 512; i++ ){ _regionsTXT.clear(); Tokenize( line, _rowTXT, ","); if( strcmp( _regionsTXT[0].c_str(), "0x000000" ) == 0 ) _dataRegion[cont].entries[i]._free = true; else{ _dataRegion[cont].entries[i]._free = false; strcpy( _dataRegion[cont].entries[i].name, B_to_A( _regionsTXT[1] ).c_str() ); if( strcmp(_regionsTXT[2].c_str(), "0x000010" ) == 0 ) _dataRegion[cont].entries[i]._dir = true; else _dataRegion[cont].entries[i]._dir = false; _dataRegion[cont].entries[i]._cDate = atol( B_to_A( _regionsTXT[3] ).c_str() ); _dataRegion[cont].entries[i]._cluster = static_cast<short>( atoi(B_to_A(_regionsTXT[4]).c_str()) ); _dataRegion[cont].entries[i]._size = bitset<32>(_regionsTXT[5]).to_ulong(); strcpy( _dataRegion[cont].entries[i].reserved, B_to_A( _regionsTXT[6] ).c_str() ); } } }else if( strcmp( (*it).substr(0,8).c_str(), "00000000" ) == 0 ){ }else strcpy( _dataRegion[cont].buffer, (*it).c_str() ); cont++; } } checkFreeIndex(); }
int main(int argc, char** argv) { string path=string(argv[0]); unsigned int loc=path.rfind("/"); string basepath= loc == string::npos ? "./" : path.substr(0,loc+1); basepath= osgDB::getRealPath (basepath); // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); bool pbufferOnly = !arguments.read("--show"); unsigned int width=512; unsigned int height=512; arguments.read("--pbuffer-only",width,height); int _tileColumns=0; int _tileRows=0; osg::BoundingBox totalbb; double lat=0,lon=0; arguments.read("-lat",lat); arguments.read("-lon",lon); bool untex= arguments.read("-untex"); string ext; bool nogfx= arguments.read("-nogfx",ext); std::vector<picture_cell> cells; FILE *fp=fopen(argv[1],"r"); if(!fp) { fprintf(stderr,"Can't open %s\n",argv[1]); exit(-1); } int cnt=0; while(!feof(fp)) { char fname[1024]; float minx,maxx,miny,maxy,minz,maxz; int row,col; int res=fscanf(fp,"%f %f %f %f %f %f %d %d %s\n",&minx,&maxx,&miny,&maxy,&minz,&maxz,&col,&row,fname); if(res != 9) { fprintf(stderr,"Bad parse\n"); exit(-1); } if(cnt==0) { totalbb=osg::BoundingBox(minx,miny,minz,maxx,maxy,maxz); _tileColumns=col; _tileRows=row; } else { picture_cell cell; cell.bbox=osg::BoundingBox(minx,miny,minz,maxx,maxy,maxz); cell.col=col; cell.row=row; if(std::string(fname) != "null") cell.name=std::string(argv[2])+"/"+std::string(fname); else cell.name=std::string(fname); cells.push_back(cell); } cnt++; } osg::Matrixd view,proj; std::stringstream os2; os2<< "view.mat"; std::fstream _file(os2.str().c_str(),std::ios::binary|std::ios::in); for(int i=0; i<4; i++) for(int j=0; j<4; j++) _file.read(reinterpret_cast<char*>(&(view(i,j))),sizeof(double)); for(int i=0; i<4; i++) for(int j=0; j<4; j++) _file.read(reinterpret_cast<char*>(&(proj(i,j))),sizeof(double)); _file.close(); // std::ostringstream os; // os <<"subtile.ppm";//<<":deflate"; vips::VImage raw; vips::VImage raw_untex; printf("X: %d Y: %d\n",width*_tileColumns,height*_tileRows); raw.initdesc(width*_tileColumns,height*_tileRows,3,vips::VImage::FMTUCHAR,vips::VImage::NOCODING,vips::VImage::sRGB,1.0,1.0,0,0); if(untex) raw_untex.initdesc(width*_tileColumns,height*_tileRows,3,vips::VImage::FMTUCHAR,vips::VImage::NOCODING,vips::VImage::sRGB,1.0,1.0,0,0); double vm, rss; process_mem_usage(vm, rss); cout << "VM: " << get_size_string(vm) << "; RSS: " << get_size_string(rss) << endl; osg::Matrix win; unsigned int validCount=0; for(int i=0; i < (int)cells.size(); i++) { if(cells[i].name != "null") validCount++; } osg::Timer_t startTick = osg::Timer::instance()->tick(); formatBar("Img",startTick,0,validCount); FILE *logfp=fopen("DItiming.txt","w"); int count=0; for(int i=0; i < (int)cells.size(); i++) { osg::Timer_t loopTick = osg::Timer::instance()->tick(); if(cells[i].name == "null" ) continue; if(nogfx) { char tmp[1024]; { sprintf(tmp,"mosaic/image_r%04d_c%04d_rs%04d_cs%04d.%s",cells[i].row,cells[i].col,_tileRows,_tileColumns,ext.c_str()); if(osgDB::fileExists(tmp)) { vips::VImage tmpI(tmp); raw.insertplace(tmpI.extract_bands(0,3),width*cells[i].col,height*(_tileRows-cells[i].row-1)); } else { vips::VImage tmpI; tmpI.initdesc(width,height,3,vips::VImage::FMTUCHAR,vips::VImage::NOCODING,vips::VImage::sRGB,1.0,1.0,0,0); memset(tmpI.data(),255,width*height*3); raw.insertplace(tmpI,width*cells[i].col,height*(_tileRows-cells[i].row-1)); fprintf(stderr,"Can't find %s\n",tmp); } } if(untex) { sprintf(tmp,"mosaic/image_r%04d_c%04d_rs%04d_cs%04d_untex.%s",cells[i].row,cells[i].col,_tileRows,_tileColumns,ext.c_str()); if(osgDB::fileExists(tmp)) { vips::VImage tmpI(tmp); raw_untex.insertplace(tmpI.extract_bands(0,3),width*cells[i].col,height*(_tileRows-cells[i].row-1)); } else { vips::VImage tmpI; tmpI.initdesc(width,height,3,vips::VImage::FMTUCHAR,vips::VImage::NOCODING,vips::VImage::sRGB,1.0,1.0,0,0); memset(tmpI.data(),255,width*height*3); raw.insertplace(tmpI,width*cells[i].col,height*(_tileRows-cells[i].row-1)); fprintf(stderr,"Can't find %s\n",tmp); } } } else { osgViewer::Viewer viewer(arguments); GLenum readBuffer = GL_BACK; WindowCaptureCallback::FramePosition position = WindowCaptureCallback::END_FRAME; WindowCaptureCallback::Mode mode = WindowCaptureCallback::SINGLE_PBO; osg::ref_ptr<osg::GraphicsContext> pbuffer; { osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = 0; traits->y = 0; traits->width = width; traits->height = height; traits->red = 8; traits->green = 8; traits->blue = 8; traits->alpha = 8; traits->windowDecoration = false; traits->pbuffer = true; traits->doubleBuffer = true; traits->sharedContext = 0; pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get()); //std::cout << "Buffer obj "<< pbuffer->getState()->getMaxBufferObjectPoolSize() << " tex "<< pbuffer->getState()->getMaxBufferObjectPoolSize() <<std::endl; if (pbuffer.valid()) { // osg::notify(osg::INFO)<<"Pixel buffer has been created successfully."<<std::endl; } else { osg::notify(osg::INFO)<<"Pixel buffer has not been created successfully."<<std::endl; } } osg::ref_ptr<WindowCaptureCallback> wcc=new WindowCaptureCallback(mode, position, readBuffer); osg::ref_ptr<osg::Camera> camera; if (pbuffer.valid()) { camera = new osg::Camera; camera->setGraphicsContext(pbuffer.get()); camera->setViewport(new osg::Viewport(0,0,width,height)); GLenum buffer = pbuffer->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT; camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); camera->setFinalDrawCallback(wcc); if (pbufferOnly) { viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); viewer.realize(); } else { viewer.realize(); viewer.stopThreading(); pbuffer->realize(); viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); viewer.startThreading(); } } else { viewer.realize(); addCallbackToViewer(viewer, wcc); } osg::Timer_t timeEndSetup = osg::Timer::instance()->tick(); //double setupTime = osg::Timer::instance()->delta_s(loopTick, timeEndSetup); // load the data osg::Matrixd offsetMatrix=osg::Matrixd::scale(_tileColumns, _tileRows, 1.0)*osg::Matrixd::translate(_tileColumns-1-2*cells[i].col, _tileRows-1-2*cells[i].row, 0.0); /* printf("\r%03d/%03d",i,(int)cells.size()); fflush(stdout); */ // std::cout <<"row: "<<cells[i].row << " col: "<<cells[i].col<<" tc: "<<_tileColumns << " "<<_tileRows<<" "<<"\n"<<osg::Matrix::scale(_tileColumns, _tileRows, 1.0) << "\n"<<osg::Matrix::translate(_tileColumns-1-2*cells[i].col, _tileRows-1-2*cells[i].row, 0.0) <<"\n"<<offsetMatrix<<endl; osg::ref_ptr<osg::Node> node=osgDB::readNodeFile(cells[i].name); osg::Timer_t timeEndLoad = osg::Timer::instance()->tick(); double loadTime = osg::Timer::instance()->delta_s(timeEndSetup, timeEndLoad); int mem=0; if (node.valid() ) { viewer.setSceneData( node ); viewer.getCamera()->setProjectionMatrix(proj*offsetMatrix); viewer.getCamera()->setViewMatrix(view); viewer.frame(); viewer.advance(); viewer.updateTraversal(); viewer.renderingTraversals(); osg::Timer_t timeEndRender = osg::Timer::instance()->tick(); double renderTime = osg::Timer::instance()->delta_s(timeEndLoad, timeEndRender); gpuUsage(1,mem); fprintf(logfp,"cnt: %d load %.1fs render: %.1fs mem1: %d MB",count,loadTime,renderTime,mem); osg::Image *img=(wcc->getContextData(pbuffer)->_imageBuffer[wcc->getContextData(pbuffer)->_currentImageIndex]); vips::VImage tmp(img->data(),img->s(),img->t(),4,vips::VImage::FMTUCHAR); raw.insertplace(tmp.flipver().extract_bands(0,3),width*cells[i].col,height*(_tileRows-cells[i].row-1)); if(untex) { node->getOrCreateStateSet()->addUniform(new osg::Uniform("shaderOut",3)); viewer.setSceneData( node ); viewer.frame(); viewer.advance(); viewer.updateTraversal(); viewer.renderingTraversals(); osg::Timer_t timeEndRender2 = osg::Timer::instance()->tick(); double renderTime2 = osg::Timer::instance()->delta_s(timeEndRender, timeEndRender2); gpuUsage(1,mem); osg::Image *img=(wcc->getContextData(pbuffer)->_imageBuffer[wcc->getContextData(pbuffer)->_currentImageIndex]); vips::VImage tmp(img->data(),img->s(),img->t(),4,vips::VImage::FMTUCHAR); raw_untex.insertplace(tmp.flipver().extract_bands(0,3),width*cells[i].col,height*(_tileRows-cells[i].row-1)); fprintf(logfp," render2: %.1fs mem2: %d",renderTime2,mem); } } else { std::cout << "Invalid " << cells[i].name << "\n"; } } formatBar("Img",startTick,++count,validCount); osg::Timer_t timeEndLoop = osg::Timer::instance()->tick(); double loopTime = osg::Timer::instance()->delta_s(loopTick, timeEndLoop); fprintf(logfp," loop: %.1fs\n",loopTime); fflush(logfp); } formatBar("Img",startTick,validCount,validCount); osg::Timer_t writeStart = osg::Timer::instance()->tick(); process_mem_usage(vm, rss); cout << "VM: " << get_size_string(vm) << "; RSS: " << get_size_string(rss) << endl; raw.write("subtile.v"); double writeTime = osg::Timer::instance()->delta_s(writeStart, osg::Timer::instance()->tick()); fprintf(logfp,"Write Time %.1fs\n",writeTime); if(untex) { osg::Timer_t writeStart = osg::Timer::instance()->tick(); raw_untex.write("subtile_untex.v"); double writeTime = osg::Timer::instance()->delta_s(writeStart, osg::Timer::instance()->tick()); fprintf(logfp,"Write Time 2 %.1fs\n",writeTime); } printf("Done\n"); fclose(logfp); applyGeoTags("subtile.tif",osg::Vec2(lat,lon),view*proj,raw.Xsize(),raw.Ysize(),basepath); }
// Hash key of the complete position. Key Zob::compute_posi_key (const Position &pos) const { Key posi_key = U64 (0); //for (Square s = SQ_A1; s <= SQ_H8; ++s) //{ // Piece p = pos[s]; // posi_key ^= _.psq_k[_color (p)][_ptype (p)][s]; //} //for (Color c = WHITE; c <= BLACK; ++c) //{ // for (PieceT pt = PAWN; pt <= KING; ++pt) // { // vector<Square> sq_lst = squares (pos[c] & pos[pt]); // for (int32_t pc = 0; pc < sq_lst.size (); ++pc) // { // Square s = sq_lst[pc]; // posi_key ^= _.psq_k[c][pt][s]; // } // } //} //Bitboard occ = pos.pieces (); //while (occ) //{ // Square s = pop_lsq (occ); // Piece p = pos[s]; // posi_key ^= _.psq_k[_color (p)][_ptype (p)][s]; //} for (Color c = WHITE; c <= BLACK; ++c) { for (PieceT pt = PAWN; pt <= KING; ++pt) { const Square *pl = pos[(c | pt)]; Square s; while ((s = *pl++) != SQ_NO) { posi_key ^= _.psq_k[c][pt][s]; } } } //if (pos.can_castle (CR_A)) //{ // for (Color c = WHITE; c <= BLACK; ++c) // { // if (pos.can_castle (c)) // { // for (CSide cs = CS_K; cs <= CS_Q; ++cs) // { // if (pos.can_castle (c, cs)) posi_key ^= _.castle_right[c][cs]; // } // } // } //} Bitboard b = pos.castle_rights (); while (b) posi_key ^= _.castle_right[0][pop_lsq (b)]; Square ep_sq = pos.en_passant (); if (SQ_NO != ep_sq) posi_key ^= _.en_passant[_file (ep_sq)]; if (WHITE == pos.active ()) posi_key ^= _.mover_side; return posi_key; }