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 : VHACD & karimnaaji qhull implementation #781

Open
wants to merge 46 commits into
base: master
Choose a base branch
from

Conversation

Kushal-Shah-03
Copy link
Contributor

@Kushal-Shah-03 Kushal-Shah-03 commented Mar 28, 2024

For issue 89 Optimize Convex Hull Algorithm, I have added the Karimanaaji implementation : https://github.com/karimnaaji/3d-quickhull/tree/master (and the VHACD implementation from zalo's reference is also added, but I just added it as an attempt to get used to the codebase), I have written comments, as to where the algorithm is having issues with larger hulls, there are segfaults that occur in the functions of the header files, I have tried to identify the faulty function and have written that in comments as well.

Copy link

google-cla bot commented Mar 28, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@elalish
Copy link
Owner

elalish commented Mar 28, 2024

Thanks; what are your next steps? Do you need anything from us right now? And have you managed to sign the CLA (the individual one should be instant)?

@Kushal-Shah-03
Copy link
Contributor Author

In this PR I have not made any changes to any other file, except adding the two new implementations, as well as adding some testcases, I am not sure as to why some testcases are failing, could you suggest what I can try to solve those issues in my PR?

Also, for my further plan I am looking into adding some other implementations as suggested by zalo like https://github.com/tomilov/quickhull https://github.com/andreacasalino/Fast-Quick-hull , I am almost done with another implementation (I will prioritize this first). I plan of adding implementations of Graham's Scan and Chan's algorithm, as they seem like suitable alternatives. I also plan to optimize the piece of code in quickhull using parallelization.

And yes I signed the individual CLA now.

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

Attention: Patch coverage is 67.01807% with 438 lines in your changes missing coverage. Please review.

Project coverage is 74.10%. Comparing base (d437097) to head (d93bd1d).
Report is 56 commits behind head on master.

Current head d93bd1d differs from pull request most recent head 9fb9b9c

Please upload reports for the commit 9fb9b9c to get more accurate results.

Files Patch % Lines
src/utilities/include/convhull_3d.h 40.00% 405 Missing ⚠️
src/utilities/include/quickhull2.h 94.61% 27 Missing ⚠️
src/manifold/src/manifold.cpp 93.75% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #781       +/-   ##
===========================================
- Coverage   91.84%   74.10%   -17.74%     
===========================================
  Files          37       64       +27     
  Lines        4976    12115     +7139     
  Branches        0     1737     +1737     
===========================================
+ Hits         4570     8978     +4408     
- Misses        406     3137     +2731     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elalish
Copy link
Owner

elalish commented Mar 29, 2024

It looks like you've already made progress - most of it is building with tests passing. It looks like MSVC may be a bit pickier about implicit type conversions. And the fact the WASM is running out of memory is not a great sign - this probably implies the memory usage of that algorithm doesn't scale well.

It looks like you're investigating several different approaches to Convex Hull, but at some point you'll want to pick one to focus on optimizing. What is your sense so far? How do you plan to choose between them?

@Kushal-Shah-03
Copy link
Contributor Author

For the WASM, I realised, I wasn't freeing up memory at one place, so I will try to see if that solves the issue, apart from that, I'm not sure as to why build_windows is failing the error message isn't clear to me, since I haven't made any changes to minimize_testcase.cpp, maybe it's an issue with the memory as well, I will fix that and see.

So, yeah right now as suggested, I am exploring different approaches and I think some part of this project is about exploring approaches so that we can narrow down our options to say 2 or 3, and then I think I'll spend some time understanding the theory of the algorithm in depth as well as the code, to account for edge cases, and once we have the options, we can study them properly to identify bottlenecks to optimize the algorithm. About choosing, the algorithms I was reading about some common algorithms, and I found that Graham's scan and Chan's algorithm were fairly fast and handled some edge cases that quickhull couldn't. I feel while identifying which 2 or 3 to narrow it down to, we can consider some complex testcases to identify time constrains of algorithms as well as look at certain cases where the quickhull algorithm suffers, to see if we can identify an algorithm which performs better in those, and certainly we should also consider the cases where the new alogirthm we plan to use suffers, to understad the tradeoff between the algorithms better. I would appreciate your input on my thoughts as well, so that I can better understand your expectations.

@elalish
Copy link
Owner

elalish commented Mar 29, 2024

That sounds good - more speed with less maintenance is ideal. As far as correctness, I'd love to see some examples of incorrect solutions. Keep in mind that our library does inexact geometry, so I'm less picky about how nearly coplanar points are handled, so long as the result is sane. You'll notice we tend to check our test cases on volume and surface area - I think this is a good approach for Hull as well. If all the points are coplanar, I'm equally okay with returning a flat manifold or an empty manifold - same volume after all.

@Kushal-Shah-03
Copy link
Contributor Author

Yeah, regarding when I said incorrect solution, I was mainly referring to coplanar points, but I understand your arguments, as to why that isn't an issue, the other case I was considering was deleted point deletions cases I can't quite recall where I read about it, but since we are mainly considering volume and surface area that shouldn't be a major problem as well. I will still try to find cases, to see if we can identify some edge case.

Also regarding this PR, I have now passed all cases but build_windows and it's TBB, and I am working on identifying the issues but it's taking some time. I will update you once it's done so you can review it, so that I can use that feedback to improve

@Kushal-Shah-03
Copy link
Contributor Author

@elalish , so I attempted to fix the issues with build_windows, but haven't succeeded yet I have switched to windows to fix the issue, I hope to get it done, but with the proposal deadline coming closer, I wanted to prioritize writing a good proposal, to convey my thoughts better. I was wondering if you could review my code (I know it doesn't pass all checks yet, but as far as I understand it's merely an implicit typecasting issue, and I would appreciate it if you could go through the code) and give me some feedback, so that I can consider that in my proposal. I also went through the guidelines on the opencax gsoc website, and since they were quite general ( for example need for IRC username even though it's not mentioned as mode of communication used by Manifold), I was wondering if there are separate guidelines that I need to consider for this project (I will follow those on opencax as well).

PS: Sorry have been busy with institute exams lately, will certainly get back to fixing this issue soon.

@pca006132
Copy link
Collaborator

We are first year in GSoC, so we don't really have any additional guideline on that. I think as long as your proposal can demonstrate your interest as long as show some related experience in courses/other work, it should be fine. And you can replace the irc username with github handle, it should be fine.

@Kushal-Shah-03
Copy link
Contributor Author

I have a submitted a draft of my GSoC proposal on the website and would appreciate it if you could go through it once and give me feedback on it.

@pca006132
Copy link
Collaborator

which website did you submit to?

@Kushal-Shah-03
Copy link
Contributor Author

GSoC website - https://summerofcode.withgoogle.com/proposals , under BRL-CAD organization

@pca006132
Copy link
Collaborator

I think the simplest way to let us read it is to email the mentors directly, so we don't have to ask BRL-CAD admin to let us read the proposal. I think you can just me, @elalish and @zalo directly.

@Kushal-Shah-03
Copy link
Contributor Author

Alright, sorry I was not aware of that, I will send an email now

@Kushal-Shah-03
Copy link
Contributor Author

Note : Hull2 is VHACD implementation, and Hull is our current implementation

1750623.stl

VolHull_hull2 : 0.9883278400351572
AreaHull_hull2 : 0.9136602346123665

VolHull_CGAL : 0.9883278400351572
AreaHull_CGAL : 0.9136602346123665

Unnormalized values:
1750623.stl

VolHull : 113775
AreaHull : 14909.7
VolHull_hull2 : 112447
AreaHull_hull2 : 13622.4
VolHull_CGAL : 112447
AreaHull_CGAL : 13622.4

39202.stl


AreaHull_hull2 : 0.936631098033676
AreaHull_CGAL : 0.936631098033676

Unnormalized values:
39202.stl

VolHull : 274765
AreaHull : 29023.7
VolHull_hull2 : 273110
AreaHull_hull2 : 27184.5
VolHull_CGAL : 273110
AreaHull_CGAL : 27184.5

These are two cases where the outputs for volume and area for our current implementation varies from VHACD and CGAL outputs (which give the same outputs), Hull3 and Hull4 give errors on these hulls (although that is a fault of the implementations)

I was able to identify these cases when I was looking for errors in volume and area over the range of 1%, there are more occurrences when checking for 0.1% but I think going through these cases could be a good starting point for trying to identify why there's a difference.

@Kushal-Shah-03
Copy link
Contributor Author

The 5 cases of segfaults that were happening in all algorithms, were due to corrupted files or files with incorrect format, I verified that the error was in the ImportMesh function call. So, I think we can safely ignore them in further analysis.

Also, for the cases where our algorithm showed the warning of dropping horizon edges, I checked the outputs of those cases and they gave the same outputs as the other algorithms, so the outputs are accurate even when warnings are present.

For reference,
'_hull2' - refers to VHACD implementation
'_hull3' - refers to karimnaaji qhull implementation (https://github.com/karimnaaji/3d-quickhull)
'_hull4' - refers to leomccormack convex hull (https://github.com/leomccormack/convhull_3d)
'_CGAL' - refers to CGAL implementation for convex hull algorithm
and the reference that we are comparing with is our current quickhull implementation

For normalized starter statistics for the algorithms

                       mean     median      mode            max       min  Success_Count
VolHull            1.000000   1.000000  1.000000       1.000000  1.000000         9995.0
VolHull_hull2      0.999998   1.000000  1.000000       1.000135  0.988328         9993.0
VolHull_hull3      0.799843   1.000138  0.000000       1.635197  0.000000         7088.0
VolHull_hull4      0.303321   0.000000  0.000000       1.000067  0.000000         9854.0
VolHull_CGAL       0.999999   1.000000  1.000000       1.000941  0.988328         9995.0
AreaHull           1.000000   1.000000  1.000000       1.000000  1.000000         9995.0
AreaHull_hull2     0.999984   1.000000  1.000000       1.000039  0.913660         9993.0
AreaHull_hull3     0.796163   1.000016  1.000000       1.246588  0.000000         7088.0
AreaHull_hull4     0.303377   0.000000  0.000000       1.000006  0.000000         9854.0
AreaHull_CGAL      0.999984   1.000000  1.000000       1.000072  0.913660         9995.0
HullTri            1.000000   1.000000  1.000000       1.000000  1.000000         9995.0
HullTri_hull2      0.998383   1.000000  1.000000       1.605794  0.714286         9993.0
HullTri_hull3      1.144347   1.017440  1.000000      19.833333  0.000000         7088.0
HullTri_hull4      0.305715   0.000000  0.000000       2.000000  0.000000         9854.0
HullTri_CGAL       1.071703   1.000750  1.000000      11.333333  0.864198         9995.0
Time               1.000000   1.000000  1.000000       1.000000  1.000000         9995.0
Time_hull2         5.576693   2.588005  0.032369     372.584085  0.032369         9993.0
Time_hull3        56.266342  21.619789  0.050973   12634.812889  0.050973         7088.0
Time_hull4      1262.230941  17.375242  0.073636  147236.434200  0.073636         9854.0
Time_CGAL          2.699975   2.181629  0.010641     119.581236  0.010641         9995.0

Mainly for the time metric, we discussed that it's helpful to omit the cases with very small values of time, to more accurately identify the difference in time by various algorithms, so I've filtered out times less than 1ms (0.001 seconds)

                      mean     median      mode           max       min  Success_Count
VolHull           1.000000   1.000000  1.000000      1.000000  1.000000         3516.0
VolHull_hull2     0.999995   1.000000  1.000000      1.000135  0.988328         3514.0
VolHull_hull3     0.559386   1.000047  0.000000      1.317467  0.000000          995.0
VolHull_hull4     0.133583   0.000000  0.000000      1.000003  0.000000         3466.0
VolHull_CGAL      0.999996   1.000000  1.000000      1.000941  0.988328         3516.0
AreaHull          1.000000   1.000000  1.000000      1.000000  1.000000         3516.0
AreaHull_hull2    0.999956   1.000000  1.000000      1.000039  0.913660         3514.0
AreaHull_hull3    0.556907   1.000009  0.000000      1.011987  0.000000          995.0
AreaHull_hull4    0.133583   0.000000  0.000000      1.000005  0.000000         3466.0
AreaHull_CGAL     0.999956   1.000000  1.000000      1.000072  0.913660         3516.0
HullTri           1.000000   1.000000  1.000000      1.000000  1.000000         3516.0
HullTri_hull2     0.996553   1.000000  1.000000      1.605794  0.804674         3514.0
HullTri_hull3     0.568876   0.900530  0.000000      2.703125  0.000000          995.0
HullTri_hull4     0.134017   0.000000  0.000000      1.089385  0.000000         3466.0
HullTri_CGAL      1.045920   1.010335  1.000000      5.833333  0.932990         3516.0
Time              1.000000   1.000000  1.000000      1.000000  1.000000         3516.0
Time_hull2       11.741470   4.908870  0.684735    372.584085  0.684735         3514.0
Time_hull3       96.975058  42.616741  3.628361  12634.812889  3.628361          995.0
Time_hull4      301.975446  37.398160  0.073636  17927.832958  0.073636         3466.0
Time_CGAL         2.879137   2.285675  0.556763     65.602728  0.556763         3516.0

From these results it's clear that Hull3 and Hull4 are not suitable alternatives, despite Hull4 showing a lot of "success" counts, it actually returns an empty hull if it's not able to compute the output, and thus it's volume and area result in many zeroes, ultimately affecting the mean volume and hull metric. Despite, several attempts to fix this, I've not been able to, so I think it's safe to say we can drop Hull4 from our list of options.
Similarly for Hull3, it gave segfaults on many testcases, so I think we should drop Hull3 as well.

Hull2 is certainly slower but is quite accurate, so is still a suitable alternative, especially considering the discrepancy in volume and area in the cases in the prior comment #781 (comment)

With a basic idea of how to compare the algorithms, I now plan to integrate the other implementations we had discussed and run tests, so that we have a larger set of algorithms to compare with.

@Kushal-Shah-03
Copy link
Contributor Author

Note : Hull2 is VHACD implementation, and Hull is our current implementation

1750623.stl

VolHull_hull2 : 0.9883278400351572
AreaHull_hull2 : 0.9136602346123665

VolHull_CGAL : 0.9883278400351572
AreaHull_CGAL : 0.9136602346123665

Unnormalized values: 1750623.stl

VolHull : 113775
AreaHull : 14909.7
VolHull_hull2 : 112447
AreaHull_hull2 : 13622.4
VolHull_CGAL : 112447
AreaHull_CGAL : 13622.4

39202.stl


AreaHull_hull2 : 0.936631098033676
AreaHull_CGAL : 0.936631098033676

Unnormalized values: 39202.stl

VolHull : 274765
AreaHull : 29023.7
VolHull_hull2 : 273110
AreaHull_hull2 : 27184.5
VolHull_CGAL : 273110
AreaHull_CGAL : 27184.5

These are two cases where the outputs for volume and area for our current implementation varies from VHACD and CGAL outputs (which give the same outputs), Hull3 and Hull4 give errors on these hulls (although that is a fault of the implementations)

I was able to identify these cases when I was looking for errors in volume and area over the range of 1%, there are more occurrences when checking for 0.1% but I think going through these cases could be a good starting point for trying to identify why there's a difference.

Keeping this in mind, we discussed how to simplify the problem to identify what could be the issue, As suggested by @pca006132 I plan to experiment with a sort of binary search where I remove half points randomly and check the volume and area to identify the set of points that could have caused the issue and then we can evaluate it better.

I also plan to subtract the two convex hulls produced and then look at the output to see if there's a clear visual indicator of what could be the issue

@elalish, these are a couple of ideas we had to better identify the issue, if there are some other ideas that you think we can look into for the same, I will try to test them as well.

PS : @pca006132 were u able to find something about the epsilon value you were mentioning earlier

@pca006132
Copy link
Collaborator

No, I haven't yet have time to do that.

For randomly removing points to reduce the test case, it was about the warning from quickhull that says failure to resolve horizon edges.

@elalish
Copy link
Owner

elalish commented Jun 21, 2024

Excellent work! So it looks like our current hull is the fastest, but may have some significant accuracy problems. I very much like the idea of taking the difference of the two hulls - save it to a GLB and link it here. I think that will tell us a lot quickly.

@Kushal-Shah-03
Copy link
Contributor Author

Kushal-Shah-03 commented Jun 24, 2024

Excellent work! So it looks like our current hull is the fastest, but may have some significant accuracy problems. I very much like the idea of taking the difference of the two hulls - save it to a GLB and link it here. I think that will tell us a lot quickly.

Sorry for the delay, I've added the glb files here. [ Note : hull1 refers to our current implementation, hull2 refers to VHACD implementation and hull1_hull2 is the file obtained from subtracting hull2 from hull1 and similarly for hull2_hull1]

@elalish
Copy link
Owner

elalish commented Jun 25, 2024

Great, do you see where the problem is occurring? Would be nice to put some renders up here perhaps with a colored overlay so we can see where the difference is.

@Kushal-Shah-03
Copy link
Contributor Author

As discussed, after testing the other algorithms (Hull 5 and Hull 6 didn't give satisfactory results in our tests and for Hull 7 (https://github.com/melax/sandbox/blob/master/include/hull.h) the time complexity wasn't feasible in theory, and Hull 8 (https://github.com/andoresu47/ConvexHull3D) had constraints like no 3 points are colinear, which are not feasible), we have decided to continue with our current implementation and VHACD implementation.

As for the cases that gave different volumes and surface areas for our implementation and VHACD implementation, here are the important observations:

39202.stl:

Screenshot from 2024-06-27 19-16-47
Screenshot from 2024-06-27 20-56-05
Screenshot from 2024-06-27 21-13-10
Screenshot from 2024-06-28 13-56-12
Screenshot from 2024-06-28 13-56-38

From these images it's clear to see that the excess volume and area is caused due to the piece contained inside the object, this extra piece is produced by our current implementation, and is clearly something that should not be present. The VHACD implementation does not have this issue.

Similary for 1750623.stl :

Screenshot from 2024-06-28 13-58-16
Screenshot from 2024-06-28 13-58-25
Screenshot from 2024-06-28 13-58-46
Screenshot from 2024-06-28 14-00-23

The extra piece is contained inside the object, and it is also produced by our implementation but not the VHACD implementation.

I hope these renders highlight the problem clearly.

I plan to slowly reduce the number of points that persist with this issue, to investigate what caused this issue,

On a side note, for the "Failed to solve Horizon edge" warning message in our current algorithm. I've added two .bin files that contain the points that caused this issue, and their glb files. I'm attaching the photos of the hull produced in blender as well. I don't think the renders help us a lot in identifying what could have caused the issue, so I plan to use gbd to run the code to better identify what causes the warning message, and if it actually affects the output in anyway (by comparing the outputs of VHACD implementation and CGAL).

points_1411700.bin:
Screenshot from 2024-06-29 16-12-21
Screenshot from 2024-06-29 16-12-53
image

points_1411702.bin:

Screenshot from 2024-06-29 16-14-52
Screenshot from 2024-06-29 16-14-59
Screenshot from 2024-06-29 16-15-05

Also, I was thinking I should post the same example for the volume discrepancy in an issue of the repo of our current implementation, to get some ideas on what could cause the issue, while I work on reducing the number of points, does that sound alright?

@pca006132
Copy link
Collaborator

Nice figures. Yeah, you should open an issue upstream and ping us.

For debugging, you can probably try to add some print statements to print the edge/point IDs that the algorithm is processing, as well as a list of neighbors (or something similar in their algorithm). This can allow you to highlight specific edges/points in the mesh for visualization, and that should help with debugging. Think of the sorting algorithm visualization, you probably want something similar but with a mesh. I am not sure if directly using GDB to debug this kind of algorithmic issue can help you much.

@elalish
Copy link
Owner

elalish commented Jul 2, 2024

Yeah, so the bug is that our quickHull implementation is generating a very non-convex shape for this convex hull operation. Good find! Does it have any interior verts? It kind of looks like it only generated incorrect triangles. Any idea where the algorithm is going off the rails? Have you filed this as a bug upstream yet? We should try to get their opinion sooner than later.

@Kushal-Shah-03
Copy link
Contributor Author

After some testing and a bit of brute force I was able to reduce the number of points for our problematic volume down to 18. This will make it significantly easier for testing.
I've attached the .bin file containing the points (18points.bin) to prevent any loss of data from floating point conversion.

The points are added to the hull in each algorithm in this order
Note : Base refers to the points added to the base tetrahedron, Hull1 is current implementation, Hull2 is VHACD implementation

Hull1 Point Base -18.2869 31.6738 2.175
Hull1 Point Base -17.6332 -17.342 89.9628
Hull1 Point Base 49.8656 -0 55.5071
Hull1 Point Base -20.4426 -35.4077 8.275
Hull1 Point -23.0164 39.8656 79.0839
Hull1 Point 10.2294 -14.7178 10.508
Hull1 Point -24.9832 43.2722 52.7107
Hull1 Point -18.6273 -39.5444 55.5071
Hull1 Point 13.2675 -19.98 28.1179
Hull1 Point -24.9832 -40.2722 52.7107
Hull1 Point 11.1761 -22.3575 45.2756
Hull1 Point -24.9492 1.5 54.5981
Hull1 Point -25 21.8857 49.9071
Hull1 Point 18.4196 -18.2153 52.4501
Hull1 Point -25 -12.7727 49.9071
Hull1 Point -24.9832 -43.2722 52.7107
Hull1 Point 9.20583 -23.4785 55.334
Hull1 Point -1.62324 -29.7942 48.3949

Hull2 Point Base -17.6332 -17.342 89.9628
Hull2 Point Base 49.8656 -0 55.5071
Hull2 Point Base -23.0164 39.8656 79.0839
Hull2 Point Base -18.2869 31.6738 2.175
Hull2 Point -20.4426 -35.4077 8.275
Hull2 Point -24.9832 43.2722 52.7107
Hull2 Point -24.9832 -43.2722 52.7107
Hull2 Point 10.2294 -14.7178 10.508
Hull2 Point 13.2675 -19.98 28.1179
Hull2 Point -18.6273 -39.5444 55.5071
Hull2 Point -25 21.8857 49.9071
Hull2 Point -24.9492 1.5 54.5981
Hull2 Point 11.1761 -22.3575 45.2756
Hull2 Point -25 -12.7727 49.9071
Hull2 Point 18.4196 -18.2153 52.4501
Hull2 Point -1.62324 -29.7942 48.3949

The first 5 points forming the hull are same for the both algorithms, so we can safely check for the points after it.

Also, I have highlighted the two differing points (these points lead to the excess volume),
One of them "-24.9832 -40.2722 52.7107", is clearly colinear (since -24.9832 43.2722 52.7107, -24.9832 -43.2722 52.7107 are a part of the convex hull)
The other point is "9.20583 -23.4785 55.334"

These 5 points are coplanar for our case
(-24.9832, -43.2722, 52.7107) (-25, -12.7727, 49.9071) (-24.9832, -40.2722, 52.7107) (-25, 21.8857, 49.9071) (-24.9832, 43.2722, 52.7107)

I will make the upstream issue tonight after our discussion, I wanted to reduce the testcase to a smaller size and have some basic idea before I posted this issue, thus the delay.
PS : I have an interesting observation that I want to discuss with you today, it may help us identify the issue.

@Kushal-Shah-03
Copy link
Contributor Author

Hull1
Screenshot from 2024-07-03 12-30-55
Hull2
Screenshot from 2024-07-03 12-30-57

Hull1
Screenshot from 2024-07-03 12-31-33
Hull2
Screenshot from 2024-07-03 12-31-40

Hull1
Screenshot from 2024-07-03 12-31-52
Hull2
Screenshot from 2024-07-03 12-31-55

Note: Hull1 is our current implementation, Hull2 is VHACD implementation
These 6 images should give you an idea of where the points lie, and you can clearly see the location of the two differing points (one of them is collinear to one of the edges of the convex hull)

@Kushal-Shah-03
Copy link
Contributor Author

I've created the issue upstream akuukka/quickhull#23, and will now start working on a check for whether the intermediate output of the algorithm is a convex hull. I will create a pull request upstream, when I've made some progress

@elalish elalish mentioned this pull request Jul 17, 2024
@starseeker
Copy link
Contributor

starseeker commented Jul 17, 2024

Could the quickhull implementation be ported to use Manifold's existing data structures directly, if Manifold is going to have its own version of that logic? Curious how much duplication there is conceptually between Quickhull and Manifold in that regard.

@starseeker
Copy link
Contributor

starseeker commented Jul 17, 2024

I realize I'm very late in spotting this, but maybe it would be worth checking out this one if we haven't already? I've had pretty good luck with a couple other algorithmic implementations from GTE over the years:

https://www.geometrictools.com/Samples/Geometrics.html#ConvexHull3D
https://www.geometrictools.com/GTE/Mathematics/ConvexHull3.h

@elalish
Copy link
Owner

elalish commented Jul 17, 2024

Ha! I worked with David Eberly at a startup some years back - great guy. It's true, his code is pretty solid; I should have thought to look there. @starseeker If you happen to have his stuff running already, would you mind giving it a quick speed test against against ours? None of the other algorithms we've tested have been faster than quickhull so far. If it looks like it's as fast or faster, then we should probably look at it more deeply.

@starseeker
Copy link
Contributor

I don't have it running at the moment, but I might be able to set it up in the next week or two (we're working on getting a release out right now, so it'll be a little bit before I can dig into it.)

@starseeker
Copy link
Contributor

@Kushal-Shah-03 What would you suggest as the best way to get a quick comparison between quickhull and the GTE ConvexHull3.h?

@Kushal-Shah-03
Copy link
Contributor Author

@Kushal-Shah-03 What would you suggest as the best way to get a quick comparison between quickhull and the GTE ConvexHull3.h?

@starseeker , sorry for the late reply. I have written a script that runs the hull algorithm for the Thingi10K dataset and saves it in a csv file, so we can run it for the current implementation and the new implementation to compare the time and accuracy, I've cleaned it up, and added it to a new PR, I would recommend using that. I've explained how to use the testing script there.
You would have to integrate the code for the new implementation into manifold though for it to work (i.e just put the hull implementation inside a wrapper Hull function in our code, I've implemented several implementations that you can take as an example you can look at this https://github.com/Kushal-Shah-03/manifold/blob/master/src/manifold/src/manifold.cpp#L961C1-L997C2 and then some declarations at https://github.com/Kushal-Shah-03/manifold/blob/6448874ed9adba9c88470a0b8447643676da0647/src/manifold/src/manifold.cpp#L1391C1-L1391C70, https://github.com/Kushal-Shah-03/manifold/blob/master/src/manifold/src/manifold.cpp#L1428C1-L1430C2, https://github.com/Kushal-Shah-03/manifold/blob/master/src/manifold/include/manifold.h#L295C1-L297C60 would get it to work (the declarations are very simple though shouldn't be any issues)). If you do face issues in integrating the code do tag me, I'll try my best to explain the process.

@starseeker
Copy link
Contributor

I think I'm getting the general idea:
starseeker@20e566e

Looks like GTE is header only as far as this functionality goes, which is nice. I took a quick stab at merging in the Hull testing files, but I've not gotten it working as yet. Where would I download the Thingi10K dataset?

@starseeker
Copy link
Contributor

@Kushal-Shah-03 I'll be juggling a lot for the next week or two here, so I don't have a lot of bandwidth - if you're still set up to do it, any chance you could put GTE through the comparison? Hopefully the above does most of the "how to hook it in" part...

@elalish
Copy link
Owner

elalish commented Jul 25, 2024

@Kushal-Shah-03 has enough to work on for now, so I think we'll leave this one for the moment. Besides, Geometric Tools uses exact arithmetic, which isn't how Manifold operates, and it tends to cost in performance.

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.

None yet

5 participants