1 |
francois |
1061 |
// nUtil - An utility Library for gnurbs |
2 |
|
|
// Copyright (C) 2008-2019 Eric Bechet |
3 |
|
|
// |
4 |
|
|
// See the LICENSE file for contributions and license information. |
5 |
|
|
// Please report all bugs and problems to <bechet@cadxfem.org>. |
6 |
|
|
// |
7 |
|
|
|
8 |
|
|
#ifndef __NDATA_H |
9 |
|
|
#define __NDATA_H |
10 |
|
|
|
11 |
|
|
#include <vector> |
12 |
|
|
#include <string> |
13 |
|
|
#include <ostream> |
14 |
|
|
#include "npoint.h" |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
class infobase |
18 |
|
|
{ |
19 |
|
|
public : |
20 |
|
|
infobase() : drawable(true),picked(false) {}; |
21 |
|
|
mutable bool drawable; |
22 |
|
|
mutable bool picked; |
23 |
|
|
std::string info; |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
class point : public infobase |
27 |
|
|
{ |
28 |
|
|
public: |
29 |
|
|
point() {} |
30 |
|
|
point(npoint3 pt1) {pts=pt1;} |
31 |
|
|
npoint3 pts; |
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
class line : public infobase |
35 |
|
|
{ |
36 |
|
|
public: |
37 |
|
|
line() {} |
38 |
|
|
line(npoint3 pt1,npoint3 pt2) {pts[0]=pt1;pts[1]=pt2;} |
39 |
|
|
npoint3 pts[2]; |
40 |
|
|
}; |
41 |
|
|
|
42 |
|
|
class triangle : public infobase |
43 |
|
|
{ |
44 |
|
|
public: |
45 |
|
|
triangle() {} |
46 |
|
|
triangle(npoint3 pt1,npoint3 pt2,npoint3 pt3) {pts[0]=pt1;pts[1]=pt2;pts[2]=pt3;} |
47 |
|
|
npoint3 pts[3]; |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
class quad : public infobase |
51 |
|
|
{ |
52 |
|
|
public: |
53 |
|
|
quad() {} |
54 |
|
|
quad(npoint3 pt1,npoint3 pt2,npoint3 pt3,npoint3 pt4) {pts[0]=pt1;pts[1]=pt2;pts[2]=pt3;pts[3]=pt4;} |
55 |
|
|
npoint3 pts[4]; |
56 |
|
|
}; |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
class nmesh |
60 |
|
|
{ |
61 |
|
|
public: |
62 |
|
|
enum eltype {NIL=0, POINT,LINE,TRIANGLE,TETRAHEDRON}; |
63 |
|
|
struct nnode |
64 |
|
|
{ |
65 |
|
|
nnode(void) : num(-1),xyz(),uvw() {} |
66 |
|
|
nnode(int num_) : num(num_),xyz(),uvw() {} |
67 |
|
|
nnode(int num_,const npoint3 &pt_) : num(num_),xyz(pt_),uvw() {} |
68 |
|
|
nnode(int num_,const npoint3 &pt_,const npoint3 &pt_uvw) : num(num_),xyz(pt_),uvw(pt_uvw) {} |
69 |
|
|
nnode(const npoint3 &pt_) : num(-1),xyz(pt_),uvw() {} |
70 |
|
|
npoint3 xyz; |
71 |
|
|
npoint3 uvw; |
72 |
|
|
long num; |
73 |
|
|
}; |
74 |
|
|
struct nelement |
75 |
|
|
{ |
76 |
|
|
nelement(eltype t) : type(t),num(-1) |
77 |
|
|
{ |
78 |
|
|
for (int i=0;i<4;++i) pts[i]=-1; |
79 |
|
|
} |
80 |
|
|
nelement(const nelement &other) : type(other.type),num(-1) |
81 |
|
|
{ |
82 |
|
|
for (int i=0;i<4;++i) pts[i]=other.pts[i]; |
83 |
|
|
} |
84 |
|
|
int pts[4]; |
85 |
|
|
eltype type; |
86 |
|
|
long num; |
87 |
|
|
}; |
88 |
|
|
int add_node(const nnode& src) |
89 |
|
|
{ |
90 |
|
|
nodes.push_back(src); |
91 |
|
|
return nodes.size()-1; |
92 |
|
|
} |
93 |
|
|
int nb_nodes(void) const |
94 |
|
|
{ |
95 |
|
|
return nodes.size(); |
96 |
|
|
} |
97 |
|
|
nnode& get_node(size_t i) |
98 |
|
|
{ |
99 |
|
|
return nodes[i]; |
100 |
|
|
} |
101 |
|
|
const nnode& get_node(size_t i) const |
102 |
|
|
{ |
103 |
|
|
return nodes[i]; |
104 |
|
|
} |
105 |
|
|
void clear(void) |
106 |
|
|
{ |
107 |
|
|
nodes.clear(); |
108 |
|
|
elements.clear(); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
int add_element(const nelement& src) |
112 |
|
|
{ |
113 |
|
|
elements.push_back(src); |
114 |
|
|
return elements.size()-1; |
115 |
|
|
} |
116 |
|
|
int nb_elements(void) const |
117 |
|
|
{ |
118 |
|
|
return elements.size(); |
119 |
|
|
} |
120 |
|
|
nelement& get_element(size_t i) |
121 |
|
|
{ |
122 |
|
|
return elements[i]; |
123 |
|
|
} |
124 |
|
|
const nelement& get_element(size_t i) const |
125 |
|
|
{ |
126 |
|
|
return elements[i]; |
127 |
|
|
} |
128 |
|
|
private: |
129 |
|
|
std::vector<nnode> nodes; |
130 |
|
|
std::vector<nelement> elements; |
131 |
|
|
}; |
132 |
|
|
|
133 |
|
|
struct color |
134 |
|
|
{ |
135 |
|
|
color(unsigned char r=255,unsigned char g=255,unsigned char b=255,unsigned char a=255) : R(r),G(g),B(b),A(a) {} |
136 |
|
|
unsigned char R; |
137 |
|
|
unsigned char G; |
138 |
|
|
unsigned char B; |
139 |
|
|
unsigned char A; //Alpha |
140 |
|
|
}; |
141 |
|
|
|
142 |
|
|
struct properties |
143 |
|
|
{ |
144 |
|
|
properties() : c(),thickness(1.),pointsize(1.),edgeon(),edgethickness(1.),edgecolor(),teston(),nb_uid(0) {} |
145 |
|
|
color c; |
146 |
|
|
float thickness; |
147 |
|
|
float pointsize; |
148 |
|
|
bool edgeon; |
149 |
|
|
float edgethickness; |
150 |
|
|
color edgecolor; |
151 |
|
|
bool teston; |
152 |
|
|
int nb_uid; //0, 1, 2 or 3 |
153 |
|
|
int uids[3];// max=3 user ids... |
154 |
|
|
}; |
155 |
|
|
|
156 |
|
|
typedef std::vector<std::pair<properties,int> > container_props; |
157 |
|
|
|
158 |
|
|
class data_container |
159 |
|
|
{ |
160 |
|
|
std::vector<point> points; |
161 |
|
|
container_props proppoints; |
162 |
|
|
std::vector<line> lines; |
163 |
|
|
container_props proplines; |
164 |
|
|
std::vector<triangle> triangles; |
165 |
|
|
container_props proptriangles; |
166 |
|
|
std::vector<quad> quads; |
167 |
|
|
container_props propquads; |
168 |
|
|
std::vector<std::pair<point,color> > texts[3]; |
169 |
|
|
|
170 |
|
|
public : |
171 |
|
|
data_container(); |
172 |
|
|
data_container(const data_container& other); // copy constructor |
173 |
|
|
|
174 |
|
|
void clear(void); |
175 |
|
|
|
176 |
|
|
const color& getcolorpoints(int i=0) const; |
177 |
|
|
const color& getcolorlines(int i=0) const; |
178 |
|
|
const color& getcolortriangles(int i=0) const; |
179 |
|
|
const color& getcolorquads(int i=0) const; |
180 |
|
|
|
181 |
|
|
const properties& getproppoints(int i) const; |
182 |
|
|
const properties& getproplines(int i) const; |
183 |
|
|
const properties& getproptriangles(int i) const; |
184 |
|
|
const properties& getpropquads(int i) const; |
185 |
|
|
|
186 |
|
|
const properties getproppoints() const; |
187 |
|
|
const properties getproplines() const; |
188 |
|
|
const properties getproptriangles() const; |
189 |
|
|
const properties getpropquads() const; |
190 |
|
|
|
191 |
|
|
int getindexpoints(int i=0) const; |
192 |
|
|
int getindexlines(int i=0) const; |
193 |
|
|
int getindextriangles(int i=0) const; |
194 |
|
|
int getindexquads(int i=0) const; |
195 |
|
|
|
196 |
|
|
|
197 |
|
|
int getnumproppoints(void) const; |
198 |
|
|
int getnumproplines(void) const; |
199 |
|
|
int getnumproptriangles(void) const; |
200 |
|
|
int getnumpropquads(void) const; |
201 |
|
|
|
202 |
|
|
|
203 |
|
|
void setcolorpoints(color c); |
204 |
|
|
void setcolorlines(color c); |
205 |
|
|
void setcolortriangles(color c); |
206 |
|
|
void setcolorquads(color c); |
207 |
|
|
|
208 |
|
|
void setproppoints(properties p); |
209 |
|
|
void setproplines(properties p); |
210 |
|
|
void setproptriangles(properties p); |
211 |
|
|
void setpropquads(properties p); |
212 |
|
|
void setpropall(properties p); |
213 |
|
|
|
214 |
|
|
int add_point(const npoint3& src); |
215 |
|
|
int add_point(const point& src); |
216 |
|
|
int add_line(const line& src); |
217 |
|
|
int add_triangle(const triangle& src); |
218 |
|
|
int add_quad(const quad& src); |
219 |
|
|
int add_text(int num,const std::pair<point,color>& src); |
220 |
|
|
|
221 |
|
|
int nb_points(void) const; |
222 |
|
|
int nb_lines(void) const; |
223 |
|
|
int nb_triangles(void) const; |
224 |
|
|
int nb_quads(void) const; |
225 |
|
|
int nb_texts(int num) const; |
226 |
|
|
|
227 |
|
|
const point& get_point(int i) const; |
228 |
|
|
const line& get_line(int i) const; |
229 |
|
|
const triangle& get_triangle(int i) const; |
230 |
|
|
const quad& get_quad(int i) const; |
231 |
|
|
const point& get_text(int num,int i) const; |
232 |
|
|
const color& get_text_color(int num,int i) const; |
233 |
|
|
point& get_point(int i); |
234 |
|
|
line& get_line(int i); |
235 |
|
|
triangle& get_triangle(int i); |
236 |
|
|
quad& get_quad(int i); |
237 |
|
|
point& get_text(int num,int i); |
238 |
|
|
color& get_text_color(int num,int i); |
239 |
|
|
void merge(const data_container & other); |
240 |
|
|
void unhide(void) const; |
241 |
|
|
virtual void print(std::ostream& stream) const; |
242 |
|
|
virtual int read(std::istream& stream); |
243 |
|
|
}; |
244 |
|
|
|
245 |
|
|
|
246 |
|
|
#endif // __NDATA_H |