diff --git a/.gitignore b/.gitignore index e79236b..19e8bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,6 @@ cmake-build-debug/ .vscode/ # Created validation_test files -validation_test/output.bpm +validation_test/**/output.bmp validation_test/**/output.jpg validation_test/**/difference.jpg \ No newline at end of file diff --git a/README.md b/README.md index f5f55d3..2cf1464 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ cmake .. && make && ./RayTracer scene.obj ## How to create a test Create a directory in validation_test with the name of the scene (it must match the name of the scene). -Create test files inside the directory with the following name format: `x__` +Create test files inside the directory with the following name format: `_.jpg` Then, follow the next point in order to generate the test. ## How to regenerate tests diff --git a/src/Dispatcher/Dispatcher.cc b/src/Dispatcher/Dispatcher.cc index c6141a3..5988486 100644 --- a/src/Dispatcher/Dispatcher.cc +++ b/src/Dispatcher/Dispatcher.cc @@ -46,7 +46,7 @@ namespace rt { _threads.clear(); } - std::vector Dispatcher::Flush() { + std::vector const& Dispatcher::Flush() const { return _image; } diff --git a/src/Dispatcher/Dispatcher.h b/src/Dispatcher/Dispatcher.h index eb96b76..251663f 100644 --- a/src/Dispatcher/Dispatcher.h +++ b/src/Dispatcher/Dispatcher.h @@ -31,7 +31,7 @@ namespace rt { void Start(void); void Stop(void); - std::vector Flush(void); + std::vector const& Flush(void) const; std::size_t GetNumberOfProcessed(void) const; private: diff --git a/validation_test/Cube/100_100.jpg b/validation_test/Cube/100_100.jpg new file mode 100644 index 0000000..acea3ab Binary files /dev/null and b/validation_test/Cube/100_100.jpg differ diff --git a/validation_test/Dragon/100_300.jpg b/validation_test/Dragon/100_300.jpg new file mode 100644 index 0000000..495dad2 Binary files /dev/null and b/validation_test/Dragon/100_300.jpg differ diff --git a/validation_test/DragonOnStandDoubleLight/100_600.jpg b/validation_test/DragonOnStandDoubleLight/100_600.jpg new file mode 100644 index 0000000..5cdadb6 Binary files /dev/null and b/validation_test/DragonOnStandDoubleLight/100_600.jpg differ diff --git a/validation_test/Ico/100_100.jpg b/validation_test/Ico/100_100.jpg new file mode 100644 index 0000000..44f745b Binary files /dev/null and b/validation_test/Ico/100_100.jpg differ diff --git a/validation_test/regenerate.sh b/validation_test/regenerate.sh index 23a22be..5aa082c 100755 --- a/validation_test/regenerate.sh +++ b/validation_test/regenerate.sh @@ -1,12 +1,13 @@ #!/usr/bin/env bash +cd ../cmake-build-debug && cmake .. && make && cd - echo "Launching regeneration of validation tests" for directory in $(ls -d */ | sed 's#/##') do for parameter in $(ls ${directory} -I output.jpg -I difference.jpg | sed -e 's/\..*$//') do echo "Launching regeneration on scene $directory with parameter ${parameter}" - ../cmake-build-debug/RayTracer ../scenes/${directory}.obj $(echo ${parameter} | cut -d '_' -f1) --output-image $(echo ${parameter} | cut -d '_' -f2) - convert output.bpm ${directory}/${parameter}.jpg + ../cmake-build-debug/RayTracer ../scenes/${directory}.dae --output-image=$(echo ${parameter} | cut -d '_' -f1) + convert -quality 100% output.bmp ${directory}/${parameter}.jpg done done \ No newline at end of file diff --git a/validation_test/test.sh b/validation_test/test.sh index e4ec049..e846fb6 100755 --- a/validation_test/test.sh +++ b/validation_test/test.sh @@ -1,17 +1,21 @@ #!/usr/bin/env bash +cd ../cmake-build-debug && cmake .. && make && cd - echo "Launching validation tests" status=0 for directory in $(ls -d */ | sed 's#/##') do for test in $(ls ${directory} -I output.jpg -I difference.jpg | sed -e 's/\..*$//') do + echo echo "Launching test on scene $directory with test $test" - ../cmake-build-debug/RayTracer ../scenes/${directory}.obj $(echo ${test} | cut -d '_' -f1) --output-image $(echo ${test} | cut -d '_' -f2) - convert output.bpm ${directory}/output.jpg + ../cmake-build-debug/RayTracer ../scenes/${directory}.dae --output-image=$(echo ${test} | cut -d '_' -f1) + convert -quality 100% output.bmp ${directory}/output.jpg diff=$(compare -metric AE -fuzz 5% ${directory}/output.jpg ${directory}/${test}.jpg ${directory}/difference.jpg 2>&1) - if [[ ${diff} -ge $(echo ${test} | cut -d '_' -f3) ]]; then + if [[ ${diff} -ge $(echo ${test} | cut -d '_' -f2) ]]; then echo "FAIL: Too many diff for $directory/${test}: $diff" + echo "Uploading difference..." + ./upload.sh ${directory}/difference.jpg status=1 else echo "SUCCESS: Passed ${directory}/${test}: $diff" diff --git a/validation_test/upload.sh b/validation_test/upload.sh new file mode 100755 index 0000000..fdce5d9 --- /dev/null +++ b/validation_test/upload.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Imgur script by Bart Nagel +# Improvements by Tino Sino +# Version 6 or more +# I release this into the public domain. Do with it what you will. +# The latest version can be found at https://github.com/tremby/imgur.sh + +# API Key provided by Bart; +# replace with your own or specify yours as IMGUR_CLIENT_ID envionment variable +# to avoid limits +default_client_id=c9a6efb3d7932fd +client_id="${IMGUR_CLIENT_ID:=$default_client_id}" + +# Function to output usage instructions +function usage { + echo "Usage: $(basename $0) [ [...]]" >&2 + echo + echo "Upload images to imgur and output their new URLs to stdout. Each one's" >&2 + echo "delete page is output to stderr between the view URLs." >&2 + echo + echo "A filename can be - to read from stdin. If no filename is given, stdin is read." >&2 + echo + echo "If xsel, xclip, or pbcopy is available, the URLs are put on the X selection for" >&2 + echo "easy pasting." >&2 +} + +# Function to upload a path +# First argument should be a content spec understood by curl's -F option +function upload { + curl -s -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=$1" https://api.imgur.com/3/image.xml + # The "Expect: " header is to get around a problem when using this through + # the Squid proxy. Not sure if it's a Squid bug or what. +} + +# Check arguments +if [ "$1" == "-h" -o "$1" == "--help" ]; then + usage + exit 0 +elif [ $# -eq 0 ]; then + echo "No file specified; reading from stdin" >&2 + exec "$0" - +fi + +# Check curl is available +type curl &>/dev/null || { + echo "Couldn't find curl, which is required." >&2 + exit 17 +} + +clip="" +errors=false + +# Loop through arguments +while [ $# -gt 0 ]; do + file="$1" + shift + + # Upload the image + if [[ "$file" =~ ^https?:// ]]; then + # URL -> imgur + response=$(upload "$file") 2>/dev/null + else + # File -> imgur + # Check file exists + if [ "$file" != "-" -a ! -f "$file" ]; then + echo "File '$file' doesn't exist; skipping" >&2 + errors=true + continue + fi + response=$(upload "@$file") 2>/dev/null + fi + + if [ $? -ne 0 ]; then + echo "Upload failed" >&2 + errors=true + continue + elif echo "$response" | grep -q 'success="0"'; then + echo "Error message from imgur:" >&2 + msg="${response##*}" + echo "${msg%%*}" >&2 + errors=true + continue + fi + + # Parse the response and output our stuff + url="${response##*}" + url="${url%%*}" + delete_hash="${response##*}" + delete_hash="${delete_hash%%*}" + echo $url | sed 's/^http:/https:/' + echo "Delete page: https://imgur.com/delete/$delete_hash" >&2 + + # Append the URL to a string so we can put them all on the clipboard later + clip+="$url" + if [ $# -gt 0 ]; then + clip+=$'\n' + fi +done + +# Put the URLs on the clipboard if we can +if type pbcopy &>/dev/null; then + echo -n "$clip" | pbcopy +elif [ $DISPLAY ]; then + if type xsel &>/dev/null; then + echo -n "$clip" | xsel -i + elif type xclip &>/dev/null; then + echo -n "$clip" | xclip + else + echo "Haven't copied to the clipboard: no xsel or xclip" >&2 + fi +else + echo "Haven't copied to the clipboard: no \$DISPLAY or pbcopy" >&2 +fi + +if $errors; then + exit 1 +fi \ No newline at end of file