CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.67k stars 1.35k forks source link

Linear Cell Complex with point and id does not work with Linear_cell_complex_incremental_builder_3 #8255

Closed petlenz closed 3 weeks ago

petlenz commented 4 weeks ago

Issue Details

I wanted to switch from CGAL::Cell_attribute_with_point to CGAL::Cell_attribute_with_point_and_id but unfortunately the code below does not compile. The compile error is quite large, but I can provide it if needed.

Source Code

#include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
#include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
#include <CGAL/Cell_attribute_with_point_and_id.h>
#include <vector>

struct dartItem
{
    using Use_index=CGAL::Tag_true;
    using Index_type=std::size_t;
    template<class Refs>
    struct Dart_wrapper
    {
        using Vertex_attribute = CGAL::Cell_attribute_with_point_and_id<Refs,/* std::vector<double>, */CGAL::Tag_true>;
        using Edge_attribute   = CGAL::Cell_attribute_with_point_and_id<Refs,/* std::vector<double>, */CGAL::Tag_true>;
        using Facet_attribute  = CGAL::Cell_attribute_with_point_and_id<Refs,/* std::vector<double>, */CGAL::Tag_true>;
        using Attributes       = std::tuple<Vertex_attribute, Edge_attribute, Facet_attribute>;
    };
};

using Kernel            = CGAL::Exact_predicates_inexact_constructions_kernel;
using cgalLCCTraits     = CGAL::Linear_cell_complex_traits<2, Kernel> ;
using LCC_2             = CGAL::Linear_cell_complex_for_combinatorial_map<2, 2, cgalLCCTraits, dartItem>;

int main()
{
        std::vector<std::vector<std::size_t>> face_idx{{0,1,4,5}, {1,2,3,4}};
        LCC_2 lcc;
        CGAL::Linear_cell_complex_incremental_builder_3<LCC_2> ib(lcc);

        ib.add_vertex(Point(0,0)); // vertex 0
        ib.add_vertex(Point(50,0)); // vertex 1
        ib.add_vertex(Point(100,0)); // vertex 2
        ib.add_vertex(Point(100,100)); // vertex 3
        ib.add_vertex(Point(50,100)); // vertex 4
        ib.add_vertex(Point(0,100)); // vertex 5

        ib.begin_surface();
        for(const auto& face : face_idx){
            // Create a new facet version 2: begin facet
            ib.begin_facet();
            for(const auto& node : face){
                ib.add_vertex_to_facet(node);
            }
            ib.end_facet();
        }
        ib.end_surface();
}

Environment

gdamiand commented 4 weeks ago

This error is strange, there is an incompatibility between storage with index and Cell_attribute_with_point_and_id.

But in fact you use these two features incorrectly:

Taking your code, and replacing all Cell_attribute_with_point_and_id with Cell_attribute_with_point solves this issue.

petlenz commented 3 weeks ago

Removing the line using Use_index=CGAL::Tag_true; and using Cell_attribute_with_point_and_id works also fine. Thanks @gdamiand

gdamiand commented 3 weeks ago

One more remark: Cell_attribute_with_point_and_id was added in CGAL before the index version. Now this version exists, I think it is better to use it instead of Cell_attribute_with_point_and_id.