Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 25, 2024
1 parent 7d97834 commit b2ce0b7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 651 deletions.
14 changes: 0 additions & 14 deletions apps/ycolorgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,16 @@ void run(const vector<string>& args) {
// parameters
auto imagename = "image.png"s;
auto outname = "out.png"s;
auto paramsname = ""s;
auto interactive = true;
auto dumpname = ""s;
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, "params", paramsname, "params filename");
add_option(cli, "interactive", interactive, "Run interactively.");
add_option(cli, "dumpparams", dumpname, "dump params filename");
parse_cli(cli, args);

// load config
if (!paramsname.empty()) {
update_colorgrade_params(paramsname, params);
}

// dump config
if (!dumpname.empty()) {
save_colorgrade_params(dumpname, params);
}

// load image
auto image = load_image(imagename);
auto in_linear = is_linear_filename(imagename);
Expand Down
17 changes: 0 additions & 17 deletions apps/yconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ 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);

Expand All @@ -69,19 +65,6 @@ void run(const vector<string>& args) {
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{};
Expand Down
16 changes: 0 additions & 16 deletions apps/ycutrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,18 @@ void run(const vector<string>& args) {
// parameters
auto scenename = "scene.json"s;
auto outname = "out.png"s;
auto paramsname = ""s;
auto interactive = false;
auto edit = false;
auto camname = ""s;
bool addsky = false;
auto envname = ""s;
auto savebatch = false;
auto dumpname = ""s;
auto params = trace_params{};

// parse command line
auto cli = make_cli("ycutrace", "render with raytracing");
add_option(cli, "scene", scenename, "scene filename");
add_option(cli, "output", outname, "output filename");
add_option(cli, "params", paramsname, "params filename");
add_option(cli, "interactive", interactive, "run interactively");
add_option(cli, "camera", camname, "camera name");
add_option(cli, "addsky", addsky, "add sky");
Expand All @@ -79,22 +76,9 @@ void run(const vector<string>& args) {
add_option(cli, "embreebvh", params.embreebvh, "use Embree bvh");
add_option(cli, "highqualitybvh", params.highqualitybvh, "high quality bvh");
add_option(cli, "noparallel", params.noparallel, "disable threading");
add_option(cli, "dumpparams", dumpname, "dump params filename");
add_option(cli, "edit", edit, "edit interactively");
parse_cli(cli, args);

// load config
if (!paramsname.empty()) {
update_trace_params(paramsname, params);
print_info("loading params {}", paramsname);
}

// dump config
if (!dumpname.empty()) {
save_trace_params(dumpname, params);
print_info("saving params {}", dumpname);
}

// start rendering
print_info("rendering {}", scenename);
auto timer = simple_timer{};
Expand Down
16 changes: 0 additions & 16 deletions apps/ytrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,18 @@ void run(const vector<string>& args) {
// parameters
auto scenename = "scene.json"s;
auto outname = "out.png"s;
auto paramsname = ""s;
auto interactive = false;
auto edit = false;
auto camname = ""s;
bool addsky = false;
auto envname = ""s;
auto savebatch = false;
auto dumpname = ""s;
auto params = trace_params{};

// parse command line
auto cli = make_cli("ytrace", "render with raytracing");
add_option(cli, "scene", scenename, "scene filename");
add_option(cli, "output", outname, "output filename");
add_option(cli, "params", paramsname, "params filename");
add_option(cli, "interactive", interactive, "run interactively");
add_option(cli, "camera", camname, "camera name");
add_option(cli, "addsky", addsky, "add sky");
Expand All @@ -78,22 +75,9 @@ void run(const vector<string>& args) {
add_option(cli, "embreebvh", params.embreebvh, "use Embree bvh");
add_option(cli, "highqualitybvh", params.highqualitybvh, "high quality bvh");
add_option(cli, "noparallel", params.noparallel, "disable threading");
add_option(cli, "dumpparams", dumpname, "dump params filename");
add_option(cli, "edit", edit, "edit interactively");
parse_cli(cli, args);

// load config
if (!paramsname.empty()) {
update_trace_params(paramsname, params);
print_info("loading params {}", paramsname);
}

// dump config
if (!dumpname.empty()) {
save_trace_params(dumpname, params);
print_info("saving params {}", dumpname);
}

// start rendering
print_info("rendering {}", scenename);
auto timer = simple_timer{};
Expand Down
7 changes: 5 additions & 2 deletions libs/yocto/yocto_diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@

#include "yocto_diagram.h"

#include <yocto/yocto_sceneio.h>

#include <future>
#include <unordered_set>

#include "yocto_bvh.h"
#include "yocto_sampling.h"
#include "yocto_sceneio.h"

// -----------------------------------------------------------------------------
// USING DIRECTIVES
// -----------------------------------------------------------------------------
Expand Down
43 changes: 37 additions & 6 deletions libs/yocto/yocto_modeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "yocto_image.h"
#include "yocto_math.h"
#include "yocto_shape.h"
#include "yocto_utils.h"

// -----------------------------------------------------------------------------
// USING DIRECTIVES
Expand Down Expand Up @@ -416,6 +415,40 @@ inline float turbulence_noise(
//
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// ARRAY UTILITIES
// -----------------------------------------------------------------------------
namespace yocto {

// Concatenation
template <typename T>
inline vector<T> join(const vector<T>& a, const vector<T>& b) {
auto c = vector<T>{};
c.reserve(a.size() + b.size());
c.insert(c.end(), a.begin(), a.end());
c.insert(c.end(), b.begin(), b.end());
return c;
}

// Concatenation
template <typename T>
inline vector<T>& append(vector<T>& a, const vector<T>& b) {
a.reserve(a.size() + b.size());
a.insert(a.end(), b.begin(), b.end());
return a;
}

// Remove duplicates
template <typename T>
inline vector<T> remove_duplicates(const vector<T>& v) {
auto result = v;
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
return result;
}

} // namespace yocto

// -----------------------------------------------------------------------------
// BÉZIER SPLINES
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -703,7 +736,7 @@ inline vector<T> tesselate_bezier(const vector<T>& control_points, int steps) {
template <typename T>
inline vector<T> flatten_beziers(const vector<vector<T>>& beziers) {
auto points = vector<T>{};
for (auto& bezier : beziers) points += bezier;
for (auto& bezier : beziers) append(points, bezier);
return points;
}

Expand Down Expand Up @@ -739,9 +772,7 @@ inline vector<vector<T>> subdivide_beziers(
// tesselate each segment
auto subdivided_beziers = vector<vector<T>>();
for (auto& control_points_ : control_points) {
auto ssubdivided = subdivide_bezier(control_points_, levels);
subdivided_beziers.insert(
subdivided_beziers.end(), ssubdivided.begin(), ssubdivided.end());
append(subdivided_beziers, subdivide_bezier(control_points_, levels));
}
return subdivided_beziers;
}
Expand Down Expand Up @@ -1160,7 +1191,7 @@ inline pair<vector<vec2i>, vector<T>> subdivide_bspline(
auto boundary = get_boundary_vertices((int)tvertices.size(), tlines);
auto valence = vector<int>(tvertices.size(), 1);
auto tcorners = vector<int>{};
for (auto index : remove_duplicates(boundary + corners)) {
for (auto index : remove_duplicates(join(boundary, corners))) {
tcorners.push_back(index);
valence[index] = 0;
}
Expand Down
Loading

0 comments on commit b2ce0b7

Please sign in to comment.