-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7805 from MaelRL/AW3-Resume_aw3-GF
Alpha wrapping: re-use and resume functionalities
- Loading branch information
Showing
40 changed files
with
2,793 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Created by the script cgal_create_cmake_script | ||
# This is the CMake script for compiling a CGAL application. | ||
|
||
cmake_minimum_required(VERSION 3.1...3.20) | ||
project(Alpha_wrap_3_Benchmark) | ||
|
||
find_package(CGAL REQUIRED) | ||
|
||
include_directories (BEFORE ../../include ./Quality ./Robustness) # AW3 includes | ||
include_directories (BEFORE ../../../CGAL-Patches/include) | ||
|
||
# create a target per cppfile | ||
create_single_source_cgal_program("Performance/performance_benchmark.cpp") | ||
create_single_source_cgal_program("Quality/quality_benchmark.cpp") | ||
create_single_source_cgal_program("Robustness/robustness_benchmark.cpp") |
61 changes: 61 additions & 0 deletions
61
Alpha_wrap_3/benchmark/Alpha_wrap_3/Performance/compute_performance_benchmark_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) 2019-2023 Google LLC (USA). | ||
# All rights reserved. | ||
# | ||
# This file is part of CGAL (www.cgal.org). | ||
# | ||
# $URL$ | ||
# $Id$ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# | ||
# Author(s) : Pierre Alliez | ||
# Michael Hemmer | ||
# Cedric Portaneri | ||
# | ||
#!/usr/bin/python | ||
|
||
import os, sys, subprocess, datetime, time, getopt | ||
|
||
def compute_performance_benchmark_data(execname, filename, alpha): | ||
|
||
output = "" | ||
cmd = ("/usr/bin/time", "-v", | ||
execname, "-i", | ||
filename, "-a", alpha) | ||
proc = subprocess.Popen( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
start_new_session=True) | ||
|
||
outs, errs = proc.communicate() | ||
output = outs.decode("utf-8") + errs.decode("utf-8") | ||
|
||
for output_line in output.split("\n"): | ||
if "User time (seconds): " in output_line: | ||
print(output_line[len("User time (seconds): "):]) | ||
continue | ||
if "Maximum resident set size (kbytes): " in output_line: | ||
print(output_line[len("Maximum resident set size (kbytes): "):]) | ||
continue | ||
|
||
def main(argv): | ||
execname="" | ||
filename="" | ||
alpha="" | ||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], 'e:i:a:') | ||
except getopt.GetoptError: | ||
sys.exit(2) | ||
for opt, arg in opts: | ||
if opt == "-e": | ||
execname = arg | ||
elif opt == "-i": | ||
filename = arg | ||
elif opt == "-a": | ||
alpha = arg | ||
|
||
compute_performance_benchmark_data(execname, filename, alpha) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
156 changes: 156 additions & 0 deletions
156
Alpha_wrap_3/benchmark/Alpha_wrap_3/Performance/generate_performance_benchmark_charts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# Copyright (c) 2019-2023 Google LLC (USA). | ||
# All rights reserved. | ||
# | ||
# This file is part of CGAL (www.cgal.org). | ||
# | ||
# $URL$ | ||
# $Id$ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# | ||
# Author(s) : Pierre Alliez | ||
# Michael Hemmer | ||
# Cedric Portaneri | ||
# | ||
#!/usr/bin/python | ||
|
||
import os, sys, subprocess, datetime, time, signal, getopt | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
def main(argv): | ||
|
||
inputdir="" | ||
outputdir="" | ||
commit_hash="" | ||
alpha="" | ||
do_diff=False | ||
diffdir="" | ||
diff_hash="" | ||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], 'i:a:o:c:d:p:') | ||
except getopt.GetoptError: | ||
sys.exit(2) | ||
for opt, arg in opts: | ||
if opt == "-i": | ||
inputdir = arg | ||
elif opt == "-a": | ||
alpha = arg | ||
elif opt == "-o": | ||
outputdir = arg | ||
elif opt == "-c": | ||
commit_hash = arg | ||
elif opt == "-d": | ||
diff_hash = arg | ||
do_diff = True | ||
elif opt == "-p": | ||
diffdir = arg | ||
|
||
all_metric = { | ||
"Time_(second)" : {}, | ||
"Memory_Peak_(kbytes)" : {}} | ||
num_input = 0 | ||
for filename in os.listdir(inputdir) : | ||
new_path = os.path.join(inputdir,filename) | ||
new_file = open(new_path) | ||
is_empty_new = os.path.getsize(new_path) <= 1 | ||
if do_diff : | ||
old_path = os.path.join(diffdir,filename) | ||
old_file = open(old_path) | ||
is_empty_old = os.path.getsize(old_path) <= 1 | ||
for key in all_metric: | ||
if is_empty_new or is_empty_old : | ||
new_val = 0. | ||
old_val = 0. | ||
else : | ||
new_val = float(new_file.readline().rstrip('\n')) | ||
old_val = float(old_file.readline().rstrip('\n')) | ||
mesh_id = str(filename.split('.')[0]) | ||
all_metric[key][mesh_id] = [new_val, old_val] | ||
else : | ||
for key in all_metric: | ||
if is_empty_new : | ||
new_val = 0. | ||
else : | ||
new_val = float(new_file.readline().rstrip('\n')) | ||
mesh_id = str(filename.split('.')[0]) | ||
all_metric[key][mesh_id] = [new_val, new_val] | ||
num_input = num_input+1 | ||
|
||
# update .pdf chart | ||
date_now = datetime.datetime.now() | ||
date_for_filename = str(date_now.year) +"_"+ str(date_now.month) +"_"+ str(date_now.day) +"_"+ str(date_now.hour) +"h"+ str(date_now.minute) +"mn" | ||
for key in all_metric: | ||
goal = 0 | ||
num_el = range(len(all_metric[key])) | ||
avg_diff_to_goal = 0. | ||
avg = 0. | ||
x1 = [] | ||
x2 = [] | ||
for value in all_metric[key].values() : | ||
avg += value[0] | ||
diff_to_goal = abs(value[1]-goal) - abs(value[0]-goal) | ||
avg_diff_to_goal += diff_to_goal | ||
x1.append(value[0]) | ||
x2.append(value[1]) | ||
avg_diff_to_goal /= float(len(all_metric[key])) | ||
avg /= float(len(all_metric[key])) | ||
|
||
plt.figure(figsize=(8,8)) | ||
if do_diff : | ||
plt.hist(x2, bins=100, color='tab:green', alpha=0.5) | ||
plt.hist(x1, bins=100, color='tab:blue', alpha=0.5) | ||
plt.vlines(x = goal, ymin=plt.ylim()[0], ymax=plt.ylim()[1], linestyles='dashed') | ||
|
||
title = "" | ||
if do_diff : | ||
title += "Diff between " + commit_hash + " and " + diff_hash + " on " + str(num_input) + " meshes from Thingi10K\nAlpha = Bbox diag length / " + alpha | ||
else : | ||
title += "Benchmarking on " + str(num_input) + " meshes from Thingi10K\nAlpha = Bbox diag length / " + alpha | ||
|
||
avg_str = str(format(abs(avg), '.2f')) | ||
if key == "Time_(second)" : | ||
title += "\nIn average we spend " + avg_str + " seconds" | ||
else : | ||
title += "\nIn average we use up to " + avg_str + " kbytes" | ||
|
||
if do_diff and avg_diff_to_goal == 0. : | ||
title += "\nNo change between the two commits" | ||
elif do_diff : | ||
avg_diff_str = str(format(abs(avg_diff_to_goal), '.2f')) | ||
if key == "Time_(second)" : | ||
if avg_diff_to_goal < 0 : | ||
title += "\nIn average we get slower by " | ||
else : | ||
title += "\nIn average we get faster " | ||
title += avg_diff_str + " seconds" | ||
else : | ||
if avg_diff_to_goal < 0 : | ||
title += "\nIn average we use " + avg_diff_str + " more" | ||
else : | ||
title += "\nIn average we use " + avg_diff_str + " less" | ||
title += " kbytes" | ||
|
||
plt.title(title, fontsize=15) | ||
plt.xlabel(key.replace("_"," "), fontsize=14) | ||
plt.ylabel("# of meshes", fontsize=14) | ||
plt.tick_params(axis="x", labelsize=9) | ||
plt.tick_params(axis="y", labelsize=9) | ||
|
||
chart_filename = "" | ||
if do_diff : | ||
chart_filename += "diff_"+commit_hash+"_"+diff_hash+"_"+key+"_"+date_for_filename+".pdf" | ||
else : | ||
chart_filename += "results_"+commit_hash+"_"+key+"_"+date_for_filename+".pdf" | ||
chart_path = os.path.join(outputdir+"/charts",chart_filename) | ||
if os.path.isfile(chart_path) : | ||
os.remove(chart_path) | ||
plt.savefig(chart_path, bbox_inches="tight") | ||
plt.close() | ||
|
||
print("pdf updated") | ||
|
||
sys.exit() | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
65 changes: 65 additions & 0 deletions
65
Alpha_wrap_3/benchmark/Alpha_wrap_3/Performance/performance_benchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | ||
#include <CGAL/Surface_mesh.h> | ||
|
||
#include <CGAL/alpha_wrap_3.h> | ||
|
||
#include <CGAL/IO/polygon_soup_io.h> | ||
|
||
#include <array> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
using K = CGAL::Exact_predicates_inexact_constructions_kernel; | ||
using Point_3 = K::Point_3; | ||
using Vector_3 = K::Vector_3; | ||
|
||
using Mesh = CGAL::Surface_mesh<Point_3>; | ||
|
||
namespace PMP = CGAL::Polygon_mesh_processing; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
const int argc_check = argc - 1; | ||
const char* entry_name_ptr = nullptr; | ||
double relative_alpha_ratio = 20., relative_offset_ratio = 600.; | ||
|
||
for(int i=1; i<argc; ++i) | ||
{ | ||
if(!strcmp("-i", argv[i]) && i < argc_check) | ||
entry_name_ptr = argv[++i]; | ||
else if(!strcmp("-a", argv[i]) && i < argc_check) | ||
relative_alpha_ratio = std::stod(argv[++i]); | ||
else if(!strcmp("-d", argv[i]) && i < argc_check) | ||
relative_offset_ratio = std::stod(argv[++i]); | ||
} | ||
|
||
if(argc < 3 || relative_alpha_ratio <= 0.) | ||
{ | ||
std::cerr << "Error: bad input parameters." << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::vector<Point_3> points; | ||
std::vector<std::array<std::size_t, 3> > faces; | ||
if(!CGAL::IO::read_polygon_soup(entry_name_ptr, points, faces) || faces.empty()) | ||
{ | ||
std::cerr << "Error: Invalid input data." << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
CGAL::Bbox_3 bbox; | ||
for(const Point_3& p : points) | ||
bbox += p.bbox(); | ||
|
||
const double diag_length = std::sqrt(CGAL::square(bbox.xmax() - bbox.xmin()) + | ||
CGAL::square(bbox.ymax() - bbox.ymin()) + | ||
CGAL::square(bbox.zmax() - bbox.zmin())); | ||
const double alpha = diag_length / relative_alpha_ratio; | ||
const double offset = diag_length / relative_offset_ratio; | ||
|
||
Mesh wrap; | ||
CGAL::alpha_wrap_3(points, faces, alpha, offset, wrap); | ||
|
||
return EXIT_SUCCESS; | ||
} |
54 changes: 54 additions & 0 deletions
54
Alpha_wrap_3/benchmark/Alpha_wrap_3/Quality/compute_quality_benchmark_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright (c) 2019-2023 Google LLC (USA). | ||
# All rights reserved. | ||
# | ||
# This file is part of CGAL (www.cgal.org). | ||
# | ||
# $URL$ | ||
# $Id$ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# | ||
# Author(s) : Pierre Alliez | ||
# Michael Hemmer | ||
# Cedric Portaneri | ||
# | ||
#!/usr/bin/python | ||
|
||
import os, sys, subprocess, datetime, time, getopt | ||
|
||
def compute_quality_benchmark_data(execname, filename, alpha): | ||
|
||
output = "" | ||
cmd = (execname, "-i", | ||
filename, "-a", alpha) | ||
proc = subprocess.Popen( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
start_new_session=True) | ||
|
||
outs, errs = proc.communicate() | ||
output = outs.decode("utf-8") + errs.decode("utf-8") | ||
|
||
print(output) | ||
|
||
def main(argv): | ||
execname="" | ||
filename="" | ||
alpha="" | ||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], 'e:i:a:') | ||
except getopt.GetoptError: | ||
sys.exit(2) | ||
for opt, arg in opts: | ||
if opt == "-e": | ||
execname = arg | ||
elif opt == "-i": | ||
filename = arg | ||
elif opt == "-a": | ||
alpha = arg | ||
|
||
compute_quality_benchmark_data(execname, filename, alpha) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
Oops, something went wrong.