-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: main
Are you sure you want to change the base?
Conversation
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)
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. |
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 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. |
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).
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 |
…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)
…hopiekar/cgal-swig-bindings into master-shape-detection-example
Signed-off-by: Thomas Karl Pietrowski <[email protected]> (github: thopiekar)
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. 😄 |
@sloriot Have you already wrapped any C++ I/O functions, in Python bindings? |
I always used a filename because it is working in all target language, I never looked for an alternative. |
cc48c39
to
ef0cb8f
Compare
0a8d65e
to
d0ed7a5
Compare
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)