This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit w/ command line recognition and app skeleton.
- Loading branch information
0 parents
commit 55665e5
Showing
13 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
.ycm_extra_conf.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "dependencies/stb"] | ||
path = dependencies/stb | ||
url = https://github.com/nothings/stb | ||
[submodule "dependencies/glm"] | ||
path = dependencies/glm | ||
url = https://github.com/g-truc/glm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(ltc_fitter) | ||
|
||
find_package( | ||
Boost 1.63.0 REQUIRED COMPONENTS program_options | ||
) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/dependencies/glm) | ||
include_directories(${PROJECT_SOURCE_DIR}/dependencies/stb) | ||
|
||
add_executable( | ||
${PROJECT_NAME} | ||
src/main.cpp | ||
src/fitting_settings.cpp | ||
src/ltc_fitting.cpp | ||
src/result_saving.cpp | ||
src/stb_implementation.c | ||
) | ||
|
||
target_link_libraries( | ||
${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES} | ||
) | ||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <iostream> | ||
#include "boost/program_options.hpp" | ||
#include "fitting_settings.hpp" | ||
|
||
namespace po = boost::program_options; | ||
|
||
bool get_fitting_settings_from_command_line( | ||
fitting_settings &output, | ||
int argc, | ||
const char *argv[] | ||
) | ||
{ | ||
output = fitting_settings(); | ||
|
||
po::options_description description("Allowed options"); | ||
description.add_options() | ||
("help", "help message") | ||
( | ||
"resolution,r", | ||
po::value<int>(&output.resolution)->default_value(64), | ||
"resolution of output image" | ||
) | ||
( | ||
"minroughness,m", | ||
po::value<float>(&output.min_roughness)->default_value(0.0001f), | ||
"minimal roughness, should be greater than 0" | ||
) | ||
( | ||
"maxroughness,M", | ||
po::value<float>(&output.max_roughness)->default_value(1.0f), | ||
"maximum roughness" | ||
) | ||
( | ||
"errorsamples,E", | ||
po::value<int>( | ||
&output.num_error_estimate_samples | ||
)->default_value(64), | ||
"number of samples during error estimation" | ||
) | ||
( | ||
"threads,j", | ||
po::value<int>( | ||
&output.num_threads | ||
)->default_value(1), | ||
"number of threads" | ||
) | ||
( | ||
"output,o", | ||
po::value<std::string>(&output.output_file), | ||
"output file" | ||
) | ||
; | ||
|
||
po::variables_map var_map; | ||
po::store(po::parse_command_line(argc, argv, description), var_map); | ||
po::notify(var_map); | ||
|
||
if (var_map.count("help")) | ||
{ | ||
std::cout << "LTC Fitter" << std::endl | ||
<< "Part of Master's thesis by Kamil Sienkiewicz" << std::endl | ||
<< "Based on work of Heitz et al: \"Linearly Transformed Cosines\"" | ||
<< std::endl; | ||
std::cout << description << std::endl; | ||
return false; | ||
} | ||
|
||
if (!var_map.count("output")) | ||
{ | ||
std::cout << "Output file is not set." << std::endl | ||
<< description << std::endl; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void print_fitting_settings(const fitting_settings& settings) | ||
{ | ||
std::cout << "Current fitting settings: " << std::endl | ||
<< "\tImage resolution:\t" << settings.resolution << "x" | ||
<< settings.resolution << std::endl | ||
<< "\tMinimum roughness:\t" << settings.min_roughness << std::endl | ||
<< "\tMaximum roughness:\t" << settings.max_roughness << std::endl | ||
<< "\tError est. samples:\t" << settings.num_error_estimate_samples | ||
<< std::endl << "\tLookup output file:\t" << settings.output_file | ||
<< std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
struct fitting_settings | ||
{ | ||
fitting_settings() {} | ||
|
||
int resolution; | ||
float min_roughness; | ||
float max_roughness; | ||
int num_error_estimate_samples; | ||
int num_threads; | ||
std::string output_file; | ||
}; | ||
|
||
bool get_fitting_settings_from_command_line( | ||
fitting_settings &output, | ||
int argc, | ||
const char *argv[] | ||
); | ||
|
||
void print_fitting_settings(const fitting_settings& settings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "ltc_fitting.hpp" | ||
|
||
fitting_result ltc_fit(fitting_settings settings) | ||
{ | ||
fitting_result result; | ||
result.settings = settings; | ||
|
||
for (auto i = 0; i < settings.resolution; ++i) | ||
{ | ||
for (auto j = 0; j < settings.resolution; ++j) | ||
{ | ||
result.transformations.push_back(glm::vec4{1.0f, 0.0f, 0.0f, 1.0f}); | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#include <vector> | ||
#include "glm/glm.hpp" | ||
#include "fitting_settings.hpp" | ||
|
||
struct fitting_result | ||
{ | ||
fitting_settings settings; | ||
std::vector<glm::vec4> transformations; | ||
}; | ||
|
||
fitting_result ltc_fit(fitting_settings settings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include "fitting_settings.hpp" | ||
#include "ltc_fitting.hpp" | ||
#include "result_saving.hpp" | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
fitting_settings settings; | ||
if (!get_fitting_settings_from_command_line(settings, argc, argv)) | ||
{ | ||
std::cout << "failed to set fitting settings" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
print_fitting_settings(settings); | ||
auto result = ltc_fit(settings); | ||
save_fitting_result(result); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "ltc_fitting.hpp" | ||
#include "stb_image_write.h" | ||
|
||
static std::vector<unsigned char> discretize_color_vector( | ||
const std::vector<glm::vec4>& colors_floating | ||
) | ||
{ | ||
std::vector<unsigned char> discretized; | ||
discretized.reserve(4 * colors_floating.size()); | ||
|
||
for (auto i = 0; i < colors_floating.size(); ++i) | ||
{ | ||
auto color = colors_floating[i]; | ||
for (auto j = 0; j < 4; ++j) | ||
{ | ||
auto clamped = std::max(0.0f, std::min(1.0f, color[j])); | ||
auto discr_channel = static_cast<unsigned char>(clamped * 255); | ||
discretized.push_back(discr_channel); | ||
} | ||
} | ||
return discretized; | ||
} | ||
|
||
void save_fitting_result(fitting_result result) | ||
{ | ||
auto discretized_texture = discretize_color_vector(result.transformations); | ||
|
||
stbi_write_png( | ||
result.settings.output_file.c_str(), | ||
result.settings.resolution, | ||
result.settings.resolution, | ||
4, | ||
discretized_texture.data(), | ||
4 * sizeof(unsigned char) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include "ltc_fitting.hpp" | ||
|
||
void save_fitting_result(fitting_result result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define STB_DEFINE | ||
#define STB_IMAGE_IMPLEMENTATION | ||
#define STB_IMAGE_WRITE_IMPLEMENTATION | ||
#include "stb.h" | ||
#include "stb_image.h" | ||
#include "stb_image_write.h" | ||
#include "stb_image_resize.h" |