Как использовать информацию вершины с триангуляцией basi c с использованием CGAL - PullRequest
0 голосов
/ 01 апреля 2020

Я пытаюсь добавить информацию индекса к вершинам в базовой c 2D триангуляции с использованием CGAL для создания файла .obj, я искал много примеров этого, но большинство случаев для Delaunay_triagnulation, но я не не хочу этого, я хотел бы иметь пример для базовых c 2D триангуляции (Triangulation_2.h). Мой код такой:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Triangulation_2.h>
#include <iostream>
#include <fstream>
#include <vector>

typedef unsigned int                    TIndex;
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Triangulation_vertex_base_with_info_2<TIndex,Kernel> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb>                      Tds;
typedef CGAL::Triangulation_2<Kernel,Tds>      Triangulation;
typedef Triangulation::Point          Point;
typedef Triangulation::Finite_vertices_iterator Finite_vertices_iterator;
typedef Triangulation::Finite_faces_iterator Finite_faces_iterator;


int main()
{

    std::string input="../input.txt";
    std::string output="../triangulation.obj";
    std::vector<std::string> colors;

    colors.push_back("red");
    colors.push_back("green");
    colors.push_back("blue");
    colors.push_back("black");
    colors.push_back("yellow");
    colors.push_back("purple");

    std::ifstream input_file;
    input_file.open(input);

    if(!input_file){
        std::cout << "Cannot open file: " << input << std::endl;
        return 0;
    }

    std::vector< std::pair<Point,TIndex>> points;

    TIndex n;
    input_file >> n;

    //READING INPUT FILE
    for( TIndex i = 0; i < n; ++i )
    {
        Point p;
        input_file >> p;
        points.push_back(std::make_pair(p,i));
    }
    input_file.close();

    Triangulation T;
    T.insert(points.begin(), points.end());

    //OUTPUT FILE
    std::ofstream os(output);
    os << "mtllib material.mtl" << std::endl << std::endl;

    for(Finite_vertices_iterator it = T.finite_vertices_begin();
    it != T.finite_vertices_end();
    ++it){
        os << "v " << it->point() << " 0.0" << std::endl;
    }
    os << std::endl;

    int i=0;

    for(Finite_faces_iterator it = T.finite_faces_begin();
    it != T.finite_faces_end();
    ++it){
        os << "usemtl " << colors[i%6] << std::endl;
        os << "f " << it->vertex(0)->info() << " " << it->vertex(1)->info() << " " << it->vertex(2)->info() << std::endl;
        os << std::endl;
        i++;
    }

    std::cout << "File " << output << " generated" << std::endl;

  return 0;
}

Файл input.txt только такой:

4
0 0
0 1
1 1
2 4

Этот код выдает мне ошибку в этой строке:

T.insert(points.begin(), points.end());

ошибка компиляции примерно такая:

error: no matching function for call to ‘CGAL::Point_2<CGAL::Epick>::Point_2(std::pair<CGAL::Point_2<CGAL::Epick>, unsigned int>&)’
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/CGAL/user_classes.h:30:0,
                 from /usr/local/include/CGAL/Kernel/global_functions_2.h:34,
                 from /usr/local/include/CGAL/Kernel/global_functions.h:32,
                 from /usr/local/include/CGAL/Cartesian/Cartesian_base.h:31,
                 from /usr/local/include/CGAL/Simple_cartesian.h:29,
                 from /usr/local/include/CGAL/Exact_predicates_inexact_constructions_kernel.h:29,

Есть что-то, что я делаю неправильно с этими базовыми c триангуляциями, потому что если я использую триангуляции Делоне вместо базовых c триангуляций, код компилируется без проблем. Но, как я уже говорил, я не хочу использовать такую ​​триангуляцию.

Ответы [ 2 ]

1 голос
/ 01 апреля 2020

Если вы используете CGAL 5.0, ваш код работает. Раньше у basi c Triangulation_2 не было перегрузки insert, которая принимает пару. Затем вы должны вручную добавить индексы к вершинам. Вы должны быть в состоянии сделать что-то вроде

for( TIndex i = 0; i < n; ++i )
{
  Vb vert = T.insert(p);
  vert->info() = i;
}
1 голос
/ 01 апреля 2020

Эта перегрузка не существует для базового c Triangulation_2 класса. Это не там, потому что это эквивалентно классу подряд for (const Point& p : points) t.insert(p.first)->info()=p.second. Для Делоне это другая история, потому что вы получаете лучшее время, перетасовывая свои входные точки (что insert(begin, end) делает внутри).

...