Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation for connected components in meshtest #1103

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion apps/ymeshtest/ymeshtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,30 @@ bool save_mesh_points(
}
}

pair<bool, string> validate_mesh(const vector<vec3i>& triangles,
const vector<vec3f>& positions, const vector<vec3i>& adjacencies) {
// check for connected components
auto visited = vector<bool>(triangles.size(), false);
auto num_visited = 0;
auto stack = vector<int>{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
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libs/yocto/yocto_commonio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/meshtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down