.. _program_listing_file_SPlisHSPlasH_Utilities_SceneLoader.h: Program Listing for File SceneLoader.h ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``SPlisHSPlasH/Utilities/SceneLoader.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef __SceneLoader_h__ #define __SceneLoader_h__ #include "SPlisHSPlasH/Common.h" #include "extern/json/json.hpp" #include #include "SceneParameterObjects.h" #include "Utilities/Logger.h" namespace Utilities { class SceneLoader { protected: nlohmann::json m_jsonData; void readParameterObject(nlohmann::json& config, GenParam::ParameterObject* paramObj); public: struct Scene { std::vector boundaryModels; std::vector fluidModels; std::vector fluidBlocks; std::vector emitters; std::vector animatedFields; std::vector materials; Real particleRadius; bool sim2D; }; nlohmann::json& getJSONData() { return m_jsonData; }; void readScene(const char *fileName, Scene &scene); template bool readValue(const nlohmann::json &j, T &v) { if (j.is_null()) return false; try { v = j.get(); } catch (const std::exception& e) { LOG_ERR << e.what(); exit(1); } return true; } template bool readVector(const nlohmann::json &j, Eigen::Matrix &vec) { if (j.is_null()) return false; try { std::vector values = j.get>(); for (unsigned int i = 0; i < values.size(); i++) vec[i] = values[i]; } catch (const std::exception& e) { LOG_ERR << e.what(); exit(1); } return true; } template bool readValue(const std::string §ion, const std::string &key, T &v) { if (m_jsonData.find(section) != m_jsonData.end()) { nlohmann::json j = m_jsonData[section]; if (j.is_null()) return false; nlohmann::json j2 = j[key]; if (j2.is_null()) return false; try { v = j2.get(); } catch (const std::exception& e) { LOG_ERR << e.what(); exit(1); } return true; } return false; } bool hasValue(const std::string& section, const std::string& key) { if (m_jsonData.find(section) != m_jsonData.end()) { nlohmann::json j = m_jsonData[section]; if (j.is_null()) return false; nlohmann::json j2 = j[key]; if (j2.is_null()) return false; return true; } return false; } template bool readVector(const std::string §ion, const std::string &key, Eigen::Matrix &vec) { if (m_jsonData.find(section) != m_jsonData.end()) { nlohmann::json j = m_jsonData[section]; if (j.is_null()) return false; nlohmann::json j2 = j[key]; if (j2.is_null()) return false; std::vector values = j2.get>(); for (unsigned int i = 0; i < values.size(); i++) vec[i] = values[i]; return true; } return false; } void readMaterialParameterObject(const std::string& key, GenParam::ParameterObject* paramObj); void readParameterObject(const std::string &key, GenParam::ParameterObject *paramObj); }; template <> bool SceneLoader::readValue(const nlohmann::json &j, bool &v); } #endif