cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Improvement backports from CDT_3 branch (Follow-up to PR #8170)

Open lrineau opened this issue 1 year ago • 6 comments

Summary of Changes

In the PR #8170, merged for CGAL-6.0, there was several commits that I had to revert, because they broke the testsuite results:

  • [x] commit 612d6e3f592a133a21d14a00e0ffe849b11e2b04, that modified the function save_binary_file. That was no correct as regards to the C3t3 concept. It is now fixed by commit https://github.com/CGAL/cgal/pull/8273/commits/c10dcf7daf6ba7fa8b382043a220430618492a9b from this PR.
  • [ ] commit 1ca6c17a2a165dccb2204f01d38d6d3d903d11c9, that optimized the efficiency of Polyline_constraint_hierarchy_2 using an unordered map, instead of a std::map. The issue was that is broke the determinism of Mesh_2. See https://github.com/CGAL/cgal/pull/8273#discussion_r1638397885.
  • [ ] commit ac47f30cd8a0921e52e3bd2a88fb435092eef837, that introduced an experimental tuple protocol for CGAL::Segment_3, for some CGAL kernels.
  • [x] commit df28ddc43ab3af1a54a2d9ad9587ab846707b752, that fixed a CMake warning about VTK-9.x. Now fixed by another PR (#8279).

This pull-request reintroduces those features, for CGAL-6.1.

Release Management

  • Affected package(s):
  • License and copyright ownership: maintenance by GeometryFactory

lrineau avatar Jun 10 '24 16:06 lrineau

Order of the sequence of values from the range CGAL::Constrained_triangulation_plus_2<Tr>::subconstraints()

@janetournois @afabri

  • The patch https://github.com/CGAL/cgal/pull/8273/commits/93fd96644c9e2a1aab33433880afada3e4eed02c makes the range CGAL::Constrained_triangulation_plus_2<Tr>::subconstraints() non-deterministic: instead of a std::map with a custom compare functor, now the sub-constraints are in an unordered map, for efficiency reasons. Note that the range was never documented as sorted or deterministic.
  • As my patch had broken a test from Mesh_2 (the test test_meshing), I had to fix that non-determinism. That was complicated to fix directly in Constrained_triangulation_plus_2 or Constrained_triangulation_plus_2. Instead, I have chosen to fix the only place in CGAL where the order of that range mattered, in Mesh_2/include/CGAL/Mesh_2/Refine_edges.h. See the commit https://github.com/CGAL/cgal/pull/8273/commits/82b53596fd6beaaf6c5accf2182cbdd3553b3365.

Is that correct? That is a sort of breaking change, but the ordering of Ctp_2::constraints() was never documented.

lrineau avatar Jun 13 '24 14:06 lrineau

Order of the sequence of values from the range CGAL::Constrained_triangulation_plus_2<Tr>::subconstraints()

Jane (IRL) suggested that:

  • it is documented that there is a breaking change
  • and add a Tag to Constrained_triangulation_plus_2 to allow users to fallback to the previous behavior.

lrineau avatar Jun 13 '24 15:06 lrineau

Test a comment that will not trigger build_doc.yml...

lrineau avatar Sep 23 '24 13:09 lrineau

/build:test_build_doc.yml

lrineau avatar Sep 23 '24 13:09 lrineau

Another test comment that will not trigger build_doc.yml...

lrineau avatar Sep 23 '24 13:09 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/8273/test_build_doc/Manual/index.html

github-actions[bot] avatar Sep 23 '24 13:09 github-actions[bot]

boost 1.74 is requested but some test plateforms do not have it. Do you really need that minimal version?

sloriot avatar Jan 14 '25 08:01 sloriot

Dump the requirement for Boost to 1.74 or later? (currently 1.72)

boost 1.74 is requested but some test plateforms do not have it. Do you really need that minimal version?

Short answer

Yes, I really need it.

Long answer

Actually no: I could use the ancient boost::iterator_facade from Boost.Iterator, but Boost.STLInterfaces is a lot nicer to use, and create real iterator types, even with proxy iterators like the one I wrote.

But platforms supported by CGAL-6.0 currently have also Boost 1.74 or later.

Details... (click to expand)

So...

  • there is no supported versions of Linux that is currently supported by CGAL-6.0 and will not be by CGAL-6.1,
  • all the package managers have Boost >= 1.85,
  • and for Windows that is as easy to install any version of Boost as it is for version 1.72.

lrineau avatar Jan 14 '25 16:01 lrineau

I saw that you changed it in ThirdParties.txt,. So all which remains to do is to ask Nicolas to upgrade the testsuite machines.

afabri avatar Jan 14 '25 16:01 afabri

/build:doc

lrineau avatar Jan 15 '25 08:01 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/8273/doc/Manual/index.html

github-actions[bot] avatar Jan 15 '25 08:01 github-actions[bot]

more errors:


    35>C:\CGAL_ROOT\CGAL-6.1-Ic-73\include\CGAL/Constrained_Delaunay_triangulation_2.h(912): error C2244: 'CGAL::Constrained_Delaunay_triangulation_2<Gt,Tds_,Itag_>::virtual_insert': unable to match function definition to an existing declaration [C:\CGAL_ROOT\CGAL-6.1-Ic-73\cmake\platforms\MSVC2017-Release-64bits\test\Triangulation_2\issue_3447.vcxproj]
         C:\CGAL_ROOT\CGAL-6.1-Ic-73\include\CGAL/Constrained_Delaunay_triangulation_2.h(907): note: see declaration of 'CGAL::Constrained_Delaunay_triangulation_2<Gt,Tds_,Itag_>::virtual_insert'
         C:\CGAL_ROOT\CGAL-6.1-Ic-73\include\CGAL/Constrained_Delaunay_triangulation_2.h(912): note: definition
         C:\CGAL_ROOT\CGAL-6.1-Ic-73\include\CGAL/Constrained_Delaunay_triangulation_2.h(912): note: 'Constrained_Delaunay_triangulation_2<Gt,Tds_,Itag_>::Vertex_handle CGAL::Constrained_Delaunay_triangulation_2<Gt,Tds_,Itag_>::virtual_insert(const Constrained_Delaunay_triangulation_2<Gt,Tds_,Itag_>::Geom_traits::Point_2 

afabri avatar Jan 29 '25 07:01 afabri

Meshing the triangulation with size 0...C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.16.27023\include\xtree(275) : Assertion failed: map/set iterators incompatible

here

afabri avatar Jan 30 '25 07:01 afabri

/mnt/testsuite/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h:129:61: error: static assertion failed
  129 |   BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(Point_it, std::bidirectional_iterator);

here

afabri avatar Jan 30 '25 07:01 afabri

include\CGAL/Base_with_time_stamp.h(23): error C2248: 'CGAL::Constrained_triangulation_face_base_2<K,CGAL::Triangulation_face_base_2<Gt,CGAL::Triangulation_ds_face_base_2<void>>>::Base': cannot access private typedef declared in class 'CGAL::Constrained_triangulation_face_base_2<K,CGAL::Triangulation_face_base_2<Gt,CGAL::Triangulation_ds_face_base_2<void>>>'

here

afabri avatar Jan 30 '25 07:01 afabri

Meshing the triangulation with size 0...C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.16.27023\include\xtree(275) : Assertion failed: map/set iterators incompatible

here

The code was doing bad operations with value-initialized iterators. Fixed in d837dbde218d9c24727b65b8e533404651341954.

/mnt/testsuite/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h:129:61: error: static assertion failed
  129 |   BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(Point_it, std::bidirectional_iterator);

here

With C++20, the behavior of Boost.STLinterface was different. I have fixed, and tested with and without C++20. And I found a bug in the macro BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS before Boost 1.83.0. That is fixed in 571c2ccadc440672917313d8540016894ae7fa78.

include\CGAL/Base_with_time_stamp.h(23): error C2248: 'CGAL::Constrained_triangulation_face_base_2<K,CGAL::Triangulation_face_base_2<Gt,CGAL::Triangulation_ds_face_base_2<void>>>::Base': cannot access private typedef declared in class 'CGAL::Constrained_triangulation_face_base_2<K,CGAL::Triangulation_face_base_2<Gt,CGAL::Triangulation_ds_face_base_2<void>>>'

here

A known issue with MSVC 2017 (see the repro). Fixed in 571c2ccadc440672917313d8540016894ae7fa78 as well (it should have been a distinct commit).

lrineau avatar Jan 30 '25 16:01 lrineau

Note that it might come from the time_stamp PR.

sloriot avatar Feb 01 '25 22:02 sloriot

@sloriot

Benchmarks

This PR got even bigger now. I had to:

  • fix the error handling of WKT input functions (765744e8b2ea77a00b2ba99b42f5b7e6527601c7),
  • change the CMake scripts to add CGAL_with_benchmarks as a CMake options (050677f002f7478d95a61d75c30db7c5cf27263d),
  • and then add a benchmark file using https://github.com/google/benchmark/ (bc44c91536c1ba39172d252f9a9855261a2b9f95)

Results

Using CGAL::Polyline_simplification_2::simplify on a CDT constructed from the file Data/data/wkt/norway-MP.wkt, the execution from this PR is about 18% faster than the code from master.

The results can be seen at https://cgal.geometryfactory.com/~lrineau/simplify-bench.html and in this screenshot:

Screenshot_20250206_180048

Details in text (click for more...)

Using the tool compare.py from Google Benchmark Tools...

...given that:

  • benchmark_simplify-AFTER is the file benchmark_simplify.cpp compiled from this branch, and flags -msse3 -DNDEBUG -O3 with gcc version 14.2.1,
  • benchmark_simplify-BEFORE is the same file compiled from the branch master, and same flags and compiler.

the command line was:

compare.py benchmarks build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s

The following results show that there is a speedup of about 15% (mean) or 18% (median)

RUNNING: build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s --benchmark_out=/tmp/tmpvxyq_i24
2025-02-06T17:23:08+01:00
Running Data/data/wkt/norway-MP.wkt
Run on (16 X 800 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 1280 KiB (x8)
  L3 Unified 24576 KiB (x1)
Load Average: 1.47, 2.07, 1.65
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations    #points  #polygons #polylines nb of constraints nb of sub-constraints nb of vertices
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.067 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.065 s         0.065 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.073 s         0.072 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.071 s         0.071 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.075 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.076 s         0.076 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.078 s         0.078 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.067 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.069 s         0.069 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_mean        0.069 s         0.069 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_median      0.067 s         0.067 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_stddev      0.005 s         0.005 s            20          0          0          0                 0                     0              0
simplify file Data/data/wkt/norway-MP.wkt_cv           6.73 %          6.68 %            20      0.00%      0.00%      0.00%             0.00%                 0.00%          0.00%
RUNNING: build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s --benchmark_out=/tmp/tmp59ui0dsw
2025-02-06T17:29:26+01:00
Running Data/data/wkt/norway-MP.wkt
Run on (16 X 800.961 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 1280 KiB (x8)
  L3 Unified 24576 KiB (x1)
Load Average: 1.61, 1.94, 1.73
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations    #points  #polygons #polylines nb of constraints nb of sub-constraints nb of vertices
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.057 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.065 s         0.065 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.058 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.056 s         0.056 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.053 s         0.053 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.061 s         0.061 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.058 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.052 s         0.052 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.057 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.055 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_mean        0.057 s         0.057 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_median      0.057 s         0.056 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_stddev      0.003 s         0.003 s            20          0          0          0                 0                     0              0
simplify file Data/data/wkt/norway-MP.wkt_cv           5.37 %          5.32 %            20      0.00%      0.00%      0.00%             0.00%                 0.00%          0.00%
Comparing build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE to build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt                       -0.1941         -0.1942             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1269         -0.1272             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.0900         -0.0918             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1049         -0.1065             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1204         -0.1206             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1279         -0.1282             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1962         -0.1961             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1370         -0.1377             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.0951         -0.0962             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1851         -0.1852             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2720         -0.2716             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1702         -0.1717             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2700         -0.2703             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2644         -0.2634             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2861         -0.2856             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2492         -0.2488             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2310         -0.2301             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1382         -0.1389             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1401         -0.1406             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1464         -0.1467             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_pvalue                 0.0000          0.0000      U Test, Repetitions: 20 vs 20
simplify file Data/data/wkt/norway-MP.wkt_mean                  -0.1804         -0.1806             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_median                -0.1547         -0.1549             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_stddev                -0.3458         -0.3479             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_cv                    -0.2018         -0.2041             0             0             0             0
OVERALL_GEOMEAN                                                 -0.1797         -0.1800             0             0             0             0

lrineau avatar Feb 06 '25 17:02 lrineau

@lrineau could you please fix conflicts?

sloriot avatar Feb 07 '25 13:02 sloriot

@lrineau could you please fix conflicts?

Done, with commit 8eefb7f173e320d9839048e727931e01bfdf3506.

lrineau avatar Feb 07 '25 15:02 lrineau

Successfully tested in CGAL-6.1-Ic-84 (and 85)

sloriot avatar Feb 12 '25 18:02 sloriot