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/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 + } +} + +``` diff --git a/source/glkernel/CMakeLists.txt b/source/glkernel/CMakeLists.txt index 3db89cb..e0fb76f 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,35 @@ set(headers ${include_path}/shuffle.hpp ${include_path}/sort.h ${include_path}/sort.hpp + ${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}/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 ) # 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 +101,16 @@ generate_template_export_header(${target} ) -# +# # Project options -# +# # none allowed, since interface library (header-only) -# +# # Include directories -# +# target_include_directories(${target} @@ -107,27 +123,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 +158,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..9d91a06 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/AssertionMacros.h @@ -0,0 +1,177 @@ +#pragma once + +#include "TypeTraits.cpp" +#include "StringMacros.h" + + + + +/* + * 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); + +/* + * 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); + +/* + * 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); + + + + +/* + * 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); + +/* + * 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); + +/* + * 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); + +/* + * 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); + +/* + * 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); + + + + +/* + * 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) + + + + +/* + * 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); \ + static_assert( !(areSameCelltype() && areSameType()), VEC3_PARAM_MATCH_DOUBLE); \ + static_assert( !(areSameCelltype() && areSameType()), VEC4_PARAM_MATCH_FLOAT); \ + static_assert( !(areSameCelltype() && areSameType()), VEC4_PARAM_MATCH_DOUBLE); + + + + +/* + * 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); + +/* + * 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/StringMacros.h b/source/glkernel/include/glkernel-generalizations/StringMacros.h new file mode 100644 index 0000000..25e3fad --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/StringMacros.h @@ -0,0 +1,125 @@ +#pragma once + + + +#define IDF ": " + + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define DOT_AT "." /*" In file " __FILE__ ":" TOSTRING(__LINE__)*/ + + +#define WHICH_IS ", which is " +#define WHICH_ARE ", which are " +#define BUT_IS ", but it is " +#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 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 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 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 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 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 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 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 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 + + + + +#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 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 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 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 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 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 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 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 new file mode 100644 index 0000000..4b7f395 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/TypeTraits.cpp @@ -0,0 +1,78 @@ +#pragma once + +#include +#include + + + +namespace glkernel +{ + + + + +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 +//constexpr bool isCellType() { return is_cellType::value; } + + +//template +//struct is_componenType : std::true_type {}; + +//template class V> +//struct is_componenType> : std::false_type {}; + +//template class V> +//constexpr bool isComponentType() { return is_componenType>::value; } + +//template +//constexpr bool isComponentType() { return is_componenType::value; } + + + + +} // glkernel diff --git a/source/glkernel/include/glkernel-generalizations/noise_generalized.h b/source/glkernel/include/glkernel-generalizations/noise_generalized.h new file mode 100644 index 0000000..965b0cf --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.h @@ -0,0 +1,111 @@ +#pragma once + +#include + +#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 +{ + + +namespace noise +{ + + + + +template +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 &); + + + + +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 class V> +void normal(tkernel> &, const T2, const T3); + + +template class V1, template class V2> +void normal(tkernel> &, const V2 &, const T3); + +template class V1, template class V2> +void normal(tkernel> &, const T2, const V2 &); + + +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); + + + + +} // namespace noise + + +} // namespace glkernel + + +#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..da99202 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/noise_generalized.hpp @@ -0,0 +1,146 @@ +#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_SCALAR(T1); +} + +template class V> +void uniform(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(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_SCALAR_OR_VECTORIAL(T1, V1); +} + +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(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_SCALAR(T1); +} + +template class V> +void normal(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(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_SCALAR_OR_VECTORIAL(T1, V1); +} + +template class V1, template class V2> +void normal(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(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..0f5e3a1 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.h @@ -0,0 +1,148 @@ +#pragma once + +#include + +#include +#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 +{ + + +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..9b9f609 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sample_generalized.hpp @@ -0,0 +1,208 @@ +#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_SCALAR(T1, V); +} + +template class V1, template class V2> +void poisson_square(tkernel> &, const V2 &, const unsigned int) +{ + FAIL_ON_PARAM_ASSUMING_SCALAR(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..25d4002 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.h @@ -0,0 +1,78 @@ +#pragma once + +#include + +#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 +{ + + +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..6990552 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/scale_generalized.hpp @@ -0,0 +1,96 @@ +#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_SCALAR(T1); +} + +template class V> +void range(tkernel &, T2, const V &, T4, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); +} + +template class V> +void range(tkernel &, T2, T3, const V &, T5) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(T1); +} + +template class V> +void range(tkernel &, T2, T3, T4, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(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_SCALAR_OR_VECTORIAL(T1, V1); +} + +template class V1, template class V2> +void range(tkernel> &, T2, const V2 &, T4, T5) +{ + 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_SCALAR_OR_VECTORIAL(T1, V1); +} + +template class V1, template class V2> +void range(tkernel> &, T2, T3, T4, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(T1, V1); +} + + + + +} // namespace scale + + +} // namespace 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..d1dde93 --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sequence_generalized.h @@ -0,0 +1,71 @@ +#pragma once + +#include + +#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 +{ + + +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..9cdaf20 --- /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_SCALAR(T1); +} + +template class V> +void uniform(tkernel &, const T2, const V &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR(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_SCALAR_OR_VECTORIAL(T1, V1); +} + +template class V1, template class V2> +void uniform(tkernel> &, const T2, const V2 &) +{ + FAIL_ON_PARAM_HETEROGENEITY_ASSUMING_SCALAR_OR_VECTORIAL(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..8cf10ef --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/shuffle_generalized.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#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 +{ + + +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..43d11ab --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#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 +{ + + +namespace sort +{ + + + + +template +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..e64476a --- /dev/null +++ b/source/glkernel/include/glkernel-generalizations/sort_generalized.hpp @@ -0,0 +1,30 @@ +#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); +} + + + + +} // namespace sort + + +} // 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/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/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..ec237b0 --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/CMakeLists.txt @@ -0,0 +1,230 @@ + +# +# 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 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(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 new file mode 100644 index 0000000..418ef86 --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/noise_fail.cpp @@ -0,0 +1,81 @@ +#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(fkernel1, glm::vec2{ 0.0 }, 1.0f); +#elif defined NOISE_NORMAL_3 + glkernel::noise::normal(fkernel1, 0.0f, glm::vec2{ 0.0 }); +#elif defined NOISE_NORMAL_4 + glkernel::noise::normal(fkernel2, 0.0f, 1.0); +#elif defined NOISE_NORMAL_5 + glkernel::noise::normal(fkernel2, glm::vec2{ 0.0 }, 1.0f); +#elif defined NOISE_NORMAL_6 + 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(fkernel1, glm::vec2{ 0.0 }, 1.0f); +#elif defined NOISE_UNIFORM_3 + glkernel::noise::uniform(fkernel1, 0.0f, glm::vec2{ 0.0 }); +#elif defined NOISE_UNIFORM_4 + glkernel::noise::uniform(fkernel2, 0.0f, 1.0); +#elif defined NOISE_UNIFORM_5 + glkernel::noise::uniform(fkernel2, glm::vec2{ 0.0 }, 1.0f); +#elif defined NOISE_UNIFORM_6 + 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 + + + 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..104db73 --- /dev/null +++ b/source/tests/glkernel-will_fail_tests/sample_fail.cpp @@ -0,0 +1,79 @@ +#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 SAMPLE_POISSON_SQUARE_1 + glkernel::sample::poisson_square(fkernel1); +#elif defined SAMPLE_POISSON_SQUARE_2 + glkernel::sample::poisson_square(fkernel1, 1.5); +#elif defined SAMPLE_POISSON_SQUARE_3 + glkernel::sample::poisson_square(fkernel1, glm::vec2{ 1.5 }); +#elif defined SAMPLE_POISSON_SQUARE_4 + glkernel::sample::poisson_square(fkernel2, 1.5); +#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_8 + glkernel::sample::poisson_square(fkernel3, 1.5); +#elif defined SAMPLE_POISSON_SQUARE_9 + glkernel::sample::poisson_square(fkernel3, glm::vec2{ 1.5 }); +#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; +} + + 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; +}