1 //#**************************************************************
2 //#
3 //# filename:             ti_misc.cpp
4 //#
5 //# author:               Gerstmayr Johannes
6 //#
7 //# generated:						10.03.2004
8 //# description:          Auxiliary Functions for timeint (mainly for graphics)
9 //# remarks:						  belongs to header file timeint.h
10 //#
11 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
12 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
13 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
14 //#
15 //# This file is part of HotInt.
16 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
17 //# the HOTINT license. See folder 'licenses' for more details.
18 //#
19 //# bug reports are welcome!!!
20 //# WWW:		www.hotint.org
21 //# email:	bug_reports@hotint.org or support@hotint.org
22 //#***************************************************************************************
23 
24 #include "../WorkingModule/stdafx.h"
25 #include "ioincludes.h"
26 
27 #include <assert.h>
28 #include <string.h>
29 #include <time.h>
30 #include <sys/timeb.h>
31 #include <math.h>
32 
33 #include "mbs_interface.h"
34 #include "rendercontext.h"
35 #include "timeint.h"
36 
37 extern UserOutputInterface * global_uo;
38 
39 //#include "../WorkingModule/stdafx.h"
40 //#include <gl/gl.h>
41 //#include <gl/glu.h>
42 
43 
44 int useFEcolortex = 1;
45 
46 
SetTexStoreResolution(int n)47 void TimeInt::SetTexStoreResolution(int n)
48 {
49 
50 	int fact = 2*(int)pow(2.,n);
51 
52 	if (fact > GetTexStoreMaxResolution()) fact = GetTexStoreMaxResolution();
53 
54 	texstorenn = fact;
55 	//uo << "settexstoreres=" << texstorenn << "\n";
56 
57 	if (texImage != NULL) delete[] texImage;
58 	texImage = new char[4*fact*fact*4]; //safety factor 4, to ensure that there are no problems ...
59 }
60 
61 
62 
SetColor(const Vector3D & col)63 void TimeInt::SetColor(const Vector3D& col)
64 {
65 	pCurrentRC->glColor4f((float)col[0],(float)col[1],(float)col[2], 1.f - (1.f-(float)GetDOption(206))*(float)transparency_on);
66 	//pCurrentRC->ChooseColor((float)col[0],(float)col[1],(float)col[2]);
67 	actcolor = col;
68 }
69 
ChooseColor(float R,float G,float B) const70 void TimeInt::ChooseColor(float R, float G, float B) const
71 {
72 	pCurrentRC->glColor4f(R, G, B, 1.f - (1.f-(float)GetDOption(206))*(float)transparency_on);
73 	//pCurrentRC->ChooseColor(R, G, B);
74 }
75 
SetFEColor(double val) const76 void TimeInt::SetFEColor(double val) const
77 {
78 	if (useFEcolortex)
79 	{
80 		if (GetIOption(108) && val >= 0 && val <= 1.) //logarithmic
81 		{
82 			//val = 1.-pow(1.-val,10.);
83 			val = pow(val,0.2);
84 		}
85 
86 		/*if (GetIOption(116))  //chladni, 0==black
87 		{
88 			if (val < 1e-4) val = 0;
89 			else val = 1;
90 		}*/
91 
92 		if (GetIOption(107)) //invert color
93 		{
94 			val = 1.-val;
95 		}
96 
97 		/*
98 		double niso = GetIOption(103);
99 		if (niso <= 32) //niso>32 == no tiling
100 		{
101 			val = ((int)(niso*val)); //for isolines ...
102 			val = val/niso+1e-12;
103 		}*/
104 
105 	  //call before drawing of object: glEnable(GL_TEXTURE_1D); afterwards glDisable(GL_TEXTURE_1D)!!!
106 		//if (val <= 0) global_uo << "cval=" << val << "\n";
107 		//if (val >= 1) global_uo << "cval=" << val << "\n";
108 
109 		float fval = (float)(0.99*val + 0.005);
110 		if (val < -1e-8) fval = 0;
111 		else if (val > 1.00000001) fval = 1;
112 
113 	  pCurrentRC->glTexCoord1f (fval); //values outside are no problem??
114 	}
115 	else
116 	{
117 		Vector3D c = FEColor(val);
118 		ChooseColor((float)c.X(), (float)c.Y(), (float)c.Z());
119 	}
120 }
121 
122 
123 int lastgreyoption=0;
FEColor(double val) const124 Vector3D TimeInt::FEColor(double val) const
125 {
126 	if (GetIOption(108) && val >= 0 && val <= 1.)
127 	{
128 		//val = 1.-pow(1.-val,10.);
129 		val = pow(val,0.2);
130 	}
131 
132 	/*if (GetIOption(116))  //chladni
133 	{
134 		if (val < 1e-4) val = 0;
135 		else val = 1;
136 	}*/
137 
138 	if (GetIOption(107))
139 	{
140 		val = 1.-val;
141 	}
142 
143 	static Vector3D col1(0.25,0.25,0.25);
144 	static Vector3D col2(0.1,0.1,0.9);
145 	static Vector3D col3(0.1,0.9,0.9);
146 	static Vector3D col4(0.1,0.9,0.1);
147 	static Vector3D col5(0.9,0.9,0.1);
148 	static Vector3D col6(0.9,0.1,0.1);
149 	static Vector3D col7(0.7,0.7,0.7);
150 	static Vector3D col8(0.1,0.1,0.1);
151 
152 	if (GetIOption(105)) //greymode
153 	{
154 		col1=Vector3D(0,0,0);
155 		col2=Vector3D(0.1,0.1,0.1);
156 		col3=Vector3D(0.3,0.3,0.3);
157 		col4=Vector3D(0.5,0.5,0.5);
158 		col5=Vector3D(0.7,0.7,0.7);
159 		col6=Vector3D(0.9,0.9,0.9);
160 		col7=Vector3D(1,0.9,0.9);
161 		/*if (GetIOption(116))  //chladni
162 		{
163 			col6=Vector3D(1,1,1);
164 			col7=Vector3D(1,1,1);
165 		}*/
166 		lastgreyoption = 1;
167 	}
168 	else if (lastgreyoption)
169 	{
170 		col1=Vector3D(0.25,0.25,0.25);
171 		col2=Vector3D(0.1,0.1,0.9);
172 		col3=Vector3D(0.1,0.9,0.9);
173 		col4=Vector3D(0.1,0.9,0.1);
174 		col5=Vector3D(0.9,0.9,0.1);
175 		col6=Vector3D(0.9,0.1,0.1);
176 		col7=Vector3D(0.7,0.7,0.7);
177 	}
178 
179 
180 	double niso = GetIOption(103);
181 	val = ((int)(niso*val)); //for isolines ...
182 	val = val/niso+1e-12;
183 
184 
185 	double fact = 0.25;
186 	if (val < -1e-10) return col1;
187 	if (val < fact)
188 	{
189     return val/fact*col3+(1.-val/fact)*col2;
190 	}
191 	val -=fact;
192 	if (val < fact)
193 	{
194     return val/fact*col4+(1.-val/fact)*col3;
195 	}
196 	val -=fact;
197 	if (val < fact)
198 	{
199     return val/fact*col5+(1.-val/fact)*col4;
200 	}
201 	val -=fact;
202 	if (val < fact*1.0000000001)
203 	{
204     return val/fact*col6+(1.-val/fact)*col5;
205 	}
206 
207   return col7;
208 }
209 
210 
UpdateFEMinMaxCol(double val)211 void TimeInt::UpdateFEMinMaxCol(double val)
212 {
213 	if (!GetIOption(101))
214 	{
215 		 TImincol = Minimum(TImincol,val);
216 	}
217 	else
218 		TImincol = GetDOption(101);
219 	if (!GetIOption(100))
220 	{
221 		TImaxcol = Maximum(TImaxcol,val);
222 	}
223 	else
224 		TImaxcol = GetDOption(100);
225 }
226 
227 
DrawLegend(double yoff) const228 void TimeInt::DrawLegend(double yoff) const
229 {
230 	int w,h;
231 	pCurrentRC->GetWindowSize(w,h);
232 
233 	double h2 = GetIOption(103);
234 
235 	double sy = (32.*h2)/(double)h;//(double)h*2.;//0.4*768./(double)h;
236 	double pix_yoff = (8.+16+32*h2+32.*yoff)/(double)h;
237 	double offx =-1.+16./(double)w;
238 	double offy = 1.-pix_yoff; //y-range is -1 (bottom) ... +1 (top)
239 	double sx = 64./(double)w;
240 	double tile = h2;
241 	double dsy = sy / tile;
242 	double val, cv1, cv2;
243 
244 	pCurrentRC->glPushMatrices();
245 	ChooseColor(1,0,0);
246 
247 	for (double i=0; i<1-1e-6; i+=1./tile)
248 	{
249 		Vector3D p1(offx,   offy+i*sy,0);
250 		Vector3D p2(offx+sx,offy+i*sy,0);
251 		Vector3D p3(offx+sx,offy+dsy+i*sy,0);
252 		Vector3D p4(offx,   offy+dsy+i*sy,0);
253 
254 		pCurrentRC->glBeginTexture1D(0); //color texture
255 		pCurrentRC->glBeginQuads();
256 		Vector3D n;
257 		Normal3D(p4,p2,p1,n);
258 
259 		val = i;
260 		if (GetIOption(108) && val >= 0 && val <= 1.)
261 		{
262 			val = pow(val,5); //for nonlinear color scale
263 		}
264 		Vector3D c1 = FEColor(val);
265 		cv1 = val;
266 		val = i+1./tile;
267 
268 		if (GetIOption(108) && val >= 0 && val <= 1.)
269 		{
270 			val = pow(val,5); //for nonlinear color scale
271 		}
272 		Vector3D c2 = FEColor(val);
273 		cv2 = val;
274 		//cv1 = (cv1+cv2)*0.5;
275 		//cv2 = cv1;
276 
277 
278 		SetFEColor(cv2);
279 		//pCurrentRC->glColor3f((float)c2[0],(float)c2[1],(float)c2[2]);
280 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
281 		SetFEColor(cv2);
282 		//pCurrentRC->glColor3f((float)c2[0],(float)c2[1],(float)c2[2]);
283 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
284 		SetFEColor(cv1);
285 		//pCurrentRC->glColor3f((float)c1[0],(float)c1[1],(float)c1[2]);
286 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
287 		SetFEColor(cv1);
288 		//pCurrentRC->glColor3f((float)c1[0],(float)c1[1],(float)c1[2]);
289 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
290 
291 		pCurrentRC->glEnd();
292 		pCurrentRC->glEndTexture1D(); //color
293 
294 		ChooseColor(0.2f,0.2f,0.2f);
295 		pCurrentRC->ChooseLineThickness(3);
296 		pCurrentRC->glBeginLines();
297 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
298 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
299 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
300 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
301 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
302 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
303 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
304 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
305 		pCurrentRC->glEnd();
306 
307 	}
308 	Vector3D p1(offx,   offy,0);
309 	Vector3D p2(offx+sx,offy,0);
310 	Vector3D p3(offx+sx,offy+sy,0);
311 	Vector3D p4(offx,   offy+sy,0);
312 
313 	ChooseColor(0.2f,0.2f,0.2f);
314 	pCurrentRC->ChooseLineThickness(3);
315 	pCurrentRC->glBeginLines();
316 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
317 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
318 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
319 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
320 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
321 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
322 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
323 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
324 	pCurrentRC->glEnd();
325 	pCurrentRC->ChooseLineThickness(1);
326 
327 	pCurrentRC->glPopMatrices();
328 }
329 
330 //interpolate values at quad with local coords 0..1
QuadInt(double x,double y,double v1,double v2,double v3,double v4)331 double QuadInt(double x, double y, double v1, double v2, double v3, double v4)
332 {
333 	//order of nodes:
334 	//
335 	//  node 4 +------+ node 3    y
336 	//         |      |           ^
337 	//         |      |           |
338 	//         |      |           ---> x
339 	//  node 1 +------+ node 2
340 	//
341 	return (1.-y)*(1.-x)*v1+(1.-y)*(x)*v2+(y)*(x)*v3+(y)*(1.-x)*v4;
342 }
343 
344 //interpolate values at quad with local coords 0..1
QuadInt(double x,double y,const Vector3D & v1,const Vector3D & v2,const Vector3D & v3,const Vector3D & v4)345 Vector3D QuadInt(double x, double y, const Vector3D& v1, const Vector3D& v2, const Vector3D& v3, const Vector3D& v4)
346 {
347 	//order of nodes:
348 	//
349 	//  node 4 +------+ node 3    y
350 	//         |      |           ^
351 	//         |      |           |
352 	//         |      |           ---> x
353 	//  node 1 +------+ node 2
354 	//
355 	return ((1.-y)*(1.-x))*v1+((1.-y)*x)*v2+(y*x)*v3+(y*(1.-x))*v4;
356 }
357 
358 
GetTexStoreMaxResolution()359 int TimeInt::GetTexStoreMaxResolution()
360 {
361 	return 128;
362 };
363 
364 
DrawIsoQuadTex(Vector3D * p,const Vector3D & n,double * v,int res,char * teximage)365 void TimeInt::DrawIsoQuadTex(Vector3D* p, const Vector3D& n, double* v, int res, char* teximage)
366 {
367 	if (res != texstorenn) return; //GetTexStoreResolution()
368 
369 	//currently only for ISO-Chladni figures
370 	Vector3D c;
371 
372 	double nn = texstorenn;
373 
374 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
375 
376 	pCurrentRC->glInitializeTexture(&texName, texImage, texstorenn, texstorenn);
377 
378 	pCurrentRC->glBeginTexture(texName);
379 	pCurrentRC->glBeginQuads();
380 
381 	const float eps = 0.5f/(float)nn;
382 	float size = (1.f - eps);
383 
384 
385 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
386 	pCurrentRC->glTexCoord2f(eps,eps);
387 	pCurrentRC->glVertex((float)p[3].X(),(float)p[3].Y(),(float)p[3].Z());
388 
389 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
390 	pCurrentRC->glTexCoord2f(eps,size);
391 	pCurrentRC->glVertex((float)p[2].X(),(float)p[2].Y(),(float)p[2].Z());
392 
393 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
394 	pCurrentRC->glTexCoord2f(size,size);
395 	pCurrentRC->glVertex((float)p[1].X(),(float)p[1].Y(),(float)p[1].Z());
396 
397 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
398 	pCurrentRC->glTexCoord2f(size,eps);
399 	pCurrentRC->glVertex((float)p[0].X(),(float)p[0].Y(),(float)p[0].Z());
400 
401 	pCurrentRC->glEnd();
402 	pCurrentRC->glEndTexture();
403 }
404 
405 int oldnn = 0;
406 
DrawIsoQuad(Vector3D * p,const Vector3D & n,double * v)407 void TimeInt::DrawIsoQuad(Vector3D* p, const Vector3D& n, double* v)
408 {
409 	if (1) //with textures
410 	{
411 		if (useFEcolortex)
412 		{
413 			pCurrentRC->glBeginTexture1D(0); //color
414 
415 			Vector3D c;
416 			pCurrentRC->glBeginQuads();
417 
418 			SetFEColor(v[3]);
419 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
420 			pCurrentRC->glVertex((float)p[3].X(),(float)p[3].Y(),(float)p[3].Z());
421 
422 			SetFEColor(v[2]);
423 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
424 			pCurrentRC->glVertex((float)p[2].X(),(float)p[2].Y(),(float)p[2].Z());
425 
426 			SetFEColor(v[1]);
427 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
428 			pCurrentRC->glVertex((float)p[1].X(),(float)p[1].Y(),(float)p[1].Z());
429 
430 			SetFEColor(v[0]);
431 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
432 			pCurrentRC->glVertex((float)p[0].X(),(float)p[0].Y(),(float)p[0].Z());
433 
434 			pCurrentRC->glEnd();
435 
436 			pCurrentRC->glEndTexture1D();
437 		}
438 		/*
439 		else if (GetIOption(116)) //chladni ISO-lines around -/+ 0
440 		{
441 			Vector3D c;
442 			//texture:
443 
444 			int rn = texstorenn;
445 			double drn = rn;
446 
447 			oldnn = texstorenn;
448 
449 			double nn = texstorenn;
450 			double intpv;  //interpolate colors
451 
452 			double chladnirad = 0.+GetDOption(100);
453 			int chladnisteps = 16;
454 			double chpx[24], chpy[24];
455 
456 			if (GetIOption(116)) //chladni ISO-lines around -/+ 0
457 			{
458 				//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
459 				//draw chladni figure: iso-line around zero-line
460 				for (int i=0; i < chladnisteps; i++)
461 				{
462 					chpx[i] = chladnirad * sin((double)i/(double)chladnisteps*2.*MY_PI);
463 					chpy[i] = chladnirad * cos((double)i/(double)chladnisteps*2.*MY_PI);
464 				}
465 			}
466 
467 
468 			for (int i=0; i<rn; i++)
469 			{
470 				for (int j=0; j<rn; j++)
471 				{
472 					double gx1 = (double)(i)/drn;
473 					double gy1 = (double)(drn-j-1)/drn;
474 
475 					if (!GetIOption(116)) //chladni ISO-lines around -/+ 0
476 					{
477 						intpv = QuadInt(gx1,gy1,v[0],v[1],v[2],v[3]);
478 						//c = 128.+127.*sin(gx1*gy1);
479 						c = 255.*FEColor(intpv);
480 					}
481 					else
482 					{
483 						//draw chladni figure: iso-line around zero-line, radius=chladnirad
484 						double epss = 1e-8;
485 						double val0 = QuadInt(gx1,gy1,v[0],v[1],v[2],v[3]);
486 						double val;
487 						int flag = Sgn(val0);
488 						c = 255;
489 						int cnt = 0;
490 						for (int k=0; k < chladnisteps; k++)
491 						{
492 							val = QuadInt(gx1+chpx[k],gy1+chpy[k],v[0],v[1],v[2],v[3]);
493 							if (flag != Sgn(val) && (fabs(val-val0) > epss))
494 							{
495 								cnt++;
496 								//if (cnt > chladnisteps/3) {c = 0;break;}
497 							}
498 						}
499 
500 						c = 255*(1.f-64.f*((float)cnt - (int)GetDOption(101))/(float)chladnisteps);
501 						if (c.X() < 0) c=0;
502 						if (c.X() > 255) c=255;
503 
504 					}
505 
506 					texImage[i*texstorenn*4+j*4+0] = (char)c.X();
507 					texImage[i*texstorenn*4+j*4+1] = (char)c.Y();
508 					texImage[i*texstorenn*4+j*4+2] = (char)c.Z();
509 					texImage[i*texstorenn*4+j*4+3] = (char)255;
510 				}
511 			}
512 
513 			pCurrentRC->glInitializeTexture(&texName, texImage, texstorenn, texstorenn);
514 
515 			pCurrentRC->glBeginTexture(texName);
516 			pCurrentRC->glBeginQuads();
517 
518 			const float eps = 0.25f/(float)rn;
519 			float size = (1.f - eps);
520 
521 
522 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
523 			pCurrentRC->glTexCoord2f(eps,eps);
524 			pCurrentRC->glVertex((float)p[3].X(),(float)p[3].Y(),(float)p[3].Z());
525 
526 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
527 			pCurrentRC->glTexCoord2f(eps,size);
528 			pCurrentRC->glVertex((float)p[2].X(),(float)p[2].Y(),(float)p[2].Z());
529 
530 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
531 			pCurrentRC->glTexCoord2f(size,size);
532 			pCurrentRC->glVertex((float)p[1].X(),(float)p[1].Y(),(float)p[1].Z());
533 
534 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
535 			pCurrentRC->glTexCoord2f(size,eps);
536 			pCurrentRC->glVertex((float)p[0].X(),(float)p[0].Y(),(float)p[0].Z());
537 
538 			pCurrentRC->glEnd();
539 			pCurrentRC->glEndTexture();
540 		}*/ //chladni
541 		else
542 		{
543 			Vector3D c;
544 			pCurrentRC->glBeginQuads();
545 
546 			c=FEColor(v[3]);
547 			pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
548 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
549 			pCurrentRC->glVertex((float)p[3].X(),(float)p[3].Y(),(float)p[3].Z());
550 
551 			c=FEColor(v[2]);
552 			pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
553 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
554 			pCurrentRC->glVertex((float)p[2].X(),(float)p[2].Y(),(float)p[2].Z());
555 
556 			c=FEColor(v[1]);
557 			pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
558 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
559 			pCurrentRC->glVertex((float)p[1].X(),(float)p[1].Y(),(float)p[1].Z());
560 
561 			c=FEColor(v[0]);
562 			pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
563 			pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
564 			pCurrentRC->glVertex((float)p[0].X(),(float)p[0].Y(),(float)p[0].Z());
565 
566 			pCurrentRC->glEnd();
567 		}
568 	}
569 	else
570 	{
571 		double nn = 4; //4 is very good
572 		Vector3D pp[4];
573 		double vv[4];
574 
575 		pCurrentRC->glBeginQuads();
576 		for (double i=1; i<=nn; i++)
577 		{
578 			for (double j=1; j<=nn; j++)
579 			{
580 				double gx1 = (i-1)/nn;
581 				double gx2 = (i)*1.001/nn;
582 				double gy1 = (j-1)/nn;
583 				double gy2 = (j)*1.001/nn;
584 
585 				vv[0] = QuadInt(gx1,gy1,v[0],v[1],v[2],v[3]);
586 				vv[1] = QuadInt(gx2,gy1,v[0],v[1],v[2],v[3]);
587 				vv[2] = QuadInt(gx2,gy2,v[0],v[1],v[2],v[3]);
588 				vv[3] = QuadInt(gx1,gy2,v[0],v[1],v[2],v[3]);
589 
590 				pp[0] = QuadInt(gx1,gy1,p[0],p[1],p[2],p[3]);
591 				pp[1] = QuadInt(gx2,gy1,p[0],p[1],p[2],p[3]);
592 				pp[2] = QuadInt(gx2,gy2,p[0],p[1],p[2],p[3]);
593 				pp[3] = QuadInt(gx1,gy2,p[0],p[1],p[2],p[3]);
594 
595 				Vector3D c;
596 				c=FEColor(vv[3]);
597 				pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
598 				pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
599 				pCurrentRC->glVertex((float)pp[3].X(),(float)pp[3].Y(),(float)pp[3].Z());
600 
601 				c=FEColor(vv[2]);
602 				pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
603 				pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
604 				pCurrentRC->glVertex((float)pp[2].X(),(float)pp[2].Y(),(float)pp[2].Z());
605 
606 				c=FEColor(vv[1]);
607 				pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
608 				pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
609 				pCurrentRC->glVertex((float)pp[1].X(),(float)pp[1].Y(),(float)pp[1].Z());
610 
611 				c=FEColor(vv[0]);
612 				pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
613 				pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
614 				pCurrentRC->glVertex((float)pp[0].X(),(float)pp[0].Y(),(float)pp[0].Z());
615 
616 			}
617 		}
618 		pCurrentRC->glEnd();
619 	}
620 }
621 
622 
623 //Draw Quads from list of points arranged in a field of n1 x n2 points, Draw color according to value v
DrawColorQuads(const TArray<Vector3D> & p,const TArray<double> & v,int n1,int n2,int colormode,int drawlines,int vres)624 void TimeInt::DrawColorQuads(const TArray<Vector3D>& p, const TArray<double>& v, int n1, int n2,
625 														 int colormode, int drawlines, int vres)
626 {
627 	//uo << "n1=" << n1 << "\n";
628 	//uo << "n2=" << n2 << "\n";
629 	//uo << "p.Length=" << p.Length() << "\n";
630 
631 	//colormode: 0=no color, 1=FE color
632 	//drawlines: 1=color+field outline, 2=field outline, 3=color+element outline, 4=element outline
633 
634 	//lateron we will store all quads in a list, determine the range and draw it
635 	if (!GetIOption(100))
636 	{
637 		for (int i=1; i<=v.Length(); i++)
638 			TImaxcol = Maximum(TImaxcol,v(i));
639 	}
640 	else
641 		TImaxcol = GetDOption(100);
642 
643 	if (!GetIOption(101))
644 	{
645 		for (int i=1; i<=v.Length(); i++)
646 			TImincol = Minimum(TImincol,v(i));
647 	}
648 	else
649 		TImincol = GetDOption(101);
650 
651 	double diff = TImaxcol-TImincol;
652 
653 	if (TImincol == 1e10) {TImincol=TImaxcol=0;}
654 	if (diff == 0) {diff=1;}
655 
656 	if (IsFlagComputeMinMaxFECol()) return;
657 
658 	Vector3D n;
659 	Vector3D c;
660 	int p1,p2,p3,p4;
661 	double vcol[4];
662 	Vector3D piso[4];
663 
664 	int usenormals = 0;
665 	int noff = 0;
666 	if (p.Length() == 2*n1*n2)
667 	{
668 		//uo << "p.Length=" << p.Length() << ", n1*n2=" << n1*n2 << "\n";
669 		usenormals = 1;
670 		noff = n1*n2;
671 	}
672 
673 	if (drawlines != 2 && drawlines != 4)
674 	{
675 		for (int i1=1; i1 < n1; i1++)
676 		{
677 			for (int i2=1; i2 < n2; i2++)
678 			{
679 				p4=(i2-1)*n1+i1;
680 				p3=(i2-1)*n1+i1+1;
681 				p2=(i2)*n1+i1+1;
682 				p1=(i2)*n1+i1;
683 
684 				//if (!usenormals) Normal3D(p(p4),p(p2),p(p1),n);
685 				if (!usenormals) Normal3D(p(p4),p(p3),p(p2),n);
686 
687 				if (colormode)
688 				{
689 						vcol[0] = (v(p1)-TImincol)/diff;
690 						vcol[1] = (v(p2)-TImincol)/diff;
691 						vcol[2] = (v(p3)-TImincol)/diff;
692 						vcol[3] = (v(p4)-TImincol)/diff;
693 
694 						piso[0] = p(p1);
695 						piso[1] = p(p2);
696 						piso[2] = p(p3);
697 						piso[3] = p(p4);
698 
699 						DrawIsoQuad(piso, n, vcol);
700 					/*
701 					//chladni
702 					if (GetIOption(116))  //chladni
703 					{
704 					if (vres == 1)
705 					{
706 					vcol[0] = v(p1);
707 					vcol[1] = v(p2);
708 					vcol[2] = v(p3);
709 					vcol[3] = v(p4);
710 
711 					piso[0] = p(p1);
712 					piso[1] = p(p2);
713 					piso[2] = p(p3);
714 					piso[3] = p(p4);
715 
716 					DrawIsoQuad(piso, n, vcol);
717 					}
718 					else
719 					{
720 
721 					}
722 					}*/
723 				}
724 				else
725 				{
726 					//uo << "n1=" << p(p4+noff) << "\n";
727 					pCurrentRC->glBeginQuads();
728 
729 					c=FEColor((v(p4)-TImincol)/diff);
730 					if (colormode) pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
731 					if (!usenormals)
732 						pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
733 					else
734 						pCurrentRC->glNormal((float)p(p4+noff).X(),(float)p(p4+noff).Y(),(float)p(p4+noff).Z());
735 					pCurrentRC->glVertex((float)p(p4).X(),(float)p(p4).Y(),(float)p(p4).Z());
736 
737 					c=FEColor((v(p3)-TImincol)/diff);
738 					if (colormode) pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
739 					if (!usenormals)
740 						pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
741 					else
742 						pCurrentRC->glNormal((float)p(p3+noff).X(),(float)p(p3+noff).Y(),(float)p(p3+noff).Z());
743 					pCurrentRC->glVertex((float)p(p3).X(),(float)p(p3).Y(),(float)p(p3).Z());
744 
745 					c=FEColor((v(p2)-TImincol)/diff);
746 					if (colormode) pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
747 					if (!usenormals)
748 						pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
749 					else
750 						pCurrentRC->glNormal((float)p(p2+noff).X(),(float)p(p2+noff).Y(),(float)p(p2+noff).Z());
751 					pCurrentRC->glVertex((float)p(p2).X(),(float)p(p2).Y(),(float)p(p2).Z());
752 
753 					c=FEColor((v(p1)-TImincol)/diff);
754 					if (colormode) pCurrentRC->glColor3f((float)c[0],(float)c[1],(float)c[2]);
755 					if (!usenormals)
756 						pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
757 					else
758 						pCurrentRC->glNormal((float)p(p1+noff).X(),(float)p(p1+noff).Y(),(float)p(p1+noff).Z());
759 					pCurrentRC->glVertex((float)p(p1).X(),(float)p(p1).Y(),(float)p(p1).Z());
760 
761 					pCurrentRC->glEnd();
762 				}
763 			}
764 		}
765 	}
766 	int advancedlinemode = 1; //draw nices lines (for presenation), but no redraw during zooming
767 	if (drawlines == 1 || drawlines == 2)
768 	{
769 		//if (drawlines != 2)
770 		if (advancedlinemode) pCurrentRC->BeginLinesOnSolid();
771 		int p1,p2;
772 		double thickness = GetDOption(102);
773 		for (int i1=1; i1 < n1; i1++)
774 		{
775 			p1=i1;
776 			p2=i1+1;
777 			MyDrawLine(p(p1),p(p2),thickness);
778 			p1=(n2-1)*n1+i1+1;
779 			p2=(n2-1)*n1+i1;
780 			MyDrawLine(p(p1),p(p2),thickness);
781 		}
782 		for (int i2=1; i2 < n2; i2++)
783 		{
784 			p1=(i2-1)*n1+1;
785 			p2=(i2-1)*n1+n1+1;
786 			MyDrawLine(p(p1),p(p2),thickness);
787 			p1=(i2)*n1;
788 			p2=(i2)*n1+n1;
789 			MyDrawLine(p(p1),p(p2),thickness);
790 		}
791 		//if (drawlines != 2)
792 		if (advancedlinemode) pCurrentRC->EndLinesOnSolid();
793 	}
794 	if (drawlines == 3 || drawlines == 4)
795 	{
796 		if (advancedlinemode) pCurrentRC->BeginLinesOnSolid();
797 		double thickness = GetDOption(102);
798 		int p1,p2,p3,p4;
799 		for (int i1=1; i1 < n1; i1++)
800 		{
801 			for (int i2=1; i2 < n2; i2++)
802 			{
803 				p4=(i2-1)*n1+i1;
804 				p3=(i2-1)*n1+i1+1;
805 				p2=(i2)*n1+i1+1;
806 				p1=(i2)*n1+i1;
807 				MyDrawLine(p(p1),p(p2),thickness);
808 				MyDrawLine(p(p2),p(p3),thickness);
809 				MyDrawLine(p(p3),p(p4),thickness);
810 				MyDrawLine(p(p4),p(p1),thickness);
811 			}
812 		}
813 		if (advancedlinemode) pCurrentRC->EndLinesOnSolid();
814 	}
815 }
816 
817 
DrawQuad(const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4) const818 void TimeInt::DrawQuad(const Vector3D& p1,const Vector3D& p2,const Vector3D& p3,const Vector3D& p4) const
819 {
820 	pCurrentRC->glBeginQuads();
821 	Vector3D n;
822 	Normal3D(p4,p2,p1,n);
823 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
824 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
825 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
826 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
827 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
828 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
829 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
830 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
831 	pCurrentRC->glEnd();
832 }
833 
DrawTrig(const Vector3D & p1,const Vector3D & p2,const Vector3D & p3) const834 void TimeInt::DrawTrig(const Vector3D& p1,const Vector3D& p2,const Vector3D& p3) const
835 {
836 	pCurrentRC->glBeginTriangles();
837 	Vector3D n;
838 	Normal3D(p3,p2,p1,n);
839 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
840 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
841 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
842 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
843 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
844 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
845 	pCurrentRC->glEnd();
846 }
847 
DrawPolygon(const TArray<Vector3D> & p,int drawlines,double linewidth) const848 void TimeInt::DrawPolygon(const TArray<Vector3D>& p, int drawlines, double linewidth) const
849 {
850 	Vector3D n(0.,0.,0.);
851 	if (p.Length() >= 2)
852 	{
853 		Normal3D(p(2),p.Last(),p(1),n);
854 	}
855 
856 	pCurrentRC->glBeginPolygon();
857 	for (int i=1; i <= p.Length(); i++)
858 	{
859 		pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
860 		pCurrentRC->glVertex((float)p(i).X(),(float)p(i).Y(),(float)p(i).Z());
861 	}
862 	pCurrentRC->glEnd();
863 
864 	if (drawlines)
865 	{
866 		DrawPolygonOutline(p,linewidth);
867 	}
868 }
869 
DrawPolygonOutline(const TArray<Vector3D> & p,double linewidth) const870 void TimeInt::DrawPolygonOutline(const TArray<Vector3D>& p, double linewidth) const
871 {
872 	Vector3D n(0.,0.,0.);
873 	if (p.Length() >= 2)
874 	{
875 		Normal3D(p(2),p.Last(),p(1),n);
876 	}
877 	ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
878 	pCurrentRC->ChooseLineThickness((float)linewidth);
879 	pCurrentRC->glBeginLineStrip();
880 
881 	for (int i=1; i <= p.Length(); i++)
882 	{
883 		pCurrentRC->glVertex((float)p(i).X(),(float)p(i).Y(),(float)p(i).Z());
884 	}
885 	pCurrentRC->glVertex((float)p(1).X(),(float)p(1).Y(),(float)p(1).Z());
886 
887 	pCurrentRC->glEnd();
888 	ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
889 }
890 
DrawHex(const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4,const Vector3D & p5,const Vector3D & p6,const Vector3D & p7,const Vector3D & p8,int drawouterfaces) const891 void TimeInt::DrawHex(const Vector3D& p1,const Vector3D& p2,const Vector3D& p3,const Vector3D& p4,
892 		const Vector3D& p5,const Vector3D& p6,const Vector3D& p7,const Vector3D& p8, int drawouterfaces) const
893 {
894 	//#outer surface right: 3-4-8-7
895 	//#outer surface left:  1-2-6-5
896 	//#bottom: 1-3-4-2
897 	//#top: 5-7-8-6
898 	float tn = 0.5;
899 	if (drawlines == 2) tn = 1.;
900 	else if (drawlines == 3) tn = 2.;
901 
902 	pCurrentRC->glBeginQuads();
903 	Vector3D n;
904 	Normal3D(p1,p2,p4,n);
905 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
906 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
907 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
908 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
909 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
910 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
911 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
912 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
913 	pCurrentRC->glEnd();
914 
915 	if (drawlines)
916 	{
917 		ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
918 		pCurrentRC->ChooseLineThickness(tn);
919 		pCurrentRC->glBeginLineStrip();
920 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
921 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
922 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
923 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
924 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
925 		pCurrentRC->glEnd();
926 		ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
927 	}
928 
929 	pCurrentRC->glBeginQuads();
930 	Normal3D(p5,p8,p6,n);
931 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
932 	pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
933 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
934 	pCurrentRC->glVertex((float)p8[0],(float)p8[1],(float)p8[2]);
935 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
936 	pCurrentRC->glVertex((float)p6[0],(float)p6[1],(float)p6[2]);
937 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
938 	pCurrentRC->glVertex((float)p5[0],(float)p5[1],(float)p5[2]);
939 	pCurrentRC->glEnd();
940 
941 	if (drawlines)
942 	{
943 		ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
944 		pCurrentRC->ChooseLineThickness(tn);
945 		pCurrentRC->glBeginLineStrip();
946 		pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
947 		pCurrentRC->glVertex((float)p8[0],(float)p8[1],(float)p8[2]);
948 		pCurrentRC->glVertex((float)p6[0],(float)p6[1],(float)p6[2]);
949 		pCurrentRC->glVertex((float)p5[0],(float)p5[1],(float)p5[2]);
950 		pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
951 		pCurrentRC->glEnd();
952 		ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
953 	}
954 
955 	pCurrentRC->glBeginQuads();
956 	Normal3D(p1,p7,p5,n);
957 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
958 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
959 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
960 	pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
961 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
962 	pCurrentRC->glVertex((float)p5[0],(float)p5[1],(float)p5[2]);
963 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
964 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
965 	pCurrentRC->glEnd();
966 
967 	if (drawlines || drawlinesh)
968 	{
969 		ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
970 		pCurrentRC->ChooseLineThickness(tn);
971 		pCurrentRC->glBeginLines();
972 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
973 		pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
974 		pCurrentRC->glEnd();
975 		pCurrentRC->glBeginLines();
976 		pCurrentRC->glVertex((float)p5[0],(float)p5[1],(float)p5[2]);
977 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
978 		pCurrentRC->glEnd();
979 		ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
980 	}
981 
982 	pCurrentRC->glBeginQuads();
983 	Normal3D(p2,p6,p8,n);
984 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
985 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
986 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
987 	pCurrentRC->glVertex((float)p6[0],(float)p6[1],(float)p6[2]);
988 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
989 	pCurrentRC->glVertex((float)p8[0],(float)p8[1],(float)p8[2]);
990 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
991 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
992 	pCurrentRC->glEnd();
993 
994 	if (drawlinesh || drawlines)
995 	{
996 		ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
997 		pCurrentRC->ChooseLineThickness(tn);
998 		pCurrentRC->glBeginLines();
999 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1000 		pCurrentRC->glVertex((float)p6[0],(float)p6[1],(float)p6[2]);
1001 		pCurrentRC->glEnd();
1002 		pCurrentRC->glBeginLines();
1003 		pCurrentRC->glVertex((float)p8[0],(float)p8[1],(float)p8[2]);
1004 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
1005 		pCurrentRC->glEnd();
1006 		ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1007 	}
1008 
1009 	if (drawouterfaces)
1010 	{
1011 	pCurrentRC->glBeginQuads();
1012 	Normal3D(p3,p4,p8,n);
1013 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1014 	pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
1015 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1016 	pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
1017 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1018 	pCurrentRC->glVertex((float)p8[0],(float)p8[1],(float)p8[2]);
1019 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1020 	pCurrentRC->glVertex((float)p7[0],(float)p7[1],(float)p7[2]);
1021 	pCurrentRC->glEnd();
1022 
1023 	pCurrentRC->glBeginQuads();
1024 	Normal3D(p1,p6,p2,n);
1025 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1026 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1027 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1028 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1029 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1030 	pCurrentRC->glVertex((float)p6[0],(float)p6[1],(float)p6[2]);
1031 	pCurrentRC->glNormal((float)n[0],(float)n[1],(float)n[2]);
1032 	pCurrentRC->glVertex((float)p5[0],(float)p5[1],(float)p5[2]);
1033 	pCurrentRC->glEnd();
1034 	}
1035 
1036 }
1037 
DrawCube(const Vector3D & p0,const Vector3D & v1,const Vector3D & v2,const Vector3D & v3) const1038 void TimeInt::DrawCube(const Vector3D& p0, const Vector3D& v1, const Vector3D& v2, const Vector3D& v3) const//draws cube with reference point and 3 axes
1039 {
1040 	Vector3D p1 = p0;
1041 	Vector3D p2 = p0+v2;
1042 	Vector3D p3 = p0+v1;
1043 	Vector3D p4 = p0+v1+v2;
1044 	Vector3D p5 = v3+p0;
1045 	Vector3D p6 = v3+p0+v2;
1046 	Vector3D p7 = v3+p0+v1;
1047 	Vector3D p8 = v3+p0+v1+v2;
1048 
1049 	DrawHex(p1,p2,p3,p4,p5,p6,p7,p8);
1050 }
1051 
1052 //draw a zylinder in 3D, with color specified by value v, endpoints p1 and p2, Radius r, number of surfaces (discretized): tile
DrawColorZyl(double v,const Vector3D & pz1,const Vector3D & pz2,double rz,int tile)1053 void TimeInt::DrawColorZyl(double v, const Vector3D& pz1,const Vector3D& pz2, double rz, int tile)
1054 {
1055 	UpdateFEMinMaxCol(v);
1056 	double diff = TImaxcol-TImincol;
1057 
1058 	if (TImincol == 1e10) {TImincol=TImaxcol=0;}
1059 	if (diff == 0) {diff=1;}
1060 
1061 	if (IsFlagComputeMinMaxFECol()) return;
1062 
1063 	pCurrentRC->glBeginTexture1D(0); //color
1064 	SetFEColor((v-TImincol)/diff);
1065 	DrawZyl(pz1,pz2, rz, tile);
1066 	pCurrentRC->glEndTexture1D();
1067 }
1068 
1069 //draw a zylinder in 3D, with endpoints p1 and p2, Radius r, number of surfaces (discretized): tile
DrawZyl(const Vector3D & pz1,const Vector3D & pz2,double rz,int tile) const1070 void TimeInt::DrawZyl(const Vector3D& pz1,const Vector3D& pz2, double rz, int tile) const
1071 {
1072 	float tn = 1.;
1073 	Vector3D n;
1074 	Vector3D p1(pz1.X()+tidraw_offx,
1075 		pz1.Y()+tidraw_offy,
1076 		pz1.Z()+tidraw_offz);
1077 	Vector3D p2(pz2.X()+tidraw_offx,
1078 		pz2.Y()+tidraw_offy,
1079 		pz2.Z()+tidraw_offz);
1080 	double r = rz;//;
1081 
1082 	//const double pi = 3.14159265358979323;
1083 	double i, phi, dphi;
1084 	double dtile = tile;
1085 	if (dtile == 0) {dtile = 1;}
1086 
1087 	Vector3D p3=p1+Vector3D(1,1,1);
1088 	Vector3D v21=p2-p1;
1089 	Vector3D v=v21;
1090 	v.Normalize();
1091 	double np1=v*p1;
1092 
1093 	if (v.X() != 0) {p3.X() = 1./v.X()*(np1-p3.Y()*v.Y()-p3.Z()*v.Z());}
1094 	else if (v.Y() != 0) {p3.Y() = 1./v.Y()*(np1-p3.X()*v.X()-p3.Z()*v.Z());}
1095 	else if (v.Z() != 0) {p3.Z() = 1./v.Z()*(np1-p3.Y()*v.Y()-p3.X()*v.X());}
1096 	else {return;}
1097 
1098 	Vector3D n1 = p3-p1;
1099 	n1.Normalize();
1100 	Vector3D n2 = v.Cross(n1);
1101 	n2.Normalize();
1102 
1103 	for (i = 0; i < dtile; i++)
1104 	{
1105 		phi = i*2.*MY_PI/dtile;
1106 		dphi = 2.*MY_PI/dtile;
1107 
1108 		Vector3D pz1=r*cos(phi)*n1+r*sin(phi)*n2+p1;
1109 		Vector3D pz2=pz1+v21;
1110 		Vector3D pz4=r*cos(phi+dphi)*n1+r*sin(phi+dphi)*n2+p1;
1111 		Vector3D pz3=pz4+v21;
1112 		Vector3D nz1 = pz1-p1;
1113 		Vector3D nz2 = pz4-p1;
1114 		nz1.Normalize();
1115 		nz2.Normalize();
1116 
1117 		pCurrentRC->glBeginQuads();
1118 		pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1119 		pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1120 		pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1121 		pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1122 		pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1123 		pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1124 		pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1125 		pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1126 		pCurrentRC->glEnd();
1127 	}
1128 	//draw triangles after quads, because of transparency!!!
1129 	for (i = 0; i < dtile; i++)
1130 	{
1131 		phi = i*2.*MY_PI/dtile;
1132 		dphi = 2.*MY_PI/dtile;
1133 
1134 		Vector3D pz1=r*cos(phi)*n1+r*sin(phi)*n2+p1;
1135 		Vector3D pz2=pz1+v21;
1136 		Vector3D pz4=r*cos(phi+dphi)*n1+r*sin(phi+dphi)*n2+p1;
1137 		Vector3D pz3=pz4+v21;
1138 		Vector3D nz1 = pz1-p1;
1139 		Vector3D nz2 = pz4-p1;
1140 		nz1.Normalize();
1141 		nz2.Normalize();
1142 
1143 		pCurrentRC->glBeginTriangles();
1144 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1145 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1146 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1147 		pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1148 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1149 		pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1150 		pCurrentRC->glEnd();
1151 	}
1152 	for (i = 0; i < dtile; i++)
1153 	{
1154 		phi = i*2.*MY_PI/dtile;
1155 		dphi = 2.*MY_PI/dtile;
1156 
1157 		Vector3D pz1=r*cos(phi)*n1+r*sin(phi)*n2+p1;
1158 		Vector3D pz2=pz1+v21;
1159 		Vector3D pz4=r*cos(phi+dphi)*n1+r*sin(phi+dphi)*n2+p1;
1160 		Vector3D pz3=pz4+v21;
1161 		Vector3D nz1 = pz1-p1;
1162 		Vector3D nz2 = pz4-p1;
1163 		nz1.Normalize();
1164 		nz2.Normalize();
1165 
1166 		pCurrentRC->glBeginTriangles();
1167 		pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1168 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1169 		pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1170 		pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1171 		pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1172 		pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1173 		pCurrentRC->glEnd();
1174 
1175 		if (drawlines)
1176 		{
1177 			ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
1178 			pCurrentRC->ChooseLineThickness(tn);
1179 			pCurrentRC->glBeginLines();
1180 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1181 			pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1182 			pCurrentRC->glEnd();
1183 			pCurrentRC->glBeginLines();
1184 			pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1185 			pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1186 			pCurrentRC->glEnd();
1187 			ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1188 		}
1189 	}
1190 }
1191 
1192 //draw a zylinder in 3D, with endpoints p1 and p2, Radius r, number of surfaces (discretized): tile
DrawCone(const Vector3D & pz1,const Vector3D & pz2,double rz,int tile,int drawconelines) const1193 void TimeInt::DrawCone(const Vector3D& pz1,const Vector3D& pz2, double rz, int tile, int drawconelines) const
1194 {
1195 	float tn = 1.;
1196 	Vector3D n;
1197 	Vector3D p1(pz1.X()+tidraw_offx,
1198 		pz1.Y()+tidraw_offy,
1199 		pz1.Z()+tidraw_offz);
1200 	Vector3D p2(pz2.X()+tidraw_offx,
1201 		pz2.Y()+tidraw_offy,
1202 		pz2.Z()+tidraw_offz);
1203 	double r = rz;//;
1204 
1205 	//const double pi = 3.14159265358979323;
1206 	double i, phi, dphi;
1207 	double dtile = tile;
1208 	if (dtile == 0) {dtile = 1;}
1209 
1210 	Vector3D p3=p1+Vector3D(1,1,1);
1211 	Vector3D v21=p2-p1;
1212 	Vector3D v=v21;
1213 	v.Normalize();
1214 	double np1=v*p1;
1215 
1216 	if (v.X() != 0) {p3.X() = 1./v.X()*(np1-p3.Y()*v.Y()-p3.Z()*v.Z());}
1217 	else if (v.Y() != 0) {p3.Y() = 1./v.Y()*(np1-p3.X()*v.X()-p3.Z()*v.Z());}
1218 	else if (v.Z() != 0) {p3.Z() = 1./v.Z()*(np1-p3.Y()*v.Y()-p3.X()*v.X());}
1219 	else {return;}
1220 
1221 	Vector3D n1 = p3-p1;
1222 	n1.Normalize();
1223 	Vector3D n2 = v.Cross(n1);
1224 	n2.Normalize();
1225 
1226 	for (i = 0; i < dtile; i++)
1227 	{
1228 		phi = i*2.*MY_PI/dtile;
1229 		dphi = 2.*MY_PI/dtile;
1230 
1231 		Vector3D pz1=r*cos(phi)*n1+r*sin(phi)*n2+p1;
1232 		Vector3D pz2=p2;
1233 		Vector3D pz4=r*cos(phi+dphi)*n1+r*sin(phi+dphi)*n2+p1;
1234 		Vector3D pz3=p2;
1235 		Vector3D nz1 = pz1-p1;
1236 		Vector3D nz2 = pz4-p1;
1237 		nz1.Normalize();
1238 		nz2.Normalize();
1239 
1240 		pCurrentRC->glBeginQuads();
1241 		pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1242 		pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1243 		pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1244 		pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1245 		pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1246 		pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1247 		pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1248 		pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1249 		pCurrentRC->glEnd();
1250 	}
1251 	//draw triangles after quads, because of transparency!!!
1252 	for (i = 0; i < dtile; i++)
1253 	{
1254 		phi = i*2.*MY_PI/dtile;
1255 		dphi = 2.*MY_PI/dtile;
1256 
1257 		Vector3D pz1=r*cos(phi)*n1+r*sin(phi)*n2+p1;
1258 		Vector3D pz2=pz1+v21;
1259 		Vector3D pz4=r*cos(phi+dphi)*n1+r*sin(phi+dphi)*n2+p1;
1260 		Vector3D pz3=pz4+v21;
1261 		Vector3D nz1 = pz1-p1;
1262 		Vector3D nz2 = pz4-p1;
1263 		nz1.Normalize();
1264 		nz2.Normalize();
1265 
1266 		pCurrentRC->glBeginTriangles();
1267 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1268 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1269 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1270 		pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1271 		pCurrentRC->glNormal(-1.f*(float)v[0],-1.f*(float)v[1],-1.f*(float)v[2]);
1272 		pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1273 		pCurrentRC->glEnd();
1274 
1275 		if (drawconelines)
1276 		{
1277 			ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
1278 			pCurrentRC->ChooseLineThickness(tn);
1279 			pCurrentRC->glBeginLines();
1280 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1281 			pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1282 			pCurrentRC->glEnd();
1283 			pCurrentRC->glBeginLines();
1284 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1285 			pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1286 			pCurrentRC->glEnd();
1287 			ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1288 		}
1289 	}
1290 }
1291 
DrawColorArrow(double v,const Vector3D & p1,const Vector3D & p2,double linethickness,double headsize,int resolution)1292 void TimeInt::DrawColorArrow(double v, const Vector3D& p1, const Vector3D&p2, double linethickness, double headsize, int resolution)
1293 {
1294 	UpdateFEMinMaxCol(v);
1295 	double diff = TImaxcol-TImincol;
1296 
1297 	if (TImincol == 1e10) {TImincol=TImaxcol=0;}
1298 	if (diff == 0) {diff=1;}
1299 
1300 	if (IsFlagComputeMinMaxFECol()) return;
1301 
1302 	pCurrentRC->glBeginTexture1D(0); //color
1303 	SetFEColor((v-TImincol)/diff);
1304 	DrawArrow(p1,p2, linethickness, headsize, resolution);
1305 	pCurrentRC->glEndTexture1D();
1306 }
1307 
MyDrawArrow(const Vector3D & p1,const Vector3D & p2,const Vector3D & col,double linethickness,double headsize,int resolution) const1308 void TimeInt::MyDrawArrow(const Vector3D& p1, const Vector3D&p2, const Vector3D& col,
1309 		double linethickness, double headsize, int resolution) const
1310 {
1311 	if (IsFlagComputeMinMaxFECol()) return;
1312 
1313 	ChooseColor((float)col.X(), (float)col.Y(), (float)col.Z());
1314 	DrawArrow(p1, p2, linethickness, headsize, resolution);
1315 }
1316 
DrawArrow(const Vector3D & p1,const Vector3D & p2,double linethickness,double headsize,int resolution) const1317 void TimeInt::DrawArrow(const Vector3D& p1, const Vector3D&p2, double linethickness, double headsize, int resolution) const
1318 {
1319 	Vector3D n;
1320 	double len = (p1-p2).Norm();
1321 	if (len < 1e-10) return;
1322 
1323 	if (linethickness == -1) linethickness = len * 0.01;
1324 	if (headsize == -1) headsize = len * 0.04;
1325 
1326 	double r1 = linethickness;//'line' thickness
1327 	double r2 = headsize;     //head radius
1328 	double lh = headsize*2; //headlength
1329 
1330 	double i, phi, dphi;
1331 	double dtile = resolution;
1332 	if (dtile == 0) {dtile = 1;}
1333 
1334 	Vector3D v21=p2-p1;
1335 
1336 	Vector3D n1,n2;
1337 
1338 	v21.SetNormalBasis(n1,n2);
1339 	Vector3D n3 = -1.*v21;
1340 	n3.Normalize();
1341 	Vector3D n4 = -1.*n3;
1342 	Vector3D p2b = p2 + lh*n3;
1343 	Vector3D v21b = p2b-p1;
1344 
1345 	for (i = 0; i < dtile; i++)
1346 	{
1347 		phi = i*2.*MY_PI/dtile;
1348 		dphi = 2.*MY_PI/dtile;
1349 
1350 		Vector3D pz1=r1*cos(phi)*n1+r1*sin(phi)*n2+p1;
1351 		Vector3D pz2=pz1+v21b;
1352 		Vector3D pz4=r1*cos(phi+dphi)*n1+r1*sin(phi+dphi)*n2+p1;
1353 		Vector3D pz3=pz4+v21b;
1354 		Vector3D nz1 = pz1-p1;
1355 		Vector3D nz2 = pz4-p1;
1356 		nz1.Normalize();
1357 		nz2.Normalize();
1358 
1359 		Vector3D pz5 = r2*cos(phi)*n1+r2*sin(phi)*n2+p2b;
1360 		Vector3D pz6 = r2*cos(phi+dphi)*n1+r2*sin(phi+dphi)*n2+p2b;
1361 
1362 		pCurrentRC->glBeginQuads();
1363 		//cylinder:
1364 		pCurrentRC->glNormal(nz1.GetVecPtr());
1365 		pCurrentRC->glVertex(pz1.GetVecPtr());
1366 		pCurrentRC->glNormal(nz2.GetVecPtr());
1367 		pCurrentRC->glVertex(pz4.GetVecPtr());
1368 		pCurrentRC->glNormal(nz2.GetVecPtr());
1369 		pCurrentRC->glVertex(pz3.GetVecPtr());
1370 		pCurrentRC->glNormal(nz1.GetVecPtr());
1371 		pCurrentRC->glVertex(pz2.GetVecPtr());
1372 
1373 		//ring:
1374 		pCurrentRC->glNormal(n3.GetVecPtr());
1375 		pCurrentRC->glVertex(pz2.GetVecPtr());
1376 		pCurrentRC->glNormal(n3.GetVecPtr());
1377 		pCurrentRC->glVertex(pz5.GetVecPtr());
1378 		pCurrentRC->glNormal(n3.GetVecPtr());
1379 		pCurrentRC->glVertex(pz6.GetVecPtr());
1380 		pCurrentRC->glNormal(n3.GetVecPtr());
1381 		pCurrentRC->glVertex(pz3.GetVecPtr());
1382 
1383 		pCurrentRC->glEnd();
1384 	}
1385 	//draw triangles after quads, because of transparency!!!
1386 	for (i = 0; i < dtile; i++)
1387 	{
1388 		phi = i*2.*MY_PI/dtile;
1389 		dphi = 2.*MY_PI/dtile;
1390 
1391 		Vector3D pz1=r1*cos(phi)*n1+r1*sin(phi)*n2+p1;
1392 		Vector3D pz4=r1*cos(phi+dphi)*n1+r1*sin(phi+dphi)*n2+p1;
1393 
1394 		pCurrentRC->glBeginTriangles();
1395 		pCurrentRC->glNormal(n3.GetVecPtr());
1396 		pCurrentRC->glVertex(p1.GetVecPtr());
1397 		pCurrentRC->glNormal(n3.GetVecPtr());
1398 		pCurrentRC->glVertex(pz4.GetVecPtr());
1399 		pCurrentRC->glNormal(n3.GetVecPtr());
1400 		pCurrentRC->glVertex(pz1.GetVecPtr());
1401 		pCurrentRC->glEnd();
1402 	}
1403 	for (i = 0; i < dtile; i++)
1404 	{
1405 		//triangles at head
1406 		phi = i*2.*MY_PI/dtile;
1407 		dphi = 2.*MY_PI/dtile;
1408 
1409 		Vector3D pz1=r2*cos(phi)*n1+r2*sin(phi)*n2+p2b;
1410 		Vector3D pz4=r2*cos(phi+dphi)*n1+r2*sin(phi+dphi)*n2+p2b;
1411 		Vector3D nz1 = pz1-p2b;
1412 		Vector3D nz2 = pz4-p2b;
1413 		Vector3D nz3 = 0.5*(nz1+nz2);
1414 		nz1.Normalize();
1415 		nz2.Normalize();
1416 		nz3.Normalize();
1417 
1418 
1419 		pCurrentRC->glBeginTriangles();
1420 		pCurrentRC->glNormal(nz3.GetVecPtr());
1421 		pCurrentRC->glVertex(p2.GetVecPtr());
1422 		pCurrentRC->glNormal(nz1.GetVecPtr());
1423 		pCurrentRC->glVertex(pz1.GetVecPtr());
1424 		pCurrentRC->glNormal(nz2.GetVecPtr());
1425 		pCurrentRC->glVertex(pz4.GetVecPtr());
1426 		pCurrentRC->glEnd();
1427 	}
1428 }
1429 
1430 
1431 //draw a zylinder in 3D, with endpoints p1 and p2, Radius r, number of surfaces (discretized): tile
1432 //use tangential vectors pz1dir and pz2dir
DrawZyl(const Vector3D & pz1,const Vector3D & pz2,const Vector3D & pz1dir,const Vector3D & pz2dir,double rz,int leftend,int rightend,int tile) const1433 void TimeInt::DrawZyl(const Vector3D& pz1, const Vector3D& pz2,
1434 											const Vector3D& pz1dir, const Vector3D& pz2dir, double rz, int leftend, int rightend, int tile) const
1435 {
1436 	float tn = 1.;
1437 	Vector3D n;
1438 	Vector3D p1(pz1.X()+tidraw_offx,
1439 		pz1.Y()+tidraw_offy,
1440 		pz1.Z()+tidraw_offz);
1441 	Vector3D p2(pz2.X()+tidraw_offx,
1442 		pz2.Y()+tidraw_offy,
1443 		pz2.Z()+tidraw_offz);
1444 
1445 	Vector3D dir1(pz1dir);
1446 	Vector3D dir2(pz2dir);
1447 	//dir1 = p2-p1;
1448 	//dir2 = p2-p1;
1449 	dir1.Normalize();
1450 	dir2.Normalize();
1451 
1452 	double r = rz;//;
1453 
1454 	//const double pi = 3.14159265358979323;
1455 	double i, phi, dphi;
1456 	double dtile = tile;
1457 	if (dtile == 0) {dtile = 1;}
1458 
1459 	Vector3D n1a, n1b, n2a, n2b;
1460 	dir1.SetNormalBasis(n1a,n1b);
1461 
1462 	n2a = n1a;
1463 	n2b = n1b;
1464 	dir2.GramSchmidt(n2a);
1465 	n2b = dir2.Cross(n2a);
1466 
1467 	//global_uo << "Basis1:" << dir1 << ", " << n1a << ", " << n1b << "=" << n1a.Cross(n1b) << "\n";
1468 	//global_uo << "Basis2:" << dir2 << ", " << n2a << ", " << n2b << "=" << n2a.Cross(n2b) << "\n";
1469 
1470 
1471 	for (i = 0; i < dtile; i++)
1472 	{
1473 		phi = i*2.*MY_PI/dtile;
1474 		dphi = 2.*MY_PI/dtile;
1475 
1476 		Vector3D pz1=r*cos(phi)*n1a+r*sin(phi)*n1b+p1;
1477 		Vector3D pz2=r*cos(phi+dphi)*n1a+r*sin(phi+dphi)*n1b+p1;
1478 		Vector3D pz3=r*cos(phi)*n2a+r*sin(phi)*n2b+p2;
1479 		Vector3D pz4=r*cos(phi+dphi)*n2a+r*sin(phi+dphi)*n2b+p2;
1480 
1481 		Vector3D nz1 = pz1-p1;
1482 		Vector3D nz2 = pz2-p1;
1483 		Vector3D nz3 = pz3-p2;
1484 		Vector3D nz4 = pz4-p2;
1485 		nz1.Normalize();
1486 		nz2.Normalize();
1487 		nz3.Normalize();
1488 		nz4.Normalize();
1489 
1490 		pCurrentRC->glBeginQuads();
1491 		pCurrentRC->glNormal((float)nz4[0],(float)nz4[1],(float)nz4[2]);
1492 		pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1493 		pCurrentRC->glNormal((float)nz3[0],(float)nz3[1],(float)nz3[2]);
1494 		pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1495 		pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1496 		pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1497 		pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1498 		pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1499 		pCurrentRC->glEnd();
1500 
1501 		if (leftend)
1502 		{
1503 			Vector3D v = -1*dir1;
1504 			pCurrentRC->glBeginTriangles();
1505 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1506 			pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1507 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1508 			pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1509 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1510 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1511 			pCurrentRC->glEnd();
1512 		}
1513 
1514 		if (rightend)
1515 		{
1516 			Vector3D v = dir2;
1517 			pCurrentRC->glBeginTriangles();
1518 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1519 			pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1520 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1521 			pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1522 			pCurrentRC->glNormal((float)v[0],(float)v[1],(float)v[2]);
1523 			pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1524 			pCurrentRC->glEnd();
1525 		}
1526 
1527 		if (drawlines)
1528 		{
1529 			ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
1530 			pCurrentRC->ChooseLineThickness(tn);
1531 			pCurrentRC->glBeginLines();
1532 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1533 			pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1534 			pCurrentRC->glEnd();
1535 			pCurrentRC->glBeginLines();
1536 			pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1537 			pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1538 			pCurrentRC->glEnd();
1539 			ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1540 		}
1541 	}
1542 }
1543 
1544 
DrawColorSphere(double v,const Vector3D & p,double r,int tile,double fill)1545 void TimeInt::DrawColorSphere(double v, const Vector3D& p, double r, int tile, double fill)
1546 {
1547 
1548 	UpdateFEMinMaxCol(v);
1549 
1550 	double diff = TImaxcol-TImincol;
1551 	if (diff == 0) {diff=1;}
1552 	if (TImincol == 1e10) {TImincol=TImaxcol=0;}
1553 
1554 	if (IsFlagComputeMinMaxFECol()) return;
1555 
1556 	pCurrentRC->glBeginTexture1D(0);
1557 	SetFEColor((v-TImincol)/diff);
1558 	DrawSphere(p, r, tile, fill);
1559 	pCurrentRC->glEndTexture1D();
1560 }
1561 
1562 TArray<double> sin_acc_tab_draw_sphere(0);
1563 TArray<double> cos_acc_tab_draw_sphere(0);
1564 TArray<Vector3D> normalvector_acc_tab_draw_sphere(0);
1565 
1566 //#define drawsphere_fast
DrawSphere(const Vector3D & p,double r,int tile,double fill) const1567 void TimeInt::DrawSphere(const Vector3D& p, double r, int tile, double fill) const
1568 {
1569 
1570 
1571 	Vector3D pk(p.X()+tidraw_offx,
1572 		p.Y()+tidraw_offy,
1573 		p.Z()+tidraw_offz);
1574 
1575 	//const double pi = 3.14159265358979323;
1576 	double i, j, phi, dphi;
1577 	if (tile == 0) {tile = 1;}
1578 
1579 #ifdef drawsphere_fast
1580 	if (sin_acc_tab_draw_sphere.Length() != tile+1)
1581 	{
1582 		sin_acc_tab_draw_sphere.SetLen(tile+1);
1583 		cos_acc_tab_draw_sphere.SetLen(tile+1);
1584 		//generate sin/cos table
1585 		for (j = 1; j <= tile+1; j++)
1586 		{
1587 			double phik1 = (j-1)*MY_PI/tile;
1588 			sin_acc_tab_draw_sphere(j) = sin(phik1);
1589 			cos_acc_tab_draw_sphere(j) = cos(phik1);
1590 		}
1591 		normalvector_acc_tab_draw_sphere.SetLen((tile+1)*(tile+1)*4);
1592 
1593 		for (j = 0; j < tile; j++)
1594 		{
1595 			for (i = 0; i < tile; i++)
1596 			{
1597 				double cosphik1 = cos_acc_tab_draw_sphere(j+1);
1598 				double cosphik2 = cos_acc_tab_draw_sphere(j+2);
1599 				double sinphik1 = sin_acc_tab_draw_sphere(j+1);
1600 				double sinphik2 = sin_acc_tab_draw_sphere(j+2);
1601 
1602 				double cosphi1 = cos_acc_tab_draw_sphere(i+1);
1603 				double cosphi2 = cos_acc_tab_draw_sphere(i+2);
1604 				double sinphi1 = sin_acc_tab_draw_sphere(i+1);
1605 				double sinphi2 = sin_acc_tab_draw_sphere(i+2);
1606 
1607 				double xpos1 = r*cosphik1;
1608 				double xpos2 = r*cosphik2;
1609 				double ypos1 = r*sinphik1;
1610 				double ypos2 = r*sinphik2;
1611 			Vector3D n1(0.,1.,0.);
1612 			Vector3D n2(0.,0.,1.);
1613 			Vector3D vr1(xpos1,0,0);
1614 			Vector3D vr2(xpos2,0,0);
1615 
1616 				Vector3D nz1(xpos1,ypos1*cosphi1,ypos1*sinphi1); //==>PG normal vector weg
1617 				Vector3D nz2=ypos2*cosphi1*n1+ypos2*sinphi1*n2+vr2;
1618 				Vector3D nz4=ypos1*cosphi2*n1+ypos1*sinphi2*n2+vr1;
1619 				Vector3D nz3=ypos2*cosphi2*n1+ypos2*sinphi2*n2+vr2;
1620 
1621 				nz1.Normalize();
1622 				nz2.Normalize();
1623 				nz3.Normalize();
1624 				nz4.Normalize();
1625 				normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*1) = nz1;
1626 				normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*2) = nz2;
1627 				normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*3) = nz3;
1628 				normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*4) = nz4;
1629 			}
1630 		}
1631 	}
1632 #endif
1633 
1634 	for (j = 0; j < tile*fill; j++)
1635 	{
1636 		for (i = 0; i < tile; i++)
1637 		{
1638 
1639 #ifdef drawsphere_fast
1640 			double cosphik1 = cos_acc_tab_draw_sphere(j+1);
1641 			double cosphik2 = cos_acc_tab_draw_sphere(j+2);
1642 			double sinphik1 = sin_acc_tab_draw_sphere(j+1);
1643 			double sinphik2 = sin_acc_tab_draw_sphere(j+2);
1644 
1645 			double cosphi1 = cos_acc_tab_draw_sphere(i+1);
1646 			double cosphi2 = cos_acc_tab_draw_sphere(i+2);
1647 			double sinphi1 = sin_acc_tab_draw_sphere(i+1);
1648 			double sinphi2 = sin_acc_tab_draw_sphere(i+2);
1649 
1650 			double xpos1 = r*cosphik1;
1651 			double xpos2 = r*cosphik2;
1652 			double ypos1 = r*sinphik1;
1653 			double ypos2 = r*sinphik2;
1654 
1655 			Vector3D pz1(xpos1+pk.X(), ypos1*cosphi1+pk.Y(), ypos1*sinphi1+pk.Z()); //==>PG normal vector weg
1656 			Vector3D pz2(xpos2+pk.X(), ypos2*cosphi1+pk.Y(), ypos2*sinphi1+pk.Z());
1657 			Vector3D pz4(xpos1+pk.X(), ypos1*cosphi2+pk.Y(), ypos1*sinphi2+pk.Z());
1658 			Vector3D pz3(xpos2+pk.X(), ypos2*cosphi2+pk.Y(), ypos2*sinphi2+pk.Z());
1659 			Vector3D nz1 = normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*1);
1660 			Vector3D nz2 = normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*2);
1661 			Vector3D nz3 = normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*3);
1662 			Vector3D nz4 = normalvector_acc_tab_draw_sphere(j+1+i*(tile+1)*4);
1663 #else
1664 			phi = i*2.*MY_PI/tile;
1665 			dphi = 2.*MY_PI/tile;
1666 			double phik1 = j*MY_PI/tile;
1667 			double phik2 = (j+1.)*MY_PI/tile;
1668 
1669 			double xpos1 = r*cos(phik1);
1670 			double xpos2 = r*cos(phik2);
1671 			double ypos1 = r*sin(phik1);
1672 			double ypos2 = r*sin(phik2);
1673 			Vector3D n1(0.,1.,0.);
1674 			Vector3D n2(0.,0.,1.);
1675 			Vector3D vr1(xpos1,0,0);
1676 			Vector3D vr2(xpos2,0,0);
1677 			Vector3D pz1=ypos1*cos(phi)*n1+ypos1*sin(phi)*n2+pk+vr1;
1678 			Vector3D pz2=ypos2*cos(phi)*n1+ypos2*sin(phi)*n2+pk+vr2;
1679 			Vector3D pz4=ypos1*cos(phi+dphi)*n1+ypos1*sin(phi+dphi)*n2+pk+vr1;
1680 			Vector3D pz3=ypos2*cos(phi+dphi)*n1+ypos2*sin(phi+dphi)*n2+pk+vr2;
1681 			Vector3D nz1 = pz1-pk;
1682 			Vector3D nz2 = pz2-pk;
1683 			Vector3D nz3 = pz3-pk;
1684 			Vector3D nz4 = pz4-pk;
1685 			nz1.Normalize();
1686 			nz2.Normalize();
1687 			nz3.Normalize();
1688 			nz4.Normalize();
1689 #endif
1690 
1691 
1692 			pCurrentRC->glBeginQuads();
1693 			pCurrentRC->glNormal((float)nz1[0],(float)nz1[1],(float)nz1[2]);
1694 			pCurrentRC->glVertex((float)pz1[0],(float)pz1[1],(float)pz1[2]);
1695 			pCurrentRC->glNormal((float)nz4[0],(float)nz4[1],(float)nz4[2]);
1696 			pCurrentRC->glVertex((float)pz4[0],(float)pz4[1],(float)pz4[2]);
1697 			pCurrentRC->glNormal((float)nz3[0],(float)nz3[1],(float)nz3[2]);
1698 			pCurrentRC->glVertex((float)pz3[0],(float)pz3[1],(float)pz3[2]);
1699 			pCurrentRC->glNormal((float)nz2[0],(float)nz2[1],(float)nz2[2]);
1700 			pCurrentRC->glVertex((float)pz2[0],(float)pz2[1],(float)pz2[2]);
1701 			pCurrentRC->glEnd();
1702 
1703 		}
1704 	}
1705 }
1706 
1707 //Draw 2-D line in 3D: (2 coordinates per point ignored)
MyDrawLineH(const Vector3D & p1,const Vector3D & p2,const Vector3D & vy2,double t,double h,int drawouterface) const1708 void TimeInt::MyDrawLineH(const Vector3D& p1, const Vector3D& p2, const Vector3D& vy2,
1709 													double t, double h, int drawouterface) const
1710 {
1711 	if (IsFlagComputeMinMaxFECol()) return;
1712 
1713 	Vector3D v = p2-p1;
1714 	double len = sqrt(sqr(v(1))+sqr(v(2)));
1715 	if (len!=0) v*=1./len;
1716 	len = sqrt(sqr(vy2(1))+sqr(vy2(2)));
1717 	if (len!=0) len=1./len;
1718 
1719 	Vector3D nvy1(v(2)*h,-v(1)*h,0);
1720 	Vector3D nvy2(vy2(2)*h*len,-vy2(1)*h*len,0);
1721 	Vector3D nvz(0.,0.,1.*t);
1722 	Vector3D v1(p1(1)+tidraw_offx,p1(2)+tidraw_offy,p1(3));
1723 	Vector3D v2(p2(1)+tidraw_offx,p2(2)+tidraw_offy,p2(3));
1724 
1725 	DrawHex(v2-nvy2-nvz,v2-nvy2+nvz,v2+nvy2-nvz,v2+nvy2+nvz,
1726 		v1-nvy1-nvz,v1-nvy1+nvz,v1+nvy1-nvz,v1+nvy1+nvz, drawouterface);
1727 
1728 }
1729 
MyDrawLine(const Vector3D & p1,const Vector3D & p2,double thickness) const1730 void TimeInt::MyDrawLine(const Vector3D& p1, const Vector3D& p2, double thickness) const
1731 {
1732 	if (IsFlagComputeMinMaxFECol()) return;
1733 
1734 	ChooseColor((float)colline[0],(float)colline[1],(float)colline[2]);
1735 	pCurrentRC->ChooseLineThickness((float)thickness);
1736 	pCurrentRC->glBeginLines();
1737 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1738 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1739 	pCurrentRC->glEnd();
1740 	ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1741 	pCurrentRC->ChooseLineThickness(1);
1742 
1743 }
1744 
MyDrawRectangle(const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4,double thickness,const Vector3D * colline,const Vector3D * colfill) const1745 void TimeInt::MyDrawRectangle(const Vector3D& p1, const Vector3D& p2, const Vector3D& p3, const Vector3D& p4, double thickness, const Vector3D* colline, const Vector3D* colfill) const
1746 {
1747 	if (IsFlagComputeMinMaxFECol()) return;
1748 
1749 	if(colfill)
1750 	{
1751 		ChooseColor((float)(*colfill)[0],(float)(*colfill)[1],(float)(*colfill)[2]);
1752 		pCurrentRC->ChooseLineThickness((float)thickness);
1753 		pCurrentRC->glBeginQuads();
1754 
1755 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1756 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1757 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
1758 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
1759 
1760 		pCurrentRC->glEnd();
1761 	}
1762 	if(colline)
1763 	{
1764 		pCurrentRC->ChooseLineThickness(2.0);
1765 		ChooseColor((float)(*colline)[0],(float)(*colline)[1],(float)(*colline)[2]);
1766 		pCurrentRC->glBeginLines();
1767 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1768 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1769 		pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1770 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
1771 		pCurrentRC->glVertex((float)p3[0],(float)p3[1],(float)p3[2]);
1772 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
1773 		pCurrentRC->glVertex((float)p4[0],(float)p4[1],(float)p4[2]);
1774 		pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1775 
1776 		pCurrentRC->glEnd();
1777 	}
1778 	ChooseColor((float)actcolor[0],(float)actcolor[1],(float)actcolor[2]);
1779 	pCurrentRC->ChooseLineThickness(1);
1780 }
1781 
MyDrawLine(const Vector3D & p1,const Vector3D & p2,double thickness,const Vector3D & col) const1782 void TimeInt::MyDrawLine(const Vector3D& p1, const Vector3D& p2, double thickness, const Vector3D& col) const
1783 {
1784 	if (IsFlagComputeMinMaxFECol()) return;
1785 
1786 	ChooseColor((float)col[0],(float)col[1],(float)col[2]);
1787 	pCurrentRC->ChooseLineThickness((float)thickness);
1788 	pCurrentRC->glBeginLines();
1789 	pCurrentRC->glVertex((float)p1[0],(float)p1[1],(float)p1[2]);
1790 	pCurrentRC->glVertex((float)p2[0],(float)p2[1],(float)p2[2]);
1791 	pCurrentRC->glEnd();
1792 	pCurrentRC->ChooseLineThickness(1);
1793 }
1794 
MyDrawCircleXY(const Vector3D p,double r,const Vector3D & col,int res,double thickness) const1795 void TimeInt::MyDrawCircleXY(const Vector3D p, double r, const Vector3D& col, int res, double thickness) const
1796 {
1797 	if (IsFlagComputeMinMaxFECol()) return;
1798 
1799 	double ns = res;
1800 
1801 	//draw points must be Vector3D
1802 
1803 	double phi1, phi2;
1804 	for (int i=0; i < ns; i++)
1805 	{
1806 		phi1 = (double)i/ns*2.*MY_PI;
1807 		phi2 = (double)(i+1)/ns*2.*MY_PI;
1808 
1809 		Vector3D p1(sin(phi1)*r,cos(phi1)*r,0.);
1810 		Vector3D p2(sin(phi2)*r,cos(phi2)*r,0.);
1811 
1812 		MyDrawLine(p+p1,p+p2,thickness, col);
1813 	}
1814 }
1815 
1816 
1817 //+++++++++++++++++++++++++++++++++++++++++
AddDrawComponent_Line(int mbs_elnr,TMBSElementType mbs_type,int sub_elnr,TDrawElementType sub_type,Vector2D p1,Vector2D p2,Vector3D col)1818 void TimeInt::AddDrawComponent_Line(int mbs_elnr, TMBSElementType mbs_type, int sub_elnr, TDrawElementType sub_type, Vector2D p1, Vector2D p2, Vector3D col)
1819 {
1820 	ControlWindowContext::DrawComponent dcomp;
1821 	dcomp.mbs_type = mbs_type;
1822 	dcomp.mbs_elnr = mbs_elnr;
1823 	dcomp.sub_type = sub_type;
1824 	dcomp.sub_elnr = sub_elnr;
1825 	dcomp.geo_type = TGLine;
1826 
1827 	dcomp.P1() = p1;
1828 	dcomp.P2() = p2;
1829   dcomp.Color() = col;
1830   // dont set 2nd Color
1831 	// dont set text
1832 	p2DDrawWindow->AddDrawComponent(dcomp);
1833 }
1834 
AddDrawComponent_Rect(int mbs_elnr,TMBSElementType mbs_type,int sub_elnr,TDrawElementType sub_type,Vector2D center,Vector2D size,Vector3D col_border,Vector3D col_background)1835 void TimeInt::AddDrawComponent_Rect(int mbs_elnr, TMBSElementType mbs_type, int sub_elnr, TDrawElementType sub_type, Vector2D center, Vector2D size, Vector3D col_border, Vector3D col_background)
1836 {
1837 	ControlWindowContext::DrawComponent dcomp;
1838 	dcomp.mbs_type = mbs_type;
1839 	dcomp.mbs_elnr = mbs_elnr;
1840 	dcomp.sub_type = sub_type;
1841 	dcomp.sub_elnr = sub_elnr;
1842 	dcomp.geo_type = TGRectangle;
1843 	dcomp.Center() = center;
1844 	dcomp.Size() = size;
1845   dcomp.Color() = col_border;
1846 	dcomp.Background() = col_background;
1847   // dont set text
1848 	p2DDrawWindow->AddDrawComponent(dcomp);
1849 }
1850 
AddDrawComponent_Ellipse(int mbs_elnr,TMBSElementType mbs_type,int sub_elnr,TDrawElementType sub_type,Vector2D center,Vector2D size,Vector3D col_border,Vector3D col_background)1851 void TimeInt::AddDrawComponent_Ellipse(int mbs_elnr, TMBSElementType mbs_type, int sub_elnr, TDrawElementType sub_type, Vector2D center, Vector2D size, Vector3D col_border, Vector3D col_background)
1852 {
1853 	ControlWindowContext::DrawComponent dcomp;
1854 	dcomp.mbs_type = mbs_type;
1855 	dcomp.mbs_elnr = mbs_elnr;
1856 	dcomp.sub_type = sub_type;
1857 	dcomp.sub_elnr = sub_elnr;
1858 	dcomp.geo_type = TGEllipse;
1859 	dcomp.Center() = center;
1860 	dcomp.Size() = size;
1861   dcomp.Color() = col_border;
1862 	dcomp.Background() = col_background;
1863   // dont set text
1864 	p2DDrawWindow->AddDrawComponent(dcomp);
1865 }
1866 
AddDrawComponent_Text(int mbs_elnr,TMBSElementType mbs_type,int sub_elnr,TDrawElementType sub_type,Vector2D center,Vector2D size,Vector3D col_text,mystr & text,TTextAllign positioning)1867 void TimeInt::AddDrawComponent_Text(int mbs_elnr, TMBSElementType mbs_type, int sub_elnr, TDrawElementType sub_type, Vector2D center, Vector2D size, Vector3D col_text, mystr& text, TTextAllign positioning)
1868 {
1869 	ControlWindowContext::DrawComponent dcomp;
1870 	dcomp.mbs_type = mbs_type;
1871 	dcomp.mbs_elnr = mbs_elnr;
1872 	dcomp.sub_type = sub_type;
1873 	dcomp.sub_elnr = sub_elnr;
1874 	dcomp.geo_type = TGText;
1875 	dcomp.Center() = center;
1876 	dcomp.Size() = size;
1877   dcomp.Color() = col_text;
1878   // dont set 2nd Color
1879   dcomp.Text() = text;
1880 	dcomp.TextAllign() = positioning;
1881 	p2DDrawWindow->AddDrawComponent(dcomp);
1882 }