main.cpp 135 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
2
3
4
#ifdef _MSC_VER //kill some warnings
#define _CRT_SECURE_NO_WARNINGS
#endif

Kirill Terekhov's avatar
Kirill Terekhov committed
5
6
//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 
Kirill Terekhov's avatar
Kirill Terekhov committed
7
#include "inmost.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
8
9
10
11
#include "rotate.h"
#include <iostream>
#include <sstream>
#include <algorithm>
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
12
#include <stdarg.h>
Kirill Terekhov's avatar
Kirill Terekhov committed
13
#include "my_glut.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
14
#include <iomanip>
15
#include "clipboard.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
16
17
18
19
20
21
22
23
24
25

inline static unsigned int flip(const unsigned int * fp)
{
	unsigned int mask = -((int)(*fp >> 31)) | 0x80000000;
	return *fp ^ mask;
}
#define _0(x)	(x & 0x7FF)
#define _1(x)	(x >> 11 & 0x7FF)
#define _2(x)	(x >> 22 )

Kirill Terekhov's avatar
Kirill Terekhov committed
26
void draw_screen();
Kirill Terekhov's avatar
Kirill Terekhov committed
27
28
29
30
31
32

using namespace INMOST;
Mesh * mesh;
int interactive = 0;
double zoom = 1;
int width = 800, height = 800;
Kirill Terekhov's avatar
Kirill Terekhov committed
33
34
35
double sleft = 1e20, sright = -1e20, sbottom = 1e20, stop = -1e20, sfar = -1e20, snear = 1e20;
double shift[3] = {0,0,0};
bool perspective = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
36
int drawedges = 0;
37
bool boundary = true, planecontrol = false, clipupdate = false, bndupdate = true, clipboxupdate = false, draw_volumetric = false, elevation = false;
38
Element disp_e;
Kirill Terekhov's avatar
Kirill Terekhov committed
39
Mesh::GeomParam table;
Kirill Terekhov's avatar
Kirill Terekhov committed
40

Kirill Terekhov's avatar
Kirill Terekhov committed
41
42
43
44
45
46
47
48
49
50
51
#define CLIP_NONE 0
#define CLIP_NODE 1
#define CLIP_FULL 2
#define CLIP_ENDP 3

#define CLIP_FACE_NONE      0
#define CLIP_FACE_INSIDE    1
#define CLIP_FACE_OUTSIDE   2
#define CLIP_FACE_INTERSECT 3

Storage::real p[3] = {0,0,0}, n[3] = {0,0,1};
Kirill Terekhov's avatar
Kirill Terekhov committed
52
ElementArray<Element> boundary_faces;
Kirill Terekhov's avatar
Kirill Terekhov committed
53
54
55
ElementArray<Edge> added_edges;
std::vector<double> harmonic_points, dual_harmonic_points, conormals;

56
57


Kirill Terekhov's avatar
Kirill Terekhov committed
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

static void GetBox(Element e, Storage::real min[3], Storage::real max[3])
{
  min[0] = min[1] = min[2] = 1.0e20;
  max[0] = max[1] = max[2] = -1.0e20;
	ElementArray<Node> nodes = e->getNodes();
	for (ElementArray<Node>::iterator it = nodes.begin(); it != nodes.end(); it++)
	{
		Storage::real_array c = it->Coords();
		for (int i = 0; i < (int)c.size(); i++) 
    {
			if (max[i] < c[i]) max[i] = c[i]; //max
			if (min[i] > c[i]) min[i] = c[i]; //min
		}
	}
  for(int i = 0; i < 3; ++i)
  {
    if( max[i] < min[i] )
    {
      max[i] = 0.0001;
      min[i] = -0.0001;
    }
    else if( max[i] == min[i] )
    {
      max[i] += 0.0001;
      min[i] += -0.0001;
    }
  }
}
Kirill Terekhov's avatar
Kirill Terekhov committed
87

Kirill Terekhov's avatar
Kirill Terekhov committed
88
89
90
double amplitude = 10;
double radius = 25;
char visualization_prompt[8192];
Kirill Terekhov's avatar
Kirill Terekhov committed
91
int visualization_prompt_active = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
92
93
Tag visualization_tag;
ElementType visualization_type;
94
bool visualization_smooth = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
95

Kirill Terekhov's avatar
Kirill Terekhov committed
96
97
98
99
void printtext(const char * fmt, ... )
{
	
	unsigned int i;
Kirill Terekhov's avatar
Kirill Terekhov committed
100
	char stext[4096];
Kirill Terekhov's avatar
Kirill Terekhov committed
101
102
103
104
105
106
107
108
109
110
111
112
	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++)
	{
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 
							stext[i]);
	}
}

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
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

class coord
{
	double p[3];
public:
	coord() { p[0] = p[1] = p[2] = 0; }
  coord(double xyz[3]) {p[0] = xyz[0]; p[1] = xyz[1]; p[2] = xyz[2];}
	coord(double x, double y, double z) {p[0] = x; p[1] = y; p[2] = z;}
	coord(const coord & other) {p[0] = other.p[0]; p[1] = other.p[1]; p[2] = other.p[2];}
	coord & operator = (coord const & other) {p[0] = other.p[0]; p[1] = other.p[1]; p[2] = other.p[2]; return *this;}
  coord & operator +=(const coord & other) {p[0] += other.p[0]; p[1] += other.p[1]; p[2] += other.p[2]; return *this;}
  coord & operator -=(const coord & other) {p[0] -= other.p[0]; p[1] -= other.p[1]; p[2] -= other.p[2]; return *this;}
  coord & operator *=(const coord & other) 
  {
    double tmp[3] = {p[1]*other.p[2] - p[2]*other.p[1], p[2]*other.p[0] - p[0]*other.p[2], p[0]*other.p[1] - p[1]*other.p[0]};
    p[0] = tmp[0]; p[1] = tmp[1]; p[2] = tmp[2];
    return *this;
  }
  coord & operator *=(double other) { p[0] *= other; p[1] *= other; p[2] *= other; return *this;}
  coord & operator /=(double other) { p[0] /= other; p[1] /= other; p[2] /= other; return *this;}
	coord operator -(const coord & other) const {return coord(p[0]-other.p[0],p[1]-other.p[1],p[2]-other.p[2]);}
	coord operator +(const coord & other) const {return coord(p[0]+other.p[0],p[1]+other.p[1],p[2]+other.p[2]);}
	coord operator *(const coord & other) const {return coord(p[1]*other.p[2] - p[2]*other.p[1],p[2]*other.p[0] - p[0]*other.p[2],p[0]*other.p[1] - p[1]*other.p[0]);}
	coord operator /(double other) const {return coord(p[0]/other,p[1]/other,p[2]/other);}
  coord operator *(double other) const {return coord(p[0]*other,p[1]*other,p[2]*other);}
	double operator ^(const coord & other) const {return p[0]*other.p[0]+p[1]*other.p[1]+p[2]*other.p[2];}
	~coord() {}
  double length() const {return sqrt((*this)^(*this));}
	double & operator [](int i) {return p[i];}
  double * data() {return p;}
};

double abs(const coord & p)
{
  return sqrt(p^p);
}


void get_matrix(const coord & a, const coord & b, double matrix[16])
{
	double d;
	coord z = (b-a)/sqrt((b-a)^(b-a));
	coord y;
	coord x;
	y = coord(z[1],-z[2],0);
	d = sqrt(y^y);
	if( d < 1e-5 )
	{
		y = coord(-z[2],0,z[0]);
		d = sqrt(y^y);
	}
	y = y / d;
	x = y*z;
	x = x / sqrt(x^x);
	y = x*z;
	matrix[0] = x[0];
	matrix[1] = x[1];
	matrix[2] = x[2];
	matrix[3] = 0;
	matrix[4] = y[0];
	matrix[5] = y[1];
	matrix[6] = y[2];
	matrix[7] = 0;
	matrix[8] = z[0];
	matrix[9] = z[1];
	matrix[10] = z[2];
	matrix[11] = 0;
	matrix[12] = 0;
	matrix[13] = 0;
	matrix[14] = 0;
	matrix[15] = 1;
}

GLUquadric * cylqs = NULL;
void drawcylinder(coord a,coord b, double width)
{
	double matrix[16];
	if( cylqs == NULL )
	{
		cylqs = gluNewQuadric();
		gluQuadricNormals(cylqs, GLU_SMOOTH);
		gluQuadricOrientation(cylqs, GLU_OUTSIDE);
		gluQuadricDrawStyle(cylqs,GLU_FILL);//GLU_SILHOUETTE
	}
	glPushMatrix();
	glTranslated(a[0],a[1],a[2]);
	get_matrix(a,b,matrix);
	glMultMatrixd(matrix);
	gluCylinder(cylqs, width,width,sqrt((b-a)^(b-a)), 4, 2);
	glPopMatrix();
}

class Octree : public ElementSet
{
  Tag save_center_tag;
  bool save_quad_tree;
  void SubConstruct(const Tag & child_tag, const Tag & center_tag, HandleType * cells, HandleType * temp, int size, bool quad_tree)
  {
    Storage::real_array center = RealArray(center_tag);
    //create 8 nodes
    Storage::real cell_center[3];
    int offsets[8], sizes[8];
    int dims = 3 - (quad_tree ? 1 : 0);
    int numchildren = (1 << dims);
    for(int k = 0; k < numchildren; ++k)
    {
      offsets[k] = 0;
      sizes[k] = 0;
    }
    for(int r = 0; r < size; ++r)
    {
      Element c = Element(GetMeshLink(),cells[r]);
      c->Centroid(cell_center);
      int child_num = 0;
      for(int k = 0; k < dims; ++k)
      {
        if( cell_center[k] > center[k] )
        {
          int m = 1<<k;
          child_num += m;
        }
      }
      c->IntegerDF(child_tag) = child_num;
      sizes[child_num]++;
    }
    for(int k = 1; k < numchildren; ++k)
    {
      offsets[k] = offsets[k-1]+sizes[k-1];
    }
    for(int k = 0; k < numchildren; ++k)
    {
      std::stringstream name;
      name << GetName() << "chld" << k;
      ElementSet child = GetMeshLink()->CreateSetUnique(name.str()).first;
      Storage::real_array child_center = child->RealArray(center_tag);
      for(int r = 0; r < dims; ++r)
      {
        int l = 1 << r;
        int m = k & l;
        child_center[r] = center[r] + ((m ? 1.0 : -1.0) * center[r+3] * 0.25);
        child_center[r+3] = center[r+3]*0.5;
      }
      int m = 0;
      for(int r = 0; r < size; ++r)
      {
        Element c = Element(GetMeshLink(),cells[r]);
        int q = c->IntegerDF(child_tag);
        if( q == k ) (temp+offsets[k])[m++] = cells[r];
      }
      AddChild(child);
      if( sizes[k] <= 16 && sizes[k] > 0 )
        child->PutElements(temp+offsets[k],sizes[k]);
    }
    // cells array is not needed anymore
    ElementSet child = GetChild();
    for(int k = 0; k < numchildren; ++k)
    {
      if( sizes[k] > 16 )
        Octree(child).SubConstruct(child_tag,center_tag,temp+offsets[k],cells+offsets[k],sizes[k], quad_tree);
      child = child->GetSibling();
    }
  }
  Cell SubFindCell(const Tag & center_tag, Storage::real pnt[3], bool quad_tree) const
  {
    if( HaveChild() )
    {
      Storage::real_array center = RealArray(center_tag);
      int child_num = 0, q;
      int dims = 3 - (quad_tree ? 1 : 0);
      for(int k = 0; k < dims; ++k)
      {
        if( pnt[k] > center[k] )
          child_num += (1 << k);
      }
      q = 0;
      ElementSet set = GetChild();
      while(q != child_num) {set = set->GetSibling(); q++;}
      return Octree(set).SubFindCell(center_tag,pnt,quad_tree);
    }
    else
    {
      HandleType * cells = getHandles();
      int ncells = (int)nbHandles();
      Node closest = InvalidNode();
      Storage::real mindist = 1.0e20, dist;
      for(int k = 0; k < ncells; ++k)
      {
        Node c = Node(GetMeshLink(),cells[k]);
        Storage::real_array cnt = c->Coords();
        dist = sqrt((cnt[0]-pnt[0])*(cnt[0]-pnt[0])+(cnt[1]-pnt[1])*(cnt[1]-pnt[1])+(cnt[2]-pnt[2])*(cnt[2]-pnt[2]));
        if( mindist > dist )
        {
          mindist = dist;
          closest = c;
        }
      }
      if( closest.isValid() )
      {
        ElementArray<Cell> cells = closest->getCells();
        for(ElementArray<Cell>::iterator c = cells.begin(); c != cells.end(); ++c)
          if( c->Inside(pnt) ) return c->self();
      }
      return InvalidCell();
    }
  }
  bool Inside(const Storage::real_array & center, Storage::real pnt[3], bool quad_tree) const
  {
    bool inside = true;
    int dims = 3 - (quad_tree ? 1 : 0);
    for(int i = 0; i < dims; ++i) 
      inside &= (pnt[i] >= center[i] - center[3+i]*0.5 && pnt[i] <= center[i] + center[3+i]*0.5);
    return inside;
  }
  Node SubFindNode(const Tag & center_tag, Storage::real pnt[3], bool quad_tree) const
  {
    if( HaveChild() )
    {
      Storage::real_array center = RealArray(center_tag);
      if( !Inside(center,pnt,quad_tree) ) return InvalidNode();
      int child_num = 0, q;
      int dims = 3 - (quad_tree ? 1 : 0);
      for(int k = 0; k < dims; ++k)
      {
        if( pnt[k] > center[k] )
          child_num += (1 << k);
      }
      q = 0;
      ElementSet set = GetChild();
      while(q != child_num) {set = set->GetSibling(); q++;}
      return Octree(set).SubFindNode(center_tag,pnt,quad_tree);
    }
    else
    {
      HandleType * cells = getHandles();
      int ncells = (int)nbHandles();
      Node closest = InvalidNode();
      Storage::real mindist = 1.0e20, dist;
      for(int k = 0; k < ncells; ++k)
      {
        Node c = Node(GetMeshLink(),cells[k]);
        Storage::real_array cnt = c->Coords();
        dist = sqrt((cnt[0]-pnt[0])*(cnt[0]-pnt[0])+(cnt[1]-pnt[1])*(cnt[1]-pnt[1])+(cnt[2]-pnt[2])*(cnt[2]-pnt[2]));
        if( mindist > dist )
        {
          mindist = dist;
          closest = c;
        }
      }
      return closest;
    }
  }
  void SubDestroy()
  {
    if( HaveChild() )
    {
      ElementSet set = GetChild(), next;
      while(set->isValid())
      {
        next = set->GetSibling();
        Octree(set).SubDestroy();
        set = next;
      }
    }
    DeleteSet();
    handle = InvalidHandle();
    handle_link = NULL;
  }
public:
  Octree() : ElementSet(InvalidElementSet()) {}
  Octree(const Octree & other) : ElementSet(other) {}
  Octree(const ElementSet & eset) : ElementSet(eset) {}
  void Construct(ElementType elem, bool quad_tree = false)
  {
    save_quad_tree = quad_tree;
    int dims = 3 - (quad_tree ? 1 : 0);
    Tag child_tag = GetMeshLink()->CreateTag("OCTREE_CHILD_NUM_"+GetName(),DATA_INTEGER,elem,NONE,1);
    save_center_tag = GetMeshLink()->CreateTag("OCTREE_CENTER_"+GetName(),DATA_REAL,ESET,ESET,6);
    Storage::real bounds[3][2];
    for(int k = 0; k < dims; ++k)
    {
      bounds[k][0] = 1.0e20;
      bounds[k][1] =-1.0e20;
    }
    //calculate bounds
    for(Mesh::iteratorNode node = GetMeshLink()->BeginNode(); node != GetMeshLink()->EndNode(); ++node)
    {
      Storage::real_array coord = node->Coords();
      for(int k = 0; k < dims; ++k)
      {
        if( coord[k] < bounds[k][0] ) bounds[k][0] = coord[k];
        if( coord[k] > bounds[k][1] ) bounds[k][1] = coord[k];
      }
    }
    Storage::real_array center_data = RealArray(save_center_tag);
    for(int k = 0; k < dims; ++k)
    {
      center_data[k] = (bounds[k][0]+bounds[k][1])*0.5; //central position
      center_data[k+3] = bounds[k][1]-bounds[k][0]; //length
    }
    //copy cells
    int size = GetMeshLink()->NumberOf(elem), k = 0;
    HandleType * cells = new HandleType[size*2];
    HandleType * temp = cells+size;
    for(Mesh::iteratorElement cell = GetMeshLink()->BeginElement(elem); cell != GetMeshLink()->EndElement(); ++cell)
      cells[k++] = *cell;
    SubConstruct(child_tag,save_center_tag,cells,temp,size,quad_tree);
    GetMeshLink()->DeleteTag(child_tag);
  }
  Cell FindCell(Storage::real pnt[3]) const
  {
    return SubFindCell(save_center_tag,pnt,save_quad_tree);
  }
  Node FindNode(Storage::real pnt[3]) const
  {
    return SubFindNode(save_center_tag,pnt,save_quad_tree);
  }
  void Destroy()
  {
    if( save_center_tag.isValid() )
      GetMeshLink()->DeleteTag(save_center_tag);
    SubDestroy();
  }
  ~Octree() { }
};



void GetVelocity(Cell c, const Tag & velocity_tag, coord pnt, coord & ret)
{
  ElementArray<Cell> adj = c->NeighbouringCells();
  adj.push_back(c);
  coord cnt;
  const Storage::real eps = 1.0e-8;
  Storage::real dist = 0;
  ret[0] = ret[1] = ret[2] = 0;
  for(ElementArray<Cell>::iterator it = adj.begin(); it != adj.end(); ++it)
  {
    it->Centroid(cnt.data());
    coord vel = coord(it->RealArray(velocity_tag).data());
    Storage::real l = (cnt-pnt).length() + eps;
    Storage::real omega = 1.0/(l*l);
    ret += vel*omega;
    dist += omega;
  }
  ret /= dist;
}

void GetVelocity(Node c, const Tag & velocity_tag, coord pnt, coord & ret)
{
  ElementArray<Cell> adj = c->getCells();
  coord cnt;
  const Storage::real eps = 1.0e-8;
  Storage::real dist = 0;
  ret[0] = ret[1] = ret[2] = 0;
  for(ElementArray<Cell>::iterator it = adj.begin(); it != adj.end(); ++it)
  {
    it->Centroid(cnt.data());
    coord vel = coord(it->RealArray(velocity_tag).data());
    Storage::real l = (cnt-pnt).length() + eps;
    Storage::real omega = 1.0/(l*l);
    ret += vel*omega;
    dist += omega;
  }
  ret /= dist;
}


Storage::real GetSize(Cell c)
{
  Storage::real bounds[3][2] = {{1.0e20,-1.0e20},{1.0e20,-1.0e20},{1.0e20,-1.0e20}};
  ElementArray<Node> nodes = c->getNodes();
  for(ElementArray<Node>::iterator n = nodes.begin(); n != nodes.end(); ++n)
  {
    Storage::real_array cnt = n->Coords();
    for(int k = 0; k < 3; ++k)
    {
      if( bounds[k][0] > cnt[k] ) bounds[k][0] = cnt[k];
      if( bounds[k][1] < cnt[k] ) bounds[k][1] = cnt[k];
    }
  }
  Storage::real ret = bounds[0][1]-bounds[0][0];
  ret = std::min(ret,bounds[1][1]-bounds[1][0]);
  ret = std::min(ret,bounds[2][1]-bounds[2][0]);
  return ret;
}


Storage::real GetSize(Node n, const Tag & size_tag)
{
  ElementArray<Cell> cells = n->getCells();
  Storage::real minsize = 1.0e+20, size;
  for(ElementArray<Cell>::iterator c = cells.begin(); c != cells.end(); ++c)
  {
    size = c->RealDF(size_tag);
    if( minsize > size ) minsize = size;
  }
  if( minsize > 1.0e+19 ) std::cout << __FILE__ << ":" << __LINE__ << " oops" << std::endl;
  return minsize;
}


class Streamline
{
private:
	std::vector<coord> points;
	std::vector<double> velarr;
public:
  Streamline() {}
	Streamline(const Octree & octsearch, coord pos, Tag velocity_tag, Tag cell_size, Storage::real velocity_min, Storage::real velocity_max, Storage::real sign, MarkerType visited)
	{
		Storage::real coef, len, size;
    coord next = pos, vel;
    Node c;
    const int maxsteps = 4000;
    points.reserve(maxsteps/2);
    velarr.reserve(maxsteps/2);
		points.push_back(pos);
		velarr.push_back(0);
	  while( points.size() < maxsteps )
		{
      c = octsearch.FindNode(next.data());
      if( !c.isValid() ) break;
      //c.SetMarker(visited);
      GetVelocity(c,velocity_tag,next,vel);
      len = vel.length();
      if( len < 1.0e-4 ) break;
      size = GetSize(c,cell_size);// c->RealDF(cell_size);
      coef = 0.35*size/len;
      next += vel*coef*sign;
      points.push_back(next);
      velarr.push_back((log(len+1.0e-25)-velocity_min)/(velocity_max-velocity_min));
		}
		//printf("%ld %ld\n",points.size(),velarr.size());
	}
	Streamline(const Streamline & other) { points = other.points; velarr = other.velarr; }
	Streamline & operator =(Streamline const & other) {points = other.points; velarr = other.velarr; return *this;}
	~Streamline() { points.clear(); velarr.clear(); }
	void Draw(int reduced)
	{
		
		if( reduced )
		{
			glBegin(GL_LINE_STRIP);
			for(unsigned int i = 0; i < points.size()-1; i++)
			{
				glColor3f(velarr[i+1]*0.65,0.65*(velarr[i+1] < 0.5 ? velarr[i] : 1.0-velarr[i]),0.65*(1-velarr[i+1]));
				glVertex3d(points[i][0],points[i][1],points[i][2]);
			}
			glEnd();
		}
		else for(unsigned int i = 0; i < points.size()-1; i++)
		{
			glColor3f(velarr[i+1]*0.65,0.65*(velarr[i+1] < 0.5 ? velarr[i] : 1.0-velarr[i]),0.65*(1-velarr[i+1]));
			drawcylinder(points[i],points[i+1],0.25*abs(points[i+1]-points[i]));
		}
		
	}
};

std::vector<Streamline> streamlines;


Kirill Terekhov's avatar
Kirill Terekhov committed
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
const int name_width = 32;
const int type_width = 14;
const int elems_width = 10;
const int sparse_width = 10;
const int length_width = 10;

void PrintTag(Tag t)
{
	std::cout << std::setw(name_width) << t.GetTagName() << std::setw(type_width) << DataTypeName(t.GetDataType());
	int num = 0;
	char elems[7] = "NEFCSM";
	std::string print = "";
	for(ElementType etype = NODE; etype <= MESH; etype = etype << 1)
	{
		if( t.isDefined(etype) )
		{
			print = print + elems[ElementNum(etype)];
			num++;
		}
	}
	std::cout << std::setw(elems_width) << print;
	print = "";
	for(ElementType etype = NODE; etype <= MESH; etype = etype << 1)
	{
		if( t.isSparse(etype) )
		{
			print = print + elems[ElementNum(etype)];
			num++;
		}
	}
	std::cout << std::setw(sparse_width) << print;
	if( t.GetSize() == ENUMUNDEF )
		std::cout << std::setw(length_width) << "VAR" << std::endl;
	else
		std::cout << std::setw(length_width) << t.GetSize() << std::endl;
}

void PrintTags(Mesh * m, ElementType etypes)
{
	std::cout << std::setw(name_width) << "Name" << std::setw(type_width) << "Type" << std::setw(elems_width) << "Element" << std::setw(sparse_width) << "Sparse" << std::setw(length_width) << "Length" << std::endl;
	for(Mesh::iteratorTag t = m->BeginTag(); t != m->EndTag(); ++t )
	{
		bool print = false;
		for(ElementType etype = NODE; etype <= MESH; etype = etype << 1) if( (etype&etypes) && t->isDefined(etype) ) {print = true; break;}
		if( print ) PrintTag(*t);
	}
}

Kirill Terekhov's avatar
Kirill Terekhov committed
623
624
625
626
627
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
662
663
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
bool write_tga( const char *filename, int w, int h, char *buffer ) 
{ 
  FILE *f = fopen( filename, "wb" ); 
  if ( !f ) 
    return false;
  putc(0,f);
  putc(0,f);
  putc(2,f);
  putc(0,f);putc(0,f);
  putc(0,f);putc(0,f);
  putc(0,f);
  putc(0,f);putc(0,f);
  putc(0,f);putc(0,f);
  putc((w & 0x00ff),f);
  putc((w & 0xff00)/256,f);
  putc((h & 0x00ff),f);
  putc((h & 0xff00)/256,f);
  putc(24,f);
  putc(0,f);
  size_t buflen = w * h * 3; 
  fwrite( buffer, 1, buflen, f ); 
  fclose(f); 
  return true; 
}

void screenshot()
{
  const int tiles = 8;
  int oldwidth = width;
  int oldheight = height;
  width *= tiles;
  height *= tiles;
  
  char * pixelbuffer = new char[width*height*3+oldwidth*oldheight*3];
  char * tempbuffer = pixelbuffer + width*height*3;

  
  
  
  for(int i = 0; i < tiles; ++i)
  {
    for(int j = 0; j < tiles; ++j )
    {
      glViewport(-oldwidth*i,-oldheight*j,width,height);
      draw_screen();
      glReadBuffer(GL_BACK);
      glReadPixels(0,0,oldwidth,oldheight,GL_BGR_EXT,GL_UNSIGNED_BYTE,tempbuffer);

      int koff = oldwidth*(i);
      int loff = oldheight*(j);
      
      for(int l = 0; l < oldheight; ++l)
      for(int k = 0; k < oldwidth; ++k)
      for(int m = 0; m < 3; ++m)
        pixelbuffer[((koff+k) + (loff+l)*width)*3+m] = tempbuffer[(k + l*oldwidth)*3+m];

      //filename[0] += i;
      //filename[1] += j;
      //write_tga(filename,width,height,pixelbuffer);
      //filename[0] = filename[1] = '0';
    }
  }
  
  /*
  glViewport(-oldwidth*3,-oldheight*3,width,height);
  draw_screen();
  glReadBuffer(GL_BACK);
  glReadPixels(0,0,width,height,GL_BGR_EXT,GL_UNSIGNED_BYTE,pixelbuffer);
  */


  
  
  
  write_tga("screenshot.tga",width,height,pixelbuffer);
  delete [] pixelbuffer;
  width = oldwidth;
  height = oldheight;
  glViewport(0,0,width,height);
}

Kirill Terekhov's avatar
Kirill Terekhov committed
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
struct color_t
{
	float c[4];
	color_t() {memset(c,0,sizeof(float)*4);}
	color_t(float r, float g, float b)
	{
		c[0] = r;
		c[1] = g;
		c[2] = b;
		c[3] = 1.0;
	}
	color_t(float r, float g, float b, float a)
	{
		c[0] = r;
		c[1] = g;
		c[2] = b;
		c[3] = a;
	}
	color_t(const color_t & other) {memcpy(c,other.c,sizeof(float)*4);}
	color_t & operator =(color_t const & other)
	{
		memmove(c,other.c,sizeof(float)*4);
		return *this;
	}
	void set_color() const {glColor4fv(c);}
	float & r() {return c[0];}
	float & g() {return c[1];}
	float & b() {return c[2];}
	float & a() {return c[3];}
	float r() const {return c[0];}
	float g() const {return c[1];}
	float b() const {return c[2];}
	float a() const {return c[3];}
	color_t operator *(float mult){return color_t(c[0]*mult,c[1]*mult,c[2]*mult,c[3]*mult);}
	color_t operator +(color_t other){return color_t(c[0]+other.c[0],c[1]+other.c[1],c[2]+other.c[2],c[3]+other.c[3]);}
739
	color_t operator -(color_t other){return color_t(c[0]-other.c[0],c[1]-other.c[1],c[2]-other.c[2],other.c[3]);}
Kirill Terekhov's avatar
Kirill Terekhov committed
740
741
742
743
744
745
746
747
};

class color_bar
{
	float min, max;
	std::vector<float> ticks; //ticks from 0 to 1 for each color
	std::vector<color_t> colors; //4 floats for each tick
	std::string comment;
748
	unsigned texture;
749
	int samples;
Kirill Terekhov's avatar
Kirill Terekhov committed
750
751
752
753
754
755
public:
	color_bar()
	{
		min = 0;
		max = 1;
		comment = "";
756
757

		/*
Kirill Terekhov's avatar
Kirill Terekhov committed
758
759
760
761
762
763
		ticks.push_back(0.f);
		ticks.push_back(0.2f);
		ticks.push_back(0.4f);
		ticks.push_back(0.6f);
		ticks.push_back(0.8f);
		ticks.push_back(1.f);
Kirill Terekhov's avatar
Kirill Terekhov committed
764

765
766
767
768
769
770
771
772
		 
		//colors.push_back(color_t(1,0,0));
		//colors.push_back(color_t(1,1,0));
		//colors.push_back(color_t(0,1,0));
		//colors.push_back(color_t(0,1,1));
		//colors.push_back(color_t(0,0,1));
		//colors.push_back(color_t(1,0,1));
		
Kirill Terekhov's avatar
Kirill Terekhov committed
773
		colors.push_back(color_t(1,0,1));
774
775
		colors.push_back(color_t(0,0,1));
		colors.push_back(color_t(0,1,1));
Kirill Terekhov's avatar
Kirill Terekhov committed
776
		colors.push_back(color_t(0,1,0));
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
		colors.push_back(color_t(1,1,0));
		colors.push_back(color_t(1,0,0));
		*/

		//inversed gnuplot color scheme
		ticks.push_back(0.f);
		ticks.push_back(0.05f);
		ticks.push_back(0.5f);
		ticks.push_back(0.75f);
		ticks.push_back(0.95f);
		ticks.push_back(1.f);

		colors.push_back(color_t(1,1,1));
		colors.push_back(color_t(1,1,0));
		colors.push_back(color_t(0.85,0,0));
		colors.push_back(color_t(0.65,0.25,0.85));
		colors.push_back(color_t(0.45,0,0.55));
		colors.push_back(color_t(0,0,0));

796
797
798
		samples = 2048;

		float * pixel_array = new float[(samples+2)*4];
799

Kirill Terekhov's avatar
Kirill Terekhov committed
800
801
		
		
802
		for(int q = 0; q < samples+2; ++q)
803
		{
804
			float t = 1.0f*q/static_cast<float>(samples+1);
805
			color_t c = pick_color(t);
806
807
808
809
			//countour lines
			//if( ((q+1) % 64 == 0 || (q+1) % 64 == 63) && (q+1) < samples ) 
			//	c = pick_color(1-t) + color_t(0,2*t*(1-t),0); 

810
811
812
813
814
815
816
817
818
819
820
			pixel_array[(q)*4+0] = c.r();
			pixel_array[(q)*4+1] = c.g();
			pixel_array[(q)*4+2] = c.b();
			pixel_array[(q)*4+3] = c.a();
		}

		pixel_array[0] = 0;
		pixel_array[1] = 1;
		pixel_array[2] = 0;
		pixel_array[3] = 1;

821
822
823
824
		pixel_array[(samples+1)*4+0] = 0;
		pixel_array[(samples+1)*4+1] = 1;
		pixel_array[(samples+1)*4+2] = 0;
		pixel_array[(samples+1)*4+3] = 1;
825
826
827
828
829
830
831
832
833

		
		
		glEnable(GL_TEXTURE);
		glEnable(GL_TEXTURE_1D);
		glGenTextures(1,&texture);
		glBindTexture(GL_TEXTURE_1D,texture);
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);
		
834
		glTexImage1D(GL_TEXTURE_1D,0,4,samples+2,1,GL_RGBA,GL_FLOAT,pixel_array);
835
836
837
838
839
840
841
842
843
844
845
846

		std::cout << "Created texture " << texture << std::endl;
		
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

		UnbindTexture();

		delete [] pixel_array;
Kirill Terekhov's avatar
Kirill Terekhov committed
847
848
849
850
851
		//colors.push_back(color_t(1,0,0));
	}
	void set_comment(std::string text) {comment = text;}
	void set_min(float newmin) { min = newmin;}
	void set_max(float newmax) { max = newmax;}
852
853
	float get_min() { return min;}
	float get_max() { return max;}
Kirill Terekhov's avatar
Kirill Terekhov committed
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
	color_t pick_color(float value) 
	{
		float t = (value-min)/(max-min);
		std::vector<float>::iterator it = std::lower_bound(ticks.begin(),ticks.end(),t);
		size_t pos = it-ticks.begin();
		if( it == ticks.end() || pos >= ticks.size() ) 
		{
			return colors.back();
		}
		if( pos == 0 ) 
		{
			return colors[0];
		}
		float interp = (t-ticks[pos-1])/(ticks[pos]-ticks[pos-1]);
		return (colors[pos]*interp+colors[pos-1]*(1-interp));
	}
870
871
872
873
874
875
876
877
878
879
880
881
882
	void BindTexture()
	{
		//glDisable( GL_TEXTURE_GEN_S ); 
		glDisable(GL_TEXTURE_2D);
		glEnable( GL_TEXTURE_1D );
		glBindTexture(GL_TEXTURE_1D, texture);
	}
	void UnbindTexture()
	{
		glDisable( GL_TEXTURE_1D );
	}
	double pick_texture(double value)
	{
883
		double eps = 1.0/static_cast<double>(samples);
884
885
886
		return (value-min)/(max-min)*(1-2*eps) + eps;
		//return std::max(std::min((value-min)/(max-min),0.99),0.01);
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
887
888
889
890
891
892
893
	void Draw()
	{
		float text_pos = -0.89;
		float left = -0.95;
		float right = -0.9;
		float bottom = -0.75;
		float top = 0.75;
894
		BindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
895
		glBegin(GL_QUADS);
896
897
898
899
900
901
902
903

		glTexCoord1d(1.0/1024.0);
		glVertex2f(left,bottom);
		glVertex2f(right,bottom);
		glTexCoord1d(1.0);
		glVertex2f(right,top);
		glVertex2f(left,top);
		/*
Kirill Terekhov's avatar
Kirill Terekhov committed
904
905
906
907
908
909
910
911
912
		for(int i = 0; i < ticks.size()-1; ++i)
		{
			colors[i].set_color();
			glVertex2f(left,bottom+ticks[i]*(top-bottom));
			glVertex2f(right,bottom+ticks[i]*(top-bottom));
			colors[i+1].set_color();
			glVertex2f(right,bottom+ticks[(i+1)]*(top-bottom));
			glVertex2f(left,bottom+ticks[(i+1)]*(top-bottom));
		}
913
		*/
Kirill Terekhov's avatar
Kirill Terekhov committed
914
		glEnd();
915
		UnbindTexture();
916
917

		int tickmarks = 11;
Kirill Terekhov's avatar
Kirill Terekhov committed
918
919
		
		glColor4f(0,0,0,1);
920
		for(int i = 0; i < tickmarks; ++i)
Kirill Terekhov's avatar
Kirill Terekhov committed
921
		{
922
923
924
			float t = 1.0f*i/static_cast<float>(tickmarks-1);
			glRasterPos2f(text_pos,bottom+t*(top-bottom));
			printtext("%g",min+t*(max-min));
Kirill Terekhov's avatar
Kirill Terekhov committed
925
926
927
928
929
930
		}
		if( comment != "")
		{
			glRasterPos2f(left,bottom-0.04);
			printtext("%s",comment.c_str());
		}
931
932
933
934
935
936
937
938
939

		glBegin(GL_LINE_LOOP);
		glVertex2f(left,bottom);
		glVertex2f(right,bottom);
		glVertex2f(right,top);
		glVertex2f(left,top);
		glEnd();

		glBegin(GL_LINES);
940
		for(int i = 0; i < tickmarks; ++i)
941
		{
942
943
			float t = 1.0f*i/static_cast<float>(tickmarks-1);
			float pos = bottom+t*(top-bottom);
944
945
946
947
948
949
950
			glVertex2f(left,pos);
			glVertex2f(left+(right-left)*0.2,pos);

			glVertex2f(right+(left-right)*0.25,pos);
			glVertex2f(right,pos);
		}
		glEnd();
Kirill Terekhov's avatar
Kirill Terekhov committed
951
	}
952
} * CommonColorBar;
Kirill Terekhov's avatar
Kirill Terekhov committed
953

Kirill Terekhov's avatar
Kirill Terekhov committed
954
955
956

class face2gl
{
Kirill Terekhov's avatar
Kirill Terekhov committed
957
	float dist;
Kirill Terekhov's avatar
Kirill Terekhov committed
958
959
960
961
962
963
	double c[4];
	double cnt[3];
	bool flag;
	ElementType etype;
	Storage::integer id;
	std::vector<double> verts;
964
	std::vector<double> texcoords;
Kirill Terekhov's avatar
Kirill Terekhov committed
965
966
	std::vector<color_t> colors;
	color_t cntcolor;
967
	double cnttexcoord;
Kirill Terekhov's avatar
Kirill Terekhov committed
968
public:
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
	static void radix_sort_dist(std::vector<face2gl> & set)
	{
		static std::vector<face2gl> tmp;
		tmp.resize(set.size());
		unsigned int i;
		const unsigned int kHist = 2048;
		unsigned int  b0[kHist * 3];
		unsigned int *b1 = b0 + kHist;
		unsigned int *b2 = b1 + kHist;
		memset(b0,0,sizeof(unsigned int)*kHist*3);
		for (i = 0; i < set.size(); i++) 
		{
			unsigned int fi = flip((unsigned int *)&set[i].dist);
			++b0[_0(fi)]; ++b1[_1(fi)]; ++b2[_2(fi)];
		}
		{
			unsigned int sum0 = 0, sum1 = 0, sum2 = 0;
			for (i = 0; i < kHist; i++) 
			{
				b0[kHist-1] = b0[i] + sum0; b0[i] = sum0 - 1; sum0 = b0[kHist-1];
				b1[kHist-1] = b1[i] + sum1; b1[i] = sum1 - 1; sum1 = b1[kHist-1];
				b2[kHist-1] = b2[i] + sum2; b2[i] = sum2 - 1; sum2 = b2[kHist-1];
			}
		}
		for (i = 0; i < set.size(); i++) tmp[++b0[_0(flip((unsigned int *)&set[i].dist))]] = set[i];
		for (i = 0; i < set.size(); i++) set[++b1[_1(flip((unsigned int *)&tmp[i].dist))]] = tmp[i];
		for (i = 0; i < set.size(); i++) tmp[++b2[_2(flip((unsigned int *)&set[i].dist))]] = set[i];
		for (i = 0; i < set.size(); i++) set[i] = tmp[set.size()-1-i];
	}
998
	face2gl():verts(),colors(),texcoords() {etype = NONE; id = 0; dist = 0; flag = false; memset(c,0,sizeof(double)*4);}
Kirill Terekhov's avatar
Kirill Terekhov committed
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
	face2gl(const face2gl & other) :verts(other.verts) 
	{
		etype = other.etype;
		id = other.id;
		dist = other.dist; 
		cnt[0] = other.cnt[0];
		cnt[1] = other.cnt[1];
		cnt[2] = other.cnt[2];
		c[0] = other.c[0];
		c[1] = other.c[1];
		c[2] = other.c[2];
		c[3] = other.c[3];
		flag = other.flag;
Kirill Terekhov's avatar
Kirill Terekhov committed
1012
		colors = other.colors;
1013
		texcoords = other.texcoords;
Kirill Terekhov's avatar
Kirill Terekhov committed
1014
		cntcolor = other.cntcolor;
1015
		cnttexcoord = other.cnttexcoord;
Kirill Terekhov's avatar
Kirill Terekhov committed
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
	}
	face2gl & operator =(face2gl const & other) 
	{ 
		etype = other.etype;
		id = other.id;
		verts = other.verts; 
		dist = other.dist; 
		cnt[0] = other.cnt[0];
		cnt[1] = other.cnt[1];
		cnt[2] = other.cnt[2];
		c[0] = other.c[0];
		c[1] = other.c[1];
		c[2] = other.c[2];
		c[3] = other.c[3];
		flag = other.flag;
Kirill Terekhov's avatar
Kirill Terekhov committed
1031
1032
		colors = other.colors;
		cntcolor = other.cntcolor;
1033
1034
		texcoords = other.texcoords;
		cnttexcoord = other.cnttexcoord;
Kirill Terekhov's avatar
Kirill Terekhov committed
1035
1036
1037
1038
1039
		return *this;
	}
	~face2gl() {}
	void draw_colour() const
	{
1040
		if( texcoords.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1041
		{
1042
			if( colors.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1043
			{
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
				glColor4dv(c); 
				for(unsigned k = 0; k < verts.size(); k+=3) 
				{
					glVertex3dv(cnt);
					glVertex3dv(&verts[k]);
					glVertex3dv(&verts[(k+3)%verts.size()]);
				}
			}
			else
			{
				for(unsigned k = 0; k < verts.size(); k+=3) 
				{
					cntcolor.set_color();
					glVertex3dv(cnt);
					colors[k/3].set_color();
					glVertex3dv(&verts[k]);
					colors[(k/3+1)%colors.size()].set_color();
					glVertex3dv(&verts[(k+3)%verts.size()]);
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
1063
1064
1065
1066
1067
1068
			}
		}
		else
		{
			for(unsigned k = 0; k < verts.size(); k+=3) 
			{
1069
				glTexCoord1d(cnttexcoord);
Kirill Terekhov's avatar
Kirill Terekhov committed
1070
				glVertex3dv(cnt);
1071
				glTexCoord1d(texcoords[k/3]);
Kirill Terekhov's avatar
Kirill Terekhov committed
1072
				glVertex3dv(&verts[k]);
1073
				glTexCoord1d(texcoords[(k/3+1)%texcoords.size()]);
Kirill Terekhov's avatar
Kirill Terekhov committed
1074
1075
1076
1077
1078
1079
				glVertex3dv(&verts[(k+3)%verts.size()]);
			}
		}
	}
	void draw_colour_alpha(double alpha) const
	{
1080
		if( texcoords.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1081
		{
1082
			if( colors.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1083
			{
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
				//double cc[4] = {c[0],c[1],c[2],alpha};
				glColor4dv(c); 
				for(unsigned k = 0; k < verts.size(); k+=3) 
				{
					glVertex3dv(cnt);
					glVertex3dv(&verts[k]);
					glVertex3dv(&verts[(k+3)%verts.size()]);
				}
			}
			else
			{
				for(unsigned k = 0; k < verts.size(); k+=3) 
				{
					color_t t = cntcolor;
					t.a() = alpha;
					t.set_color();
					glVertex3dv(cnt);
					t = colors[k/3];
					t.a() = alpha;
					t.set_color();
					glVertex3dv(&verts[k]);
					t = colors[(k/3+1)%colors.size()];
					t.a() = alpha;
					t.set_color();
					glVertex3dv(&verts[(k+3)%verts.size()]);
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
1110
1111
1112
1113
1114
1115
			}
		}
		else
		{
			for(unsigned k = 0; k < verts.size(); k+=3) 
			{
1116
				glTexCoord1d(cnttexcoord);
Kirill Terekhov's avatar
Kirill Terekhov committed
1117
				glVertex3dv(cnt);
1118
				glTexCoord1d(texcoords[k/3]);
Kirill Terekhov's avatar
Kirill Terekhov committed
1119
				glVertex3dv(&verts[k]);
1120
				glTexCoord1d(texcoords[(k/3+1)%texcoords.size()]);
Kirill Terekhov's avatar
Kirill Terekhov committed
1121
1122
				glVertex3dv(&verts[(k+3)%verts.size()]);
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
		}
	}
	void draw() const
	{
		for(unsigned k = 0; k < verts.size(); k+=3) 
		{
			glVertex3dv(cnt);
			glVertex3dv(&verts[k]);
			glVertex3dv(&verts[(k+3)%verts.size()]);
		}
	}
	void drawedges() const
	{
		for(unsigned k = 0; k < verts.size(); k+=3) 
		{
			glVertex3dv(&verts[k]); 
			glVertex3dv(&verts[(k+3)%verts.size()]); 
		}
	}
	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;}
Kirill Terekhov's avatar
Kirill Terekhov committed
1144
	void add_vert(double x, double y, double z) {unsigned s = (unsigned)verts.size(); verts.resize(s+3); verts[s] = x; verts[s+1] = y; verts[s+2] = z;}
Kirill Terekhov's avatar
Kirill Terekhov committed
1145
	void add_vert(double v[3]) {verts.insert(verts.end(),v,v+3);}
Kirill Terekhov's avatar
Kirill Terekhov committed
1146
	void add_color(color_t c) {colors.push_back(c);}
1147
	void add_texcoord(double val) {texcoords.push_back(val);}
Kirill Terekhov's avatar
Kirill Terekhov committed
1148
	double * get_vert(int k) {return &verts[k*3];}
Kirill Terekhov's avatar
Kirill Terekhov committed
1149
	unsigned size() {return (unsigned)verts.size()/3;}
Kirill Terekhov's avatar
Kirill Terekhov committed
1150
	void set_center(double _cnt[3], color_t c = color_t(0,0,0,0))
Kirill Terekhov's avatar
Kirill Terekhov committed
1151
1152
1153
1154
	{
		cnt[0] = _cnt[0];
		cnt[1] = _cnt[1];
		cnt[2] = _cnt[2];
Kirill Terekhov's avatar
Kirill Terekhov committed
1155
		cntcolor = c;
Kirill Terekhov's avatar
Kirill Terekhov committed
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
	}
	void get_center(float _cnt[3])
	{
		_cnt[0] = cnt[0];
		_cnt[1] = cnt[1];
		_cnt[2] = cnt[2];
	}
	void get_center(double _cnt[3])
	{
		_cnt[0] = cnt[0];
		_cnt[1] = cnt[1];
		_cnt[2] = cnt[2];
	}
	double * get_center() {return cnt;}
	void compute_center()
	{
		cnt[0] = cnt[1] = cnt[2] = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
1173
		for(INMOST_DATA_ENUM_TYPE k = 0; k < verts.size(); k+=3)
Kirill Terekhov's avatar
Kirill Terekhov committed
1174
1175
1176
1177
1178
1179
1180
1181
		{
			cnt[0] += verts[k+0];
			cnt[1] += verts[k+1];
			cnt[2] += verts[k+2];
		}
		cnt[0] /= (verts.size()/3)*1.0;
		cnt[1] /= (verts.size()/3)*1.0;
		cnt[2] /= (verts.size()/3)*1.0;
Kirill Terekhov's avatar
Kirill Terekhov committed
1182
		compute_center_color();
1183
		compute_center_texcoord();
Kirill Terekhov's avatar
Kirill Terekhov committed
1184
1185
1186
	}
	void compute_center_color()
	{
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
		if( !colors.empty() )
		{
			cntcolor.r() = 0;
			cntcolor.g() = 0;
			cntcolor.b() = 0;
			cntcolor.a() = 0;
			for(INMOST_DATA_ENUM_TYPE k = 0; k < colors.size(); k++)
				cntcolor = cntcolor + colors[k];
			cntcolor =  cntcolor*(1.0f/static_cast<float>(colors.size()));
		}
	}
	void compute_center_texcoord()
	{
		if( !texcoords.empty() )
		{
			cnttexcoord = 0.0;
			for(INMOST_DATA_ENUM_TYPE k = 0; k < texcoords.size(); k++)
				cnttexcoord += texcoords[k];
			cnttexcoord /= static_cast<double>(texcoords.size());
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1207
1208
1209
1210
1211
1212
1213
1214
	}
	void compute_dist(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]));
	}
	void set_flag(bool set) { flag = set;}
	bool get_flag() {return flag;}
	void set_elem(ElementType _etype, Storage::integer _id) {etype = _etype; id = _id;}
Kirill Terekhov's avatar
Kirill Terekhov committed
1215
	Element get_elem(Mesh * m) {return m->ElementByLocalID(etype,id);}
Kirill Terekhov's avatar
Kirill Terekhov committed
1216
};
Kirill Terekhov's avatar
Kirill Terekhov committed
1217
face2gl DrawFace(Element f);
Kirill Terekhov's avatar
Kirill Terekhov committed
1218
1219

std::vector<face2gl> all_boundary;
Kirill Terekhov's avatar
Kirill Terekhov committed
1220
std::vector<face2gl> added_faces;
Kirill Terekhov's avatar
Kirill Terekhov committed
1221
1222
std::vector<face2gl> clip_boundary;

Kirill Terekhov's avatar
Kirill Terekhov committed
1223
1224
void draw_faces_nc(std::vector<face2gl> & set, int highlight = -1)
{
1225
  if( drawedges == 2 || drawedges == 3 ) return;
Kirill Terekhov's avatar
Kirill Terekhov committed
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
	glColor4f(0,1,0,0.1);
	glBegin(GL_TRIANGLES);
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) set[q].draw();
	glEnd();
	if( highlight != -1 )
	{
		glColor4f(1,0,0,1);
		glBegin(GL_TRIANGLES);
		set[highlight].draw();
		glEnd();
	}
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1239
1240
void draw_faces(std::vector<face2gl> & set, int highlight = -1)
{
1241
	if( drawedges == 2 || drawedges == 3) return;
1242
	if( visualization_tag.isValid() ) CommonColorBar->BindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1243
	glBegin(GL_TRIANGLES);
Kirill Terekhov's avatar
Kirill Terekhov committed
1244
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) set[q].draw_colour();
Kirill Terekhov's avatar
Kirill Terekhov committed
1245
	glEnd();
1246
	if( visualization_tag.isValid() ) CommonColorBar->UnbindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1247
1248
1249
1250
1251
1252
1253
1254
1255
	if( highlight != -1 )
	{
		glColor4f(1,0,0,1);
		glBegin(GL_TRIANGLES);
		set[highlight].draw();
		glEnd();
	}
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1256
1257
void draw_faces_alpha(std::vector<face2gl> & set, double alpha)
{
1258
	if( drawedges == 2 || drawedges==3) return;
1259
	if( visualization_tag.isValid() ) CommonColorBar->BindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1260
1261
1262
	glBegin(GL_TRIANGLES);
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) set[q].draw_colour_alpha(alpha);
	glEnd();
1263
	if( visualization_tag.isValid() ) CommonColorBar->UnbindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1264
1265
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1266
1267
void draw_edges(std::vector<face2gl> & set, int highlight = -1)
{
Kirill Terekhov's avatar
Kirill Terekhov committed
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
  if( drawedges && drawedges != 2 )
  {
	  glBegin(GL_LINES);
	  for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) set[q].drawedges();
	  glEnd();
	  if( highlight != -1 )
	  {
		  glColor4f(0,1,0,1);
		  glBegin(GL_LINES);
		  set[highlight].drawedges();
		  glEnd();
	  }
  }
Kirill Terekhov's avatar
Kirill Terekhov committed
1281
1282
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1283
1284
void draw_faces_interactive_nc(std::vector<face2gl> & set)
{
1285
  if( drawedges == 2 || drawedges==3 ) return;
Kirill Terekhov's avatar
Kirill Terekhov committed
1286
1287
1288
1289
1290
1291
	glColor4f(0,1,0,0.1);
	glBegin(GL_TRIANGLES);
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) if( set[q].get_flag() ) set[q].draw();
	glEnd();
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1292
1293
void draw_faces_interactive(std::vector<face2gl> & set)
{
1294
  if( drawedges == 2 || drawedges==3 ) return;
1295
  if( visualization_tag.isValid() ) CommonColorBar->BindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1296
	glBegin(GL_TRIANGLES);
Kirill Terekhov's avatar
Kirill Terekhov committed
1297
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) if( set[q].get_flag() ) set[q].draw_colour();
Kirill Terekhov's avatar
Kirill Terekhov committed
1298
	glEnd();
1299
	if( visualization_tag.isValid() ) CommonColorBar->UnbindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1300
1301
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1302
1303
void draw_faces_interactive_alpha(std::vector<face2gl> & set, double alpha)
{
1304
  if( drawedges == 2 || drawedges==3 ) return;
1305
  if( visualization_tag.isValid() ) CommonColorBar->BindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1306
1307
1308
	glBegin(GL_TRIANGLES);
	for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) if( set[q].get_flag() ) set[q].draw_colour_alpha(alpha);
	glEnd();
1309
	if( visualization_tag.isValid() ) CommonColorBar->UnbindTexture();
Kirill Terekhov's avatar
Kirill Terekhov committed
1310
1311
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1312
1313
void draw_edges_interactive(std::vector<face2gl> & set)
{
Kirill Terekhov's avatar
Kirill Terekhov committed
1314
1315
1316
1317
1318
1319
  if( drawedges && drawedges != 2 )
  {
	  glBegin(GL_LINES);
	  for(INMOST_DATA_ENUM_TYPE q = 0; q < set.size() ; q++) if( set[q].get_flag() ) set[q].drawedges();
	  glEnd();
  }
Kirill Terekhov's avatar
Kirill Terekhov committed
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
}

Storage::integer clip_plane_edge(double sp0[3], double sp1[3], double p[3], double n[3], double node[3])
{
	Storage::real u[3], w[3], D, N, sI;
	u[0] = sp1[0] - sp0[0]; u[1] = sp1[1] - sp0[1]; u[2] = sp1[2] - sp0[2];
	w[0] = sp0[0] - p[0];   w[1] = sp0[1] - p[1];   w[2] = sp0[2] - p[2];
	D =  (n[0]*u[0] + n[1]*u[1] + n[2]*u[2]);
	N = -(n[0]*w[0] + n[1]*w[1] + n[2]*w[2]);
	if( fabs(D) < 1.0e-9 )
	{
		if( fabs(N) < 1.0e-9 ) return CLIP_FULL;
		else return CLIP_NONE;
	}
	else
	{
		sI = N/D;
		if( sI < 0-1.0e-9 || sI > 1+1.0e-9 ) return CLIP_NONE;
		else
		{
			node[0] = sp0[0] + sI * u[0];
			node[1] = sp0[1] + sI * u[1];
			node[2] = sp0[2] + sI * u[2];
			return (sI > 1.0e-9 && sI < 1.0-1.0e-9) ? CLIP_NODE : CLIP_ENDP;
		}
	}
}

Kirill Terekhov's avatar
Kirill Terekhov committed
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
typedef struct point
{
	float coords[3];
	float diam;
	float dist;
	int id;
	/*
	point & operator = (point const & b)
	{
		coords[0] = b.coords[0];
		coords[1] = b.coords[1];
		coords[2] = b.coords[2];
		diam = b.diam;
		dist = b.dist;
		id = b.id;
	}

	point(const point & b)
	{
		coords[0] = b.coords[0];
		coords[1] = b.coords[1];
		coords[2] = b.coords[2];
		diam = b.diam;
		dist = b.dist;
		id = b.id;
	}
	*/
} point_t;

bool operator <(point_t & a, point_t & b) {return a.dist < b.dist;}




class volumetric
{
	std::vector<point_t> points;
	Mesh * m;

	void radix_sort_dist(std::vector<point_t> & set)
	{
		static std::vector<point_t> tmp;
		tmp.resize(set.size());
		unsigned int i;
		const unsigned int kHist = 2048;
		unsigned int  b0[kHist * 3];
		unsigned int *b1 = b0 + kHist;
		unsigned int *b2 = b1 + kHist;
		memset(b0,0,sizeof(unsigned int)*kHist*3);
		for (i = 0; i < set.size(); i++) 
		{
			unsigned int fi = flip((unsigned int *)&set[i].dist);
			++b0[_0(fi)]; ++b1[_1(fi)]; ++b2[_2(fi)];
		}
		{
			unsigned int sum0 = 0, sum1 = 0, sum2 = 0;
			for (i = 0; i < kHist; i++) 
			{
				b0[kHist-1] = b0[i] + sum0; b0[i] = sum0 - 1; sum0 = b0[kHist-1];
				b1[kHist-1] = b1[i] + sum1; b1[i] = sum1 - 1; sum1 = b1[kHist-1];
				b2[kHist-1] = b2[i] + sum2; b2[i] = sum2 - 1; sum2 = b2[kHist-1];
			}
		}
		for (i = 0; i < set.size(); i++) tmp[++b0[_0(flip((unsigned int *)&set[i].dist))]] = set[i];
		for (i = 0; i < set.size(); i++) set[++b1[_1(flip((unsigned int *)&tmp[i].dist))]] = tmp[i];
		for (i = 0; i < set.size(); i++) tmp[++b2[_2(flip((unsigned int *)&set[i].dist))]] = set[i];
		for (i = 0; i < set.size(); i++) set[i] = tmp[set.size()-1-i];
	}
public:
	
	volumetric(Mesh * _m)
	{
		m = _m;
		
		points.resize(m->NumberOfCells());
		int q = 0;
		for(Mesh::iteratorCell it = m->BeginCell(); it != m->EndCell(); ++it)
		{
			Storage::real cnt[3], cntf[3];
			it->Centroid(cnt);
			points[q].coords[0] = cnt[0];
			points[q].coords[1] = cnt[1];
			points[q].coords[2] = cnt[2];
			points[q].id = it->LocalID();
			points[q].diam = 0.f;
			ElementArray<Face> faces = it->getFaces();
			for(ElementArray<Face>::iterator f = faces.begin(); f != faces.end(); ++f)
			{
				f->Centroid(cntf);
				Storage::real d = sqrt((cnt[0]-cntf[0])*(cnt[0]-cntf[0])+(cnt[1]-cntf[1])*(cnt[1]-cntf[1])+(cnt[2]-cntf[2])*(cnt[2]-cntf[2]));
				if( points[q].diam < d ) points[q].diam = d;
			}
			++q;
		}
		/*
		points.reserve(m->NumberOfNodes()*20);
		int q = 0;
		for(Mesh::iteratorNode it = m->BeginNode(); it != m->EndNode(); ++it)
		{
			point_t pnt;
			Storage::real_array cnt = it->Coords();
			pnt.coords[0] = cnt[0];
			pnt.coords[1] = cnt[1];
			pnt.coords[2] = cnt[2];
			pnt.id = it->LocalID();
			points.push_back(pnt);
			
			ElementArray<Element> adj = it->getAdjElements(CELL);
			for(ElementArray<Element>::iterator jt = adj.begin(); jt != adj.end(); ++jt)
			{
				Storage::real cnt2[3];
				jt->Centroid(cnt2);
				const int ncoefs = 1;
				const Storage::real coefs[ncoefs] = {0.82};
				for(int j = 0; j < ncoefs; ++j)
				{
					pnt.coords[0] = cnt[0]*(1-coefs[j]) + cnt2[0]*coefs[j];
					pnt.coords[1] = cnt[1]*(1-coefs[j]) + cnt2[1]*coefs[j];
					pnt.coords[2] = cnt[2]*(1-coefs[j]) + cnt2[2]*coefs[j];
					pnt.id = it->LocalID();
					points.push_back(pnt);
				}
			}
			
		}
		*/
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
1474
		printf("number of points %d\n",(int)points.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
	}
	void camera(double pos[3], int interactive)
	{
		if( interactive ) return;
		float posf[3];
		posf[0] = pos[0];
		posf[1] = pos[1];
		posf[2] = pos[2];
		for(int k = 0; k < points.size(); ++k)
		{
			points[k].dist = sqrtf(
				(posf[0]-points[k].coords[0])*(posf[0]-points[k].coords[0])+
				(posf[1]-points[k].coords[1])*(posf[1]-points[k].coords[1])+
				(posf[2]-points[k].coords[2])*(posf[2]-points[k].coords[2]));
		}
		double t = Timer();
		radix_sort_dist(points);
		//std::sort(points.rbegin(),points.rend());
		printf("Time to sort %lf\n",Timer()-t);
	}
	void draw(int interactive)
	{
		double origin[3], right[3], up[3];
		GLdouble modelview[16],projection[16];
		GLint viewport[4] = {0,0,1,1};
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
		glGetDoublev(GL_PROJECTION_MATRIX, projection);
		GLdouble outx, outy, outz;  // Var's to save the answer in
		gluUnProject(0.5, 0.5, 0.,
               modelview, projection, viewport,
               &outx, &outy, &outz);
		origin[0] = outx;
		origin[1] = outy;
		origin[2] = outz;
		gluUnProject(1.0, 0.5, 0.,
               modelview, projection, viewport,
               &outx, &outy, &outz);
		right[0] = outx;
		right[1] = outy;
		right[2] = outz;
		gluUnProject(0.5, 1.0, 0.,
               modelview, projection, viewport,
               &outx, &outy, &outz);
		up[0] = outx;
		up[1] = outy;
		up[2] = outz;
		right[0] -= origin[0];
		right[1] -= origin[1];
		right[2] -= origin[2];
		up[0] -= origin[0];
		up[1] -= origin[1];
		up[2] -= origin[2];
Kirill Terekhov's avatar
Kirill Terekhov committed
1527
    
Kirill Terekhov's avatar
Kirill Terekhov committed
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
		double l = sqrt(right[0]*right[0]+right[1]*right[1]+right[2]*right[2]);
		if( l )
		{
			right[0] /= l;
			right[1] /= l;
			right[2] /= l;
		}
		l = sqrt(up[0]*up[0]+up[1]*up[1]+up[2]*up[2]);
		if( l )
		{
			up[0] /= l;
			up[1] /= l;
			up[2] /= l;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1542
    
Kirill Terekhov's avatar
Kirill Terekhov committed
1543
		const float alpha = 0.0075f;
Kirill Terekhov's avatar
Kirill Terekhov committed
1544
		const float mult = 1.0f;
Kirill Terekhov's avatar
Kirill Terekhov committed
1545
1546
1547
1548
1549
1550
1551
1552
		const float rmult = 0.7f;
		//glPointSize(5.0);
		glColor4f(0.5f,0.5f,0.5f,alpha);
		glEnable(GL_BLEND);
		//glBegin(GL_TRIANGLES);
		//glBegin(GL_QUADS);
		if( interactive )
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
1553
      for(int k = 0; k < points.size(); ++k) if( k % 100 == 0 )
Kirill Terekhov's avatar
Kirill Terekhov committed
1554
1555
1556
			{
				if( visualization_tag.isValid() )
				{
1557
					color_t c = CommonColorBar->pick_color(m->CellByLocalID(points[k].id)->RealDF(visualization_tag));
Kirill Terekhov's avatar
Kirill Terekhov committed
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
					c.a() = alpha;
					c.set_color();
				}
				
				glBegin(GL_TRIANGLE_FAN);
				glVertex3f(points[k].coords[0],points[k].coords[1],points[k].coords[2]);
				glVertex3f(points[k].coords[0]+(right[0]*rmult+up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]*rmult+up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]*rmult+up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(right[0]*rmult*2)*points[k].diam*mult,points[k].coords[1]+(right[1]*rmult*2)*points[k].diam*mult,points[k].coords[2]+(right[2]*rmult*2)*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(right[0]*rmult-up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]*rmult-up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]*rmult-up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]*rmult-up[0])*points[k].diam*mult,points[k].coords[1]+(-right[1]*rmult-up[1])*points[k].diam*mult,points[k].coords[2]+(-right[2]*rmult-up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]*rmult*2)*points[k].diam*mult,points[k].coords[1]+(-right[1]*rmult*2)*points[k].diam*mult,points[k].coords[2]+(-right[2]*rmult*2)*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]*rmult+up[0])*points[k].diam*mult,points[k].coords[1]+(-right[1]*rmult+up[1])*points[k].diam*mult,points[k].coords[2]+(-right[2]*rmult+up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(right[0]*rmult+up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]*rmult+up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]*rmult+up[2])*points[k].diam*mult);
				glEnd();
				
				/*
				glVertex3f(points[k].coords[0]+(right[0]+up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]+up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]+up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-up[0]*2)*points[k].diam*mult,points[k].coords[1]+(-up[1]*2)*points[k].diam*mult,points[k].coords[2]+(-up[2]*2)*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]+up[0])*points[k].diam*mult,points[k].coords[1]+(-right[1]+up[1])*points[k].diam*mult,points[k].coords[2]+(-right[2]+up[2])*points[k].diam*mult);
				*/
				/*
				glVertex3f(points[k].coords[0]+(right[0]+up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]+up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]+up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(right[0]-up[0])*points[k].diam*mult,points[k].coords[1]+(right[1]-up[1])*points[k].diam*mult,points[k].coords[2]+(right[2]-up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]-up[0])*points[k].diam*mult,points[k].coords[1]+(-right[1]-up[1])*points[k].diam*mult,points[k].coords[2]+(-right[2]-up[2])*points[k].diam*mult);
				glVertex3f(points[k].coords[0]+(-right[0]+up[0])*points[k].diam*mult,points[k].coords[1]+(-right[1]+up[1])*points[k].diam*mult,points[k].coords[2]+(-right[2]+up[2])*points[k].diam*mult);
				*/
				//glVertex3f(points[k].coords[0]+right[0]*points[k].diam*mult,points[k].coords[1]+right[1]*points[k].diam*mult,points[k].coords[2]+right[2]*points[k].diam*mult);
				//glVertex3f(points[k].coords[0]+up[0]*points[k].diam*mult,points[k].coords[1]+up[1]*points[k].diam*mult,points[k].coords[2]+up[2]*points[k].diam*mult);
				//glVertex3f(points[k].coords[0]-right[0]*points[k].diam*mult,points[k].coords[1]-right[1]*points[k].diam*mult,points[k].coords[2]-right[2]*points[k].diam*mult);
				//glVertex3f(points[k].coords[0]-up[0]*points[k].diam*mult,points[k].coords[1]-up[1]*points[k].diam*mult,points[k].coords[2]-up[2]*points[k].diam*mult);
			}
		}
		else
		for(int k = 0; k < points.size(); ++k)
		{
			if( visualization_tag.isValid() )
			{
1595
				color_t c = CommonColorBar->pick_color(m->CellByLocalID(points[k].id)->RealDF(visualization_tag));
Kirill Terekhov's avatar
Kirill Terekhov committed
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613