From da9efe3b5b774afb485ad79b26236e1cece985a5 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Tue, 8 Dec 2020 13:51:09 +0100 Subject: [PATCH] updated --- apps/ymeshtest/ymeshtest.cpp | 33 ++++++++++++++++++++++++++++++++- libs/yocto/yocto_commonio.cpp | 2 +- scripts/meshtest.py | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/ymeshtest/ymeshtest.cpp b/apps/ymeshtest/ymeshtest.cpp index 97239a8d6..29b72144a 100644 --- a/apps/ymeshtest/ymeshtest.cpp +++ b/apps/ymeshtest/ymeshtest.cpp @@ -547,6 +547,30 @@ bool save_mesh_points( } } +pair validate_mesh(const vector& triangles, + const vector& positions, const vector& adjacencies) { + // check for connected components + auto visited = vector(triangles.size(), false); + auto num_visited = 0; + auto stack = vector{0}; + while (!stack.empty()) { + auto triangle = stack.back(); + stack.pop_back(); + if (visited[triangle]) continue; + visited[triangle] = true; + num_visited += 1; + for (auto neighbor : adjacencies[triangle]) { + if (neighbor < 0 || visited[neighbor]) continue; + stack.push_back(neighbor); + } + } + if (num_visited != triangles.size()) { + return {false, "not connectd"}; + } else { + return {true, ""}; + } +} + // ----------------------------------------------------------------------------- // MAIN FUNCTION // ----------------------------------------------------------------------------- @@ -590,6 +614,7 @@ int main(int argc, const char* argv[]) { if (!load_mesh( meshname, triangles, positions, normals, texcoords, colors, ioerror)) print_fatal(ioerror); + auto adjacencies = face_adjacencies(triangles); stats["mesh"] = json_value::object(); stats["mesh"]["load_time"] = elapsed_nanoseconds(load_timer); stats["mesh"]["filename"] = meshname; @@ -600,6 +625,13 @@ int main(int argc, const char* argv[]) { // check if valid if (validate) { // TODO(fabio): validation code here + auto [ok, validation] = validate_mesh(triangles, positions, adjacencies); + stats["mesh"]["valid"] = ok; + if (!ok) { + stats["mesh"]["validation"] = validation; + if (!save_json(statsname, stats, ioerror)) print_fatal(ioerror); + print_fatal("validation error: " + validation); + } } else { stats["mesh"]["valid"] = true; } @@ -639,7 +671,6 @@ int main(int argc, const char* argv[]) { // build graph print_progress("build graph", progress.x++, progress.y); auto graph_timer = simple_timer{}; - auto adjacencies = face_adjacencies(triangles); auto graph = make_dual_geodesic_solver(triangles, positions, adjacencies); stats["solver"] = json_value::object(); stats["solver"]["time"] = elapsed_nanoseconds(graph_timer); diff --git a/libs/yocto/yocto_commonio.cpp b/libs/yocto/yocto_commonio.cpp index 4835c979b..b02fcb23b 100644 --- a/libs/yocto/yocto_commonio.cpp +++ b/libs/yocto/yocto_commonio.cpp @@ -63,7 +63,7 @@ namespace yocto { void print_info(const string& msg) { printf("%s\n", msg.c_str()); } // Prints a messgae to the console and exit with an error. void print_fatal(const string& msg) { - printf("%s\n", msg.c_str()); + printf("\n%s\n", msg.c_str()); exit(1); } diff --git a/scripts/meshtest.py b/scripts/meshtest.py index 4306ba902..0120f1769 100755 --- a/scripts/meshtest.py +++ b/scripts/meshtest.py @@ -42,7 +42,7 @@ def handle_error(err, result, mesh_name, stats_name): 'meshes/', 'scenes/').replace('.obj', '.json') msg = f'[{mesh_id}/{mesh_num}] {mesh_name}' print(msg + ' ' * max(0, 78-len(msg))) - cmd = f'../yocto-gl/bin/ymeshtest {mesh_name} -s {stats_name} -S {scene_name} -p {curve_name}' + cmd = f'../yocto-gl/bin/ymeshtest -v {mesh_name} -s {stats_name} -S {scene_name} -p {curve_name}' try: retcode = subprocess.run(cmd, timeout=5, shell=True).returncode if retcode < 0: