FilePaths getLibExtensions() { FilePaths strs; strs.push_back(FilePath("a", FP_Ext)); strs.push_back(FilePath("lib", FP_Ext)); return strs; }
FilePaths getCppSourceExtensions() { FilePaths strs; strs.push_back(FilePath("c", FP_Ext)); strs.push_back(FilePath("cc", FP_Ext)); strs.push_back(FilePath("c++", FP_Ext)); strs.push_back(FilePath("cpp", FP_Ext)); strs.push_back(FilePath("cxx", FP_Ext)); return strs; }
FilePaths getCppHeaderExtensions() { FilePaths strs; strs.push_back(FilePath("h", FP_Ext)); strs.push_back(FilePath("hh", FP_Ext)); strs.push_back(FilePath("hpp", FP_Ext)); strs.push_back(FilePath("hxx", FP_Ext)); strs.push_back(FilePath("inc", FP_Ext)); return strs; }
bool SimpleFileStore::remove(const std::string& name) { FilePaths fps = filepath(name); bool success = File::remove(fps.inprogress()) | File::remove(fps.deleted()) | File::remove(fps.current()); boost::filesystem::path path = fps.current(); path = path.parent_path(); while (File::remove(path.string())) path = path.parent_path(); return success; }
writestream SimpleFileStore::write(const std::string& name, const std::string& version, unsigned short, unsigned long long offset) { KeyMetadata md; md.version.fromString(version); if (md.version.empty()) md.version.increment("sec"); uint64_t current = timeFromVersion( mergedVersion(name, true) ); uint64_t prospective = timeFromVersion(md.version); if ( prospective < current || (prospective == current && !md.version.isDeleted()) || md.version.isExpired(EXPIRY_TIMEOUT_SECONDS) ) return writestream(); // correct versions in the future back to now? FilePaths paths = filepath(name); string tempname(paths.inprogress()); boost::filesystem::create_directories(boost::filesystem::path(tempname).parent_path()); FileWriter* writer = new FileWriter(tempname); return writestream(writer, md, std::bind(&SimpleFileStore::onWriteComplete, this, name, _1)); }
readstream SimpleFileStore::read(const std::string& name, const std::string& version, bool inprogress/*=false*/) const { // can't read inprogress versions, because I don't want to think about it. FilePaths paths = filepath(name); KeyMetadata md; if (!version.empty()) { md.version.fromString(version); if (md.version.compare(mergedVersion(name)) != VectorClock::EQUAL) return readstream(); } else md.version = mergedVersion(name); string filename = md.version.isDeleted()? paths.deleted() : paths.current(); FileReader* reader = new FileReader(filename); if (name.find(MEMBERSHIP_FILE_PREFIX) == 0) md.totalCopies = 0; return readstream(reader, md); }
void ProjectPackagesDialog::winScanDirectories() { Package pkg = mProjectPackages.getPackage( mProjectPackagesList.getSelected()); if(pkg.getPkgName().length() > 0) { OovString rootDir = getEntry("PackageRootDirEntry"); FilePaths dirs; dirs.push_back(FilePath("/", FP_Dir)); dirs.push_back(FilePath("/Program Files", FP_Dir)); OovString dir = findMatchingDir(dirs, rootDir); if(dir.length()) { pkg.setRootDir(dir); // move to project packages. mProjectPackages.insertPackage(pkg); } setEntry("PackageRootDirEntry", pkg.getRootDir()); } else Gui::messageBox("Select a package to scan", GTK_MESSAGE_INFO); }
std::vector<std::string> SimpleFileStore::versions(const std::string& name, bool inprogress/*=false*/) const { std::vector<std::string> versions; FilePaths paths = filepath(name); if ( File::exists(paths.current()) ) versions.push_back( lookupVersion(paths.current()).toString() ); if ( File::exists(paths.deleted()) ) versions.push_back( lookupVersion(paths.deleted(), true).toString() ); if ( inprogress && File::exists(paths.inprogress()) ) versions.push_back( lookupVersion(paths.inprogress()).toString() ); return versions; }
bool SimpleFileStore::onDeleteComplete(const std::string& name, KeyMetadata& md) { FilePaths paths = filepath(name); if ( !testIfVersionGreater(md.version, paths.current()) ) { File::remove(paths.inprogress()); return false; } unsigned long long currentDigest = removeIfExists(paths.deleted(), true); if ( !File::set_modified_time(paths.inprogress(), timeFromVersion(md.version)) || !File::rename(paths.inprogress(), paths.deleted()) ) { File::remove(paths.inprogress()); return false; } md.digest ^= removeIfExists(paths.current()); md.digest ^= currentDigest; return true; }
void Skybox::InitializePresets(Renderer* pRenderer, const Settings::Rendering& renderSettings) { EnvironmentMap::Initialize(pRenderer); EnvironmentMap::LoadShaders(); const std::string extension = ".hdr"; const std::string BRDFLUTTextureFileName = "BRDFIntegrationLUT"; const std::string BRDFLUTTextureFilePath = EnvironmentMap::sTextureCacheDirectory + BRDFLUTTextureFileName + extension; const bool bUseCache = Engine::GetSettings().bCacheEnvironmentMapsOnDisk && DirectoryUtil::FileExists(BRDFLUTTextureFilePath); if(bUseCache) { EnvironmentMap::sBRDFIntegrationLUTTexture = pRenderer->CreateHDRTexture(BRDFLUTTextureFileName + extension, EnvironmentMap::sTextureCacheDirectory); } else { Texture LUTTexture = EnvironmentMap::CreateBRDFIntegralLUTTexture(); EnvironmentMap::sBRDFIntegrationLUTTexture = LUTTexture._id; if (Engine::GetSettings().bCacheEnvironmentMapsOnDisk) { pRenderer->SaveTextureToDisk(EnvironmentMap::sBRDFIntegrationLUTTexture, BRDFLUTTextureFilePath, false); } // todo: we can unload shaders / render targets here } // Cubemap Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ { // NIGHTSKY // #AsyncLoad: Mutex DEVICE const bool bEquirectangular = false; const auto offsetIter = s_filePaths.begin() + ECubeMapPresets::NIGHT_SKY; const FilePaths filePaths = FilePaths(offsetIter, offsetIter + 6); TextureID skydomeTex = pRenderer->CreateCubemapFromFaceTextures(filePaths, false); //Skybox::SetPreset(ECubeMapPresets::NIGHT_SKY, std::move(Skybox(pRenderer, skydomeTex, bEquirectangular))); s_Presets[ECubeMapPresets::NIGHT_SKY] = Skybox(pRenderer, skydomeTex, bEquirectangular); } if (renderSettings.bEnableEnvironmentLighting) { // HDR / IBL - Equirectangular Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ //EnvironmentMap::Initialize(pRenderer); const bool bEquirectangular = true; EnvironmentMapFileNames files; const std::vector<EEnvironmentMapPresets> presets = { EEnvironmentMapPresets::BARCELONA , EEnvironmentMapPresets::TROPICAL_BEACH, EEnvironmentMapPresets::MILKYWAY , EEnvironmentMapPresets::TROPICAL_RUINS, EEnvironmentMapPresets::WALK_OF_FAME }; std::for_each(RANGE(presets), [&](auto preset) { const auto rootAndFilesPair = GetsIBLFiles(preset); s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); }); } }
void Skybox::InitializePresets_Async(Renderer* pRenderer, const Settings::Rendering& renderSettings) { EnvironmentMap::Initialize(pRenderer); { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); EnvironmentMap::LoadShaders(); } { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); Texture LUTTexture = EnvironmentMap::CreateBRDFIntegralLUTTexture(); EnvironmentMap::sBRDFIntegrationLUTTexture = LUTTexture._id; } // Cubemap Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ { // NIGHTSKY // #AsyncLoad: Mutex DEVICE const bool bEquirectangular = false; const auto offsetIter = s_filePaths.begin() + ECubeMapPresets::NIGHT_SKY; const FilePaths filePaths = FilePaths(offsetIter, offsetIter + 6); TextureID skydomeTex = -1; { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); skydomeTex = pRenderer->CreateCubemapFromFaceTextures(filePaths, false); } s_Presets[ECubeMapPresets::NIGHT_SKY] = Skybox(pRenderer, skydomeTex, bEquirectangular); } if (renderSettings.bEnableEnvironmentLighting) { // HDR / IBL - Equirectangular Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ //EnvironmentMap::Initialize(pRenderer); const std::string sIBLDirectory = Renderer::sHDRTextureRoot + std::string("sIBL/"); const bool bEquirectangular = true; EnvironmentMapFileNames files; const std::vector<EEnvironmentMapPresets> presets = { EEnvironmentMapPresets::BARCELONA , EEnvironmentMapPresets::TROPICAL_BEACH, EEnvironmentMapPresets::MILKYWAY , EEnvironmentMapPresets::TROPICAL_RUINS, EEnvironmentMapPresets::WALK_OF_FAME }; if (renderSettings.bPreLoadEnvironmentMaps) { std::for_each(RANGE(presets), [&](auto preset) { const auto rootAndFilesPair = GetsIBLFiles(preset); { s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); } }); } else { auto& preset = presets.back(); const auto rootAndFilesPair = GetsIBLFiles(preset); { s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); } } } }
void VoronoiDustGridStructure::setupSelfBefore() { GenDustGridStructure::setupSelfBefore(); Log* log = find<Log>(); // Determine an appropriate set of particles and construct the Voronoi mesh switch (_distribution) { case Uniform: { if (_numParticles < 10) throw FATALERROR("The number of particles should be at least 10"); vector<Vec> rv(_numParticles); for (int m=0; m<_numParticles; m++) { rv[m] = _random->position(extent()); } log->info("Computing Voronoi tesselation for " + QString::number(_numParticles) + " uniformly distributed random particles..."); _mesh = new VoronoiMesh(rv, extent()); break; } case CentralPeak: { if (_numParticles < 10) throw FATALERROR("The number of particles should be at least 10"); const int a = 1000; // steepness of the peak; the central 1/a portion is NOT covered const double rscale = extent().rmax().norm(); vector<Vec> rv(_numParticles); for (int m=1; m<_numParticles; m++) // skip first particle so that it remains (0,0,0) { while (true) { double r = rscale * pow(1./a, _random->uniform()); // random distribution according to 1/x Direction k = _random->direction(); Position p = Position(r,k); if (extent().contains(p)) // discard any points outside of the domain { rv[m] = p; break; } } } log->info("Computing Voronoi tesselation for " + QString::number(_numParticles) + " random particles distributed in a central peak..."); _mesh = new VoronoiMesh(rv, extent()); break; } case DustDensity: { if (_numParticles < 10) throw FATALERROR("The number of particles should be at least 10"); DustDistribution* dd = find<DustDistribution>(); vector<Vec> rv(_numParticles); for (int m=0; m<_numParticles; m++) { while (true) { Position p = dd->generatePosition(); if (extent().contains(p)) // discard any points outside of the domain { rv[m] = p; break; } } } log->info("Computing Voronoi tesselation for " + QString::number(_numParticles) + " random particles distributed according to dust density..."); _mesh = new VoronoiMesh(rv, extent()); break; } case DustTesselation: { VoronoiMeshInterface* vmi = find<DustDistribution>()->interface<VoronoiMeshInterface>(); if (!vmi) throw FATALERROR("Can't retrieve Voronoi mesh from this dust distribution"); _mesh = vmi->mesh(); _meshOwned = false; log->info("Using Voronoi tesselation from dust distribution with " + QString::number(_mesh->Ncells()) + " particles..."); break; } case SPHParticles: { DustParticleInterface* dpi = find<DustDistribution>()->interface<DustParticleInterface>(); if (!dpi) throw FATALERROR("Can't retrieve particle locations from this dust distribution"); log->info("Computing Voronoi tesselation for " + QString::number(dpi->numParticles()) + " dust distribution particles..."); _mesh = new VoronoiMesh(dpi, extent()); break; } case File: { if (!_meshfile) throw FATALERROR("File containing particle locations is not defined"); log->info("Computing Voronoi tesselation for particles loaded from file " + _meshfile->filename() + "..."); _mesh = new VoronoiMesh(_meshfile, QList<int>(), extent()); break; } default: throw FATALERROR("Unknown distribution type"); } // Communicate the number of dust cells to the base class _Ncells = _mesh->Ncells(); // Log statistics on the cell neighbors double avgNeighbors; int minNeighbors, maxNeighbors; _mesh->neighborStatistics(avgNeighbors, minNeighbors, maxNeighbors); log->info("Computed Voronoi tesselation with " + QString::number(_Ncells) + " cells:"); log->info(" Average number of neighbors per cell: " + QString::number(avgNeighbors,'f',1)); log->info(" Minimum number of neighbors per cell: " + QString::number(minNeighbors)); log->info(" Maximum number of neighbors per cell: " + QString::number(maxNeighbors)); // Log statistics on the block lists int nblocks = _mesh->Nblocks(); double avgRefsPerBlock; int minRefsPerBlock, maxRefsPerBlock; _mesh->blockStatistics(avgRefsPerBlock, minRefsPerBlock, maxRefsPerBlock); log->info("Created grid to accelerate which-cell operations:"); log->info(" Number of cells : " + QString::number(_Ncells)); log->info(" Number of blocks : " + QString::number(nblocks*nblocks*nblocks) + " (" + QString::number(nblocks) + " in each dimension)"); log->info(" Average number of cells per block: " + QString::number(avgRefsPerBlock,'f',1)); log->info(" Minimum number of cells per block: " + QString::number(minRefsPerBlock)); log->info(" Maximum number of cells per block: " + QString::number(maxRefsPerBlock)); // Log statistics on the search trees double avgRefsPerTree; int nTrees, minRefsPerTree, maxRefsPerTree; _mesh->treeStatistics(nTrees, avgRefsPerTree, minRefsPerTree, maxRefsPerTree); log->info("Created search trees to accelerate which-cell operations:"); log->info(" Number of trees : " + QString::number(nTrees) + " (" + QString::number(100.*nTrees/(nblocks*nblocks*nblocks),'f',1) + "% of blocks)"); log->info(" Average number of cells per tree : " + QString::number(avgRefsPerTree,'f',1)); log->info(" Minimum number of cells per tree : " + QString::number(minRefsPerTree)); log->info(" Maximum number of cells per tree : " + QString::number(maxRefsPerTree)); // If requested, output the plot files (we have to reconstruct the Voronoi tesselation...) if (writeGrid()) { setWriteGrid(false); // keep the base class from overwriting our plot files Units* units = find<Units>(); FilePaths* filepaths = find<FilePaths>(); // create the plot files QString name = filepaths->output("ds_grid"); DustGridPlotFile plotxy(name+"xy.dat",log,units); DustGridPlotFile plotxz(name+"xz.dat",log,units); DustGridPlotFile plotyz(name+"yz.dat",log,units); DustGridPlotFile plotxyz(name+"xyz.dat",log,units); // load all particles in a Voro container int nb = max(3, min(1000, static_cast<int>(pow(_Ncells/5.,1./3.)) )); voro::container con(xmin(), xmax(), ymin(), ymax(), zmin(), zmax(), nb, nb, nb, false,false,false, 8); for (int m=0; m<_Ncells; m++) { Vec r = _mesh->particlePosition(m); con.put(m, r.x(),r.y(),r.z()); } // loop over all Voro cells voro::c_loop_all loop(con); if (loop.start()) do { // Compute the cell voro::voronoicell fullcell; con.compute_cell(fullcell, loop); // Get the edges of the cell double x,y,z; loop.pos(x,y,z); vector<double> coords; fullcell.vertices(x,y,z, coords); vector<int> indices; fullcell.face_vertices(indices); // Write the edges of the cell to the plot files Box bounds = _mesh->extent(loop.pid()); if (bounds.zmin()<=0 && bounds.zmax()>=0) plotxy.writePolyhedron(coords, indices); if (bounds.ymin()<=0 && bounds.ymax()>=0) plotxz.writePolyhedron(coords, indices); if (bounds.xmin()<=0 && bounds.xmax()>=0) plotyz.writePolyhedron(coords, indices); if (loop.pid() <= 1000) plotxyz.writePolyhedron(coords, indices); } while (loop.inc()); } }
FilePaths getJavaSourceExtensions() { FilePaths strs; strs.push_back(FilePath("java", FP_Ext)); return strs; }