Skip to content

Commit

Permalink
Merge pull request mmp#134 from Tom94/cpp20
Browse files Browse the repository at this point in the history
C++20 usage & other improvements
  • Loading branch information
Tom94 authored Dec 26, 2021
2 parents 5355390 + a05cbb4 commit 47d5b0d
Show file tree
Hide file tree
Showing 63 changed files with 2,119 additions and 1,125 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ jobs:

steps:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install cmake xorg-dev libglu1-mesa-dev zlib1g-dev zenity
run: sudo apt-get update && sudo apt-get install cmake gcc-10 g++-10 libglu1-mesa-dev xorg-dev zenity zlib1g-dev
- uses: actions/checkout@v1
with:
submodules: recursive
- name: CMake
run: cmake .
shell: bash
env:
CC: gcc-10
CXX: g++-10
- name: Build
run: make -j

build_macos:
name: Build on macOS
runs-on: macos-latest
runs-on: macos-11

steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# Python cache
__pycache__

# macOS
.DS_Store

# Development project files
*.sublime-project

Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
[submodule "dependencies/nanogui"]
path = dependencies/nanogui
url = https://github.com/Tom94/nanogui-1
[submodule "dependencies/eigen"]
path = dependencies/eigen
url = https://gitlab.com/libeigen/eigen.git
[submodule "dependencies/qoi"]
path = dependencies/qoi
url = https://github.com/phoboslab/qoi.git
29 changes: 19 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(
DESCRIPTION "High dynamic range (HDR) image comparison tool for graphics people. With an emphasis on OpenEXR images."
LANGUAGES C CXX
)
set(TEV_VERSION "1.18")
set(TEV_VERSION "1.20")

if (NOT TEV_DEPLOY)
set(TEV_VERSION "${TEV_VERSION}dev")
Expand All @@ -35,19 +35,15 @@ if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
# Disable annoying secure CRT warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")

# Parallel build
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

# 32 bit windows
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DEIGEN_DONT_ALIGN")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP24")

# Static build
set(CompilerFlags
Expand Down Expand Up @@ -117,20 +113,29 @@ if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()

# Disable warnings that are present in dependencies and irrelevant to us
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") # unused arguments
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd5054") # deprecated enum & operator

# To allow for wildcards in command-line path arguments on windows,
# we need to link to wsetargv.obj
# http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} wsetargv.obj")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register -Wno-deprecated-anon-enum-enum-conversion")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-misleading-indentation -Wno-deprecated-declarations")
endif()
endif()

# Coroutines need to be explicitly enabled on g++
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
endif()

set(TEV_LIBS clip IlmImf nanogui ${NANOGUI_EXTRA_LIBS})
if (MSVC)
set(TEV_LIBS ${TEV_LIBS} zlibstatic DirectXTex wsock32 ws2_32)
Expand All @@ -144,10 +149,13 @@ set(TEV_SOURCES
include/tev/imageio/ImageLoader.h src/imageio/ImageLoader.cpp
include/tev/imageio/ImageSaver.h src/imageio/ImageSaver.cpp
include/tev/imageio/PfmImageLoader.h src/imageio/PfmImageLoader.cpp
include/tev/imageio/QoiImageLoader.h src/imageio/QoiImageLoader.cpp
include/tev/imageio/QoiImageSaver.h src/imageio/QoiImageSaver.cpp
include/tev/imageio/StbiHdrImageSaver.h src/imageio/StbiHdrImageSaver.cpp
include/tev/imageio/StbiImageLoader.h src/imageio/StbiImageLoader.cpp
include/tev/imageio/StbiLdrImageSaver.h src/imageio/StbiLdrImageSaver.cpp

include/tev/Box.h src/Box.cpp
include/tev/Channel.h src/Channel.cpp
include/tev/Common.h src/Common.cpp
include/tev/FalseColor.h src/FalseColor.cpp
Expand All @@ -160,6 +168,7 @@ set(TEV_SOURCES
include/tev/Lazy.h src/Lazy.cpp
include/tev/MultiGraph.h src/MultiGraph.cpp
include/tev/SharedQueue.h src/SharedQueue.cpp
include/tev/Task.h src/Task.cpp
include/tev/ThreadPool.h src/ThreadPool.cpp
include/tev/UberShader.h src/UberShader.cpp

Expand Down Expand Up @@ -194,12 +203,12 @@ include_directories(
${ARGS_INCLUDE}
${CLIP_INCLUDE}
${DIRECTXTEX_INCLUDE}
${EIGEN_INCLUDE}
${FILESYSTEM_INCLUDE}
${GLFW_INCLUDE}
${NANOGUI_EXTRA_INCS}
${NANOGUI_INCLUDE}
${OPENEXR_INCLUDE_DIRS}
${QOI_INCLUDE}
${STB_INCLUDE}
${TINYFORMAT_INCLUDE}
${TINYLOGGER_INCLUDE}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __New__: __tev__ can display true HDR on Apple extended dynamic range (EDR) and
While the predominantly supported file format is OpenEXR certain other types of images can also be loaded. The following file formats are currently supported:
- __EXR__ (via [OpenEXR](https://github.com/wjakob/openexr))
- __PFM__ (compatible with [Netbpm](http://www.pauldebevec.com/Research/HDR/PFM/))
- __QOI__ (via [qoi](https://github.com/phoboslab/qoi). Shoutout to [Tiago Chaves](https://github.com/laurelkeys) for adding support!)
- __DDS__ (via [DirectXTex](https://github.com/microsoft/DirectXTex); Windows only. Shoutout to [Craig Kolb](https://github.com/cek) for adding support!)
- Supports BC1-BC7 compressed formats.
- Low-dynamic-range (LDR) images are "promoted" to HDR through the reverse sRGB transformation.
Expand Down Expand Up @@ -97,7 +98,7 @@ brew install --cask tev

## Building tev

All that is required for building __tev__ is a C++17-compatible compiler. Begin by cloning this repository and all its submodules using the following command:
All that is required for building __tev__ is a C++20-compatible compiler. Begin by cloning this repository and all its submodules using the following command:
```sh
$ git clone --recursive https://github.com/Tom94/tev
```
Expand Down Expand Up @@ -131,7 +132,7 @@ $ make install

### Windows

On Windows, install [CMake](https://cmake.org/download/), open the included GUI application, and point it to the root directory of __tev__. CMake will then generate [Visual Studio](https://www.visualstudio.com/) project files for compiling __tev__. Make sure you select at least Visual Studio 2017 or higher!
On Windows, install [CMake](https://cmake.org/download/), open the included GUI application, and point it to the root directory of __tev__. CMake will then generate [Visual Studio](https://www.visualstudio.com/) project files for compiling __tev__. Make sure you select at least Visual Studio 2019 or higher!

## License

Expand Down
4 changes: 2 additions & 2 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ set(ARGS_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/args PARENT_SCOPE)

set(CLIP_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/clip PARENT_SCOPE)

set(EIGEN_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/eigen PARENT_SCOPE)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(GLFW_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nanogui/ext/glfw/include PARENT_SCOPE)
endif()
Expand All @@ -93,6 +91,8 @@ PARENT_SCOPE)

set(FILESYSTEM_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/filesystem PARENT_SCOPE)

set(QOI_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/qoi PARENT_SCOPE)

set(STB_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/stb PARENT_SCOPE)

set(TINYFORMAT_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/tinyformat PARENT_SCOPE)
Expand Down
1 change: 0 additions & 1 deletion dependencies/eigen
Submodule eigen deleted from a45d28
2 changes: 1 addition & 1 deletion dependencies/nanogui
Submodule nanogui updated 1 files
+2 −0 CMakeLists.txt
1 change: 1 addition & 0 deletions dependencies/qoi
Submodule qoi added at 4bc071
57 changes: 57 additions & 0 deletions include/tev/Box.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This file was developed by Thomas Müller <[email protected]>.
// It is published under the BSD 3-Clause License within the LICENSE file.

#pragma once

#include <tev/Common.h>


TEV_NAMESPACE_BEGIN

template <typename T, uint32_t N_DIMS>
struct Box {
using Vector = nanogui::Array<T, N_DIMS>;

Box(const Vector& min, const Vector& max) : min{min}, max{max} {}
Box(const Vector& max) : Box{Vector{(T)0}, max} {}
Box() : Box{Vector{std::numeric_limits<T>::max()}, Vector{std::numeric_limits<T>::min()}} {}

// Casting boxes of other types to this one
template <typename U>
Box(const Box<U, N_DIMS>& other) : min{other.min}, max{other.max} {}

Vector size() const {
return max - min;
}

Vector middle() const {
return (min + max) / (T)2;
}

bool isValid() const {
bool result = true;
for (uint32_t i = 0; i < N_DIMS; ++i) {
result &= max[i] >= min[i];
}
return result;
}

bool operator==(const Box& other) const {
return min == other.min && max == other.max;
}

Box<T, N_DIMS> inflate(T amount) const {
return {min - Vector{amount}, max + Vector{amount}};
}

Vector min, max;
};

using Box2f = Box<float, 2>;
using Box3f = Box<float, 3>;
using Box4f = Box<float, 4>;
using Box2i = Box<int32_t, 2>;
using Box3i = Box<int32_t, 3>;
using Box4i = Box<int32_t, 4>;

TEV_NAMESPACE_END
69 changes: 42 additions & 27 deletions include/tev/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#pragma once

#include <tev/Common.h>
#include <tev/Task.h>

#include <nanogui/vector.h>

#include <Eigen/Dense>

#include <future>
#include <string>
#include <vector>
Expand All @@ -17,62 +16,77 @@ TEV_NAMESPACE_BEGIN

class Channel {
public:
using RowMatrixXf = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;

Channel(const std::string& name, Eigen::Vector2i size);
Channel(const std::string& name, const nanogui::Vector2i& size);

const std::string& name() const {
return mName;
}

const RowMatrixXf& data() const {
const std::vector<float>& data() const {
return mData;
}

float eval(Eigen::DenseIndex index) const {
float eval(size_t index) const {
if (index >= mData.size()) {
return 0;
}
return mData(index);
return mData[index];
}

float eval(Eigen::Vector2i index) const {
if (index.x() < 0 || index.x() >= mData.cols() ||
index.y() < 0 || index.y() >= mData.rows()) {
float eval(nanogui::Vector2i index) const {
if (index.x() < 0 || index.x() >= mSize.x() ||
index.y() < 0 || index.y() >= mSize.y()) {
return 0;
}

return mData(index.x() + index.y() * mData.cols());
return mData[index.x() + index.y() * mSize.x()];
}

float& at(Eigen::DenseIndex index) {
return mData(index);
float& at(size_t index) {
return mData[index];
}

float at(Eigen::DenseIndex index) const {
return mData(index);
float at(size_t index) const {
return mData[index];
}

float& at(Eigen::Vector2i index) {
return at(index.x() + index.y() * mData.cols());
float& at(nanogui::Vector2i index) {
return at(index.x() + index.y() * mSize.x());
}

float at(Eigen::Vector2i index) const {
return at(index.x() + index.y() * mData.cols());
float at(nanogui::Vector2i index) const {
return at(index.x() + index.y() * mSize.x());
}

Eigen::DenseIndex count() const {
size_t numPixels() const {
return mData.size();
}

Eigen::Vector2i size() const {
return {mData.cols(), mData.rows()};
const nanogui::Vector2i& size() const {
return mSize;
}

std::tuple<float, float, float> minMaxMean() const {
float min = std::numeric_limits<float>::infinity();
float max = -std::numeric_limits<float>::infinity();
float mean = 0;
for (float f : mData) {
mean += f;
if (f < min) {
min = f;
}
if (f > max) {
max = f;
}
}
return {min, max, mean/numPixels()};
}

void divideByAsync(const Channel& other, std::vector<std::future<void>>& futures);
void multiplyWithAsync(const Channel& other, std::vector<std::future<void>>& futures);
Task<void> divideByAsync(const Channel& other, int priority);

Task<void> multiplyWithAsync(const Channel& other, int priority);

void setZero() { mData.setZero(); }
void setZero() { std::memset(mData.data(), 0, mData.size()*sizeof(float)); }

void updateTile(int x, int y, int width, int height, const std::vector<float>& newData);

Expand All @@ -87,7 +101,8 @@ class Channel {

private:
std::string mName;
RowMatrixXf mData;
nanogui::Vector2i mSize;
std::vector<float> mData;
};

TEV_NAMESPACE_END
Loading

0 comments on commit 47d5b0d

Please sign in to comment.