-
Notifications
You must be signed in to change notification settings - Fork 79
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
Octree gives various clojure.lang level errors #75
Comments
(reduce #(g/add-point % %2 %2)
(st/octree 0 0 0 100 100 100)
[[0 0 0]
[-1.9446942785288333 -4.311887733904416 -0.5723572012550799]
[-0.2643569452823872 0.8996130544133574 4.885296326158475]
; [-0.4272646031 3795933 -0.8410052835626067 -4.894709960433672]]
]))
but remove a minus sign from the third number in the second vec and all is well: (reduce #(g/add-point % %2 %2)
(st/octree 0 0 0 100 100 100)
[[0 0 0]
[-1.9446942785288333 -4.311887733904416 0.5723572012550799]
[-0.2643569452823872 0.8996130544133574 4.885296326158475]
; [-0.4272646031 3795933 -0.8410052835626067 -4.894709960433672]]
])) #thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [100.0 100.0 100.0]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [50.0 50.0 50.0]} :children [#thi.ng.geom.sp
atialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [25.0 25.0 25.0]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [12.5 12.5 12.5]} :children [#thi.ng.geom.spatialtree.MutableO
ctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [6.25 6.25 6.25]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [3.125 3.125 3.125]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:boun
ds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [1.5625 1.5625 1.5625]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [0.78125 0.78125 0.78125]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds
#thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [0.390625 0.390625 0.390625]} :children nil :p [0 0 0] :d [0 0 0]} nil nil nil #thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.390625], :size [0.390625 0.390625 0.390625]} :children nil
:p [-1.9446942785288333 -4.311887733904416 0.5723572012550799] :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]} nil nil nil ni
l nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil #thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 3.125], :size [3.125 3.125 3.125]} :children nil :p [-0.2643569452823872 0.89961305441335
74 4.885296326158475] :d [-0.2643569452823872 0.8996130544133574 4.885296326158475]} nil nil nil] :p nil :d [0 0 0]} nil nil nil nil nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]} nil nil n
il nil nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]}
#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [100.0 100.0 100.0]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [50.0 50.0 50.0]} :children [#thi.ng.geom.sp
atialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [25.0 25.0 25.0]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [12.5 12.5 12.5]} :children [#thi.ng.geom.spatialtree.MutableO
ctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [6.25 6.25 6.25]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [3.125 3.125 3.125]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:boun
ds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [1.5625 1.5625 1.5625]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [0.78125 0.78125 0.78125]} :children [#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds
#thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [0.390625 0.390625 0.390625]} :children nil :p [0 0 0] :d [0 0 0]} nil nil nil #thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.390625], :size [0.390625 0.390625 0.390625]} :children nil
:p [-1.9446942785288333 -4.311887733904416 0.5723572012550799] :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]} nil nil nil ni
l nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil #thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 3.125], :size [3.125 3.125 3.125]} :children nil :p [-0.2643569452823872 0.89961305441335
74 4.885296326158475] :d [-0.2643569452823872 0.8996130544133574 4.885296326158475]} nil nil nil] :p nil :d [0 0 0]} nil nil nil nil nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]} nil nil n
il nil nil nil nil] :p nil :d [-1.9446942785288333 -4.311887733904416 0.5723572012550799]} nil nil nil nil nil nil nil] :p nil :d [0 0 0]} |
@charlieb i will take a closer look at this over the weekend. my first hunch is that the large selection sphere is in the wrong place. the octree (as defined by you) is between (0,0,0) -> (100,100,100), so the sphere should be centered around (50,50,50), not (0,0,0)... |
the other thing is that i can't recall right now how points outside the octree volume are handled (if at all). i think this might cause some issues, so please try to clamp them to the indexable region... |
That was my hunch as well but I wasn't able to get behaviour that was consistent with that hypothesis. It wasn't clear from the comments whether the second argument was only in one direction or whether it defined a region offset by a maximum from the center. I assumed the second. |
yeah, sorry - that part of the library is very much under-documented :( In general, for use cases like this (unknown/growing regions to be indexed), a k-D tree is definitely the better solution, especially if it supports rebalancing... |
No need to apologise, thank you for all your work on this! |
@charlieb @postspectacular Why is it required to center the selection sphere? If I pick a point and would like to see the neighboring points shouldn't it be possible to place the selection sphere at any point within the octree? |
So I can confirm that, as predicted earlier, the error/hang has to do with inserting points outside the defined octree volume, which really is a kind of user error, since conceptually these points are not indexable with an octree. So all you'd need to do is pre-clamping points before inserting, e.g. via: (require
'[thi.ng.geom.spatialtree :as st]
'[thi.ng.geom.vector :as v]
'[thi.ng.geom.core :as g])
(def tree (st/octree (v/vec3) (v/vec3 100)))
;; first outside point succeeds
(g/add-point tree (v/vec3 -1) nil)
#thi.ng.geom.spatialtree.MutableOctreeNode{:bounds #thi.ng.geom.types.AABB{:p [0.0 0.0 0.0], :size [100.0 100.0 100.0]} :children nil :p [-1.0 -1.0 -1.0] :d nil}
;; next outside point fails
(g/add-point tree (v/vec3 -2) nil)
;; hangs @dimovich pls ignore my comment about centered sphere :) of course you should be able to position it anywhere in the indexed space, but it was my first (and wrong) hunch, which i then replaced straight after with the other (outlier points) prediction... |
Btw. Fixing this would make a nice & easy PR. Just need to decide how to deal with the case of trying to index an outside point, e.g. return
Tree nodes implement (add-point [_ p d]
(when (g/contains-point? (g/bounds _) p)
(add-point* _ p d) _)) |
@postspectacular Yes, this works! Btw, shouldn't the tree always be returned? (add-point [_ p d]
(when (g/contains-point? (g/bounds _) p)
(add-point* _ p d)) _) |
@dimovich great - and re: always returning the tree, that's what I meant with: "Just need to decide how to deal with the case of trying to index an outside point". Using |
First let me apologise for the poor title of this issue and then apologise again for not having narrowed down the exact cases that cause these problems.
I have this piece of code
Which when run sometimes succeeds, sometimes gets to the last point and fails with
and sometimes freezes, waits and then gives this:
I'm probably breaking some (unwritten) rules in the way I'm using this but please let me know.
The text was updated successfully, but these errors were encountered: