diff --git a/apps/yimage/yimage.cpp b/apps/yimage/yimage.cpp index a80a607a1..ace8198b3 100644 --- a/apps/yimage/yimage.cpp +++ b/apps/yimage/yimage.cpp @@ -200,7 +200,7 @@ void run_setalpha(const setalpha_params& params) { // edit alpha auto out = make_image(image.width, image.height, image.linear); - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { auto calpha = alpha.pixels[idx]; auto alpha_ = params.from_color ? mean(xyz(calpha)) : params.from_black ? (mean(xyz(calpha)) > 0.01 ? 1.0f : 0.0f) diff --git a/apps/ymesh/ymesh.cpp b/apps/ymesh/ymesh.cpp index 09b2880b5..fd2314cd2 100644 --- a/apps/ymesh/ymesh.cpp +++ b/apps/ymesh/ymesh.cpp @@ -1073,7 +1073,7 @@ static pair, vec2f> sample_stroke(const bvh_tree& bvh, auto update_uv = (mouse_uv - last_uv) * stroke_dist / delta_pos; auto cur_uv = last_uv; auto samples = vector{}; - for (auto step = 0; step < steps; step++) { + for (auto step : range(steps)) { cur_uv += update_uv; auto isec = intersect_shape(cur_uv); if (!isec.hit) continue; diff --git a/apps/yscene/yscene.cpp b/apps/yscene/yscene.cpp index 4138e0c7e..bfb73a51d 100644 --- a/apps/yscene/yscene.cpp +++ b/apps/yscene/yscene.cpp @@ -215,7 +215,7 @@ void run_render(const render_params& params_) { // render timer = simple_timer{}; - for (auto sample = 0; sample < params.samples; sample++) { + for (auto sample : range(params.samples)) { auto sample_timer = simple_timer{}; trace_samples(state, scene, bvh, lights, params); print_info("render sample {}/{}: {}", sample, params.samples, diff --git a/libs/yocto/yocto_bvh.cpp b/libs/yocto/yocto_bvh.cpp index 614e2159d..b90798c3a 100644 --- a/libs/yocto/yocto_bvh.cpp +++ b/libs/yocto/yocto_bvh.cpp @@ -125,7 +125,7 @@ static pair split_sah(vector& primitives, return 1e-12f + 2 * size.x * size.y + 2 * size.x * size.z + 2 * size.y * size.z; }; - for (auto saxis = 0; saxis < 3; saxis++) { + for (auto saxis : range(3)) { for (auto b = 1; b < nbins; b++) { auto bsplit = cbbox.min[saxis] + b * csize[saxis] / nbins; auto left_bbox = invalidb3f, right_bbox = invalidb3f; @@ -303,11 +303,11 @@ static void refit_bvh(vector& nodes, const vector& primitives, auto& node = nodes[nodeid]; node.bbox = invalidb3f; if (node.internal) { - for (auto idx = 0; idx < 2; idx++) { + for (auto idx : range(2)) { node.bbox = merge(node.bbox, nodes[node.start + idx].bbox); } } else { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { node.bbox = merge(node.bbox, bboxes[primitives[node.start + idx]]); } } @@ -365,7 +365,7 @@ scene_bvh make_scene_bvh( // build shape bvh bvh.shapes.resize(scene.shapes.size()); if (noparallel) { - for (auto idx = (size_t)0; idx < scene.shapes.size(); idx++) { + for (auto idx : range(scene.shapes.size())) { bvh.shapes[idx] = make_shape_bvh(scene.shapes[idx], highquality); } } else { @@ -654,7 +654,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& bvh, node_stack[node_cur++] = node.start + 0; node_stack[node_cur++] = node.start + 1; } else if (!shape.points.empty()) { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; auto& p = shape.points[primitive]; auto eintersection = overlap_point( @@ -665,7 +665,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& bvh, max_distance = eintersection.distance; } } else if (!shape.lines.empty()) { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; auto& l = shape.lines[primitive]; auto eintersection = overlap_line(pos, max_distance, @@ -677,7 +677,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& bvh, max_distance = eintersection.distance; } } else if (!shape.triangles.empty()) { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; auto& t = shape.triangles[primitive]; auto eintersection = overlap_triangle(pos, max_distance, @@ -689,7 +689,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& bvh, max_distance = eintersection.distance; } } else if (!shape.quads.empty()) { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; auto& q = shape.quads[primitive]; auto eintersection = overlap_quad(pos, max_distance, @@ -740,7 +740,7 @@ scene_intersection overlap_scene_bvh(const scene_bvh& bvh, node_stack[node_cur++] = node.start + 0; node_stack[node_cur++] = node.start + 1; } else { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; auto& instance_ = scene.instances[primitive]; auto& shape = scene.shapes[instance_.shape]; @@ -973,7 +973,7 @@ scene_embree_bvh make_scene_embree_bvh( // shape bvhs bvh.shapes.resize(scene.shapes.size()); if (noparallel) { - for (auto idx = (size_t)0; idx < scene.shapes.size(); idx++) { + for (auto idx : range(scene.shapes.size())) { bvh.shapes[idx] = make_shape_embree_bvh(scene.shapes[idx], highquality); } } else { diff --git a/libs/yocto/yocto_cli.h b/libs/yocto/yocto_cli.h index 881a3bd44..f97e9c2ea 100644 --- a/libs/yocto/yocto_cli.h +++ b/libs/yocto/yocto_cli.h @@ -434,7 +434,7 @@ inline void add_option(cli_command& cli, const string& name, vector& value, cli.options[name] = [&value](const vector& args, string& error) { if (!_cli_parse_size(args, 1, 1024, error)) return false; value.resize(args.size()); - for (auto idx = (size_t)0; idx < args.size(); idx++) { + for (auto idx = 0; idx < (int)args.size(); idx++) { if (!_cli_parse_value(args[idx], value[idx], error)) return false; } return true; @@ -449,7 +449,7 @@ inline void add_option(cli_command& cli, const string& name, array& value, cli.usage_options += _cli_usage_option(name, value, usage); cli.options[name] = [&value](const vector& args, string& error) { if (!_cli_parse_size(args, N, N, error)) return false; - for (auto idx = (size_t)0; idx < args.size(); idx++) { + for (auto idx = 0; idx < (int)args.size(); idx++) { if (!_cli_parse_value(args[idx], value[idx], error)) return false; } return true; diff --git a/libs/yocto/yocto_gui.cpp b/libs/yocto/yocto_gui.cpp index e1d09a6f1..e067aceaf 100644 --- a/libs/yocto/yocto_gui.cpp +++ b/libs/yocto/yocto_gui.cpp @@ -479,7 +479,7 @@ void show_image_gui(const string& title, const vector& names, auto displays = vector(images.size()); auto exposures = vector(images.size(), 0); auto filmics = vector(images.size(), false); - for (auto idx = 0; idx < (int)images.size(); idx++) { + for (auto idx : range((int)images.size())) { displays[idx] = make_image(images[idx].width, images[idx].height, false); tonemap_image_mt(displays[idx], images[idx], exposures[idx], filmics[idx]); } @@ -678,7 +678,7 @@ void show_trace_gui(const string& title, const string& name, scene_data& scene, for (auto sample = 0; sample < params.samples; sample += params.batch) { if (render_stop) return; parallel_for(state.width, state.height, [&](int i, int j) { - for (auto s = 0; s < params.batch; s++) { + for (auto s : range(params.batch)) { if (render_stop) return; trace_sample(state, scene, bvh, lights, i, j, params); } @@ -2275,7 +2275,7 @@ bool draw_gui_combobox(const char* lbl, int& idx, int num, if (idx < 0) ImGui::SetItemDefaultFocus(); ImGui::PopID(); } - for (auto i = 0; i < num; i++) { + for (auto i : range(num)) { ImGui::PushID(i); if (ImGui::Selectable(labels(i).c_str(), idx == i)) idx = i; if (idx == i) ImGui::SetItemDefaultFocus(); diff --git a/libs/yocto/yocto_image.cpp b/libs/yocto/yocto_image.cpp index 221304104..67fb90be1 100644 --- a/libs/yocto/yocto_image.cpp +++ b/libs/yocto/yocto_image.cpp @@ -128,7 +128,7 @@ void convert_image(image_data& result, const image_data& image) { if (image.linear == result.linear) { result.pixels = image.pixels; } else { - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { result.pixels[idx] = image.linear ? rgb_to_srgb(image.pixels[idx]) : srgb_to_rgb(image.pixels[idx]); } @@ -198,12 +198,12 @@ void tonemap_image( throw std::invalid_argument{"image should be the same size"}; if (result.linear) throw std::invalid_argument{"ldr expected"}; if (image.linear) { - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { result.pixels[idx] = tonemap(image.pixels[idx], exposure, filmic); } } else { auto scale = vec4f{pow(2, exposure), pow(2, exposure), pow(2, exposure), 1}; - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { result.pixels[idx] = image.pixels[idx] * scale; } } @@ -265,7 +265,7 @@ image_data image_difference( // compute diff auto difference = make_image(image1.width, image1.height, image1.linear); - for (auto idx = (size_t)0; idx < difference.pixels.size(); idx++) { + for (auto idx : range(difference.pixels.size())) { auto diff = abs(image1.pixels[idx] - image2.pixels[idx]); difference.pixels[idx] = display ? vec4f{max(diff), max(diff), max(diff), 1} : diff; @@ -274,8 +274,8 @@ image_data image_difference( } void set_region(image_data& image, const image_data& region, int x, int y) { - for (auto j = 0; j < region.height; j++) { - for (auto i = 0; i < region.width; i++) { + for (auto j : range(region.height)) { + for (auto i : range(region.width)) { image.pixels[(j + y) * image.width + (i + x)] = region.pixels[j * region.width + i]; } @@ -287,8 +287,8 @@ void get_region(image_data& region, const image_data& image, int x, int y, if (region.width != width || region.height != height) { region = make_image(width, height, image.linear); } - for (auto j = 0; j < height; j++) { - for (auto i = 0; i < width; i++) { + for (auto j : range(height)) { + for (auto i : range(width)) { region.pixels[j * region.width + i] = image.pixels[(j + y) * image.width + (i + x)]; } @@ -303,7 +303,7 @@ image_data composite_image( if (image_a.linear != image_b.linear) throw std::invalid_argument{"image should be of the same type"}; auto result = make_image(image_a.width, image_a.height, image_a.linear); - for (auto idx = (size_t)0; idx < result.pixels.size(); idx++) { + for (auto idx : range(result.pixels.size())) { result.pixels[idx] = composite(image_a.pixels[idx], image_b.pixels[idx]); } return result; @@ -320,7 +320,7 @@ void composite_image( throw std::invalid_argument{"image should be the same size"}; if (image_a.linear != result.linear) throw std::invalid_argument{"image should be of the same type"}; - for (auto idx = (size_t)0; idx < result.pixels.size(); idx++) { + for (auto idx : range(result.pixels.size())) { result.pixels[idx] = composite(image_a.pixels[idx], image_b.pixels[idx]); } } @@ -365,7 +365,7 @@ vec4f colorgradeb( image_data colorgrade_image( const image_data& image, const colorgrade_params& params) { auto result = make_image(image.width, image.height, false); - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { result.pixels[idx] = colorgrade(image.pixels[idx], image.linear, params); } return result; @@ -378,7 +378,7 @@ void colorgrade_image(image_data& result, const image_data& image, if (image.width != result.width || image.height != result.height) throw std::invalid_argument{"image should be the same size"}; if (!!result.linear) throw std::invalid_argument{"non linear expected"}; - for (auto idx = (size_t)0; idx < image.pixels.size(); idx++) { + for (auto idx : range(image.pixels.size())) { result.pixels[idx] = colorgrade(image.pixels[idx], image.linear, params); } } @@ -452,8 +452,8 @@ static image_data make_proc_image( int width, int height, bool linear, Shader&& shader) { auto image = make_image(width, height, linear); auto scale = 1.0f / max(width, height); - for (auto j = 0; j < height; j++) { - for (auto i = 0; i < width; i++) { + for (auto j : range(height)) { + for (auto i : range(width)) { auto uv = vec2f{i * scale, j * scale}; image.pixels[j * width + i] = shader(uv); } @@ -637,8 +637,8 @@ image_data add_border( const image_data& image, float width, const vec4f& color) { auto result = image; auto scale = 1.0f / max(image.width, image.height); - for (auto j = 0; j < image.height; j++) { - for (auto i = 0; i < image.width; i++) { + for (auto j : range(image.height)) { + for (auto i : range(image.width)) { auto uv = vec2f{i * scale, j * scale}; if (uv.x < width || uv.y < width || uv.x > image.width * scale - width || uv.y > image.height * scale - width) { @@ -798,7 +798,7 @@ image_data make_lights(int width, int height, const vec3f& le, int nlights, for (int i = 0; i < width; i++) { auto phi = 2 * pif * (float(i + 0.5f) / width); auto inlight = false; - for (auto l = 0; l < nlights; l++) { + for (auto l : range(nlights)) { auto lphi = 2 * pif * (l + 0.5f) / nlights; inlight = inlight || fabs(phi - lphi) < lwidth / 2; } @@ -1045,8 +1045,8 @@ static void make_proc_image( vector& pixels, int width, int height, Shader&& shader) { pixels.resize((size_t)width * (size_t)height); auto scale = 1.0f / max(width, height); - for (auto j = 0; j < height; j++) { - for (auto i = 0; i < width; i++) { + for (auto j : range(height)) { + for (auto i : range(width)) { auto uv = vec2f{i * scale, j * scale}; pixels[j * width + i] = shader(uv); } @@ -1231,8 +1231,8 @@ void add_border(vector& pixels, const vector& source, int width, int height, float thickness, const vec4f& color) { pixels = source; auto scale = 1.0f / max(width, height); - for (auto j = 0; j < height; j++) { - for (auto i = 0; i < width; i++) { + for (auto j : range(height)) { + for (auto i : range(width)) { auto uv = vec2f{i * scale, j * scale}; if (uv.x < thickness || uv.y < thickness || uv.x > width * scale - thickness || @@ -1389,7 +1389,7 @@ void make_lights(vector& pixels, int width, int height, const vec3f& le, for (int i = 0; i < width; i++) { auto phi = 2 * pif * (float(i + 0.5f) / width); auto inlight = false; - for (auto l = 0; l < nlights; l++) { + for (auto l : range(nlights)) { auto lphi = 2 * pif * (l + 0.5f) / nlights; inlight = inlight || fabs(phi - lphi) < lwidth / 2; } diff --git a/libs/yocto/yocto_mesh.cpp b/libs/yocto/yocto_mesh.cpp index 610901fbf..1d9910620 100644 --- a/libs/yocto/yocto_mesh.cpp +++ b/libs/yocto/yocto_mesh.cpp @@ -104,7 +104,7 @@ static int find_in_vec(const vector& vec, int x) { } static int find_in_vec(const vec3i& vec, int x) { - for (auto i = 0; i < 3; i++) + for (auto i : range(3)) if (vec[i] == x) return i; return -1; } @@ -283,7 +283,7 @@ unfold_triangle init_flat_triangle( static int find_adjacent_triangle( const vec3i& triangle, const vec3i& adjacent) { - for (auto i = 0; i < 3; i++) { + for (auto i : range(3)) { auto k = find_in_vec(adjacent, triangle[i]); if (k != -1) { if (find_in_vec(adjacent, triangle[mod3(i + 1)]) != -1) { @@ -658,7 +658,7 @@ vector triangle_fan( auto prev = face; auto node = adjacencies[face][k]; auto offset = 2 - (int)clockwise; - // for (auto i = 0; i < 256; i++) { + // for(auto i : range(256)) { while (true) { if (node == -1) break; if (node == face) break; @@ -718,8 +718,8 @@ int opposite_vertex(const vector& triangles, // Finds common edge between triangles vec2i common_edge(const vec3i& triangle0, const vec3i& triangle1) { - for (auto i = 0; i < 3; i++) { - for (auto k = 0; k < 3; k++) { + for (auto i : range(3)) { + for (auto k : range(3)) { if (triangle0[i] == triangle1[k] && triangle0[mod3(i + 1)] == triangle1[mod3(k + 2)]) return {triangle0[i], triangle0[mod3(i + 1)]}; @@ -805,7 +805,7 @@ void meandering_triangles(const vector& field, float isoline, // Find which vertex has different tag, if any. auto j = -1; - for (auto k = 0; k < 3; k++) { + for (auto k : range(3)) { if (get_tag(tr[k]) != get_tag(tr[mod3(k + 1)]) && get_tag(tr[k]) != get_tag(tr[mod3(k + 2)])) { j = k; @@ -937,7 +937,7 @@ geodesic_solver make_geodesic_solver(const vector& triangles, auto solver = geodesic_solver{}; solver.graph.resize(positions.size()); for (auto face = 0; face < (int)triangles.size(); face++) { - for (auto k = 0; k < 3; k++) { + for (auto k : range(3)) { auto a = triangles[face][k]; auto b = triangles[face][mod3(k + 1)]; @@ -1788,7 +1788,7 @@ surface_path integrate_field(const vector& triangles, const int num_steps = 10000; - for (auto i = 0; i < num_steps; i++) { + for (auto i : range(num_steps)) { auto [old_edge, old_face, old_alpha] = lerps.back(); if (old_face == -1) throw std::runtime_error("programmer error"); auto point = (1 - old_alpha) * positions[old_edge.x] + @@ -1864,7 +1864,7 @@ surface_path integrate_field(const vector& triangles, const int num_steps = 10000; - for (auto i = 0; i < num_steps; i++) { + for (auto i : range(num_steps)) { auto [old_edge, old_face, old_alpha] = lerps.back(); auto point = (1 - old_alpha) * positions[old_edge.x] + old_alpha * positions[old_edge.y]; @@ -3730,7 +3730,7 @@ static vector de_casteljau_uniform( const spline_polygon& control_points, int subdivisions) { auto segments = vector{control_points}; auto result = vector(); - for (auto subdivision = 0; subdivision < subdivisions; subdivision++) { + for (auto subdivision : range(subdivisions)) { result.resize(segments.size() * 2); for (auto i = 0; i < (int)segments.size(); i++) { auto [split0, split1] = subdivide_bezier_polygon( @@ -4643,7 +4643,7 @@ static bool is_bezier_straight_enough(const geodesic_path& a, pos[2] = eval_position(triangles, positions, c.start); pos[3] = eval_position(triangles, positions, c.end); float len = 0; - for (auto i = 0; i < 3; i++) { + for (auto i : range(3)) { len += length(pos[i] - pos[i + 1]); } if (len < params.min_curve_size) return true; @@ -4751,7 +4751,7 @@ static vector de_casteljau_adaptive( result[k * 2 + 1] = split1; }; - for (auto subdivision = 0; subdivision < params.subdivisions; subdivision++) { + for (auto subdivision : range(params.subdivisions)) { result.resize(segments.size() * 2); for (auto i = 0; i < (int)segments.size(); i++) { threads[i] = std::thread(f, i); @@ -4772,7 +4772,7 @@ static vector de_casteljau_uniform( auto segments = vector{control_points}; auto result = vector(); - for (auto subdivision = 0; subdivision < params.subdivisions; subdivision++) { + for (auto subdivision : range(params.subdivisions)) { result.resize(segments.size() * 2); for (auto i = 0; i < (int)segments.size(); i++) { auto [split0, split1] = subdivide_bezier_polygon( diff --git a/libs/yocto/yocto_noise.h b/libs/yocto/yocto_noise.h index f9b387985..dd6d3c63d 100644 --- a/libs/yocto/yocto_noise.h +++ b/libs/yocto/yocto_noise.h @@ -336,7 +336,7 @@ inline float perlin_ridge(const vec3f& p, float lacunarity, float gain, auto prev = 1.0f; auto amplitude = 0.5f; auto sum = 0.0f; - for (auto i = 0; i < octaves; i++) { + for (auto i : range(octaves)) { auto r = offset - abs(perlin_noise(p * frequency, wrap) * 2 - 1); r = r * r; sum += r * amplitude * prev; @@ -353,7 +353,7 @@ inline float perlin_fbm(const vec3f& p, float lacunarity, float gain, auto frequency = 1.0f; auto amplitude = 1.0f; auto sum = 0.0f; - for (auto i = 0; i < octaves; i++) { + for (auto i : range(octaves)) { sum += perlin_noise(p * frequency, wrap) * amplitude; frequency *= lacunarity; amplitude *= gain; @@ -367,7 +367,7 @@ inline float perlin_turbulence(const vec3f& p, float lacunarity, float gain, auto frequency = 1.0f; auto amplitude = 1.0f; auto sum = 0.0f; - for (auto i = 0; i < octaves; i++) { + for (auto i : range(octaves)) { sum += abs(perlin_noise(p * frequency, wrap) * 2 - 1) * amplitude; frequency *= lacunarity; amplitude *= gain; diff --git a/libs/yocto/yocto_scene.cpp b/libs/yocto/yocto_scene.cpp index f608053e7..0655288ae 100644 --- a/libs/yocto/yocto_scene.cpp +++ b/libs/yocto/yocto_scene.cpp @@ -756,7 +756,7 @@ void tesselate_subdiv( for (auto fid = (size_t)0; fid < subdiv.quadspos.size(); fid++) { auto qpos = subdiv.quadspos[fid]; auto qtxt = subdiv.quadstexcoord[fid]; - for (auto i = 0; i < 4; i++) { + for (auto i : range(4)) { auto& displacement_tex = scene.textures[subdiv.displacement_tex]; auto disp = mean( eval_texture(displacement_tex, subdiv.texcoords[qtxt[i]], false)); diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index 38cee874a..b69d730fb 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -462,7 +462,7 @@ bool load_image(const string& filename, image_data& image, string& error) { }; auto from_srgb = [](const byte* pixels, int width, int height) { auto pixelsf = vector((size_t)width * (size_t)height); - for (auto idx = (size_t)0; idx < pixelsf.size(); idx++) { + for (auto idx : range(pixelsf.size())) { pixelsf[idx] = byte_to_float(((vec4b*)pixels)[idx]); } return pixelsf; @@ -1808,11 +1808,11 @@ bool save_texture( // check for correct handling if (!texture.pixelsf.empty() && is_ldr_filename(filename)) { - auto ntexture = texture_data{}; - ntexture.width = texture.width; + auto ntexture = texture_data{}; + ntexture.width = texture.width; ntexture.height = texture.height; ntexture.pixelsb.resize(texture.pixelsf.size()); - for (auto idx = (size_t)0; idx < texture.pixelsf.size(); idx++) { + for (auto idx : range(texture.pixelsf.size())) { ntexture.pixelsb[idx] = float_to_byte(rgb_to_srgb(texture.pixelsf[idx])); } return save_texture(filename, ntexture, error); @@ -1822,7 +1822,7 @@ bool save_texture( ntexture.width = texture.width; ntexture.height = texture.height; ntexture.pixelsf.resize(texture.pixelsb.size()); - for (auto idx = (size_t)0; idx < texture.pixelsb.size(); idx++) { + for (auto idx : range(texture.pixelsb.size())) { ntexture.pixelsf[idx] = srgb_to_rgb(byte_to_float(texture.pixelsb[idx])); } return save_texture(filename, ntexture, error); @@ -4335,7 +4335,7 @@ static bool load_gltf_scene( // convert cameras auto cameras = vector{}; - for (auto idx = 0; idx < cgltf.cameras_count; idx++) { + for (auto idx : range(cgltf.cameras_count)) { auto& gcamera = cgltf.cameras[idx]; auto& camera = cameras.emplace_back(); if (gcamera.type == cgltf_camera_type_orthographic) { @@ -4385,14 +4385,14 @@ static bool load_gltf_scene( // convert textures auto texture_paths = vector{}; - for (auto idx = 0; idx < cgltf.images_count; idx++) { + for (auto idx : range(cgltf.images_count)) { auto& gimage = cgltf.images[idx]; scene.textures.emplace_back(); texture_paths.push_back(replace(gimage.uri, "%20", " ")); } // convert materials - for (auto idx = 0; idx < cgltf.materials_count; idx++) { + for (auto idx : range(cgltf.materials_count)) { auto& gmaterial = cgltf.materials[idx]; auto& material = scene.materials.emplace_back(); material.type = material_type::gltfpbr; @@ -4427,11 +4427,11 @@ static bool load_gltf_scene( // convert meshes auto mesh_primitives = vector>{}; - for (auto idx = 0; idx < cgltf.meshes_count; idx++) { + for (auto idx : range(cgltf.meshes_count)) { auto& gmesh = cgltf.meshes[idx]; auto& primitives = mesh_primitives.emplace_back(); if (gmesh.primitives == nullptr) continue; - for (auto idx = 0; idx < gmesh.primitives_count; idx++) { + for (auto idx : range(gmesh.primitives_count)) { auto& gprimitive = gmesh.primitives[idx]; if (gprimitive.attributes == nullptr) continue; auto& shape = scene.shapes.emplace_back(); @@ -4440,7 +4440,7 @@ static bool load_gltf_scene( instance.material = gprimitive.material ? (int)(gprimitive.material - cgltf.materials) : -1; - for (auto idx = 0; idx < gprimitive.attributes_count; idx++) { + for (auto idx : range(gprimitive.attributes_count)) { auto& gattribute = gprimitive.attributes[idx]; auto& gaccessor = *gattribute.data; if (gaccessor.is_sparse) return unsupported_error("sparse accessor"); @@ -4483,7 +4483,7 @@ static bool load_gltf_scene( continue; } // convert values - for (auto idx = (size_t)0; idx < count; idx++) { + for (auto idx : range(count)) { if (!cgltf_accessor_read_float( &gaccessor, idx, &data[idx * dcomponents], components)) return unsupported_error("accessor float conversion"); @@ -4530,7 +4530,7 @@ static bool load_gltf_scene( if (gaccessor.type != cgltf_type_scalar) return unsupported_error("non-scalar indices"); auto indices = vector(gaccessor.count); - for (auto idx = (size_t)0; idx < gaccessor.count; idx++) { + for (auto idx : range(gaccessor.count)) { if (!cgltf_accessor_read_uint( &gaccessor, idx, (cgltf_uint*)&indices[idx], 1)) return unsupported_error("accessor uint conversion"); @@ -4579,7 +4579,7 @@ static bool load_gltf_scene( } // convert nodes - for (auto idx = 0; idx < cgltf.nodes_count; idx++) { + for (auto idx : range(cgltf.nodes_count)) { auto& gnode = cgltf.nodes[idx]; if (gnode.camera != nullptr) { auto& camera = scene.cameras.emplace_back(); @@ -4665,7 +4665,7 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, // cameras if (!scene.cameras.empty()) { alloc_array(cgltf.cameras_count, cgltf.cameras, scene.cameras.size()); - for (auto idx = (size_t)0; idx < scene.cameras.size(); idx++) { + for (auto idx : range(scene.cameras.size())) { auto& camera = scene.cameras[idx]; auto& gcamera = cgltf.cameras[idx]; gcamera.name = copy_string(get_camera_name(scene, camera)); @@ -4683,11 +4683,11 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, alloc_array(cgltf.textures_count, cgltf.textures, scene.textures.size()); alloc_array(cgltf.images_count, cgltf.images, scene.textures.size()); alloc_array(cgltf.samplers_count, cgltf.samplers, 1); - auto& gsampler = cgltf.samplers[0]; - gsampler.name = copy_string("sampler"); + auto& gsampler = cgltf.samplers[0]; + gsampler.name = copy_string("sampler"); gsampler.wrap_s = 10497; gsampler.wrap_t = 10497; - for (auto idx = (size_t)0; idx < scene.textures.size(); idx++) { + for (auto idx : range(scene.textures.size())) { auto& texture = scene.textures[idx]; auto& gtexture = cgltf.textures[idx]; auto& gimage = cgltf.images[idx]; @@ -4703,18 +4703,18 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, // materials if (!scene.materials.empty()) { alloc_array(cgltf.materials_count, cgltf.materials, scene.materials.size()); - for (auto idx = (size_t)0; idx < scene.materials.size(); idx++) { + for (auto idx : range(scene.materials.size())) { auto& material = scene.materials[idx]; auto& gmaterial = cgltf.materials[idx]; gmaterial.name = copy_string(get_material_name(scene, material)); - auto emission_scale = max(material.emission) > 1.0f ? max(material.emission) - : 1.0f; + auto emission_scale = + max(material.emission) > 1.0f ? max(material.emission) : 1.0f; gmaterial.emissive_factor[0] = material.emission.x / emission_scale; gmaterial.emissive_factor[1] = material.emission.y / emission_scale; gmaterial.emissive_factor[2] = material.emission.z / emission_scale; if (emission_scale > 1.0f) { - gmaterial.has_emissive_strength = true; - gmaterial.emissive_strength.emissive_strength = emission_scale; + gmaterial.has_emissive_strength = true; + gmaterial.emissive_strength.emissive_strength = emission_scale; } gmaterial.has_pbr_metallic_roughness = true; auto& gpbr = gmaterial.pbr_metallic_roughness; @@ -4772,10 +4772,10 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, gaccessor.component_type = cgltf_component_type_r_32f; gaccessor.has_min = true; gaccessor.has_max = true; - for (auto component = 0; component < components; component++) { + for (auto component : range(components)) { gaccessor.min[component] = flt_max; gaccessor.max[component] = flt_min; - for (auto idx = 0; idx < count; idx++) { + for (auto idx : range(count)) { gaccessor.min[component] = min( gaccessor.min[component], data[idx * components + component]); gaccessor.max[component] = max( @@ -4800,7 +4800,7 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, gaccessor.component_type = cgltf_component_type_r_32u; gbuffer.size += gbufferview.size; }; - for (auto idx = (size_t)0; idx < scene.shapes.size(); idx++) { + for (auto idx : range(scene.shapes.size())) { auto& shape = scene.shapes[idx]; auto& gbuffer = cgltf.buffers[idx]; shape_accessor_start[idx] = cgltf.accessors_count; @@ -4819,10 +4819,11 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, add_element(cgltf, gbuffer, shape.points.size(), cgltf_type_scalar); add_element(cgltf, gbuffer, shape.lines.size(), cgltf_type_vec2); add_element(cgltf, gbuffer, shape.triangles.size(), cgltf_type_vec3); - add_element(cgltf, gbuffer, quads_to_triangles(shape.quads).size(), cgltf_type_vec3); + add_element(cgltf, gbuffer, quads_to_triangles(shape.quads).size(), + cgltf_type_vec3); } } - + // meshes using mesh_key = pair; struct mesh_hash { @@ -4835,7 +4836,7 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, if (!scene.instances.empty()) { alloc_array(cgltf.meshes_count, cgltf.meshes, scene.instances.size()); cgltf.meshes_count = 0; - for (auto idx = (size_t)0; idx < scene.instances.size(); idx++) { + for (auto idx : range(scene.instances.size())) { auto& instance = scene.instances[idx]; if (mesh_map.find({instance.shape, instance.material}) != mesh_map.end()) continue; @@ -4898,16 +4899,16 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, if (!scene.cameras.empty() || !scene.instances.empty()) { alloc_array(cgltf.nodes_count, cgltf.nodes, scene.cameras.size() + scene.instances.size() + 1); - for (auto idx = (size_t)0; idx < scene.cameras.size(); idx++) { + for (auto idx : range(scene.cameras.size())) { auto& camera = scene.cameras[idx]; auto& gnode = cgltf.nodes[idx]; gnode.name = copy_string(get_camera_name(scene, camera)); auto xform = frame_to_mat(camera.frame); memcpy(gnode.matrix, &xform, sizeof(mat4f)); gnode.has_matrix = true; - gnode.camera = cgltf.cameras + idx; + gnode.camera = cgltf.cameras + idx; } - for (auto idx = (size_t)0; idx < scene.instances.size(); idx++) { + for (auto idx : range(scene.instances.size())) { auto& instance = scene.instances[idx]; auto& gnode = cgltf.nodes[idx + scene.cameras.size()]; gnode.name = copy_string(get_instance_name(scene, instance)); @@ -4921,7 +4922,7 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, auto& groot = cgltf.nodes[cgltf.nodes_count - 1]; groot.name = copy_string("root"); alloc_array(groot.children_count, groot.children, cgltf.nodes_count - 1); - for (auto idx = (size_t)0; idx < cgltf.nodes_count - 1; idx++) + for (auto idx : range(cgltf.nodes_count - 1)) groot.children[idx] = cgltf.nodes + idx; // scene alloc_array(cgltf.scenes_count, cgltf.scenes, 1); @@ -4932,11 +4933,11 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, } // save gltf - auto options = cgltf_options{}; + auto options = cgltf_options{}; memset(&options, 0, sizeof(options)); options.memory.free = [](void*, void* ptr) { free(ptr); }; cgltf.memory.free = [](void*, void* ptr) { free(ptr); }; - auto result = cgltf_write_file(&options, filename.c_str(), &cgltf); + auto result = cgltf_write_file(&options, filename.c_str(), &cgltf); if (result != cgltf_result_success) { error = "cannot save " + filename; cgltf_free(&cgltf); @@ -4982,7 +4983,8 @@ static bool save_gltf_scene(const string& filename, const scene_data& scene, // save textures if (!parallel_foreach( scene.textures, error, [&](auto& texture, string& error) { - auto path = "textures/" + get_texture_name(scene, texture) + ".png"; + auto path = "textures/" + get_texture_name(scene, texture) + + ".png"; return save_texture(path_join(dirname, path), texture, error); })) return dependent_error(); diff --git a/libs/yocto/yocto_shape.cpp b/libs/yocto/yocto_shape.cpp index 400fb27f2..9a470a260 100644 --- a/libs/yocto/yocto_shape.cpp +++ b/libs/yocto/yocto_shape.cpp @@ -550,8 +550,8 @@ static shape_data make_quads( shape.positions.resize((steps.x + 1) * (steps.y + 1)); shape.normals.resize((steps.x + 1) * (steps.y + 1)); shape.texcoords.resize((steps.x + 1) * (steps.y + 1)); - for (auto j = 0; j <= steps.y; j++) { - for (auto i = 0; i <= steps.x; i++) { + for (auto j : range(steps.y + 1)) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, j / (float)steps.y}; shape.positions[j * (steps.x + 1) + i] = { (2 * uv.x - 1) * scale.x, (2 * uv.y - 1) * scale.y, 0}; @@ -561,8 +561,8 @@ static shape_data make_quads( } shape.quads.resize(steps.x * steps.y); - for (auto j = 0; j < steps.y; j++) { - for (auto i = 0; i < steps.x; i++) { + for (auto j : range(steps.y)) { + for (auto i : range(steps.x)) { shape.quads[j * steps.x + i] = {j * (steps.x + 1) + i, j * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i}; @@ -726,7 +726,7 @@ shape_data make_rect_stack( const vec3i& steps, const vec3f& scale, const vec2f& uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; - for (auto i = 0; i <= steps.z; i++) { + for (auto i : range(steps.z + 1)) { qshape = make_rect({steps.x, steps.y}, {scale.x, scale.y}, uvscale); for (auto& p : qshape.positions) p.z = (-1 + 2 * (float)i / steps.z) * scale.z; @@ -967,8 +967,8 @@ shape_data make_lines(const vec2i& steps, const vec2f& scale, shape.texcoords.resize((steps.x + 1) * steps.y); shape.radius.resize((steps.x + 1) * steps.y); if (steps.y > 1) { - for (auto j = 0; j < steps.y; j++) { - for (auto i = 0; i <= steps.x; i++) { + for (auto j : range(steps.y)) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, j / (float)(steps.y - 1)}; shape.positions[j * (steps.x + 1) + i] = { (uv.x - 0.5f) * scale.x, (uv.y - 0.5f) * scale.y, 0}; @@ -978,7 +978,7 @@ shape_data make_lines(const vec2i& steps, const vec2f& scale, } } } else { - for (auto i = 0; i <= steps.x; i++) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, 0}; shape.positions[i] = {(uv.x - 0.5f) * scale.x, 0, 0}; shape.normals[i] = {1, 0, 0}; @@ -1014,7 +1014,7 @@ shape_data make_point(float radius) { shape_data make_points(int num, float uvscale, float radius) { auto shape = shape_data{}; shape.points.resize(num); - for (auto i = 0; i < num; i++) shape.points[i] = i; + for (auto i : range(num)) shape.points[i] = i; shape.positions.assign(num, {0, 0, 0}); shape.normals.assign(num, {0, 0, 1}); shape.texcoords.assign(num, {0, 0}); @@ -1285,7 +1285,7 @@ shape_data make_hair(const shape_data& base, const vec2i& steps, for (auto bidx = 0; bidx < (int)bpos.size(); bidx++) { cidx.push_back(0); auto cdist = flt_max; - for (auto c = 0; c < clump.y; c++) { + for (auto c : range(clump.y)) { auto d = length(bpos[bidx] - bpos[c]); if (d < cdist) { cdist = d; @@ -1349,7 +1349,7 @@ shape_data make_hair2(const shape_data& base, const vec2i& steps, auto shape = make_lines(steps, {1, 1}, {1, 1}, radius); auto rng = make_rng(seed); - for (auto idx = 0; idx < steps.y; idx++) { + for (auto idx : range(steps.y)) { auto offset = idx * (steps.x + 1); auto position = bpositions[idx]; auto direction = bnormals[idx]; @@ -1374,8 +1374,8 @@ shape_data make_hair2(const shape_data& base, const vec2i& steps, shape_data make_heightfield(const vec2i& size, const vector& height) { auto shape = make_recty({size.x - 1, size.y - 1}, vec2f{(float)size.x, (float)size.y} / (float)max(size), {1, 1}); - for (auto j = 0; j < size.y; j++) - for (auto i = 0; i < size.x; i++) + for (auto j : range(size.y)) + for (auto i : range(size.x)) shape.positions[j * size.x + i].y = height[j * size.x + i]; shape.normals = quads_normals(shape.quads, shape.positions); return shape; @@ -1383,8 +1383,8 @@ shape_data make_heightfield(const vec2i& size, const vector& height) { shape_data make_heightfield(const vec2i& size, const vector& color) { auto shape = make_recty({size.x - 1, size.y - 1}, vec2f{(float)size.x, (float)size.y} / (float)max(size), {1, 1}); - for (auto j = 0; j < size.y; j++) - for (auto i = 0; i < size.x; i++) + for (auto j : range(size.y)) + for (auto i : range(size.x)) shape.positions[j * size.x + i].y = mean(xyz(color[j * size.x + i])); shape.normals = quads_normals(shape.quads, shape.positions); return shape; @@ -1873,7 +1873,7 @@ vector> vertex_adjacencies( auto face_from_vertex = vector(triangles.size() * 3, -1); for (auto i = 0; i < (int)triangles.size(); ++i) { - for (auto k = 0; k < 3; k++) { + for (auto k : range(3)) { face_from_vertex[triangles[i][k]] = i; num_vertices = max(num_vertices, triangles[i][k]); } @@ -1919,7 +1919,7 @@ vector> vertex_to_faces_adjacencies( auto face_from_vertex = vector(triangles.size() * 3, -1); for (auto i = 0; i < (int)triangles.size(); ++i) { - for (auto k = 0; k < 3; k++) { + for (auto k : range(3)) { face_from_vertex[triangles[i][k]] = i; num_vertices = max(num_vertices, triangles[i][k]); } @@ -2109,11 +2109,11 @@ static void update_bvh(bvh_tree& bvh, const vector& bboxes) { auto& node = bvh.nodes[nodeid]; node.bbox = invalidb3f; if (node.internal) { - for (auto idx = 0; idx < 2; idx++) { + for (auto idx : range(2)) { node.bbox = merge(node.bbox, bvh.nodes[node.start + idx].bbox); } } else { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { node.bbox = merge(node.bbox, bboxes[bvh.primitives[node.start + idx]]); } } @@ -2279,7 +2279,7 @@ static bool intersect_elements_bvh(const bvh_tree& bvh, node_stack[node_cur++] = node.start + 0; } } else { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; if (intersect_element(primitive, ray, uv, distance)) { hit = true; @@ -2392,7 +2392,7 @@ static bool overlap_elements_bvh(const bvh_tree& bvh, Overlap&& overlap_element, node_stack[node_cur++] = node.start + 0; node_stack[node_cur++] = node.start + 1; } else { - for (auto idx = 0; idx < node.num; idx++) { + for (auto idx : range(node.num)) { auto primitive = bvh.primitives[node.start + idx]; if (overlap_element(primitive, pos, max_distance, uv, distance)) { hit = true; @@ -2604,7 +2604,7 @@ void split_facevarying(vector& split_quads, unordered_map vert_map; split_quads.resize(quadspos.size()); for (auto fid = 0; fid < (int)quadspos.size(); fid++) { - for (auto c = 0; c < 4; c++) { + for (auto c : range(4)) { auto v = vec3i{ (&quadspos[fid].x)[c], (!quadsnorm.empty()) ? (&quadsnorm[fid].x)[c] : -1, @@ -3232,7 +3232,7 @@ void sample_triangles(vector& sampled_positions, sampled_texcoords.resize(npoints); auto cdf = sample_triangles_cdf(triangles, positions); auto rng = make_rng(seed); - for (auto i = 0; i < npoints; i++) { + for (auto i : range(npoints)) { auto sample = sample_triangles(cdf, rand1f(rng), rand2f(rng)); auto& t = triangles[sample.first]; auto uv = sample.second; @@ -3267,7 +3267,7 @@ void sample_quads(vector& sampled_positions, sampled_texcoords.resize(npoints); auto cdf = sample_quads_cdf(quads, positions); auto rng = make_rng(seed); - for (auto i = 0; i < npoints; i++) { + for (auto i : range(npoints)) { auto sample = sample_quads(cdf, rand1f(rng), rand2f(rng)); auto& q = quads[sample.first]; auto uv = sample.second; @@ -3303,8 +3303,8 @@ void make_rect(vector& quads, vector& positions, positions.resize((steps.x + 1) * (steps.y + 1)); normals.resize((steps.x + 1) * (steps.y + 1)); texcoords.resize((steps.x + 1) * (steps.y + 1)); - for (auto j = 0; j <= steps.y; j++) { - for (auto i = 0; i <= steps.x; i++) { + for (auto j : range(steps.y + 1)) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, j / (float)steps.y}; positions[j * (steps.x + 1) + i] = { (2 * uv.x - 1) * scale.x, (2 * uv.y - 1) * scale.y, 0}; @@ -3314,8 +3314,8 @@ void make_rect(vector& quads, vector& positions, } quads.resize(steps.x * steps.y); - for (auto j = 0; j < steps.y; j++) { - for (auto i = 0; i < steps.x; i++) { + for (auto j : range(steps.y)) { + for (auto i : range(steps.x)) { quads[j * steps.x + i] = {j * (steps.x + 1) + i, j * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i}; @@ -3463,7 +3463,7 @@ void make_rect_stack(vector& quads, vector& positions, auto qpositions = vector{}; auto qnormals = vector{}; auto qtexturecoords = vector{}; - for (auto i = 0; i <= steps.z; i++) { + for (auto i : range(steps.z + 1)) { make_rect(qquads, qpositions, qnormals, qtexturecoords, {steps.x, steps.y}, {scale.x, scale.y}, uvscale); for (auto& p : qpositions) p.z = (-1 + 2 * (float)i / steps.z) * scale.z; @@ -3709,8 +3709,8 @@ void make_lines(vector& lines, vector& positions, texcoords.resize((steps.x + 1) * steps.y); radius.resize((steps.x + 1) * steps.y); if (steps.y > 1) { - for (auto j = 0; j < steps.y; j++) { - for (auto i = 0; i <= steps.x; i++) { + for (auto j : range(steps.y)) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, j / (float)(steps.y - 1)}; positions[j * (steps.x + 1) + i] = { (uv.x - 0.5f) * size.x, (uv.y - 0.5f) * size.y, 0}; @@ -3720,7 +3720,7 @@ void make_lines(vector& lines, vector& positions, } } } else { - for (auto i = 0; i <= steps.x; i++) { + for (auto i : range(steps.x + 1)) { auto uv = vec2f{i / (float)steps.x, 0}; positions[i] = {(uv.x - 0.5f) * size.x, 0, 0}; normals[i] = {1, 0, 0}; @@ -3755,7 +3755,7 @@ void make_points(vector& points, vector& positions, vector& normals, vector& texcoords, vector& radius, int num, float uvscale, float point_radius) { points.resize(num); - for (auto i = 0; i < num; i++) points[i] = i; + for (auto i : range(num)) points[i] = i; positions.assign(num, {0, 0, 0}); normals.assign(num, {0, 0, 1}); texcoords.assign(num, {0, 0}); @@ -4046,7 +4046,7 @@ void make_hair(vector& lines, vector& positions, for (auto bidx = 0; bidx < (int)bpos.size(); bidx++) { cidx.push_back(0); auto cdist = flt_max; - for (auto c = 0; c < clump.y; c++) { + for (auto c : range(clump.y)) { auto d = length(bpos[bidx] - bpos[c]); if (d < cdist) { cdist = d; @@ -4109,7 +4109,7 @@ void make_hair2(vector& lines, vector& positions, make_lines( lines, positions, normals, texcoords, radius, steps, {1, 1}, {1, 1}, rad); auto rng = make_rng(seed); - for (auto idx = 0; idx < steps.y; idx++) { + for (auto idx : range(steps.y)) { auto offset = idx * (steps.x + 1); auto position = bpositions[idx]; auto direction = bnormals[idx]; @@ -4152,8 +4152,8 @@ void make_heightfield(vector& quads, vector& positions, const vector& height) { make_recty(quads, positions, normals, texcoords, size - 1, vec2f{(float)size.x, (float)size.y} / (float)max(size), {1, 1}); - for (auto j = 0; j < size.y; j++) - for (auto i = 0; i < size.x; i++) + for (auto j : range(size.y)) + for (auto i : range(size.x)) positions[j * size.x + i].y = height[j * size.x + i]; normals = quads_normals(quads, positions); } @@ -4162,8 +4162,8 @@ void make_heightfield(vector& quads, vector& positions, const vector& color) { make_recty(quads, positions, normals, texcoords, size - 1, vec2f{(float)size.x, (float)size.y} / (float)max(size), {1, 1}); - for (auto j = 0; j < size.y; j++) - for (auto i = 0; i < size.x; i++) + for (auto j : range(size.y)) + for (auto i : range(size.x)) positions[j * size.x + i].y = mean(xyz(color[j * size.x + i])); normals = quads_normals(quads, positions); } diff --git a/libs/yocto/yocto_shape.h b/libs/yocto/yocto_shape.h index 3657e5763..e83163d6b 100644 --- a/libs/yocto/yocto_shape.h +++ b/libs/yocto/yocto_shape.h @@ -975,8 +975,7 @@ inline pair, vector> subdivide_lines( const vector& lines, const vector& vertices, int level) { if (level < 1) return {lines, vertices}; auto tess = pair{lines, vertices}; - for (auto idx = 0; idx < level; idx++) - tess = subdivide_lines(tess.first, tess.second); + for (auto idx : range(level)) tess = subdivide_lines(tess.first, tess.second); return tess; } // Subdivide triangle by splitting each triangle in four, creating new @@ -986,7 +985,7 @@ inline pair, vector> subdivide_triangles( const vector& triangles, const vector& vertices, int level) { if (level < 1) return {triangles, vertices}; auto tess = pair{triangles, vertices}; - for (auto idx = 0; idx < level; idx++) + for (auto idx : range(level)) tess = subdivide_triangles(tess.first, tess.second); return tess; } @@ -997,8 +996,7 @@ inline pair, vector> subdivide_quads( const vector& quads, const vector& vertices, int level) { if (level < 1) return {quads, vertices}; auto tess = pair{quads, vertices}; - for (auto idx = 0; idx < level; idx++) - tess = subdivide_quads(tess.first, tess.second); + for (auto idx : range(level)) tess = subdivide_quads(tess.first, tess.second); return tess; } // Subdivide beziers by splitting each segment in two. @@ -1007,7 +1005,7 @@ inline pair, vector> subdivide_beziers( const vector& beziers, const vector& vertices, int level) { if (level < 1) return {beziers, vertices}; auto tess = pair{beziers, vertices}; - for (auto idx = 0; idx < level; idx++) + for (auto idx : range(level)) tess = subdivide_beziers(tess.first, tess.second); return tess; } @@ -1018,7 +1016,7 @@ inline pair, vector> subdivide_catmullclark( bool lock_boundary) { if (level < 1) return {quads, vertices}; auto tess = pair{quads, vertices}; - for (auto idx = 0; idx < level; idx++) + for (auto idx : range(level)) tess = subdivide_catmullclark(tess.first, tess.second, lock_boundary); return tess; } diff --git a/libs/yocto/yocto_trace.cpp b/libs/yocto/yocto_trace.cpp index 79537597c..013c7e078 100644 --- a/libs/yocto/yocto_trace.cpp +++ b/libs/yocto/yocto_trace.cpp @@ -1511,8 +1511,8 @@ void trace_samples(trace_state& state, const scene_data& scene, const trace_params& params) { if (state.samples >= params.samples) return; if (params.noparallel) { - for (auto j = 0; j < state.height; j++) { - for (auto i = 0; i < state.width; i++) { + for (auto j : range(state.height)) { + for (auto i : range(state.width)) { trace_sample(state, scene, bvh, lights, i, j, params); } }