File: File_poly.h

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (170 lines) | stat: -rw-r--r-- 4,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2004  INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Mesh_2/include/CGAL/IO/File_poly.h $
// $Id: include/CGAL/IO/File_poly.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Laurent RINEAU

#ifndef CGAL_FILE_POLY_H
#define CGAL_FILE_POLY_H

#include <CGAL/license/Mesh_2.h>
#include <CGAL/IO/OFF/File_scanner_OFF.h>

namespace CGAL {

namespace IO {

//the function that reads a Shewchuk Triangle .poly file
template <class CDT, class OutputIterator>
void
read_triangle_poly_file(CDT& t, std::istream &f,
                        OutputIterator seeds)
{
  typedef typename CDT::Vertex_handle Vertex_handle;
  typedef typename CDT::Point Point;

  t.clear();

  unsigned int number_of_points;
  skip_comment_OFF(f);
  f >> number_of_points;
  skip_until_EOL(f);
  skip_comment_OFF(f);

  // read vertices
  std::vector<Vertex_handle> vertices(number_of_points);
  for(unsigned int i = 0; i < number_of_points; ++i)
    {
      unsigned int j;
      double x, y;
      f >> j >> IO::iformat(x) >> IO::iformat(y);
      Point p(x, y);
      skip_until_EOL(f); skip_comment_OFF(f);
      vertices[--j] = t.insert(p);
    }

  // read segments
  unsigned int number_of_segments;
  f >> number_of_segments;
  skip_until_EOL(f); skip_comment_OFF(f);
  for(unsigned int k = 0; k < number_of_segments; ++k)
    {
      unsigned int l, v1, v2;
      f >> l >> v1 >> v2;
      skip_until_EOL(f); skip_comment_OFF(f);
      t.insert_constraint(vertices[--v1], vertices[--v2]);
    }

  // read holes
  unsigned int number_of_holes;
  f >> number_of_holes;
  for(unsigned int m = 0; m < number_of_holes; ++m)
    {
      unsigned int n;
      Point p;
      f >> n >> p;
      skip_until_EOL(f); skip_comment_OFF(f);
      *seeds++ = p;
    }
}

template <class CDT>
inline
void
read_triangle_poly_file(CDT& t, std::istream &f)
{
  read_triangle_poly_file(t, f, Emptyset_iterator());
}

//the function that write a Shewchuk Triangle .poly file
template <class CDT, typename InputIterator>
void
write_triangle_poly_file(const CDT& t, std::ostream &f,
                         InputIterator begin, InputIterator end)
{
  typedef typename CDT::Vertex_handle Vertex_handle;
  typedef typename CDT::Finite_vertices_iterator
    Finite_vertices_iterator;
  typedef typename CDT::Finite_edges_iterator
    Finite_edges_iterator;

  std::map<Vertex_handle, unsigned int> index;

  // write vertices
  f << "# Shewchuk Triangle .poly file, produced by the CGAL::Mesh_2 package"
    << std::endl
    << "# Neither attributes nor boundary markers are used." << std::endl
    << t.number_of_vertices() << " " << 2 << " "
    << 0 << " " << 0 << std::endl;

  f << std::endl;

  unsigned int vertices_counter = 0;
  for(Finite_vertices_iterator vit = t.finite_vertices_begin();
      vit != t.finite_vertices_end();
      ++vit)
    {
      f << ++vertices_counter << " " << vit->point() << std::endl;
      index[vit] = vertices_counter;
    }

  f << std::endl;

  // write constrained edges

  int number_of_constrained_edges = 0;
  for(Finite_edges_iterator it = t.finite_edges_begin();
      it != t.finite_edges_end();
      ++it)
    if(it->first->is_constrained(it->second))
      ++number_of_constrained_edges;

  f << number_of_constrained_edges << " " << 0 << std::endl;
  unsigned int edges_counter = 0;

  for(Finite_edges_iterator eit = t.finite_edges_begin();
      eit != t.finite_edges_end();
      ++eit)
    if(eit->first->is_constrained(eit->second))
      f << ++edges_counter << " "
        << index[eit->first->vertex(t.cw(eit->second))] << " "
        << index[eit->first->vertex(t.ccw(eit->second))]
        << std::endl;

  f << std::endl;


  // write seeds, assuming that the seeds unmarks faces
  f << std::distance(begin, end) << std::endl;
  unsigned int seeds_counter = 0;
  for(InputIterator sit = begin;
      sit!=end; ++sit)
    f << ++seeds_counter << " " << *sit << std::endl;
}

//the same without holes.
template <class CDT>
void
write_triangle_poly_file(const CDT& t, std::ostream &f)
{
  std::list<int> l;

  write_triangle_poly_file(t, f, l.begin(), l.end());
}

} // namespace IO

#ifndef CGAL_NO_DEPRECATED_CODE
using IO::read_triangle_poly_file;
using IO::write_triangle_poly_file;
#endif

} // end namespace CGAL

#endif // CGAL_FILE_POLY_H