/
Generalized_map_2_test.h
208 lines (174 loc) · 5.36 KB
/
Generalized_map_2_test.h
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright (c) 2016 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0+
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#ifndef CGAL_GENERALIZED_MAP_2_TEST
#define CGAL_GENERALIZED_MAP_2_TEST 1
#include <CGAL/Generalized_map_operations.h>
#include <CGAL/Random.h>
#include <iostream>
using namespace std;
// #define GMAP_TRACE_TEST_BEGIN 1
void trace_test_begin()
{
#ifdef GMAP_TRACE_TEST_BEGIN
static unsigned int nbtest = 0;
std::cout<<"Test "<<nbtest++<<" ..."<<std::flush;
#endif
}
void trace_test_end()
{
#ifdef GMAP_TRACE_TEST_BEGIN
std::cout<<"Ok."<<std::endl;
#endif
}
void trace_display_msg(const char*
#ifdef GMAP_TRACE_TEST_BEGIN
msg
#endif
)
{
#ifdef GMAP_TRACE_TEST_BEGIN
std::cout<<"***************** "<<msg<<"***************** "<<std::endl;
#endif
}
template<typename GMap, typename Info=typename GMap::Dart_info>
struct InitDartInfo
{
static void run(GMap& gmap)
{
long long int nb=0;
for(typename GMap::Dart_range::iterator it=gmap.darts().begin(),
itend=gmap.darts().end(); it!=itend; ++it)
{
nb=CGAL::get_default_random().get_int(0,20000);
gmap.info(it)=Info(nb);
}
}
};
template<typename GMap>
struct InitDartInfo<GMap, CGAL::Void>
{
static void run(GMap&)
{}
};
template<typename GMAP>
bool check_number_of_cells_2(GMAP& gmap, unsigned int nbv, unsigned int nbe,
unsigned int nbf, unsigned int nbcc)
{
if ( !gmap.is_valid() )
{
std::cout<<"ERROR: the gmap is not valid."<<std::endl;
assert(false);
return false;
}
std::vector<unsigned int> nbc;
nbc=gmap.count_all_cells();
if (nbv!=nbc[0] || nbe!=nbc[1] || nbf!=nbc[2] || nbcc!=nbc[3])
{
std::cout<<"ERROR: the number of cells is not correct. We must have "
<<" ("<<nbv<<", "<<nbe<<", "<<nbf<<", "<<nbcc<<") and we have"
<<" ("<<nbc[0]<<", "<<nbc[1]<<", "<<nbc[2]<<", "<<nbc[3]<<")."
<<std::endl;
assert(false);
return false;
}
trace_test_end();
return true;
}
template<class Gmap>
bool test_GMAP_2()
{
Gmap gmap;
typedef typename Gmap::Dart_handle Dart_handle;
// Construction operations
trace_test_begin();
Dart_handle dh1=gmap.make_edge();
Dart_handle dh2=gmap.make_edge();
Dart_handle dh3=gmap.make_edge();
if ( !check_number_of_cells_2(gmap, 6, 3, 3, 3) )
return false;
trace_test_begin();
gmap.template sew<1>(dh1,dh2);
gmap.template sew<1>(gmap.alpha(dh2, 0),dh3);
if ( !check_number_of_cells_2(gmap, 4, 3, 1, 1) )
return false;
trace_test_begin();
Dart_handle dh5=gmap.make_combinatorial_polygon(3);
Dart_handle dh6=gmap.make_combinatorial_polygon(3);
if ( !check_number_of_cells_2(gmap, 10, 9, 3, 3) )
return false;
trace_test_begin();
gmap.template sew<2>(dh5,dh6);
if ( !check_number_of_cells_2(gmap, 8, 8, 3, 2) )
return false;
trace_test_begin();
dh5=gmap.template alpha<1>(dh5);
dh6=gmap.template alpha<1>(dh6);
gmap.template contract_cell<1>(gmap.template alpha<1>(dh5));
if ( !check_number_of_cells_2(gmap, 8, 7, 3, 3) )
return false;
trace_test_begin();
gmap.template contract_cell<2>(dh6);
if ( !check_number_of_cells_2(gmap, 6, 5, 2, 2) )
return false;
trace_test_begin();
gmap.template contract_cell<1>(gmap.template alpha<1>(dh5));
if ( !check_number_of_cells_2(gmap, 5, 4, 2, 2) )
return false;
trace_test_begin();
gmap.template contract_cell<1>(dh5);
if ( !check_number_of_cells_2(gmap, 4, 3, 1, 1) )
return false;
trace_test_begin();
gmap.template contract_cell<1>(dh2);
if ( !check_number_of_cells_2(gmap, 3, 2, 1, 1) )
return false;
trace_test_begin();
gmap.template contract_cell<1>(dh1);
if ( !check_number_of_cells_2(gmap, 2, 1, 1, 1) )
return false;
trace_test_begin();
gmap.template contract_cell<1>(dh3);
if ( !check_number_of_cells_2(gmap, 0, 0, 0, 0) )
return false;
trace_test_begin();
Dart_handle dh7=gmap.make_combinatorial_hexahedron(); // f1
Dart_handle dh8=gmap.template alpha<2,1,0,1,2>(dh7); // f2 opposite to f1
Dart_handle dh9=gmap.template alpha<2>(dh7); // face incident to f1 and d2
gmap.template remove_cell<2>(dh7);
if ( !check_number_of_cells_2(gmap, 8, 12, 5, 1) )
return false;
trace_test_begin();
gmap.template remove_cell<2>(dh8);
if ( !check_number_of_cells_2(gmap, 8, 12, 4, 1) )
return false;
trace_test_begin();
gmap.template close<2>();
if ( !check_number_of_cells_2(gmap, 8, 12, 6, 1) )
return false;
if ( !gmap.is_volume_combinatorial_hexahedron(dh9) )
{
std::cout<<"Error: the closed volume is not a combinatorial hexahedron.\n";
assert(false);
return false;
}
return true;
}
#endif // CGAL_GENERALIZED_MAP_2_TEST