dilevin / computer-graphics-bounding-volume-hierarchy

Computer Graphics Assignment about Bounding Volume Hierarchies
6 stars 5 forks source link

./intersections crashes when opening the libgl viewer #86

Open AditMeh opened 8 months ago

AditMeh commented 8 months ago
> ./intersections
# Triangle Mesh Intersection Detection
  |VA| 2002  
  |FA| 4000  

  |VB| 6669  
  |FB| 13334  

  | Method      | Time in seconds |
  |:------------|----------------:|
  | brute force |   0.83611798286 |
  | build trees |   0.02045512199 |
  | use trees   |  16.40268492699 |

igl::opengl::glfw::Viewer usage:
  [drag]  Rotate scene
  A,a     Toggle animation (tight draw loop)
  D,d     Toggle double sided lighting
  F,f     Toggle face based
  I,i     Toggle invert normals
  L,l     Toggle wireframe
  O,o     Toggle orthographic/perspective projection
  T,t     Toggle filled faces
  Z       Snap to canonical view
  [,]     Toggle between rotation control types (trackball, two-axis
          valuator with fixed up, 2D mode with no rotation))
  <,>     Toggle between models
  ;       Toggle vertex labels
  :       Toggle face labels
zsh: killed     ./intersections

My code probably has a long runtime because I haven't gotten around to optimizing it, but my intersect algorithm has the same complexity as the one given in the README. However, the process gets killed (probably because it takes up too much memory). Does this mean I'm detecting too many leaf pairs? My AABB method seems to align with the brute force, so I'm confused.

Zhecheng-Wang commented 8 months ago

No, if the program is using that much memory, that means memory is being allocated but never freed.

Can you verify you are working with std::shared_ptr?

AditMeh commented 8 months ago

Yes, and I'm pretty much never allocating any new memory except for when actually making the tree. By the time it reaches the code to launch the libgl viewer screen it should have freed everything it doesn't need.

I checked the memory usage and reached near the maximum of my computer's memory before crashing. The code works for other combinations of objects though (though it also uses a lot of my computer memory). This combination specifically (../data/knight.obj and ../data/cheburashka.obj) seems to be way too costly for my machine to render.

Zhecheng-Wang commented 8 months ago

This combination specifically (../data/knight.obj and ../data/cheburashka.obj) seems to be way too costly for my machine to render.

In my implementation, intersections of those two objects don't use more than 100 MB of memory. Since intersections check is also queue-based, I would check anything involving recursion (e.g. AABB construction).

AditMeh commented 8 months ago

How many leaf pairs does your solution get for these two models? Mine is getting 53336000. I suspect it is too high an amount which is why it crashes

Zhecheng-Wang commented 8 months ago

How many leaf pairs does your solution get for these two models?

Less than 1500 pairs.

AditMeh commented 8 months ago

Then that's probably it. Both my brute force triangle-triangle intersection and AABB intersection algorithms return the same amount of pairs, but both algorithms must be incorrect in some way.

Thanks for the help