1 #ifndef MOBILERT_UTILS_UTILS_HPP 2 #define MOBILERT_UTILS_UTILS_HPP 4 #include "Utils_dependent.hpp" 8 #include <boost/assert.hpp> 11 #include <glm/ext.hpp> 12 #include <glm/glm.hpp> 14 #define GLM_ENABLE_EXPERIMENTAL 15 #include <glm/gtx/string_cast.hpp> 17 #include <pcg_random.hpp> 30 #define LOG_DEBUG(...) \ 31 ::Dependent::printDebug( \ 32 ::MobileRT::convertToString(::MobileRT::getFileName(__FILE__), ":", __LINE__, ": ", __VA_ARGS__) \ 40 #define LOG_DEBUG(...) do { } while (false) 43 #define LOG_INFO(...) \ 44 ::Dependent::printInfo( \ 45 ::MobileRT::convertToString(::MobileRT::getFileName(__FILE__), ":", __LINE__, ": ", __VA_ARGS__) \ 48 #define LOG_WARN(...) \ 49 ::Dependent::printWarn( \ 50 ::MobileRT::convertToString(::MobileRT::getFileName(__FILE__), ":", __LINE__, ": ", __VA_ARGS__) \ 53 #define LOG_ERROR(...) \ 54 ::Dependent::printError( \ 55 ::MobileRT::convertToString(::MobileRT::getFileName(__FILE__), ":", __LINE__, ": ", __VA_ARGS__) \ 60 #define LOG_DEBUG(...) 72 #define LOG_ERROR(...) 75 template<
typename T, ::std::
size_t S>
78 template<
typename T, ::std::
size_t S>
81 template<
typename T, ::std::
size_t S>
84 inline ::std::string
getFileName(
const char *filepath);
93 ::std::int32_t numSample);
95 template<::std::
int32_t S,
typename T>
96 inline ::std::array<T, S>
toArray(
const char *values);
98 ::glm::vec2
toVec2(
const char *values);
100 ::glm::vec3
toVec3(
const char *values);
102 ::glm::vec3
toVec3(
const float *values);
104 bool equal(
float a,
float b);
106 bool equal(const ::glm::vec3 &vec1, const ::glm::vec3 &vec2);
108 template<::std::
int32_t S,
typename T>
109 bool isValid(const ::glm::vec<S, T> &value);
111 template<::std::
int32_t S,
typename T>
116 ::glm::vec2
normalize(const ::glm::vec2 &textureCoordinates);
118 ::glm::vec3
normalize(const ::glm::vec3 &color);
120 float fresnel(const ::glm::vec3 &I, const ::glm::vec3 &N,
float ior);
134 template<::std::
int32_t S,
typename T>
146 template <
typename Type>
160 template <
typename First,
typename... Args>
173 template <
typename... Args>
175 ::std::ostringstream oss {
""};
178 const ::std::string &line {oss.str()};
189 const ::std::string &filePath {filepath};
190 ::std::string::size_type filePos {filePath.rfind(
'/')};
191 if (filePos != ::std::string::npos) {
196 const ::std::string &res {filePath.substr(filePos)};
209 template<
typename T, ::std::
size_t S>
211 for (typename ::std::array<T, S>::iterator itValues {values->begin()}; itValues < values->end(); ::std::advance(itValues, 1)) {
212 const ::std::uint32_t index {
static_cast<::std::uint32_t
> (::std::distance(values->begin(), itValues))};
215 static ::std::random_device randomDevice {};
216 static ::std::mt19937 generator {randomDevice()};
217 ::std::shuffle(values->begin(), values->end(), generator);
229 template<
typename T, ::std::
size_t S>
231 static ::std::uniform_real_distribution<float> uniformDist {0.0F, 1.0F};
232 static ::std::random_device randomDevice {};
233 static ::std::mt19937 generator {randomDevice()};
234 ::std::generate(values->begin(), values->end(), []() {
return uniformDist(generator);});
246 template<
typename T, ::std::
size_t S>
248 static ::pcg_extras::seed_seq_from<::std::random_device> seedSource {};
249 static ::pcg32 generator(seedSource);
250 static ::std::uniform_real_distribution<float> uniformDist {0.0F, 1.0F};
251 ::std::generate(values->begin(), values->end(), []() {
return uniformDist(generator);});
262 template<::std::
int32_t S,
typename T>
264 const bool isNaN {::glm::all(::glm::isnan(value))};
265 const bool isInf {::glm::all(::glm::isinf(value))};
266 const bool res {!isNaN && !isInf};
278 template<::std::
int32_t S,
typename T>
280 return ::glm::any(::glm::greaterThan(value, ::glm::vec<S, T> {0}));
291 template<::std::
int32_t S,
typename T>
292 inline ::std::array<T, S>
toArray(
const char *
const values) {
293 ::std::stringstream data {values};
294 ::std::array<float, S> parsedValues {};
295 for (::std::uint32_t i {0u}; i < S; ++i) {
296 data >> parsedValues[i];
308 #define ASSERT(condition, ...) \ 310 if (!(condition)) { \ 311 LOG_DEBUG("Assertion '", #condition, "': ", __VA_ARGS__); \ 312 BOOST_ASSERT_MSG(condition, ::MobileRT::convertToString(__VA_ARGS__).c_str()); \ 321 #define ASSERT(condition, ...) do { } while (false) 334 #if __cplusplus < 201402L 344 template<
typename T,
typename... Args>
346 return ::std::unique_ptr<T>(
new T(::std::forward<Args>(args)...));
358 template<
typename T,
typename... Args>
359 ::std::unique_ptr<T>
make_unique(Args &&... args) {
360 return ::std::make_unique<T>(::std::forward<Args>(args)...);
369 #if __cplusplus < 201703L 378 template <
typename T> ::std::string
to_string(
const T& str) {
379 ::std::ostringstream stm {
""};
391 template <
typename T> ::std::string
to_string(
const T& str) {
400 #endif //MOBILERT_UTILS_UTILS_HPP void fillArrayWithMersenneTwister(::std::array< T, S > *values)
Definition: Utils.hpp:230
void checkSystemError(const char *const message)
Definition: Utils.cpp:237
::std::int32_t roundDownToMultipleOf(const ::std::int32_t value, const ::std::int32_t multiple)
Definition: Utils.cpp:26
::std::string convertToString(Args &&... args)
Definition: Utils.hpp:174
float haltonSequence(::std::uint32_t index, const ::std::uint32_t base)
Definition: Utils.cpp:43
bool hasPositiveValue(const ::glm::vec< S, T > &value)
Definition: Utils.hpp:279
::std::unique_ptr< T > make_unique(Args &&... args)
Definition: Utils.hpp:345
::std::int32_t incrementalAvg(const ::glm::vec3 &sample, const ::std::int32_t avg, const ::std::int32_t numSample)
Definition: Utils.cpp:66
::glm::vec3 toVec3(const char *const values)
Definition: Utils.cpp:109
inline ::std::string getFileName(const char *filepath)
Definition: Utils.hpp:188
void printFreeMemory()
Definition: Utils.cpp:285
bool equal(const float a, const float b)
Definition: Utils.cpp:133
void fillArrayWithPCG(::std::array< T, S > *values)
Definition: Utils.hpp:247
::std::string to_string(const T &str)
Definition: Utils.hpp:378
float fresnel(const ::glm::vec3 &I, const ::glm::vec3 &N, const float ior)
Definition: Utils.cpp:206
bool isValid(const float value)
Definition: Utils.cpp:163
::glm::vec2 normalize(const ::glm::vec2 &textureCoordinates)
Definition: Utils.cpp:177
::glm::vec2 toVec2(const char *const values)
Definition: Utils.cpp:98
void fillArrayWithHaltonSeq(::std::array< T, S > *values)
Definition: Utils.hpp:210
inline ::std::array< T, S > toArray(const char *values)
Definition: Utils.hpp:292
void addToStringStream(::std::ostringstream *oss, const ::glm::vec< S, T > ¶meter)
Definition: Utils.hpp:135