main.cpp 48.7 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
2
3
//g++ main.cpp rotate.cpp -L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU ../../inmost.a -O5
// press space - explode mesh to see connection 
//#define OCTREECUTCELL_DEBUG
Kirill Terekhov's avatar
Kirill Terekhov committed
4
5
#define DISCR_DEBUG

Dmitry Bagaev's avatar
Dmitry Bagaev committed
6
#include "inmost.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
7
8
9
10
11
12
13
#include "my_glut.h"
#include <iostream>
#include <sstream>
#include <algorithm>
#include "rotate.h"
#include <stdarg.h>

Kirill Terekhov's avatar
Kirill Terekhov committed
14

Kirill Terekhov's avatar
Kirill Terekhov committed
15
16
17
18
19
20
21
22
using namespace INMOST;
Mesh * mesh;
int drawgrid = 0;
int interactive = 0;
double zoom = 1;
int width = 800, height = 800;
double sleft = 1e20, sright = -1e20, sbottom = 1e20, stop = -1e20, sfar = -1e20, snear = 1e20;
Tag mat,colort; int maxmat = -1, maxcolor = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
23
Mesh::GeomParam table;
Kirill Terekhov's avatar
Kirill Terekhov committed
24
25
26
27
28
29
30
31
double reset_timer = Timer();
double shift[3] = {0,0,0};
int boundary = 2;
int color = 0;
int edges = 1;
bool perspective = false;
int text = 4;
int display_orphans = 1;
Kirill Terekhov's avatar
Kirill Terekhov committed
32
int badfaces = 1;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
33
ElementSet problem_set, orphan_edges, orphan_faces;
Kirill Terekhov's avatar
Kirill Terekhov committed
34
35


Kirill Terekhov's avatar
Kirill Terekhov committed
36
37
38
39
40
41
42
43
44
45
46
#if defined(DISCR_DEBUG)
Tag avg_coord, tensor;

static Storage::real dot_prod(Storage::real x[3], Storage::real y[3])  { return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; }
static void tensor_prod3(Storage::real * K, Storage::real v[3], Storage::real out[3])
{
	out[0] = v[0] * K[0] + v[1] * K[1] + v[2] * K[2];
	out[1] = v[0] * K[3] + v[1] * K[4] + v[2] * K[5];
	out[2] = v[0] * K[6] + v[1] * K[7] + v[2] * K[8];
}

Dmitry Bagaev's avatar
Dmitry Bagaev committed
47
void FindHarmonicPoint(Face & fKL, Cell & cK, Cell & cL, Tag tensor, Storage::real xK[3], Storage::real xL[3], Storage::real y[3], Storage::real & coef)
Kirill Terekhov's avatar
Kirill Terekhov committed
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
{
	Storage::real yK[3], yL[3], xKL[3], nKL[3], dK, dL, lK, lL, lKs[3], lLs[3], D, t;
	Storage::real coefK, coefL, coefQ, coefDiv;
	Storage::real_array KK = cK->RealArray(tensor), KL = cL->RealArray(tensor);
	fKL->OrientedUnitNormal(cK,nKL);
	fKL->Centroid(xKL);
	tensor_prod3(&KK[0],nKL,lKs);
	tensor_prod3(&KL[0],nKL,lLs);
	lK = dot_prod(nKL,lKs);
	lL = dot_prod(nKL,lLs);
	lKs[0] -= nKL[0]*lK;
	lKs[1] -= nKL[1]*lK;
	lKs[2] -= nKL[2]*lK;
	lLs[0] -= nKL[0]*lL;
	lLs[1] -= nKL[1]*lL;
	lLs[2] -= nKL[2]*lL;
	D = -dot_prod(xKL,nKL);
	dK = fabs(dot_prod(xK,nKL)+D);
	dL = fabs(dot_prod(xL,nKL)+D);
	yK[0] = xK[0] + dK*nKL[0];
	yK[1] = xK[1] + dK*nKL[1];
	yK[2] = xK[2] + dK*nKL[2];
	yL[0] = xL[0] - dL*nKL[0];
	yL[1] = xL[1] - dL*nKL[1];
	yL[2] = xL[2] - dL*nKL[2];
	coefDiv = (lL*dK+lK*dL);
	coefL = lL*dK/coefDiv;
	coefK = lK*dL/coefDiv;
	coefQ = dK*dL/coefDiv;
	y[0] = yK[0]*coefK + yL[0]*coefL + (lKs[0]-lLs[0])*coefQ;
	y[1] = yK[1]*coefK + yL[1]*coefL + (lKs[1]-lLs[1])*coefQ;
	y[2] = yK[2]*coefK + yL[2]*coefL + (lKs[2]-lLs[2])*coefQ;
	coef = coefL;
}


Dmitry Bagaev's avatar
Dmitry Bagaev committed
84
void FindBoundaryPoint(Face & fK, Cell & cK, Tag tensor, Storage::real xK[3], Storage::real y[3])
Kirill Terekhov's avatar
Kirill Terekhov committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
	Storage::real nK[3], lKs[3], lK, xfK[3], t;
	Storage::real_array KK = cK->RealArray(tensor);
	fK->Centroid(xfK);
	fK->OrientedUnitNormal(cK,nK);
	tensor_prod3(&KK[0],nK,lKs);
	lK = dot_prod(nK,lKs);
	t = (dot_prod(nK,xfK) - dot_prod(nK,xK))/lK;
	y[0] = xK[0] + t*lKs[0];
	y[1] = xK[1] + t*lKs[1];
	y[2] = xK[2] + t*lKs[2];
}
#endif

Kirill Terekhov's avatar
Kirill Terekhov committed
99
100
101

void printtext(const char * fmt, ... )
{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
102

Kirill Terekhov's avatar
Kirill Terekhov committed
103
104
105
106
107
108
109
110
111
	unsigned int i;
	char stext[1024];
	va_list ap;
	if ( fmt == NULL ) return;
	va_start(ap,fmt);
	vsprintf(stext,fmt,ap);
	va_end(ap);
	for(i=0;i<strlen(stext);i++)
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
112
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,
Kirill Terekhov's avatar
Kirill Terekhov committed
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
							stext[i]);
	}
}

void set_matrix3d()
{
	double aspect = (double)width/(double)height;
	double side = std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
	//double center[3] = { (sleft+sright)*0.5, (sbottom+stop)*0.5, (sfar+snear)*0.5};
	const double sc = 2;
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	//~ glOrtho(center[0]-sc*side*zoom*aspect,center[0]+sc*zoom*side*aspect,
		//~ center[1]-sc*side*zoom,center[1]+sc*zoom*side,
		//~ center[2]-sc*side*100,center[2]+sc*side*100);
	if( !perspective )
	{
		glOrtho(-sc*side*zoom*aspect,sc*side*zoom*aspect,
				-sc*side*zoom,sc*side*zoom,
				-sc*side*100,sc*side*100);
	}
	else
		gluPerspective(60.0, aspect, 0.00001, 1000.0);
	glMatrixMode (GL_MODELVIEW);
}

void set_matrix2d()
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1,1,-1,1,-1,1);
	glMatrixMode(GL_MODELVIEW);
}

void reshape(int w, int h)
{
	width = w;
	height = h;
	set_matrix3d();
	glViewport(0, 0, w, h);
}

class Input
{
public:
	enum InputType {Double,Integer};
private:
	std::string str;
	void * input_link;
	InputType type;
	bool done;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
164
165


Kirill Terekhov's avatar
Kirill Terekhov committed
166
167
168
169
170
171
172
public:
	Input(int * val) {input_link = val; type = Integer; done = false; str = "";}
	Input(double * val) {input_link = val; type = Double; done = false; str = "";}
	Input(void * link, InputType type) : input_link(link), type(type) {done = false; str = "";}
	Input(const Input & other):input_link(other.input_link), str(other.str), type(other.type), done(other.done) {}
	Input & operator =(Input const & other) {input_link = other.input_link; str = other.str; type = other.type; done = other.done; return *this;}
	~Input() {}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
173
	void KeyPress(char c)
Kirill Terekhov's avatar
Kirill Terekhov committed
174
175
176
	{
		if( c == 13 )
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
177

Kirill Terekhov's avatar
Kirill Terekhov committed
178
179
180
181
182
183
184
185
186
187
			done = true;
			if( type == Double ) *((double *)input_link) = atof(str.c_str());
			else if( type == Integer ) *((int *)input_link) = atoi(str.c_str());
			glutPostRedisplay();
		}
		else if( c == 8 )
		{
			if( !str.empty() ) str.erase(str.size()-1);
			glutPostRedisplay();
		}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
188
		else if( (c >= '0' && c <= '9') || c=='+' || c=='-' || c=='.' || c=='e' || c == 'E' )
Kirill Terekhov's avatar
Kirill Terekhov committed
189
190
191
192
193
194
		{
			str += c;
			glutPostRedisplay();
		}
		else if( c == 27 )
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
195

Kirill Terekhov's avatar
Kirill Terekhov committed
196
197
198
199
200
201
202
203
			done = true;
			glutPostRedisplay();
		}
	}
	bool Done() {return done;}
	void Draw()
	{
		float h = 24.0f/(float)height;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
204

Kirill Terekhov's avatar
Kirill Terekhov committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
		glColor3f(1,1,1);
		glBegin(GL_QUADS);
		glVertex3f(-0.99,-0.99,1);
		glVertex3f(-0.99,-0.99+h,1);
		glVertex3f(0.99,-0.99+h,1);
		glVertex3f(0.99,-0.99,1);
		glEnd();
		glColor3f(0,0,0);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-0.99,-0.99,1);
		glVertex3f(-0.99,-0.99+h,1);
		glVertex3f(0.99,-0.99+h,1);
		glVertex3f(0.99,-0.99,1);
		glEnd();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
219

Kirill Terekhov's avatar
Kirill Terekhov committed
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
		glColor4f(0,0,0,1);
		glRasterPos2d(-0.985,-0.985);
		//printtext(str.c_str());
		printtext("input number (%s): %s",type == Integer ? "integer":"double", str.c_str());
	}
} * CommonInput = NULL;





void keyboard2(unsigned char key, int x, int y)
{
	if( key == '=' || key == '+' ||  key == '_' || key == '-' || key == 'w' || key == 's' || key == 'a' || key == 'd' || key == 'r' || key == 'p' || key == 'z')
	{
		interactive = false;
		glutPostRedisplay();
	}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
238

Kirill Terekhov's avatar
Kirill Terekhov committed
239
240
241
242
243
}

int matfilter = 0;
int show_cell = -1, show_face = -1;
int parentfilter = -1;
Kirill Terekhov's avatar
Kirill Terekhov committed
244
std::vector<int> show_cells, show_faces;
Kirill Terekhov's avatar
Kirill Terekhov committed
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

void keyboard(unsigned char key, int x, int y)
{
	if( CommonInput != NULL )
	{
		CommonInput->KeyPress(key);
		return;
	}
	if( key == 't' )
	{
		text = (text+1)%6;
		glutPostRedisplay();
	}
	else if( key == 'b' )
	{
		boundary = (boundary+1)%3;
		glutPostRedisplay();
	}
	else if( key == 'p' )
	{
		perspective = !perspective;
		reshape(width,height);
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 'w' )
	{
		double shiftmod[3] = {0,0,0};
		shiftmod[1] -= 0.03f*expf(zoom-1)*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
		rotatevector((double*)shiftmod);
		shift[0] += shiftmod[0];
		shift[1] += shiftmod[1];
		shift[2] += shiftmod[2];
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 's' )
	{
		double shiftmod[3] = {0,0,0};
		shiftmod[1] += 0.03f*expf(zoom-1)*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
		rotatevector((double*)shiftmod);
		shift[0] += shiftmod[0];
		shift[1] += shiftmod[1];
		shift[2] += shiftmod[2];
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 'a' )
	{
		double shiftmod[3] = {0,0,0};
		shiftmod[0] += 0.03f*expf(zoom-1)*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
		rotatevector((double*)shiftmod);
		shift[0] += shiftmod[0];
		shift[1] += shiftmod[1];
		shift[2] += shiftmod[2];
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 'd' )
	{
		double shiftmod[3] = {0,0,0};
		shiftmod[0] -= 0.03f*expf(zoom-1)*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
		rotatevector((double*)shiftmod);
		shift[0] += shiftmod[0];
		shift[1] += shiftmod[1];
		shift[2] += shiftmod[2];
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 'r' )
	{
		shift[0] = 0.0f;
		shift[1] = 0.0f;
		shift[2] = 0.0f;
		zoom = 1;
		quatinit();
		glutPostRedisplay();
		interactive = true;
	}
	else if( key == 'e' )
	{
		edges = !edges;
Kirill Terekhov's avatar
Kirill Terekhov committed
327
		glutPostRedisplay();
Kirill Terekhov's avatar
Kirill Terekhov committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
	}
	else if( key == 27 )
	{
		//delete mesh;
		exit(-1);
	}
	else if( key == '=' || key == '+')
	{
		zoom /= 1.1;
		reshape(width,height);
		glutPostRedisplay();
		interactive = true;
		//reset_timer = Timer();
	}
	else if( key == '_' || key == '-')
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
344
		zoom *= 1.1;
Kirill Terekhov's avatar
Kirill Terekhov committed
345
346
347
348
349
350
351
		reshape(width,height);
		glutPostRedisplay();
		interactive = true;
		//reset_timer = Timer();
	}
	else if( key == ' ')
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
352
353
354
		show_cells.clear();
		show_faces.clear();
		//mesh->Save("out.vtk");
Kirill Terekhov's avatar
Kirill Terekhov committed
355
356
		//drawgrid = (drawgrid+1)%2;
		//glutPostRedisplay();
Kirill Terekhov's avatar
Kirill Terekhov committed
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
	}
	else if( key == 'q' )
	{
		mesh->PrepareGeometricData(table);
	}
	else if( key == 'w' )
	{
		mesh->RemoveGeometricData(table);
	}
	else if( key-'0' >= 0 && key-'9' <= 0 )
	{
		matfilter = key-'0';
		glutPostRedisplay();
	}
	else if( key == 'm' )
	{
		if( parentfilter == -1 )
		{
			if( CommonInput == NULL ) CommonInput = new Input(&parentfilter);
		}
		else parentfilter = -1;
		glutPostRedisplay();
	}
	else if( key == 'c' )
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
382
		if( CommonInput == NULL ) CommonInput = new Input(&show_cell);
Kirill Terekhov's avatar
Kirill Terekhov committed
383
384
385
386
		glutPostRedisplay();
	}
	else if( key == 'f' )
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
387
		if( CommonInput == NULL ) CommonInput = new Input(&show_face);
Kirill Terekhov's avatar
Kirill Terekhov committed
388
389
390
391
392
393
394
395
		glutPostRedisplay();
	}
	else if( key == 'z' )
	{
		if( !colort.isValid() )
		{
			unsigned visited = 0;
			colort = mesh->CreateTag("COLOR",DATA_INTEGER,CELL,NONE,1);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
396
397
			std::vector<Cell> queue;
			ElementArray<Element> around;
Kirill Terekhov's avatar
Kirill Terekhov committed
398
399
400
401
402
403
404
405
406
			queue.reserve(256);
			while(visited != mesh->NumberOfCells() )
			{
				maxcolor++;
				std::cout << "new part " << maxcolor << std::endl;
				for(Mesh::iteratorCell it = mesh->BeginCell(); it != mesh->EndCell(); ++it)
				{
					if( it->Integer(colort) == 0 )
					{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
407
						queue.push_back(it->self());
Kirill Terekhov's avatar
Kirill Terekhov committed
408
409
410
411
412
413
414
415
						visited++;
						queue.back()->Integer(colort) = maxcolor;
						break;
					}
				}
				while(!queue.empty())
				{
					around = queue.back()->BridgeAdjacencies(FACE,CELL);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
416

Kirill Terekhov's avatar
Kirill Terekhov committed
417
					queue.pop_back();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
418
					for(ElementArray<Element>::iterator it = around.begin(); it != around.end(); ++it)
Kirill Terekhov's avatar
Kirill Terekhov committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
						if( it->Integer(colort) == 0 )
						{
							queue.push_back(it->getAsCell());
							visited++;
							queue.back()->Integer(colort) = maxcolor;
						}
				}
			}
		}
		color = !color;
	}
	else if( key == 'o' )
	{
		display_orphans = !display_orphans;
		glutPostRedisplay();
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
435
436
437
438
439
440

	else if( key == 'l' )
	{
		badfaces = !badfaces;
		glutPostRedisplay();
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
}




class face2gl
{
	double dist;
	double c[4];
	std::vector<double> verts;
public:
	face2gl():verts() {dist = 0; memset(c,0,sizeof(double)*4);}
	face2gl(const face2gl & other) :verts(other.verts) {dist = other.dist; memcpy(c,other.c,sizeof(double)*4);}
	face2gl & operator =(face2gl const & other) { verts = other.verts; dist = other.dist; memmove(c,other.c,sizeof(double)*4); return *this;}
	~face2gl() {}
	void draw() const
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
458
459
460
461
462
		if( boundary == 2 ) glColor3dv(c);
		else glColor4dv(c);
		glBegin(GL_POLYGON);
		for(unsigned k = 0; k < verts.size(); k+=3)
			glVertex3dv(&verts[k]);
Kirill Terekhov's avatar
Kirill Terekhov committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
		glEnd();
	}
	bool operator <(const face2gl & other) const {return dist < other.dist;}
	void set_color(double r, double g, double b, double a) {c[0] = r; c[1] = g; c[2] = b; c[3] = a;}
	void add_vert(double x, double y, double z) {unsigned s = verts.size(); verts.resize(s+3); verts[s] = x; verts[s+1] = y; verts[s+2] = z;}
	void add_vert(double v[3]) {verts.insert(verts.end(),v,v+3);}
	void set_center(double cnt[3], double cam[3])
	{
		dist = sqrt((cnt[0]-cam[0])*(cnt[0]-cam[0])+(cnt[1]-cam[1])*(cnt[1]-cam[1])+(cnt[2]-cam[2])*(cnt[2]-cam[2]));
	}
};



Dmitry Bagaev's avatar
Dmitry Bagaev committed
477
face2gl DrawFace(Element & f, int mmat, double campos[3])
Kirill Terekhov's avatar
Kirill Terekhov committed
478
479
480
481
482
{
	double cnt[3];
	face2gl ret;
	f->Centroid(cnt);
	ret.set_center(cnt,campos);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
483
	ElementArray<Node> nodes = f->getNodes();
Kirill Terekhov's avatar
Kirill Terekhov committed
484
485
486
487
488
489
490
491
492
493
494
495

	if( f->nbAdjElements(CELL) == 0 )
		ret.set_color(1,0,0,0.25);
	else if( mmat == 0 )
	{
		ret.set_color(0.2,0,1,0.25);
	}
	else
	{
		double r = color ? mmat / (double)maxcolor : mmat / (double) maxmat;
		ret.set_color(1-r,r,1-r,0.25);
	}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
496
497

	for( ElementArray<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
498
		ret.add_vert(&(kt->Coords()[0]));
Dmitry Bagaev's avatar
Dmitry Bagaev committed
499

Kirill Terekhov's avatar
Kirill Terekhov committed
500
501
502

	if( edges )
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
503
504
		//glLineWidth(2.0);
		if( boundary == 1 ) glColor3f(0,0,1); else glColor3f(0,0,0);
Kirill Terekhov's avatar
Kirill Terekhov committed
505
		glBegin(GL_LINE_LOOP);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
506
		for( ElementArray<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
507
508
			glVertex3dv(&(kt->Coords()[0]));
		glEnd();
Kirill Terekhov's avatar
Kirill Terekhov committed
509
		//glLineWidth(1.0);
Kirill Terekhov's avatar
Kirill Terekhov committed
510
511
512
513
514
515
516
517
518
519
520
521
522
523
	}
	return ret;
}

Tag problem_tag, mats_tag,parent_tag,cell_material_tag;

void fill_mat_str(Storage::integer id, Storage::integer_array mats, char str[2048])
{
	str[0] = '\0';
	sprintf(str,"%d",id);
	for(unsigned q = 0; q < mats.size(); q++)
		sprintf(str,"%s,%d",str,mats[q]+1);
}

Kirill Terekhov's avatar
Kirill Terekhov committed
524
525
526
527
528
529
530

void fill_str(Storage::integer id, char str[2048])
{
	str[0] = '\0';
	sprintf(str,"%d",id);
}

Kirill Terekhov's avatar
Kirill Terekhov committed
531
532
533
534
535
536
537
void whereami(double & cx, double & cy, double & cz)
{
   // Get the viewing matrix
   GLdouble modelview[16],projection[16];
   GLint viewport[4] = {0,0,1,1};
   glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
   glGetDoublev(GL_PROJECTION_MATRIX, projection);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
538

Kirill Terekhov's avatar
Kirill Terekhov committed
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
   GLdouble outx, outy, outz;  // Var's to save the answer in

   gluUnProject(0.5, 0.5, 0.,
               modelview, projection, viewport,
               &outx, &outy, &outz);

   // Return the result.
   cx = outx;
   cy = outy;
   cz = outz;
}

void draw()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	set_matrix3d();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
556

Kirill Terekhov's avatar
Kirill Terekhov committed
557
558
559
560
	if( perspective )
		glTranslated(0,0,-zoom*2*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5);
	//glTranslated((sleft+sright)*0.5,(sbottom+stop)*0.5,(snear+sfar)*0.5);
	rotate();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
561

Kirill Terekhov's avatar
Kirill Terekhov committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
	//glPointSize(5);
	//glColor3f(0,1,1);
	glLineWidth(3.0);
	glBegin(GL_LINES);
	glColor3f(1,0,0);
	glVertex3d(0,0,0);
	glVertex3d(zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5*0.1,0,0);
	glColor3f(0,1,0);
	glVertex3d(0,0,0);
	glVertex3d(0,zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5*0.1,0);
	glColor3f(0,0,1);
	glVertex3d(0,0,0);
	glVertex3d(0,0,zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5*0.1);
	glEnd();
	glLineWidth(1.0);
	//glPointSize(1);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
578

Kirill Terekhov's avatar
Kirill Terekhov committed
579
	//glTranslated(-(sleft+sright)*0.5+shift[0],-(sbottom+stop)*0.5 + shift[1],-(snear+sfar)*0.5 + shift[2]);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
580

Kirill Terekhov's avatar
Kirill Terekhov committed
581
	glTranslated(shift[0],shift[1],shift[2]);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
582

Kirill Terekhov's avatar
Kirill Terekhov committed
583
584
585
586
587
588
589
590
591
592
593
	double campos[3] = {0.5,0.5,0};
	//~ double matrix[16], inverse[16];
	//~ glGetDoublev(GL_MODELVIEW_MATRIX,matrix);
	//~ inverse_v1(inverse,matrix);
	//~ campos[0] = inverse[12];
	//~ campos[1] = inverse[13];
	//~ campos[2] = inverse[14];

	//~ campos[0] = inverse[3];
	//~ campos[1] = inverse[7];
	//~ campos[2] = inverse[11];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
594

Kirill Terekhov's avatar
Kirill Terekhov committed
595
596
597
598
	whereami(campos[0],campos[1],campos[2]);


	//glTranslated((l+r)*0.5,(b+t)*0.5,(near+far)*0.5);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
599
	int pacef = std::max(1,mesh->FaceLastLocalID()/10000);
Kirill Terekhov's avatar
Kirill Terekhov committed
600

Kirill Terekhov's avatar
Kirill Terekhov committed
601
	std::vector<face2gl> polygons;
Kirill Terekhov's avatar
Kirill Terekhov committed
602
603
604

	if( badfaces )
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
605
		for(INMOST_DATA_INTEGER_TYPE it = 0; it < mesh->FaceLastLocalID(); it += (interactive ? pacef : 1)) if( mesh->isValidFace(it) )
Kirill Terekhov's avatar
Kirill Terekhov committed
606
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
607
608
609
			Face f = mesh->FaceByLocalID(it);
			if( !f->CheckNormalOrientation() )
				polygons.push_back(DrawFace(f,1,campos));
Kirill Terekhov's avatar
Kirill Terekhov committed
610
611
		}
	}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
612
613


Kirill Terekhov's avatar
Kirill Terekhov committed
614
	char str[2048];
Kirill Terekhov's avatar
Kirill Terekhov committed
615
616
617
618
619
620
621
622
623
624
625

#if defined(DISCR_DEBUG)
	if(avg_coord.isValid())
	{
		glLineWidth(2.0);
		glColor3f(0,1,0);
		glBegin(GL_LINES);
		for(Mesh::iteratorCell it = mesh->BeginCell(); it != mesh->EndCell(); ++it)
		{
			Storage::real cnt[3];
			it->Centroid(cnt);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
626
627
			ElementArray<Face> faces = it->getFaces();
			for(ElementArray<Face>::iterator jt = faces.begin(); jt != faces.end(); ++jt) if(!jt->Boundary())
Kirill Terekhov's avatar
Kirill Terekhov committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
			{
				Storage::real_array cc = jt->RealArray(avg_coord);
				glVertex3dv(cnt);
				glVertex3dv(&cc[0]);
			}
		}
		glEnd();
		glLineWidth(1.0);
		glPointSize(4.0);
		glColor3f(1,0,0);
		glBegin(GL_POINTS);
		for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); ++it) if(!it->Boundary() )
		{
			Storage::real_array cc = it->RealArray(avg_coord);
			glVertex3dv(&cc[0]);
		}
		glEnd();
		glPointSize(1.0);
	}

	if(tensor.isValid())
	{
		glColor3f(0,0,0);
		glBegin(GL_LINES);
		Storage::real h = 0, nh = 0;
		for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); ++it) if(!it->Boundary())
		{
			h += (it->BackCell()->Volume() + it->FrontCell()->Volume());
			nh += it->Area();
		}
		h /= nh;
		for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); ++it) if(!it->Boundary() )
		{
			Storage::real nrm[3], scale, f1[3], f2[3], l, cnt[3], v[3];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
662
663
			Cell c1 = it->BackCell(), c2 = it->FrontCell();
			if( c1.isValid() && c2.isValid() )
Kirill Terekhov's avatar
Kirill Terekhov committed
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
			{
				it->Centroid(cnt);
				it->OrientedUnitNormal(c1,nrm);
				scale = h;
				Storage::real_array K1 = c1->RealArray(tensor), K2 = c2->RealArray(tensor);
				f1[0] = K1[0]*nrm[0] + K1[1]*nrm[1] + K1[2]*nrm[2];
				f1[1] = K1[3]*nrm[0] + K1[4]*nrm[1] + K1[5]*nrm[2];
				f1[2] = K1[6]*nrm[0] + K1[7]*nrm[1] + K1[8]*nrm[2];

				l = 0.15*scale/sqrt(f1[0]*f1[0]+f1[1]*f1[1]+f1[2]*f1[2]);

				f1[0] *= l;
				f1[1] *= l;
				f1[2] *= l;

				v[0] = f1[0] + cnt[0];
				v[1] = f1[1] + cnt[1];
				v[2] = f1[2] + cnt[2];

				glVertex3dv(cnt);
				glVertex3dv(v);

				v[0] = -f1[0] + cnt[0];
				v[1] = -f1[1] + cnt[1];
				v[2] = -f1[2] + cnt[2];

				glVertex3dv(cnt);
				glVertex3dv(v);

				f2[0] = K2[0]*nrm[0] + K2[1]*nrm[1] + K2[2]*nrm[2];
				f2[1] = K2[3]*nrm[0] + K2[4]*nrm[1] + K2[5]*nrm[2];
				f2[2] = K2[6]*nrm[0] + K2[7]*nrm[1] + K2[8]*nrm[2];



				l = 0.15*scale/sqrt(f2[0]*f2[0]+f2[1]*f2[1]+f2[2]*f2[2]);

				f2[0] *= l;
				f2[1] *= l;
				f2[2] *= l;

				v[0] = f2[0] + cnt[0];
				v[1] = f2[1] + cnt[1];
				v[2] = f2[2] + cnt[2];

				glVertex3dv(cnt);
				glVertex3dv(v);

				v[0] = -f2[0] + cnt[0];
				v[1] = -f2[1] + cnt[1];
				v[2] = -f2[2] + cnt[2];

				glVertex3dv(cnt);
				glVertex3dv(v);
			}
		}

		glEnd();

	}
#endif
Dmitry Bagaev's avatar
Dmitry Bagaev committed
725
726


Kirill Terekhov's avatar
Kirill Terekhov committed
727
	//glColor3f(0,0,0);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
728

Kirill Terekhov's avatar
Kirill Terekhov committed
729
	if( !show_cells.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
730
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
731
		for(int qq = 0; qq < show_cells.size(); qq++)
Kirill Terekhov's avatar
Kirill Terekhov committed
732
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
733
734
735
			if( show_cells[qq] < 0 || show_cells[qq] >= mesh->CellLastLocalID() ) continue;
			Element it = mesh->ElementByLocalID(CELL,show_cells[qq]);
			if( it.isValid() )
Kirill Terekhov's avatar
Kirill Terekhov committed
736
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
737
				Storage::integer_array mats;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
738
				ElementArray<Edge> edges = it->getEdges();
Kirill Terekhov's avatar
Kirill Terekhov committed
739
740
741
742
743
				Storage::real cnt[3];
				for(unsigned k = 0; k < edges.size(); k++)
				{
					edges[k].Centroid(cnt);
					if( mats_tag.isValid() )mats = edges[k].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
744
745
746

					ElementArray<Node> nodes = edges[k].getNodes();

Kirill Terekhov's avatar
Kirill Terekhov committed
747
748
749
750
751
752
					if( matfilter == 0 || (mats_tag.isValid() && std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
						if( mats_tag.isValid() ) fill_mat_str(edges[k].LocalID(), mats,str);
						else fill_str(edges[k].LocalID(),str);
						glColor3f(0,0,1);
						glRasterPos3dv(cnt);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
753
						if( text == 2 || text == 5 ) if(text) printtext(str);
Kirill Terekhov's avatar
Kirill Terekhov committed
754
755
756
757
758
759
						glColor3f(0,0,0);
						glBegin(GL_LINES);
						glVertex3dv(&nodes[0].Coords()[0]);
						glVertex3dv(&nodes[1].Coords()[0]);
						glEnd();
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
760

Kirill Terekhov's avatar
Kirill Terekhov committed
761
762
					glColor3f(1,0,0);
					if(mats_tag.isValid())mats = nodes[0].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
763

Kirill Terekhov's avatar
Kirill Terekhov committed
764
765
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
766

Kirill Terekhov's avatar
Kirill Terekhov committed
767
768
769
770
771
						if( mats_tag.isValid() ) fill_mat_str(nodes[0].LocalID(), mats,str);
						else fill_str(nodes[0].LocalID(),str);
						glRasterPos3dv(&nodes[0].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
772

Kirill Terekhov's avatar
Kirill Terekhov committed
773
					if(mats_tag.isValid()) mats = nodes[1].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
774

Kirill Terekhov's avatar
Kirill Terekhov committed
775
776
777
778
779
780
781
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
						if( mats_tag.isValid() ) fill_mat_str(nodes[1].LocalID(),mats,str);
						else fill_str(nodes[1].LocalID(),str);
						glRasterPos3dv(&nodes[1].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
782
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
783
784
785

				ElementArray<Face> faces = it->getFaces();

Kirill Terekhov's avatar
Kirill Terekhov committed
786
				for(unsigned k = 0; k < faces.size(); k++)
Kirill Terekhov's avatar
Kirill Terekhov committed
787
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
788
789
790
791
792
793
794
795
796
797
798
					if(mats_tag.isValid())mats = faces[k].IntegerArray(mats_tag);
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
						if( faces[k].Boundary() )
							glColor3f(0.15,0.45,0);
						else glColor3f(0,1,0);
						faces[k].Centroid(cnt);
						if( mats_tag.isValid() ) fill_mat_str(faces[k].LocalID(),mats,str);
						else fill_str(faces[k].LocalID(), str);
						glRasterPos3dv(cnt);
						if( text == 3 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
799

Kirill Terekhov's avatar
Kirill Terekhov committed
800
801
802
803
804
805
806
807
808
809
						//~ glColor3f(0,0,0);
						//~ Storage::real nrm[3];
						//~ faces[k].OrientedNormal(it->getAsCell(),nrm);
						//~ glLineWidth(2.0);
						//~ glBegin(GL_LINES);
						//~ glVertex3dv(cnt);
						//~ glVertex3d(cnt[0]+nrm[0]*20,cnt[1]+nrm[1]*20,cnt[2]+nrm[2]*20);
						//~ glEnd();
						//~ glLineWidth(1.0);
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
810
					//polygons.push_back(DrawFace(&faces[k],0,campos));
Kirill Terekhov's avatar
Kirill Terekhov committed
811
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
812
813


Kirill Terekhov's avatar
Kirill Terekhov committed
814
815
816
817
818
819
820
821
822
823
				if( matfilter == 0 || (mat.isValid() && it->Integer(mat) == matfilter-1) )
				{
					glColor3f(0,0,0);
					it->Centroid(cnt);
					sprintf(str,"%d",it->LocalID());
					if(parent_tag.isValid()) sprintf(str,"%s, %d",str,it->Integer(parent_tag));
					if(cell_material_tag.isValid()) sprintf(str,"%s, %d",str,it->Integer(cell_material_tag));
					if( problem_tag.isValid() ) sprintf(str,"%s, %d", str, it->Integer(problem_tag));
					glRasterPos3dv(cnt);
					if( text == 4 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
824

Kirill Terekhov's avatar
Kirill Terekhov committed
825
826
827
828
829
830
831
					glPointSize(3);
					glColor3f(1,0,0);
					glBegin(GL_POINTS);
					glVertex3dv(cnt);
					glEnd();
					glPointSize(1);
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
832
833
834
			}
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
835
836
	std::vector<face2gl> inside_face;
	if( !show_faces.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
837
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
838
		for(int qq = 0; qq < show_faces.size(); qq++)
Kirill Terekhov's avatar
Kirill Terekhov committed
839
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
840
841
			Element it = InvalidElement();
			if( show_faces[qq] < 0 || show_faces[qq] >= mesh->LastLocalID(FACE) ) continue;
Kirill Terekhov's avatar
Kirill Terekhov committed
842
843

			it = mesh->ElementByLocalID(FACE,show_faces[qq]);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
844
			if( it.isValid() )
Kirill Terekhov's avatar
Kirill Terekhov committed
845
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
846
847
				Storage::integer_array mats;
				Storage::real cnt[3], cntf[3];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
848
				ElementArray<Edge> edges = it->getEdges();
Kirill Terekhov's avatar
Kirill Terekhov committed
849
850
851
852
853
				it->Centroid(cntf);
				for(unsigned k = 0; k < edges.size(); k++)
				//if( edges[k].nbAdjElements(CELL) == 0 )
				{
					if(mats_tag.isValid() ) mats = edges[k].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
854
855
856

					ElementArray<Node> nodes = edges[k].getNodes();

Kirill Terekhov's avatar
Kirill Terekhov committed
857
858
859
860
861
862
863
864
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
						edges[k].Centroid(cnt);
						if( mats_tag.isValid() ) fill_mat_str(edges[k].LocalID(), mats,str);
						else fill_str(edges[k].LocalID(),str);
						glColor3f(0,0,1);
						glRasterPos3dv(cnt);
						if( text == 2 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
865

Kirill Terekhov's avatar
Kirill Terekhov committed
866
867
868
869
870
871
872
873
874
875
876
877
878
879
						glColor3f(0,0,0);
						glBegin(GL_LINES);
						glVertex3dv(&nodes[0].Coords()[0]);
						glVertex3dv(&nodes[1].Coords()[0]);
						glEnd();

						face2gl f;
						f.set_color(0.6,0.6,0.6,0.1);
						f.add_vert(cntf);
						f.add_vert(&nodes[0].Coords()[0]);
						f.add_vert(&nodes[1].Coords()[0]);
						f.set_center(cntf,campos);
						inside_face.push_back(f);
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
880

Kirill Terekhov's avatar
Kirill Terekhov committed
881
882
883
884
885
886
887
888
889
890
891
892
					glColor3f(1,0,0);
					 if( mats_tag.isValid() ) mats = nodes[0].IntegerArray(mats_tag);
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
						if( mats_tag.isValid() ) fill_mat_str(nodes[0].LocalID(), mats,str);
						else fill_str(nodes[0].LocalID(),str);
						glRasterPos3dv(&nodes[0].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
					if( mats_tag.isValid() ) mats = nodes[1].IntegerArray(mats_tag);
					if( matfilter == 0 || (mats_tag.isValid() &&std::binary_search(mats.begin(),mats.end(),matfilter-1)) )
					{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
893

Kirill Terekhov's avatar
Kirill Terekhov committed
894
895
896
897
898
						if( mats_tag.isValid() ) fill_mat_str(nodes[1].LocalID(),mats,str);
						else fill_str(nodes[1].LocalID(),str);
						glRasterPos3dv(&nodes[1].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
899

Kirill Terekhov's avatar
Kirill Terekhov committed
900
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
901

Kirill Terekhov's avatar
Kirill Terekhov committed
902
903
904
905
906
907
908
909
910
				if( matfilter == 0 || (mat.isValid() &&it->Integer(mat) == matfilter-1) )
				{
					glColor3f(0,1,0);
					if( mats_tag.isValid() ) fill_mat_str(it->LocalID(),it->IntegerArray(mats_tag),str);
					else fill_str(it->LocalID(),str);
					glRasterPos3dv(cntf);
					if( text == 3 || text == 5 ) if(text) printtext(str);
				}
#if 0
Dmitry Bagaev's avatar
Dmitry Bagaev committed
911
				ElementArray<Cell> cells = it->getCells();
Kirill Terekhov's avatar
Kirill Terekhov committed
912

Dmitry Bagaev's avatar
Dmitry Bagaev committed
913
				for(ElementArray<Cell>::iterator jt = cells.begin(); jt != cells.end(); ++jt)
Kirill Terekhov's avatar
Kirill Terekhov committed
914
915
916
917
918
919
920
				{
					glColor3f(0,0,0);
					jt->Centroid(cnt);
					fill_str(jt->LocalID(),str);
					glRasterPos3dv(cnt);
					if( text == 4 || text == 5 ) if(text) printtext(str);
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
921

Kirill Terekhov's avatar
Kirill Terekhov committed
922
923
	#if defined(DISCR_DEBUG)
				Storage::real cnt0[3], cnt2[3], nrm[3], f1[3],f2[3],l;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
924

Kirill Terekhov's avatar
Kirill Terekhov committed
925
926
927
				it->Centroid(cnt0);
				/*
				glColor3f(0,0,1);
Kirill Terekhov's avatar
Kirill Terekhov committed
928
				glBegin(GL_LINES);
Kirill Terekhov's avatar
Kirill Terekhov committed
929
930
931
932
				it->getAsFace()->UnitNormal(nrm);
				tensor_prod3(&it->getAsFace()->BackCell()->RealArrayDF(tensor)[0],
							 nrm,f1);
				l = dot_prod(f1,f1);
Kirill Terekhov's avatar
Kirill Terekhov committed
933
				glVertex3dv(cnt0);
Kirill Terekhov's avatar
Kirill Terekhov committed
934
				glVertex3d(cnt[0]-f1[0],cnt[1]-f1[1],cnt[2]-f1[2]);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
935

Kirill Terekhov's avatar
Kirill Terekhov committed
936
937
938
939
940
941
942
				if(it->getAsFace()->FrontCell() != NULL )
				{
					tensor_prod3(&it->getAsFace()->BackCell()->RealArrayDF(tensor)[0],
								 nrm,f2);
					glVertex3dv(cnt0);
					glVertex3d(cnt[0]+f2[0],cnt[1]+f2[1],cnt[2]+f2[2]);
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
943
				glEnd();
Kirill Terekhov's avatar
Kirill Terekhov committed
944
				*/
Dmitry Bagaev's avatar
Dmitry Bagaev committed
945
				for(ElementArray<Cell>::iterator jt = cells.begin(); jt != cells.end(); ++jt)
Kirill Terekhov's avatar
Kirill Terekhov committed
946
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
947
948
949
					jt->Centroid(cnt);

					glColor3f(0,0,0);
Kirill Terekhov's avatar
Kirill Terekhov committed
950
951
952
953
954
					glBegin(GL_LINES);
					glVertex3dv(cnt0);
					glVertex3dv(cnt);
					glEnd();

Dmitry Bagaev's avatar
Dmitry Bagaev committed
955
					ElementArray<Face> faces = jt->getFaces();
Kirill Terekhov's avatar
Kirill Terekhov committed
956

Dmitry Bagaev's avatar
Dmitry Bagaev committed
957
					for(ElementArray<Face>::iterator qt = faces.begin(); qt != faces.end(); ++qt)
Kirill Terekhov's avatar
Kirill Terekhov committed
958
959
960
					{
						qt->Centroid(cnt);
						glColor3f(0,0,1);
Kirill Terekhov's avatar
Kirill Terekhov committed
961
962
963
964
965
966
967
						glBegin(GL_LINES);
						glVertex3dv(cnt0);
						glVertex3dv(cnt);
						glEnd();
						sprintf(str,"%d",qt->LocalID());
						glRasterPos3dv(cnt);
						printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
968

Kirill Terekhov's avatar
Kirill Terekhov committed
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
						if( !qt->Boundary() )
						{
							Storage::real stub;
							Cell * xL = qt->FrontCell();
							Cell * xK = qt->BackCell();
							Cell * xQ = xK == &*jt ? xL : xK;
							xQ->Centroid(cnt2);
							FindHarmonicPoint(&*qt,&*jt,xQ,tensor,cnt0,cnt2,cnt,stub);
							glColor3f(1,0,0);
							glBegin(GL_LINES);
							glVertex3dv(cnt0);
							glVertex3dv(cnt);
							glVertex3dv(cnt);
							glVertex3dv(cnt2);
							glEnd();

							sprintf(str,"%d",xQ->LocalID());
							glRasterPos3dv(cnt2);
							printtext(str);
						}
						else
						{
							Cell * xK = qt->BackCell();
							xK->Centroid(cnt2);
							FindBoundaryPoint(&*qt,xK,tensor,cnt2,cnt);

							glColor3f(0,1,0);
							glBegin(GL_LINES);
							glVertex3dv(cnt0);
							glVertex3dv(cnt);
							glEnd();

							sprintf(str,"%d",qt->LocalID());
							glRasterPos3dv(cnt);
							printtext(str);
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
1005
1006
1007
					}
				}

Kirill Terekhov's avatar
Kirill Terekhov committed
1008
1009
				glEnd();
	#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
1010
#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
1011
1012
1013
1014
				//mats = it->IntegerArray(mats_tag);
				//if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
				//	polygons.push_back(DrawFace(&*it,0,campos));
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
1015
1016
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1017
	std::sort(inside_face.rbegin(),inside_face.rend());
Kirill Terekhov's avatar
Kirill Terekhov committed
1018

Kirill Terekhov's avatar
Kirill Terekhov committed
1019
1020
1021
1022
1023
	glEnable(GL_BLEND);

	for(int q = 0; q < inside_face.size() ; q++) inside_face[q].draw();

	glDisable(GL_BLEND);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1024

Kirill Terekhov's avatar
Kirill Terekhov committed
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
	//for(Mesh::iteratorCell it = mesh->BeginCell(); it != mesh->EndCell(); it++)
#if defined(OCTREECUTCELL_DEBUG)
	if( show_cell == -1 && show_face == -1 )
	{
		int end = mesh->MaxLocalID(CELL);
		//for(int i = 0; i < end; ++i)
		if( problem_set != NULL ) for(ElementSet::iterator iit = problem_set->begin(); iit != problem_set->end(); ++iit)
		{
			Element * it = &*iit;//mesh->ElementByLocalID(CELL,i);
			//if( it == NULL ) continue;
			//if(it->HaveData(problem_tag) && it->Integer(problem_tag) != 0 )
			{
				if( parentfilter != -1 && parent_tag.isValid() && it->Integer(parent_tag) != parentfilter ) continue;
				Storage::integer_array mats;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1039
				ElementArray<Edge> edges = it->getEdges();
Kirill Terekhov's avatar
Kirill Terekhov committed
1040
1041
1042
1043
1044
				Storage::real cnt[3];
				for(unsigned k = 0; k < edges.size(); k++)
				{
					edges[k].Centroid(cnt);
					mats = edges[k].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1045
1046
1047

					ElementArray<Node> nodes = edges[k].getNodes();

Kirill Terekhov's avatar
Kirill Terekhov committed
1048
1049
1050
1051
1052
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
					{
						fill_mat_str(edges[k].LocalID(), mats,str);
						glColor3f(0,0,1);
						glRasterPos3dv(cnt);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1053
						if( text == 2 || text == 5 ) if(text) printtext(str);
Kirill Terekhov's avatar
Kirill Terekhov committed
1054
1055
1056
1057
1058
1059
						glColor3f(0,0,0);
						glBegin(GL_LINES);
						glVertex3dv(&nodes[0].Coords()[0]);
						glVertex3dv(&nodes[1].Coords()[0]);
						glEnd();
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1060

Kirill Terekhov's avatar
Kirill Terekhov committed
1061
1062
					glColor3f(1,0,0);
					mats = nodes[0].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1063

Kirill Terekhov's avatar
Kirill Terekhov committed
1064
1065
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
					{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1066

Kirill Terekhov's avatar
Kirill Terekhov committed
1067
1068
1069
1070
						fill_mat_str(nodes[0].LocalID(), mats,str);
						glRasterPos3dv(&nodes[0].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1071

Kirill Terekhov's avatar
Kirill Terekhov committed
1072
					mats = nodes[1].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1073

Kirill Terekhov's avatar
Kirill Terekhov committed
1074
1075
1076
1077
1078
1079
1080
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
					{
						fill_mat_str(nodes[1].LocalID(),mats,str);
						glRasterPos3dv(&nodes[1].Coords()[0]);
						if( text == 1 || text == 5 ) if(text) printtext(str);
					}
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1081
1082
1083

				ElementArray<Face> faces = it->getFaces();

Kirill Terekhov's avatar
Kirill Terekhov committed
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
				for(unsigned k = 0; k < faces.size(); k++)
				{
					mats = faces[k].IntegerArray(mats_tag);
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
					{
						if( faces[k].Boundary() )
							glColor3f(0.15,0.45,0);
						else glColor3f(0,1,0);
						faces[k].Centroid(cnt);
						fill_mat_str(faces[k].LocalID(),mats,str);
						glRasterPos3dv(cnt);
						if( text == 3 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1096
1097


Kirill Terekhov's avatar
Kirill Terekhov committed
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
						//~ glColor3f(0,0,0);
						//~ Storage::real nrm[3];
						//~ faces[k].OrientedNormal(it->getAsCell(),nrm);
						//~ glLineWidth(3.0);
						//~ glBegin(GL_LINES);
						//~ glVertex3dv(cnt);
						//~ glVertex3d(cnt[0]+nrm[0]*20,cnt[1]+nrm[1]*20,cnt[2]+nrm[2]*20);
						//~ glEnd();
						//~ glLineWidth(1.0);
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1108
					//polygons.push_back(DrawFace(&faces[k],0,campos));
Kirill Terekhov's avatar
Kirill Terekhov committed
1109
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1110
1111


Kirill Terekhov's avatar
Kirill Terekhov committed
1112
1113
1114
1115
1116
1117
1118
1119
				if( matfilter == 0 || it->Integer(mat) == matfilter-1 )
				{
					glColor3f(0,0,0);
					it->Centroid(cnt);
					sprintf(str,"%d, %d, %d",it->LocalID(),it->Integer(parent_tag),it->Integer(cell_material_tag)+1);
					if( problem_tag.isValid() ) sprintf(str,"%s, %d", str, it->Integer(problem_tag));
					glRasterPos3dv(cnt);
					if( text == 4 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1120

Kirill Terekhov's avatar
Kirill Terekhov committed
1121
1122
1123
1124
1125
1126
1127
					glPointSize(3);
					glColor3f(1,0,0);
					glBegin(GL_POINTS);
					glVertex3dv(cnt);
					glEnd();
					glPointSize(1);
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1128
1129
1130
1131
1132
1133






Kirill Terekhov's avatar
Kirill Terekhov committed
1134
1135
1136
1137
1138
1139
1140
			}
		}
		if( display_orphans )
		{
			//end = mesh->MaxLocalID(EDGE);
			//for(Mesh::iteratorEdge it = mesh->BeginEdge(); it != mesh->EndEdge(); it++)
			//for(int i = 0; i < end; i++)
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1141
			if( orphan_edges != NULL ) for(ElementSet::iterator iit = orphan_edges.Begin(); iit != orphan_edges.End(); ++iit)
Kirill Terekhov's avatar
Kirill Terekhov committed
1142
1143
1144
1145
1146
1147
1148
			{
				Element * it = &*iit;//mesh->ElementByLocalID(EDGE,i);
				//if( it == NULL ) continue;
				//if( it->nbAdjElements(CELL) == 0 )
				{
					Storage::integer_array mats = it->IntegerArray(mats_tag);
					Storage::real cnt[3];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1149
1150
1151

					ElementArray<Node> nodes = it->getNodes();

Kirill Terekhov's avatar
Kirill Terekhov committed
1152
1153
1154
1155
1156
1157
1158
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
					{
						it->Centroid(cnt);
						fill_mat_str(it->LocalID(), mats,str);
						glColor3f(1,0,1);
						glRasterPos3dv(cnt);
						if( text == 2 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1159
1160


Kirill Terekhov's avatar
Kirill Terekhov committed
1161
1162
1163
1164
						glBegin(GL_LINES);
						glVertex3dv(&nodes[0].Coords()[0]);
						glVertex3dv(&nodes[1].Coords()[0]);
						glEnd();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1165
1166


Kirill Terekhov's avatar
Kirill Terekhov committed
1167
1168
						glColor3f(1,0,1);
						mats = nodes[0].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1169
1170


Kirill Terekhov's avatar
Kirill Terekhov committed
1171
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1172
1173


Kirill Terekhov's avatar
Kirill Terekhov committed
1174
1175
1176
1177
1178
					//~ glColor3f(1,0,0);
					//~ mats = nodes[0].IntegerArray(mats_tag);
					//~ fill_mat_str(nodes[0].LocalID(), mats,str);
					//~ glRasterPos3dv(&nodes[0].Coords()[0]);
					//~ printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1179
					//~
Kirill Terekhov's avatar
Kirill Terekhov committed
1180
1181
1182
1183
					//~ mats = nodes[1].IntegerArray(mats_tag);
					//~ fill_mat_str(nodes[1].LocalID(),mats,str);
					//~ glRasterPos3dv(&nodes[1].Coords()[0]);
					//~ printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1184

Kirill Terekhov's avatar
Kirill Terekhov committed
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
				}
			}
			//end = mesh->MaxLocalID(FACE);
			//for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); it++)
			//for(int i = 0; i < end; i++)
			if( orphan_faces != NULL ) for(ElementSet::iterator iit = orphan_faces->begin(); iit != orphan_faces->end(); ++iit)
			{
				Element * it = &*iit;//mesh->ElementByLocalID(FACE,i);
				//if( it == NULL ) continue;
				//if( it->nbAdjElements(CELL) == 0 )
				{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1196

Kirill Terekhov's avatar
Kirill Terekhov committed
1197
1198
					Storage::integer_array mats;
					Storage::real cnt[3];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1199
1200
					ElementArray<Edge> edges = it->getEdges();

Kirill Terekhov's avatar
Kirill Terekhov committed
1201
1202
1203
1204
					for(unsigned k = 0; k < edges.size(); k++)
					//if( edges[k].nbAdjElements(CELL) == 0 )
					{
						mats = edges[k].IntegerArray(mats_tag);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1205
1206
1207

						ElementArray<Node> nodes = edges[k].getNodes();

Kirill Terekhov's avatar
Kirill Terekhov committed
1208
1209
1210
1211
1212
1213
1214
						if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
						{
							edges[k].Centroid(cnt);
							fill_mat_str(edges[k].LocalID(), mats,str);
							glColor3f(0,0,1);
							glRasterPos3dv(cnt);
							if( text == 2 || text == 5 ) if(text) printtext(str);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1215

Kirill Terekhov's avatar
Kirill Terekhov committed
1216
1217
1218
1219
1220
1221
							glColor3f(0,0,0);
							glBegin(GL_LINES);
							glVertex3dv(&nodes[0].Coords()[0]);
							glVertex3dv(&nodes[1].Coords()[0]);
							glEnd();
						}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1222

Kirill Terekhov's avatar
Kirill Terekhov committed
1223
1224
1225
1226
1227
1228
1229
1230
						glColor3f(1,0,0);
						mats = nodes[0].IntegerArray(mats_tag);
						if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
						{
							fill_mat_str(nodes[0].LocalID(), mats,str);
							glRasterPos3dv(&nodes[0].Coords()[0]);
							if( text == 1 || text == 5 ) if(text) printtext(str);
						}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1231

Kirill Terekhov's avatar
Kirill Terekhov committed
1232
1233
1234
1235
1236
1237
1238
1239
						if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
						{
							mats = nodes[1].IntegerArray(mats_tag);
							fill_mat_str(nodes[1].LocalID(),mats,str);
							glRasterPos3dv(&nodes[1].Coords()[0]);
							if( text == 1 || text == 5 ) if(text) printtext(str);
						}
					}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1240
1241


Kirill Terekhov's avatar
Kirill Terekhov committed
1242
1243
1244

					mats = it->IntegerArray(mats_tag);

Dmitry Bagaev's avatar
Dmitry Bagaev committed
1245
					if( text == 3 || text == 5 )
Kirill Terekhov's avatar
Kirill Terekhov committed
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
					{
						it->Centroid(cnt);
						glColor3f(0,0.5,0.5);
						glRasterPos3dv(cnt);
						fill_mat_str(it->LocalID(), mats,str);
						if(text) printtext(str);
					}

			//~ EDGE 647252
					if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
						polygons.push_back(DrawFace(&*it,0,campos));
				}
			}
		}
	}
#endif
	if( boundary )
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1264
		for(ElementType etype = FACE; etype <= CELL; etype = NextElementType(etype) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1265
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1266
1267
1268
			int end = mesh->LastLocalID(etype);
			//for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); it++)
			if( colort.isValid() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1269
			{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1270
				for(int i = 0; i < end; i+= interactive ? pacef : 1)
Kirill Terekhov's avatar
Kirill Terekhov committed
1271
				{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1272
1273
1274
1275
1276
1277
1278
1279
					Element it = mesh->ElementByLocalID(etype,i);
					if( !it.isValid() ) continue;
					if( it->Boundary() )
					{
						int mmat = color ? (!it->getAsFace()->BackCell().isValid() ? 0 : it->getAsFace()->BackCell()->Integer(colort)) : (!it->getAsFace()->BackCell().isValid() ? 0 : it->getAsFace()->BackCell()->Integer(mat));
						if( matfilter == 0 || matfilter-1 == mmat )
							polygons.push_back(DrawFace(it->self(),mmat,campos));
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
1280
1281
				}
			}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1282
			else
Kirill Terekhov's avatar
Kirill Terekhov committed
1283
			{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1284
1285
1286
1287
1288
1289
1290
				for(int i = 0; i < end; i+= interactive ? pacef : 1)
				{
					Element it = mesh->ElementByLocalID(etype,i);
					if( !it.isValid() ) continue;
					if( it->Boundary() )
						polygons.push_back(DrawFace(it->self(),0,campos));
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
1291
1292
1293
			}
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1294
1295
1296

	if( display_orphans )
	{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1297
		if( orphan_edges.isValid()) for(ElementSet::iterator iit = orphan_edges.Begin(); iit != orphan_edges.End(); ++iit)
Kirill Terekhov's avatar
Kirill Terekhov committed
1298
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1299
			Element it = iit->self();//mesh->ElementByLocalID(EDGE,i);
Kirill Terekhov's avatar
Kirill Terekhov committed
1300
1301
1302
1303
1304
			//if( it == NULL ) continue;
			//if( it->nbAdjElements(CELL) == 0 )
			{
				Storage::real cnt[3];
				
Kirill Terekhov's avatar
Kirill Terekhov committed
1305
				ElementArray<Node> nodes = it->getNodes();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1306

Kirill Terekhov's avatar
Kirill Terekhov committed
1307
1308
1309
1310
1311
				{
					glBegin(GL_LINES);
					glVertex3dv(&nodes[0].Coords()[0]);
					glVertex3dv(&nodes[1].Coords()[0]);
					glEnd();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1312

Kirill Terekhov's avatar
Kirill Terekhov committed
1313
1314
1315
				}
			}
		}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1316
		if( orphan_faces.isValid() ) for(ElementSet::iterator iit = orphan_faces.Begin(); iit != orphan_faces.End(); ++iit)
Kirill Terekhov's avatar
Kirill Terekhov committed
1317
		{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1318
			Element it = iit->self();
Kirill Terekhov's avatar
Kirill Terekhov committed
1319
			{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1320

Kirill Terekhov's avatar
Kirill Terekhov committed
1321
1322
				Storage::integer_array mats;
				Storage::real cnt[3];
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1323
1324
				ElementArray<Edge> edges = it->getEdges();

Kirill Terekhov's avatar
Kirill Terekhov committed
1325
1326
				for(unsigned k = 0; k < edges.size(); k++)
				{
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1327
					ElementArray<Node> nodes = edges[k].getNodes();
Kirill Terekhov's avatar
Kirill Terekhov committed
1328
1329
1330
1331
1332
					{
						glBegin(GL_LINES);
						glVertex3dv(&nodes[0].Coords()[0]);
						glVertex3dv(&nodes[1].Coords()[0]);
						glEnd();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1333
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
1334
				}
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1335
1336


Kirill Terekhov's avatar
Kirill Terekhov committed
1337
				if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1338
					polygons.push_back(DrawFace(it->self(),0,campos));
Kirill Terekhov's avatar
Kirill Terekhov committed
1339
1340
1341
1342
			}
		}
	}

Dmitry Bagaev's avatar
Dmitry Bagaev committed
1343

Kirill Terekhov's avatar
Kirill Terekhov committed
1344
	std::sort(polygons.begin(),polygons.end());
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1345
1346
1347


	//glDisable(GL_DEPTH_TEST);
Kirill Terekhov's avatar
Kirill Terekhov committed
1348
1349
1350
1351
1352
	//if( boundary == 1 ) glEnable(GL_BLEND);
	//else glDisable(GL_BLEND);
	glEnable(GL_BLEND);

	for(int q = polygons.size(); q > 0 ; q--) polygons[q-1].draw();
Kirill Terekhov's avatar
Kirill Terekhov committed
1353
1354

	glDisable(GL_BLEND);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1355
//~
Kirill Terekhov's avatar
Kirill Terekhov committed
1356
1357
1358
	//~ for(int q = 0; q < polygons.size() ; q++)
		//~ polygons[q].draw();

Dmitry Bagaev's avatar
Dmitry Bagaev committed
1359
	//glEnable(GL_DEPTH_TEST);