-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypedefs.h
278 lines (232 loc) · 6.42 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
#ifndef TYPEDEFS_H
#define TYPEDEFS_H
#include "thirdparty/json.hpp"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.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 <stdlib.h>
// Use to define properties on volumes.
#define LCC_DEMO_VISIBLE 1 // if not visible => hidden
#define LCC_DEMO_FILLED 2 // if not filled, wireframe
class Vertex_info
{
public:
Vertex_info() : m_vertex(0)
{}
const unsigned long vertex() const
{
return m_vertex;
}
void set_vertex(unsigned long i)
{
m_vertex = i;
}
private:
unsigned long m_vertex = 0;
};
class Face_info
{
friend void CGAL::read_cmap_attribute_node<Face_info>
(const boost::property_tree::ptree::value_type &v,Face_info &val);
friend void CGAL::write_cmap_attribute_node<Face_info>(boost::property_tree::ptree & node,
const Face_info& arg);
public:
Face_info() : m_guid("nothing"),
m_geometry_id(0),
m_semantic_surface(-1)
{}
void set_guid(std::string guid)
{
m_guid = guid;
}
std::string get_guid() const
{
return m_guid;
}
void set_geometry_id(int geometry_id)
{
m_geometry_id = geometry_id;
}
int get_geometry_id() const
{
return m_geometry_id;
}
void set_semantic_surface_id(int semantic_surface_id)
{
m_semantic_surface = semantic_surface_id;
}
int get_semantic_surface_id() const
{
return m_semantic_surface;
}
private:
std::string m_guid;
int m_geometry_id, 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(rand() % 256, rand() % 256, rand() % 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(); }
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_guid(std::string guid)
{
m_guid = guid;
}
std::string get_guid() const
{
return m_guid;
}
void set_attributes(std::map<std::string, std::string> attributes)
{
m_attributes = attributes;
}
std::map<std::string, std::string> get_attributes()
{
return m_attributes;
}
void negate_visible()
{ set_visible(!is_visible()); }
void negate_filled()
{ set_filled(!is_filled()); }
private:
CGAL::Color m_color;
char m_status;
std::string m_guid;
std::map<std::string, std::string> m_attributes;
};
namespace CGAL
{
template<>
inline void read_cmap_attribute_node<Face_info>
(const boost::property_tree::ptree::value_type &v,Face_info &val)
{
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<Face_info>(boost::property_tree::ptree & node,
const Face_info& arg)
{
boost::property_tree::ptree & nValue = node.add("v","");
nValue.add("guid",arg.m_guid);
}
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 & )
{}
try
{
boost::property_tree::ptree pt = v.second.get_child("attributes");
for(boost::property_tree::ptree::iterator iter = pt.begin(); iter != pt.end(); iter++)
{
val.m_attributes[iter->first] = iter->second.data();
}
}
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);
for (auto it = arg.m_attributes.begin(); it != arg.m_attributes.end(); ++it)
{
nValue.add("attributes." + it->first, it->second);
}
}
}
class Myitems
{
public:
template < class Refs >
struct Dart_wrapper
{
typedef CGAL::Cell_attribute_with_point< Refs, Vertex_info > Vertex_attrib;
typedef CGAL::Cell_attribute< Refs, Face_info> 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::Point Point;
typedef LCC::Vector Vector;
typedef LCC::FT FT;
#endif