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

examples: Shape_detection: Loading the points the Python way #157

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

thopiekar
Copy link
Collaborator

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 [email protected] (github: thopiekar)

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 <[email protected]> (github: thopiekar)
@thopiekar thopiekar changed the title Shape_detection_example: Loading the points the Python way [BUG!] Shape_detection_example: Loading the points the Python way Feb 23, 2020
@sgiraudot
Copy link
Contributor

I'm opposed to this PR.

I agree with the analysis: the fact that the reading function takes a file name instead of a data stream was done because it was simpler for us to handle the file IO from the C++ side. But indeed, it would be much better to use a stream (similarly to what is done in C++). I don't know how hard it is to bind a Python stream to a C++ STD stream, but I think it's a good idea to look into it, so again, I agree with the analysis, it'd be better to be able to do:

point_set = Point_set_3()
with open(“filename”) as file:
    point_set.read(file)

Nevertheless, focusing now on the content of this PR: I really don't see how it would be an upgrade to replace a single line that does the work of reading the file by 25 lines that basically encourage users to parse the files by themselves.

@thopiekar
Copy link
Collaborator Author

Well, it reproduces crashes I get when getting the values from somewhere else. I'm trying to use your bindings within a software, which already read all mesh data. When I feed your Point_set_3() with data as I do here, I get segmentation faults, too.
So a workaround might be to create a temporary pwn file as you have in the examples and then let your bindings read it. However, going this indirect way isn't something I'd like to do.

So back to the PR here: Yes, parsing and analysing the file like this is not the most efficent way, but doing the steps as done in line 24, 25 and 26 is probably how many other people would integrate your bindings in other software and it causes a segmentation fault as you can see in the CI, too.

@sgiraudot
Copy link
Contributor

Well, it reproduces crashes I get when getting the values from somewhere else. I'm trying to use your bindings within a software, which already read all mesh data. When I feed your Point_set_3() with data as I do here, I get segmentation faults, too.

First: sorry if this wasn't clear from my comment in #158, but there is no bug here, the crash you get is from a misuse of the package (as I explained, you need to add the normal map before inserting normals).

So back to the PR here: Yes, parsing and analysing the file like this is not the most efficent way, but doing the steps as done in line 24, 25 and 26 is probably how many other people would integrate your bindings in other software

Which is exactly what is covered in the Point_set_3 example (which also covers the normal map addition by the way).

The example here is not about feeding existing data to a Point_set_3, it's about shape detection and it uses a file, for which using the file reading function is the way to go.

…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 <[email protected]> (github: thopiekar)
@thopiekar thopiekar changed the title [BUG!] Shape_detection_example: Loading the points the Python way Shape_detection_example: Loading the points the Python way Feb 26, 2020
Signed-off-by: Thomas Karl Pietrowski <[email protected]> (github: thopiekar)
@thopiekar
Copy link
Collaborator Author

As mentioned in the previous issue ticket (which has been renamed now), I added the missing normal map. The example works as intended now.

It is up to you whether to merge it or not. 😄

@thopiekar thopiekar changed the title Shape_detection_example: Loading the points the Python way examples: Shape_detection: Loading the points the Python way Feb 26, 2020
@lrineau
Copy link
Member

lrineau commented Feb 27, 2020

I'm opposed to this PR.

I agree with the analysis: the fact that the reading function takes a file name instead of a data stream was done because it was simpler for us to handle the file IO from the C++ side. But indeed, it would be much better to use a stream (similarly to what is done in C++). I don't know how hard it is to bind a Python stream to a C++ STD stream, but I think it's a good idea to look into it, so again, I agree with the analysis, it'd be better to be able to do:

point_set = Point_set_3()
with open(“filename”) as file:
    point_set.read(file)

@sloriot Have you already wrapped any C++ I/O functions, in Python bindings?

@sloriot
Copy link
Member

sloriot commented Feb 27, 2020

I always used a filename because it is working in all target language, I never looked for an alternative.

@maxGimeno maxGimeno force-pushed the master branch 12 times, most recently from cc48c39 to ef0cb8f Compare August 5, 2020 09:25
Base automatically changed from master to main January 25, 2021 12:08
@lrineau lrineau force-pushed the main branch 3 times, most recently from 0a8d65e to d0ed7a5 Compare December 20, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants