From eb62d448fd78f3d7e8499af9c4d24d1445286ddb Mon Sep 17 00:00:00 2001 From: Julian Amann Date: Mon, 24 Jul 2017 10:01:22 +0200 Subject: [PATCH] ImageProcessing: Added functions to generate difference images. --- CMake/ProjectVersion.cmake | 2 +- Core/src/BlueFramework/Core/Version.h | 2 +- .../src/BlueFramework/ImageProcessing/Color.h | 893 +++++++----------- .../ImageProcessing/ImageFilter.h | 180 ++-- .../ImageProcessing/captureScreen.cpp | 35 + .../ImageProcessing/captureScreen.h | 33 + .../ImageProcessing/difference.cpp | 110 +++ .../ImageProcessing/difference.h | 39 + .../proceduralTextureGeneration.cpp | 279 +++--- .../proceduralTextureGeneration.h | 1 - Tools/fileHeaderGenerator.py | 7 +- .../randomHeightmapGeneration.cpp | 37 +- 12 files changed, 812 insertions(+), 806 deletions(-) create mode 100644 ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.cpp create mode 100644 ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.h create mode 100644 ImageProcessing/src/BlueFramework/ImageProcessing/difference.cpp create mode 100644 ImageProcessing/src/BlueFramework/ImageProcessing/difference.h diff --git a/CMake/ProjectVersion.cmake b/CMake/ProjectVersion.cmake index 9244842..bc5a859 100644 --- a/CMake/ProjectVersion.cmake +++ b/CMake/ProjectVersion.cmake @@ -1,4 +1,4 @@ -set(PROJECT_VERSION_TWEAK "42") +set(PROJECT_VERSION_TWEAK "46") set(PROJECT_VERSION_PATCH "1") set(PROJECT_VERSION_MINOR "1") set(PROJECT_VERSION_MAJOR "3") \ No newline at end of file diff --git a/Core/src/BlueFramework/Core/Version.h b/Core/src/BlueFramework/Core/Version.h index 6821c69..9b2f231 100644 --- a/Core/src/BlueFramework/Core/Version.h +++ b/Core/src/BlueFramework/Core/Version.h @@ -17,7 +17,7 @@ #define BLUEFRAMEWORK_API_MAJOR 3 #define BLUEFRAMEWORK_API_MINOR 1 #define BLUEFRAMEWORK_API_PATCH 1 -#define BLUEFRAMEWORK_API_TWEAK 42 +#define BLUEFRAMEWORK_API_TWEAK 46 BLUEFRAMEWORK_CORE_NAMESPACE_BEGIN diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/Color.h b/ImageProcessing/src/BlueFramework/ImageProcessing/Color.h index d9f2c4a..7f9c338 100644 --- a/ImageProcessing/src/BlueFramework/ImageProcessing/Color.h +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/Color.h @@ -34,8 +34,8 @@ #ifndef BlueFramework_ImageProcessing_Color_a6e437c4_de88_4d75_acb1_70d78886fbe5_h #define BlueFramework_ImageProcessing_Color_a6e437c4_de88_4d75_acb1_70d78886fbe5_h -#include #include +#include #include #include #include @@ -49,17 +49,16 @@ BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN // N-dimensional color class and operations. // template -class Color -{ +class Color { public: // Value type and number of components. typedef T ValueType; static const size_t Components = N; // Constructors. - Color(); // leave all components uninitialized - explicit Color(const ValueType* rhs); // initialize with array of N scalars - explicit Color(const ValueType val); // set all components to 'val' + Color(); // leave all components uninitialized + explicit Color(const ValueType* rhs); // initialize with array of N scalars + explicit Color(const ValueType val); // set all components to 'val' // Construct a color from another color of a different type. template @@ -73,10 +72,8 @@ class Color const ValueType& operator[](const size_t i) const; // Checks if all color values are valid (non-infinite, non-negative, non-NAN) - bool isValid() const - { - for (int i = 0; i < N; ++i) - { + bool isValid() const { + for (size_t i = 0; i < N; ++i) { T value = comp_[i]; int cl = boost::math::fpclassify(value); @@ -86,72 +83,100 @@ class Color return true; } - // swizzle functions - #include "Color2Swizzles.inc" - #include "Color3Swizzles.inc" - #include "Color4Swizzles.inc" +// swizzle functions +#include "Color2Swizzles.inc" +#include "Color3Swizzles.inc" +#include "Color4Swizzles.inc" - private: +private: // Color components. ValueType comp_[N]; }; // Exact inequality and equality tests. -template bool operator!=(const Color& lhs, const Color& rhs); -template bool operator==(const Color& lhs, const Color& rhs); +template +bool operator!=(const Color& lhs, const Color& rhs); +template +bool operator==(const Color& lhs, const Color& rhs); // Approximate equality tests. -template bool feq(const Color& lhs, const Color& rhs); -template bool feq(const Color& lhs, const Color& rhs, const T eps); +template +bool feq(const Color& lhs, const Color& rhs); +template +bool feq(const Color& lhs, const Color& rhs, const T eps); // Approximate zero tests. -template bool fz(const Color& c); -template bool fz(const Color& c, const T eps); +template +bool fz(const Color& c); +template +bool fz(const Color& c, const T eps); // Color arithmetic. -template Color operator+ (const Color& lhs, const Color& rhs); -template Color operator- (const Color& lhs, const Color& rhs); -template Color operator- (const Color& lhs); -template Color operator* (const Color& lhs, const T rhs); -template Color operator* (const T lhs, const Color& rhs); -template Color operator* (const Color& lhs, const Color& rhs); -template Color operator/ (const Color& lhs, const T rhs); -template Color operator/ (const Color& lhs, const Color& rhs); -template Color& operator+=(Color& lhs, const Color& rhs); -template Color& operator-=(Color& lhs, const Color& rhs); -template Color& operator*=(Color& lhs, const T rhs); -template Color& operator*=(Color& lhs, const Color& rhs); -template Color& operator/=(Color& lhs, const T rhs); -template Color& operator/=(Color& lhs, const Color& rhs); +template +Color operator+(const Color& lhs, const Color& rhs); +template +Color operator-(const Color& lhs, const Color& rhs); +template +Color operator-(const Color& lhs); +template +Color operator*(const Color& lhs, const T rhs); +template +Color operator*(const T lhs, const Color& rhs); +template +Color operator*(const Color& lhs, const Color& rhs); +template +Color operator/(const Color& lhs, const T rhs); +template +Color operator/(const Color& lhs, const Color& rhs); +template +Color& operator+=(Color& lhs, const Color& rhs); +template +Color& operator-=(Color& lhs, const Color& rhs); +template +Color& operator*=(Color& lhs, const T rhs); +template +Color& operator*=(Color& lhs, const Color& rhs); +template +Color& operator/=(Color& lhs, const T rhs); +template +Color& operator/=(Color& lhs, const Color& rhs); // Clamp the argument to [min, max]. -template Color clamp(const Color& c, const T min, const T max); +template +Color clamp(const Color& c, const T min, const T max); // Clamp the argument to [0,1]. -template Color saturate(const Color& c); +template +Color saturate(const Color& c); // Return the smallest or largest signed component of a color. -template T min_value(const Color& c); -template T max_value(const Color& c); +template +T min_value(const Color& c); +template +T max_value(const Color& c); // Return the index of the smallest or largest signed component of a color. -template size_t min_index(const Color& c); -template size_t max_index(const Color& c); +template +size_t min_index(const Color& c); +template +size_t max_index(const Color& c); // Return the index of the smallest or largest component of a color, in absolute value. -template size_t min_abs_index(const Color& c); -template size_t max_abs_index(const Color& c); +template +size_t min_abs_index(const Color& c); +template +size_t max_abs_index(const Color& c); // Return the average value of a color. -template T average_value(const Color& c); +template +T average_value(const Color& c); // // RGB color class of arbitrary type. // template -struct Color -{ +struct Color { // Value type and number of components. typedef T ValueType; static const size_t Components = 1; @@ -160,10 +185,9 @@ struct Color ValueType g; // grayvalue // Constructors. - Color(); // leave all components uninitialized - explicit Color(const ValueType* rhs); // initialize with array of 1 scalars - explicit Color( const ValueType grayvalue); // set individual components - + Color(); // leave all components uninitialized + explicit Color(const ValueType* rhs); // initialize with array of 1 scalars + explicit Color(const ValueType grayvalue); // set individual components // Construct a color from another color of a different type. template @@ -176,8 +200,7 @@ struct Color ValueType& operator[](const size_t i); const ValueType& operator[](const size_t i) const; - ValueType grayvalue() const - { + ValueType grayvalue() const { return (*this)[0]; } }; @@ -187,8 +210,7 @@ struct Color // template -struct Color -{ +struct Color { // Value type and number of components. typedef T ValueType; static const size_t Components = 3; @@ -197,13 +219,13 @@ struct Color ValueType r, g, b; // Constructors. - Color(); // leave all components uninitialized - explicit Color(const ValueType* rhs); // initialize with array of 3 scalars - explicit Color(const ValueType val); // set all components to 'val' - Color( // set individual components - const ValueType r, - const ValueType g, - const ValueType b); + Color(); // leave all components uninitialized + explicit Color(const ValueType* rhs); // initialize with array of 3 scalars + explicit Color(const ValueType val); // set all components to 'val' + Color( // set individual components + const ValueType r, + const ValueType g, + const ValueType b); // Construct a color from another color of a different type. template @@ -216,223 +238,185 @@ struct Color ValueType& operator[](const size_t i); const ValueType& operator[](const size_t i) const; - ValueType red() const - { + ValueType red() const { return (*this)[0]; } - ValueType green() const - { + ValueType green() const { return (*this)[1]; } - ValueType blue() const - { + ValueType blue() const { return (*this)[2]; } - + // other color spaces - double getAlpha() const - { + double getAlpha() const { return -1.0; } - double getBeta() const - { + double getBeta() const { return -1.0; } - double getHue() - { + double getHue() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; double max = std::max(std::max(r, g), b); double min = std::min(std::min(r, g), b); - if(max == min) - { + if (max == min) { return 0; - } - else if(max == r) - { - return 60 * ((g-b)/(max-min)); - } - else if(max == g) - { - return 60 * (2 + (b-r)/(max-min)); - } - else - { - return 60 * (4 + (r-g)/(max-min)); + } else if (max == r) { + return 60 * ((g - b) / (max - min)); + } else if (max == g) { + return 60 * (2 + (b - r) / (max - min)); + } else { + return 60 * (4 + (r - g) / (max - min)); } } - double getSaturation() - { + double getSaturation() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; double max = std::max(std::max(r, g), b); double min = std::min(std::min(r, g), b); - if(max == 0) - { + if (max == 0) { return 0; - } - else - { - return (max - min)/max; + } else { + return (max - min) / max; } } - double getBrightness() - { + double getBrightness() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; return std::max(std::max(r, g), b); } - //needed for conversion from XYZ to sRGB - //does not need to be accessible for the user - double gammaEncoding(double t) - { - if(t > 0.0031308) - { - return 1.055*pow(t, 1.0/2.4) - 0.055; - } - else - { - return 12.92*t; + // needed for conversion from XYZ to sRGB + // does not need to be accessible for the user + double gammaEncoding(double t) { + if (t > 0.0031308) { + return 1.055 * pow(t, 1.0 / 2.4) - 0.055; + } else { + return 12.92 * t; } } - //needed for conversion from sRGB to XYZ - //does not need to be accessible for the user - double inverseGammaEncoding(double t) - { - if(t > 0.04045) - { - return pow((t + 0.055)/1.055, 2.4); - } - else - { - return t/12.92; + // needed for conversion from sRGB to XYZ + // does not need to be accessible for the user + double inverseGammaEncoding(double t) { + if (t > 0.04045) { + return pow((t + 0.055) / 1.055, 2.4); + } else { + return t / 12.92; } } - //get the X-Value of XYZ from sRGB value - double getXYZ_X() - { + // get the X-Value of XYZ from sRGB value + double getXYZ_X() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.4124564*r + 0.3575761*g + 0.1804375*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.4124564 * r + 0.3575761 * g + 0.1804375 * b; } - //get the Y-Value of XYZ from sRGB value - double getXYZ_Y() - { + // get the Y-Value of XYZ from sRGB value + double getXYZ_Y() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.2126729*r + 0.7151522*g + 0.0721750*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.2126729 * r + 0.7151522 * g + 0.0721750 * b; } - //get the Z-Value of XYZ from sRGB value - double getXYZ_Z() - { + // get the Z-Value of XYZ from sRGB value + double getXYZ_Z() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.0193339*r + 0.1191920*g + 0.9503041*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.0193339 * r + 0.1191920 * g + 0.9503041 * b; } - //just a helper function that's needed for the L*ab-conversion - //needn't to be accessible for the user - double LAB_helperFunction(double t) - { - if(t > 0.008856) - { - return pow(t, 1.0/3.0); - } - else - { - return 7.78704*t + 0.137931; + // just a helper function that's needed for the L*ab-conversion + // needn't to be accessible for the user + double LAB_helperFunction(double t) { + if (t > 0.008856) { + return pow(t, 1.0 / 3.0); + } else { + return 7.78704 * t + 0.137931; } } - //get the L-value of L*ab from sRGB value - double getLAB_L() - { + // get the L-value of L*ab from sRGB value + double getLAB_L() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; double Y = getXYZ_Y(red, green, blue); - std::cout< return true; } - static Color fromRGB(const int red, const int green, const int blue) - { - return Color( - static_cast(red) / 255, - static_cast(green) / 255, - static_cast(blue) / 255 - ); + static Color fromRGB(const int red, const int green, const int blue) { + return Color(static_cast(red) / 255, static_cast(green) / 255, static_cast(blue) / 255); } - // swizzle functions - #include "Color2Swizzles.inc" - #include "Color3Swizzles.inc" - #include "Color4Swizzles.inc" +// swizzle functions +#include "Color2Swizzles.inc" +#include "Color3Swizzles.inc" +#include "Color4Swizzles.inc" }; - // // RGBA color class of arbitrary type. // template -struct Color -{ +struct Color { // Value type and number of components. typedef T ValueType; static const size_t Components = 4; @@ -473,294 +450,251 @@ struct Color ValueType r, g, b, a; // Constructors. - Color(); // leave all components uninitialized - explicit Color(const ValueType* rhs); // initialize with array of 4 scalars - explicit Color(const ValueType val); // set all components to 'val' - Color( - const Color& rgb, - const ValueType a); - Color( // set individual components - const ValueType r, - const ValueType g, - const ValueType b, - const ValueType a); + Color(); // leave all components uninitialized + explicit Color(const ValueType* rhs); // initialize with array of 4 scalars + explicit Color(const ValueType val); // set all components to 'val' + Color(const Color& rgb, const ValueType a); + Color( // set individual components + const ValueType r, + const ValueType g, + const ValueType b, + const ValueType a); // Construct a color from another color of a different type. template explicit Color(const Color& rhs); - explicit Color(const Color& rhs) - { + explicit Color(const Color& rhs) { r = rhs.r; g = rhs.g; b = rhs.b; a = 1.0; } - + // Set all components to a given value. void set(const ValueType val); // Access the color as a 3-component color. - //color& rgb(); - //const color& rgb() const; + // color& rgb(); + // const color& rgb() const; // Unchecked array subscripting. ValueType& operator[](const size_t i); const ValueType& operator[](const size_t i) const; - ValueType red() const - { + ValueType red() const { return (*this)[0]; } - ValueType green() const - { + ValueType green() const { return (*this)[1]; } - ValueType blue() const - { + ValueType blue() const { return (*this)[2]; } - ValueType alpha() const - { + ValueType alpha() const { return (*this)[3]; } // other color spaces - double getAlpha() const - { + double getAlpha() const { return -1.0; } - double getBeta() const - { + double getBeta() const { return -1.0; } - double getHue() - { + double getHue() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; double max = std::max(std::max(r, g), b); double min = std::min(std::min(r, g), b); - if(max == min) - { + if (max == min) { return 0; - } - else if(max == r) - { - return 60 * ((g-b)/(max-min)); - } - else if(max == g) - { - return 60 * (2 + (b-r)/(max-min)); - } - else - { - return 60 * (4 + (r-g)/(max-min)); + } else if (max == r) { + return 60 * ((g - b) / (max - min)); + } else if (max == g) { + return 60 * (2 + (b - r) / (max - min)); + } else { + return 60 * (4 + (r - g) / (max - min)); } } - double getSaturation() - { + double getSaturation() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; double max = std::max(std::max(r, g), b); double min = std::min(std::min(r, g), b); - if(max == 0) - { + if (max == 0) { return 0; - } - else - { - return (max - min)/max; + } else { + return (max - min) / max; } } - double getBrightness() - { + double getBrightness() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = (double)red/255; - double g = (double)green/255; - double b = (double)blue/255; + double r = (double)red / 255; + double g = (double)green / 255; + double b = (double)blue / 255; return std::max(std::max(r, g), b); } - //needed for conversion from XYZ to sRGB - //does not need to be accessable for the user - double gammaEncoding(double t) - { - if(t > 0.0031308) - { - return 1.055*pow(t, 1.0/2.4) - 0.055; - } - else - { - return 12.92*t; + // needed for conversion from XYZ to sRGB + // does not need to be accessable for the user + double gammaEncoding(double t) { + if (t > 0.0031308) { + return 1.055 * pow(t, 1.0 / 2.4) - 0.055; + } else { + return 12.92 * t; } } - //needed for conversion from sRGB to XYZ - //does not need to be accessable for the user - double inverseGammaEncoding(double t) - { - if(t > 0.04045) - { - return pow((t + 0.055)/1.055, 2.4); - } - else - { - return t/12.92; + // needed for conversion from sRGB to XYZ + // does not need to be accessable for the user + double inverseGammaEncoding(double t) { + if (t > 0.04045) { + return pow((t + 0.055) / 1.055, 2.4); + } else { + return t / 12.92; } } - //get the X-Value of XYZ from sRGB value - double getXYZ_X() - { + // get the X-Value of XYZ from sRGB value + double getXYZ_X() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.4124564*r + 0.3575761*g + 0.1804375*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.4124564 * r + 0.3575761 * g + 0.1804375 * b; } - //get the Y-Value of XYZ from sRGB value - double getXYZ_Y() - { + // get the Y-Value of XYZ from sRGB value + double getXYZ_Y() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.2126729*r + 0.7151522*g + 0.0721750*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.2126729 * r + 0.7151522 * g + 0.0721750 * b; } - //get the Z-Value of XYZ from sRGB value - double getXYZ_Z() - { + // get the Z-Value of XYZ from sRGB value + double getXYZ_Z() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; - double r = inverseGammaEncoding((double)red/255); - double g = inverseGammaEncoding((double)green/255); - double b = inverseGammaEncoding((double)blue/255); - return 0.0193339*r + 0.1191920*g + 0.9503041*b; + double r = inverseGammaEncoding((double)red / 255); + double g = inverseGammaEncoding((double)green / 255); + double b = inverseGammaEncoding((double)blue / 255); + return 0.0193339 * r + 0.1191920 * g + 0.9503041 * b; } - //just a helper function that's needed for the L*ab-conversion - //needn't to be accessable for the user - double LAB_helperFunction(double t) - { - if(t > 0.008856) - { - return pow(t, 1.0/3.0); - } - else - { - return 7.78704*t + 0.137931; + // just a helper function that's needed for the L*ab-conversion + // needn't to be accessable for the user + double LAB_helperFunction(double t) { + if (t > 0.008856) { + return pow(t, 1.0 / 3.0); + } else { + return 7.78704 * t + 0.137931; } } - //get the L-value of L*ab from sRGB value - double getLAB_L() - { + // get the L-value of L*ab from sRGB value + double getLAB_L() { int red = (*this)[0]; int green = (*this)[1]; int blue = (*this)[2]; double Y = getXYZ_Y(red, green, blue); - std::cout< Color1b; -typedef Color Color1f; -typedef Color Color1d; +typedef Color Color1f; +typedef Color Color1d; typedef Color Color2b; -typedef Color Color2f; -typedef Color Color2d; +typedef Color Color2f; +typedef Color Color2d; typedef Color Color3b; -typedef Color Color3f; -typedef Color Color3d; +typedef Color Color3f; +typedef Color Color3d; typedef Color Color4b; -typedef Color Color4f; -typedef Color Color4d; +typedef Color Color4f; +typedef Color Color4d; // // N-dimensional color implementation. // template -inline Color::Color() -{ +inline Color::Color() { } template -inline Color::Color(const ValueType* rhs) -{ +inline Color::Color(const ValueType* rhs) { assert(rhs); for (size_t i = 0; i < N; ++i) @@ -768,45 +702,38 @@ inline Color::Color(const ValueType* rhs) } template -inline Color::Color(const ValueType val) -{ +inline Color::Color(const ValueType val) { set(val); } template template -inline Color::Color(const Color& rhs) -{ +inline Color::Color(const Color& rhs) { for (size_t i = 0; i < N; ++i) comp_[i] = static_cast(rhs.comp_[i]); } template -inline void Color::set(const ValueType val) -{ +inline void Color::set(const ValueType val) { for (size_t i = 0; i < N; ++i) comp_[i] = val; } template -inline T& Color::operator[](const size_t i) -{ +inline T& Color::operator[](const size_t i) { assert(i < Components); return comp_[i]; } template -inline const T& Color::operator[](const size_t i) const -{ +inline const T& Color::operator[](const size_t i) const { assert(i < Components); return comp_[i]; } template -inline bool operator!=(const Color& lhs, const Color& rhs) -{ - for (size_t i = 0; i < N; ++i) - { +inline bool operator!=(const Color& lhs, const Color& rhs) { + for (size_t i = 0; i < N; ++i) { if (lhs[i] != rhs[i]) return true; } @@ -815,16 +742,13 @@ inline bool operator!=(const Color& lhs, const Color& rhs) } template -inline bool operator==(const Color& lhs, const Color& rhs) -{ +inline bool operator==(const Color& lhs, const Color& rhs) { return !(lhs != rhs); } template -inline bool feq(const Color& lhs, const Color& rhs) -{ - for (size_t i = 0; i < N; ++i) - { +inline bool feq(const Color& lhs, const Color& rhs) { + for (size_t i = 0; i < N; ++i) { if (!feq(lhs[i], rhs[i])) return false; } @@ -833,10 +757,8 @@ inline bool feq(const Color& lhs, const Color& rhs) } template -inline bool feq(const Color& lhs, const Color& rhs, const T eps) -{ - for (size_t i = 0; i < N; ++i) - { +inline bool feq(const Color& lhs, const Color& rhs, const T eps) { + for (size_t i = 0; i < N; ++i) { if (!feq(lhs[i], rhs[i], eps)) return false; } @@ -845,10 +767,8 @@ inline bool feq(const Color& lhs, const Color& rhs, const T eps) } template -inline bool fz(const Color& v) -{ - for (size_t i = 0; i < N; ++i) - { +inline bool fz(const Color& v) { + for (size_t i = 0; i < N; ++i) { if (!fz(v[i])) return false; } @@ -857,10 +777,8 @@ inline bool fz(const Color& v) } template -inline bool fz(const Color& v, const T eps) -{ - for (size_t i = 0; i < N; ++i) - { +inline bool fz(const Color& v, const T eps) { + for (size_t i = 0; i < N; ++i) { if (!fz(v[i], eps)) return false; } @@ -869,8 +787,7 @@ inline bool fz(const Color& v, const T eps) } template -inline Color operator+(const Color& lhs, const Color& rhs) -{ +inline Color operator+(const Color& lhs, const Color& rhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -880,8 +797,7 @@ inline Color operator+(const Color& lhs, const Color& rhs) } template -inline Color operator-(const Color& lhs, const Color& rhs) -{ +inline Color operator-(const Color& lhs, const Color& rhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -891,8 +807,7 @@ inline Color operator-(const Color& lhs, const Color& rhs) } template -inline Color operator-(const Color& lhs) -{ +inline Color operator-(const Color& lhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -902,8 +817,7 @@ inline Color operator-(const Color& lhs) } template -inline Color operator*(const Color& lhs, const T rhs) -{ +inline Color operator*(const Color& lhs, const T rhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -913,14 +827,12 @@ inline Color operator*(const Color& lhs, const T rhs) } template -inline Color operator*(const T lhs, const Color& rhs) -{ +inline Color operator*(const T lhs, const Color& rhs) { return rhs * lhs; } template -inline Color operator*(const Color& lhs, const Color& rhs) -{ +inline Color operator*(const Color& lhs, const Color& rhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -930,14 +842,12 @@ inline Color operator*(const Color& lhs, const Color& rhs) } template -inline Color operator/(const Color& lhs, const T rhs) -{ +inline Color operator/(const Color& lhs, const T rhs) { return lhs * (T(1.0) / rhs); } template -inline Color operator/(const Color& lhs, const Color& rhs) -{ +inline Color operator/(const Color& lhs, const Color& rhs) { Color col; for (size_t i = 0; i < N; ++i) @@ -947,8 +857,7 @@ inline Color operator/(const Color& lhs, const Color& rhs) } template -inline Color& operator+=(Color& lhs, const Color& rhs) -{ +inline Color& operator+=(Color& lhs, const Color& rhs) { for (size_t i = 0; i < N; ++i) lhs[i] += rhs[i]; @@ -956,8 +865,7 @@ inline Color& operator+=(Color& lhs, const Color& rhs) } template -inline Color& operator-=(Color& lhs, const Color& rhs) -{ +inline Color& operator-=(Color& lhs, const Color& rhs) { for (size_t i = 0; i < N; ++i) lhs[i] -= rhs[i]; @@ -965,8 +873,7 @@ inline Color& operator-=(Color& lhs, const Color& rhs) } template -inline Color& operator*=(Color& lhs, const T rhs) -{ +inline Color& operator*=(Color& lhs, const T rhs) { for (size_t i = 0; i < N; ++i) lhs[i] *= rhs; @@ -974,8 +881,7 @@ inline Color& operator*=(Color& lhs, const T rhs) } template -inline Color& operator*=(Color& lhs, const Color& rhs) -{ +inline Color& operator*=(Color& lhs, const Color& rhs) { for (size_t i = 0; i < N; ++i) lhs[i] *= rhs[i]; @@ -983,14 +889,12 @@ inline Color& operator*=(Color& lhs, const Color& rhs) } template -inline Color& operator/=(Color& lhs, const T rhs) -{ +inline Color& operator/=(Color& lhs, const T rhs) { return lhs *= (T(1.0) / rhs); } template -inline Color& operator/=(Color& lhs, const Color& rhs) -{ +inline Color& operator/=(Color& lhs, const Color& rhs) { for (size_t i = 0; i < N; ++i) lhs[i] /= rhs[i]; @@ -998,8 +902,7 @@ inline Color& operator/=(Color& lhs, const Color& rhs) } template -inline Color clamp(const Color& c, const T min, const T max) -{ +inline Color clamp(const Color& c, const T min, const T max) { Color col; for (size_t i = 0; i < N; ++i) @@ -1009,8 +912,7 @@ inline Color clamp(const Color& c, const T min, const T max) } template -inline Color saturate(const Color& c) -{ +inline Color saturate(const Color& c) { Color col; for (size_t i = 0; i < N; ++i) @@ -1020,12 +922,10 @@ inline Color saturate(const Color& c) } template -inline T min_value(const Color& c) -{ +inline T min_value(const Color& c) { T value = c[0]; - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { if (value > c[i]) value = c[i]; } @@ -1034,12 +934,10 @@ inline T min_value(const Color& c) } template -inline T max_value(const Color& c) -{ +inline T max_value(const Color& c) { T value = c[0]; - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { if (value < c[i]) value = c[i]; } @@ -1048,17 +946,14 @@ inline T max_value(const Color& c) } template -inline size_t min_index(const Color& c) -{ +inline size_t min_index(const Color& c) { size_t index = 0; T value = c[0]; - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { const T x = c[i]; - if (value > x) - { + if (value > x) { value = x; index = i; } @@ -1068,17 +963,14 @@ inline size_t min_index(const Color& c) } template -inline size_t max_index(const Color& c) -{ +inline size_t max_index(const Color& c) { size_t index = 0; T value = c[0]; - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { const T x = c[i]; - if (value < x) - { + if (value < x) { value = x; index = i; } @@ -1088,17 +980,14 @@ inline size_t max_index(const Color& c) } template -inline size_t min_abs_index(const Color& c) -{ +inline size_t min_abs_index(const Color& c) { size_t index = 0; T value = std::abs(c[0]); - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { const T x = std::abs(c[i]); - if (value > x) - { + if (value > x) { value = x; index = i; } @@ -1108,17 +997,14 @@ inline size_t min_abs_index(const Color& c) } template -inline size_t max_abs_index(const Color& c) -{ +inline size_t max_abs_index(const Color& c) { size_t index = 0; T value = std::abs(c[0]); - for (size_t i = 1; i < N; ++i) - { + for (size_t i = 1; i < N; ++i) { const T x = std::abs(c[i]); - if (value < x) - { + if (value < x) { value = x; index = i; } @@ -1128,8 +1014,7 @@ inline size_t max_abs_index(const Color& c) } template -inline T average_value(const Color& c) -{ +inline T average_value(const Color& c) { T average = c[0]; for (size_t i = 1; i < N; ++i) @@ -1143,46 +1028,37 @@ inline T average_value(const Color& c) // template -inline Color::Color() -{ +inline Color::Color() { } template -inline Color::Color(const ValueType* rhs) -{ +inline Color::Color(const ValueType* rhs) { assert(rhs); grayvalue = rhs[0]; } template -inline Color::Color(const ValueType grayvalue) - : g(grayvalue) -{ +inline Color::Color(const ValueType grayvalue) : g(grayvalue) { } template template -inline Color::Color(const Color& rhs) - : g(static_cast(rhs.g)) -{ +inline Color::Color(const Color& rhs) : g(static_cast(rhs.g)) { } template -inline void Color::set(const ValueType val) -{ +inline void Color::set(const ValueType val) { g = val; } template -inline T& Color::operator[](const size_t i) -{ +inline T& Color::operator[](const size_t i) { assert(i < Components); return (&g)[i]; } template -inline const T& Color::operator[](const size_t i) const -{ +inline const T& Color::operator[](const size_t i) const { assert(i < Components); return (&g)[i]; } @@ -1192,13 +1068,11 @@ inline const T& Color::operator[](const size_t i) const // template -inline Color::Color() -{ +inline Color::Color() { } template -inline Color::Color(const ValueType* rhs) -{ +inline Color::Color(const ValueType* rhs) { assert(rhs); r = rhs[0]; g = rhs[1]; @@ -1206,66 +1080,45 @@ inline Color::Color(const ValueType* rhs) } template -inline Color::Color(const ValueType val) - : r(val) - , g(val) - , b(val) -{ +inline Color::Color(const ValueType val) : r(val), g(val), b(val) { } template -inline Color::Color( - const ValueType r_, - const ValueType g_, - const ValueType b_) - : r(r_) - , g(g_) - , b(b_) -{ +inline Color::Color(const ValueType r_, const ValueType g_, const ValueType b_) : r(r_), g(g_), b(b_) { } template template -inline Color::Color(const Color& rhs) - : r(static_cast(rhs.r)) - , g(static_cast(rhs.g)) - , b(static_cast(rhs.b)) -{ +inline Color::Color(const Color& rhs) : r(static_cast(rhs.r)), g(static_cast(rhs.g)), b(static_cast(rhs.b)) { } template -inline void Color::set(const ValueType val) -{ +inline void Color::set(const ValueType val) { r = g = b = val; } template -inline T& Color::operator[](const size_t i) -{ +inline T& Color::operator[](const size_t i) { assert(i < Components); return (&r)[i]; } template -inline const T& Color::operator[](const size_t i) const -{ +inline const T& Color::operator[](const size_t i) const { assert(i < Components); return (&r)[i]; } - // // RGBA color implementation. // template -inline Color::Color() -{ +inline Color::Color() { } template -inline Color::Color(const ValueType* rhs) -{ +inline Color::Color(const ValueType* rhs) { assert(rhs); r = rhs[0]; g = rhs[1]; @@ -1274,51 +1127,25 @@ inline Color::Color(const ValueType* rhs) } template -inline Color::Color(const ValueType val) - : r(val) - , g(val) - , b(val) - , a(val) -{ +inline Color::Color(const ValueType val) : r(val), g(val), b(val), a(val) { } template -inline Color::Color( - const Color& rgb, - const ValueType a_) - : r(rgb.r) - , g(rgb.g) - , b(rgb.b) - , a(a_) -{ +inline Color::Color(const Color& rgb, const ValueType a_) : r(rgb.r), g(rgb.g), b(rgb.b), a(a_) { } template -inline Color::Color( - const ValueType r_, - const ValueType g_, - const ValueType b_, - const ValueType a_) - : r(r_) - , g(g_) - , b(b_) - , a(a_) -{ +inline Color::Color(const ValueType r_, const ValueType g_, const ValueType b_, const ValueType a_) : r(r_), g(g_), b(b_), a(a_) { } template template inline Color::Color(const Color& rhs) - : r(static_cast(rhs.r)) - , g(static_cast(rhs.g)) - , b(static_cast(rhs.b)) - , a(static_cast(rhs.a)) -{ + : r(static_cast(rhs.r)), g(static_cast(rhs.g)), b(static_cast(rhs.b)), a(static_cast(rhs.a)) { } template -inline void Color::set(const ValueType val) -{ +inline void Color::set(const ValueType val) { r = g = b = a = val; } @@ -1327,7 +1154,7 @@ inline void Color::set(const ValueType val) // { // return *reinterpret_cast*>(&r); // } -// +// // template // inline const color& color::rgb() const // { @@ -1335,15 +1162,13 @@ inline void Color::set(const ValueType val) // } template -inline T& Color::operator[](const size_t i) -{ +inline T& Color::operator[](const size_t i) { assert(i < Components); return (&r)[i]; } template -inline const T& Color::operator[](const size_t i) const -{ +inline const T& Color::operator[](const size_t i) const { assert(i < Components); return (&r)[i]; } @@ -1351,8 +1176,7 @@ inline const T& Color::operator[](const size_t i) const // helper/util functions // applies game correction to a given color template -Color gammaCorrect( const Color& c, T gamma ) -{ +Color gammaCorrect(const Color& c, T gamma) { T power = 1.0f / gamma; Color temp = c; @@ -1363,11 +1187,8 @@ Color gammaCorrect( const Color& c, T gamma ) } template -inline std::ostream& -operator<<(std::ostream& os, const Color& v) -{ - for (size_t i = 0; i < v.Components; ++i) - { +inline std::ostream& operator<<(std::ostream& os, const Color& v) { + for (size_t i = 0; i < v.Components; ++i) { os << "["; os << " " << v[i]; @@ -1383,11 +1204,11 @@ BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END // Overload std::min() and std::max() for component-wise min/max operations on colors. // -//namespace std +// namespace std //{ // -//template -//inline foundation::Color min(const foundation::Color& lhs, const foundation::Color& rhs) +// template +// inline foundation::Color min(const foundation::Color& lhs, const foundation::Color& rhs) //{ // foundation::Color col; // @@ -1397,8 +1218,8 @@ BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END // return col; //} // -//template -//inline foundation::Color max(const foundation::Color& lhs, const foundation::Color& rhs) +// template +// inline foundation::Color max(const foundation::Color& lhs, const foundation::Color& rhs) //{ // foundation::Color col; // diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/ImageFilter.h b/ImageProcessing/src/BlueFramework/ImageProcessing/ImageFilter.h index c529eca..a783050 100644 --- a/ImageProcessing/src/BlueFramework/ImageProcessing/ImageFilter.h +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/ImageFilter.h @@ -1,7 +1,7 @@ /* This file is part of BlueFramework, a simple 3D engine. - Copyright (c) 2016-2017 Technical University of Munich - Chair of Computational Modeling and Simulation. + Copyright (c) 2016-2017 Technical University of Munich + Chair of Computational Modeling and Simulation. BlueFramework is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 @@ -20,145 +20,131 @@ #ifndef BlueFramework_ImageProcessing_ImageFilter_01b74518_66c3_44bd_bde8_68720fa5d1f2_h #define BlueFramework_ImageProcessing_ImageFilter_01b74518_66c3_44bd_bde8_68720fa5d1f2_h -#include "BlueFramework/ImageProcessing/namespace.h" #include "BlueFramework/ImageProcessing/Image.h" +#include "BlueFramework/ImageProcessing/namespace.h" #include "BlueFramework/Core/Math/Matrix.h" #include "BlueFramework/Core/Math/Vector.h" BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN -enum ePaddingStrategy { - Mirror -}; +enum ePaddingStrategy { Mirror }; -enum eFilterSize { - Small = 3, - Medium = 5, - Large = 7 -}; +enum eFilterSize { Small = 3, Medium = 5, Large = 7 }; struct filterDescription { - eFilterSize filterSize; - ePaddingStrategy strategy; + eFilterSize filterSize; + ePaddingStrategy strategy; }; -template inline buw::Image> applyGaussian(buw::Image> image, buw::Matrix22f sigma) - { - auto square = [](float x) { return x * x; }; +template +inline buw::Image> applyGaussian(buw::Image> image, buw::Matrix22f sigma) { + auto square = [](float x) { return x * x; }; - buw::Vector2f mean = buw::Vector2f(S / 2, S / 2); - eFilterSize filterSize = (eFilterSize) S; - float amplitude = 1.0f / std::sqrtf(square(2.0f*M_PI)* sigma.determinant()); + buw::Vector2f mean = buw::Vector2f(S / 2, S / 2); + eFilterSize filterSize = (eFilterSize)S; + float amplitude = 1.0f / std::sqrtf(square(2.0f * M_PI) * sigma.determinant()); - buw::Matrix matrix; + buw::Matrix matrix; - float sum = 0.0f; + float sum = 0.0f; - for(int y = 0; y < filterSize; y++) { - for(int x = 0; x < filterSize; x++) { - buw::Vector2f pos = buw::Vector2f(x, y); - matrix(x, y) = amplitude * std::expf(-0.5f*((pos-mean).transpose()*(sigma.inverse())*(pos - mean))[0]); - sum += matrix(x, y); - } - } - matrix /= sum; - - - buw::Image> filteredImage = buw::Image>(image.getWidth(), image.getHeight()); - buw::Image> paddedImage = createPaddedImage(image, filterSize); - int offset = 2; - switch(filterSize) { - case eFilterSize::Small: - offset = 2; - break; - case eFilterSize::Medium: - offset = 1; - break; - case eFilterSize::Large: - offset = 0; - break; - default: - offset = 2; - break; + for (int y = 0; y < filterSize; y++) { + for (int x = 0; x < filterSize; x++) { + buw::Vector2f pos = buw::Vector2f(x, y); + matrix(x, y) = amplitude * std::expf(-0.5f * ((pos - mean).transpose() * (sigma.inverse()) * (pos - mean))[0]); + sum += matrix(x, y); } + } + matrix /= sum; + + buw::Image> filteredImage = buw::Image>(image.getWidth(), image.getHeight()); + buw::Image> paddedImage = createPaddedImage(image, filterSize); + int offset = 2; + switch (filterSize) { + case eFilterSize::Small: offset = 2; break; + case eFilterSize::Medium: offset = 1; break; + case eFilterSize::Large: offset = 0; break; + default: offset = 2; break; + } #pragma omp parallel for - for(int y = offset; y < filteredImage.getHeight() + offset; y++) { - for(int x = offset; x < filteredImage.getWidth() + offset; x++) { - buw::Vector value; - value.setZero(); - for(int i = 0; i < filterSize; i++) { - for(int j = 0; j < filterSize; j++) { - buw::Color color = paddedImage.getPixelColor(x + i - offset, y + j - offset); - for(int idx = 0; idx < N; idx++) { - value[idx] += (float)color[idx] * matrix(i, j); - } + for (int y = offset; y < filteredImage.getHeight() + offset; y++) { + for (int x = offset; x < filteredImage.getWidth() + offset; x++) { + buw::Vector value; + value.setZero(); + for (int i = 0; i < filterSize; i++) { + for (int j = 0; j < filterSize; j++) { + buw::Color color = paddedImage.getPixelColor(x + i - offset, y + j - offset); + for (int idx = 0; idx < N; idx++) { + value[idx] += (float)color[idx] * matrix(i, j); } } - buw::Color color; - for(int idx = 0; idx < N; idx++) - color[idx] = (T)value[idx]; - - filteredImage.setPixelColor(x - offset, y - offset, color); } + buw::Color color; + for (int idx = 0; idx < N; idx++) + color[idx] = (T)value[idx]; + + filteredImage.setPixelColor(x - offset, y - offset, color); } - return filteredImage; } + return filteredImage; +} -template inline buw::Image> createPaddedImage(buw::Image> image, eFilterSize filterSize) - { - buw::Image> paddedImage(image.getWidth() + filterSize - 1, image.getHeight() + filterSize - 1); +template +inline buw::Image> createPaddedImage(buw::Image> image, eFilterSize filterSize) { + buw::Image> paddedImage(image.getWidth() + filterSize - 1, image.getHeight() + filterSize - 1); - for(int y = 0; y < (filterSize - 1) / 2; y++) { + for (int y = 0; y < (filterSize - 1) / 2; y++) { #pragma omp parallel for - for(int x = 0; x < image.getWidth(); x++) { - buw::Color color = image.getPixelColor(x, y); - paddedImage.setPixelColor(x + ((filterSize - 1) / 2), ((filterSize - 1) / 2) - 1 - y, color); + for (int x = 0; x < image.getWidth(); x++) { + buw::Color color = image.getPixelColor(x, y); + paddedImage.setPixelColor(x + ((filterSize - 1) / 2), ((filterSize - 1) / 2) - 1 - y, color); - color = image.getPixelColor(x, image.getHeight() - 1 - y); - paddedImage.setPixelColor(x + ((filterSize - 1) / 2), image.getHeight() + y, color); - } + color = image.getPixelColor(x, image.getHeight() - 1 - y); + paddedImage.setPixelColor(x + ((filterSize - 1) / 2), image.getHeight() + y, color); } + } #pragma omp parallel for - for(int y = 0; y < image.getHeight(); y++) { - for(int x = 0; x < (filterSize - 1) / 2; x++) { - buw::Color color = image.getPixelColor(x, y); - paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, y + ((filterSize - 1) / 2), color); + for (int y = 0; y < image.getHeight(); y++) { + for (int x = 0; x < (filterSize - 1) / 2; x++) { + buw::Color color = image.getPixelColor(x, y); + paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, y + ((filterSize - 1) / 2), color); - color = image.getPixelColor(image.getWidth() - 1 - x, y); - paddedImage.setPixelColor(image.getWidth() + x, y + ((filterSize - 1) / 2), color); - } + color = image.getPixelColor(image.getWidth() - 1 - x, y); + paddedImage.setPixelColor(image.getWidth() + x, y + ((filterSize - 1) / 2), color); } + } - for(int y = 0; y < (filterSize - 1) / 2; y++) { - for(int x = 0; x < (filterSize - 1) / 2; x++) { - buw::Color color = image.getPixelColor(x, y); - paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, ((filterSize - 1) / 2) - 1 - y, color); + for (int y = 0; y < (filterSize - 1) / 2; y++) { + for (int x = 0; x < (filterSize - 1) / 2; x++) { + buw::Color color = image.getPixelColor(x, y); + paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, ((filterSize - 1) / 2) - 1 - y, color); - color = image.getPixelColor(image.getWidth() - 1 - x, y); - paddedImage.setPixelColor(image.getWidth() + x, ((filterSize - 1) / 2) - 1 - y, color); + color = image.getPixelColor(image.getWidth() - 1 - x, y); + paddedImage.setPixelColor(image.getWidth() + x, ((filterSize - 1) / 2) - 1 - y, color); - color = image.getPixelColor(x, image.getHeight() - 1 - y); - paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, image.getHeight() + y, color); + color = image.getPixelColor(x, image.getHeight() - 1 - y); + paddedImage.setPixelColor(((filterSize - 1) / 2) - 1 - x, image.getHeight() + y, color); - color = image.getPixelColor(image.getWidth() - 1 - x, image.getHeight() - 1 - y); - paddedImage.setPixelColor(image.getWidth() + x, image.getHeight() + y, color); - } + color = image.getPixelColor(image.getWidth() - 1 - x, image.getHeight() - 1 - y); + paddedImage.setPixelColor(image.getWidth() + x, image.getHeight() + y, color); } + } #pragma omp parallel for - for(int y = 0; y < image.getHeight(); y++) { - for(int x = 0; x < image.getWidth(); x++) { - paddedImage.setPixelColor(x + (filterSize - 1) / 2, y + (filterSize - 1) / 2, image.getPixelColor(x, y)); - } + for (int y = 0; y < image.getHeight(); y++) { + for (int x = 0; x < image.getWidth(); x++) { + paddedImage.setPixelColor(x + (filterSize - 1) / 2, y + (filterSize - 1) / 2, image.getPixelColor(x, y)); } - - return paddedImage; } + return paddedImage; +} + BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END +BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(applyGaussian) BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(filterDescription); BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(eFilterSize); BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(ePaddingStrategy); diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.cpp b/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.cpp new file mode 100644 index 0000000..45319a8 --- /dev/null +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.cpp @@ -0,0 +1,35 @@ +/* + This file is part of BlueFramework, a simple 3D engine. + Copyright (c) 2016 Technical University of Munich + Chair of Computational Modeling and Simulation. + + BlueFramework is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + BlueFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include + +void captureScreen() { + QScreen *screen = QGuiApplication::primaryScreen(); + + if (!screen) + return; + + auto originalPixmap = screen->grabWindow(0); + + originalPixmap.save("C:/temp/screen.png"); + +} diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.h b/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.h new file mode 100644 index 0000000..5c1a952 --- /dev/null +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/captureScreen.h @@ -0,0 +1,33 @@ +/* + This file is part of BlueFramework, a simple 3D engine. + Copyright (c) 2016 Technical University of Munich + Chair of Computational Modeling and Simulation. + + BlueFramework is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + BlueFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once +#ifndef BlueFramework_ImageProcessing_captureScreen_9e8a5485_df06_42f6_b96f_0fc986cf0d7b_h +#define BlueFramework_ImageProcessing_captureScreen_9e8a5485_df06_42f6_b96f_0fc986cf0d7b_h + +#include "BlueFramework/ImageProcessing/namespace.h" + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN + +void captureScreen(); + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END + +BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(captureScreen) + +#endif // end define BlueFramework_ImageProcessing_captureScreen_9e8a5485_df06_42f6_b96f_0fc986cf0d7b_h diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/difference.cpp b/ImageProcessing/src/BlueFramework/ImageProcessing/difference.cpp new file mode 100644 index 0000000..5ddd457 --- /dev/null +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/difference.cpp @@ -0,0 +1,110 @@ +/* + This file is part of BlueFramework, a simple 3D engine. + Copyright (c) 2016 Technical University of Munich + Chair of Computational Modeling and Simulation. + + BlueFramework is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + BlueFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "BlueFramework/ImageProcessing/difference.h" +#include "BlueFramework/ImageProcessing/Color.h" + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN + +bool areEqual( + buw::ReferenceCounted a, + buw::ReferenceCounted b) +{ + BLUE_ASSERT(a->getWidth() == b->getWidth(), "different widths"); + BLUE_ASSERT(a->getHeight() == b->getHeight(), "different heights"); + + if (a->getWidth() != b->getWidth() || + a->getHeight() != b->getHeight()) + { + return false; + } + + int width = a->getWidth(); + int height = a->getHeight(); + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + if (a->getPixelColor(x, y) != b->getPixelColor(x, y)) + return false; + } + } + + return true; +} + +buw::ReferenceCounted createDifferenceImage(buw::ReferenceCounted a, buw::ReferenceCounted b, const std::uint8_t color[3]) { + buw::ReferenceCounted tmp = std::make_shared(a->getWidth(), b->getHeight()); + + for (int y = 0; y < a->getHeight(); y++) { + for (int x = 0; x < a->getWidth(); x++) { + if (a->getPixelColor(x, y) != b->getPixelColor(x, y)) { + if (color) { + tmp->setPixelColor(x, y, buw::Color3b(color[0], color[1], color[2])); + } else { + tmp->setPixelColor(x, y, buw::Color3b(255, 0, 0)); + } + + } else { + tmp->setPixelColor(x, y, a->getPixelColor(x, y)); + } + } + } + + return tmp; +} + +buw::ReferenceCounted createDifferenceImage(buw::ReferenceCounted a, buw::ReferenceCounted b, const float color[4]) { + buw::ReferenceCounted tmp = std::make_shared(a->getWidth(), b->getHeight()); + + for (int y = 0; y < a->getHeight(); y++) { + for (int x = 0; x < a->getWidth(); x++) { + auto ca = a->getPixelColor(x, y); + auto cb = b->getPixelColor(x, y); + auto diff = ca - cb; + + if (ca != cb) { + tmp->setPixelColor(x, y, Color4f(color[0], color[1], color[2], color[3])); + } + + //diff = Color4f(std::abs(diff.r), std::abs(diff.g), std::abs(diff.b), 1.0f); + //tmp->setPixelColor(x, y, diff); + } + } + + return tmp; +} + +buw::ReferenceCounted highlightDifferences(buw::ReferenceCounted a, buw::ReferenceCounted b, const Color3b color) { + buw::ReferenceCounted tmp = std::make_shared(a->getWidth(), b->getHeight()); + + for (int y = 0; y < a->getHeight(); y++) { + for (int x = 0; x < a->getWidth(); x++) { + if (a->getPixelColor(x, y) != b->getPixelColor(x, y)) { + tmp->setPixelColor(x, y, color); + } else { + tmp->setPixelColor(x, y, Color3b(0, 0, 0)); + } + } + } + + return tmp; +} + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END \ No newline at end of file diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/difference.h b/ImageProcessing/src/BlueFramework/ImageProcessing/difference.h new file mode 100644 index 0000000..8b24701 --- /dev/null +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/difference.h @@ -0,0 +1,39 @@ +/* + This file is part of BlueFramework, a simple 3D engine. + Copyright (c) 2016 Technical University of Munich + Chair of Computational Modeling and Simulation. + + BlueFramework is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + BlueFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once +#ifndef BlueFramework_ImageProcessing_difference_91e49169_661c_4f4c_9c07_6588d56c1f01_h +#define BlueFramework_ImageProcessing_difference_91e49169_661c_4f4c_9c07_6588d56c1f01_h + +#include "BlueFramework/Core/memory.h" +#include "BlueFramework/ImageProcessing/Image.h" +#include "BlueFramework/ImageProcessing/namespace.h" + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN + +bool areEqual(buw::ReferenceCounted a, buw::ReferenceCounted b); +buw::ReferenceCounted highlightDifferences(buw::ReferenceCounted a, buw::ReferenceCounted b, const Color3b color); +buw::ReferenceCounted createDifferenceImage(buw::ReferenceCounted a, buw::ReferenceCounted b, const float Color[4]); +buw::ReferenceCounted createDifferenceImage(buw::ReferenceCounted a, buw::ReferenceCounted b, const std::uint8_t color[3]); + +BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END + +BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(highlightDifferences) +BLUE_BLUEFRAMEWORK_IMAGEPROCESSING_EMBED_INTO_BUW_NAMESPACE(createDifferenceImage) + +#endif // end define BlueFramework_ImageProcessing_difference_91e49169_661c_4f4c_9c07_6588d56c1f01_h diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.cpp b/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.cpp index 59feedf..3a973c0 100644 --- a/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.cpp +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.cpp @@ -1,7 +1,7 @@ /* This file is part of BlueFramework, a simple 3D engine. - Copyright (c) 2016-2017 Technical University of Munich - Chair of Computational Modeling and Simulation. + Copyright (c) 2016-2017 Technical University of Munich + Chair of Computational Modeling and Simulation. BlueFramework is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 @@ -23,24 +23,23 @@ BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN -#define IDX(x,y,w) idx(x,y,w) +#define IDX(x, y, w) idx(x, y, w) unsigned int seed; std::default_random_engine generator; int idx(int x, int y, int w) { - - if(x >= w) - x = (w - 1) - (x - w); - if(x < 0) - x *= - 1; - if(y < 0) - y *= - 1; - if(y >= w) - y = (w - 1) - (y - w); - - int index = x + y*w; - return index; + if (x >= w) + x = (w - 1) - (x - w); + if (x < 0) + x *= -1; + if (y < 0) + y *= -1; + if (y >= w) + y = (w - 1) - (y - w); + + int index = x + y * w; + return index; } bool isEven(const int number) { return number % 2 == 0; @@ -56,8 +55,7 @@ Image4b generateCheckerboardImage(const int width, const int height) { img.setPixelColorStandardCartesian(x, y, buw::Color4b(255, 0, 0, 255)); else img.setPixelColorStandardCartesian(x, y, buw::Color4b(255, 255, 255, 255)); - } - else { + } else { if (isEven(y / 20)) img.setPixelColorStandardCartesian(x, y, buw::Color4b(255, 255, 255, 255)); else @@ -70,163 +68,150 @@ Image4b generateCheckerboardImage(const int width, const int height) { } float normal_distributed_random(float mean, float sigma) { - std::normal_distribution distribution(mean, sigma); - return distribution(generator); + std::normal_distribution distribution(mean, sigma); + return distribution(generator); } float uniform_distributed_random(float roughness, int iteration) { - float max = std::powf(roughness, iteration + 1); - float min = -max; - std::uniform_real_distribution distribution(min, max); - return distribution(generator); + float max = std::powf(roughness, iteration + 1); + float min = -max; + std::uniform_real_distribution distribution(min, max); + return distribution(generator); } void normalize(std::vector &heightfield, int resolution) { - float minimum = heightfield[0]; - float maximum = 0.0; - - for(int y = 0; y <= resolution; y++) { - for(int x = 0; x <= resolution; x++) { - if(heightfield[idx(x, y, resolution + 1)] < minimum) - minimum = heightfield[idx(x, y, resolution + 1)]; - } - } - - for(int y = 0; y <= resolution; y++) { - for(int x = 0; x <= resolution; x++) { - heightfield[idx(x, y, resolution + 1)] -= minimum; - } - } - - for(int y = 0; y <= resolution; y++) { - for(int x = 0; x <= resolution; x++) { - if(heightfield[idx(x, y, resolution + 1)] > maximum) - maximum = heightfield[idx(x, y, resolution + 1)]; - } - } - - for(int y = 0; y <= resolution; y++) { - for(int x = 0; x <= resolution; x++) { - heightfield[idx(x, y, resolution + 1)] /= maximum; - } - } + float minimum = heightfield[0]; + float maximum = 0.0; + + for (int y = 0; y <= resolution; y++) { + for (int x = 0; x <= resolution; x++) { + if (heightfield[idx(x, y, resolution + 1)] < minimum) + minimum = heightfield[idx(x, y, resolution + 1)]; + } + } + + for (int y = 0; y <= resolution; y++) { + for (int x = 0; x <= resolution; x++) { + heightfield[idx(x, y, resolution + 1)] -= minimum; + } + } + + for (int y = 0; y <= resolution; y++) { + for (int x = 0; x <= resolution; x++) { + if (heightfield[idx(x, y, resolution + 1)] > maximum) + maximum = heightfield[idx(x, y, resolution + 1)]; + } + } + + for (int y = 0; y <= resolution; y++) { + for (int x = 0; x <= resolution; x++) { + heightfield[idx(x, y, resolution + 1)] /= maximum; + } + } } void normalize(std::vector &normalMap, int resolution) { - for(int i = 0; i <= resolution; i++) { - for(int j = 0; j <= resolution; j++) { - normalMap[idx(j, i, resolution + 1)].x() += 1.0f; - normalMap[idx(j, i, resolution + 1)].y() += 1.0f; - normalMap[idx(j, i, resolution + 1)].z() += 1.0f; - - normalMap[idx(j, i, resolution + 1)].x() /= 2.0f; - normalMap[idx(j, i, resolution + 1)].y() /= 2.0f; - normalMap[idx(j, i, resolution + 1)].z() /= 2.0f; - } - } + for (int i = 0; i <= resolution; i++) { + for (int j = 0; j <= resolution; j++) { + normalMap[idx(j, i, resolution + 1)].x() += 1.0f; + normalMap[idx(j, i, resolution + 1)].y() += 1.0f; + normalMap[idx(j, i, resolution + 1)].z() += 1.0f; + + normalMap[idx(j, i, resolution + 1)].x() /= 2.0f; + normalMap[idx(j, i, resolution + 1)].y() /= 2.0f; + normalMap[idx(j, i, resolution + 1)].z() /= 2.0f; + } + } } void initialize(std::vector &heightfield, int resolution, float mean, float sigma) { + for (int i = 0; i <= resolution; i++) { + for (int j = 0; j <= resolution; j++) { + heightfield[idx(j, i, resolution + 1)] = 0.0; + } + } - for(int i = 0; i <= resolution; i++) { - for(int j = 0; j <= resolution; j++) { - heightfield[idx(j, i, resolution + 1)] = 0.0; - } - } - - heightfield[idx(0, 0, resolution + 1)] = normal_distributed_random(mean, sigma); - heightfield[idx(0, resolution, resolution + 1)] = normal_distributed_random(mean, sigma); - heightfield[idx(resolution, 0, resolution + 1)] = normal_distributed_random(mean, sigma); - heightfield[idx(resolution, resolution, resolution + 1)] = normal_distributed_random(mean, sigma); + heightfield[idx(0, 0, resolution + 1)] = normal_distributed_random(mean, sigma); + heightfield[idx(0, resolution, resolution + 1)] = normal_distributed_random(mean, sigma); + heightfield[idx(resolution, 0, resolution + 1)] = normal_distributed_random(mean, sigma); + heightfield[idx(resolution, resolution, resolution + 1)] = normal_distributed_random(mean, sigma); } void diamondStep(std::vector &heightfield, int startx, int starty, int resolution, int iteration, float roughness) { - int resolution_global = resolution * pow(2, iteration) + 1; - - float values[4] = { - heightfield[idx(startx, starty, resolution_global)], - heightfield[idx(startx + resolution, starty, resolution_global)], - heightfield[idx(startx, starty + resolution, resolution_global)], - heightfield[idx(startx + resolution, starty + resolution, resolution_global)] - }; - - float average = (values[0] + values[1] + values[2] + values[3]) / 4.0f; - int pos = idx(startx + resolution / 2, starty + resolution / 2, resolution_global); - heightfield[pos] = average + uniform_distributed_random(roughness, iteration); + int resolution_global = resolution * pow(2, iteration) + 1; + + float values[4] = {heightfield[idx(startx, starty, resolution_global)], heightfield[idx(startx + resolution, starty, resolution_global)], + heightfield[idx(startx, starty + resolution, resolution_global)], heightfield[idx(startx + resolution, starty + resolution, resolution_global)]}; + + float average = (values[0] + values[1] + values[2] + values[3]) / 4.0f; + int pos = idx(startx + resolution / 2, starty + resolution / 2, resolution_global); + heightfield[pos] = average + uniform_distributed_random(roughness, iteration); } void squareStep(std::vector &heightfield, int startx, int starty, int resolution, int iteration, float roughness) { - int resolution_global = resolution * pow(2, iteration) + 1; - float values[9] = { - heightfield[idx(startx, starty - resolution, resolution_global)], - heightfield[idx(startx - (resolution / 2),starty - (resolution / 2), resolution_global)], - heightfield[idx(startx + (resolution / 2),starty - (resolution / 2), resolution_global)], - heightfield[idx(startx - resolution,starty, resolution_global)], - heightfield[idx(startx, starty, resolution_global)], - heightfield[idx(startx + resolution,starty, resolution_global)], - heightfield[idx(startx - (resolution / 2),starty + (resolution / 2), resolution_global)], - heightfield[idx(startx + (resolution / 2),starty + (resolution / 2), resolution_global)], - heightfield[idx(startx, starty + resolution, resolution_global)] - }; - - int pos0 = idx(startx, starty - resolution / 2, resolution_global), - pos1 = idx(startx + resolution / 2, starty, resolution_global), - pos2 = idx(startx, starty + resolution / 2, resolution_global), - pos3 = idx(startx - resolution / 2, starty, resolution_global); - - float h0 = (values[0] + values[1] + values[2] + values[4]) / 4.0f, - h1 = (values[2] + values[4] + values[5] + values[7]) / 4.0f, - h2 = (values[4] + values[6] + values[7] + values[8]) / 4.0f, - h3 = (values[1] + values[3] + values[4] + values[6]) / 4.0f; - - heightfield[pos0] = h0 + uniform_distributed_random(roughness, iteration); - heightfield[pos1] = h1 + uniform_distributed_random(roughness, iteration); - heightfield[pos2] = h2 + uniform_distributed_random(roughness, iteration); - heightfield[pos3] = h3 + uniform_distributed_random(roughness, iteration); + int resolution_global = resolution * pow(2, iteration) + 1; + float values[9] = {heightfield[idx(startx, starty - resolution, resolution_global)], + heightfield[idx(startx - (resolution / 2), starty - (resolution / 2), resolution_global)], + heightfield[idx(startx + (resolution / 2), starty - (resolution / 2), resolution_global)], + heightfield[idx(startx - resolution, starty, resolution_global)], + heightfield[idx(startx, starty, resolution_global)], + heightfield[idx(startx + resolution, starty, resolution_global)], + heightfield[idx(startx - (resolution / 2), starty + (resolution / 2), resolution_global)], + heightfield[idx(startx + (resolution / 2), starty + (resolution / 2), resolution_global)], + heightfield[idx(startx, starty + resolution, resolution_global)]}; + + int pos0 = idx(startx, starty - resolution / 2, resolution_global), pos1 = idx(startx + resolution / 2, starty, resolution_global), + pos2 = idx(startx, starty + resolution / 2, resolution_global), pos3 = idx(startx - resolution / 2, starty, resolution_global); + + float h0 = (values[0] + values[1] + values[2] + values[4]) / 4.0f, h1 = (values[2] + values[4] + values[5] + values[7]) / 4.0f, + h2 = (values[4] + values[6] + values[7] + values[8]) / 4.0f, h3 = (values[1] + values[3] + values[4] + values[6]) / 4.0f; + + heightfield[pos0] = h0 + uniform_distributed_random(roughness, iteration); + heightfield[pos1] = h1 + uniform_distributed_random(roughness, iteration); + heightfield[pos2] = h2 + uniform_distributed_random(roughness, iteration); + heightfield[pos3] = h3 + uniform_distributed_random(roughness, iteration); } void diamondSquareIterative(std::vector &heightfield, int resolution, float roughness) { - int iteration = 0; - while(resolution > 1) { - for(int y = 0; y < resolution * pow(2, iteration); y += resolution) { - for(int x = 0; x < resolution * pow(2, iteration); x += resolution) { - diamondStep(heightfield, x, y, resolution, iteration, roughness); - } - } - - for(int y = 0; y < resolution * pow(2, iteration); y += resolution) { - for(int x = 0; x < resolution * pow(2, iteration); x += resolution) { - squareStep(heightfield, x + resolution / 2, y + resolution / 2, resolution, iteration, roughness); - } - } - resolution = resolution / 2; - iteration++; - } + int iteration = 0; + while (resolution > 1) { + for (int y = 0; y < resolution * pow(2, iteration); y += resolution) { + for (int x = 0; x < resolution * pow(2, iteration); x += resolution) { + diamondStep(heightfield, x, y, resolution, iteration, roughness); + } + } + + for (int y = 0; y < resolution * pow(2, iteration); y += resolution) { + for (int x = 0; x < resolution * pow(2, iteration); x += resolution) { + squareStep(heightfield, x + resolution / 2, y + resolution / 2, resolution, iteration, roughness); + } + } + resolution = resolution / 2; + iteration++; + } } -Image4b generateRandomHeightmap(const int lod, float roughness, float mean, float sigma) -{ - seed = clock(); - generator.seed(seed); - int resolution = std::pow(2, lod); - std::vector heightfield = std::vector((resolution + 1)*(resolution + 1)); - - initialize(heightfield, resolution, mean, sigma); - diamondSquareIterative(heightfield, resolution, roughness); - normalize(heightfield, resolution); - buw::Image4b heightmap = buw::Image4b(resolution, resolution); - - for(int y = 0; y < resolution; y++) { - for(int x = 0; x < resolution; x++) { - float value = heightfield[idx(x, y, resolution + 1)]; +Image4b generateRandomHeightmap(const int lod, float roughness, float mean, float sigma) { + seed = clock(); + generator.seed(seed); + int resolution = std::pow(2, lod); + std::vector heightfield = std::vector((resolution + 1) * (resolution + 1)); + + initialize(heightfield, resolution, mean, sigma); + diamondSquareIterative(heightfield, resolution, roughness); + normalize(heightfield, resolution); + buw::Image4b heightmap = buw::Image4b(resolution, resolution); + + for (int y = 0; y < resolution; y++) { + for (int x = 0; x < resolution; x++) { + float value = heightfield[idx(x, y, resolution + 1)]; buw::Color1f grayColor1f(value); buw::Color4b grayColor4b = ColorConverter::convertTo(grayColor1f); - heightmap.setPixelColor((unsigned int)x, (unsigned int)y, grayColor4b); - } - - } - return heightmap; + heightmap.setPixelColor((unsigned int)x, (unsigned int)y, grayColor4b); + } + } + return heightmap; } BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_END \ No newline at end of file diff --git a/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.h b/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.h index 25e5127..96d9dbe 100644 --- a/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.h +++ b/ImageProcessing/src/BlueFramework/ImageProcessing/proceduralTextureGeneration.h @@ -16,7 +16,6 @@ along with this program. If not, see . */ - #pragma once #ifndef BlueFramework_ImageProcessing_proceduralTextureGeneration_fb971c8e_c331_4e5d_b444_a1e6fc789732_h #define BlueFramework_ImageProcessing_proceduralTextureGeneration_fb971c8e_c331_4e5d_b444_a1e6fc789732_h diff --git a/Tools/fileHeaderGenerator.py b/Tools/fileHeaderGenerator.py index 7400114..a1b427b 100644 --- a/Tools/fileHeaderGenerator.py +++ b/Tools/fileHeaderGenerator.py @@ -61,15 +61,14 @@ def main(argv): print(textHeader) - print("") print("#pragma once") print("#ifndef BlueFramework_" + moduleName + "_" + className + "_" + strUuid + "_h") print("#define BlueFramework_" + moduleName + "_" + className + "_" + strUuid + "_h") print("") - print("BLUE_NAMESPACE_BLUEFRAMEWORK_" + moduleName.upper() + "_BEGIN") - print("") print("#include \"BlueFramework/" + moduleName + "/namespace.h\"") print("") + print("BLUEFRAMEWORK_" + moduleName.upper() + "_NAMESPACE_BEGIN") + print("class " + className + "{"); print("public:") @@ -82,7 +81,7 @@ def main(argv): print("};") print("") - print("BLUE_NAMESPACE_BLUEFRAMEWORK_" + moduleName.upper() + "_END") + print("BLUEFRAMEWORK_" + moduleName.upper() + "_NAMESPACE_END") print("") print("#endif // end define BlueFramework_" + moduleName + "_" + className + "_" + strUuid + "_h") diff --git a/UnitTests/src/BlueFramework/UnitTests/ImageProcessing/RandomHeightmapGeneration/randomHeightmapGeneration.cpp b/UnitTests/src/BlueFramework/UnitTests/ImageProcessing/RandomHeightmapGeneration/randomHeightmapGeneration.cpp index c500d98..55d8dcd 100644 --- a/UnitTests/src/BlueFramework/UnitTests/ImageProcessing/RandomHeightmapGeneration/randomHeightmapGeneration.cpp +++ b/UnitTests/src/BlueFramework/UnitTests/ImageProcessing/RandomHeightmapGeneration/randomHeightmapGeneration.cpp @@ -1,19 +1,19 @@ /* -This file is part of BlueFramework, a simple 3D engine. -Copyright (c) 2016-2017 Technical University of Munich -Chair of Computational Modeling and Simulation. - -BlueFramework is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License Version 3 -as published by the Free Software Foundation. - -BlueFramework is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . + This file is part of BlueFramework, a simple 3D engine. + Copyright (c) 2016-2017 Technical University of Munich + Chair of Computational Modeling and Simulation. + + BlueFramework is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + BlueFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include @@ -25,12 +25,11 @@ along with this program. If not, see . #include #include - TEST(ImageProcessing, RandomHeightmapGeneration) { buw::Image4b heightmap = buw::generateRandomHeightmap(10, 0.5f, 0.0f, 1.0f); - - buw::Image4b filtered = BlueFramework::ImageProcessing::applyGaussian(heightmap, buw::Matrix22f::Identity()); + + buw::Image4b filtered = buw::applyGaussian(heightmap, buw::Matrix22f::Identity()); buw::storeImage("heightmap.png", heightmap); buw::storeImage("heightmap_smoothed.png", filtered); -} \ No newline at end of file +}