From 825a15cf6aea310c8e91a709b34c0de8422398a9 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sun, 23 Feb 2020 14:07:03 +0100 Subject: [PATCH 1/4] Shape_detection_example: Loading the points the Python way Personally, I find it very confusing that it is allowed to load points by passing a path to Point_set_3(). Logically (from what I know from Python) I would expect that open("myfile"), which is a data stream, can be passed instead. Anyway, this rewritten code should work alternatively as far as I understand the documentation of CGAL. However, I get an segmentation fault when running the example like this. This commit is therefore a more pythonic example and a bug report at the same time. Signed-off-by: Thomas Karl Pietrowski (github: thopiekar) --- examples/python/Shape_detection_example.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/python/Shape_detection_example.py b/examples/python/Shape_detection_example.py index 996003a31..0b4192333 100644 --- a/examples/python/Shape_detection_example.py +++ b/examples/python/Shape_detection_example.py @@ -8,7 +8,20 @@ datadir = os.environ.get('DATADIR', '../data') datafile = datadir+'/cube.pwn' -points = Point_set_3(datafile) +# Creating an empty set of points and their normals +points = Point_set_3() + +point_normal_file = open(datafile, "rb") +point_normal_lines = point_normal_file.readlines() + +for line in point_normal_lines: + print(line) + line = [float(entry) for entry in line.split()] + px, py, pz, nx, ny, nz = line + point_location = Point_3(px, py, pz) + point_normal = Vector_3(nx, ny, nz) + points.insert(point_location, point_normal) + print(points.size(), "points read") print("Detecting planes with region growing (sphere query)") From 87f132f15a64a37eee8f5ee228cccc306588e182 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sun, 23 Feb 2020 18:08:01 +0100 Subject: [PATCH 2/4] Shape_detection_example: Adding more comments --- examples/python/Shape_detection_example.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/python/Shape_detection_example.py b/examples/python/Shape_detection_example.py index 0b4192333..0a0034535 100644 --- a/examples/python/Shape_detection_example.py +++ b/examples/python/Shape_detection_example.py @@ -11,9 +11,12 @@ # Creating an empty set of points and their normals points = Point_set_3() +# Reading all lines point_normal_file = open(datafile, "rb") point_normal_lines = point_normal_file.readlines() +# Per line split the string, convert the values into floats, +# feed point and vector with it and insert it into our point set. for line in point_normal_lines: print(line) line = [float(entry) for entry in line.split()] From d0043bb62bf7005cde1a504f1ad32cd6912fb687 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 26 Feb 2020 18:56:15 +0100 Subject: [PATCH 3/4] examples: Shape_detection: Adding missing normal_map and reload from file Gives back the original behaviour to load a file and gives an extra example for users how to feed Point_set_3() with points and normals manually. Signed-off-by: Thomas Karl Pietrowski (github: thopiekar) --- examples/python/Shape_detection_example.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/python/Shape_detection_example.py b/examples/python/Shape_detection_example.py index 0b4192333..ff01add78 100644 --- a/examples/python/Shape_detection_example.py +++ b/examples/python/Shape_detection_example.py @@ -10,19 +10,27 @@ # Creating an empty set of points and their normals points = Point_set_3() +points.add_normal_map() point_normal_file = open(datafile, "rb") point_normal_lines = point_normal_file.readlines() for line in point_normal_lines: - print(line) line = [float(entry) for entry in line.split()] px, py, pz, nx, ny, nz = line point_location = Point_3(px, py, pz) point_normal = Vector_3(nx, ny, nz) points.insert(point_location, point_normal) -print(points.size(), "points read") +print(points.size(), "points read from Python") + +# NOTE: The following lines remove the content in our point set +# and reload the contents directly from our file. +points.clear() +points.read(datafile) + +print(points.size(), "points read from file") +# NOTE END print("Detecting planes with region growing (sphere query)") plane_map = points.add_int_map("plane_index") From 93d0ff850a7b37ee9991a73fbf0ec5c3124a432e Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 26 Feb 2020 20:31:41 +0100 Subject: [PATCH 4/4] examples: Shape_detection: Removing trailing whitespace Signed-off-by: Thomas Karl Pietrowski (github: thopiekar) --- examples/python/Shape_detection_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/python/Shape_detection_example.py b/examples/python/Shape_detection_example.py index 05fcdf9dd..7dbf7863c 100644 --- a/examples/python/Shape_detection_example.py +++ b/examples/python/Shape_detection_example.py @@ -28,7 +28,7 @@ print(points.size(), "points read from Python") # NOTE: The following lines remove the content in our point set -# and reload the contents directly from our file. +# and reload the contents directly from our file. points.clear() points.read(datafile)