-
Notifications
You must be signed in to change notification settings - Fork 0
/
typedefs.h
407 lines (347 loc) · 9.43 KB
/
typedefs.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// Copyright (c) 2011 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 <[email protected]>
//
#ifndef TYPEDEFS_H
#define TYPEDEFS_H
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2_projection_traits_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>
#include <CGAL/Linear_cell_complex.h>
#include <CGAL/Linear_cell_complex_constructors.h>
#include <CGAL/Linear_cell_complex_operations.h>
#include <CGAL/Combinatorial_map_save_load.h>
#include <CGAL/IO/Color.h>
#include <CGAL/Timer.h>
#include <CGAL/Random.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include "thirdparty/json.hpp"
// Global random
extern CGAL::Random myrandom;
// Use to define properties on volumes.
#define LCC_DEMO_VISIBLE 1 // if not visible => hidden
#define LCC_DEMO_FILLED 2 // if not filled, wireframe
#define LCC_DEMO_SELECTED 4 // if selected
struct CachePoint
{
double x, y, z;
};
struct CacheTriangle{
CachePoint points[3];
CachePoint normals[3];
};
class Face_cache
{
public:
Face_cache() {}
bool has_triangle_cache()
{
return !m_triangles.empty();
}
void clear_triangle_cache()
{
m_triangles.clear();
}
std::vector<CacheTriangle>* triangle_cache()
{
return &m_triangles;
}
void set_guid(std::string guid)
{
m_guid = guid;
}
std::string get_guid()
{
return m_guid;
}
void set_semantic_surface(std::string semantic_surface)
{
m_semantic_surface = semantic_surface;
}
std::string get_semantic_surface()
{
return m_semantic_surface;
}
private:
std::vector<CacheTriangle> m_triangles;
std::string m_guid;
std::string m_semantic_surface;
};
class Volume_info
{
friend void CGAL::read_cmap_attribute_node<Volume_info>
(const boost::property_tree::ptree::value_type &v,Volume_info &val);
friend void CGAL::write_cmap_attribute_node<Volume_info>(boost::property_tree::ptree & node,
const Volume_info& arg);
public:
Volume_info() : m_color(CGAL::Color(myrandom.get_int(0,256),
myrandom.get_int(0,256),
myrandom.get_int(0,256))),
m_status( LCC_DEMO_VISIBLE | LCC_DEMO_FILLED ),
m_guid("nothing")
{}
CGAL::Color& color()
{ return m_color; }
const CGAL::Color& color() const
{ return m_color; }
std::string color_name() const
{
std::ostringstream ss;
ss<<std::setfill('0');
ss<<"#"<<std::hex<<std::setw(2)<<(int)m_color.red()
<<std::setw(2)<<(int)m_color.green()<<std::setw(2)<<(int)m_color.blue();
return ss.str();
}
bool is_visible() const
{ return (m_status & LCC_DEMO_VISIBLE)!=0; }
bool is_filled() const
{ return (m_status & LCC_DEMO_FILLED)!=0; }
bool is_filled_and_visible() const
{ return is_filled() && is_visible(); }
bool is_selected() const
{ return (m_status & LCC_DEMO_SELECTED)!=0; }
void set_visible(bool val=true)
{
if ( is_visible()==val ) return;
if ( val ) m_status = m_status | LCC_DEMO_VISIBLE;
else m_status = m_status ^ LCC_DEMO_VISIBLE;
}
void set_filled(bool val=true)
{
if ( is_filled()==val ) return;
if ( val ) m_status = m_status | LCC_DEMO_FILLED;
else m_status = m_status ^ LCC_DEMO_FILLED;
}
void set_selected(bool val=true)
{
if ( is_selected()==val ) return;
if ( val ) m_status = m_status | LCC_DEMO_SELECTED;
else m_status = m_status ^ LCC_DEMO_SELECTED;
}
void set_guid(std::string guid)
{
m_guid = guid;
}
std::string get_guid()
{
return m_guid;
}
void negate_visible()
{ set_visible(!is_visible()); }
void negate_filled()
{ set_filled(!is_filled()); }
void negate_selected()
{ set_selected(!is_selected()); }
private:
CGAL::Color m_color;
char m_status;
std::string m_guid;
};
namespace CGAL
{
template<>
inline void read_cmap_attribute_node<Volume_info>
(const boost::property_tree::ptree::value_type &v,Volume_info &val)
{
try
{
val.m_status = v.second.get<int>("status");
}
catch(const std::exception & )
{}
try
{
char r = v.second.get<int>("color-r");
char g = v.second.get<int>("color-g");
char b = v.second.get<int>("color-b");
val.m_color = CGAL::Color(r,g,b);
}
catch(const std::exception & )
{}
try
{
val.m_guid = v.second.get<std::string>("guid");
}
catch(const std::exception & )
{}
}
// Definition of function allowing to save custon information.
template<>
inline void write_cmap_attribute_node<Volume_info>(boost::property_tree::ptree & node,
const Volume_info& arg)
{
boost::property_tree::ptree & nValue = node.add("v","");
nValue.add("status",(int)arg.m_status);
nValue.add("color-r",(int)arg.m_color.r());
nValue.add("color-g",(int)arg.m_color.g());
nValue.add("color-b",(int)arg.m_color.b());
nValue.add("guid",arg.m_guid);
}
}
class Myitems
{
public:
template < class Refs >
struct Dart_wrapper
{
typedef CGAL::Cell_attribute_with_point< Refs > Vertex_attrib;
typedef CGAL::Cell_attribute< Refs, Face_cache> Face_attrib;
typedef CGAL::Cell_attribute< Refs, Volume_info> Volume_attrib;
typedef CGAL::cpp11::tuple<Vertex_attrib,void,Face_attrib,
Volume_attrib> Attributes;
};
};
typedef CGAL::Linear_cell_complex_traits
<3,CGAL::Exact_predicates_inexact_constructions_kernel> Mytraits;
typedef CGAL::Linear_cell_complex_for_combinatorial_map<3,3,Mytraits,Myitems> LCC;
typedef LCC::Dart_handle Dart_handle;
typedef LCC::Vertex_attribute Vertex;
typedef LCC::Point Point_3;
typedef LCC::Vector Vector_3;
typedef CGAL::Timer Timer;
struct Vertex_info
{
Dart_handle dh;
Vector_3 v;
};
struct Face_info {
bool exist_edge[3];
bool is_external;
bool is_process;
};
typedef CGAL::Triangulation_2_projection_traits_3<CGAL::Exact_predicates_inexact_constructions_kernel> P_traits;
typedef CGAL::Triangulation_vertex_base_with_info_2<Vertex_info, P_traits> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<Face_info,P_traits> Fb1;
typedef CGAL::Constrained_triangulation_face_base_2<P_traits, Fb1> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
// typedef CGAL::No_intersection_tag Itag;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<P_traits, TDS,
Itag> CDT;
class FaceFormatter {
public:
virtual void getColor(Face_cache*, double&, double&, double&){};
};
class SurfaceFaceFormatter : public FaceFormatter {
public:
void getColor(Face_cache* face_info, double& r, double& g, double& b) override
{
r *= 255.0;
g *= 255.0;
b *= 255.0;
if (face_info->get_semantic_surface() == "WallSurface")
{
r = 255;
g = 255;
b = 255;
}
else if (face_info->get_semantic_surface() == "RoofSurface")
{
r = 255;
g = 0;
b = 0;
}
else if (face_info->get_semantic_surface() == "GroundSurface")
{
r = 0;
g = 0;
b = 0;
}
else if (face_info->get_semantic_surface() == "Window")
{
r = 0;
g = 0;
b = 255;
}
else if (face_info->get_semantic_surface() == "Door")
{
r = 0;
g = 255;
b = 0;
}
else if (face_info->get_semantic_surface() == "WaterSurface")
{
r = 0;
g = 0;
b = 255;
}
else if (face_info->get_semantic_surface() == "TrafficArea")
{
r = 0;
g = 128;
b = 128;
}
r /= 255.0;
g /= 255.0;
b /= 255.0;
}
~SurfaceFaceFormatter()
{}
};
struct Color
{
Color() :
r(myrandom.get_int(0,256)),
g(myrandom.get_int(0,256)),
b(myrandom.get_int(0,256))
{}
double r, g, b;
};
class ObjectFaceFormatter : public FaceFormatter {
public:
std::map<std::string, Color*> colormap;
ObjectFaceFormatter(LCC* lcc)
{
for (auto it=lcc->one_dart_per_cell<2>().begin();
it!=lcc->one_dart_per_cell<2>().end(); ++it)
{
Color* new_color = new Color();
colormap[lcc->info<2>(it).get_guid()] = new_color;
}
}
void getColor(Face_cache* face_info, double& r, double& g, double& b) override
{
Color* mycolor = colormap[face_info->get_guid()];
r = mycolor->r;
g = mycolor->g;
b = mycolor->b;
r /= 255.0;
g /= 255.0;
b /= 255.0;
}
~ObjectFaceFormatter()
{
for(auto color = colormap.begin(); color != colormap.end(); color++)
{
delete color->second;
}
}
};
struct Scene {
LCC* lcc;
};
#endif