| 2320 | |
| 2321 | |
| 2322 | void SimulatorBase::initDensityMap(std::vector<Vector3r> &x, std::vector<unsigned int> &faces, const Utilities::BoundaryParameterObject *boundaryData, const bool md5, const bool isDynamic, BoundaryModel_Koschier2017 *boundaryModel) |
| 2323 | { |
| 2324 | Simulation *sim = Simulation::getCurrent(); |
| 2325 | const std::string& sceneFile = SceneConfiguration::getCurrent()->getSceneFile(); |
| 2326 | const Utilities::SceneLoader::Scene& scene = SceneConfiguration::getCurrent()->getScene(); |
| 2327 | const Real supportRadius = sim->getSupportRadius(); |
| 2328 | std::string scene_path = FileSystem::getFilePath(sceneFile); |
| 2329 | std::string scene_file_name = FileSystem::getFileName(sceneFile); |
| 2330 | const bool useCache = getUseParticleCaching(); |
| 2331 | Discregrid::CubicLagrangeDiscreteGrid *densityMap; |
| 2332 | |
| 2333 | // if a map file is given, use this one |
| 2334 | if (boundaryData->mapFile != "") |
| 2335 | { |
| 2336 | std::string mapFileName = boundaryData->mapFile; |
| 2337 | if (FileSystem::isRelativePath(mapFileName)) |
| 2338 | mapFileName = FileSystem::normalizePath(scene_path + "/" + mapFileName); |
| 2339 | densityMap = new Discregrid::CubicLagrangeDiscreteGrid(mapFileName); |
| 2340 | boundaryModel->setMap(densityMap); |
| 2341 | LOG_INFO << "Loaded density map: " << mapFileName; |
| 2342 | return; |
| 2343 | } |
| 2344 | |
| 2345 | string cachePath = scene_path + "/Cache"; |
| 2346 | |
| 2347 | // Cache map |
| 2348 | std::string mesh_base_path = FileSystem::getFilePath(boundaryData->meshFile); |
| 2349 | std::string mesh_file_name = FileSystem::getFileName(boundaryData->meshFile); |
| 2350 | |
| 2351 | |
| 2352 | Eigen::Matrix<unsigned int, 3, 1> resolutionSDF = boundaryData->mapResolution; |
| 2353 | const string scaleStr = "s" + StringTools::real2String(boundaryData->scale[0]) + "_" + StringTools::StringTools::real2String(boundaryData->scale[1]) + "_" + StringTools::real2String(boundaryData->scale[2]); |
| 2354 | const string resStr = "r" + to_string(resolutionSDF[0]) + "_" + to_string(resolutionSDF[1]) + "_" + to_string(resolutionSDF[2]); |
| 2355 | const string invertStr = "i" + to_string((int)boundaryData->mapInvert); |
| 2356 | const string thicknessStr = "t" + StringTools::real2String(boundaryData->mapThickness); |
| 2357 | const string kernelStr = "k" + to_string(sim->getKernel()); |
| 2358 | string densityMapFileName = ""; |
| 2359 | if (isDynamic) |
| 2360 | densityMapFileName = FileSystem::normalizePath(cachePath + "/" + mesh_file_name + "_db_dm_" + StringTools::real2String(scene.particleRadius) + "_" + scaleStr + "_" + resStr + "_" + invertStr + "_" + thicknessStr + "_" + kernelStr + ".cdm"); |
| 2361 | else |
| 2362 | densityMapFileName = FileSystem::normalizePath(cachePath + "/" + mesh_file_name + "_sb_dm_" + StringTools::real2String(scene.particleRadius) + "_" + scaleStr + "_" + resStr + "_" + invertStr + "_" + thicknessStr + "_" + kernelStr + ".cdm"); |
| 2363 | |
| 2364 | // check MD5 if cache file is available |
| 2365 | bool foundCacheFile = false; |
| 2366 | |
| 2367 | if (useCache) |
| 2368 | foundCacheFile = FileSystem::fileExists(densityMapFileName); |
| 2369 | |
| 2370 | if (useCache && foundCacheFile && md5) |
| 2371 | { |
| 2372 | densityMap = new Discregrid::CubicLagrangeDiscreteGrid(densityMapFileName); |
| 2373 | boundaryModel->setMap(densityMap); |
| 2374 | LOG_INFO << "Loaded cached density map: " << densityMapFileName; |
| 2375 | return; |
| 2376 | } |
| 2377 | |
| 2378 | if (!useCache || !foundCacheFile || !md5) |
| 2379 | { |