2009-01-13 04:40:13 +05:00
# include <mystdlib.h>
# include <myadt.hpp>
# include <meshing.hpp>
# include <visual.hpp>
2009-01-25 17:20:07 +05:00
// #include <parallel.hpp>
2009-01-13 04:40:13 +05:00
2009-02-05 04:09:28 +05:00
# ifndef WIN32
2009-01-13 04:40:13 +05:00
# define GLX_GLXEXT_LEGACY
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <X11/Xatom.h> /* for XA_RGB_DEFAULT_MAP atom */
2009-02-05 04:09:28 +05:00
// #include <GL/glx.h> // for parallel GL ???
2009-01-13 04:40:13 +05:00
# endif
namespace netgen
{
2011-03-04 02:42:20 +05:00
DLL_HEADER Point3d VisualScene : : center ;
DLL_HEADER double VisualScene : : rad ;
DLL_HEADER GLdouble VisualScene : : backcolor ;
2009-09-07 21:15:22 +06:00
/*
# if TOGL_MAJOR_VERSION!=2
2009-01-13 04:40:13 +05:00
GLuint VisualScene : : fontbase = 0 ;
2009-09-07 21:15:22 +06:00
# else
Tcl_Obj * VisualScene : : fontbase = NULL ;
Togl * VisualScene : : globtogl ;
# endif
*/
2009-01-13 04:40:13 +05:00
2014-10-08 18:46:25 +06:00
void ( * opengl_text_function ) ( const char * text ) = NULL ;
void Set_OpenGLText_Callback ( void ( * fun ) ( const char * text ) )
{
opengl_text_function = fun ;
}
2014-10-06 15:57:44 +06:00
void MyOpenGLText ( const char * text )
{
2014-10-08 18:46:25 +06:00
if ( opengl_text_function )
( * opengl_text_function ) ( text ) ;
// cout << "MyOpenGLText: " << text << endl;
2014-10-06 15:57:44 +06:00
}
2009-01-13 04:40:13 +05:00
// texture for color decoding
// GLubyte * VisualScene :: colortexture = NULL;
GLuint VisualScene : : coltexname = 1 ;
int VisualScene : : ntexcols = - 1 ;
2014-02-12 21:13:35 +06:00
double VisualScene : : lookatmat [ 16 ] ;
double VisualScene : : transmat [ 16 ] ;
double VisualScene : : rotmat [ 16 ] ;
double VisualScene : : centermat [ 16 ] ;
double VisualScene : : transformationmat [ 16 ] ;
2009-01-13 04:40:13 +05:00
int VisualScene : : selface ;
int VisualScene : : selelement ;
int VisualScene : : selpoint ;
int VisualScene : : selpoint2 ;
int VisualScene : : locpi ;
int VisualScene : : seledge ;
int VisualScene : : selecttimestamp ;
2012-10-29 23:52:31 +06:00
int VisualScene : : viewport [ 4 ] ;
2009-01-13 04:40:13 +05:00
VisualizationParameters : : VisualizationParameters ( )
{
lightamb = 0.3 ;
lightdiff = 0.7 ;
lightspec = 1 ;
shininess = 50 ;
transp = 0.3 ;
locviewer = 0 ;
showstltrias = 0 ;
centerpoint = 0 ;
usedispllists = 1 ;
strcpy ( selectvisual , " cross " ) ;
use_center_coords = false ;
} ;
VisualizationParameters vispar ;
double dist = 0 ;
// double dist = 6;
// vorher: pnear = 2;
2011-01-11 01:18:01 +05:00
// double pnear = 0.1;
// double pfar = 10;
2009-01-13 04:40:13 +05:00
VisualScene : : VisualScene ( )
{
changeval = - 1 ;
backcolor = 0 ;
}
VisualScene : : ~ VisualScene ( )
{
;
}
2014-12-04 15:24:45 +05:00
extern DLL_HEADER void Render ( bool blocking ) ;
DLL_HEADER void Render ( bool blocking )
2009-01-13 04:40:13 +05:00
{
2015-06-26 19:30:27 +05:00
if ( blocking & & multithread . running )
2014-12-04 15:24:45 +05:00
{
multithread . redraw = 2 ;
while ( multithread . redraw = = 2 ) ;
}
else
multithread . redraw = 1 ;
2009-01-13 04:40:13 +05:00
}
void VisualScene : : BuildScene ( int zoomall )
{
center = Point3d ( 0 , 0 , 0 ) ;
rad = 1 ;
CalcTransformationMatrices ( ) ;
glEnable ( GL_DEPTH_TEST ) ;
glDisable ( GL_DITHER ) ;
GLfloat ambvals [ ] = { 0.4f , 0.4f , 0.4f , 1.0f } ;
GLfloat diffvals [ ] = { 0.5f , 0.5f , 0.5f , 1.0f } ;
GLfloat specvals [ ] = { 0.7f , 0.7f , 0.7f , 1.0f } ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambvals ) ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , diffvals ) ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , specvals ) ;
GLfloat light_position [ ] = { 1 , 3 , 3 , 0 } ;
glLightfv ( GL_LIGHT0 , GL_POSITION , light_position ) ;
glLightModeli ( GL_LIGHT_MODEL_TWO_SIDE , 0 ) ;
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
}
void VisualScene : : DrawScene ( )
{
if ( changeval = = - 1 )
BuildScene ( ) ;
changeval = 0 ;
glClearColor ( backcolor , backcolor , backcolor , 1.0 ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glColor3f ( 1.0f , 1.0f , 1.0f ) ;
glLineWidth ( 1.0f ) ;
DrawCoordinateCross ( ) ;
DrawNetgenLogo ( ) ;
glFinish ( ) ;
}
void VisualScene : : CalcTransformationMatrices ( )
{
// prepare model view matrix
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
gluLookAt ( 0 , 0 , 6 , 0 , 0 , 0 , 0 , 1 , 0 ) ;
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , lookatmat ) ;
2009-01-13 04:40:13 +05:00
glLoadIdentity ( ) ;
glTranslatef ( 0.0f , 0.0f , - dist ) ;
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , transmat ) ;
2009-01-13 04:40:13 +05:00
glLoadIdentity ( ) ;
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , rotmat ) ;
2009-01-13 04:40:13 +05:00
2014-02-12 21:13:35 +06:00
glScaled ( 1 / rad , 1 / rad , 1 / rad ) ;
2009-01-13 04:40:13 +05:00
glTranslated ( - center . X ( ) , - center . Y ( ) , - center . Z ( ) ) ;
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , centermat ) ;
2009-01-13 04:40:13 +05:00
glLoadIdentity ( ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( lookatmat ) ;
glMultMatrixd ( transmat ) ;
glMultMatrixd ( rotmat ) ;
glMultMatrixd ( centermat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transformationmat ) ;
2009-01-13 04:40:13 +05:00
glPopMatrix ( ) ;
}
2009-01-25 17:35:25 +05:00
void VisualScene : : ArbitraryRotation ( const Array < double > & alpha , const Array < Vec3d > & vec )
2009-01-13 04:40:13 +05:00
{
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
for ( int i = 0 ; i < alpha . Size ( ) & & i < vec . Size ( ) ; i + + )
{
glRotatef ( alpha [ i ] , vec [ i ] . X ( ) , vec [ i ] . Y ( ) , vec [ i ] . Z ( ) ) ;
}
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , rotmat ) ;
2009-01-13 04:40:13 +05:00
glLoadIdentity ( ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( lookatmat ) ;
glMultMatrixd ( transmat ) ;
glMultMatrixd ( rotmat ) ;
glMultMatrixd ( centermat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transformationmat ) ;
2009-01-13 04:40:13 +05:00
glPopMatrix ( ) ;
}
void VisualScene : : ArbitraryRotation ( const double alpha , const Vec3d & vec )
{
2009-01-25 17:35:25 +05:00
Array < double > a ( 1 ) ; a [ 0 ] = alpha ;
Array < Vec3d > v ( 1 ) ; v [ 0 ] = vec ;
2009-01-13 04:40:13 +05:00
ArbitraryRotation ( a , v ) ;
}
void VisualScene : : StandardRotation ( const char * dir )
{
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
if ( strcmp ( dir , " xy " ) = = 0 )
;
else if ( strcmp ( dir , " yx " ) = = 0 )
glRotatef ( 180.0 , 1.0f , 1.0f , 0.0f ) ;
else if ( strcmp ( dir , " xz " ) = = 0 )
glRotatef ( - 90.0 , 1.0f , 0.0f , 0.0f ) ;
else if ( strcmp ( dir , " zx " ) = = 0 )
{
glRotatef ( 180.0 , 1.0f , 1.0f , 0.0f ) ;
glRotatef ( - 90.0 , 1.0f , 0.0f , 0.0f ) ;
}
else if ( strcmp ( dir , " yz " ) = = 0 )
{
glRotatef ( - 90.0 , 0.0f , 0.0f , 1.0f ) ;
glRotatef ( - 90.0 , 0.0f , 1.0f , 0.0f ) ;
}
else if ( strcmp ( dir , " zy " ) = = 0 )
glRotatef ( 90.0 , 0.0f , 1.0f , 0.0f ) ;
2014-02-12 21:13:35 +06:00
glGetDoublev ( GL_MODELVIEW_MATRIX , rotmat ) ;
2009-01-13 04:40:13 +05:00
glLoadIdentity ( ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( lookatmat ) ;
glMultMatrixd ( transmat ) ;
glMultMatrixd ( rotmat ) ;
glMultMatrixd ( centermat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transformationmat ) ;
2009-01-13 04:40:13 +05:00
glPopMatrix ( ) ;
}
void VisualScene : : MouseMove ( int oldx , int oldy ,
int newx , int newy ,
char mode )
{
int deltax = newx - oldx ;
int deltay = newy - oldy ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
switch ( mode )
{
case ' r ' :
{
glRotatef ( float ( deltax ) / 2 , 0.0f , 1.0f , 0.0f ) ;
glRotatef ( float ( deltay ) / 2 , 1.0f , 0.0f , 0.0f ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( rotmat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , rotmat ) ;
2009-01-13 04:40:13 +05:00
break ;
}
case ' m ' :
{
GLdouble projmat [ 16 ] , modelviewmat [ 16 ] ;
GLint viewport [ 4 ] ;
glGetDoublev ( GL_PROJECTION_MATRIX , projmat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , modelviewmat ) ;
glGetIntegerv ( GL_VIEWPORT , viewport ) ;
// vorher pvz1/2 = 0
GLdouble pvx1 = 0 , pvy1 = 0 , pvz1 = 0.99 ; // 0.95;
GLdouble pvx2 = deltax , pvy2 = - deltay , pvz2 = 0.99 ; // 0.95;
GLdouble px1 , py1 , pz1 ;
GLdouble px2 , py2 , pz2 ;
gluUnProject ( pvx1 , pvy1 , pvz1 ,
modelviewmat , projmat , viewport ,
& px1 , & py1 , & pz1 ) ;
gluUnProject ( pvx2 , pvy2 , pvz2 ,
modelviewmat , projmat , viewport ,
& px2 , & py2 , & pz2 ) ;
/*
gluUnProject ( oldx , oldy , 1 ,
modelviewmat , projmat , viewport ,
& px1 , & py1 , & pz1 ) ;
gluUnProject ( newx , newy , 1 ,
modelviewmat , projmat , viewport ,
& px2 , & py2 , & pz2 ) ;
*/
/*
cout < < " pv1 = " < < pvx1 < < " , " < < pvy1 < < " , " < < pvz1 < < endl ;
cout < < " p1 = " < < px1 < < " , " < < py1 < < " , " < < pz1 < < endl ;
*/
glTranslated ( px2 - px1 , py2 - py1 , pz2 - pz1 ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( transmat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transmat ) ;
2009-01-13 04:40:13 +05:00
break ;
}
case ' z ' :
{
// glTranslatef(0.0f, 0.0f, -dist);
// cout << "deltay = " << deltay << endl;
// cout << "float_bug = " << (float(deltay)/100) << endl; gives wrong result with icc 9.0.021
glScaled ( exp ( double ( - deltay ) / 100 ) ,
exp ( double ( - deltay ) / 100 ) ,
exp ( double ( - deltay ) / 100 ) ) ;
// glTranslatef(0.0f, 0.0f, dist);
2014-02-12 21:13:35 +06:00
glMultMatrixd ( transmat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transmat ) ;
2009-01-13 04:40:13 +05:00
break ;
}
}
glLoadIdentity ( ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( lookatmat ) ;
glMultMatrixd ( transmat ) ;
glMultMatrixd ( rotmat ) ;
glMultMatrixd ( centermat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transformationmat ) ;
2009-01-13 04:40:13 +05:00
glPopMatrix ( ) ;
}
void VisualScene : : LookAt ( const Point < 3 > & cam , const Point < 3 > & obj ,
const Point < 3 > & camup )
{
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
gluLookAt ( cam ( 0 ) , cam ( 1 ) , cam ( 2 ) ,
obj ( 0 ) , obj ( 1 ) , obj ( 2 ) ,
camup ( 0 ) , camup ( 1 ) , camup ( 2 ) ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( centermat ) ;
glGetDoublev ( GL_MODELVIEW_MATRIX , transformationmat ) ;
2009-01-13 04:40:13 +05:00
glPopMatrix ( ) ;
}
void VisualScene : : SetClippingPlane ( )
{
2012-11-05 17:28:36 +06:00
if ( vispar . clipping . enable )
2009-01-13 04:40:13 +05:00
{
2012-11-05 17:28:36 +06:00
Vec3d n = vispar . clipping . normal ;
2009-01-13 04:40:13 +05:00
n / = ( n . Length ( ) + 1e-10 ) ;
clipplane [ 0 ] = n . X ( ) ;
clipplane [ 1 ] = n . Y ( ) ;
clipplane [ 2 ] = n . Z ( ) ;
2012-11-05 17:28:36 +06:00
clipplane [ 3 ] = - ( Vec3d ( center ) * n ) + rad * vispar . clipping . dist ;
2009-01-13 04:40:13 +05:00
2013-02-03 20:41:44 +06:00
double clipplane2 [ 4 ] ;
clipplane2 [ 0 ] = n . X ( ) ;
clipplane2 [ 1 ] = n . Y ( ) ;
clipplane2 [ 2 ] = n . Z ( ) ;
clipplane2 [ 3 ] = - ( Vec3d ( center ) * n ) +
rad * ( vispar . clipping . dist + vispar . clipping . dist2 ) ;
glClipPlane ( GL_CLIP_PLANE0 , clipplane2 ) ;
2009-01-13 04:40:13 +05:00
glEnable ( GL_CLIP_PLANE0 ) ;
}
else
glDisable ( GL_CLIP_PLANE0 ) ;
}
void VisualScene : : MouseDblClick ( int /* px */ , int /* py */ )
{
;
}
void VisualScene : : SetLight ( )
{
GLfloat vals [ 3 ] ;
double lightamb = vispar . lightamb ;
vals [ 0 ] = vals [ 1 ] = vals [ 2 ] = lightamb ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , vals ) ;
double lightdiff = vispar . lightdiff ;
vals [ 0 ] = vals [ 1 ] = vals [ 2 ] = lightdiff ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , vals ) ;
double lightspec = vispar . lightspec ;
vals [ 0 ] = vals [ 1 ] = vals [ 2 ] = lightspec ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , vals ) ;
glMaterialf ( GL_FRONT_AND_BACK , GL_SHININESS , vispar . shininess ) ;
glLightModeli ( GL_LIGHT_MODEL_LOCAL_VIEWER , vispar . locviewer ) ;
float mat_spec_col [ ] = { 1 , 1 , 1 , 1 } ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_SPECULAR , mat_spec_col ) ;
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
}
void VisualScene : : SetOpenGlColor ( double val , double valmin , double valmax ,
int logscale )
{
double value ;
if ( ! logscale )
value = ( val - valmin ) / ( valmax - valmin ) ;
else
{
if ( valmax < = 0 ) valmax = 1 ;
if ( valmin < = 0 ) valmin = 1e-4 * valmax ;
value = ( log ( fabs ( val ) ) - log ( valmin ) ) / ( log ( valmax ) - log ( valmin ) ) ;
}
if ( ! invcolor )
value = 1 - value ;
glTexCoord1f ( 0.998 * value + 0.001 ) ;
// glTexCoord1f ( val );
glTexCoord2f ( 0.998 * value + 0.001 , 1.5 ) ;
// glTexCoord1f ( value );
if ( value > 1 ) value = 1 ;
if ( value < 0 ) value = 0 ;
value * = 4 ;
static const double colp [ ] [ 3 ] =
{
{ 1 , 0 , 0 } ,
{ 1 , 1 , 0 } ,
{ 0 , 1 , 0 } ,
{ 0 , 1 , 1 } ,
{ 0 , 0 , 1 } ,
// { 1, 0, 1 },
// { 1, 0, 0 },
} ;
int i = int ( value ) ;
double r = value - i ;
GLdouble col [ 3 ] ;
for ( int j = 0 ; j < 3 ; j + + )
col [ j ] = ( 1 - r ) * colp [ i ] [ j ] + r * colp [ i + 1 ] [ j ] ;
glColor3d ( col [ 0 ] , col [ 1 ] , col [ 2 ] ) ;
}
2013-02-03 20:41:44 +06:00
void VisualScene : : CreateTexture ( int ncols , int linear , double alpha , int typ )
2009-01-13 04:40:13 +05:00
{
if ( linear ) ncols = 32 ;
else ncols = 8 ;
if ( ntexcols ! = ncols )
{
ntexcols = ncols ;
GLubyte colortexture [ 4 * 32 ] ;
const double colp [ ] [ 3 ] =
{
{ 1 , 0 , 0 } ,
{ 1 , 1 , 0 } ,
{ 0 , 1 , 0 } ,
{ 0 , 1 , 1 } ,
{ 0 , 0 , 1 } ,
} ;
for ( int i = 0 ; i < ncols ; i + + )
{
double value = 4.0 * i / ( ncols - 1 ) ;
int iv = int ( value ) ;
double r = value - iv ;
GLdouble col [ 3 ] ;
if ( r > 1e-3 )
for ( int j = 0 ; j < 3 ; j + + )
col [ j ] = ( 1. - r ) * colp [ iv ] [ j ] + r * colp [ iv + 1 ] [ j ] ;
else
for ( int j = 0 ; j < 3 ; j + + )
col [ j ] = colp [ iv ] [ j ] ;
colortexture [ 4 * i ] = GLubyte ( 255 * col [ 0 ] ) ;
colortexture [ 4 * i + 1 ] = GLubyte ( 255 * col [ 1 ] ) ;
colortexture [ 4 * i + 2 ] = GLubyte ( 255 * col [ 2 ] ) ;
2013-02-03 20:41:44 +06:00
colortexture [ 4 * i + 3 ] = GLubyte ( 255 * alpha ) ;
2009-01-13 04:40:13 +05:00
}
// glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage1D ( GL_TEXTURE_1D , 0 , 4 , ncols , 0 , GL_RGBA , GL_UNSIGNED_BYTE , colortexture ) ;
glTexImage2D ( GL_TEXTURE_2D , 0 , 4 , ncols , 1 , 0 , GL_RGBA , GL_UNSIGNED_BYTE , colortexture ) ;
2011-03-04 02:35:06 +05:00
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , typ ) ; // DECAL or MODULATE
2009-01-13 04:40:13 +05:00
GLfloat bcol [ ] = { 1 , 1 , 1 , 1.0 } ;
glTexParameterfv ( GL_TEXTURE_1D , GL_TEXTURE_BORDER_COLOR , bcol ) ;
glTexParameteri ( GL_TEXTURE_1D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ;
glTexParameterfv ( GL_TEXTURE_2D , GL_TEXTURE_BORDER_COLOR , bcol ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ;
if ( linear )
{
glTexParameteri ( GL_TEXTURE_1D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_1D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ;
}
else
{
glTexParameteri ( GL_TEXTURE_1D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_1D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ;
}
}
}
void VisualScene : : DrawColorBar ( double minval , double maxval , int logscale , bool linear )
{
if ( ! vispar . drawcolorbar ) return ;
2013-02-03 20:41:44 +06:00
CreateTexture ( 8 , linear , 1 , GL_DECAL ) ;
2009-01-13 04:40:13 +05:00
if ( logscale & & maxval < = 0 ) maxval = 1 ;
if ( logscale & & minval < = 0 ) minval = 1e-4 * maxval ;
double minx = - 1 ;
double maxx = 1 ;
double miny = 0.75 ;
double maxy = 0.8 ;
glDisable ( GL_LIGHTING ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glEnable ( GL_TEXTURE_1D ) ;
glNormal3d ( 0 , 0 , 1 ) ;
glPolygonMode ( GL_FRONT_AND_BACK , GL_FILL ) ;
glDisable ( GL_DEPTH_TEST ) ;
glBegin ( GL_QUAD_STRIP ) ;
for ( double x = minx ; x < = maxx ; x + = ( maxx - minx ) / 50 )
{
SetOpenGlColor ( x , minx , maxx ) ;
glVertex3d ( x , miny , - 5 ) ;
glVertex3d ( x , maxy , - 5 ) ;
}
glEnd ( ) ;
glDisable ( GL_TEXTURE_1D ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
2014-08-15 20:46:26 +06:00
GLfloat textcol [ 3 ] = { GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) } ;
2009-01-13 04:40:13 +05:00
glColor3fv ( textcol ) ;
glPushAttrib ( GL_LIST_BIT ) ;
2009-09-07 21:15:22 +06:00
// glListBase (fontbase);
2009-01-13 04:40:13 +05:00
char buf [ 20 ] ;
for ( int i = 0 ; i < = 4 ; i + + )
{
double x = minx + i * ( maxx - minx ) / 4 ;
glRasterPos3d ( x , 0.7 , - 5 ) ;
double val ;
if ( logscale )
val = minval * pow ( maxval / minval , i / 4.0 ) ;
else
val = minval + i * ( maxval - minval ) / 4 ;
sprintf ( buf , " %8.3e " , val ) ;
2009-09-07 21:15:22 +06:00
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
MyOpenGLText ( buf ) ;
2009-01-13 04:40:13 +05:00
}
glPopAttrib ( ) ;
glEnable ( GL_DEPTH_TEST ) ;
}
void VisualScene : : DrawCoordinateCross ( )
{
if ( ! vispar . drawcoordinatecross ) return ;
glDisable ( GL_DEPTH_TEST ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
GLint viewport [ 4 ] ;
glGetIntegerv ( GL_VIEWPORT , viewport ) ;
glTranslatef ( - 1 , - 1 , 0.0 ) ;
glScalef ( 40.0 / viewport [ 2 ] , 40.0 / viewport [ 3 ] , 1 ) ;
glTranslatef ( 2.0 , 2.0 , 0.0 ) ;
2014-02-12 21:13:35 +06:00
glMultMatrixd ( rotmat ) ;
2009-01-13 04:40:13 +05:00
glEnable ( GL_COLOR_MATERIAL ) ;
glDisable ( GL_LIGHTING ) ;
glPolygonMode ( GL_FRONT_AND_BACK , GL_LINE ) ;
2014-08-15 20:46:26 +06:00
GLfloat textcol [ 3 ] = { GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) } ;
2009-01-13 04:40:13 +05:00
glColor3fv ( textcol ) ;
glLineWidth ( 1.0f ) ;
double len = 1 ;
glBegin ( GL_LINES ) ;
glVertex3d ( 0 , 0 , 0 ) ;
glVertex3d ( len , 0 , 0 ) ;
glVertex3d ( 0.0f , 0.0f , 0.0f ) ;
glVertex3d ( 0.0f , len , 0.0f ) ;
glVertex3d ( 0.0f , 0.0f , 0.0f ) ;
glVertex3d ( 0.0f , 0.0f , len ) ;
glEnd ( ) ;
glPushAttrib ( GL_LIST_BIT ) ;
2009-09-07 21:15:22 +06:00
// glListBase (fontbase);
2009-01-13 04:40:13 +05:00
char buf [ 20 ] ;
glRasterPos3d ( len , 0.0f , 0.0f ) ;
sprintf ( buf , " x " ) ;
2009-09-07 21:15:22 +06:00
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
MyOpenGLText ( buf ) ;
2009-01-13 04:40:13 +05:00
glRasterPos3d ( 0.0f , len , 0.0f ) ;
sprintf ( buf , " y " ) ;
2009-09-07 21:15:22 +06:00
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
MyOpenGLText ( buf ) ;
2009-01-13 04:40:13 +05:00
glRasterPos3d ( 0.0f , 0.0f , len ) ;
sprintf ( buf , " z " ) ;
2009-09-07 21:15:22 +06:00
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
MyOpenGLText ( buf ) ;
2009-01-13 04:40:13 +05:00
glPopAttrib ( ) ;
glEnable ( GL_LIGHTING ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glPopMatrix ( ) ;
glEnable ( GL_DEPTH_TEST ) ;
}
void VisualScene : : DrawNetgenLogo ( )
{
if ( ! vispar . drawnetgenlogo ) return ;
glDisable ( GL_DEPTH_TEST ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
GLint viewport [ 4 ] ;
glGetIntegerv ( GL_VIEWPORT , viewport ) ;
glTranslatef ( 1 , - 1 , 0.0 ) ;
glScalef ( 40.0 / viewport [ 2 ] , 40.0 / viewport [ 3 ] , 1 ) ;
2009-03-20 10:59:47 +05:00
glTranslatef ( - 7.0 , 2.0 , 0.0 ) ;
2009-01-13 04:40:13 +05:00
glDisable ( GL_CLIP_PLANE0 ) ;
glDisable ( GL_LIGHTING ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
2014-08-15 20:46:26 +06:00
GLfloat textcol [ 3 ] = { GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) ,
GLfloat ( 1 - backcolor ) } ;
2009-01-13 04:40:13 +05:00
glColor3fv ( textcol ) ;
glLineWidth ( 1.0f ) ;
glPushAttrib ( GL_LIST_BIT ) ;
2009-09-07 21:15:22 +06:00
// glListBase (fontbase);
2009-01-13 04:40:13 +05:00
2009-01-16 01:41:14 +05:00
char buf [ ] = " Netgen " PACKAGE_VERSION ;
2009-01-13 04:40:13 +05:00
glRasterPos3d ( 0.0f , 0.0f , 0.0f ) ;
2009-09-07 21:15:22 +06:00
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
MyOpenGLText ( buf ) ;
2009-01-13 04:40:13 +05:00
glPopAttrib ( ) ;
glEnable ( GL_LIGHTING ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glPopMatrix ( ) ;
glEnable ( GL_DEPTH_TEST ) ;
}
# ifdef PARALLELGL
void VisualScene : : InitParallelGL ( )
{
static int init = 0 ;
if ( ! init )
{
init = 1 ;
if ( id = = 0 )
{
string displname ;
2016-11-07 21:49:38 +05:00
Display * dpy = glXGetCurrentDisplay ( ) ;
2009-01-13 04:40:13 +05:00
GLXDrawable drawable = glXGetCurrentDrawable ( ) ;
GLXContext ctx = glXGetCurrentContext ( ) ;
GLXContextID xid = glXGetContextIDEXT ( ctx ) ;
displname = XDisplayName ( 0 ) ;
2011-02-14 18:01:51 +05:00
2016-11-07 21:49:38 +05:00
if ( glXIsDirect ( dpy , ctx ) )
cout < < " WARNING: direct rendering enabled; this might break mpi-parallel netgen (especially if X-forwarding is used! (to disable, change -indirect to true in ng/drawing.tcl) " < < endl ;
2012-06-13 15:07:11 +06:00
/*
2009-01-13 04:40:13 +05:00
cout < < " Init Parallel GL " < < endl ;
cout < < " DisplayName = " < < displname < < endl ;
cout < < " current display = " < < dpy < < endl ;
cout < < " current drawable = " < < drawable < < endl ;
cout < < " current context = " < < ctx < < endl ;
cout < < " contextid = " < < xid < < endl ;
cout < < " isdirect = " < < glXIsDirect ( dpy , ctx ) < < endl ;
cout < < " extensionstring = " < < glXQueryExtensionsString ( dpy , 0 ) < < endl ;
2011-02-14 17:27:18 +05:00
*/
2009-01-13 04:40:13 +05:00
2011-07-15 03:36:19 +06:00
MyMPI_SendCmd ( " redraw " ) ;
MyMPI_SendCmd ( " init " ) ;
2011-07-07 03:08:58 +06:00
for ( int dest = 1 ; dest < ntasks ; dest + + )
2009-01-13 04:40:13 +05:00
{
2011-07-07 03:08:58 +06:00
MyMPI_Send ( displname , dest , MPI_TAG_VIS ) ;
MyMPI_Send ( int ( drawable ) , dest , MPI_TAG_VIS ) ;
MyMPI_Send ( int ( xid ) , dest , MPI_TAG_VIS ) ;
2009-01-13 04:40:13 +05:00
}
}
}
}
void VisualScene : : Broadcast ( )
{
if ( ntasks = = 1 ) return ;
if ( id = = 0 )
{
2011-07-15 03:36:19 +06:00
/*
2009-01-13 04:40:13 +05:00
for ( int dest = 1 ; dest < ntasks ; dest + + )
{
2011-07-07 03:08:58 +06:00
MyMPI_Send ( " redraw " , dest , MPI_TAG_CMD ) ;
MyMPI_Send ( " broadcast " , dest , MPI_TAG_VIS ) ;
2009-01-13 04:40:13 +05:00
}
2011-07-15 03:36:19 +06:00
*/
MyMPI_SendCmd ( " redraw " ) ;
MyMPI_SendCmd ( " broadcast " ) ;
2009-01-13 04:40:13 +05:00
}
MyMPI_Bcast ( selface ) ;
vssolution . Broadcast ( ) ;
}
# endif
}