home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum23.lzh
/
f23b
/
SOFTWARE
/
PDRAW
/
plotNOX.c
< prev
next >
Wrap
Text File
|
1992-01-15
|
42KB
|
1,320 lines
/* plotX.c - all the X11 routines ***/
#ifdef X
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/keysym.h>
#include <stdio.h>
#include <strings.h>
#include <math.h>
#include "header.h"
#include "Xdefs.h"
#include "iconX11.ic"
/* colors */
#define DEFAULT_BORDER_COLOR "Blue"
#define DEFAULT_BACK_COLOR "MidNightBlue"
#define DEFAULT_FORE_COLOR "White"
#define DEFAULT_MOUSE_COLOR "White"
#define DEFAULT_ICON_COLOR "Red"
#define BDR_C 0
#define BACK_C 1
#define FORE_C 2
#define MOUSE_C 3
#define ICON_C 4
#define LINE1_C 5
#define LINE2_C 6
#define LINE3_C 7
#define LINE4_C 8
#define LINE5_C 9
#define BACK2_C 10
#define MAX_COLORS 11
unsigned long border_pixel; /* color of border */
unsigned long background_pixel; /* color of background */
unsigned long foreground_pixel; /* color of foreground */
unsigned long mouseground_pixel; /* mouse cursor color */
unsigned long icon_pixel; /* icon color */
unsigned long colors[MAX_COLORS]; /* color pixel values */
char *clr_name[MAX_COLORS]; /* color names */
/* line-types */
# define DOTTED 2
# define SHORT_DOTTED 2
# define LONG_DOTTED 2
# define DASHED 2
# define DOT_DASHED 4
# define DASH_DOTTED 4
# define SHORT_DASHED 2
# define LONG_DASHED 2
# define EQUAL_DASHED 2
# define ODD_DASHED 3
static unsigned char dash_list_dotted[DOTTED] = {1,6};
static unsigned char dash_list_short_dotted[SHORT_DOTTED] = {1,3};
static unsigned char dash_list_long_dotted[LONG_DOTTED] = {1,8};
static unsigned char dash_list_dashed[DASHED] = {4,4};
static unsigned char dash_list_dot_dashed[DOT_DASHED] = {3,4,3,1};
static unsigned char dash_list_dash_dotted[DASH_DOTTED] = {4,3,1,3};
static unsigned char dash_list_short_dashed[SHORT_DASHED] = {3,5};
static unsigned char dash_list_equal_dashed[EQUAL_DASHED] = {6,6};
static unsigned char dash_list_long_dashed[LONG_DASHED] = {7,4};
static unsigned char dash_list_odd_dashed[ODD_DASHED] = {1,2,3};
/* characters */
#define EVO 1
#define EVL 2
#define EVJ 3
#define EVK 4
#define EVH 5
#define EVF 6
#define EVS 7
#define EVD 8
#define EVA 9
#define EVX 10
#define EVY 11
#define EVZ 12
/* buttons */
char button_label[10][100];
#define REVERSE 0
#define NORMAL 1
#define NBUTTONS 7
#define B_HEIGHT 20
/* plot information */
#define X_ORG 5
#define Y_ORG 5
#define X_DIM 600
#define Y_DIM 600
#define DEFAULT_BDR_DIM 100
int Width, Height;
/* Misc */
#define DEFAULT_BORDER_WIDTH 3
#define DEFAULT_FONT "8x13"
short gray_bits[16] = {
0xaaaa, 0x5555, 0xaaaa, 0x5555,
0xaaaa, 0x5555, 0xaaaa, 0x5555,
0xaaaa, 0x5555, 0xaaaa, 0x5555,
0xaaaa, 0x5555, 0xaaaa, 0x5555};
Display *display; /* display */
int screen; /* screen */
Window vwwindow; /* parent window */
Window buttons[NBUTTONS]; /* button windows */
XFontStruct *font_info; /* font information */
XSizeHints size_hints; /* window info for manager */
GC gc; /* graphics context */
GC bgc, bgcr; /* graphics context, buttons */
#endif
InitWindow(argc,argv)
int argc;
char **argv;
{
#ifdef X
Pixmap icon_pixmap;
XGCValues gcvalues;
char *sprintf(), default_geometry[100];
int i, x, y, width, height;
double bwd;
/* Open display first, and get screen info */
if (!(display = XOpenDisplay(display_name))) {
fprintf(stderr,"%s:Could not open display %s\n",
progname,display_name);
exit(1);
}
screen = DefaultScreen(display);
sprintf(default_geometry,"=%dx%d+%d+%d",X_DIM,Y_DIM,X_ORG,Y_ORG);
/* Merge the options first */
Merge_Options();
/* allocate the colors */
Alloc_Colors();
/* Initialize the window */
if (!XGeometry(display,screen,geometry,default_geometry,border_width,
0,0,0,0,&x,&y,&width,&height)) {
x = X_ORG;
y = Y_ORG;
width = X_DIM;
height = Y_DIM;
}
vwwindow = XCreateSimpleWindow(display, RootWindow(display,screen),
x, y, width, height, border_width,
border_pixel, background_pixel);
/* make buttons */
bwd = (width-10)/((double)(NBUTTONS-2));
buttons[0]= XCreateSimpleWindow(display, vwwindow,
5, 5, (int)(width-10-bwd), B_HEIGHT,1,
border_pixel, background_pixel);
buttons[1]= XCreateSimpleWindow(display, vwwindow,
(int)(5+width-10-bwd), 5, (int)bwd, B_HEIGHT,1,
border_pixel, background_pixel);
for (i=2; i<NBUTTONS; i++) {
buttons[i]= XCreateSimpleWindow(display, vwwindow,
5+(int)(bwd*(i-2)),5+B_HEIGHT,
(int)bwd,B_HEIGHT,1,
border_pixel, background_pixel);
}
/* Initialize size hint property for window manager */
size_hints.flags = PPosition | PSize | PMinSize;
size_hints.x = x;
size_hints.y = y;
size_hints.width = width;
size_hints.height = height;
size_hints.min_width = X_DIM;
size_hints.min_height = Y_DIM;
/* Create pixmap of depth 1 (bitmap) for icon */
icon_pixmap = XCreateBitmapFromData(display, vwwindow, icon_bitmap_bits,
icon_bitmap_width, icon_bitmap_height);
/* set properties for window manager */
XSetStandardProperties(display, vwwindow, "Pdraw Program", "Pdraw",
icon_pixmap, argv, argc, &size_hints);
/* Select event types wanted */
XSelectInput(display,vwwindow,ExposureMask | ButtonPressMask |
ButtonReleaseMask | KeyPressMask | StructureNotifyMask );
for (i=0; i<NBUTTONS; i++)
XSelectInput(display,buttons[i],ExposureMask | ButtonPressMask |
ButtonReleaseMask);
/* Create GC for text and drawing */
gc = XCreateGC(display, vwwindow, 0, &gcvalues);
/* create 2 graphics contexts for buttons */
bgc = XCreateGC(display, vwwindow, 0, NULL);
XSetForeground(display, bgc, background_pixel);
bgcr = XCreateGC(display, vwwindow, 0, NULL);
XSetForeground(display, bgcr, foreground_pixel);
/* Find a font and load it */
if (!(font_info = XLoadQueryFont(display,font_name))){
fprintf(stderr,"%s:Could not open font %s\n",progname,font_name);
exit(1);
}
XSetFont(display, gc, font_info->fid);
/* specify foreground */
XSetForeground(display, gc, foreground_pixel);
/* Display the window */
XMapSubwindows(display, vwwindow);
XMapWindow(display, vwwindow);
#endif
}
/* Initialize and merge the various options */
Merge_Options()
{
#ifdef X
char *option;
/* process the various options */
if (reverse < 0) {
if ((option = XGetDefault(display,progname,"ReverseVideo")) != NULL)
if (strcmp(option,"on")) reverse = 1;
}
if (!geometry) {
option = XGetDefault(display,progname,"Geometry");
geometry = option ? option : "=+5+5";
}
if (!font_name) {
/* option = XGetDefault(display,progname,"BodyFont"); */
font_name = DEFAULT_FONT;
}
if (!border_color) {
option = XGetDefault(display,progname,"Border");
border_color = option ? option : DEFAULT_BORDER_COLOR;
}
if (!back_color) {
option = XGetDefault(display,progname,"Background");
back_color = option ? option : DEFAULT_BACK_COLOR;
}
if (!fore_color) {
option = XGetDefault(display,progname,"Foreground");
fore_color = option ? option : DEFAULT_FORE_COLOR;
}
if (!mouse_color) {
option = XGetDefault(display,progname,"Mouse");
mouse_color = option ? option : DEFAULT_MOUSE_COLOR;
}
if (!icon_color) {
option = XGetDefault(display,progname,"Icon");
icon_color = option ? option : DEFAULT_ICON_COLOR;
}
if (border_width <= 0) {
option = XGetDefault(display,progname,"BorderWidth");
border_width = option ? atoi(option) : DEFAULT_BORDER_WIDTH;
}
#endif
}
/* allocate the colors on color display */
Alloc_Colors()
{
#ifdef X
XColor cdef;
Colormap cmap;
int i, depth;
unsigned long tmp_pixel;
/* get info on depth and colormap */
depth = DisplayPlanes(display,screen);
cmap = DefaultColormap(display,screen);
/* associate named colors with pixel values */
if (depth == 1) { /* one-plane monochrome */
colors[BDR_C] = BlackPixel(display,screen);
colors[BACK_C] = BlackPixel(display,screen);
colors[BACK2_C] = BlackPixel(display,screen);
colors[FORE_C] = WhitePixel(display,screen);
colors[MOUSE_C] = colors[FORE_C];
colors[ICON_C] = colors[FORE_C];
for (i=LINE1_C; i<=LINE5_C; i++) colors[i] = colors[FORE_C];
} else { /* color */
clr_name[BDR_C] = border_color;
clr_name[BACK_C] = back_color;
clr_name[BACK2_C] = "MediumBlue";
clr_name[FORE_C] = fore_color;
clr_name[MOUSE_C] = mouse_color;
clr_name[ICON_C] = icon_color;
clr_name[LINE1_C] = "red";
clr_name[LINE2_C] = "yellow";
clr_name[LINE3_C] = "MediumBlue";
clr_name[LINE4_C] = "green";
clr_name[LINE5_C] = "blue";
for (i=0; i<MAX_COLORS; i++)
if (XAllocNamedColor(display,cmap,clr_name[i],&cdef,&cdef))
colors[i] = cdef.pixel;
else {
fprintf(stderr,"%s: Can't allocate color %s\n",
progname, clr_name[i]);
exit(1);
} /* end if */
} /* end if */
/* assign pixel values */
border_pixel = colors[BDR_C];
background_pixel = colors[BACK_C];
foreground_pixel = colors[FORE_C];
mouseground_pixel = colors[MOUSE_C];
icon_pixel = colors[ICON_C];
/* reverse video */
if (reverse) {
tmp_pixel = background_pixel;
background_pixel = foreground_pixel;
foreground_pixel = tmp_pixel;
if (border_pixel == background_pixel)
border_pixel = foreground_pixel;
if (mouseground_pixel == background_pixel)
mouseground_pixel = foreground_pixel;
for (i=LINE1_C; i<=LINE5_C; i++)
if (colors[i]==background_pixel) colors[i] = foreground_pixel;
}
#endif
}
RunOps()
{
#ifdef X
XEvent event;
KeySym keysym;
XComposeStatus compose;
char buffer[1];
int bufsize = 1;
int i;
double theta = 0.0;
double phi = 0.0;
unsigned int button;
static char *event_name[] = {
"",
"",
"KeyPress",
"KeyRelease",
"ButtonPress",
"ButtonRelease",
"MotionNotify",
"EnterNotify",
"LeaveNotify",
"FocusIn",
"FocusOut",
"KeymapNotify",
"Expose",
"GraphicsExpose",
"NoExpose",
"VisibilityNotify",
"CreateNotify",
"DestroyNotify",
"UnmapNotify",
"MapNotify",
"MapRequest",
"ReparentNotify",
"ConfigureNotify",
"ConfigureRequest",
"GravityNotify",
"ResizeRequest",
"CirculateNotify",
"CirculateRequest",
"PropertyNotify",
"SelectionClear",
"SelectionRequest",
"SelectionNotify",
"ColormapNotify",
"ClientMessage",
"MappingNotify",
};
/* Initialize window size */
Width = X_DIM;
Height = Y_DIM - 2*B_HEIGHT;
/* event loop */
while(1) {
XNextEvent(display, &event);
/* printf("Event : %s\n",event_name[event.type]); */
switch (event.type) {
case Expose:
/* get rid of all other expose events */
while (XCheckTypedEvent(display,Expose,&event));
ShowView(theta,phi);
break;
case ButtonPress:
for (i=0; i<NBUTTONS; i++) {
if (event.xbutton.window == buttons[i]) {
paint_button(buttons[i],REVERSE,i,theta,phi);
button = event.xbutton.button;
/* get the matching button release on the same button */
while (1) {
while (XCheckTypedEvent(display,ButtonPress,&event));
/* wait for release; if on correct button, exit */
XMaskEvent(display, ButtonReleaseMask, &event);
if (event.xbutton.button == button) {
paint_button(buttons[i],NORMAL,i,theta,phi);
break;
}
}
switch (i) {
case 0 : XUnloadFont(display, font_info->fid);
XFreeGC(display, gc);
XFreeGC(display, bgc);
XFreeGC(display, bgcr);
XCloseDisplay(display);
return;
break;
case 1 : if (hiddenline) hiddenline = FALSE;
else hiddenline = TRUE ;
rotate_picture(100,&theta,&phi); break;
case 2 : rotate_picture(EVO,&theta,&phi); break;
case 3 : rotate_picture(EVH,&theta,&phi); break;
case 4 : rotate_picture(EVL,&theta,&phi); break;
case 5 : rotate_picture(EVK,&theta,&phi); break;
case 6 : rotate_picture(EVJ,&theta,&phi); break;
default: break;
}
}
}
/* don't do anything if button is pressed in general window */
break;
case ConfigureNotify:
/* window has been resized */
/* change width and height */
Width = event.xconfigure.width;
Height = event.xconfigure.height - 2*B_HEIGHT;
break;
case KeyPress:
XLookupString(&event,buffer,bufsize,&keysym,&compose);
if ((keysym == XK_q) || (keysym == XK_Q)) {
XUnloadFont(display, font_info->fid);
XFreeGC(display, gc);
XFreeGC(display, bgc);
XFreeGC(display, bgcr);
XCloseDisplay(display);
return;
} else if ((keysym == XK_l) || (keysym == XK_L))
rotate_picture(EVL,&theta,&phi);
else if ((keysym == XK_k) || (keysym == XK_K))
rotate_picture(EVK,&theta,&phi);
else if ((keysym == XK_j) || (keysym == XK_J))
rotate_picture(EVJ,&theta,&phi);
else if ((keysym == XK_h) || (keysym == XK_H))
rotate_picture(EVH,&theta,&phi);
else if ((keysym == XK_o) || (keysym == XK_O))
rotate_picture(EVO,&theta,&phi);
else if ((keysym == XK_f) || (keysym == XK_F))
rotate_picture(EVF,&theta,&phi);
else if ((keysym == XK_d) || (keysym == XK_D))
rotate_picture(EVD,&theta,&phi);
else if ((keysym == XK_s) || (keysym == XK_S))
rotate_picture(EVS,&theta,&phi);
else if ((keysym == XK_a) || (keysym == XK_A))
rotate_picture(EVA,&theta,&phi);
else if ((keysym == XK_x) || (keysym == XK_X))
rotate_picture(EVX,&theta,&phi);
else if ((keysym == XK_y) || (keysym == XK_Y))
rotate_picture(EVY,&theta,&phi);
else if ((keysym == XK_z) || (keysym == XK_Z))
rotate_picture(EVZ,&theta,&phi);
break;
default:
break;
} /* end switch */
} /* end while */
#endif
}
paint_button(win, mode, i,theta,phi)
char * win;
int mode, i;
double theta, phi;
{
#ifdef X
char *sprintf(), *strcpy();
GC button_gc;
double theta0, phi0;
if (mode == REVERSE) {
XSetWindowBackground(display,win,foreground_pixel);
button_gc = bgc;
} else {
XSetWindowBackground(display,win,background_pixel);
button_gc = bgcr;
}
/* clearing repaints the background */
XClearWindow(display,buttons[i]);
/* assign button labels */
switch (i) {
case 0 : check_view_angles(&theta0,&phi0);
theta = (theta + theta0) * 180.0 / 3.14159;
while (theta > 360.0) theta -= 360.0;
while (theta < -0.01) theta += 360.0;
phi = (phi + phi0) * 180.0 / 3.14159;
while (phi > 360.0) phi -= 360.0;
while (phi < -0.01) phi += 360.0;
sprintf(button_label[i],
"Quit : Theta = %.3g Phi = %.3g",theta,phi);
break;
case 1 : if (hiddenline) strcpy(button_label[i],"Hidden Lines");
else strcpy(button_label[i],"Wire Frame");
break;
case 2 : strcpy(button_label[i],"Center"); break;
case 3 : strcpy(button_label[i],"Left" ); break;
case 4 : strcpy(button_label[i],"Right" ); break;
case 5 : strcpy(button_label[i],"Up" ); break;
case 6 : strcpy(button_label[i],"Down" ); break;
default : fprintf(stderr,"Error! - Button %d has not been defined!\n",i);
strcpy(button_label[i],"");
break;
}
/*
printf("i = %d label = %s\n",i,button_label[i]);
*/
/* draw text */
XDrawString(display,buttons[i],button_gc,
2,font_info->max_bounds.ascent,button_label[i],
strlen(button_label[i]));
#endif
}
rotate_picture(mode,theta,phi)
int mode;
double *theta, *phi;
{
#ifdef X
double conv, theta0, phi0;
conv = 3.14159/180.0;
XClearWindow(display,vwwindow);
switch (mode) {
case EVL : *theta = *theta + 10*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVJ : *phi = *phi - 10*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVK : *phi = *phi + 10*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVH : *theta = *theta - 10*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVO : *theta = 0.0; *phi = 0.0;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVF : *theta = *theta + 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVS : *phi = *phi - 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVD : *phi = *phi + 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVA : *theta = *theta - 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVX : check_view_angles(&theta0,&phi0);
*theta = -theta0 + 0*conv;
*phi = -phi0 + 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVY : check_view_angles(&theta0,&phi0);
*theta = -theta0 + 90*conv;
*phi = -phi0 + 90*conv;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
case EVZ : check_view_angles(&theta0,&phi0);
*theta = -theta0;
*phi = -phi0;
read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
default : read_view(*theta,*phi);
ShowView(*theta,*phi);
break;
}
#endif
}
ShowView(theta,phi)
double theta,phi;
{
#ifdef X
int i;
for (i=0; i<NBUTTONS; i++)
paint_button(buttons[i],NORMAL,i,theta,phi);
back_axesX();
axesX();
plotX();
front_axesX();
#endif
}
/* draw the toplabel and the z-axis */
axesX()
{
#ifdef X
xyzdata transform_point();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
int text_len, text_width, text_xpos, text_ypos;
int font_height, char_width;
xyzdata point[4], newpt[4];
double minx;
int i, mini;
/* Labels */
font_height = font_info->max_bounds.ascent +
font_info->max_bounds.descent;
/* Top Label */
text_len = strlen(toplabel);
text_width = XTextWidth(font_info,toplabel,text_len);
text_xpos = (Width - text_width)/2;
text_ypos = Y_ORG + 2*B_HEIGHT + 2*font_height;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,toplabel,text_len);
/*
* choose which z-axis to draw
* There are 4 lines on the z-axis containing the 4 points below
*/
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* transform the 4 points */
for (i=0; i<4; i++)
newpt[i] = transform_point(point[i],view_transfo);
/*
* The line drawn will contain the smallest x-value of the
* 4 points decribed above (on the zplane)
*/
minx = newpt[0].x; mini = 0;
for (i=0; i<4; i++)
if (newpt[i].x < minx) {
minx = newpt[i].x;
mini = i;
}
/* draw the z-axis */
if (mini == 0)
draw_zaxis(xmin,ymin,zmin,xmin,ymin,zmax);
else if (mini == 1)
draw_zaxis(xmin,ymax,zmin,xmin,ymax,zmax);
else if (mini == 2)
draw_zaxis(xmax,ymin,zmin,xmax,ymin,zmax);
else if (mini == 3)
draw_zaxis(xmax,ymax,zmin,xmax,ymax,zmax);
#endif
}
/* draw the axes that are further from the viewer */
back_axesX()
{
#ifdef X
/* Draw the plane intersecting x-axis */
draw_back_xplane();
/* Draw the plane intersecting y-axis */
draw_back_yplane();
/* Draw the plane intersecting z-axis */
draw_back_zplane();
#endif
}
/* draw the axes that are closer to the viewer */
front_axesX()
{
#ifdef X
/* Draw the plane intersecting x-axis */
draw_front_xplane();
/* Draw the plane intersecting y-axis */
draw_front_yplane();
/* Draw the plane intersecting z-axis */
draw_front_zplane();
#endif
}
/* Draw the axis - parallel to X */
draw_xaxis(xa,ya,za,xb,yb,zb)
double xa,ya,za,xb,yb,zb;
{
#ifdef X
xyzdata midpoint();
xyzdata transform_point();
char *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int text_len, text_width, text_xpos, text_ypos;
int font_height, char_width;
int i;
char text[100];
double xtmp, ratio, dl;
/*
* xa = xmin xb = xmax
* ya = yb = (ymin ? ymax)
* za = zb = (zmin ? zmax)
*/
/* Labels */
font_height = font_info->max_bounds.ascent +
font_info->max_bounds.descent;
char_width = XTextWidth(font_info,"a",1);
/* midpoint of the line */
dl = (ya == ymin) ? -0.2*(ymax-ymin) : 0.2*(ymax-ymin);
midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
/* X-Axis Label */
strcpy(text,xlabel);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x) - char_width/2;
text_ypos = Height - (int)(midpt.y) + 2*font_height;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
/* Draw the tick marks */
dl = 0.5*dl;
for (i=0; i<=xticks; i++) {
ratio = i/(double)xticks;
xtmp = xa + (xb-xa)*ratio;
draw_Xline(xtmp,ya,za,xtmp,ya+dl,za,2);
midpt.x = xtmp;
midpt.y = ya+dl;
midpt.z = za;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",xtmp);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x);
text_ypos = Height - (int)(midpt.y) + 10;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
}
#endif
}
/* Draw the axis - parallel to Y */
draw_yaxis(xa,ya,za,xb,yb,zb)
double xa,ya,za,xb,yb,zb;
{
#ifdef X
xyzdata midpoint();
xyzdata transform_point();
char *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int text_len, text_width, text_xpos, text_ypos;
int font_height, char_width, i;
char text[100];
double ytmp, ratio, dl;
/*
* xa = xb = (xmin ? xmax)
* ya = ymin yb = ymax
* za = zb = (zmin ? zmax)
*/
/* Labels */
font_height = font_info->max_bounds.ascent +
font_info->max_bounds.descent;
char_width = XTextWidth(font_info,"a",1);
/* midpoint of the line */
dl = (xa == xmin) ? -0.2*(xmax-xmin) : 0.2*(xmax-xmin);
midpt = midpoint(xa+dl,ya,za,xb+dl,yb,zb,0.5);
/* Y-Axis Label */
strcpy(text,ylabel);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x) - char_width/2;
text_ypos = Height - (int)(midpt.y) + 2*font_height;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
/* Draw the tick marks */
dl = 0.5*dl;
for (i=0; i<=yticks; i++) {
ratio = i/(double)yticks;
ytmp = ya + (yb-ya)*ratio;
draw_Xline(xa,ytmp,za,xa+dl,ytmp,za,2);
midpt.x = xa + dl;
midpt.y = ytmp;
midpt.z = za;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",ytmp);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x) ;
text_ypos = Height - (int)(midpt.y) + 10;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
}
#endif
}
/* Draw the axis - parallel to Z */
draw_zaxis(xa,ya,za,xb,yb,zb)
double xa,ya,za,xb,yb,zb;
{
#ifdef X
xyzdata midpoint();
xyzdata transform_point();
char *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int text_len, text_width, text_xpos, text_ypos;
int font_height, char_width, i;
char text[100];
double ztmp, ratio, dl;
/*
* xa = xb = (xmin ? xmax)
* ya = yb = (ymin ? ymax)
* za = zmin zb = zmax
*/
/* Labels */
font_height = font_info->max_bounds.ascent +
font_info->max_bounds.descent;
char_width = XTextWidth(font_info,"a",1);
/* midpoint of the line */
dl = (ya == ymin) ? -0.2*(ymax-ymin) : 0.2*(ymax-ymin);
midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
/* Z-Axis Label */
strcpy(text,zlabel);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x) - char_width/2;
text_ypos = Height - (int)(midpt.y) + 2*font_height;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
/* Draw the tick marks */
dl = 0.5*dl;
for (i=0; i<=zticks; i++) {
ratio = i/(double)zticks;
ztmp = za + (zb-za)*ratio;
draw_Xline(xa,ya,ztmp,xa,ya+dl,ztmp,2);
midpt.x = xa;
midpt.y = ya+dl;
midpt.z = ztmp;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",ztmp);
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
text_xpos = (int)(midpt.x) - (int)(1.5*text_width);
text_ypos = Height - (int)(midpt.y) - 20;
XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
}
#endif
}
/* draw the back x-plane */
draw_back_xplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.0*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 1.0*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains xmax */
point[0].x = xmax; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmax; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmax; point[4].y = ymin; point[4].z = zmin;
} else {
/* draw the lesser - point1 contains xmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmin; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmin; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,colors[BACK2_C]);
XFillPolygon(display,vwwindow,gc,xpoint,5,
Convex,CoordModeOrigin);
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
#endif
}
/* draw the back y-plane */
draw_back_yplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.0*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 1.0*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains ymax */
point[0].x = xmin; point[0].y = ymax; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymax; point[4].z = zmin;
} else {
/* draw the lesser - point1 contains ymin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,colors[BACK2_C]);
XFillPolygon(display,vwwindow,gc,xpoint,5,
Convex,CoordModeOrigin);
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
#endif
}
/* draw the back z-plane */
draw_back_zplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
double ztmp, maxy;
int i, maxi;
/* 2 planes intersecting the z-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.0*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 1.0*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains zmax */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmax;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmax;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmax;
} else {
/* draw the lesser - point1 contains zmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,colors[BACK2_C]);
XFillPolygon(display,vwwindow,gc,xpoint,5,
Convex,CoordModeOrigin);
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
/*
* The line drawn will contain the largest y-value of the
* 4 points on the z-plane
*/
maxy = xpoint[0].y; maxi = 0;
for (i=0; i<4; i++)
if (xpoint[i].y > maxy) {
maxy = xpoint[i].y;
maxi = i;
}
ztmp = (point1.z > point2.z) ? zmax : zmin;
/* draw the x-axis first */
if (maxi == 0 || maxi == 3)
draw_xaxis(xmin,ymin,ztmp,xmax,ymin,ztmp);
else if (maxi == 1 || maxi == 2)
draw_xaxis(xmin,ymax,ztmp,xmax,ymax,ztmp);
/* draw the y-axis first */
if (maxi == 0 || maxi == 1)
draw_yaxis(xmin,ymin,ztmp,xmin,ymax,ztmp);
else if (maxi == 2 || maxi == 3)
draw_yaxis(xmax,ymin,ztmp,xmax,ymax,ztmp);
#endif
}
/* draw the front x-plane */
draw_front_xplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.0*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 1.0*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains xmax */
point[0].x = xmax; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmax; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmax; point[4].y = ymin; point[4].z = zmin;
} else {
/* draw the greater - point1 contains xmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmin; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmin; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
XSetDashes(display,gc,0,dash_list_dashed,DASHED);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
#endif
}
/* draw the front y-plane */
draw_front_yplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.0*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 1.0*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains ymax */
point[0].x = xmin; point[0].y = ymax; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymax; point[4].z = zmin;
} else {
/* draw the greater - point1 contains ymin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
XSetDashes(display,gc,0,dash_list_dashed,DASHED);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
#endif
}
/* draw the front z-plane */
draw_front_zplane()
{
#ifdef X
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt;
XPoint xpoint[5];
int i;
/* 2 planes intersecting the z-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.0*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 1.0*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains zmax */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmax;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmax;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmax;
} else {
/* draw the greater - point1 contains zmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt = transform_point(point[i],view_transfo);
xpoint[i].x = (int)newpt.x;
xpoint[i].y = Height - (int)newpt.y;
}
XSetForeground(display,gc,foreground_pixel);
XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
XSetDashes(display,gc,0,dash_list_dashed,DASHED);
XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
#endif
}
draw_Xline(x1, y1, z1, x2, y2, z2, ithk)
double x1, y1, z1, x2, y2, z2;
int ithk;
{
#ifdef X
xyzdata point1, point2, newpt1, newpt2;
xyzdata transform_point();
int ix1, iy1, ix2, iy2;
point1.x = x1;
point1.y = y1;
point1.z = z1;
point2.x = x2;
point2.y = y2;
point2.z = z2;
newpt1 = transform_point(point1,view_transfo);
newpt2 = transform_point(point2,view_transfo);
ix1 = (int)newpt1.x;
iy1 = Height-(int)newpt1.y;
ix2 = (int)newpt2.x;
iy2 = Height-(int)newpt2.y;
/* draw the line */
XSetLineAttributes(display,gc,ithk,LineSolid,CapButt,JoinBevel);
XDrawLine(display,vwwindow,gc,ix1,iy1,ix2,iy2);
#endif
}
/* draw the plot */
plotX()
{
#ifdef X
xyzdata transform_point();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
extern int hiddenline, quick_sort;
extern segmptr segmhead;
XPoint points[MAXPTS];
segmptr S;
nodeptr Nd;
int j,npts;
xyzdata point, newpt;
/* reset the line attributes n*/
XSetLineAttributes(display,gc,0,LineSolid,CapButt,JoinBevel);
/* now draw the plot */
if (hiddenline==ON) {
/* sort the mesh */
if (quick_sort)
do_quick_sort();
else
bubble_sort();
}
S = segmhead;
for ( ; S!=NULL; S=S->next) {
/* rescale points */
j = 0;
for (Nd=S->head; Nd!=NULL; Nd=Nd->next) {
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
points[j].x = (int)newpt.x;
points[j].y = Height - (int)newpt.y;
j++;
}
npts = j;
/* plot the points */
if (line == ON) {
if (hiddenline == ON) {
XSetForeground(display,gc,colors[LINE2_C]);
XFillPolygon(display,vwwindow,gc,points,npts,
Complex,CoordModeOrigin);
}
XSetForeground(display,gc,colors[LINE1_C]);
XDrawLines(display,vwwindow,gc,points,npts,CoordModeOrigin);
}
}
/* reset the color */
XSetForeground(display,gc,foreground_pixel);
#endif
}