void addonTransfer::sendFile(std::string filename) { boost::upgrade_lock<boost::shared_mutex> lockit(tMutex); boost::filesystem::path fpath(filename); if(transfering) { return; //already started } if(!boost::filesystem::exists(fpath)) { // file does not exist; return; } std::size_t file_size = boost::filesystem::file_size(fpath); int file_crc = addonHash::crc32_file(filename); gSocket->writeTo(boost::str(boost::format("CMDRESPONSE|%1%|%2%|%3%|%4%") % ADDON_CMD_QUERY_TRF % filename % file_size % file_crc)); { boost::upgrade_to_unique_lock<boost::shared_mutex> lockit_(lockit); transfering = true; } tHandle = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&addonTransfer::sendFileThread, this, filename, file_size, file_crc))); }
static void outputStateVtk(const UnstructuredGrid& grid, const Opm::BlackoilState& state, const int step, const std::string& output_dir) { // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; boost::filesystem::path fpath(vtkfilename.str()); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } vtkfilename << "/output-" << std::setw(3) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { OPM_THROW(std::runtime_error, "Failed to open " << vtkfilename.str()); } Opm::DataMap dm; dm["saturation"] = &state.saturation(); dm["pressure"] = &state.pressure(); std::vector<double> cell_velocity; Opm::estimateCellVelocity(grid, state.faceflux(), cell_velocity); dm["velocity"] = &cell_velocity; Opm::writeVtkData(grid, dm, vtkfile); }
void W3cXmlPlugin::WriteManifestFile(const QString &aPath) { QString newList("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n <widget xmlns=\"http://www.w3.org/ns/widgets\" id=\""); newList.append(m_metadata->value(W3CSettingsKey::WIDGET_ID).toString()); newList.append("\" version=\""); newList.append(m_metadata->value(W3CSettingsKey::WIDGET_VERSION).toString()); newList.append("\" height=\""); newList.append(m_metadata->value(W3CSettingsKey::WIDGET_HEIGHT).toString()); newList.append("\" width=\""); newList.append(m_metadata->value(W3CSettingsKey::WIDGET_WIDTH).toString()); newList.append("\" xml:lang=\""); newList.append(m_metadata->value(W3CSettingsKey::WIDGET_LANG).toString()); newList.append("\">\n"); newList.append("<name>"); newList.append(value(W3CSettingsKey::WIDGET_NAME)); newList.append("</name>\n"); newList.append("<content src=\""); newList.append(value(W3CSettingsKey::WIDGET_CONTENT , QString("src"))); newList.append("\"/>\n"); newList.append("</widget>"); LOG("*********\n\n" << newList); QString fpath(aPath); if (aPath.isEmpty()) fpath=QDesktopServices::storageLocation(QDesktopServices::TempLocation)+QDir::separator()+"config.xml"; QFile file(fpath); file.open(QIODevice::WriteOnly); file.write(newList.toUtf8().data(),newList.length()); file.close(); }
void error(char *str) { (void) fprintf(stderr, "\n%s:", procnam); fpath(stderr); (void) fprintf(stderr, ":%d %s\n", fline[ifx], str); error3(); }
void TextureRes::reserveData(){ if ( _pImgData == NULL ){ _f fpath(_fileName.c_str()); int numChannels; int w, h; _pImgData = SOIL_load_image(fpath, &w, &h, &numChannels, SOIL_LOAD_AUTO); } }
// // 1. Iterates through the chisel files on disk (.sc and .lua) // 2. Opens them and extracts the fields (name, description, etc) // 3. Adds them to the chisel_descs vector. // void sinsp_chisel::get_chisel_list(vector<chisel_desc>* chisel_descs) { for(vector<chiseldir_info>::const_iterator it = g_chisel_dirs->begin(); it != g_chisel_dirs->end(); ++it) { if(string(it->m_dir).empty()) { continue; } tinydir_dir dir; tinydir_open(&dir, it->m_dir); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); string fpath(file.path); bool add_to_vector = false; chisel_desc cd; filename fn = split_filename(string(file.name)); if(fn.ext != "sc" && fn.ext != "lua") { goto next_file; } for(vector<chisel_desc>::const_iterator it_desc = chisel_descs->begin(); it_desc != chisel_descs->end(); ++it_desc) { if(fn.name == it_desc->m_name) { goto next_file; } } cd.m_name = fn.name; #ifdef HAS_LUA_CHISELS if(fn.ext == "lua") { add_to_vector = init_lua_chisel(cd, fpath); } if(add_to_vector) { chisel_descs->push_back(cd); } #endif next_file: tinydir_next(&dir); } tinydir_close(&dir); } }
void PathGroups::addPath(QString flnm) { QFile fpath(flnm); fpath.open(QFile::ReadOnly); QTextStream fd(&fpath); QString line = fd.readLine(); if (line.contains("#indexed", Qt::CaseInsensitive)) { addIndexedPath(flnm); return; } PathGroupGrabber *pg = new PathGroupGrabber(); while (! fd.atEnd()) { QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 1) { int npts = list[0].toInt(); QList<Vec> pts; for(int i=0; i<npts; i++) { if (fd.atEnd()) break; else { QString line = fd.readLine(); QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 3) { float x = list[0].toFloat(); float y = list[1].toFloat(); float z = list[2].toFloat(); pts.append(Vec(x,y,z)); } } } if (pts.count() > 0) pg->addPoints(pts); } line = fd.readLine(); } m_paths.append(pg); makePathConnections(); }
void FileWatcherWin32::handleAction(Watcher* watch, const std::string& filename, unsigned long action, std::string oldFilename) { Action fwAction; switch(action) { case FILE_ACTION_RENAMED_OLD_NAME: watch->OldFileName = filename; return; case FILE_ACTION_ADDED: fwAction = Actions::Add; break; case FILE_ACTION_RENAMED_NEW_NAME: { fwAction = Actions::Moved; std::string fpath( watch->Directory + filename ); // Update the directory path if ( watch->Recursive && FileSystem::isDirectory( fpath ) ) { // Update the new directory path std::string opath( watch->Directory + watch->OldFileName ); FileSystem::dirAddSlashAtEnd( opath ); FileSystem::dirAddSlashAtEnd( fpath ); for ( WatchVector::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) { if ( (*it)->Watch->Directory == opath ) { (*it)->Watch->Directory = fpath; break; } } } watch->Listener->handleFileAction(watch->ID, static_cast<WatcherWin32*>( watch )->DirName, filename, fwAction, watch->OldFileName); return; } case FILE_ACTION_REMOVED: fwAction = Actions::Delete; break; case FILE_ACTION_MODIFIED: fwAction = Actions::Modified; break; }; watch->Listener->handleFileAction(watch->ID, static_cast<WatcherWin32*>( watch )->DirName, filename, fwAction); }
void PathGroups::addVector(QString flnm) { QFile fpath(flnm); fpath.open(QFile::ReadOnly); QTextStream fd(&fpath); QString line = fd.readLine(); PathGroupGrabber *pg = new PathGroupGrabber(); QList<Vec> pts; while (! fd.atEnd()) { QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 1) { int npts = list[0].toInt(); for(int i=0; i<npts; i++) { if (fd.atEnd()) break; else { QString line = fd.readLine(); QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() > 3) { float x = list[0].toFloat(); float y = list[1].toFloat(); float z = list[2].toFloat(); pts.append(Vec(x,y,z)); x += list[3].toFloat(); if (list.count() > 4) y += list[4].toFloat(); if (list.count() > 5) z += list[5].toFloat(); pts.append(Vec(x,y,z)); } } } } line = fd.readLine(); } pg->setVectorPoints(pts); m_paths.append(pg); makePathConnections(); }
// \TODO: Treat bcs. SimulatorFullyImplicitCompressiblePolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const DerivedGeology& geo, const BlackoilPropsAdInterface& props, const PolymerPropsAd& polymer_props, const RockCompressibility* rock_comp_props, std::shared_ptr<EclipseState> eclipse_state, EclipseWriter& output_writer, Opm::DeckConstPtr& deck, NewtonIterationBlackoilInterface& linsolver, const double* gravity) : grid_(grid), props_(props), polymer_props_(polymer_props), rock_comp_props_(rock_comp_props), eclipse_state_(eclipse_state), output_writer_(output_writer), deck_(deck), linsolver_(linsolver), gravity_(gravity), geo_(geo) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
// \TODO: Treat bcs. SimulatorFullyImplicitBlackoil::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropsAdInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), gravity_(gravity), geo_(grid_, props_, gravity_), solver_(grid_, props_, geo_, rock_comp_props, *wells_manager.c_wells(), linsolver) /* param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, */ { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
static void lnsync(FILE *iop) { static int cline = 0; static int cfile = 0; if (!sflag || iop != stdout) return; if (nflag || ifx != cfile) { nflag = 0; cfile = ifx; (void) fprintf(iop, "#line %d \"", cline = fline[ifx]); fpath(iop); (void) fprintf(iop, "\"\n"); } else if (++cline != fline[ifx]) (void) fprintf(iop, "#line %d\n", cline = fline[ifx]); }
FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; String tpath( path ); if ( tpath[ tpath.size() - 1 ] == '/' || tpath[ tpath.size() - 1 ] == '\\' ) { tpath += "*"; } else { tpath += "\\*"; } WIN32_FIND_DATAW findFileData; HANDLE hFind = FindFirstFileW( (LPCWSTR)tpath.toWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { std::string name( String( findFileData.cFileName ).toUtf8() ); std::string fpath( path + name ); if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } while( FindNextFileW( hFind, &findFileData ) ) { name = String( findFileData.cFileName ).toUtf8(); fpath = path + name; if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } } FindClose( hFind ); } return files; }
void GA::Initialize(std::string filePath){ std::string fpath(filePath); baseCityVector = loadDataFromFile(fpath); std::cout << "City vector size: " << baseCityVector.size() << "\n"; for(const auto& c : baseCityVector) std::cout << c << "\n"; distances = createDistanceMatrix(baseCityVector); for(int i = 0; i < populationSize ; i++){ population.push_back( Candidate(generateRandomCandidate(baseCityVector),distances) ); } maxXPosition = 0; maxYPosition = 0; for(const auto& city : population[0].getCandidate()){ if(city.getX() > maxXPosition) maxXPosition = city.getX(); if(city.getY() > maxYPosition) maxYPosition = city.getY(); } }
bool cImage::SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ) { bool Res = false; std::string fpath( FileSystem::FileRemoveFileName( filepath )); if ( !FileSystem::IsDirectory( fpath ) ) FileSystem::MakeDir( fpath ); if ( NULL != mPixels && 0 != mWidth && 0 != mHeight && 0 != mChannels ) { if ( SAVE_TYPE_JPG != Format ) { Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, (Int32)mWidth, (Int32)mHeight, mChannels, GetPixelsPtr() ) ); } else { jpge::params params; params.m_quality = JpegQuality(); Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), mWidth, mHeight, mChannels, GetPixelsPtr(), params); } } return Res; }
int load_file(const char *directory, const char *ip) { char block_type; int sock, file; int trans_cond = EXIT_SUCCESS; /** Opening socket descriptor */ if ((sock = open_socket(ip)) == EXIT_FAILURE) { return EXIT_FAILURE; } /** Reading block until all files will not be received **/ while (read_total(sock, &block_type, 1) == 1 && block_type == BLOCK_FILE_START) { /** Reading file name **/ const char *file_name = (const char *) read_data(sock, '\n', 0); /** Concatinating into file path **/ char *file_path = fpath(file_name, directory); /** Reading file size **/ off_t file_size = *((unsigned long *) read_data(sock, 0, 8)); /** Opening file descriptor */ if ((file = open_file(file_path, O_CREAT | O_WRONLY)) == EXIT_FAILURE) { return EXIT_FAILURE; } setup_bar(file_name, file_size); trans_cond = transfer_data(sock, file, 0, file_size); /** Closing streams **/ close(file); /** Checking for transfer condition **/ if (trans_cond == EXIT_FAILURE) { /** Nothing to do now **/ break; } printf("\n"); } /** Checking for transaction success **/ if (trans_cond == EXIT_SUCCESS) { block_type = BLOCK_FILE_END; write_total(sock, &block_type, 1); } shutdown(sock, SHUT_RDWR); return trans_cond; }
void outputStateVtk(const Dune::CpGrid& grid, const Opm::BlackoilState& state, const int step, const std::string& output_dir) { // Write data in VTK format. std::ostringstream vtkfilename; std::ostringstream vtkpath; vtkpath << output_dir << "/vtk_files"; vtkpath << "/output-" << std::setw(3) << std::setfill('0') << step; boost::filesystem::path fpath(vtkpath.str()); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } vtkfilename << "output-" << std::setw(3) << std::setfill('0') << step; #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 3) Dune::VTKWriter<Dune::CpGrid::LeafGridView> writer(grid.leafGridView(), Dune::VTK::nonconforming); #else Dune::VTKWriter<Dune::CpGrid::LeafGridView> writer(grid.leafView(), Dune::VTK::nonconforming); #endif writer.addCellData(state.saturation(), "saturation", state.numPhases()); writer.addCellData(state.pressure(), "pressure", 1); std::vector<double> cell_velocity; Opm::estimateCellVelocity(AutoDiffGrid::numCells(grid), AutoDiffGrid::numFaces(grid), AutoDiffGrid::beginFaceCentroids(grid), AutoDiffGrid::faceCells(grid), AutoDiffGrid::beginCellCentroids(grid), AutoDiffGrid::beginCellVolumes(grid), AutoDiffGrid::dimensions(grid), state.faceflux(), cell_velocity); writer.addCellData(cell_velocity, "velocity", Dune::CpGrid::dimension); writer.pwrite(vtkfilename.str(), vtkpath.str(), std::string("."), Dune::VTK::ascii); }
bool CreateShortcut(wxString path, wxString name, wxString dest, wxString args, wxString iconPath) { wxString fname (Utils::RemoveInvalidFilenameChars(name, '_') + ".desktop"); wxFileName fpath(path, fname, wxPATH_NATIVE); fpath.MakeAbsolute(); path = fpath.GetFullPath(); std::ofstream desktopfile (path); if (!desktopfile.is_open()) return false; desktopfile << "[Desktop Entry]" << std::endl; desktopfile << "Type=Application" << std::endl; desktopfile << "Exec=" << dest << " " << args << std::endl; desktopfile << "Name=" << name << std::endl; desktopfile << "Icon=" << iconPath << std::endl; desktopfile.close(); chmod(path, 0755); return true; }
bool PathGroups::checkForMultiplePaths(QString flnm) { int npaths = 0; QFile fpath(flnm); fpath.open(QFile::ReadOnly); QTextStream fd(&fpath); QString line = fd.readLine(); if (line.contains("#indexed", Qt::CaseInsensitive)) // return true; while (! fd.atEnd()) { QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 1) { int npts = list[0].toInt(); if (npts > 0) npaths ++; if (npaths > 1) return true; for(int i=0; i<npts; i++) { if (fd.atEnd()) break; else fd.readLine(); } } line = fd.readLine(); } return (npaths > 1); }
/** * Scan a directory (no-recursion) for shared-object modules and load them. */ void Host::FindBasicModules(std::string& dir) { Poco::Mutex::ScopedLock lock(moduleMutex); Poco::DirectoryIterator iter = Poco::DirectoryIterator(dir); Poco::DirectoryIterator end; while (iter != end) { Poco::File f = *iter; if (!f.isDirectory() && !f.isHidden()) { std::string fpath(iter.path().absolute().toString()); if (IsModule(fpath)) { this->LoadModule(fpath, this); } else { this->AddInvalidModuleFile(fpath); } } iter++; } }
TextureRes::TextureRes(const char* fileName, bool reserveData, bool revertY) : _glId(-1), _pImgData(NULL){ lwassert(fileName); _fileName = fileName; size_t len = strlen(fileName); if ( len < 4 ){ lwerror("texture file name too short: filepath = " << _f(fileName)); _glId = -1; return; } _f fpath(fileName); if ( fileName[len-4] == '.' && fileName[len-3] == 'p' && fileName[len-2] == 'n' && fileName[len-1] == 'g'){ if ( fpath.isValid() ){ loadPNG(fpath, reserveData); }else{ lwerror("texture is not exist: " << fileName); return; } }else{ lwerror("only support PNG file: " << fileName); return; } }
SimulatorPolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const IncompPropertiesInterface& props, const PolymerProperties& poly_props, const RockCompressibility* rock_comp_props, const Wells* wells, const std::vector<double>& src, const FlowBoundaryConditions* bcs, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), poly_props_(poly_props), rock_comp_props_(rock_comp_props), wells_(wells), src_(src), bcs_(bcs), linsolver_(linsolver), gravity_(gravity), psolver_(grid, props, rock_comp_props, poly_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells, src, bcs), tsolver_(grid, props, poly_props, TransportModelPolymer::Bracketing, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)), poly_inflow_(param.getDefault("poly_start_days", 300.0)*Opm::unit::day, param.getDefault("poly_end_days", 800.0)*Opm::unit::day, param.getDefault("poly_amount", poly_props.cMax())) { // For output. output_ = param.getDefault("output", true); if (output_) { output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { THROW("Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Transport related init. TransportModelPolymer::SingleCellMethod method; std::string method_string = param.getDefault("single_cell_method", std::string("Bracketing")); if (method_string == "Bracketing") { method = Opm::TransportModelPolymer::Bracketing; } else if (method_string == "Newton") { method = Opm::TransportModelPolymer::Newton; } else { THROW("Unknown method: " << method_string); } tsolver_.setPreferredMethod(method); num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_){ tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
SimulatorIncompTwophase::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const IncompPropertiesInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const std::vector<double>& src, const FlowBoundaryConditions* bcs, LinearSolverInterface& linsolver, const double* gravity) : use_reorder_(param.getDefault("use_reorder", true)), use_segregation_split_(param.getDefault("use_segregation_split", false)), grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), src_(src), bcs_(bcs), psolver_(grid, props, rock_comp_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells(), src, bcs) { // Initialize transport solver. if (use_reorder_) { tsolver_.reset(new Opm::TransportSolverTwophaseReorder(grid, props, use_segregation_split_ ? gravity : NULL, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30))); } else { if (rock_comp_props && rock_comp_props->isActive()) { OPM_THROW(std::runtime_error, "The implicit pressure solver cannot handle rock compressibility."); } if (use_segregation_split_) { OPM_THROW(std::runtime_error, "The implicit pressure solver is not set up to use segregation splitting."); } std::vector<double> porevol; computePorevolume(grid, props.porosity(), porevol); tsolver_.reset(new Opm::TransportSolverTwophaseImplicit(grid, props, porevol, gravity, psolver_.getHalfTrans(), param)); } // For output. log_ = param.getDefault("quiet", false) ? &Opm::null_stream : &std::cout; output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
wxString S3D_FILENAME_RESOLVER::ResolvePath( const wxString& aFileName ) { wxCriticalSectionLocker lock( lock3D_resolver ); if( aFileName.empty() ) return wxEmptyString; if( m_Paths.empty() ) createPathList(); // look up the filename in the internal filename map std::map< wxString, wxString, S3D::rsort_wxString >::iterator mi; mi = m_NameMap.find( aFileName ); if( mi != m_NameMap.end() ) return mi->second; // first attempt to use the name as specified: wxString tname = aFileName; #ifdef _WIN32 // translate from KiCad's internal UNIX-like path to MSWin paths tname.Replace( wxT( "/" ), wxT( "\\" ) ); #endif // this case covers full paths and paths relative to // the current working directory (which is not necessarily // the current project directory) if( wxFileName::FileExists( tname ) ) { wxFileName tmp( tname ); if( tmp.Normalize() ) tname = tmp.GetFullPath(); m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } // at this point aFileName: // a. is a legacy ${} shortened name // b. an aliased shortened name // c. cannot be determined if( aFileName.StartsWith( wxT( "${" ) ) ) { wxFileName tmp( aFileName ); if( tmp.Normalize() ) { tname = tmp.GetFullPath(); m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } else if( resolveVirtualEnv( aFileName, tname ) ) { m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } if( !( m_errflags & ERRFLG_ENVPATH ) ) { m_errflags |= ERRFLG_ENVPATH; wxString errmsg = _( "[3D File Resolver] No such path; ensure the environment var is defined" ); errmsg.append( "\n" ); errmsg.append( tname ); wxLogMessage( "%s\n", errmsg.ToUTF8() ); } return wxEmptyString; } std::list< S3D_ALIAS >::const_iterator sPL = m_Paths.begin(); std::list< S3D_ALIAS >::const_iterator ePL = m_Paths.end(); // check the path relative to the current project directory; // note: this is not necessarily the same as the current working // directory, which has already been checked. This case accounts // for partial paths which do not contain ${KIPRJMOD}. if( !sPL->m_pathexp.empty() ) { wxFileName fpath( wxFileName::DirName( sPL->m_pathexp ) ); wxString fullPath = fpath.GetPathWithSep() + tname; if( wxFileName::FileExists( fullPath ) ) { wxFileName tmp( fullPath ); if( tmp.Normalize() ) tname = tmp.GetFullPath(); m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } } // ${ENV_VAR} paths have already been checked; skip all but // ${KISYS3DMOD}, since legacy behavior was to check if paths // were relative to ${KISYS3DMOD} while( sPL != ePL && sPL->m_alias.StartsWith( "${" ) ) { if( sPL->m_alias == "${KISYS3DMOD}" ) { wxFileName fpath( wxFileName::DirName( sPL->m_pathexp ) ); wxString fullPath = fpath.GetPathWithSep() + tname; if( wxFileName::FileExists( fullPath ) ) { wxFileName tmp( fullPath ); if( tmp.Normalize() ) tname = tmp.GetFullPath(); m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } } ++sPL; } // at this point the filename must contain an alias or else it is invalid wxString alias; // the alias portion of the short filename wxString relpath; // the path relative to the alias if( !SplitAlias( tname, alias, relpath ) ) { if( !( m_errflags & ERRFLG_RELPATH ) ) { // this can happen if the file was intended to be relative to // ${KISYS3DMOD} but ${KISYS3DMOD} not set or incorrect. m_errflags |= ERRFLG_RELPATH; wxString errmsg = _( "[3D File Resolver] No such path" ); errmsg.append( "\n" ); errmsg.append( tname ); wxLogTrace( MASK_3D_RESOLVER, "%s\n", errmsg.ToUTF8() ); } return wxEmptyString; } while( sPL != ePL ) { if( !sPL->m_alias.Cmp( alias ) && !sPL->m_pathexp.empty() ) { wxFileName fpath( wxFileName::DirName( sPL->m_pathexp ) ); wxString fullPath = fpath.GetPathWithSep() + relpath; if( wxFileName::FileExists( fullPath ) ) { wxFileName tmp( fullPath ); if( tmp.Normalize() ) tname = tmp.GetFullPath(); m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); return tname; } } ++sPL; } if( !( m_errflags & ERRFLG_ALIAS ) ) { m_errflags |= ERRFLG_ALIAS; wxString errmsg = _( "[3D File Resolver] No such path; ensure the path alias is defined" ); errmsg.append( "\n" ); errmsg.append( tname.substr( 1 ) ); wxLogTrace( MASK_3D_RESOLVER, "%s\n", errmsg.ToUTF8() ); } return wxEmptyString; }
void MakeTRDFullMisAlignment(){ // Create TClonesArray of full misalignment objects for TRD // Expects to read objects for FRAME // TClonesArray *array = new TClonesArray("AliAlignObjParams",1000); const char* macroname = "MakeTRDFullMisAlignment.C"; // Activate CDB storage and load geometry from CDB AliCDBManager* cdb = AliCDBManager::Instance(); if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); cdb->SetRun(0); AliCDBStorage* storage; TString Storage; if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){ Storage = gSystem->Getenv("STORAGE"); if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) { Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()); return; } storage = cdb->GetStorage(Storage.Data()); if(!storage){ Error(macroname,"Unable to open storage %s\n",Storage.Data()); return; } AliCDBPath path("GRP","Geometry","Data"); AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun()); if(!entry) Fatal(macroname,"Could not get the specified CDB entry!"); entry->SetOwner(0); TGeoManager* geom = (TGeoManager*) entry->GetObject(); AliGeomManager::SetGeometry(geom); }else{ AliGeomManager::LoadGeometry(); //load geom from default CDB storage } // load FRAME full misalignment objects (if needed, the macro // for FRAME has to be ran in advance) and apply them to geometry AliCDBPath fpath("GRP","Align","Data"); AliCDBEntry *eFrame; if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){ Info(macroname,"Loading FRAME alignment objects from CDB storage %s", Storage.Data()); eFrame = storage->Get(fpath.GetPath(),cdb->GetRun()); }else{ eFrame = cdb->Get(fpath.GetPath()); } if(!eFrame) Fatal(macroname,"Could not get the specified CDB entry!"); TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject(); arFrame->Sort(); Int_t nvols = arFrame->GetEntriesFast(); Bool_t flag = kTRUE; for(Int_t j=0; j<nvols; j++) { AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j); if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE; } if(!flag) Fatal(macroname,"Error in the application of FRAME objects"); // Sigmas for the chambers Double_t smdx = 0.3; // 3 mm Double_t smdy = 0.3; // 3 mm Double_t smdz = 0.3; // 3 mm Double_t smrx = 0.4 / 1000.0 / TMath::Pi()*180; // 0.4 mrad Double_t smry = 2.0 / 1000.0 / TMath::Pi()*180; // 2.0 mrad Double_t smrz = 0.4 / 1000.0 / TMath::Pi()*180; // 0.4 mrad // Truncation for the chambers Double_t cutSmdx = 3.0 * smdx; Double_t cutSmdy = 3.0 * smdy; Double_t cutSmdz = 3.0 * smdz; // Sigmas for the chambers Double_t chdx = 0.05; // 0.5 mm Double_t chdy = 0.1; // 1.0 mm Double_t chdz = 0.007; // 70 microns Double_t chrx = 0.0005 / 1000.0 / TMath::Pi()*180; // 0 mrad Double_t chry = 0.0005 / 1000.0 / TMath::Pi()*180; // 0 mrad Double_t chrz = 0.3 / 1000.0 / TMath::Pi()*180; // 0.3 mrad // Truncation for the chambers Double_t cutChdx = 1.0 * chdx; Double_t cutChdy = 1.0 * chdy; Double_t cutChdz = 0.14 * chdz; Int_t sActive[18]={1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1}; Double_t dx,dy,dz,rx,ry,rz; Int_t j=0; UShort_t volid; const char *symname; // create the supermodules' alignment objects for (int iSect; iSect<18; iSect++) { TString sm_symname(Form("TRD/sm%02d",iSect)); dx = AliMathBase::TruncatedGaus(0.0,smdx,cutSmdx); dy = AliMathBase::TruncatedGaus(0.0,smdy,cutSmdy); dz = AliMathBase::TruncatedGaus(0.0,smdz,cutSmdz); rx = gRandom->Rndm() * 2.0*smrx - smrx; ry = gRandom->Rndm() * 2.0*smry - smry; rz = gRandom->Rndm() * 2.0*smrz - smrz; if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue; new((*array)[j++]) AliAlignObjParams(sm_symname.Data(),0,dx,dy,dz,rx,ry,rz,kFALSE); } // apply supermodules' alignment objects Int_t smCounter=0; for(Int_t iSect=0; iSect<18; iSect++){ if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue; AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(smCounter++); if(!smobj->ApplyToGeometry()){ Fatal(macroname,Form("application of full misalignment object for sector %d failed!",iSect)); return; } } // create the chambers' alignment objects ran = new TRandom(4357); Int_t chId; for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) { chId=-1; for (Int_t iSect = 0; iSect < 18; iSect++){ for (Int_t iCh = 0; iCh < 5; iCh++) { dx = AliMathBase::TruncatedGaus(0.0,chdx,cutChdx); dy = AliMathBase::TruncatedGaus(0.0,chdy,cutChdy); dz = AliMathBase::TruncatedGaus(0.0,chdz,cutChdz); rx = gRandom->Rndm() * 2.0*chrx - chrx; ry = gRandom->Rndm() * 2.0*chry - chry; rz = gRandom->Rndm() * 2.0*chrz - chrz; chId++; if ((iSect==13 || iSect==14 || iSect==15) && iCh==2) continue; volid = AliGeomManager::LayerToVolUID(iLayer,chId); if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue; symname = AliGeomManager::SymName(volid); new((*array)[j++]) AliAlignObjParams(symname,volid,dx,dy,dz,rx,ry,rz,kFALSE); } } } if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){ // save on file const char* filename = "TRDfullMisalignment.root"; TFile f(filename,"RECREATE"); if(!f){ Error(macroname,"cannot open file for output\n"); return; } Info(macroname,"Saving alignment objects to the file %s", filename); f.cd(); f.WriteObject(array,"TRDAlignObjs","kSingleKey"); f.Close(); }else{ // save in CDB storage Info(macroname,"Saving alignment objects in CDB storage %s", Storage.Data()); AliCDBMetaData* md = new AliCDBMetaData(); md->SetResponsible("Dariusz Miskowiec"); md->SetComment("Full misalignment for TRD"); md->SetAliRootVersion(gSystem->Getenv("ARVERSION")); AliCDBId id("TRD/Align/Data",0,AliCDBRunRange::Infinity()); storage->Put(array,id,md); } array->Delete(); }
void PathGroups::addIndexedPath(QString flnm) { QFile fpath(flnm); fpath.open(QFile::ReadOnly); QTextStream fd(&fpath); QString line = fd.readLine(); // ignore first line PathGroupGrabber *pg = new PathGroupGrabber(); QList<Vec> pts; // first read all points while (! fd.atEnd()) { line = fd.readLine(); // ignore first line QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 1) { int npts = list[0].toInt(); for(int i=0; i<npts; i++) { if (fd.atEnd()) break; else { line = fd.readLine(); QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() == 3) { float x = list[0].toFloat(); float y = list[1].toFloat(); float z = list[2].toFloat(); pts.append(Vec(x,y,z)); } } } break; } } // now read indices while (! fd.atEnd()) { line = fd.readLine(); QStringList list = line.split(" ", QString::SkipEmptyParts); if (list.count() > 1) { QList<Vec> ipts; for(int i=0; i<list.count(); i++) { int j = list[i].toInt(); if (j>=0 && j<pts.count()) ipts.append(pts[j]); } if (ipts.count() > 0) pg->addPoints(ipts); } } m_paths.append(pg); makePathConnections(); }
wxString S3D_FILENAME_RESOLVER::ResolvePath( const wxString& aFileName ) { wxCriticalSectionLocker lock( lock3D_resolver ); if( aFileName.empty() ) return wxEmptyString; if( m_Paths.empty() ) createPathList(); // first attempt to use the name as specified: wxString tname = aFileName; #ifdef _WIN32 // translate from KiCad's internal UNIX-like path to MSWin paths tname.Replace( wxT( "/" ), wxT( "\\" ) ); #endif // Note: variable expansion must be performed using a threadsafe // wrapper for the getenv() system call. If we allow the // wxFileName::Normalize() routine to perform expansion then // we will have a race condition since wxWidgets does not assure // a threadsafe wrapper for getenv(). if( tname.StartsWith( "${" ) || tname.StartsWith( "$(" ) ) tname = ExpandEnvVarSubstitutions( tname ); wxFileName tmpFN( tname ); // in the case of absolute filenames we don't store a map item if( !aFileName.StartsWith( "${" ) && !aFileName.StartsWith( "$(" ) && !aFileName.StartsWith( ":" ) && tmpFN.IsAbsolute() ) { tmpFN.Normalize(); if( tmpFN.FileExists() ) return tmpFN.GetFullPath(); return wxEmptyString; } // this case covers full paths, leading expanded vars, and paths // relative to the current working directory (which is not necessarily // the current project directory) if( tmpFN.FileExists() ) { tmpFN.Normalize(); tname = tmpFN.GetFullPath(); // special case: if a path begins with ${ENV_VAR} but is not in the // resolver's path list then add it. if( aFileName.StartsWith( "${" ) || aFileName.StartsWith( "$(" ) ) checkEnvVarPath( aFileName ); return tname; } // if a path begins with ${ENV_VAR}/$(ENV_VAR) and is not resolved then the // file either does not exist or the ENV_VAR is not defined if( aFileName.StartsWith( "${" ) || aFileName.StartsWith( "$(" ) ) { if( !( m_errflags & ERRFLG_ENVPATH ) ) { m_errflags |= ERRFLG_ENVPATH; wxString errmsg = "[3D File Resolver] No such path; ensure the environment var is defined"; errmsg.append( "\n" ); errmsg.append( tname ); wxLogMessage( errmsg ); } return wxEmptyString; } // at this point aFileName is: // a. an aliased shortened name or // b. cannot be determined std::list< S3D_ALIAS >::const_iterator sPL = m_Paths.begin(); std::list< S3D_ALIAS >::const_iterator ePL = m_Paths.end(); // check the path relative to the current project directory; // note: this is not necessarily the same as the current working // directory, which has already been checked. This case accounts // for partial paths which do not contain ${KIPRJMOD}. // This check is performed before checking the path relative to // ${KISYS3DMOD} so that users can potentially override a model // within ${KISYS3DMOD} if( !sPL->m_pathexp.empty() && !tname.StartsWith( ":" ) ) { tmpFN.Assign( sPL->m_pathexp, "" ); wxString fullPath = tmpFN.GetPathWithSep() + tname; if( fullPath.StartsWith( "${" ) || fullPath.StartsWith( "$(" ) ) fullPath = ExpandEnvVarSubstitutions( fullPath ); if( wxFileName::FileExists( fullPath ) ) { tmpFN.Assign( fullPath ); tmpFN.Normalize(); tname = tmpFN.GetFullPath(); return tname; } } // check the partial path relative to ${KISYS3DMOD} (legacy behavior) if( !tname.StartsWith( ":" ) ) { wxFileName fpath; wxString fullPath( "${KISYS3DMOD}" ); fullPath.Append( fpath.GetPathSeparator() ); fullPath.Append( tname ); fullPath = ExpandEnvVarSubstitutions( fullPath ); fpath.Assign( fullPath ); if( fpath.Normalize() && fpath.FileExists() ) { tname = fpath.GetFullPath(); return tname; } } // ${ENV_VAR} paths have already been checked; skip them while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) || sPL->m_alias.StartsWith( "$(" ) ) ) ++sPL; // at this point the filename must contain an alias or else it is invalid wxString alias; // the alias portion of the short filename wxString relpath; // the path relative to the alias if( !SplitAlias( tname, alias, relpath ) ) { if( !( m_errflags & ERRFLG_RELPATH ) ) { // this can happen if the file was intended to be relative to // ${KISYS3DMOD} but ${KISYS3DMOD} not set or incorrect. m_errflags |= ERRFLG_RELPATH; wxString errmsg = "[3D File Resolver] No such path"; errmsg.append( "\n" ); errmsg.append( tname ); wxLogTrace( MASK_3D_RESOLVER, errmsg ); } return wxEmptyString; } while( sPL != ePL ) { if( !sPL->m_alias.Cmp( alias ) && !sPL->m_pathexp.empty() ) { wxFileName fpath( wxFileName::DirName( sPL->m_pathexp ) ); wxString fullPath = fpath.GetPathWithSep() + relpath; if( fullPath.StartsWith( "${") || fullPath.StartsWith( "$(" ) ) fullPath = ExpandEnvVarSubstitutions( fullPath ); if( wxFileName::FileExists( fullPath ) ) { wxFileName tmp( fullPath ); if( tmp.Normalize() ) tname = tmp.GetFullPath(); return tname; } } ++sPL; } if( !( m_errflags & ERRFLG_ALIAS ) ) { m_errflags |= ERRFLG_ALIAS; wxString errmsg = "[3D File Resolver] No such path; ensure the path alias is defined"; errmsg.append( "\n" ); errmsg.append( tname.substr( 1 ) ); wxLogTrace( MASK_3D_RESOLVER, errmsg ); } return wxEmptyString; }
SimulatorCompressiblePolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropertiesInterface& props, const PolymerProperties& poly_props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const PolymerInflowInterface& polymer_inflow, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), poly_props_(poly_props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), polymer_inflow_(polymer_inflow), gravity_(gravity), psolver_(grid, props, rock_comp_props, poly_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells()), tsolver_(grid, props, poly_props, TransportSolverTwophaseCompressiblePolymer::Bracketing, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. TransportSolverTwophaseCompressiblePolymer::SingleCellMethod method; std::string method_string = param.getDefault("single_cell_method", std::string("Bracketing")); if (method_string == "Bracketing") { method = Opm::TransportSolverTwophaseCompressiblePolymer::Bracketing; } else if (method_string == "Newton") { method = Opm::TransportSolverTwophaseCompressiblePolymer::Newton; } else { OPM_THROW(std::runtime_error, "Unknown method: " << method_string); } tsolver_.setPreferredMethod(method); num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_) { tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
// \TODO: make CompressibleTpfa take src and bcs. SimulatorCompressibleTwophase::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropertiesInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const std::vector<double>&, const FlowBoundaryConditions*, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), //src_(src), //bcs_(bcs), gravity_(gravity), psolver_(grid, props, rock_comp_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells() /*, src, bcs*/), tsolver_(grid, props, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_){ tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
void DicomSelectorDialog::exec() { typedef itk::ImageFileReader< CTImageType > ReaderType; int index = 0; bool canceled = false; QProgressDialog indexProgress(tr("Indexing Files..."), tr("Abort"), 0, m_fileNames.size(), this); indexProgress.setMinimumDuration(1000); indexProgress.setWindowModality(Qt::ApplicationModal); while( index < m_fileNames.size() ) { indexProgress.setValue(index + 1); if (indexProgress.wasCanceled()) break; if ( boost::filesystem::is_directory( m_fileNames[index].toAscii().data() ) ) { boost::filesystem::path fpath( m_fileNames.takeAt(index).toAscii().data() ); QList< boost::filesystem::path > pathList; boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end pathList.push_back( fpath ); indexProgress.setMaximum(m_fileNames.size() + pathList.size()); while( !pathList.isEmpty() ) { if (indexProgress.wasCanceled()) break; boost::filesystem::path currentPath = pathList.takeFirst(); for ( boost::filesystem::directory_iterator itr( currentPath ); itr != end_itr; ++itr ) { if (indexProgress.wasCanceled()) break; if ( boost::filesystem::is_directory(itr->status()) ) { pathList.push_back( itr->path() ); indexProgress.setMaximum(m_fileNames.size() + pathList.size()); indexProgress.setValue(index); } else if ( boost::filesystem::is_regular_file( itr->status() )) { m_fileNames.push_back( itr->path().directory_string().c_str() ); } } } } else { index++; } } canceled = indexProgress.wasCanceled(); m_fileNames.removeDuplicates(); if (!canceled ) { QProgressDialog metaReadProgress(tr("Reading MetaData..."), tr("Abort"), 0, m_fileNames.size(), this); metaReadProgress.setMinimumDuration(1000); metaReadProgress.setWindowModality(Qt::ApplicationModal); for(int i = 0; i < m_fileNames.size(); i++) { metaReadProgress.setValue(i); if (metaReadProgress.wasCanceled()) break; boost::filesystem::path fpath( m_fileNames[i].toAscii().data() ); if ( boost::filesystem::is_regular_file( fpath ) ) { try { ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( fpath.string() ); reader->GenerateOutputInformation(); m_ctImageModel.appendFilename( reader->GetMetaDataDictionary(), fpath.string() ); } catch (itk::ImageFileReaderException &ifrExep) { std::cerr << "Exception caught !" << std::endl; std::cerr << ifrExep << std::endl; } catch (itk::ExceptionObject & excep) { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; } } } } if (m_ctImageModel.rowCount(QModelIndex())==0) return; treeView->setModel( &m_ctImageModel ); treeView->selectAll(); for(unsigned int t=0; t < m_HeaderFields.size(); t++) treeView->resizeColumnToContents(t); treeView->setSortingEnabled(true); treeView->sortByColumn(2,Qt::AscendingOrder); QDialog::exec(); }