Question about AABB_tree_Triangle_3_soup and primitives

53 views
Skip to first unread message

Willie Maddox

unread,
Jul 26, 2013, 11:56:19 AM7/26/13
to cgal-bindi...@googlegroups.com
Hello,

I am trying to gain a better understanding of how the AABB_tree_Triangle_3_Soup works.  Consider the following python script:

#### triangle_tree_segment_intersection.py ####
#### BEGIN ####
from CGAL.CGAL_Kernel import Point_3, Triangle_3, Segment_3

def func(p,s):
    
    from CGAL.CGAL_AABB_tree import AABB_tree_Triangle_3_soup
    
    t = [Triangle_3(p[0],p[1],p[3]),Triangle_3(p[1],p[2],p[3])]
    tree = AABB_tree_Triangle_3_soup(t)
    intersections = []
    tree.all_intersections(s, intersections)
    for i in intersections:
        print 'The segment intersects primitive',i.second,'at the point(',i.first.get_Point_3(),')'
            
pa = [Point_3(0,0,0),Point_3(0,4,0),Point_3(4,4,0),Point_3(4,0,0)]
sa = Segment_3(Point_3(1,1,-1),Point_3(1,1,1))

func(pa, sa)
func(pa, sa)

pb = [Point_3(6,0,0),Point_3(6,4,0),Point_3(10,4,0),Point_3(10,0,0)]
sb = Segment_3(Point_3(7,1,-1),Point_3(7,1,1))

func(pb, sb)

#### END ####

This script returns the following:

The segment intersects primitive 0 at the point( 1 1 -0 )
The segment intersects primitive 2 at the point( 1 1 -0 )
The segment intersects primitive 4 at the point( 7 1 -0 )

My question is this:

Should python not destroy (garbage collect) the tree object when leaving the scope of func()? If so, why then do the primitives increment?

Thanks,

-Will

Sebastien Loriot (GeometryFactory)

unread,
Jul 26, 2013, 12:14:45 PM7/26/13
to cgal-bindi...@googlegroups.com

Hi,

This is a bit hacky, there is an internal static counter
in the primitive class.

If you call t[0].reset_id() when you quit the function, it should be fine.

I don't see how I could make this automatic...

Sebastien.
> --
> You received this message because you are subscribed to the Google
> Groups "CGAL Bindings discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cgal-bindings-di...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Willie Maddox

unread,
Jul 26, 2013, 12:44:25 PM7/26/13
to cgal-bindi...@googlegroups.com
Sebastien,

Thank you for your quick response.

calling t[0].reset_id() at the end of the function throws an error:

Traceback (most recent call last):
  File "/home/maddoxw/workspace/CGAL_testing/src/triangle_tree_segment_intersection.py", line 24, in <module>
    test = func(pa, sa)
  File "/home/maddoxw/workspace/CGAL_testing/src/triangle_tree_segment_intersection.py", line 19, in func
    t[0].reset_id()
  File "/home/maddoxw/src/cgal-bindings/examples/python/CGAL/CGAL_Kernel.py", line 510, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, Triangle_3, name)
  File "/home/maddoxw/src/cgal-bindings/examples/python/CGAL/CGAL_Kernel.py", line 55, in _swig_getattr
    raise AttributeError(name)
AttributeError: reset_id

Suggestions?

-Will

Sebastien Loriot (GeometryFactory)

unread,
Jul 26, 2013, 1:16:10 PM7/26/13
to cgal-bindi...@googlegroups.com
Sorry I overlooked the code. I added a workaround that is not
perfect but improves the situation.

git pull

and try

tree.reset_id()


Sebastien.

Willie Maddox

unread,
Jul 26, 2013, 2:08:05 PM7/26/13
to cgal-bindi...@googlegroups.com
That seems to do it. You say the workaround is not perfect? How could it fail?

Thanks for the update!


On Friday, July 26, 2013 10:56:19 AM UTC-5, Willie Maddox wrote:

Sebastien Loriot (GeometryFactory)

unread,
Jul 27, 2013, 3:55:53 PM7/27/13
to cgal-bindi...@googlegroups.com
Say you have two tree, the counter will be shared which can lead to unexpected behavior.

Sebastien.
Reply all
Reply to author
Forward
0 new messages