Skip to content

Commit

Permalink
Simpler example apps (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Mar 14, 2022
1 parent b11edec commit 5655a42
Show file tree
Hide file tree
Showing 23 changed files with 1,207 additions and 203 deletions.
12 changes: 12 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
add_subdirectory(yimage)
add_subdirectory(yshape)
add_subdirectory(yscene)

add_subdirectory(ytonemap)
add_subdirectory(ycolorgrade)

add_subdirectory(yview)
add_subdirectory(ytrace)
add_subdirectory(ycutrace)

add_subdirectory(yimdiff)
add_subdirectory(yimalpha)
add_subdirectory(yconvert)
add_subdirectory(yconverts)
add_subdirectory(ysamples)
5 changes: 5 additions & 0 deletions apps/ycolorgrade/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(ycolorgrade ycolorgrade.cpp)

set_target_properties(ycolorgrade PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
target_include_directories(ycolorgrade PRIVATE ${CMAKE_SOURCE_DIR}/libs)
target_link_libraries(ycolorgrade PRIVATE yocto)
80 changes: 80 additions & 0 deletions apps/ycolorgrade/ycolorgrade.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// LICENSE:
//
// Copyright (c) 2016 -- 2021 Fabio Pellacini
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//

#include <yocto/yocto_cli.h>
#include <yocto/yocto_color.h>
#include <yocto/yocto_gui.h>
#include <yocto/yocto_image.h>
#include <yocto/yocto_math.h>
#include <yocto/yocto_scene.h>
#include <yocto/yocto_sceneio.h>

using namespace yocto;
using namespace std::string_literals;

// main function
void run(const vector<string>& args) {
// parameters
auto imagename = "image.png"s;
auto outname = "out.png"s;
auto interactive = true;
auto params = colorgrade_params{};

// parse command line
auto cli = make_cli("ycolorgrade", "adjust image colors");
add_option(cli, "image", imagename, "Input image.");
add_option(cli, "output", outname, "Output image.");
add_option(cli, "interactive", interactive, "Run interactively.");
parse_cli(cli, args);

// load image
auto image = load_image(imagename);

// switch between interactive and offline
if (!interactive) {
// apply color grade
image = colorgrade_image(image, params);

// save image
save_image(outname, image);
} else {
// run viewer
show_colorgrade_gui("ycolorgrade", imagename, image);
}
}

// Main
int main(int argc, const char* argv[]) {
try {
run({argv, argv + argc});
return 0;
} catch (const std::exception& error) {
print_error(error.what());
return 1;
}
}
5 changes: 5 additions & 0 deletions apps/yconvert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(yconvert yconvert.cpp)

set_target_properties(yconvert PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
target_include_directories(yconvert PRIVATE ${CMAKE_SOURCE_DIR}/libs)
target_link_libraries(yconvert PRIVATE yocto)
108 changes: 108 additions & 0 deletions apps/yconvert/yconvert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// LICENSE:
//
// Copyright (c) 2016 -- 2021 Fabio Pellacini
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//

#include <yocto/yocto_cli.h>
#include <yocto/yocto_gui.h>
#include <yocto/yocto_math.h>
#include <yocto/yocto_scene.h>
#include <yocto/yocto_sceneio.h>
#include <yocto/yocto_shape.h>
#include <yocto/yocto_trace.h>

using namespace yocto;
using namespace std::string_literals;

// main function
void run(const vector<string>& args) {
// parameters
auto scenename = "scene.json"s;
auto outname = "out.json"s;
auto info = false;
auto validate = false;
auto copyright = ""s;

// parse command line
auto cli = make_cli("yconvert", "convert scenes, shapes and images");
add_option(cli, "scene", scenename, "input scene");
add_option(cli, "output", outname, "output scenename");
add_option(cli, "info", info, "print info");
add_option(cli, "validate", validate, "run validate");
add_option(cli, "copyright", copyright, "set scene copyright");
parse_cli(cli, args);

// start converting
print_info("converting {}", scenename);
auto timer = simple_timer{};

// load scene
timer = simple_timer{};
auto scene = load_scene(scenename);
print_info("load scene: {}", elapsed_formatted(timer));

// copyright
if (copyright != "") {
scene.copyright = copyright;
}

// validate scene
if (validate) {
auto errors = scene_validation(scene);
for (auto& error : errors) print_error(error);
if (!errors.empty()) throw io_error{"invalid scene"};
}

// print info
if (info) {
print_info("scene stats ------------");
for (auto stat : scene_stats(scene)) print_info(stat);
}

// tesselate if needed
if (!scene.subdivs.empty()) {
timer = simple_timer{};
tesselate_subdivs(scene);
print_info("tesselate subdivs: {}", elapsed_formatted(timer));
}

// save scene
timer = simple_timer{};
make_scene_directories(outname, scene);
save_scene(outname, scene);
print_info("save scene: {}", elapsed_formatted(timer));
}

// Main
int main(int argc, const char* argv[]) {
try {
run({argv, argv + argc});
return 0;
} catch (const std::exception& error) {
print_error(error.what());
return 1;
}
}
5 changes: 5 additions & 0 deletions apps/yconverts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(yconverts yconverts.cpp)

set_target_properties(yconverts PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
target_include_directories(yconverts PRIVATE ${CMAKE_SOURCE_DIR}/libs)
target_link_libraries(yconverts PRIVATE yocto)
Loading

0 comments on commit 5655a42

Please sign in to comment.