Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 26, 2024
1 parent 19d516b commit 1894941
Show file tree
Hide file tree
Showing 18 changed files with 591 additions and 784 deletions.
3 changes: 1 addition & 2 deletions libs/yocto/yocto_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ inline quat4f log_map(const quat4f& q) {

// Linear interpolation of translation, scaling and rotations.
// Rotations are interpolated using the exponential map.
inline frame3f interpolate_translation(
vec3f a, vec3f b, float t) {
inline frame3f interpolate_translation(vec3f a, vec3f b, float t) {
return translation_frame(lerp(a, b, t));
}
inline frame3f interpolate_scaling(vec3f a, vec3f b, float t) {
Expand Down
6 changes: 2 additions & 4 deletions libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ namespace yocto {

// Intersect ray with a bvh.
shape_intersection overlap_shape_bvh(const shape_bvh& sbvh,
const shape_data& shape, vec3f pos, float max_distance,
bool find_any) {
const shape_data& shape, vec3f pos, float max_distance, bool find_any) {
// get bvh tree
auto& bvh = sbvh.bvh;

Expand Down Expand Up @@ -748,8 +747,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& sbvh,

// Intersect ray with a bvh.
scene_intersection overlap_scene_bvh(const scene_bvh& sbvh,
const scene_data& scene, vec3f pos, float max_distance,
bool find_any) {
const scene_data& scene, vec3f pos, float max_distance, bool find_any) {
// get instances bvh
auto& bvh = sbvh.bvh;

Expand Down
45 changes: 18 additions & 27 deletions libs/yocto/yocto_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,11 @@ inline vec4f srgb_to_rgb(vec4f srgb) {
inline vec3f rgb_to_srgb(vec3f rgb) {
return {rgb_to_srgb(rgb.x), rgb_to_srgb(rgb.y), rgb_to_srgb(rgb.z)};
}
inline vec4f rgb_to_srgb(vec4f rgb) {
return {rgb_to_srgb(xyz(rgb)), rgb.w};
}
inline vec4f rgb_to_srgb(vec4f rgb) { return {rgb_to_srgb(xyz(rgb)), rgb.w}; }
inline vec4f srgbb_to_rgb(vec4b srgb) {
return srgb_to_rgb(byte_to_float(srgb));
}
inline vec4b rgb_to_srgbb(vec4f rgb) {
return float_to_byte(rgb_to_srgb(rgb));
}
inline vec4b rgb_to_srgbb(vec4f rgb) { return float_to_byte(rgb_to_srgb(rgb)); }

// Conversion between number of channels.
inline vec4f rgb_to_rgba(vec3f rgb) { return {rgb, 1}; }
Expand Down Expand Up @@ -293,13 +289,11 @@ inline vec4f contrast(vec4f rgb, float contrast) {
return {yocto::contrast(xyz(rgb), contrast), rgb.w};
}
// Apply saturation.
inline vec3f saturate(
vec3f rgb, float saturation, vec3f weights) {
inline vec3f saturate(vec3f rgb, float saturation, vec3f weights) {
auto grey = dot(weights, rgb);
return max({0, 0, 0}, grey + (rgb - grey) * (saturation * 2));
}
inline vec4f saturate(
vec4f rgb, float saturation, vec3f weights) {
inline vec4f saturate(vec4f rgb, float saturation, vec3f weights) {
return {saturate(xyz(rgb), saturation, weights), rgb.w};
}

Expand Down Expand Up @@ -638,8 +632,7 @@ struct color_space_params {
// Input: red, green, blue, white (x,y) chromoticities
// Algorithm from: SMPTE Recommended Practice RP 177-1993
// http://car.france3.mars.free.fr/HD/INA-%2026%20jan%2006/SMPTE%20normes%20et%20confs/rp177.pdf
inline mat3f rgb_to_xyz_mat(
vec2f rc, vec2f gc, vec2f bc, vec2f wc) {
inline mat3f rgb_to_xyz_mat(vec2f rc, vec2f gc, vec2f bc, vec2f wc) {
auto rgb = mat3f{
{rc.x, rc.y, 1 - rc.x - rc.y},
{gc.x, gc.y, 1 - gc.x - gc.y},
Expand All @@ -652,28 +645,26 @@ inline mat3f rgb_to_xyz_mat(

// Construct an RGB color space. Predefined color spaces below
inline color_space_params get_color_scape_params(color_space space) {
static auto make_linear_rgb_space = [](vec2f red, vec2f green,
vec2f blue,
static auto make_linear_rgb_space = [](vec2f red, vec2f green, vec2f blue,
vec2f white) {
return color_space_params{red, green, blue, white,
rgb_to_xyz_mat(red, green, blue, white),
inverse(rgb_to_xyz_mat(red, green, blue, white)),
color_space_params::curve_t::linear};
};
static auto make_gamma_rgb_space =
[](vec2f red, vec2f green, vec2f blue,
vec2f white, float gamma,
vec4f curve_abcd = vec4f{0, 0, 0, 0}) {
return color_space_params{red, green, blue, white,
rgb_to_xyz_mat(red, green, blue, white),
inverse(rgb_to_xyz_mat(red, green, blue, white)),
curve_abcd == vec4f{0, 0, 0, 0}
? color_space_params::curve_t::gamma
: color_space_params::curve_t::linear_gamma};
};
static auto make_gamma_rgb_space = [](vec2f red, vec2f green, vec2f blue,
vec2f white, float gamma,
vec4f curve_abcd = vec4f{0, 0, 0, 0}) {
return color_space_params{red, green, blue, white,
rgb_to_xyz_mat(red, green, blue, white),
inverse(rgb_to_xyz_mat(red, green, blue, white)),
curve_abcd == vec4f{0, 0, 0, 0}
? color_space_params::curve_t::gamma
: color_space_params::curve_t::linear_gamma};
};
static auto make_other_rgb_space =
[](vec2f red, vec2f green, vec2f blue,
vec2f white, color_space_params::curve_t curve_type) {
[](vec2f red, vec2f green, vec2f blue, vec2f white,
color_space_params::curve_t curve_type) {
return color_space_params{red, green, blue, white,
rgb_to_xyz_mat(red, green, blue, white),
inverse(rgb_to_xyz_mat(red, green, blue, white)), curve_type};
Expand Down
39 changes: 16 additions & 23 deletions libs/yocto/yocto_diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ static void merge_dshape_inplace(shape_data& shape, const shape_data& merge) {
}

// Make a tesselated rectangle. Useful in other subdivisions.
static shape_data make_dquads(
vec2i steps, vec2f scale, vec2f uvscale) {
static shape_data make_dquads(vec2i steps, vec2f scale, vec2f uvscale) {
auto shape = shape_data{};

shape.positions.resize((steps.x + 1) * (steps.y + 1));
Expand Down Expand Up @@ -111,8 +110,7 @@ static shape_data make_dquads(
}

// Make a rect
static shape_data make_drect(
vec2i steps, vec2f scale, vec2f uvscale = {1, 1}) {
static shape_data make_drect(vec2i steps, vec2f scale, vec2f uvscale = {1, 1}) {
return make_dquads(steps, scale, uvscale);
}

Expand Down Expand Up @@ -420,17 +418,16 @@ static void update_offsets(diagram_data& diagram) {
}

// Scene
diagram_scene& add_scene(diagram_data& diagram, const string& title,
vec2f size, const frame3f& frame, vec2f margin) {
diagram_scene& add_scene(diagram_data& diagram, const string& title, vec2f size,
const frame3f& frame, vec2f margin) {
return add_scenews(diagram, title, "", size, frame, margin);
}
diagram_scene& add_scene(diagram_data& diagram, const string& title,
const frame3f& frame, vec2f margin) {
return add_scenews(diagram, title, "", {2, 2}, frame, margin);
}
diagram_scene& add_scenews(diagram_data& diagram, const string& title,
const string& subtitle, vec2f size, const frame3f& frame,
vec2f margin) {
const string& subtitle, vec2f size, const frame3f& frame, vec2f margin) {
auto& scene = diagram.scenes.emplace_back();
scene.size = size;
scene.margin = margin;
Expand Down Expand Up @@ -877,8 +874,7 @@ diagram_shape dhalfdisk(int steps) {
}

// Add arc
diagram_shape darc(
vec3f from, vec3f to, vec3f center, int steps) {
diagram_shape darc(vec3f from, vec3f to, vec3f center, int steps) {
// refence frame
auto x = normalize(from - center);
auto y = normalize(to - center);
Expand Down Expand Up @@ -1206,8 +1202,7 @@ diagram_shape dudiskgrid(vec2i steps, int dsteps) {
}

// Add affine grid
diagram_shape daffinegrid(
vec3f axes_a, vec3f axes_b, vec2i steps) {
diagram_shape daffinegrid(vec3f axes_a, vec3f axes_b, vec2i steps) {
auto ratio = (float)steps.x / (float)steps.y;
auto shape_ = make_drect({steps.x, steps.y}, {ratio, 1});
auto positions_ = shape_.positions;
Expand Down Expand Up @@ -1430,8 +1425,8 @@ diagram_shape drandomlines(drandomlines_type type, int num, bool stratified) {
}

// Add plot
diagram_scene& add_plot(diagram_data& diagram, const string& title,
vec2f size, const frame3f& frame, vec2f margin) {
diagram_scene& add_plot(diagram_data& diagram, const string& title, vec2f size,
const frame3f& frame, vec2f margin) {
return add_scene(diagram, title, size, frame, margin);
}

Expand Down Expand Up @@ -1546,8 +1541,8 @@ vector<vec2f> dplotcurve(const vector<float>& curve, vec2f range) {
}

// Add plot
diagram_scene& add_plot3(diagram_data& diagram, const string& title,
vec2f size, const frame3f& frame, vec2f margin) {
diagram_scene& add_plot3(diagram_data& diagram, const string& title, vec2f size,
const frame3f& frame, vec2f margin) {
return add_scene(diagram, title, size, frame, margin);
}

Expand Down Expand Up @@ -1612,9 +1607,8 @@ diagram_scene& add_plotaxes3(diagram_scene& diagram, const bbox3f& bounds,
}

// Plot surface
diagram_shape dplotsurface(const function<float(vec2f)>& func,
vec2f xrange, vec2f yrange, vec2i steps,
bool isolines) {
diagram_shape dplotsurface(const function<float(vec2f)>& func, vec2f xrange,
vec2f yrange, vec2i steps, bool isolines) {
auto shape = diagram_shape{};

// steps
Expand Down Expand Up @@ -2171,8 +2165,8 @@ image_t<vec4f> render_diagram(const diagram_data& diagram, int resolution,
auto render = render_image(yscene, resolution, samples, false);

// helpers
auto draw_quad = [](image_t<vec4f>& composite, vec2i center,
vec2i size, vec4f color) {
auto draw_quad = [](image_t<vec4f>& composite, vec2i center, vec2i size,
vec4f color) {
auto extents = composite.size();
for (auto i : range(-size.x / 2, +size.x / 2)) {
composite[clamp(
Expand All @@ -2188,8 +2182,7 @@ image_t<vec4f> render_diagram(const diagram_data& diagram, int resolution,
}
};
auto copy_quad = [](image_t<vec4f>& composite, const image_t<vec4f>& source,
vec2i icenter, vec2i scenter,
vec2i size) {
vec2i icenter, vec2i scenter, vec2i size) {
auto csize = composite.size();
auto ssize = source.size();
for (auto j : range(-size.y / 2, +size.y / 2)) {
Expand Down
55 changes: 24 additions & 31 deletions libs/yocto/yocto_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,13 @@ inline frame3f dscale(float scale) {
inline frame3f dframez(vec3f z, vec3f pos = {0, 0, 0}) {
return frame_fromz(pos, z);
}
inline frame3f dlookat(vec3f from, vec3f to = {0, 0, 0},
vec3f up = {0, 1, 0}) {
inline frame3f dlookat(vec3f from, vec3f to = {0, 0, 0}, vec3f up = {0, 1, 0}) {
return lookat_frame(from, to, up, true);
}
inline frame3f dtransform(vec3f translation, vec3f rotation) {
return dtranslation(translation) * drotation(rotation);
}
inline frame3f dgtransform(
vec3f translation, vec3f rotation, vec3f scaling) {
inline frame3f dgtransform(vec3f translation, vec3f rotation, vec3f scaling) {
return dtranslation(translation) * drotation(rotation) * dscaling(scaling);
}
inline frame3f dreflectx() {
Expand Down Expand Up @@ -355,30 +353,27 @@ inline diagram_shape transform_shape(
}

// Styles
inline diagram_style dstroke(vec4f stroke = dcolors::black,
float thickness = dthickness::default_) {
inline diagram_style dstroke(
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {
.stroke = stroke, .fill = dcolors::transparent, .thickness = thickness};
}
inline diagram_style dfill(vec4f fill = dcolors::fill1) {
return {.stroke = dcolors::transparent, .fill = fill};
}
inline diagram_style dfilled(vec4f fill = dcolors::fill1,
vec4f stroke = dcolors::black,
float thickness = dthickness::default_) {
inline diagram_style dfilled(vec4f fill = dcolors::fill1,
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke, .fill = fill, .thickness = thickness};
}
inline diagram_style dtextured(const image_t<vec4f>& texture,
vec4f stroke = dcolors::black,
float thickness = dthickness::default_) {
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke,
.fill = {1, 1, 1, 1},
.thickness = thickness,
.texture = texture};
}
inline diagram_style dtextured(const image_t<vec4f>& texture, bool interpolate,
vec4f stroke = dcolors::black,
float thickness = dthickness::default_) {
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke,
.fill = {1, 1, 1, 1},
.thickness = thickness,
Expand All @@ -387,7 +382,7 @@ inline diagram_style dtextured(const image_t<vec4f>& texture, bool interpolate,
}
inline diagram_style dimtextured(const image_t<vec4f>& texture,
vec4f stroke = dcolors::transparent,
float thickness = dthickness::default_) {
float thickness = dthickness::default_) {
return {
.stroke = stroke,
.fill = {1, 1, 1, 1},
Expand Down Expand Up @@ -424,9 +419,8 @@ namespace yocto {
// Add scene
diagram_scene& add_scene(diagram_data& diagram, const string& title,
const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0});
diagram_scene& add_scene(diagram_data& diagram, const string& title,
vec2f size, const frame3f& frame = identity3x4f,
vec2f margin = {0.2, 1.0});
diagram_scene& add_scene(diagram_data& diagram, const string& title, vec2f size,
const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0});
diagram_scene& add_scenews(diagram_data& diagram, const string& title,
const string& subtitle, vec2f size = {2, 2},
const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0});
Expand Down Expand Up @@ -531,8 +525,8 @@ diagram_shape ddisk(int steps = 64);
diagram_shape dhalfdisk(int steps = 32);

// Arc
diagram_shape darc(vec3f from, vec3f to,
vec3f center = {0, 0, 0}, int steps = 16);
diagram_shape darc(
vec3f from, vec3f to, vec3f center = {0, 0, 0}, int steps = 16);

// Qbezier
diagram_shape dqbeziers(const vector<vec3f>& positions, int steps = 32);
Expand Down Expand Up @@ -577,8 +571,8 @@ diagram_shape ddiskgrid(vec2i steps = {4, 4}, int dstep = 32);
diagram_shape dudiskgrid(vec2i steps = {4, 4}, int dstep = 32);

// Affine grid
diagram_shape daffinegrid(vec3f axes_a = {1, 0, 0},
vec3f axes_b = {0, 1, 0}, vec2i steps = {4, 4});
diagram_shape daffinegrid(
vec3f axes_a = {1, 0, 0}, vec3f axes_b = {0, 1, 0}, vec2i steps = {4, 4});

// Image
diagram_shape dimagerect(vec2i size);
Expand Down Expand Up @@ -666,25 +660,24 @@ diagram_scene& add_plot3(diagram_data& diagram, vec2f size = {4, 3},
drotation({270, 0, 0}) * drotation({0, 0, 180}),
vec2f margin = {0.8, 1.0});
diagram_scene& add_plot3(diagram_data& diagram, const string& title,
vec2f size = {4, 3},
vec2f size = {4, 3},
const frame3f& frame = drotation({25, 0, 0}) * drotation({0, 45, 0}) *
drotation({270, 0, 0}) * drotation({0, 0, 180}),
vec2f margin = {0.8, 1.0});

// Add plot axes
diagram_scene& add_plotaxes3(diagram_scene& diagram,
const bbox3f& bounds = {{0, 0, 0}, {1, 1, 1}},
vec3f size = {1, 1, 1},
const vector<pair<float, string>>& xticks = {},
const vector<pair<float, string>>& yticks = {},
const vector<pair<float, string>>& zticks = {},
const diagram_style& style = dstroke(),
const diagram_style& lstyle = dstroke(dcolors::transparent));
const bbox3f& bounds = {{0, 0, 0}, {1, 1, 1}}, vec3f size = {1, 1, 1},
const vector<pair<float, string>>& xticks = {},
const vector<pair<float, string>>& yticks = {},
const vector<pair<float, string>>& zticks = {},
const diagram_style& style = dstroke(),
const diagram_style& lstyle = dstroke(dcolors::transparent));

// Plot surface
diagram_shape dplotsurface(const function<float(vec2f)>& func,
vec2f xrange = {0, 1}, vec2f yrange = {0, 1},
vec2i steps = {64, 64}, bool wireframe = true);
vec2f xrange = {0, 1}, vec2f yrange = {0, 1}, vec2i steps = {64, 64},
bool wireframe = true);

// Helpers to clip lines
diagram_shape clip_lines(const diagram_shape& shape, const bbox3f& bbox);
Expand Down
Loading

0 comments on commit 1894941

Please sign in to comment.