From 8cb7587d7866cc491323867d07c9234588f886b8 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 5 Feb 2018 20:35:04 +0100 Subject: [PATCH 01/10] compile errors and tests: noise scope (partly) --- CMakeLists.txt | 38 ++--- source/glkernel/CMakeLists.txt | 55 ++++--- .../AssertionMacros.h | 51 ++++++ .../ConstExpressions.cpp | 66 ++++++++ .../glkernel-generalizations/StringMacros.h | 22 +++ .../glkernel-generalizations/TypeTraits.cpp | 82 ++++++++++ .../glkernel_generalizations.cpp | 124 +++++++++++++++ .../glkernel_generalizations.h | 90 +++++++++++ source/tests/CMakeLists.txt | 40 +++-- .../glkernel-will_fail_tests/CMakeLists.txt | 148 ++++++++++++++++++ .../glkernel-will_fail_tests/noise_fail.cpp | 50 ++++++ 11 files changed, 712 insertions(+), 54 deletions(-) create mode 100644 source/glkernel/include/glkernel-generalizations/AssertionMacros.h create mode 100644 source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp create mode 100644 source/glkernel/include/glkernel-generalizations/StringMacros.h create mode 100644 source/glkernel/include/glkernel-generalizations/TypeTraits.cpp create mode 100644 source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp create mode 100644 source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h create mode 100644 source/tests/glkernel-will_fail_tests/CMakeLists.txt create mode 100644 source/tests/glkernel-will_fail_tests/noise_fail.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7aeae81..82d510b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ -# +# # CMake options -# +# # CMake version cmake_minimum_required(VERSION 3.0 FATAL_ERROR) @@ -30,9 +30,9 @@ set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. -# +# # Project description and (meta) information -# +# # Get git revision get_git_head_revision(GIT_REFSPEC GIT_SHA1) @@ -56,9 +56,9 @@ set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERS set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") -# +# # Project configuration options -# +# # Project options option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) @@ -68,17 +68,19 @@ option(OPTION_BUILD_EXAMPLES "Build examples." option(OPTION_BUILD_TOOLS "Build tools." ON) -# +# # Declare project -# +# # Generate folders for IDE targets (e.g., VisualStudio solutions) set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set(IDE_FOLDER "") +set(IDE_FOLDER "") # Declare project project(${META_PROJECT_NAME} C CXX) +include(CTest) + # Set output directories set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) @@ -88,9 +90,9 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") -# +# # Compiler settings and options -# +# include(cmake/CompileOptions.cmake) @@ -107,9 +109,9 @@ enable_cppcheck(On) enable_clang_tidy(On) -# +# # Deployment/installation setup -# +# # Get project name set(project ${META_PROJECT_NAME}) @@ -161,23 +163,23 @@ if(NOT SYSTEM_DIR_INSTALL) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") else() - set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") + set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") endif() endif() -# +# # Project modules -# +# add_subdirectory(source) add_subdirectory(docs) add_subdirectory(deploy) -# +# # Deployment (global project files) -# +# # Install version file install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) diff --git a/source/glkernel/CMakeLists.txt b/source/glkernel/CMakeLists.txt index 3db89cb..5b46b5a 100644 --- a/source/glkernel/CMakeLists.txt +++ b/source/glkernel/CMakeLists.txt @@ -1,14 +1,14 @@ -# +# # External dependencies -# +# find_package(GLM REQUIRED) -# +# # Library name and options -# +# # Target name set(target glkernel) @@ -25,11 +25,12 @@ set(template_export_file "include/${target}/${target}_api.h") set(export_macro "${target_id}_API") -# +# # Sources -# +# set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}") +set(include_generalizations_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}-generalizations") set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") set(headers @@ -52,20 +53,26 @@ set(headers ${include_path}/shuffle.hpp ${include_path}/sort.h ${include_path}/sort.hpp + ${include_generalizations_path}/glkernel_generalizations.cpp + ${include_generalizations_path}/glkernel_generalizations.h + ${include_generalizations_path}/AssertionMacros.h + ${include_generalizations_path}/ConstExpressions.cpp + ${include_generalizations_path}/StringMacros.h + ${include_generalizations_path}/TypeTraits.cpp ) # Group source files set(header_group "Header Files (API)") set(source_group "Source Files") -source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" +source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" ${header_group} ${headers}) -source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" +source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" ${source_group} ${sources}) -# +# # Create library -# +# add_custom_target(${target}-sources SOURCES ${headers}) @@ -85,16 +92,16 @@ generate_template_export_header(${target} ) -# +# # Project options -# +# # none allowed, since interface library (header-only) -# +# # Include directories -# +# target_include_directories(${target} @@ -107,27 +114,27 @@ target_include_directories(${target} ) -# +# # Libraries -# +# # none required, since interface library (header-only) -# +# # Compile definitions -# +# # none required, since interface library (header-only) -# +# # Compile options -# +# # none required, since interface library (header-only) -# +# # Linker options -# +# # none required, since interface library (header-only) @@ -142,9 +149,9 @@ target_include_directories(${target} #) -# +# # Deployment -# +# # Library install(TARGETS ${target} diff --git a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h new file mode 100644 index 0000000..6a435a7 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -0,0 +1,51 @@ +#pragma once + +#include "TypeTraits.cpp" +#include "ConstExpressions.cpp" +#include "StringMacros.h" + + +//#define CHECK_FLOATING_TYPE(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) +//#define CHECK_TYPE_EQUALITY(T1, T2, T3) static_assert(areSameType(), PARAM_MATCH_KERNEL) +//#define CHECK_CELLTYPE_EQUALITY(V1, V2, V3) static_assert(areSameCelltype(), PARAM_MATCH_CELL) + + + + +#define CHECK_TYPE_FLOATING(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) + + +#define CHECK_TYPE_EQUALITY(T, ...) \ + static_assert( (areSameType() && areSameType()) || \ + (!areSameType() && areSameType()) || \ + !(areSameType() && !areSameType()) || \ + (!areSameType() && !areSameType()) \ + , PARAM_MATCH_FLOAT); \ + static_assert( (areSameType() && areSameType()) || \ + (!areSameType() && areSameType()) || \ + !(areSameType() && !areSameType()) || \ + (!areSameType() && !areSameType()) \ + , PARAM_MATCH_DOUBLE); + + +#define CHECK_CELLTYPE_EQUALITY(V, ...) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , PARAM_MATCH_VEC2); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , PARAM_MATCH_VEC3); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , PARAM_MATCH_VEC4); + + +//#define CHECK_FLOATING_TYPE(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) +//#define CHECK_TYPE_EQUALITY(...) checkTypeEquality<__VA_ARGS__>() + diff --git a/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp b/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp new file mode 100644 index 0000000..d6c3588 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp @@ -0,0 +1,66 @@ +#pragma once + +#include + +#include + +#include "TypeTraits.cpp" +#include "StringMacros.h" + + +namespace glkernel +{ + +namespace noise +{ + + +/* + * These methods are mainly used for actually typing the assertions. + * Later the lines are copied to AssertionMacros.h. + */ + + +template +constexpr void checkTypeEquality() +{ + static_assert( (areSameType() && areSameType()) || + (!areSameType() && areSameType()) || + !(areSameType() && !areSameType()) || + (!areSameType() && !areSameType()) + , PARAM_MATCH_FLOAT); + + static_assert( (areSameType() && areSameType()) || + (!areSameType() && areSameType()) || + !(areSameType() && !areSameType()) || + (!areSameType() && !areSameType()) + , PARAM_MATCH_DOUBLE); +} + +template class V, template class... Vs> +constexpr void checkCelltypeEquality() +{ + static_assert( (areSameCelltype() && areSameCelltype()) || + (!areSameCelltype() && areSameCelltype()) || + !(areSameCelltype() && !areSameCelltype()) || + (!areSameCelltype() && !areSameCelltype()) + , PARAM_MATCH_VEC2); + + static_assert( (areSameCelltype() && areSameCelltype()) || + (!areSameCelltype() && areSameCelltype()) || + !(areSameCelltype() && !areSameCelltype()) || + (!areSameCelltype() && !areSameCelltype()) + , PARAM_MATCH_VEC3); + + static_assert( (areSameCelltype() && areSameCelltype()) || + (!areSameCelltype() && areSameCelltype()) || + !(areSameCelltype() && !areSameCelltype()) || + (!areSameCelltype() && !areSameCelltype()) + , PARAM_MATCH_VEC4); +} + + + +} // testEnv + +} // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h new file mode 100644 index 0000000..b2bc307 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -0,0 +1,22 @@ +#pragma once + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT " In file " __FILE__ ":" TOSTRING(__LINE__) + + +#define KERNEL_FLOATING "Kernel must be of a floating type (float or double)!" + +#define WHICH_IS_FLOAT ", which is float." +#define WHICH_IS_DOUBLE ", which is double." +#define PARAM_MATCH_KERNEL "Type of kernel parameters must match kernel type" +#define PARAM_MATCH_FLOAT PARAM_MATCH_KERNEL WHICH_IS_FLOAT AT +#define PARAM_MATCH_DOUBLE PARAM_MATCH_KERNEL WHICH_IS_DOUBLE AT + +#define WHICH_IS_VEC2 ", which is glm::tvec2." +#define WHICH_IS_VEC3 ", which is glm::tvec3." +#define WHICH_IS_VEC4 ", which is glm::tvec4." +#define PARAM_MATCH_CELL "Celltype of kernel parameters must match kernel celltype" +#define PARAM_MATCH_VEC2 PARAM_MATCH_CELL WHICH_IS_VEC2 AT +#define PARAM_MATCH_VEC3 PARAM_MATCH_CELL WHICH_IS_VEC3 AT +#define PARAM_MATCH_VEC4 PARAM_MATCH_CELL WHICH_IS_VEC4 AT diff --git a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp new file mode 100644 index 0000000..6095d1f --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -0,0 +1,82 @@ +#pragma once + +#include +#include + + + +namespace glkernel +{ + +namespace noise +{ + + + + +template +struct are_same_type : std::false_type { }; + +template<> +struct are_same_type<> : std::true_type { }; + +template +struct are_same_type : std::true_type { }; + +template +struct are_same_type : are_same_type { }; + +template +constexpr bool areSameType() { return are_same_type::value; } + + + + +template class... Vs> +struct are_same_celltype : std::false_type { }; + +template<> +struct are_same_celltype<> : std::true_type { }; + +template class V> +struct are_same_celltype : std::true_type { }; + +template class V, template class... Vs> +struct are_same_celltype : are_same_celltype { }; + +template class... Vs> +constexpr bool areSameCelltype() { return are_same_celltype::value; } + + + + +template +struct is_celltype : std::false_type {}; + +template class V> +struct is_celltype> : std::true_type {}; + +template class V> +constexpr bool isCelltype() { return is_celltype>::value; } + + + + +template +struct is_templateTemplate : std::false_type {}; + +template class V> +struct is_templateTemplate> : std::true_type {}; + +template class V> +constexpr bool isTemplateTemplate() { return is_templateTemplate>::value; } + +template class V> +constexpr bool isPureTemplate() { return !is_templateTemplate>::value; } + + + + +} // testEnv + +} // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp new file mode 100644 index 0000000..a1a7e19 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp @@ -0,0 +1,124 @@ +#pragma once + +#include "glkernel_generalizations.h" +#include "AssertionMacros.h" +#include + + +namespace glkernel +{ + + + + +namespace noise +{ + + +template +void uniform(tkernel &, const T2, const T3) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); +} + +template class V> +void uniform(tkernel> &, const T2, const T3) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); +} + +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); + CHECK_CELLTYPE_EQUALITY(V1, V2, V3); +} + + +template +void normal(tkernel &, const T2, const T3) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); +} + +template class V> +void normal(tkernel> &, const T2, const T3) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); +} + +template class V1, template class V2, template class V3> +void normal(tkernel> &, const V2 &, const V3 &) +{ + CHECK_TYPE_FLOATING(T1); + CHECK_TYPE_EQUALITY(T1, T2, T3); + CHECK_CELLTYPE_EQUALITY(V1, V2, V3); +} + + +} // namespace noise + + + + +namespace sample +{ + + + +} // namespace sample + + + + +namespace scale +{ + + + +} // namespace scale + + + + +namespace sequence +{ + + +} // namespace sequence + + + + +namespace shuffle +{ + + + +} // namespace shuffle + + + + +namespace sort +{ + + + +} // namespace sort + + + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h new file mode 100644 index 0000000..64b8978 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h @@ -0,0 +1,90 @@ +#pragma once + +#include +#include + + +namespace glkernel +{ + + + + +namespace noise +{ + + +template +void uniform(tkernel &, const T2, const T3); + +template class V> +void uniform(tkernel> &, const T2, const T3); + +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &); + + +template +void normal(tkernel &, const T2, const T3); + +template class V> +void normal(tkernel> &, const T2, const T3); + +template class V1, template class V2, template class V3> +void normal(tkernel> &, const V2 &, const V3 &); + + +} // namespace noise + + +namespace sample +{ + + + +} // namespace sample + + +namespace scale +{ + + + +} // namespace scale + + +namespace sequence +{ + + +} // namespace sequence + + +namespace shuffle +{ + + + +} // namespace shuffle + + +namespace sort +{ + + + +} // namespace sort + + + + +} // namespace glkernel + + +#include "glkernel_generalizations.cpp" diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 65142b5..42c4010 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -11,6 +11,7 @@ set(META_PROJECT_NAME "glkernel") # Declare project project("${META_PROJECT_NAME}-tests" C CXX) +include(CTest) # Set policies set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. @@ -31,19 +32,31 @@ else() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") endif() -# Function: Build test and add command to execute it via target 'test' + +# Function: Build failuretest and register it under target 'test' via CTest automatically +#function(add_test_with_ctest target) + + #add_subdirectory(${target}) + + + +#endfunction() + + +# Function: Build test and add command to execute it via target 'tests' function(add_test_without_ctest target) add_subdirectory(${target}) - + if(NOT TARGET ${target}) return() endif() - - add_dependencies(test ${target}) - add_custom_command(TARGET test POST_BUILD + + add_dependencies(tests ${target}) + add_custom_command(TARGET tests POST_BUILD COMMAND $ --gtest_output=xml:gtests-${target}.xml) endfunction() + # Build gmock set(gmock_build_tests OFF CACHE BOOL "") set(gtest_build_samples OFF CACHE BOOL "") @@ -69,16 +82,19 @@ target_link_libraries(gmock-dev ) -# -# Target 'test' -# +# +# Target 'tests' +# Target 'test' is reserved (hard-coded) for CTest! +# -add_custom_target(test) -set_target_properties(test PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) +add_custom_target(tests) +set_target_properties(tests PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) -# +# # Tests -# +# +add_subdirectory(glkernel-will_fail_tests) +#add_test_with_ctest(glkernel-will_fail_tests) add_test_without_ctest(glkernel-test) diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt new file mode 100644 index 0000000..f33f5ff --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -0,0 +1,148 @@ + +# +# External dependencies +# + +find_package(${META_PROJECT_NAME} REQUIRED HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../../") +find_package(GLM 0.9.6 REQUIRED) +find_package(OpenMP) + +# +# Executable name and options +# + + +function(add_own_test scope name idx) + + set(filename "${scope}_fail.cpp") + set(target "${scope}_${name}_${idx}") + string(TOUPPER ${target} MACRONAME) + + message(STATUS "Test ${target} in ${filename}") + + if (NOT OPENMP_FOUND) + message("Loop parallelization in ${target} skipped: OpenMP not found") + endif() + + + # + # Sources + # + + set(sources + ${filename} + ) + + + # + # Create executable + # + + # Build executable + add_executable(${target} + ${sources} + ) + + # Create namespaced alias + add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + + + # + # Project options + # + + set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE + ) + + + # + # Include directories + # + + target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${GLM_INCLUDE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${PROJECT_BINARY_DIR}/source/include + ) + + + # + # Libraries + # + + target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + ${META_PROJECT_NAME}::glkernel + ) + + + # + # Compile definitions + # + + target_compile_definitions(${target} + PRIVATE + ${MACRONAME} + GLM_FORCE_RADIANS + $<$:USE_OPENMP> + ${DEFAULT_COMPILE_DEFINITIONS} + ) + + + # + # Compile options + # + + target_compile_options(${target} + PRIVATE + $<$:${OpenMP_CXX_FLAGS}> + ${DEFAULT_COMPILE_OPTIONS} + ) + + + # + # Linker options + # + + target_link_libraries(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} + $<$>:$<$:${OpenMP_CXX_FLAGS}>> + ) + + if(BUILD_TESTING) + message("CTest ready for registering ${target}") + # Add the tests. These invoke "cmake --build ..." which is a + # cross-platform way of building the given target. + add_test(NAME ${target} + COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + # Expect these tests to fail (i.e. cmake --build should return + # a non-zero value) + set_tests_properties(${target} PROPERTIES WILL_FAIL TRUE) + endif() + +endfunction() + + + +add_own_test(noise normal 1) +add_own_test(noise normal 2) +add_own_test(noise normal 3) +add_own_test(noise normal 4) +add_own_test(noise normal 5) +add_own_test(noise normal 6) +add_own_test(noise uniform 1) +add_own_test(noise uniform 2) +add_own_test(noise uniform 3) +add_own_test(noise uniform 4) +add_own_test(noise uniform 5) +add_own_test(noise uniform 6) diff --git a/source/tests/glkernel-will_fail_tests/noise_fail.cpp b/source/tests/glkernel-will_fail_tests/noise_fail.cpp new file mode 100644 index 0000000..616e43f --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/noise_fail.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +#include +#include + +#include + +#include + +int main() +{ + auto fkernel1 = glkernel::kernel1{ 1 }; + auto fkernel2 = glkernel::kernel2{ 1 }; + + auto dkernel1 = glkernel::dkernel1{ 1 }; + auto dkernel2 = glkernel::dkernel2{ 1 }; + + +#if defined NOISE_NORMAL_1 + glkernel::noise::normal(fkernel1, 0.0f, 1.0); +#elif defined NOISE_NORMAL_2 + glkernel::noise::normal(fkernel2, 0.0f, 1.0); +#elif defined NOISE_NORMAL_3 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined NOISE_NORMAL_4 + glkernel::noise::normal(dkernel1, 0.0, 1.0f); +#elif defined NOISE_NORMAL_5 + glkernel::noise::normal(dkernel2, 0.0, 1.0f); +#elif defined NOISE_NORMAL_6 + glkernel::noise::normal(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_UNIFORM_1 + glkernel::noise::uniform(fkernel1, 0.0f, 1.0); +#elif defined NOISE_UNIFORM_2 + glkernel::noise::uniform(fkernel2, 0.0f, 1.0); +#elif defined NOISE_UNIFORM_3 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined NOISE_UNIFORM_4 + glkernel::noise::uniform(dkernel1, 0.0, 1.0f); +#elif defined NOISE_UNIFORM_5 + glkernel::noise::uniform(dkernel2, 0.0, 1.0f); +#elif defined NOISE_UNIFORM_6 + glkernel::noise::uniform(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); + + + return 0; +} + + From 55db9bddfd7ee9830c063d192b400d358ad2a376 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 12 Feb 2018 14:07:04 +0100 Subject: [PATCH 02/10] compile errors and tests: noise done, sample scope (partly) --- .../AssertionMacros.h | 77 ++++++++++++++++++- .../glkernel-generalizations/StringMacros.h | 73 ++++++++++++++---- .../glkernel-generalizations/TypeTraits.cpp | 14 ++-- .../glkernel_generalizations.cpp | 60 +++++++++++++++ .../glkernel_generalizations.h | 49 ++++++++++++ .../glkernel-will_fail_tests/CMakeLists.txt | 6 ++ .../glkernel-will_fail_tests/noise_fail.cpp | 3 + .../glkernel-will_fail_tests/sample_fail.cpp | 56 ++++++++++++++ 8 files changed, 318 insertions(+), 20 deletions(-) create mode 100644 source/tests/glkernel-will_fail_tests/sample_fail.cpp diff --git a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h index 6a435a7..476ad6b 100644 --- a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -15,6 +15,80 @@ #define CHECK_TYPE_FLOATING(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) + +// Checks, if kernel is of CELLtype vec2. +#define CHECK_KERNEL_CELLTYPE_VEC2(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC2_KERNEL_CELLTYPE_MATCH_VEC3); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC2_KERNEL_CELLTYPE_MATCH_VEC4); + +// Checks, if kernel is of CELLtype vec3. +#define CHECK_KERNEL_CELLTYPE_VEC3(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC3_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC3_KERNEL_CELLTYPE_MATCH_VEC4); + +// Checks, if kernel is of CELLtype vec4. +#define CHECK_KERNEL_CELLTYPE_VEC4(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC4_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC4_KERNEL_CELLTYPE_MATCH_VEC3); + + +// Fail, because vec2 kernel is of some scalar type +#define FAIL_KERNEL_CELLTYPE_VEC2(T) \ + static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_FLOAT); \ + static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE); +// Fail, because vec3 kernel is of some scalar type +#define FAIL_KERNEL_CELLTYPE_VEC3(T) \ + static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ + static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE); +// Fail, because vec4 kernel is of some scalar type +#define FAIL_KERNEL_CELLTYPE_VEC4(T) \ + static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_FLOAT); \ + static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE); + +// Fail, because scalar kernel is of some vectorial type +#define FAIL_KERNEL_CELLTYPE_SCALAR(V) \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC3); \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC4); + + +// Fail, because scalar parameter (float or double) is of some vectorial celltype +#define FAIL_PARAM_TYPE_T(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC4); + + + +// Checks if all arguments are of the same type. +// Implicitly assumes that arguements are parameters of a method including kernel as first argument! #define CHECK_TYPE_EQUALITY(T, ...) \ static_assert( (areSameType() && areSameType()) || \ (!areSameType() && areSameType()) || \ @@ -27,7 +101,8 @@ (!areSameType() && !areSameType()) \ , PARAM_MATCH_DOUBLE); - +// Checks if all arguments are of the same CELLtype. +// Implicitly assumes that arguements are parameters of a method including kernel as first argument! #define CHECK_CELLTYPE_EQUALITY(V, ...) \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ diff --git a/source/glkernel/include/glkernel-generalizations/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h index b2bc307..1af3f0e 100644 --- a/source/glkernel/include/glkernel-generalizations/StringMacros.h +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -2,21 +2,66 @@ #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) -#define AT " In file " __FILE__ ":" TOSTRING(__LINE__) +#define AT /*" In file " __FILE__ ":" TOSTRING(__LINE__)*/ + + +#define WHICH_IS ", which is " +#define BUT_IS ", but is " +#define FLOAT "float." +#define DOUBLE "double." +#define VEC2 "glm::tvec2." +#define VEC3 "glm::tvec3." +#define VEC4 "glm::tvec4." #define KERNEL_FLOATING "Kernel must be of a floating type (float or double)!" -#define WHICH_IS_FLOAT ", which is float." -#define WHICH_IS_DOUBLE ", which is double." -#define PARAM_MATCH_KERNEL "Type of kernel parameters must match kernel type" -#define PARAM_MATCH_FLOAT PARAM_MATCH_KERNEL WHICH_IS_FLOAT AT -#define PARAM_MATCH_DOUBLE PARAM_MATCH_KERNEL WHICH_IS_DOUBLE AT - -#define WHICH_IS_VEC2 ", which is glm::tvec2." -#define WHICH_IS_VEC3 ", which is glm::tvec3." -#define WHICH_IS_VEC4 ", which is glm::tvec4." -#define PARAM_MATCH_CELL "Celltype of kernel parameters must match kernel celltype" -#define PARAM_MATCH_VEC2 PARAM_MATCH_CELL WHICH_IS_VEC2 AT -#define PARAM_MATCH_VEC3 PARAM_MATCH_CELL WHICH_IS_VEC3 AT -#define PARAM_MATCH_VEC4 PARAM_MATCH_CELL WHICH_IS_VEC4 AT +#define PARAM_MUST_KERNEL "Type of kernel parameter(s) must match kernel type" +#define PARAM_MATCH_FLOAT PARAM_MUST_KERNEL WHICH_IS FLOAT AT +#define PARAM_MATCH_DOUBLE PARAM_MUST_KERNEL WHICH_IS DOUBLE AT + +#define PARAM_MUST_CELL "Celltype of kernel parameter(s) must match kernel celltype" +#define PARAM_MATCH_VEC2 PARAM_MUST_CELL WHICH_IS VEC2 AT +#define PARAM_MATCH_VEC3 PARAM_MUST_CELL WHICH_IS VEC3 AT +#define PARAM_MATCH_VEC4 PARAM_MUST_CELL WHICH_IS VEC4 AT + + +#define KERNEL_MUST_SCALAR "Kernel must be of a scalar (floating: float or double) type" +#define KERNEL_MUST_VEC2 "Kernel must be of type glm::tvec2" +#define KERNEL_MUST_VEC3 "Kernel must be of type glm::tvec3" +#define KERNEL_MUST_VEC4 "Kernel must be of type glm::tvec4" + +#define VEC2_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 BUT_IS FLOAT AT +#define VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 BUT_IS DOUBLE AT + +#define VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC3 BUT_IS FLOAT AT +#define VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC3 BUT_IS DOUBLE AT + +#define VEC4_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC4 BUT_IS FLOAT AT +#define VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC4 BUT_IS DOUBLE AT + + +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC2 BUT_IS VEC3 AT +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC2 BUT_IS VEC4 AT + +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC3 BUT_IS VEC2 AT +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC3 BUT_IS VEC4 AT + +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC4 BUT_IS VEC2 AT +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC4 BUT_IS VEC3 AT + +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_SCALAR BUT_IS VEC2 AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_SCALAR BUT_IS VEC3 AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_SCALAR BUT_IS VEC4 AT + + +#define PARAM_MUST_FLOAT "Parameter must be of type float" +#define PARAM_MUST_DOUBLE "Parameter must be of type float" + +#define FLOAT_PARAM_TYPE_MATCH_VEC2 PARAM_MUST_FLOAT BUT_IS VEC2 AT +#define FLOAT_PARAM_TYPE_MATCH_VEC3 PARAM_MUST_FLOAT BUT_IS VEC3 AT +#define FLOAT_PARAM_TYPE_MATCH_VEC4 PARAM_MUST_FLOAT BUT_IS VEC4 AT + +#define DOUBLE_PARAM_TYPE_MATCH_VEC2 PARAM_MUST_DOUBLE BUT_IS VEC2 AT +#define DOUBLE_PARAM_TYPE_MATCH_VEC3 PARAM_MUST_DOUBLE BUT_IS VEC3 AT +#define DOUBLE_PARAM_TYPE_MATCH_VEC4 PARAM_MUST_DOUBLE BUT_IS VEC4 AT diff --git a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp index 6095d1f..2e8b4f7 100644 --- a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -8,10 +8,6 @@ namespace glkernel { -namespace noise -{ - - template @@ -62,6 +58,10 @@ constexpr bool isCelltype() { return is_celltype>::value; } +template< typename T > +struct always_false : std::false_type {}; + + template struct is_templateTemplate : std::false_type {}; @@ -74,9 +74,13 @@ constexpr bool isTemplateTemplate() { return is_templateTemplate>::value template class V> constexpr bool isPureTemplate() { return !is_templateTemplate>::value; } +template +constexpr bool isTemplateTemplate() { return is_templateTemplate::value; } + +template +constexpr bool isPureTemplate() { return !is_templateTemplate::value; } -} // testEnv } // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp index a1a7e19..840d868 100644 --- a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp +++ b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp @@ -67,6 +67,17 @@ void normal(tkernel> &, const V2 &, const V3 &) } +template class V> +void gradient(tkernel> & + , const GradientNoiseType + , const OctaveType + , const unsigned int + , const unsigned int) +{ + FAIL_KERNEL_CELLTYPE_SCALAR(V); +} + + } // namespace noise @@ -76,6 +87,55 @@ namespace sample { +template +void poisson_square(tkernel &, const unsigned int) +{ + FAIL_KERNEL_CELLTYPE_VEC2(T); +} + +template class V> +void poisson_square(tkernel> &, const unsigned int) +{ + CHECK_KERNEL_CELLTYPE_VEC2(V); +} + + +template +void poisson_square(tkernel &, const T2, const unsigned int) +{ + FAIL_KERNEL_CELLTYPE_VEC2(T1); + CHECK_TYPE_EQUALITY(T1, T2); +} + +template class V> +void poisson_square(tkernel> &, const T2, const unsigned int) +{ + CHECK_KERNEL_CELLTYPE_VEC2(V); + CHECK_TYPE_EQUALITY(T1, T2); +} + + +template class V> +void poisson_square(tkernel &, const V &, const unsigned int) +{ + FAIL_KERNEL_CELLTYPE_VEC2(T1); + FAIL_PARAM_TYPE_T(T1, V); + CHECK_TYPE_EQUALITY(T1, T2); +} + +template class V1, template class V2> +void poisson_square(tkernel> &, const V2 &, const unsigned int) +{ + CHECK_KERNEL_CELLTYPE_VEC2(V1); + FAIL_PARAM_TYPE_T(T1, V2); + CHECK_TYPE_EQUALITY(T1, T2); +} + } // namespace sample diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h index 64b8978..015c403 100644 --- a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h +++ b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h @@ -2,6 +2,7 @@ #include #include +#include namespace glkernel @@ -40,6 +41,14 @@ template > &, const V2 &, const V3 &); +template class V> +void gradient(tkernel> & + , const GradientNoiseType = GradientNoiseType::Perlin + , const OctaveType = OctaveType::Standard + , const unsigned int = 3 + , const unsigned int = 5); + + } // namespace noise @@ -47,6 +56,46 @@ namespace sample { +//template +//size_t poisson_square(tkernel> & kernel, unsigned int num_probes = 32); + +template +void poisson_square(tkernel &, const unsigned int = 32); + +template class V> +void poisson_square(tkernel> &, const unsigned int = 32); + + + + +template +void poisson_square(tkernel &, const T2, const unsigned int = 32); + +template class V> +void poisson_square(tkernel> &, const T2, const unsigned int = 32); + + + + +template class V1, template class V2> +size_t poisson_square(tkernel> &, const V2 &, const unsigned int = 32); + +template class V> +size_t poisson_square(tkernel &, const V &, const unsigned int = 32); + + + + + + +//template +//size_t poisson_square(tkernel> & kernel, T min_dist, unsigned int num_probes = 32); + } // namespace sample diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt index f33f5ff..8be2a44 100644 --- a/source/tests/glkernel-will_fail_tests/CMakeLists.txt +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -146,3 +146,9 @@ add_own_test(noise uniform 3) add_own_test(noise uniform 4) add_own_test(noise uniform 5) add_own_test(noise uniform 6) +add_own_test(noise uniform 7) + +add_own_test(sample poisson_square 1) +add_own_test(sample poisson_square 2) +add_own_test(sample poisson_square 3) +add_own_test(sample poisson_square 4) diff --git a/source/tests/glkernel-will_fail_tests/noise_fail.cpp b/source/tests/glkernel-will_fail_tests/noise_fail.cpp index 616e43f..32c3a1c 100644 --- a/source/tests/glkernel-will_fail_tests/noise_fail.cpp +++ b/source/tests/glkernel-will_fail_tests/noise_fail.cpp @@ -42,6 +42,9 @@ int main() glkernel::noise::uniform(dkernel2, 0.0, 1.0f); #elif defined NOISE_UNIFORM_6 glkernel::noise::uniform(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_UNIFORM_7 + glkernel::noise::gradient(dkernel2); +#endif return 0; diff --git a/source/tests/glkernel-will_fail_tests/sample_fail.cpp b/source/tests/glkernel-will_fail_tests/sample_fail.cpp new file mode 100644 index 0000000..4b0f0bc --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/sample_fail.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#include +#include + +#include + +#include + +int main() +{ + auto fkernel1 = glkernel::kernel1{ 1 }; + auto fkernel2 = glkernel::kernel2{ 1 }; + auto fkernel3 = glkernel::kernel3{ 1 }; + + auto dkernel1 = glkernel::dkernel1{ 1 }; + auto dkernel2 = glkernel::dkernel2{ 1 }; + auto dkernel3 = glkernel::dkernel3{ 1 }; + + +#if defined SAMPLE_POISSON_SQUARE_1 + glkernel::sample::poisson_square(fkernel1); +#elif defined SAMPLE_POISSON_SQUARE_1 + glkernel::sample::poisson_square(fkernel1, 1.5); +#elif defined SAMPLE_POISSON_SQUARE_1 + glkernel::sample::poisson_square(fkernel1, glm::vec2{ 1.5 }); +#elif defined SAMPLE_POISSON_SQUARE_2 + glkernel::sample::poisson_square(fkernel2, 1.5); +#elif defined SAMPLE_POISSON_SQUARE_3 + glkernel::sample::poisson_square(fkernel3); +#elif defined SAMPLE_POISSON_SQUARE_4 + glkernel::sample::poisson_square(fkernel3, 1.5); +#elif defined SAMPLE_POISSON_SQUARE_5 + glkernel::sample::poisson_square(fkernel3, glm::vec2{ 1.5 }); +#elif defined SAMPLE_POISSON_SQUARE_6 + glkernel::noise::normal(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_UNIFORM_1 + glkernel::noise::uniform(fkernel1, 0.0f, 1.0); +#elif defined NOISE_UNIFORM_2 + glkernel::noise::uniform(fkernel2, 0.0f, 1.0); +#elif defined NOISE_UNIFORM_3 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined NOISE_UNIFORM_4 + glkernel::noise::uniform(dkernel1, 0.0, 1.0f); +#elif defined NOISE_UNIFORM_5 + glkernel::noise::uniform(dkernel2, 0.0, 1.0f); +#elif defined NOISE_UNIFORM_6 + glkernel::noise::uniform(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); +#endif + + return 0; +} + + From b10b039cbaa6f37f92edd58f1705d769e7514e30 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 26 Feb 2018 20:53:11 +0100 Subject: [PATCH 03/10] compile errors and tests: sample done, scale done --- source/glkernel/CMakeLists.txt | 9 +- .../AssertionMacros.h | 192 +++++++++------- .../ConstExpressions.cpp | 66 ------ .../glkernel-generalizations/StringMacros.h | 116 ++++++---- .../glkernel-generalizations/TypeTraits.cpp | 23 +- .../glkernel_generalizations.cpp | 184 ---------------- ..._generalizations.h => noise_generalized.h} | 134 +++++------- .../noise_generalized.hpp | 150 +++++++++++++ .../sample_generalized.h | 137 ++++++++++++ .../sample_generalized.hpp | 205 ++++++++++++++++++ .../scale_generalized.h | 69 ++++++ .../scale_generalized.hpp | 97 +++++++++ source/glkernel/include/glkernel/noise.h | 2 + source/glkernel/include/glkernel/sample.h | 2 + source/glkernel/include/glkernel/scale.h | 2 + .../glkernel-will_fail_tests/CMakeLists.txt | 54 ++++- .../glkernel-will_fail_tests/noise_fail.cpp | 54 ++++- .../glkernel-will_fail_tests/sample_fail.cpp | 67 ++++-- .../glkernel-will_fail_tests/scale_fail.cpp | 43 ++++ 19 files changed, 1106 insertions(+), 500 deletions(-) delete mode 100644 source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp delete mode 100644 source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp rename source/glkernel/include/glkernel-generalizations/{glkernel_generalizations.h => noise_generalized.h} (50%) create mode 100644 source/glkernel/include/glkernel-generalizations/noise_generalized.hpp create mode 100644 source/glkernel/include/glkernel-generalizations/sample_generalized.h create mode 100644 source/glkernel/include/glkernel-generalizations/sample_generalized.hpp create mode 100644 source/glkernel/include/glkernel-generalizations/scale_generalized.h create mode 100644 source/glkernel/include/glkernel-generalizations/scale_generalized.hpp create mode 100644 source/tests/glkernel-will_fail_tests/scale_fail.cpp diff --git a/source/glkernel/CMakeLists.txt b/source/glkernel/CMakeLists.txt index 5b46b5a..9429950 100644 --- a/source/glkernel/CMakeLists.txt +++ b/source/glkernel/CMakeLists.txt @@ -53,10 +53,13 @@ set(headers ${include_path}/shuffle.hpp ${include_path}/sort.h ${include_path}/sort.hpp - ${include_generalizations_path}/glkernel_generalizations.cpp - ${include_generalizations_path}/glkernel_generalizations.h + ${include_generalizations_path}/noise_generalized.hpp + ${include_generalizations_path}/noise_generalized.h + ${include_generalizations_path}/sample_generalized.hpp + ${include_generalizations_path}/sample_generalized.h + ${include_generalizations_path}/scale_generalized.hpp + ${include_generalizations_path}/scale_generalized.h ${include_generalizations_path}/AssertionMacros.h - ${include_generalizations_path}/ConstExpressions.cpp ${include_generalizations_path}/StringMacros.h ${include_generalizations_path}/TypeTraits.cpp ) diff --git a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h index 476ad6b..803d7be 100644 --- a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -1,126 +1,152 @@ #pragma once #include "TypeTraits.cpp" -#include "ConstExpressions.cpp" #include "StringMacros.h" -//#define CHECK_FLOATING_TYPE(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) -//#define CHECK_TYPE_EQUALITY(T1, T2, T3) static_assert(areSameType(), PARAM_MATCH_KERNEL) -//#define CHECK_CELLTYPE_EQUALITY(V1, V2, V3) static_assert(areSameCelltype(), PARAM_MATCH_CELL) +// Asserts, that kernel is of cell type vec2. +#define ASSERT_KERNEL_CELLTYPE_VEC2(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC2_KERNEL_CELLTYPE_MATCH_VEC3); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC2_KERNEL_CELLTYPE_MATCH_VEC4); +// Asserts, that kernel is of cell type vec3. +#define ASSERT_KERNEL_CELLTYPE_VEC3(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC3_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC3_KERNEL_CELLTYPE_MATCH_VEC4); -#define CHECK_TYPE_FLOATING(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) +// Asserts, that kernel is of cell type vec4. +#define ASSERT_KERNEL_CELLTYPE_VEC4(V) \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC4_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert( (areSameCelltype() && areSameCelltype()) || \ + (!areSameCelltype() && areSameCelltype()) || \ + !(areSameCelltype() && !areSameCelltype()) || \ + (!areSameCelltype() && !areSameCelltype()) \ + , VEC4_KERNEL_CELLTYPE_MATCH_VEC3); +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC2(V) \ + static_assert(!areSameCelltype(), NOT_VEC2_KERNEL_CELLTYPE); +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC3(V) \ + static_assert(!areSameCelltype(), NOT_VEC3_KERNEL_CELLTYPE); -// Checks, if kernel is of CELLtype vec2. -#define CHECK_KERNEL_CELLTYPE_VEC2(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC2_KERNEL_CELLTYPE_MATCH_VEC3); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC2_KERNEL_CELLTYPE_MATCH_VEC4); +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC4(V) \ + static_assert(!areSameCelltype(), NOT_VEC4_KERNEL_CELLTYPE); -// Checks, if kernel is of CELLtype vec3. -#define CHECK_KERNEL_CELLTYPE_VEC3(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC3_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC3_KERNEL_CELLTYPE_MATCH_VEC4); -// Checks, if kernel is of CELLtype vec4. -#define CHECK_KERNEL_CELLTYPE_VEC4(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC4_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC4_KERNEL_CELLTYPE_MATCH_VEC3); +// Fail, because (scalar) kernel is of some vectorial type. +#define FAIL_ON_VECTORIAL_KERNEL_CELLTYPE_ASSUMING_SCALAR(V) \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC3); \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC4); -// Fail, because vec2 kernel is of some scalar type -#define FAIL_KERNEL_CELLTYPE_VEC2(T) \ - static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_FLOAT); \ +// Fail, because (vec2) kernel is of some scalar type. +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T) \ + static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because vec3 kernel is of some scalar type -#define FAIL_KERNEL_CELLTYPE_VEC3(T) \ - static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ + +// Fail, because (vec3) kernel is of some scalar type. +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC3(T) \ + static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because vec4 kernel is of some scalar type -#define FAIL_KERNEL_CELLTYPE_VEC4(T) \ - static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_FLOAT); \ + +// Fail, because (vec4) kernel is of some scalar type. +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC4(T) \ + static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because scalar kernel is of some vectorial type -#define FAIL_KERNEL_CELLTYPE_SCALAR(V) \ - static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC3); \ - static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC4); +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2_OR_VEC3(T) \ + static_assert(!areSameType(), VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ + static_assert(!areSameType(), VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because scalar parameter (float or double) is of some vectorial celltype -#define FAIL_PARAM_TYPE_T(T, V) \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_TYPE_MATCH_VEC4); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_TYPE_MATCH_VEC4); -// Checks if all arguments are of the same type. +// Checks if all arguments are of the same component type. // Implicitly assumes that arguements are parameters of a method including kernel as first argument! -#define CHECK_TYPE_EQUALITY(T, ...) \ - static_assert( (areSameType() && areSameType()) || \ - (!areSameType() && areSameType()) || \ - !(areSameType() && !areSameType()) || \ - (!areSameType() && !areSameType()) \ - , PARAM_MATCH_FLOAT); \ - static_assert( (areSameType() && areSameType()) || \ - (!areSameType() && areSameType()) || \ - !(areSameType() && !areSameType()) || \ - (!areSameType() && !areSameType()) \ - , PARAM_MATCH_DOUBLE); - -// Checks if all arguments are of the same CELLtype. +#define ASSERT_COMPONENTTYPE_EQUALITY(T, ...) \ + static_assert( (areSameType() && areSameType()) || \ + (!areSameType() && areSameType()) || \ + !(areSameType() && !areSameType()) || \ + (!areSameType() && !areSameType()) \ + , PARAMS_MATCH_FLOAT); \ + static_assert( (areSameType() && areSameType()) || \ + (!areSameType() && areSameType()) || \ + !(areSameType() && !areSameType()) || \ + (!areSameType() && !areSameType()) \ + , PARAMS_MATCH_DOUBLE); + +// Checks if all arguments are of the same cell type. // Implicitly assumes that arguements are parameters of a method including kernel as first argument! -#define CHECK_CELLTYPE_EQUALITY(V, ...) \ +#define ASSERT_CELLTYPE_EQUALITY(V, ...) \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ (!areSameCelltype() && !areSameCelltype()) \ - , PARAM_MATCH_VEC2); \ + , PARAMS_MATCH_VEC2); \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ (!areSameCelltype() && !areSameCelltype()) \ - , PARAM_MATCH_VEC3); \ + , PARAMS_MATCH_VEC3); \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ (!areSameCelltype() && !areSameCelltype()) \ - , PARAM_MATCH_VEC4); + , PARAMS_MATCH_VEC4); + + + + +// Fail, because scalar parameter (float or double) is of some vectorial celltype +#define FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC4); + + + + +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T) \ + static_assert( !areSameType(), PARAMS_EQUAL_MATCH_FLOAT); \ + static_assert( !areSameType(), PARAMS_EQUAL_MATCH_DOUBLE); + + +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4); + + -//#define CHECK_FLOATING_TYPE(T) static_assert(std::is_floating_point::value, KERNEL_FLOATING) -//#define CHECK_TYPE_EQUALITY(...) checkTypeEquality<__VA_ARGS__>() diff --git a/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp b/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp deleted file mode 100644 index d6c3588..0000000 --- a/source/glkernel/include/glkernel-generalizations/ConstExpressions.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include - -#include - -#include "TypeTraits.cpp" -#include "StringMacros.h" - - -namespace glkernel -{ - -namespace noise -{ - - -/* - * These methods are mainly used for actually typing the assertions. - * Later the lines are copied to AssertionMacros.h. - */ - - -template -constexpr void checkTypeEquality() -{ - static_assert( (areSameType() && areSameType()) || - (!areSameType() && areSameType()) || - !(areSameType() && !areSameType()) || - (!areSameType() && !areSameType()) - , PARAM_MATCH_FLOAT); - - static_assert( (areSameType() && areSameType()) || - (!areSameType() && areSameType()) || - !(areSameType() && !areSameType()) || - (!areSameType() && !areSameType()) - , PARAM_MATCH_DOUBLE); -} - -template class V, template class... Vs> -constexpr void checkCelltypeEquality() -{ - static_assert( (areSameCelltype() && areSameCelltype()) || - (!areSameCelltype() && areSameCelltype()) || - !(areSameCelltype() && !areSameCelltype()) || - (!areSameCelltype() && !areSameCelltype()) - , PARAM_MATCH_VEC2); - - static_assert( (areSameCelltype() && areSameCelltype()) || - (!areSameCelltype() && areSameCelltype()) || - !(areSameCelltype() && !areSameCelltype()) || - (!areSameCelltype() && !areSameCelltype()) - , PARAM_MATCH_VEC3); - - static_assert( (areSameCelltype() && areSameCelltype()) || - (!areSameCelltype() && areSameCelltype()) || - !(areSameCelltype() && !areSameCelltype()) || - (!areSameCelltype() && !areSameCelltype()) - , PARAM_MATCH_VEC4); -} - - - -} // testEnv - -} // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h index 1af3f0e..d082e41 100644 --- a/source/glkernel/include/glkernel-generalizations/StringMacros.h +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -1,67 +1,101 @@ #pragma once + + + #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) -#define AT /*" In file " __FILE__ ":" TOSTRING(__LINE__)*/ +#define DOT_AT "." /*" In file " __FILE__ ":" TOSTRING(__LINE__)*/ #define WHICH_IS ", which is " +#define WHICH_ARE ", which are " #define BUT_IS ", but is " -#define FLOAT "float." -#define DOUBLE "double." -#define VEC2 "glm::tvec2." -#define VEC3 "glm::tvec3." -#define VEC4 "glm::tvec4." +#define FLOAT "float" +#define DOUBLE "double" +#define VEC2 "glm::tvec2" +#define VEC3 "glm::tvec3" +#define VEC4 "glm::tvec4" + + + + +#define KERNEL_MUST_SCALAR "Kernel must be of a floating scalar cell type" +#define KERNEL_MUST_VEC2 "Kernel must be of cell type glm::tvec2" +#define KERNEL_MUST_VEC3 "Kernel must be of cell type glm::tvec3" +#define KERNEL_MUST_VEC4 "Kernel must be of cell type glm::tvec4" + +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_SCALAR BUT_IS VEC2 DOT_AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_SCALAR BUT_IS VEC3 DOT_AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_SCALAR BUT_IS VEC4 DOT_AT + +#define VEC2_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 BUT_IS FLOAT DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 BUT_IS DOUBLE DOT_AT + +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC2 BUT_IS VEC3 DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC2 BUT_IS VEC4 DOT_AT + +#define VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC3 BUT_IS FLOAT DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC3 BUT_IS DOUBLE DOT_AT + +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC3 BUT_IS VEC2 DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC3 BUT_IS VEC4 DOT_AT + +#define VEC4_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC4 BUT_IS FLOAT DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC4 BUT_IS DOUBLE DOT_AT + +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC4 BUT_IS VEC2 DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC4 BUT_IS VEC3 DOT_AT + + +#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 " or " VEC3 BUT_IS FLOAT DOT_AT +#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 " or " BUT_IS DOUBLE DOT_AT + + -#define KERNEL_FLOATING "Kernel must be of a floating type (float or double)!" +#define PARAMS_MUST_EQUAL_KERNELTYPE "Types of kernel parameters must be equal and match kernel " +#define PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE PARAMS_MUST_EQUAL_KERNELTYPE "component type" +#define PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE PARAMS_MUST_EQUAL_KERNELTYPE "component- or cell type" -#define PARAM_MUST_KERNEL "Type of kernel parameter(s) must match kernel type" -#define PARAM_MATCH_FLOAT PARAM_MUST_KERNEL WHICH_IS FLOAT AT -#define PARAM_MATCH_DOUBLE PARAM_MUST_KERNEL WHICH_IS DOUBLE AT +#define PARAMS_EQUAL_MATCH_FLOAT PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT -#define PARAM_MUST_CELL "Celltype of kernel parameter(s) must match kernel celltype" -#define PARAM_MATCH_VEC2 PARAM_MUST_CELL WHICH_IS VEC2 AT -#define PARAM_MATCH_VEC3 PARAM_MUST_CELL WHICH_IS VEC3 AT -#define PARAM_MATCH_VEC4 PARAM_MUST_CELL WHICH_IS VEC4 AT +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC2 DOT_AT +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC3 DOT_AT +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC4 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC2 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC3 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC4 DOT_AT -#define KERNEL_MUST_SCALAR "Kernel must be of a scalar (floating: float or double) type" -#define KERNEL_MUST_VEC2 "Kernel must be of type glm::tvec2" -#define KERNEL_MUST_VEC3 "Kernel must be of type glm::tvec3" -#define KERNEL_MUST_VEC4 "Kernel must be of type glm::tvec4" -#define VEC2_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 BUT_IS FLOAT AT -#define VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 BUT_IS DOUBLE AT -#define VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC3 BUT_IS FLOAT AT -#define VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC3 BUT_IS DOUBLE AT +#define PARAMS_MUST_KERNEL_COMPONENTTYPE "Component type of kernel parameter(s) must match kernel component type" +#define PARAMS_MATCH_FLOAT PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT +#define PARAMS_MATCH_DOUBLE PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT -#define VEC4_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC4 BUT_IS FLOAT AT -#define VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC4 BUT_IS DOUBLE AT +#define PARAMS_MUST_KERNEL_CELLTYPE "Cell type of kernel parameter(s) must match kernel cell type" +#define PARAMS_MATCH_VEC2 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC2 DOT_AT +#define PARAMS_MATCH_VEC3 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC3 DOT_AT +#define PARAMS_MATCH_VEC4 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC4 DOT_AT -#define VEC2_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC2 BUT_IS VEC3 AT -#define VEC2_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC2 BUT_IS VEC4 AT -#define VEC3_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC3 BUT_IS VEC2 AT -#define VEC3_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC3 BUT_IS VEC4 AT +#define PARAM_MUST_KERNEL_FLOAT "Component type of kernel parameter must match kernel component type" WHICH_IS FLOAT +#define PARAM_MUST_KERNEL_DOUBLE "Component type of kernel parameter must match kernel component type" WHICH_IS DOUBLE -#define VEC4_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC4 BUT_IS VEC2 AT -#define VEC4_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC4 BUT_IS VEC3 AT +#define FLOAT_PARAM_MATCH_VEC2 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC2 DOT_AT +#define FLOAT_PARAM_MATCH_VEC3 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC3 DOT_AT +#define FLOAT_PARAM_MATCH_VEC4 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC4 DOT_AT -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_SCALAR BUT_IS VEC2 AT -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_SCALAR BUT_IS VEC3 AT -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_SCALAR BUT_IS VEC4 AT +#define DOUBLE_PARAM_MATCH_VEC2 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC2 DOT_AT +#define DOUBLE_PARAM_MATCH_VEC3 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC3 DOT_AT +#define DOUBLE_PARAM_MATCH_VEC4 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC4 DOT_AT -#define PARAM_MUST_FLOAT "Parameter must be of type float" -#define PARAM_MUST_DOUBLE "Parameter must be of type float" -#define FLOAT_PARAM_TYPE_MATCH_VEC2 PARAM_MUST_FLOAT BUT_IS VEC2 AT -#define FLOAT_PARAM_TYPE_MATCH_VEC3 PARAM_MUST_FLOAT BUT_IS VEC3 AT -#define FLOAT_PARAM_TYPE_MATCH_VEC4 PARAM_MUST_FLOAT BUT_IS VEC4 AT -#define DOUBLE_PARAM_TYPE_MATCH_VEC2 PARAM_MUST_DOUBLE BUT_IS VEC2 AT -#define DOUBLE_PARAM_TYPE_MATCH_VEC3 PARAM_MUST_DOUBLE BUT_IS VEC3 AT -#define DOUBLE_PARAM_TYPE_MATCH_VEC4 PARAM_MUST_DOUBLE BUT_IS VEC4 AT +#define NOT_VEC2_KERNEL_CELLTYPE "Kernel of type glm::tvec2 is not supported!" +#define NOT_VEC3_KERNEL_CELLTYPE "Kernel of type glm::tvec3 is not supported!" +#define NOT_VEC4_KERNEL_CELLTYPE "Kernel of type glm::tvec4 is not supported!" diff --git a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp index 2e8b4f7..4bf7937 100644 --- a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -10,6 +10,7 @@ namespace glkernel + template struct are_same_type : std::false_type { }; @@ -47,19 +48,31 @@ constexpr bool areSameCelltype() { return are_same_celltype::value; } template -struct is_celltype : std::false_type {}; +struct is_cellType : std::false_type {}; + +template class V> +struct is_cellType> : std::true_type {}; template class V> -struct is_celltype> : std::true_type {}; +constexpr bool isCellType() { return is_cellType>::value; } + +template +constexpr bool isCellType() { return is_cellType::value; } + + +template +struct is_componenType : std::true_type {}; template class V> -constexpr bool isCelltype() { return is_celltype>::value; } +struct is_componenType> : std::false_type {}; +template class V> +constexpr bool isComponentType() { return is_componenType>::value; } +template +constexpr bool isComponentType() { return is_componenType::value; } -template< typename T > -struct always_false : std::false_type {}; template diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp b/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp deleted file mode 100644 index 840d868..0000000 --- a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#pragma once - -#include "glkernel_generalizations.h" -#include "AssertionMacros.h" -#include - - -namespace glkernel -{ - - - - -namespace noise -{ - - -template -void uniform(tkernel &, const T2, const T3) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); -} - -template class V> -void uniform(tkernel> &, const T2, const T3) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); -} - -template class V1, template class V2, template class V3> -void uniform(tkernel> &, const V2 &, const V3 &) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); - CHECK_CELLTYPE_EQUALITY(V1, V2, V3); -} - - -template -void normal(tkernel &, const T2, const T3) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); -} - -template class V> -void normal(tkernel> &, const T2, const T3) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); -} - -template class V1, template class V2, template class V3> -void normal(tkernel> &, const V2 &, const V3 &) -{ - CHECK_TYPE_FLOATING(T1); - CHECK_TYPE_EQUALITY(T1, T2, T3); - CHECK_CELLTYPE_EQUALITY(V1, V2, V3); -} - - -template class V> -void gradient(tkernel> & - , const GradientNoiseType - , const OctaveType - , const unsigned int - , const unsigned int) -{ - FAIL_KERNEL_CELLTYPE_SCALAR(V); -} - - -} // namespace noise - - - - -namespace sample -{ - - -template -void poisson_square(tkernel &, const unsigned int) -{ - FAIL_KERNEL_CELLTYPE_VEC2(T); -} - -template class V> -void poisson_square(tkernel> &, const unsigned int) -{ - CHECK_KERNEL_CELLTYPE_VEC2(V); -} - - -template -void poisson_square(tkernel &, const T2, const unsigned int) -{ - FAIL_KERNEL_CELLTYPE_VEC2(T1); - CHECK_TYPE_EQUALITY(T1, T2); -} - -template class V> -void poisson_square(tkernel> &, const T2, const unsigned int) -{ - CHECK_KERNEL_CELLTYPE_VEC2(V); - CHECK_TYPE_EQUALITY(T1, T2); -} - - -template class V> -void poisson_square(tkernel &, const V &, const unsigned int) -{ - FAIL_KERNEL_CELLTYPE_VEC2(T1); - FAIL_PARAM_TYPE_T(T1, V); - CHECK_TYPE_EQUALITY(T1, T2); -} - -template class V1, template class V2> -void poisson_square(tkernel> &, const V2 &, const unsigned int) -{ - CHECK_KERNEL_CELLTYPE_VEC2(V1); - FAIL_PARAM_TYPE_T(T1, V2); - CHECK_TYPE_EQUALITY(T1, T2); -} - - -} // namespace sample - - - - -namespace scale -{ - - - -} // namespace scale - - - - -namespace sequence -{ - - -} // namespace sequence - - - - -namespace shuffle -{ - - - -} // namespace shuffle - - - - -namespace sort -{ - - - -} // namespace sort - - - - -} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h b/source/glkernel/include/glkernel-generalizations/noise_generalized.h similarity index 50% rename from source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h rename to source/glkernel/include/glkernel-generalizations/noise_generalized.h index 015c403..3c214e0 100644 --- a/source/glkernel/include/glkernel-generalizations/glkernel_generalizations.h +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.h @@ -1,139 +1,107 @@ #pragma once #include + #include -#include namespace glkernel { - - namespace noise { -template + + +template class V> void uniform(tkernel &, const T2, const T3); -template class V> -void uniform(tkernel> &, const T2, const T3); -template class V1, template class V2, template class V3> -void uniform(tkernel> &, const V2 &, const V3 &); +template class V> +void uniform(tkernel &, const V &, const T3); +template class V> +void uniform(tkernel &, const T2, const V &); -template -void normal(tkernel &, const T2, const T3); template class V> -void normal(tkernel> &, const T2, const T3); +void uniform(tkernel> &, const T2, const T3); + template class V1, template class V2, template class V3> -void normal(tkernel> &, const V2 &, const V3 &); - - -template class V> -void gradient(tkernel> & - , const GradientNoiseType = GradientNoiseType::Perlin - , const OctaveType = OctaveType::Standard - , const unsigned int = 3 - , const unsigned int = 5); - + template class V1, template class V2> +void uniform(tkernel> &, const V2 &, const T3); -} // namespace noise +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &); -namespace sample -{ +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &); -//template -//size_t poisson_square(tkernel> & kernel, unsigned int num_probes = 32); -template -void poisson_square(tkernel &, const unsigned int = 32); -template class V> -void poisson_square(tkernel> &, const unsigned int = 32); +template +void normal(tkernel &, const T2, const T3); +template class V> +void normal(tkernel &, const V &, const T3); +template class V> +void normal(tkernel &, const T2, const V &); -template -void poisson_square(tkernel &, const T2, const unsigned int = 32); -template class V> -void poisson_square(tkernel> &, const T2, const unsigned int = 32); - - +void normal(tkernel> &, const T2, const T3); -template class V1, template class V2> -size_t poisson_square(tkernel> &, const V2 &, const unsigned int = 32); - -template class V> -size_t poisson_square(tkernel &, const V &, const unsigned int = 32); - - - - - - -//template -//size_t poisson_square(tkernel> & kernel, T min_dist, unsigned int num_probes = 32); - - -} // namespace sample - - -namespace scale -{ - - - -} // namespace scale - - -namespace sequence -{ - - -} // namespace sequence - - -namespace shuffle -{ - +void normal(tkernel> &, const V2 &, const T3); +template class V1, template class V2> +void normal(tkernel> &, const T2, const V2 &); -} // namespace shuffle +template class V1, template class V2, template class V3> +void normal(tkernel> &, const V2 &, const V3 &); -namespace sort -{ +template class V> +void gradient(tkernel> & + , const GradientNoiseType = GradientNoiseType::Perlin + , const OctaveType = OctaveType::Standard + , const unsigned int = 3 + , const unsigned int = 5); -} // namespace sort +} // namespace noise } // namespace glkernel -#include "glkernel_generalizations.cpp" +#include "noise_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp new file mode 100644 index 0000000..5627c8d --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp @@ -0,0 +1,150 @@ +#pragma once + +#include "noise_generalized.h" +#include "AssertionMacros.h" +#include + + +namespace glkernel +{ + + +namespace noise +{ + + + + +template +void uniform(tkernel &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V> +void uniform(tkernel &, const V &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void uniform(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + + +template class V> +void uniform(tkernel> &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V1, template class V2> +void uniform(tkernel> &, const V2 &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + + +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); + ASSERT_CELLTYPE_EQUALITY(V1, V2, V3); +} + + + + +template +void normal(tkernel &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V> +void normal(tkernel &, const V &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void normal(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + + +template class V> +void normal(tkernel> &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V1, template class V2> +void normal(tkernel> &, const V2 &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void normal(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + + +template class V1, template class V2, template class V3> +void normal(tkernel> &, const V2 &, const V3 &) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); + ASSERT_CELLTYPE_EQUALITY(V1, V2, V3); +} + + +template class V> +void gradient(tkernel> & + , const GradientNoiseType + , const OctaveType + , const unsigned int + , const unsigned int) +{ + FAIL_ON_VECTORIAL_KERNEL_CELLTYPE_ASSUMING_SCALAR(V); +} + + + + +} // namespace noise + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.h b/source/glkernel/include/glkernel-generalizations/sample_generalized.h new file mode 100644 index 0000000..f57e253 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.h @@ -0,0 +1,137 @@ +#pragma once + +#include + +#include +#include + + +namespace glkernel +{ + + +namespace sample +{ + + +template +void poisson_square(tkernel &, const unsigned int = 32); + +template class V> +void poisson_square(tkernel> &, const unsigned int = 32); + + +template +void poisson_square(tkernel &, const T2, const unsigned int = 32); + +template class V> +void poisson_square(tkernel> &, const T2, const unsigned int = 32); + + +template class V1, template class V2> +void poisson_square(tkernel> &, const V2 &, const unsigned int = 32); + +template class V> +void poisson_square(tkernel &, const V &, const unsigned int = 32); + + + + +template class V> +void stratified(tkernel> &); + + + + +template +void hammersley(tkernel &); + +template class V> +void hammersley(tkernel> &); + + + + +template +void halton(tkernel &, const unsigned int, const unsigned int); + + +template class V> +void halton(tkernel> &, const unsigned int, const unsigned int); + + + + +template +void hammersley_sphere(tkernel &, const HemisphereMapping = HemisphereMapping::Uniform); + +template class V> +void hammersley_sphere(tkernel> &, const HemisphereMapping = HemisphereMapping::Uniform); + + + + + +template +void halton_sphere(tkernel &, const unsigned int, const unsigned int, const HemisphereMapping = HemisphereMapping::Uniform); + +template class V> +void halton_sphere(tkernel> &, const unsigned int, const unsigned int, const HemisphereMapping = HemisphereMapping::Uniform); + + + + +template +void best_candidate(tkernel &, unsigned int = 32); + +template class V> +void best_candidate(tkernel> &, unsigned int = 32); + + + + +template +void n_rooks(tkernel &); + +template class V> +void n_rooks(tkernel> &); + + + + +template +void multi_jittered(tkernel &, const bool = false); + +template class V> +void multi_jittered(tkernel> &, const bool = false); + + + + +template +void golden_point_set(tkernel &); + +template class V> +void golden_point_set(tkernel> &); + + + + +} // namespace sample + + +} // namespace glkernel + + +#include "sample_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp new file mode 100644 index 0000000..4431079 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp @@ -0,0 +1,205 @@ +#pragma once + +#include "sample_generalized.h" +#include "AssertionMacros.h" +#include + + + +namespace glkernel +{ + + +namespace sample +{ + + +template +void poisson_square(tkernel &, const unsigned int) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + +template class V> +void poisson_square(tkernel> &, const unsigned int) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + +template +void poisson_square(tkernel &, const T2, const unsigned int) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T1); +} + +template class V> +void poisson_square(tkernel> &, const T2, const unsigned int) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2); +} + + +template class V> +void poisson_square(tkernel &, const V &, const unsigned int) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T1); + FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V); + //FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V) +} + +template class V1, template class V2> +void poisson_square(tkernel> &, const V2 &, const unsigned int) +{ + FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V2); + //FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V2) +} + + + + +template class V> +void stratified(tkernel> &) +{ + ASSERT_KERNEL_CELLTYPE_NOT_VEC4(V); +} + + + + +template +void hammersley(tkernel &) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + +template class V> +void hammersley(tkernel> &) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + + + +template +void halton(tkernel &, const unsigned int, const unsigned int) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + + +template class V> +void halton(tkernel> &, const unsigned int, const unsigned int) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + + + +template +void hammersley_sphere(tkernel &, const HemisphereMapping) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC3(T); +} + +template class V> +void hammersley_sphere(tkernel> &, const HemisphereMapping) +{ + ASSERT_KERNEL_CELLTYPE_VEC3(V); +} + + + + + +template +void halton_sphere(tkernel &, const unsigned int, const unsigned int, const HemisphereMapping) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC3(T); +} + +template class V> +void halton_sphere(tkernel> &, const unsigned int, const unsigned int, const HemisphereMapping) +{ + ASSERT_KERNEL_CELLTYPE_VEC3(V); +} + + + + +template +void best_candidate(tkernel &, unsigned int) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2_OR_VEC3(T); +} + +template class V> +void best_candidate(tkernel> &, unsigned int) +{ + ASSERT_KERNEL_CELLTYPE_NOT_VEC4(V); +} + + + + +template +void n_rooks(tkernel &) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + +template class V> +void n_rooks(tkernel> &) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + + + +template +void multi_jittered(tkernel &, const bool) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + +template class V> +void multi_jittered(tkernel> &, const bool) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + + + +template +void golden_point_set(tkernel &) +{ + FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T); +} + +template class V> +void golden_point_set(tkernel> &) +{ + ASSERT_KERNEL_CELLTYPE_VEC2(V); +} + + +} // namespace sample + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/scale_generalized.h b/source/glkernel/include/glkernel-generalizations/scale_generalized.h new file mode 100644 index 0000000..9e045db --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.h @@ -0,0 +1,69 @@ +#pragma once + +#include + +#include + + +namespace glkernel +{ + + +namespace scale +{ + + + + +template +void range(tkernel &, T2, T3, T4 = 0, T5 = 1); + + +template class V> +void range(tkernel &, const V &, T3, T4 = 0, T5 = 1); + +template class V> +void range(tkernel &, T2, const V &, T4 = 0, T5 = 1); + +template class V> +void range(tkernel &, T2, T3, const V & = 0, T5 = 1); + +template class V> +void range(tkernel &, T2, T3, T4 = 0, const V & = 1); + + +template class V> +void range(tkernel> &, T2, T3, T4 = 0, T5 = 1); + + +template class V1, template class V2> +void range(tkernel> &, const V2 &, T3, T4 = 0, T5 = 1); + +template class V1, template class V2> +void range(tkernel> &, T2, const V2 &, T4 = 0, T5 = 1); + +template class V1, template class V2> +void range(tkernel> &, T2, T3, const V2 & = 0, T5 = 1); + +template class V1, template class V2> +void range(tkernel> &, T2, T3, T4 = 0, const V2 & = 1); + + + + +} // namespace scale + + +} // namespace glkernel + + +#include "scale_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp new file mode 100644 index 0000000..1bfc291 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include "scale_generalized.h" +#include "AssertionMacros.h" +#include + + + +namespace glkernel +{ + + +namespace scale +{ + + + + +template +void range(tkernel &, T2, T3, T4, T5) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3, T4, T5); +} + + +template class V> +void range(tkernel &, const V &, T3, T4, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void range(tkernel &, T2, const V &, T4, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void range(tkernel &, T2, T3, const V &, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void range(tkernel &, T2, T3, T4, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + + +template class V> +void range(tkernel> &, T2, T3, T4, T5) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3, T4, T5); +} + + +template class V1, template class V2> +void range(tkernel> &, const V2 &, T3, T4, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void range(tkernel> &, T2, const V2 &, T4, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void range(tkernel> &, T2, T3, const V2 &, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void range(tkernel> &, T2, T3, T4, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + + + + +} // namespace scale + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel/noise.h b/source/glkernel/include/glkernel/noise.h index 7f27713..fc37f7e 100644 --- a/source/glkernel/include/glkernel/noise.h +++ b/source/glkernel/include/glkernel/noise.h @@ -99,3 +99,5 @@ void gradient(tkernel & kernel #include + +#include diff --git a/source/glkernel/include/glkernel/sample.h b/source/glkernel/include/glkernel/sample.h index 3615fe0..efe6cfe 100644 --- a/source/glkernel/include/glkernel/sample.h +++ b/source/glkernel/include/glkernel/sample.h @@ -204,3 +204,5 @@ void golden_point_set(tkernel> & kernel); #include + +#include diff --git a/source/glkernel/include/glkernel/scale.h b/source/glkernel/include/glkernel/scale.h index 0aa9b77..e717235 100644 --- a/source/glkernel/include/glkernel/scale.h +++ b/source/glkernel/include/glkernel/scale.h @@ -27,3 +27,5 @@ void range(tkernel> & kernel, T rangeToLower, T rangeToUpper, T rangeFro #include + +#include diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt index 8be2a44..4b5cc71 100644 --- a/source/tests/glkernel-will_fail_tests/CMakeLists.txt +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -127,7 +127,7 @@ function(add_own_test scope name idx) WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # Expect these tests to fail (i.e. cmake --build should return # a non-zero value) - set_tests_properties(${target} PROPERTIES WILL_FAIL TRUE) + set_tests_properties(${target} PROPERTIES PASS_REGULAR_EXPRESSION "static assertion failed") endif() endfunction() @@ -140,6 +140,15 @@ add_own_test(noise normal 3) add_own_test(noise normal 4) add_own_test(noise normal 5) add_own_test(noise normal 6) +add_own_test(noise normal 7) +add_own_test(noise normal 8) +add_own_test(noise normal 9) +add_own_test(noise normal 10) +add_own_test(noise normal 11) +add_own_test(noise normal 12) +add_own_test(noise normal 13) +add_own_test(noise normal 14) + add_own_test(noise uniform 1) add_own_test(noise uniform 2) add_own_test(noise uniform 3) @@ -147,8 +156,51 @@ add_own_test(noise uniform 4) add_own_test(noise uniform 5) add_own_test(noise uniform 6) add_own_test(noise uniform 7) +add_own_test(noise uniform 8) +add_own_test(noise uniform 9) +add_own_test(noise uniform 10) +add_own_test(noise uniform 11) +add_own_test(noise uniform 12) +add_own_test(noise uniform 13) +add_own_test(noise uniform 14) + +add_own_test(noise gradient 1) + add_own_test(sample poisson_square 1) add_own_test(sample poisson_square 2) add_own_test(sample poisson_square 3) add_own_test(sample poisson_square 4) +add_own_test(sample poisson_square 5) +add_own_test(sample poisson_square 6) +add_own_test(sample poisson_square 7) +add_own_test(sample poisson_square 8) +add_own_test(sample poisson_square 9) + +add_own_test(sample stratified 1) +add_own_test(sample hammersley 1) +add_own_test(sample hammersley 2) +add_own_test(sample halton 1) +add_own_test(sample halton 2) +add_own_test(sample hammersley_sphere 1) +add_own_test(sample hammersley_sphere 2) +add_own_test(sample halton_sphere 1) +add_own_test(sample halton_sphere 2) +add_own_test(sample best_candidate 1) +add_own_test(sample best_candidate 2) +add_own_test(sample nrooks 1) +add_own_test(sample nrooks 2) +add_own_test(sample multi_jittered 1) +add_own_test(sample multi_jittered 2) +add_own_test(sample golden_point_set 1) +add_own_test(sample golden_point_set 2) + + +add_own_test(scale range 1) +add_own_test(scale range 2) +add_own_test(scale range 3) +add_own_test(scale range 4) +add_own_test(scale range 5) +add_own_test(scale range 6) +add_own_test(scale range 7) +add_own_test(scale range 8) diff --git a/source/tests/glkernel-will_fail_tests/noise_fail.cpp b/source/tests/glkernel-will_fail_tests/noise_fail.cpp index 32c3a1c..8bcd722 100644 --- a/source/tests/glkernel-will_fail_tests/noise_fail.cpp +++ b/source/tests/glkernel-will_fail_tests/noise_fail.cpp @@ -5,8 +5,6 @@ #include #include -#include - #include int main() @@ -21,28 +19,60 @@ int main() #if defined NOISE_NORMAL_1 glkernel::noise::normal(fkernel1, 0.0f, 1.0); #elif defined NOISE_NORMAL_2 - glkernel::noise::normal(fkernel2, 0.0f, 1.0); + glkernel::noise::normal(fkernel1, glm::vec2{ 0.0 }, 1.0f); #elif defined NOISE_NORMAL_3 - glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); + glkernel::noise::normal(fkernel1, 0.0f, glm::vec2{ 0.0 }); #elif defined NOISE_NORMAL_4 - glkernel::noise::normal(dkernel1, 0.0, 1.0f); + glkernel::noise::normal(fkernel2, 0.0f, 1.0); #elif defined NOISE_NORMAL_5 - glkernel::noise::normal(dkernel2, 0.0, 1.0f); + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, 1.0f); #elif defined NOISE_NORMAL_6 - glkernel::noise::normal(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); + glkernel::noise::normal(fkernel2, 0.0f, glm::vec2{ 1.0 }); +#elif defined NOISE_NORMAL_7 + glkernel::noise::normal(fkernel2, glm::dvec2{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_NORMAL_8 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined NOISE_NORMAL_9 + glkernel::noise::normal(fkernel2, glm::vec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_NORMAL_10 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined NOISE_NORMAL_11 + glkernel::noise::normal(fkernel2, glm::dvec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_NORMAL_12 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_NORMAL_13 + glkernel::noise::normal(fkernel2, glm::vec3{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined NOISE_NORMAL_14 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); #elif defined NOISE_UNIFORM_1 glkernel::noise::uniform(fkernel1, 0.0f, 1.0); #elif defined NOISE_UNIFORM_2 - glkernel::noise::uniform(fkernel2, 0.0f, 1.0); + glkernel::noise::uniform(fkernel1, glm::vec2{ 0.0 }, 1.0f); #elif defined NOISE_UNIFORM_3 - glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); + glkernel::noise::uniform(fkernel1, 0.0f, glm::vec2{ 0.0 }); #elif defined NOISE_UNIFORM_4 - glkernel::noise::uniform(dkernel1, 0.0, 1.0f); + glkernel::noise::uniform(fkernel2, 0.0f, 1.0); #elif defined NOISE_UNIFORM_5 - glkernel::noise::uniform(dkernel2, 0.0, 1.0f); + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, 1.0f); #elif defined NOISE_UNIFORM_6 - glkernel::noise::uniform(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); + glkernel::noise::uniform(fkernel2, 0.0f, glm::vec2{ 1.0 }); #elif defined NOISE_UNIFORM_7 + glkernel::noise::uniform(fkernel2, glm::dvec2{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_UNIFORM_8 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined NOISE_UNIFORM_9 + glkernel::noise::uniform(fkernel2, glm::vec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_UNIFORM_10 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined NOISE_UNIFORM_11 + glkernel::noise::uniform(fkernel2, glm::dvec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined NOISE_UNIFORM_12 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_UNIFORM_13 + glkernel::noise::uniform(fkernel2, glm::vec3{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined NOISE_UNIFORM_14 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined NOISE_GRADIENT_1 glkernel::noise::gradient(dkernel2); #endif diff --git a/source/tests/glkernel-will_fail_tests/sample_fail.cpp b/source/tests/glkernel-will_fail_tests/sample_fail.cpp index 4b0f0bc..104db73 100644 --- a/source/tests/glkernel-will_fail_tests/sample_fail.cpp +++ b/source/tests/glkernel-will_fail_tests/sample_fail.cpp @@ -5,8 +5,6 @@ #include #include -#include - #include int main() @@ -14,6 +12,7 @@ int main() auto fkernel1 = glkernel::kernel1{ 1 }; auto fkernel2 = glkernel::kernel2{ 1 }; auto fkernel3 = glkernel::kernel3{ 1 }; + auto fkernel4 = glkernel::kernel4{ 1 }; auto dkernel1 = glkernel::dkernel1{ 1 }; auto dkernel2 = glkernel::dkernel2{ 1 }; @@ -22,32 +21,56 @@ int main() #if defined SAMPLE_POISSON_SQUARE_1 glkernel::sample::poisson_square(fkernel1); -#elif defined SAMPLE_POISSON_SQUARE_1 +#elif defined SAMPLE_POISSON_SQUARE_2 glkernel::sample::poisson_square(fkernel1, 1.5); -#elif defined SAMPLE_POISSON_SQUARE_1 +#elif defined SAMPLE_POISSON_SQUARE_3 glkernel::sample::poisson_square(fkernel1, glm::vec2{ 1.5 }); -#elif defined SAMPLE_POISSON_SQUARE_2 +#elif defined SAMPLE_POISSON_SQUARE_4 glkernel::sample::poisson_square(fkernel2, 1.5); -#elif defined SAMPLE_POISSON_SQUARE_3 +#elif defined SAMPLE_POISSON_SQUARE_5 + glkernel::sample::poisson_square(fkernel2, glm::vec2{ 1.5 }); +#elif defined SAMPLE_POISSON_SQUARE_6 + glkernel::sample::poisson_square(fkernel2, glm::vec3{ 1.5 }); +#elif defined SAMPLE_POISSON_SQUARE_7 glkernel::sample::poisson_square(fkernel3); -#elif defined SAMPLE_POISSON_SQUARE_4 +#elif defined SAMPLE_POISSON_SQUARE_8 glkernel::sample::poisson_square(fkernel3, 1.5); -#elif defined SAMPLE_POISSON_SQUARE_5 +#elif defined SAMPLE_POISSON_SQUARE_9 glkernel::sample::poisson_square(fkernel3, glm::vec2{ 1.5 }); -#elif defined SAMPLE_POISSON_SQUARE_6 - glkernel::noise::normal(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); -#elif defined NOISE_UNIFORM_1 - glkernel::noise::uniform(fkernel1, 0.0f, 1.0); -#elif defined NOISE_UNIFORM_2 - glkernel::noise::uniform(fkernel2, 0.0f, 1.0); -#elif defined NOISE_UNIFORM_3 - glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); -#elif defined NOISE_UNIFORM_4 - glkernel::noise::uniform(dkernel1, 0.0, 1.0f); -#elif defined NOISE_UNIFORM_5 - glkernel::noise::uniform(dkernel2, 0.0, 1.0f); -#elif defined NOISE_UNIFORM_6 - glkernel::noise::uniform(dkernel2, glm::dvec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined SAMPLE_STRATIFIED_1 + glkernel::sample::stratified(fkernel4); +#elif defined SAMPLE_HAMMERSLEY_1 + glkernel::sample::hammersley(fkernel1); +#elif defined SAMPLE_HAMMERSLEY_2 + glkernel::sample::hammersley(fkernel3); +#elif defined SAMPLE_HALTON_1 + glkernel::sample::halton(fkernel1, 2, 3); +#elif defined SAMPLE_HALTON_2 + glkernel::sample::halton(fkernel3, 2, 3); +#elif defined SAMPLE_HAMMERSLEY_SPHERE_1 + glkernel::sample::hammersley_sphere(fkernel1); +#elif defined SAMPLE_HAMMERSLEY_SPHERE_2 + glkernel::sample::hammersley_sphere(fkernel2); +#elif defined SAMPLE_HALTON_SPHERE_1 + glkernel::sample::halton_sphere(fkernel1, 2, 3); +#elif defined SAMPLE_HALTON_SPHERE_2 + glkernel::sample::halton_sphere(fkernel2, 2, 3); +#elif defined SAMPLE_BEST_CANDIDATE_1 + glkernel::sample::best_candidate(fkernel1); +#elif defined SAMPLE_BEST_CANDIDATE_2 + glkernel::sample::best_candidate(fkernel4); +#elif defined SAMPLE_NROOKS_1 + glkernel::sample::n_rooks(fkernel1); +#elif defined SAMPLE_NROOKS_2 + glkernel::sample::n_rooks(fkernel3); +#elif defined SAMPLE_MULTI_JITTERED_1 + glkernel::sample::multi_jittered(fkernel1); +#elif defined SAMPLE_MULTI_JITTERED_2 + glkernel::sample::multi_jittered(fkernel3); +#elif defined SAMPLE_GOLDEN_POINT_SET_1 + glkernel::sample::golden_point_set(fkernel1); +#elif defined SAMPLE_GOLDEN_POINT_SET_2 + glkernel::sample::golden_point_set(fkernel3); #endif return 0; diff --git a/source/tests/glkernel-will_fail_tests/scale_fail.cpp b/source/tests/glkernel-will_fail_tests/scale_fail.cpp new file mode 100644 index 0000000..fc30c52 --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/scale_fail.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include +#include + +#include + +int main() +{ + auto fkernel1 = glkernel::kernel1{ 1 }; + auto fkernel2 = glkernel::kernel2{ 1 }; + auto fkernel3 = glkernel::kernel3{ 1 }; + auto fkernel4 = glkernel::kernel4{ 1 }; + + auto dkernel1 = glkernel::dkernel1{ 1 }; + auto dkernel2 = glkernel::dkernel2{ 1 }; + auto dkernel3 = glkernel::dkernel3{ 1 }; + + +#if defined SCALE_RANGE_1 + glkernel::scale::range(fkernel1, -0.5, 0.5f, 5.f, 10.f); +#elif defined SCALE_RANGE_2 + glkernel::scale::range(fkernel1, -0.5f, 0.5f, 5.f, 10.0); +#elif defined SCALE_RANGE_3 + glkernel::scale::range(fkernel1, glm::vec2{ -0.5 }, 0.5f, 5.f, 10.f); +#elif defined SCALE_RANGE_4 + glkernel::scale::range(fkernel3, -0.5, 0.5f, 5.f, glm::vec3(10.0)); +#elif defined SCALE_RANGE_5 + glkernel::scale::range(fkernel3, -0.5, 0.5f, 5.f, 10.f); +#elif defined SCALE_RANGE_6 + glkernel::scale::range(fkernel3, -0.5f, 0.5f, 5.f, 10.0); +#elif defined SCALE_RANGE_7 + glkernel::scale::range(fkernel3, glm::vec2{ -0.5 }, 0.5f, 5.f, 10.f); +#elif defined SCALE_RANGE_8 + glkernel::scale::range(fkernel3, -0.5, 0.5f, 5.f, glm::vec3(10.0)); +#endif + + return 0; +} + + From 6f022cf63f25187295babfa8442b39738791959a Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 5 Mar 2018 10:56:43 +0100 Subject: [PATCH 04/10] compile errors and tests: all done --- source/glkernel/CMakeLists.txt | 6 + .../AssertionMacros.h | 34 ++-- .../glkernel-generalizations/StringMacros.h | 112 +++++++----- .../glkernel-generalizations/TypeTraits.cpp | 21 --- .../sequence_generalized.h | 62 +++++++ .../sequence_generalized.hpp | 80 +++++++++ .../shuffle_generalized.h | 24 +++ .../shuffle_generalized.hpp | 21 +++ .../sort_generalized.h | 53 ++++++ .../sort_generalized.hpp | 66 +++++++ source/glkernel/include/glkernel/sequence.h | 2 + source/glkernel/include/glkernel/shuffle.h | 2 + source/glkernel/include/glkernel/sort.h | 2 + .../glkernel-will_fail_tests/CMakeLists.txt | 165 ++++++++++-------- .../glkernel-will_fail_tests/noise_fail.cpp | 2 - .../sequence_fail.cpp | 51 ++++++ .../glkernel-will_fail_tests/shuffle_fail.cpp | 13 ++ .../glkernel-will_fail_tests/sort_fail.cpp | 37 ++++ 18 files changed, 605 insertions(+), 148 deletions(-) create mode 100644 source/glkernel/include/glkernel-generalizations/sequence_generalized.h create mode 100644 source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp create mode 100644 source/glkernel/include/glkernel-generalizations/shuffle_generalized.h create mode 100644 source/glkernel/include/glkernel-generalizations/shuffle_generalized.hpp create mode 100644 source/glkernel/include/glkernel-generalizations/sort_generalized.h create mode 100644 source/glkernel/include/glkernel-generalizations/sort_generalized.hpp create mode 100644 source/tests/glkernel-will_fail_tests/sequence_fail.cpp create mode 100644 source/tests/glkernel-will_fail_tests/shuffle_fail.cpp create mode 100644 source/tests/glkernel-will_fail_tests/sort_fail.cpp diff --git a/source/glkernel/CMakeLists.txt b/source/glkernel/CMakeLists.txt index 9429950..e0fb76f 100644 --- a/source/glkernel/CMakeLists.txt +++ b/source/glkernel/CMakeLists.txt @@ -59,6 +59,12 @@ set(headers ${include_generalizations_path}/sample_generalized.h ${include_generalizations_path}/scale_generalized.hpp ${include_generalizations_path}/scale_generalized.h + ${include_generalizations_path}/sequence_generalized.h + ${include_generalizations_path}/sequence_generalized.hpp + ${include_generalizations_path}/shuffle_generalized.h + ${include_generalizations_path}/shuffle_generalized.hpp + ${include_generalizations_path}/sort_generalized.h + ${include_generalizations_path}/sort_generalized.hpp ${include_generalizations_path}/AssertionMacros.h ${include_generalizations_path}/StringMacros.h ${include_generalizations_path}/TypeTraits.cpp diff --git a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h index 803d7be..2196b5d 100644 --- a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -85,6 +85,10 @@ +#define ASSERT_TYPE_EQUALITY(...) \ + static_assert(areSameType<__VA_ARGS__>(), ARGUMENTS_MUST_EQUAL) + + // Checks if all arguments are of the same component type. // Implicitly assumes that arguements are parameters of a method including kernel as first argument! #define ASSERT_COMPONENTTYPE_EQUALITY(T, ...) \ @@ -92,7 +96,7 @@ (!areSameType() && areSameType()) || \ !(areSameType() && !areSameType()) || \ (!areSameType() && !areSameType()) \ - , PARAMS_MATCH_FLOAT); \ + , PARAMS_MATCH_FLOAT); \ static_assert( (areSameType() && areSameType()) || \ (!areSameType() && areSameType()) || \ !(areSameType() && !areSameType()) || \ @@ -106,12 +110,12 @@ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ (!areSameCelltype() && !areSameCelltype()) \ - , PARAMS_MATCH_VEC2); \ + , PARAMS_MATCH_VEC2); \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ (!areSameCelltype() && !areSameCelltype()) \ - , PARAMS_MATCH_VEC3); \ + , PARAMS_MATCH_VEC3); \ static_assert( (areSameCelltype() && areSameCelltype()) || \ (!areSameCelltype() && areSameCelltype()) || \ !(areSameCelltype() && !areSameCelltype()) || \ @@ -131,19 +135,29 @@ static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC4); +// Fail, because vectorial parameter is of some scalar celltype +#define FAIL_ON_PARAM_ASSUMING_CELLTYPE(V, T) \ + static_assert( !(areSameCelltype() && areSameType()), VEC2_PARAM_MATCH_FLOAT); \ + static_assert( !(areSameCelltype() && areSameType()), VEC2_PARAM_MATCH_DOUBLE); \ + static_assert( !(areSameCelltype() && areSameType()), VEC3_PARAM_MATCH_FLOAT); \ + static_assert( !(areSameCelltype() && areSameType()), VEC3_PARAM_MATCH_DOUBLE); \ + static_assert( !(areSameCelltype() && areSameType()), VEC4_PARAM_MATCH_FLOAT); \ + static_assert( !(areSameCelltype() && areSameType()), VEC4_PARAM_MATCH_DOUBLE); + + -#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T) \ +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T) \ static_assert( !areSameType(), PARAMS_EQUAL_MATCH_FLOAT); \ static_assert( !areSameType(), PARAMS_EQUAL_MATCH_DOUBLE); -#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T, V) \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3); \ +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3); \ static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4); diff --git a/source/glkernel/include/glkernel-generalizations/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h index d082e41..17b6283 100644 --- a/source/glkernel/include/glkernel-generalizations/StringMacros.h +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -2,6 +2,8 @@ +#define IDF "Kernel Template Error: " + #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) @@ -10,7 +12,7 @@ #define WHICH_IS ", which is " #define WHICH_ARE ", which are " -#define BUT_IS ", but is " +#define BUT_IS ", but it is " #define FLOAT "float" #define DOUBLE "double" #define VEC2 "glm::tvec2" @@ -25,31 +27,31 @@ #define KERNEL_MUST_VEC3 "Kernel must be of cell type glm::tvec3" #define KERNEL_MUST_VEC4 "Kernel must be of cell type glm::tvec4" -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_SCALAR BUT_IS VEC2 DOT_AT -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_SCALAR BUT_IS VEC3 DOT_AT -#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_SCALAR BUT_IS VEC4 DOT_AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC2 IDF KERNEL_MUST_SCALAR BUT_IS VEC2 DOT_AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC3 IDF KERNEL_MUST_SCALAR BUT_IS VEC3 DOT_AT +#define SCALAR_KERNEL_CELLTYPE_MATCH_VEC4 IDF KERNEL_MUST_SCALAR BUT_IS VEC4 DOT_AT -#define VEC2_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 BUT_IS FLOAT DOT_AT -#define VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 BUT_IS DOUBLE DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_FLOAT IDF KERNEL_MUST_VEC2 BUT_IS FLOAT DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE IDF KERNEL_MUST_VEC2 BUT_IS DOUBLE DOT_AT -#define VEC2_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC2 BUT_IS VEC3 DOT_AT -#define VEC2_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC2 BUT_IS VEC4 DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC3 IDF KERNEL_MUST_VEC2 BUT_IS VEC3 DOT_AT +#define VEC2_KERNEL_CELLTYPE_MATCH_VEC4 IDF KERNEL_MUST_VEC2 BUT_IS VEC4 DOT_AT -#define VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC3 BUT_IS FLOAT DOT_AT -#define VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC3 BUT_IS DOUBLE DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_FLOAT IDF KERNEL_MUST_VEC3 BUT_IS FLOAT DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE IDF KERNEL_MUST_VEC3 BUT_IS DOUBLE DOT_AT -#define VEC3_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC3 BUT_IS VEC2 DOT_AT -#define VEC3_KERNEL_CELLTYPE_MATCH_VEC4 KERNEL_MUST_VEC3 BUT_IS VEC4 DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC2 IDF KERNEL_MUST_VEC3 BUT_IS VEC2 DOT_AT +#define VEC3_KERNEL_CELLTYPE_MATCH_VEC4 IDF KERNEL_MUST_VEC3 BUT_IS VEC4 DOT_AT -#define VEC4_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC4 BUT_IS FLOAT DOT_AT -#define VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC4 BUT_IS DOUBLE DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_FLOAT IDF KERNEL_MUST_VEC4 BUT_IS FLOAT DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE IDF KERNEL_MUST_VEC4 BUT_IS DOUBLE DOT_AT -#define VEC4_KERNEL_CELLTYPE_MATCH_VEC2 KERNEL_MUST_VEC4 BUT_IS VEC2 DOT_AT -#define VEC4_KERNEL_CELLTYPE_MATCH_VEC3 KERNEL_MUST_VEC4 BUT_IS VEC3 DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC2 IDF KERNEL_MUST_VEC4 BUT_IS VEC2 DOT_AT +#define VEC4_KERNEL_CELLTYPE_MATCH_VEC3 IDF KERNEL_MUST_VEC4 BUT_IS VEC3 DOT_AT -#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT KERNEL_MUST_VEC2 " or " VEC3 BUT_IS FLOAT DOT_AT -#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE KERNEL_MUST_VEC2 " or " BUT_IS DOUBLE DOT_AT +#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT IDF KERNEL_MUST_VEC2 " or " VEC3 BUT_IS FLOAT DOT_AT +#define VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE IDF KERNEL_MUST_VEC2 " or " BUT_IS DOUBLE DOT_AT @@ -58,44 +60,66 @@ #define PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE PARAMS_MUST_EQUAL_KERNELTYPE "component type" #define PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE PARAMS_MUST_EQUAL_KERNELTYPE "component- or cell type" -#define PARAMS_EQUAL_MATCH_FLOAT PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT -#define PARAMS_EQUAL_MATCH_DOUBLE PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT +#define PARAMS_EQUAL_MATCH_FLOAT IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT + +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC2 DOT_AT +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC3 DOT_AT +#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC4 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC2 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC3 DOT_AT +#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4 IDF PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC4 DOT_AT + + + + +#define ARGUMENTS_MUST_EQUAL IDF "Types of arguments must be equal" DOT_AT + + + + +#define PARAMS_MUST_KERNEL_COMPONENTTYPE "Type(s) of kernel parameter(s) must match kernel component type" +#define PARAMS_MATCH_FLOAT IDF PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT +#define PARAMS_MATCH_DOUBLE IDF PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT + +#define PARAMS_MUST_KERNEL_CELLTYPE "Type(s) of kernel parameter(s) must match kernel cell type" +#define PARAMS_MATCH_VEC2 IDF PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC2 DOT_AT +#define PARAMS_MATCH_VEC3 IDF PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC3 DOT_AT +#define PARAMS_MATCH_VEC4 IDF PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC4 DOT_AT + + -#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC2 DOT_AT -#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC3 DOT_AT -#define PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE FLOAT " and " VEC4 DOT_AT -#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC2 DOT_AT -#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC3 DOT_AT -#define PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4 PARAMS_MUST_EQUAL_KERNEL_COMPONENTTYPE_OR_CELLTYPE WHICH_ARE DOUBLE " and " VEC4 DOT_AT +#define PARAM_MUST_KERNEL_FLOAT "Type of kernel parameter must match kernel component type (which is " FLOAT ")" +#define PARAM_MUST_KERNEL_DOUBLE "Type of kernel parameter must match kernel component type (which is " DOUBLE ")" +#define FLOAT_PARAM_MATCH_VEC2 IDF PARAM_MUST_KERNEL_FLOAT BUT_IS VEC2 DOT_AT +#define FLOAT_PARAM_MATCH_VEC3 IDF PARAM_MUST_KERNEL_FLOAT BUT_IS VEC3 DOT_AT +#define FLOAT_PARAM_MATCH_VEC4 IDF PARAM_MUST_KERNEL_FLOAT BUT_IS VEC4 DOT_AT +#define DOUBLE_PARAM_MATCH_VEC2 IDF PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC2 DOT_AT +#define DOUBLE_PARAM_MATCH_VEC3 IDF PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC3 DOT_AT +#define DOUBLE_PARAM_MATCH_VEC4 IDF PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC4 DOT_AT -#define PARAMS_MUST_KERNEL_COMPONENTTYPE "Component type of kernel parameter(s) must match kernel component type" -#define PARAMS_MATCH_FLOAT PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS FLOAT DOT_AT -#define PARAMS_MATCH_DOUBLE PARAMS_MUST_KERNEL_COMPONENTTYPE WHICH_IS DOUBLE DOT_AT -#define PARAMS_MUST_KERNEL_CELLTYPE "Cell type of kernel parameter(s) must match kernel cell type" -#define PARAMS_MATCH_VEC2 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC2 DOT_AT -#define PARAMS_MATCH_VEC3 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC3 DOT_AT -#define PARAMS_MATCH_VEC4 PARAMS_MUST_KERNEL_CELLTYPE WHICH_IS VEC4 DOT_AT +#define PARAM_MUST_KERNEL_VEC2 "Type of kernel parameter must match kernel cell type (which is " VEC2 ")" +#define PARAM_MUST_KERNEL_VEC3 "Type of kernel parameter must match kernel cell type (which is " VEC3 ")" +#define PARAM_MUST_KERNEL_VEC4 "Type of kernel parameter must match kernel cell type (which is " VEC4 ")" -#define PARAM_MUST_KERNEL_FLOAT "Component type of kernel parameter must match kernel component type" WHICH_IS FLOAT -#define PARAM_MUST_KERNEL_DOUBLE "Component type of kernel parameter must match kernel component type" WHICH_IS DOUBLE +#define VEC2_PARAM_MATCH_FLOAT IDF PARAM_MUST_KERNEL_VEC2 BUT_IS FLOAT DOT_AT +#define VEC2_PARAM_MATCH_DOUBLE IDF PARAM_MUST_KERNEL_VEC2 BUT_IS DOUBLE DOT_AT -#define FLOAT_PARAM_MATCH_VEC2 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC2 DOT_AT -#define FLOAT_PARAM_MATCH_VEC3 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC3 DOT_AT -#define FLOAT_PARAM_MATCH_VEC4 PARAM_MUST_KERNEL_FLOAT BUT_IS VEC4 DOT_AT +#define VEC3_PARAM_MATCH_FLOAT IDF PARAM_MUST_KERNEL_VEC3 BUT_IS FLOAT DOT_AT +#define VEC3_PARAM_MATCH_DOUBLE IDF PARAM_MUST_KERNEL_VEC3 BUT_IS DOUBLE DOT_AT -#define DOUBLE_PARAM_MATCH_VEC2 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC2 DOT_AT -#define DOUBLE_PARAM_MATCH_VEC3 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC3 DOT_AT -#define DOUBLE_PARAM_MATCH_VEC4 PARAM_MUST_KERNEL_DOUBLE BUT_IS VEC4 DOT_AT +#define VEC4_PARAM_MATCH_FLOAT IDF PARAM_MUST_KERNEL_VEC4 BUT_IS FLOAT DOT_AT +#define VEC4_PARAM_MATCH_DOUBLE IDF PARAM_MUST_KERNEL_VEC4 BUT_IS DOUBLE DOT_AT -#define NOT_VEC2_KERNEL_CELLTYPE "Kernel of type glm::tvec2 is not supported!" -#define NOT_VEC3_KERNEL_CELLTYPE "Kernel of type glm::tvec3 is not supported!" -#define NOT_VEC4_KERNEL_CELLTYPE "Kernel of type glm::tvec4 is not supported!" +#define NOT_VEC2_KERNEL_CELLTYPE IDF "Kernel of type glm::tvec2 is not supported!" +#define NOT_VEC3_KERNEL_CELLTYPE IDF "Kernel of type glm::tvec3 is not supported!" +#define NOT_VEC4_KERNEL_CELLTYPE IDF "Kernel of type glm::tvec4 is not supported!" diff --git a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp index 4bf7937..421d6eb 100644 --- a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -75,25 +75,4 @@ constexpr bool isComponentType() { return is_componenType::value; } -template -struct is_templateTemplate : std::false_type {}; - -template class V> -struct is_templateTemplate> : std::true_type {}; - -template class V> -constexpr bool isTemplateTemplate() { return is_templateTemplate>::value; } - -template class V> -constexpr bool isPureTemplate() { return !is_templateTemplate>::value; } - -template -constexpr bool isTemplateTemplate() { return is_templateTemplate::value; } - -template -constexpr bool isPureTemplate() { return !is_templateTemplate::value; } - - - - } // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/sequence_generalized.h b/source/glkernel/include/glkernel-generalizations/sequence_generalized.h new file mode 100644 index 0000000..efed252 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sequence_generalized.h @@ -0,0 +1,62 @@ +#pragma once + +#include + +#include + + +namespace glkernel +{ + + +namespace sequence +{ + + + + +template class V> +void uniform(tkernel &, const T2, const T3); + + +template class V> +void uniform(tkernel &, const V &, const T3); + +template class V> +void uniform(tkernel &, const T2, const V &); + + +template class V> +void uniform(tkernel> &, const T2, const T3); + + +template class V1, template class V2> +void uniform(tkernel> &, const V2 &, const T3); + +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &); + + +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &); + + + + +} // namespace sequence + + +} // namespace glkernel + + +#include "sequence_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp new file mode 100644 index 0000000..88a6286 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include "sequence_generalized.h" +#include "AssertionMacros.h" +#include + + +namespace glkernel +{ + + +namespace sequence +{ + + + + +template +void uniform(tkernel &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V> +void uniform(tkernel &, const V &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + +template class V> +void uniform(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); +} + + +template class V> +void uniform(tkernel> &, const T2, const T3) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); +} + + +template class V1, template class V2> +void uniform(tkernel> &, const V2 &, const T3) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); +} + + +template class V1, template class V2, template class V3> +void uniform(tkernel> &, const V2 &, const V3 &) +{ + ASSERT_COMPONENTTYPE_EQUALITY(T1, T2, T3); + ASSERT_CELLTYPE_EQUALITY(V1, V2, V3); +} + + + + +} // namespace sequence + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h new file mode 100644 index 0000000..ed9165a --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include + + +namespace glkernel +{ + + +namespace shuffle +{ + + + + +} // namespace shuffle + + +} // namespace glkernel + + +#include "shuffle_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/shuffle_generalized.hpp b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.hpp new file mode 100644 index 0000000..99b4d87 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "shuffle_generalized.h" +#include "AssertionMacros.h" +#include + + +namespace glkernel +{ + + +namespace shuffle +{ + + + + +} // namespace shuffle + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel-generalizations/sort_generalized.h b/source/glkernel/include/glkernel-generalizations/sort_generalized.h new file mode 100644 index 0000000..dd98687 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.h @@ -0,0 +1,53 @@ +#pragma once + +#include + +#include + + +namespace glkernel +{ + + +namespace sort +{ + + + + +template +void distance(tkernel &, const T2 &); + + + + +//template +//void distance(tkernel &, const T2); + + +//template class V> +//void distance(tkernel &, const V &); + + + + +//template class V1, template class V2> +//void distance(tkernel> &, const V2 &); + + +//template class V> +//void distance(tkernel> &, const T2); + + + + +} // namespace sort + + +} // namespace glkernel + + +#include "sort_generalized.hpp" diff --git a/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp new file mode 100644 index 0000000..dcf340f --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include "sort_generalized.h" +#include "AssertionMacros.h" +#include + + +namespace glkernel +{ + + +namespace sort +{ + + + + +template +void distance(tkernel &, const T2 &) +{ + ASSERT_TYPE_EQUALITY(T1, T2); +} + + + + +//template +//void distance(tkernel &, const T2) +//{ +// ASSERT_COMPONENTTYPE_EQUALITY(T1, T2); +//} + + +//template class V> +//void distance(tkernel &, const V &) +//{ +// FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V); +//} + + + + +//template class V1, template class V2> +//void distance(tkernel> &, const V2 &) +//{ +// ASSERT_CELLTYPE_EQUALITY(V1, V2); +// ASSERT_COMPONENTTYPE_EQUALITY(T1, T2); +//} + + +//template class V> +//void distance(tkernel> &, const T2) +//{ +// FAIL_ON_PARAM_ASSUMING_CELLTYPE(V, T2) +//} + + + + +} // namespace sort + + +} // namespace glkernel diff --git a/source/glkernel/include/glkernel/sequence.h b/source/glkernel/include/glkernel/sequence.h index b837b20..243e174 100644 --- a/source/glkernel/include/glkernel/sequence.h +++ b/source/glkernel/include/glkernel/sequence.h @@ -31,3 +31,5 @@ void uniform(tkernel> & kernel, const V & range_min, const V #include + +#include diff --git a/source/glkernel/include/glkernel/shuffle.h b/source/glkernel/include/glkernel/shuffle.h index 28b775f..db7dc69 100644 --- a/source/glkernel/include/glkernel/shuffle.h +++ b/source/glkernel/include/glkernel/shuffle.h @@ -38,3 +38,5 @@ void random(tkernel & kernel, size_t start = 1); #include + +#include diff --git a/source/glkernel/include/glkernel/sort.h b/source/glkernel/include/glkernel/sort.h index 743757a..2122723 100644 --- a/source/glkernel/include/glkernel/sort.h +++ b/source/glkernel/include/glkernel/sort.h @@ -25,3 +25,5 @@ void distance(tkernel & kernel, const T & origin); #include + +#include diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt index 4b5cc71..0d4dac0 100644 --- a/source/tests/glkernel-will_fail_tests/CMakeLists.txt +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -127,80 +127,103 @@ function(add_own_test scope name idx) WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # Expect these tests to fail (i.e. cmake --build should return # a non-zero value) - set_tests_properties(${target} PROPERTIES PASS_REGULAR_EXPRESSION "static assertion failed") + set_tests_properties(${target} PROPERTIES PASS_REGULAR_EXPRESSION "Kernel Template Error") endif() endfunction() -add_own_test(noise normal 1) -add_own_test(noise normal 2) -add_own_test(noise normal 3) -add_own_test(noise normal 4) -add_own_test(noise normal 5) -add_own_test(noise normal 6) -add_own_test(noise normal 7) -add_own_test(noise normal 8) -add_own_test(noise normal 9) -add_own_test(noise normal 10) -add_own_test(noise normal 11) -add_own_test(noise normal 12) -add_own_test(noise normal 13) -add_own_test(noise normal 14) - -add_own_test(noise uniform 1) -add_own_test(noise uniform 2) -add_own_test(noise uniform 3) -add_own_test(noise uniform 4) -add_own_test(noise uniform 5) -add_own_test(noise uniform 6) -add_own_test(noise uniform 7) -add_own_test(noise uniform 8) -add_own_test(noise uniform 9) -add_own_test(noise uniform 10) -add_own_test(noise uniform 11) -add_own_test(noise uniform 12) -add_own_test(noise uniform 13) -add_own_test(noise uniform 14) - -add_own_test(noise gradient 1) - - -add_own_test(sample poisson_square 1) -add_own_test(sample poisson_square 2) -add_own_test(sample poisson_square 3) -add_own_test(sample poisson_square 4) -add_own_test(sample poisson_square 5) -add_own_test(sample poisson_square 6) -add_own_test(sample poisson_square 7) -add_own_test(sample poisson_square 8) -add_own_test(sample poisson_square 9) - -add_own_test(sample stratified 1) -add_own_test(sample hammersley 1) -add_own_test(sample hammersley 2) -add_own_test(sample halton 1) -add_own_test(sample halton 2) -add_own_test(sample hammersley_sphere 1) -add_own_test(sample hammersley_sphere 2) -add_own_test(sample halton_sphere 1) -add_own_test(sample halton_sphere 2) -add_own_test(sample best_candidate 1) -add_own_test(sample best_candidate 2) -add_own_test(sample nrooks 1) -add_own_test(sample nrooks 2) -add_own_test(sample multi_jittered 1) -add_own_test(sample multi_jittered 2) -add_own_test(sample golden_point_set 1) -add_own_test(sample golden_point_set 2) - - -add_own_test(scale range 1) -add_own_test(scale range 2) -add_own_test(scale range 3) -add_own_test(scale range 4) -add_own_test(scale range 5) -add_own_test(scale range 6) -add_own_test(scale range 7) -add_own_test(scale range 8) +#add_own_test(noise normal 1) +#add_own_test(noise normal 2) +#add_own_test(noise normal 3) +#add_own_test(noise normal 4) +#add_own_test(noise normal 5) +#add_own_test(noise normal 6) +#add_own_test(noise normal 7) +#add_own_test(noise normal 8) +#add_own_test(noise normal 9) +#add_own_test(noise normal 10) +#add_own_test(noise normal 11) +#add_own_test(noise normal 12) +#add_own_test(noise normal 13) +#add_own_test(noise normal 14) + +#add_own_test(noise uniform 1) +#add_own_test(noise uniform 2) +#add_own_test(noise uniform 3) +#add_own_test(noise uniform 4) +#add_own_test(noise uniform 5) +#add_own_test(noise uniform 6) +#add_own_test(noise uniform 7) +#add_own_test(noise uniform 8) +#add_own_test(noise uniform 9) +#add_own_test(noise uniform 10) +#add_own_test(noise uniform 11) +#add_own_test(noise uniform 12) +#add_own_test(noise uniform 13) +#add_own_test(noise uniform 14) + +#add_own_test(noise gradient 1) + + +#add_own_test(sample poisson_square 1) +#add_own_test(sample poisson_square 2) +#add_own_test(sample poisson_square 3) +#add_own_test(sample poisson_square 4) +#add_own_test(sample poisson_square 5) +#add_own_test(sample poisson_square 6) +#add_own_test(sample poisson_square 7) +#add_own_test(sample poisson_square 8) +#add_own_test(sample poisson_square 9) + +#add_own_test(sample stratified 1) +#add_own_test(sample hammersley 1) +#add_own_test(sample hammersley 2) +#add_own_test(sample halton 1) +#add_own_test(sample halton 2) +#add_own_test(sample hammersley_sphere 1) +#add_own_test(sample hammersley_sphere 2) +#add_own_test(sample halton_sphere 1) +#add_own_test(sample halton_sphere 2) +#add_own_test(sample best_candidate 1) +#add_own_test(sample best_candidate 2) +#add_own_test(sample nrooks 1) +#add_own_test(sample nrooks 2) +#add_own_test(sample multi_jittered 1) +#add_own_test(sample multi_jittered 2) +#add_own_test(sample golden_point_set 1) +#add_own_test(sample golden_point_set 2) + + +#add_own_test(scale range 1) +#add_own_test(scale range 2) +#add_own_test(scale range 3) +#add_own_test(scale range 4) +#add_own_test(scale range 5) +#add_own_test(scale range 6) +#add_own_test(scale range 7) +#add_own_test(scale range 8) + +#add_own_test(sequence uniform 1) +#add_own_test(sequence uniform 2) +#add_own_test(sequence uniform 3) +#add_own_test(sequence uniform 4) +#add_own_test(sequence uniform 5) +#add_own_test(sequence uniform 6) +#add_own_test(sequence uniform 7) +#add_own_test(sequence uniform 8) +#add_own_test(sequence uniform 9) +#add_own_test(sequence uniform 10) +#add_own_test(sequence uniform 11) +#add_own_test(sequence uniform 12) +#add_own_test(sequence uniform 13) +#add_own_test(sequence uniform 14) + +add_own_test(sort distance 1) +add_own_test(sort distance 2) +add_own_test(sort distance 3) +add_own_test(sort distance 4) +add_own_test(sort distance 5) +add_own_test(sort distance 6) +add_own_test(sort distance 7) diff --git a/source/tests/glkernel-will_fail_tests/noise_fail.cpp b/source/tests/glkernel-will_fail_tests/noise_fail.cpp index 8bcd722..418ef86 100644 --- a/source/tests/glkernel-will_fail_tests/noise_fail.cpp +++ b/source/tests/glkernel-will_fail_tests/noise_fail.cpp @@ -79,5 +79,3 @@ int main() return 0; } - - diff --git a/source/tests/glkernel-will_fail_tests/sequence_fail.cpp b/source/tests/glkernel-will_fail_tests/sequence_fail.cpp new file mode 100644 index 0000000..e5aeb4f --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/sequence_fail.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +#include +#include + +#include + +int main() +{ + auto fkernel1 = glkernel::kernel1{ 1 }; + auto fkernel2 = glkernel::kernel2{ 1 }; + + auto dkernel1 = glkernel::dkernel1{ 1 }; + auto dkernel2 = glkernel::dkernel2{ 1 }; + + +#if defined SEQUENCE_UNIFORM_1 + glkernel::sequence::uniform(fkernel1, 0.0f, 1.0); +#elif defined SEQUENCE_UNIFORM_2 + glkernel::sequence::uniform(fkernel1, glm::vec2{ 0.0 }, 1.0f); +#elif defined SEQUENCE_UNIFORM_3 + glkernel::sequence::uniform(fkernel1, 0.0f, glm::vec2{ 0.0 }); +#elif defined SEQUENCE_UNIFORM_4 + glkernel::sequence::uniform(fkernel2, 0.0f, 1.0); +#elif defined SEQUENCE_UNIFORM_5 + glkernel::sequence::uniform(fkernel2, glm::vec2{ 0.0 }, 1.0f); +#elif defined SEQUENCE_UNIFORM_6 + glkernel::sequence::uniform(fkernel2, 0.0f, glm::vec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_7 + glkernel::sequence::uniform(fkernel2, glm::dvec2{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_8 + glkernel::sequence::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_9 + glkernel::sequence::uniform(fkernel2, glm::vec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_10 + glkernel::sequence::uniform(fkernel2, glm::vec2{ 0.0 }, glm::vec3{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_11 + glkernel::sequence::uniform(fkernel2, glm::dvec3{ 0.0 }, glm::vec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_12 + glkernel::sequence::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_13 + glkernel::sequence::uniform(fkernel2, glm::vec3{ 0.0 }, glm::dvec2{ 1.0 }); +#elif defined SEQUENCE_UNIFORM_14 + glkernel::sequence::uniform(fkernel2, glm::vec2{ 0.0 }, glm::dvec3{ 1.0 }); +#endif + + + return 0; +} diff --git a/source/tests/glkernel-will_fail_tests/shuffle_fail.cpp b/source/tests/glkernel-will_fail_tests/shuffle_fail.cpp new file mode 100644 index 0000000..b8f92fb --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/shuffle_fail.cpp @@ -0,0 +1,13 @@ +#include +#include +#include + +#include +#include + +#include + +int main() +{ + return 0; +} diff --git a/source/tests/glkernel-will_fail_tests/sort_fail.cpp b/source/tests/glkernel-will_fail_tests/sort_fail.cpp new file mode 100644 index 0000000..5030181 --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/sort_fail.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +#include +#include + +#include + +int main() +{ + auto fkernel1 = glkernel::kernel1{ 1 }; + auto fkernel2 = glkernel::kernel2{ 1 }; + + auto dkernel1 = glkernel::dkernel1{ 1 }; + auto dkernel2 = glkernel::dkernel2{ 1 }; + + +#if defined SORT_DISTANCE_1 + glkernel::sort::distance(fkernel1, 0.5); +#elif defined SORT_DISTANCE_2 + glkernel::sort::distance(fkernel1, glm::vec3{ 0.5 }); +#elif defined SORT_DISTANCE_3 + glkernel::sort::distance(fkernel2, 0.5f); +#elif defined SORT_DISTANCE_4 + glkernel::sort::distance(fkernel2, 0.5); +#elif defined SORT_DISTANCE_5 + glkernel::sort::distance(fkernel2, glm::dvec2{ 0.5 }); +#elif defined SORT_DISTANCE_6 + glkernel::sort::distance(fkernel2, glm::vec3{ 0.5 }); +#elif defined SORT_DISTANCE_7 + glkernel::sort::distance(fkernel2, glm::dvec3{ 0.5 }); +#endif + + + return 0; +} From 8c19908d972cbc6a34e798986fdb5d4b9ef59e9b Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 5 Mar 2018 10:59:39 +0100 Subject: [PATCH 05/10] compile errors and tests: uncommented all tests --- .../glkernel-will_fail_tests/CMakeLists.txt | 170 +++++++++--------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt index 0d4dac0..481e0f3 100644 --- a/source/tests/glkernel-will_fail_tests/CMakeLists.txt +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -134,91 +134,91 @@ endfunction() -#add_own_test(noise normal 1) -#add_own_test(noise normal 2) -#add_own_test(noise normal 3) -#add_own_test(noise normal 4) -#add_own_test(noise normal 5) -#add_own_test(noise normal 6) -#add_own_test(noise normal 7) -#add_own_test(noise normal 8) -#add_own_test(noise normal 9) -#add_own_test(noise normal 10) -#add_own_test(noise normal 11) -#add_own_test(noise normal 12) -#add_own_test(noise normal 13) -#add_own_test(noise normal 14) - -#add_own_test(noise uniform 1) -#add_own_test(noise uniform 2) -#add_own_test(noise uniform 3) -#add_own_test(noise uniform 4) -#add_own_test(noise uniform 5) -#add_own_test(noise uniform 6) -#add_own_test(noise uniform 7) -#add_own_test(noise uniform 8) -#add_own_test(noise uniform 9) -#add_own_test(noise uniform 10) -#add_own_test(noise uniform 11) -#add_own_test(noise uniform 12) -#add_own_test(noise uniform 13) -#add_own_test(noise uniform 14) - -#add_own_test(noise gradient 1) - - -#add_own_test(sample poisson_square 1) -#add_own_test(sample poisson_square 2) -#add_own_test(sample poisson_square 3) -#add_own_test(sample poisson_square 4) -#add_own_test(sample poisson_square 5) -#add_own_test(sample poisson_square 6) -#add_own_test(sample poisson_square 7) -#add_own_test(sample poisson_square 8) -#add_own_test(sample poisson_square 9) - -#add_own_test(sample stratified 1) -#add_own_test(sample hammersley 1) -#add_own_test(sample hammersley 2) -#add_own_test(sample halton 1) -#add_own_test(sample halton 2) -#add_own_test(sample hammersley_sphere 1) -#add_own_test(sample hammersley_sphere 2) -#add_own_test(sample halton_sphere 1) -#add_own_test(sample halton_sphere 2) -#add_own_test(sample best_candidate 1) -#add_own_test(sample best_candidate 2) -#add_own_test(sample nrooks 1) -#add_own_test(sample nrooks 2) -#add_own_test(sample multi_jittered 1) -#add_own_test(sample multi_jittered 2) -#add_own_test(sample golden_point_set 1) -#add_own_test(sample golden_point_set 2) - - -#add_own_test(scale range 1) -#add_own_test(scale range 2) -#add_own_test(scale range 3) -#add_own_test(scale range 4) -#add_own_test(scale range 5) -#add_own_test(scale range 6) -#add_own_test(scale range 7) -#add_own_test(scale range 8) - -#add_own_test(sequence uniform 1) -#add_own_test(sequence uniform 2) -#add_own_test(sequence uniform 3) -#add_own_test(sequence uniform 4) -#add_own_test(sequence uniform 5) -#add_own_test(sequence uniform 6) -#add_own_test(sequence uniform 7) -#add_own_test(sequence uniform 8) -#add_own_test(sequence uniform 9) -#add_own_test(sequence uniform 10) -#add_own_test(sequence uniform 11) -#add_own_test(sequence uniform 12) -#add_own_test(sequence uniform 13) -#add_own_test(sequence uniform 14) +add_own_test(noise normal 1) +add_own_test(noise normal 2) +add_own_test(noise normal 3) +add_own_test(noise normal 4) +add_own_test(noise normal 5) +add_own_test(noise normal 6) +add_own_test(noise normal 7) +add_own_test(noise normal 8) +add_own_test(noise normal 9) +add_own_test(noise normal 10) +add_own_test(noise normal 11) +add_own_test(noise normal 12) +add_own_test(noise normal 13) +add_own_test(noise normal 14) + +add_own_test(noise uniform 1) +add_own_test(noise uniform 2) +add_own_test(noise uniform 3) +add_own_test(noise uniform 4) +add_own_test(noise uniform 5) +add_own_test(noise uniform 6) +add_own_test(noise uniform 7) +add_own_test(noise uniform 8) +add_own_test(noise uniform 9) +add_own_test(noise uniform 10) +add_own_test(noise uniform 11) +add_own_test(noise uniform 12) +add_own_test(noise uniform 13) +add_own_test(noise uniform 14) + +add_own_test(noise gradient 1) + + +add_own_test(sample poisson_square 1) +add_own_test(sample poisson_square 2) +add_own_test(sample poisson_square 3) +add_own_test(sample poisson_square 4) +add_own_test(sample poisson_square 5) +add_own_test(sample poisson_square 6) +add_own_test(sample poisson_square 7) +add_own_test(sample poisson_square 8) +add_own_test(sample poisson_square 9) + +add_own_test(sample stratified 1) +add_own_test(sample hammersley 1) +add_own_test(sample hammersley 2) +add_own_test(sample halton 1) +add_own_test(sample halton 2) +add_own_test(sample hammersley_sphere 1) +add_own_test(sample hammersley_sphere 2) +add_own_test(sample halton_sphere 1) +add_own_test(sample halton_sphere 2) +add_own_test(sample best_candidate 1) +add_own_test(sample best_candidate 2) +add_own_test(sample nrooks 1) +add_own_test(sample nrooks 2) +add_own_test(sample multi_jittered 1) +add_own_test(sample multi_jittered 2) +add_own_test(sample golden_point_set 1) +add_own_test(sample golden_point_set 2) + + +add_own_test(scale range 1) +add_own_test(scale range 2) +add_own_test(scale range 3) +add_own_test(scale range 4) +add_own_test(scale range 5) +add_own_test(scale range 6) +add_own_test(scale range 7) +add_own_test(scale range 8) + +add_own_test(sequence uniform 1) +add_own_test(sequence uniform 2) +add_own_test(sequence uniform 3) +add_own_test(sequence uniform 4) +add_own_test(sequence uniform 5) +add_own_test(sequence uniform 6) +add_own_test(sequence uniform 7) +add_own_test(sequence uniform 8) +add_own_test(sequence uniform 9) +add_own_test(sequence uniform 10) +add_own_test(sequence uniform 11) +add_own_test(sequence uniform 12) +add_own_test(sequence uniform 13) +add_own_test(sequence uniform 14) add_own_test(sort distance 1) add_own_test(sort distance 2) From a0bc591556dc0e5d3d41b7fb7cfb2b12c25a187d Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Tue, 6 Mar 2018 09:53:24 +0100 Subject: [PATCH 06/10] documentation block in header files of generalized methods --- .../noise_generalized.h | 15 +++++--- .../noise_generalized.hpp | 6 +--- .../sample_generalized.h | 9 +++++ .../scale_generalized.h | 9 +++++ .../sequence_generalized.h | 9 +++++ .../shuffle_generalized.h | 9 +++++ .../sort_generalized.h | 32 +++++------------ .../sort_generalized.hpp | 36 ------------------- 8 files changed, 56 insertions(+), 69 deletions(-) diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.h b/source/glkernel/include/glkernel-generalizations/noise_generalized.h index 3c214e0..ecf3d58 100644 --- a/source/glkernel/include/glkernel-generalizations/noise_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.h @@ -5,6 +5,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::noise +* that exist in parallel to the ones in noise.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { @@ -89,11 +98,7 @@ void normal(tkernel> &, const V2 &, const V3 &); template class V> -void gradient(tkernel> & - , const GradientNoiseType = GradientNoiseType::Perlin - , const OctaveType = OctaveType::Standard - , const unsigned int = 3 - , const unsigned int = 5); +void gradient(tkernel> &, const GradientNoiseType = GradientNoiseType::Perlin, const OctaveType = OctaveType::Standard, const unsigned int = 3, const unsigned int = 5); diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp index 5627c8d..ff0ee68 100644 --- a/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp @@ -132,11 +132,7 @@ void normal(tkernel> &, const V2 &, const V3 &) template class V> -void gradient(tkernel> & - , const GradientNoiseType - , const OctaveType - , const unsigned int - , const unsigned int) +void gradient(tkernel> &, const GradientNoiseType, const OctaveType, const unsigned int, const unsigned int) { FAIL_ON_VECTORIAL_KERNEL_CELLTYPE_ASSUMING_SCALAR(V); } diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.h b/source/glkernel/include/glkernel-generalizations/sample_generalized.h index f57e253..bab28d4 100644 --- a/source/glkernel/include/glkernel-generalizations/sample_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.h @@ -6,6 +6,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::sample +* that exist in parallel to the ones in sample.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { diff --git a/source/glkernel/include/glkernel-generalizations/scale_generalized.h b/source/glkernel/include/glkernel-generalizations/scale_generalized.h index 9e045db..25d4002 100644 --- a/source/glkernel/include/glkernel-generalizations/scale_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.h @@ -5,6 +5,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::scale +* that exist in parallel to the ones in scale.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { diff --git a/source/glkernel/include/glkernel-generalizations/sequence_generalized.h b/source/glkernel/include/glkernel-generalizations/sequence_generalized.h index efed252..d1dde93 100644 --- a/source/glkernel/include/glkernel-generalizations/sequence_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/sequence_generalized.h @@ -5,6 +5,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::sequence +* that exist in parallel to the ones in sequence.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { diff --git a/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h index ed9165a..8cf10ef 100644 --- a/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h @@ -5,6 +5,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::shuffle +* that exist in parallel to the ones in shuffle.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { diff --git a/source/glkernel/include/glkernel-generalizations/sort_generalized.h b/source/glkernel/include/glkernel-generalizations/sort_generalized.h index dd98687..43d11ab 100644 --- a/source/glkernel/include/glkernel-generalizations/sort_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.h @@ -5,6 +5,15 @@ #include +/* +* This file contains further overloaded methods of the namespace glkernel::sort +* that exist in parallel to the ones in sort.h. +* These methods feature generalized signatures that are intented to match all the +* prohibited calls. This way, calling a method with wrong arguments does not result +* in a template deduction failure, but instead gives specific and verbose error messages. +*/ + + namespace glkernel { @@ -21,29 +30,6 @@ void distance(tkernel &, const T2 &); -//template -//void distance(tkernel &, const T2); - - -//template class V> -//void distance(tkernel &, const V &); - - - - -//template class V1, template class V2> -//void distance(tkernel> &, const V2 &); - - -//template class V> -//void distance(tkernel> &, const T2); - - - - } // namespace sort diff --git a/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp index dcf340f..e64476a 100644 --- a/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp @@ -24,42 +24,6 @@ void distance(tkernel &, const T2 &) -//template -//void distance(tkernel &, const T2) -//{ -// ASSERT_COMPONENTTYPE_EQUALITY(T1, T2); -//} - - -//template class V> -//void distance(tkernel &, const V &) -//{ -// FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V); -//} - - - - -//template class V1, template class V2> -//void distance(tkernel> &, const V2 &) -//{ -// ASSERT_CELLTYPE_EQUALITY(V1, V2); -// ASSERT_COMPONENTTYPE_EQUALITY(T1, T2); -//} - - -//template class V> -//void distance(tkernel> &, const T2) -//{ -// FAIL_ON_PARAM_ASSUMING_CELLTYPE(V, T2) -//} - - - - } // namespace sort From 258c63e9496a4af9c0968897bb17ddfe9752dc74 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Tue, 6 Mar 2018 09:59:36 +0100 Subject: [PATCH 07/10] autosave changes --- .../include/glkernel-generalizations/sample_generalized.h | 2 ++ .../include/glkernel-generalizations/sample_generalized.hpp | 5 +++++ .../include/glkernel-generalizations/scale_generalized.hpp | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.h b/source/glkernel/include/glkernel-generalizations/sample_generalized.h index bab28d4..0f5e3a1 100644 --- a/source/glkernel/include/glkernel-generalizations/sample_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.h @@ -23,6 +23,8 @@ namespace sample { + + template void poisson_square(tkernel &, const unsigned int = 32); diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp index 4431079..bacd2cc 100644 --- a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp @@ -6,6 +6,7 @@ + namespace glkernel { @@ -14,6 +15,8 @@ namespace sample { + + template void poisson_square(tkernel &, const unsigned int) { @@ -199,6 +202,8 @@ void golden_point_set(tkernel> &) } + + } // namespace sample diff --git a/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp index 1bfc291..cb7aae8 100644 --- a/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp @@ -5,7 +5,6 @@ #include - namespace glkernel { From b459b8c57e5959946bcb831050c66c907387fcf5 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Mon, 19 Mar 2018 20:22:27 +0100 Subject: [PATCH 08/10] minor changes --- .../glkernel/include/glkernel-generalizations/StringMacros.h | 2 +- .../include/glkernel-generalizations/noise_generalized.h | 3 +-- .../include/glkernel-generalizations/sample_generalized.hpp | 2 -- source/tests/glkernel-will_fail_tests/CMakeLists.txt | 1 + 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/glkernel/include/glkernel-generalizations/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h index 17b6283..25e3fad 100644 --- a/source/glkernel/include/glkernel-generalizations/StringMacros.h +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -2,7 +2,7 @@ -#define IDF "Kernel Template Error: " +#define IDF ": " #define STRINGIFY(x) #x diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.h b/source/glkernel/include/glkernel-generalizations/noise_generalized.h index ecf3d58..965b0cf 100644 --- a/source/glkernel/include/glkernel-generalizations/noise_generalized.h +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.h @@ -24,8 +24,7 @@ namespace noise -template class V> +template void uniform(tkernel &, const T2, const T3); diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp index bacd2cc..d505694 100644 --- a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp @@ -52,7 +52,6 @@ void poisson_square(tkernel &, const V &, const unsigned int) { FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T1); FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V); - //FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V) } template > &, const V2 &, const unsigned int) { FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V2); - //FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V2) } diff --git a/source/tests/glkernel-will_fail_tests/CMakeLists.txt b/source/tests/glkernel-will_fail_tests/CMakeLists.txt index 481e0f3..ec237b0 100644 --- a/source/tests/glkernel-will_fail_tests/CMakeLists.txt +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -118,6 +118,7 @@ function(add_own_test scope name idx) $<$>:$<$:${OpenMP_CXX_FLAGS}>> ) + if(BUILD_TESTING) message("CTest ready for registering ${target}") # Add the tests. These invoke "cmake --build ..." which is a From 61c1618bd78800c868f141f3a2e895480b7d83c7 Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Wed, 28 Mar 2018 15:12:08 +0200 Subject: [PATCH 09/10] documentation for AssertionMacros and slight changes to underlying implementations --- .../AssertionMacros.h | 249 +++++++++--------- .../glkernel-generalizations/TypeTraits.cpp | 32 +-- .../noise_generalized.hpp | 16 +- .../sample_generalized.hpp | 4 +- .../scale_generalized.hpp | 16 +- .../sequence_generalized.hpp | 8 +- 6 files changed, 168 insertions(+), 157 deletions(-) diff --git a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h index 2196b5d..9d91a06 100644 --- a/source/glkernel/include/glkernel-generalizations/AssertionMacros.h +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -6,137 +6,146 @@ -// Asserts, that kernel is of cell type vec2. -#define ASSERT_KERNEL_CELLTYPE_VEC2(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC2_KERNEL_CELLTYPE_MATCH_VEC3); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC2_KERNEL_CELLTYPE_MATCH_VEC4); - -// Asserts, that kernel is of cell type vec3. -#define ASSERT_KERNEL_CELLTYPE_VEC3(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC3_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC3_KERNEL_CELLTYPE_MATCH_VEC4); - -// Asserts, that kernel is of cell type vec4. -#define ASSERT_KERNEL_CELLTYPE_VEC4(V) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC4_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , VEC4_KERNEL_CELLTYPE_MATCH_VEC3); - -#define ASSERT_KERNEL_CELLTYPE_NOT_VEC2(V) \ +/* + * Asserts, that kernel is of cell type glm::vec2. + */ +#define ASSERT_KERNEL_CELLTYPE_VEC2(V) \ + static_assert(!(areSameCelltype() && !areSameCelltype()), VEC2_KERNEL_CELLTYPE_MATCH_VEC3); \ + static_assert(!(areSameCelltype() && !areSameCelltype()), VEC2_KERNEL_CELLTYPE_MATCH_VEC4); + +/* + * Asserts, that kernel is of cell type glm::vec3. + */ +#define ASSERT_KERNEL_CELLTYPE_VEC3(V) \ + static_assert(!(areSameCelltype() && !areSameCelltype()), VEC3_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert(!(areSameCelltype() && !areSameCelltype()), VEC3_KERNEL_CELLTYPE_MATCH_VEC4); + +/* + * Asserts, that kernel is of cell type glm::vec4. + */ +#define ASSERT_KERNEL_CELLTYPE_VEC4(V) \ + static_assert( !(areSameCelltype() && !areSameCelltype()), VEC4_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert( !(areSameCelltype() && !areSameCelltype()), VEC4_KERNEL_CELLTYPE_MATCH_VEC3); + + +/* + * Asserts, that kernel is of a cell type anything but glm::vec2. + */ +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC2(V) \ static_assert(!areSameCelltype(), NOT_VEC2_KERNEL_CELLTYPE); -#define ASSERT_KERNEL_CELLTYPE_NOT_VEC3(V) \ +/* + * Asserts, that kernel is of a cell type anything but glm::vec3. + */ +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC3(V) \ static_assert(!areSameCelltype(), NOT_VEC3_KERNEL_CELLTYPE); -#define ASSERT_KERNEL_CELLTYPE_NOT_VEC4(V) \ +/* + * Asserts, that kernel is of a cell type anything but glm::vec4. + */ +#define ASSERT_KERNEL_CELLTYPE_NOT_VEC4(V) \ static_assert(!areSameCelltype(), NOT_VEC4_KERNEL_CELLTYPE); -// Fail, because (scalar) kernel is of some vectorial type. -#define FAIL_ON_VECTORIAL_KERNEL_CELLTYPE_ASSUMING_SCALAR(V) \ - static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC2); \ - static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC3); \ + +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when the kernel is of + * a vectorial (V: glm::vec2, glm::vec3, glm::vec4) cell type, although it should be a scalar one. + */ +#define FAIL_ON_VECTORIAL_KERNEL_CELLTYPE_ASSUMING_SCALAR(V) \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC2); \ + static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC3); \ static_assert(!areSameCelltype(), SCALAR_KERNEL_CELLTYPE_MATCH_VEC4); -// Fail, because (vec2) kernel is of some scalar type. -#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T) \ - static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_FLOAT); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when the kernel is of + * a scalar cell type (T: float, double), although it should be of cell type glm::vec2. + */ +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T) \ + static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC2_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because (vec3) kernel is of some scalar type. -#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC3(T) \ - static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when the kernel is of + * a scalar cell type (T: float, double), although it should be of cell type glm::vec3. + */ +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC3(T) \ + static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE); -// Fail, because (vec4) kernel is of some scalar type. -#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC4(T) \ - static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_FLOAT); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when the kernel is of + * a scalar cell type (T: float, double), although it should be of cell type glm::vec4. + */ +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC4(T) \ + static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC4_KERNEL_CELLTYPE_MATCH_DOUBLE); - -#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2_OR_VEC3(T) \ - static_assert(!areSameType(), VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when the kernel is of + * a scalar cell type (T: float, double), although it should be of cell type glm::vec4. + */ +#define FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2_OR_VEC3(T) \ + static_assert(!areSameType(), VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_FLOAT); \ static_assert(!areSameType(), VEC2_OR_VEC3_KERNEL_CELLTYPE_MATCH_DOUBLE); -#define ASSERT_TYPE_EQUALITY(...) \ +/* + * Asserts, that all arguments are of the same component type. + * Implicitly assumes that arguements are type template parameters of a method + * including the kernel's type template as first argument! + */ +#define ASSERT_COMPONENTTYPE_EQUALITY(T, ...) \ + static_assert( !(areSameType() && !areSameType()), PARAMS_MATCH_FLOAT); \ + static_assert( !(areSameType() && !areSameType()), PARAMS_MATCH_DOUBLE); + +/* + * Asserts, that all arguments are of the same cell type. + * Implicitly assumes that arguements are template template parameters of a method + * including the kernel's template template as first argument! + */ +#define ASSERT_CELLTYPE_EQUALITY(V, ...) \ + static_assert( !(areSameCelltype() && !areSameCelltype()), PARAMS_MATCH_VEC2); \ + static_assert( !(areSameCelltype() && !areSameCelltype()), PARAMS_MATCH_VEC3); \ + static_assert( !(areSameCelltype() && !areSameCelltype()), PARAMS_MATCH_VEC4); + +/* + * Asserts, that all arguments are of the same type. + * Implicitly assumes that arguements are type template parameters of a method + * including the kernel's type template as first argument! + * + * This version differentiates from the two beforenamed,since it does not differentiate between + * scalar cell types (specifically type template arguments) and vectorial cell types (specifically template template arguments). + * Because of that, the triggered string literals are not able to hint to concrete cell types (float, double, glm::vec2, ...). + * What seems to be worse (= less specific) than the other two options is the only way to go, if a method is templated by + * type templates only (e.g. sort::distance) mapping to both, scalar and vectorial cell types. + */ +#define ASSERT_TYPE_EQUALITY(...) \ static_assert(areSameType<__VA_ARGS__>(), ARGUMENTS_MUST_EQUAL) -// Checks if all arguments are of the same component type. -// Implicitly assumes that arguements are parameters of a method including kernel as first argument! -#define ASSERT_COMPONENTTYPE_EQUALITY(T, ...) \ - static_assert( (areSameType() && areSameType()) || \ - (!areSameType() && areSameType()) || \ - !(areSameType() && !areSameType()) || \ - (!areSameType() && !areSameType()) \ - , PARAMS_MATCH_FLOAT); \ - static_assert( (areSameType() && areSameType()) || \ - (!areSameType() && areSameType()) || \ - !(areSameType() && !areSameType()) || \ - (!areSameType() && !areSameType()) \ - , PARAMS_MATCH_DOUBLE); - -// Checks if all arguments are of the same cell type. -// Implicitly assumes that arguements are parameters of a method including kernel as first argument! -#define ASSERT_CELLTYPE_EQUALITY(V, ...) \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , PARAMS_MATCH_VEC2); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , PARAMS_MATCH_VEC3); \ - static_assert( (areSameCelltype() && areSameCelltype()) || \ - (!areSameCelltype() && areSameCelltype()) || \ - !(areSameCelltype() && !areSameCelltype()) || \ - (!areSameCelltype() && !areSameCelltype()) \ - , PARAMS_MATCH_VEC4); - - - - -// Fail, because scalar parameter (float or double) is of some vectorial celltype -#define FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T, V) \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC4); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC4); -// Fail, because vectorial parameter is of some scalar celltype -#define FAIL_ON_PARAM_ASSUMING_CELLTYPE(V, T) \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when + * a parameter is of a vectorial cell type, although it must fit to the kernel's scalar cell type. + */ +#define FAIL_ON_PARAM_ASSUMING_SCALAR(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), FLOAT_PARAM_MATCH_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), DOUBLE_PARAM_MATCH_VEC4); + +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when + * a parameter is of a scalar cell type, although it must fit to the kernel's vectorial cell type. + */ +#define FAIL_ON_PARAM_ASSUMING_VECTORIAL(V, T) \ static_assert( !(areSameCelltype() && areSameType()), VEC2_PARAM_MATCH_FLOAT); \ static_assert( !(areSameCelltype() && areSameType()), VEC2_PARAM_MATCH_DOUBLE); \ static_assert( !(areSameCelltype() && areSameType()), VEC3_PARAM_MATCH_FLOAT); \ @@ -147,20 +156,22 @@ -#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T) \ - static_assert( !areSameType(), PARAMS_EQUAL_MATCH_FLOAT); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when + * multiple parameters' types are not equal, although they must be homogeneous and fit to the kernel's scalar cell type. + */ +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T) \ + static_assert( !areSameType(), PARAMS_EQUAL_MATCH_FLOAT); \ static_assert( !areSameType(), PARAMS_EQUAL_MATCH_DOUBLE); - -#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T, V) \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2); \ - static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3); \ +/* + * The intention of this macro is to lead to a guaranteed failure, since it is supposed to be used when + * multiple parameters' types are not equal, although they must be homogeneous and fit to the kernel's vectorial cell type. + */ +#define FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T, V) \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC3); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_FLOAT_OR_VEC4); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC2); \ + static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC3); \ static_assert( !(areSameType() && areSameCelltype()), PARAMS_EQUAL_MATCH_DOUBLE_OR_VEC4); - - - - - diff --git a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp index 421d6eb..4b7f395 100644 --- a/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -47,30 +47,30 @@ constexpr bool areSameCelltype() { return are_same_celltype::value; } -template -struct is_cellType : std::false_type {}; +//template +//struct is_cellType : std::false_type {}; -template class V> -struct is_cellType> : std::true_type {}; +//template class V> +//struct is_cellType> : std::true_type {}; -template class V> -constexpr bool isCellType() { return is_cellType>::value; } +//template class V> +//constexpr bool isCellType() { return is_cellType>::value; } -template -constexpr bool isCellType() { return is_cellType::value; } +//template +//constexpr bool isCellType() { return is_cellType::value; } -template -struct is_componenType : std::true_type {}; +//template +//struct is_componenType : std::true_type {}; -template class V> -struct is_componenType> : std::false_type {}; +//template class V> +//struct is_componenType> : std::false_type {}; -template class V> -constexpr bool isComponentType() { return is_componenType>::value; } +//template class V> +//constexpr bool isComponentType() { return is_componenType>::value; } -template -constexpr bool isComponentType() { return is_componenType::value; } +//template +//constexpr bool isComponentType() { return is_componenType::value; } diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp index ff0ee68..da99202 100644 --- a/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp @@ -26,14 +26,14 @@ template class V> void uniform(tkernel &, const V &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void uniform(tkernel &, const T2, const V &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } @@ -50,7 +50,7 @@ template class V1, template class V2> void uniform(tkernel> &, const V2 &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void uniform(tkernel> &, const T2, const V2 &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } @@ -85,14 +85,14 @@ template class V> void normal(tkernel &, const V &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void normal(tkernel &, const T2, const V &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } @@ -109,7 +109,7 @@ template class V1, template class V2> void normal(tkernel> &, const V2 &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void normal(tkernel> &, const T2, const V2 &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } diff --git a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp index d505694..9b9f609 100644 --- a/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp @@ -51,7 +51,7 @@ template &, const V &, const unsigned int) { FAIL_ON_SCALAR_KERNEL_CELLTYPE_ASSUMING_VEC2(T1); - FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V); + FAIL_ON_PARAM_ASSUMING_SCALAR(T1, V); } template class V1, template class V2> void poisson_square(tkernel> &, const V2 &, const unsigned int) { - FAIL_ON_PARAM_ASSUMING_COMPONENTTYPE(T1, V2); + FAIL_ON_PARAM_ASSUMING_SCALAR(T1, V2); } diff --git a/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp index cb7aae8..6990552 100644 --- a/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp @@ -26,28 +26,28 @@ template class V> void range(tkernel &, const V &, T3, T4, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void range(tkernel &, T2, const V &, T4, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void range(tkernel &, T2, T3, const V &, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void range(tkernel &, T2, T3, T4, const V &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } @@ -63,28 +63,28 @@ template class V1, template class V2> void range(tkernel> &, const V2 &, T3, T4, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void range(tkernel> &, T2, const V2 &, T4, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void range(tkernel> &, T2, T3, const V2 &, T5) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void range(tkernel> &, T2, T3, T4, const V2 &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } diff --git a/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp b/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp index 88a6286..9cdaf20 100644 --- a/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp +++ b/source/glkernel/include/glkernel-generalizations/sequence_generalized.hpp @@ -26,14 +26,14 @@ template class V> void uniform(tkernel &, const V &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } template class V> void uniform(tkernel &, const T2, const V &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE(T1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); } @@ -50,7 +50,7 @@ template class V1, template class V2> void uniform(tkernel> &, const V2 &, const T3) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } template class V1, template class V2> void uniform(tkernel> &, const T2, const V2 &) { - FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_COMPONENTTYPE_OR_CELLTYPE(T1, V1); + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); } From a8b8002412801a575de6c4347d914944d046ea3a Mon Sep 17 00:00:00 2001 From: Raphael Badel Date: Wed, 28 Mar 2018 15:17:21 +0200 Subject: [PATCH 10/10] extended readme according to the new compile time error messages --- README.md | 259 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 162 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 537f896..3210a37 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,162 @@ -# glkernel -C++ library for pre-computing noise, and random sample-kernels. - -## Project Health (master) - -| Service | System | Compiler | Targets | Status | -| ------- | ------ | -------- | ------- | ------ | -| Jenkins | Ubuntu 14.04 | GCC 4.8 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc4.8)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc4.8)| -| Jenkins | Ubuntu 14.04 | GCC 4.9 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc4.9)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc4.9)| -| Jenkins | Ubuntu 14.04 | GCC 5.3 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc5.3)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc5.3)| -| Jenkins | Ubuntu 14.04 | Clang 3.5 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-clang3.5)](http://jenkins.hpi3d.de/job/glkernel-linux-clang3.5) | -| Jenkins | Windows 8.1 | MSVC 2013 Update 5 | all, test, install | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-windows-msvc2013)](http://jenkins.hpi3d.de/job/glkernel-windows-msvc2013) | -| Jenkins | Windows 8.1 | MSVC 2015 Update 1 | all, test, install | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-windows-msvc2015)](http://jenkins.hpi3d.de/job/glkernel-windows-msvc2015) | - -## Features - -ToDo - -##### Feature - -ToDo - -## Using glkernel - -ToDo - -##### Dependencies - -ToDo - -##### Linking binaries - -ToDo - -##### glkernel-cmd - -Additionally to using glkernel as a library, there is a standalone command line tool to generate kernels from JSON descriptions. -The usage is as follows: ```glkernel-cmd --i {input filename} --o {output filename}```, where ```{input filename}``` is a JSON kernel description file and ```{output file}``` is a JSON file containing a kernel. - -The description file must contain an entry "init-kernel" that describes the size and the number of components of the the kernel that will be generated. -It also has to contain an entry "commands", which is an array of commands that will be executed on the kernel. -For these, all glkernel commands can be used. - -The naming convention for applying glkernel commands is ```"{namespace}.{function name}"```, e.g. ```"noise.uniform"``` for ```noise::uniform```. -Arguments can be passed as a JSON object, e.g. ```{ "noise.uniform": { "range_min": -1.0, "range_max": 1.0 } }``` will call ```noise::uniform(kernel, -1.0, 1.0)```. - -Here is an input JSON for generating 4 samples using golden point set sampling, scaling them to [-0.5, 0.5] and shuffling them randomly: -```json -{ - "init-kernel": { - "components": 2, - "width": 4, - "height": 1, - "depth": 1 - }, - - "commands": [ - { "sample.golden_point_set": { } }, - { "scale.range": { "range_to_lower": -0.5, "range_to_upper": 0.5 } }, - { "shuffle.random": { } } - ] -} -``` - -The generated output JSON will look like this: -```json -{ - "kernel": [ - [ - [ - [ - -0.286392, - -0.437815 - ], - [ - -0.140494, - 0.180219 - ], - [ - 0.0955744, - -0.201747 - ], - [ - 0.47754, - 0.416287 - ] - ] - ] - ], - "size": { - "depth": 1, - "height": 1, - "width": 4 - } -} - -``` +# glkernel +C++ library for pre-computing noise, and random sample-kernels. + +## Project Health (master) + +| Service | System | Compiler | Targets | Status | +| ------- | ------ | -------- | ------- | ------ | +| Jenkins | Ubuntu 14.04 | GCC 4.8 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc4.8)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc4.8)| +| Jenkins | Ubuntu 14.04 | GCC 4.9 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc4.9)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc4.9)| +| Jenkins | Ubuntu 14.04 | GCC 5.3 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-gcc5.3)](http://jenkins.hpi3d.de/job/glkernel-linux-gcc5.3)| +| Jenkins | Ubuntu 14.04 | Clang 3.5 | all, test | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-linux-clang3.5)](http://jenkins.hpi3d.de/job/glkernel-linux-clang3.5) | +| Jenkins | Windows 8.1 | MSVC 2013 Update 5 | all, test, install | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-windows-msvc2013)](http://jenkins.hpi3d.de/job/glkernel-windows-msvc2013) | +| Jenkins | Windows 8.1 | MSVC 2015 Update 1 | all, test, install | [![Build Status](http://jenkins.hpi3d.de/buildStatus/icon?job=glkernel-windows-msvc2015)](http://jenkins.hpi3d.de/job/glkernel-windows-msvc2015) | + +## Features + +* Smart template error messages + +##### Smart template error messages + +Most methods of glkernel operate a kernel as well as additional parameters. This may lead to a template argument mismatch if a method is called with arguments that do not match the intended signature. +These cases are caught by glkernel and a helpful compile time error message is provided to the developers. + +## Using glkernel + +Before using glkernel, it is important to get clear about the following three properties of a kernel: +* Dimension +* Cell type +* Component type + +###### Dimension +Defines in how many dimensions a kernel extends. Can be compared to the dimension of a tensor. +The dimension is defined implicitly by the kernel's size, which is determined for each dimension. +A kernel of size `{4, 1, 2}` has the dimension _three_. + +###### Cell type +The number of cells is determined by the kernel's size. In the example above, the kernel would contain eight cells. These cells can be of different cell types. However, the cell type must be homogeneous for the entire kernel. Cells can be of a scalar (_one_ component per cell) or of a vectorial (_two_, _three_ or _four_ components per cell) type. + +###### Component type +The component type specifies of which type the values (= components) within a kernel are. Again, the component type must be homogeneous. This is most likely a matter of precision and `float` or `double` would be appropriate component types. + + +### As a library + +##### Dependencies + +Using glkernel requires a C++11 compatible compiler. +For linking against glkernel: `glm` +For multithreading support (optional): `OpenMP` for multithreading support +For building the glkernel tests: `cmake` Version 3.1 or newer + +##### Linking + +Glkernel is a header-only library, so linking is as simple as including the headers providing the needed functionality. +For flexibel kernel instantiation, you need to: +```cpp +#include +#include +#include +#include +``` +This allows the instantiation of kernels with scalar or vectorial cell types. Following this, a kernel can be used within methods of different namespaces each providing specific functionality. According to your purpose, you need to: +```cpp +#include // Kernel generation based on noise +#include // Kernel generation based on sampling +#include // Kernel generation based on regular sequences +#include // Kernel transformation by range adjustments +#include // Kernel transformation by shuffling of elements +#include // Kernel transformation by sorting of elements +``` + + +##### Usage +The following aliases are ___already defined by glkernel___ for comfortable usage: +```cpp +using kernel1 = tkernel; // Cell type: scalar, Component type: float +using kernel2 = tkernel; // Cell type: vec2, Component type: float +using kernel3 = tkernel; // Cell type: vec3, Component type: float +using kernel4 = tkernel; // Cell type: vec4, Component type: float + +using dkernel1 = tkernel; // Cell type: scalar, Component type: double +using dkernel2 = tkernel; // Cell type: vec2, Component type: double +using dkernel3 = tkernel; // Cell type: vec3, Component type: double +using dkernel4 = tkernel; // Cell type: vec4, Component type: double +``` +As you can see from the aliases above, the __cell-__ and __component__ type are specified by the kernel class' template arguments. The __dimension__ must be specified during the instantiation. +The following snippet shows a basic order in which the glkernel library can be used: + +```cpp +auto fkernel2 = glkernel::kernel2{4, 1, 1}; // Instantiate 3D float kernel with two components per cell +glkernel::sample::golden_point_set(fkernel2); // Generate 'golden point set' +glkernel::scale::range(fkernel2, -0.5f, 0.5f);) // Scale kernel to [-0.5, 0.5] in each dimension +glkernel::shuffle::random(fkernel2); // Shuffle elements randomly +``` + + + + +### Via command line interface +###### glkernel-cmd + +Additionally to using glkernel as a library, there is a standalone command line tool to generate kernels from JSON descriptions. +The usage is as follows: ```glkernel-cmd --i {input filename} --o {output filename}```, where ```{input filename}``` is a JSON kernel description file and ```{output file}``` is a JSON file containing a kernel. + +The description file must contain an entry "init-kernel" that describes the size and the number of components of the the kernel that will be generated. +It also has to contain an entry "commands", which is an array of commands that will be executed on the kernel. +For these, all glkernel commands can be used. + +The naming convention for applying glkernel commands is ```"{namespace}.{function name}"```, e.g. ```"noise.uniform"``` for ```noise::uniform```. +Arguments can be passed as a JSON object, e.g. ```{ "noise.uniform": { "range_min": -1.0, "range_max": 1.0 } }``` will call ```noise::uniform(kernel, -1.0, 1.0)```. + +Here is an input JSON for generating 4 samples using golden point set sampling, scaling them to [-0.5, 0.5] and shuffling them randomly: +```json +{ + "init-kernel": { + "components": 2, + "width": 4, + "height": 1, + "depth": 1 + }, + + "commands": [ + { "sample.golden_point_set": { } }, + { "scale.range": { "range_to_lower": -0.5, "range_to_upper": 0.5 } }, + { "shuffle.random": { } } + ] +} +``` + +The generated output JSON will look like this: +```json +{ + "kernel": [ + [ + [ + [ + -0.286392, + -0.437815 + ], + [ + -0.140494, + 0.180219 + ], + [ + 0.0955744, + -0.201747 + ], + [ + 0.47754, + 0.416287 + ] + ] + ] + ], + "size": { + "depth": 1, + "height": 1, + "width": 4 + } +} + +```