Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] AABB tree with custom iterator for VTK polydata

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] AABB tree with custom iterator for VTK polydata


Chronological Thread 
  • From: Rostislav Khlebnikov <>
  • To: <>
  • Subject: Re: [cgal-discuss] AABB tree with custom iterator for VTK polydata
  • Date: Sat, 9 Aug 2014 16:59:55 +0100

Hello again,

I am just quite curious that the first call to the all_intersections is very very slow compared to the rest. For example for mesh with about 500k triangles, the first call takes about 10 seconds, while the all the following ones with the same cutting query take about 3 milliseconds, giving the difference of 3000 times! Is there some lazy processing going on that are triggered by the first call? Is this normal anyway?

Additionally, by adding the cached converted triangle as a member of Triangles_const_iterator, setting the reference template parameter to default and returning K::Triangle_3 const& from derefence() will speed up the first 10 times (down to 1 second) and also speed up the subsequent calls to about 2 milliseconds. It is clear why this happens, but I just wanted to mention it.

So, if you could answer the questions in the first paragraph - that would be absolutely great!

Thank you,
   Rostislav.

On 08/08/2014 00:30, Rostislav Khlebnikov wrote:
Hello Sebastien,

yes, indeed changing the signature of the Triangles_const_iterator to

class Triangles_const_iterator
    : public boost::iterator_facade<
      Triangles_const_iterator
    , K::Triangle_3 const           // Value
    , boost::forward_traversal_tag  // CategoryOrTraversal
    , K::Triangle_3
    >

helped resolving the issue. Just writing this to say thanks to you and perhaps help anyone looking into similar problem.

Thanks again,
  Rostislav.

PS: still weird that it worked in release :)

On 07/08/2014 23:33, Sebastien Loriot (GeometryFactory) wrote:
Thanks for the minimal reproducible example!

Actually, if you read again the doc of boost::iterator_facade
you'll see you're using the default for reference, which is
value&. In your case, reference should be value (Triangle is a temporary).

Sebastien.

On 08/07/2014 11:14 PM, Rostislav Khlebnikov wrote:
Hi everyone,

I'm using AABB_tree to compute intersections of a VTK poly data with a
plane. When I just convert the triangles from VTK to CGAL and store them
in std list, everything works fine. However, I would like to reduce
storage requirements by creating a triangle iterator that iterates over
the VTK triangle data.
Code in main.cpp here shows how I do it http://pastebin.com/kNLQevXV
<http://pastebin.com/sKPFHTT2>

In Release version everything works fine, but in Debug version -
intersections are never found! (Funnily enough it's a debug version that
fails). I tried finding the problem - but I don't seem to understand it.
What I found is that when CGAL uses the kernel to convert from
Triangle_3 to TriangleC3 with rep() and then uses this TriangleC3's
vertex() method on line 1909 in function_objects.h, the TriangleC3
'base' variable becomes corrupted during get(base) call at line 94 in
Triangle_3.h (i.e. correct coordinates are overwritten in what seems to
be stack initialization in function call when I looked at disassembly).

Is it something wrong that I do with my custom iterator? Or perhaps it's
a bug in VS2013 compiler (I saw some bug reports regarding stack
corruption for VS2012 such as this
<http://stackoverflow.com/questions/11000798/structure-parameter-corrupted-on-function-call>,
so perhaps it's not completely resolved).

I attached all the code, input files and cmake file, so if someone who
has VTK and CGAL could quitckly test it on their platform. For me the
release version returns 54 intersections and debug - 0.

Thank you in advance,
    Rostislav.

CGAL installation info:
Windows 8.1, MSVS 2013, x64
CGAL 4.4 installed with the CGAL-4.4-Setup.exe installer and then
built
with CMake and MSVS 2013.







Archive powered by MHonArc 2.6.18.

Top of Page