pax_global_header00006660000000000000000000000064115420517030014510gustar00rootroot0000000000000052 comment=6a0eaf0a2f0b08d90668cf95dde64e5ac50d3122 showmesh-1.0/000075500000000000000000000000001154205170300132035ustar00rootroot00000000000000showmesh-1.0/.gear/000075500000000000000000000000001154205170300141775ustar00rootroot00000000000000showmesh-1.0/.gear/Makefile000064400000000000000000000004341154205170300156400ustar00rootroot00000000000000# Created by real at altlinux.org SRC = showmesh_1_0.c EXE = ShowMesh all: $(SRC) gcc -o $(EXE) -g -pipe -Wall -O3 $(SRC) -lX11 install: $(EXE) install -d ${DESTDIR}/usr/bin install -m755 $(EXE) ${DESTDIR}/usr/bin ln -s $(EXE) ${DESTDIR}/usr/bin/showmesh clean: rm -f $(EXE) showmesh-1.0/.gear/rules000064400000000000000000000001421154205170300152510ustar00rootroot00000000000000spec: .gear/showmesh.spec copy: .gear/Makefile tar: . name=@name@-@version@ base=@name@-@version@ showmesh-1.0/.gear/showmesh.spec000064400000000000000000000016561154205170300167200ustar00rootroot00000000000000Name: showmesh Version: 1.0 Release: alt3 Summary: Mesh visualisation tool for X Windows License: Free for non-commertial using Group: Sciences/Mathematics Url: http://www-dinma.univ.trieste.it/nirftc/research/easymesh/showmesh.html Packager: Eugeny A. Rostovtsev (REAL) # http://www-dinma.univ.trieste.it/nirftc/research/easymesh/showmesh_1_0.c Source: %name-%version.tar Source1: Makefile BuildPreReq: libX11-devel %description ShowMesh is a mesh visualisation tool for X Windows. %prep %setup install -p -m644 %SOURCE1 . %build %make_build %install %makeinstall_std %files %_bindir/* %changelog * Tue Mar 22 2011 Eugeny A. Rostovtsev (REAL) 1.0-alt3 - Rebuilt for debuginfo * Tue Jan 25 2011 Eugeny A. Rostovtsev (REAL) 1.0-alt2 - Fixed using of fonts * Mon Jan 24 2011 Eugeny A. Rostovtsev (REAL) 1.0-alt1 - Initial build for Sisyphus showmesh-1.0/showmesh_1_0.c000064400000000000000000000740131154205170300156500ustar00rootroot00000000000000/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 %%%%%%%%%%%% %%%%%%%%%%%% o88°°88o 888°°88o o88°°88o 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 °°° 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% °888888o 888 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% ooo 888 888 888 888 888 °88 888 88° %%%%%%%%%%%% %%%%%%%%%%%% °88oo88° 888 888 °88oo88° °888° °888° %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 %%%%%%%%%%%% %%%%%%%%%%%% 8888888o888o o88°°88o o88°°88o 888°°88o %%%%%%%%%%%% %%%%%%%%%%%% 888 888 88o 888 888 888 °°° 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 8888888° °888888o 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 888 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 888 ooo ooo 888 888 888 %%%%%%%%%%%% %%%%%%%%%%%% 888 888 888 °88oo88° °88oo88° 888 888 %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% Author: Bojan NICENO %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% niceno@univ.trieste.it %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include #include #include #include #include #include #include #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #define SMALL 1e-30 #define GREAT 1e+30 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%% Definitions for the mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ int Nn, Ne, Ns; double xmax, ymax, xmin, ymin, scl, X0, Y0; struct ele { int i, j, k; int mark; double xv, yv; } * elem; struct sid { int ea, eb; /* left and right element */ int a, b, c, d; /* left, right, start and end point */ int mark; /* is it off, is on the boundary */ } * side; struct nod { double x, y; int mark; } * node; /*%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #define MAIN_WDTH 750 #define MAIN_HGHT 500 #define BUTTON_HEIGHT 18 #define BUTTON_WIDTH 80 #define NBUTTONS 10 #define ON 0 #define OFF -1 #define DELAUNAY 0 #define VORONOI 1 #define NODES 2 #define ELEMENTS 3 #define MATERIALS 4 #define BOUNDARY 5 #define ZOOM 6 #define MOVE 7 #define FIT 8 #define QUIT 9 Display *display; Window main_win; Window draw_win; int main_wdth, main_hght, draw_wdth, draw_hght; int scr_num; static char *prog_name, *file_name; GC gc_BoW, gc_WoB, gc_XOR, gc_THICK, gc_DASHED, gc_numb; XFontStruct *text_font, *numb_font; int main_wdth=MAIN_WDTH, main_hght=MAIN_HGHT; struct butt_data { int x0, y0, hght, wdth, border; char *caption; int pressed; } butt_data[NBUTTONS]= { { MAIN_WDTH-BUTTON_WIDTH-20, 10, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Delaunay", ON}, { MAIN_WDTH-BUTTON_WIDTH-20, 40, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Voronoi", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 70, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Nodes", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 100, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Elements", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 130, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Materials", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 160, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Boundary", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 190, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Zoom", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 220, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Move", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 250, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Fit", OFF}, { MAIN_WDTH-BUTTON_WIDTH-20, 280, BUTTON_HEIGHT, BUTTON_WIDTH, 2, "Quit", OFF}, }; Window button[NBUTTONS]; /*========================================================================*/ getGC(Window win) { unsigned long valuemask=0; XGCValues values; int dash_offset=0; static char dash_list[2]={1,1}; int list_len=2; /* Normal, thin lines */ gc_BoW = XCreateGC(display, win, valuemask, &values); gc_WoB = XCreateGC(display, win, valuemask, &values); XSetFont(display, gc_BoW, text_font->fid); XSetFont(display, gc_WoB, text_font->fid); XSetForeground(display, gc_BoW, BlackPixel(display, scr_num)); XSetForeground(display, gc_WoB, WhitePixel(display, scr_num)); XSetLineAttributes(display, gc_BoW, 0, LineSolid, CapRound, JoinRound); XSetLineAttributes(display, gc_WoB, 0, LineSolid, CapRound, JoinRound); /* Thick lines */ gc_THICK = XCreateGC(display, win, valuemask, &values); XSetForeground(display, gc_THICK, BlackPixel(display, scr_num)); XSetLineAttributes(display, gc_THICK, 3, LineSolid, CapRound, JoinRound); /* Dashed lines */ gc_DASHED = XCreateGC(display, win, valuemask, &values); XSetForeground(display, gc_DASHED, BlackPixel(display, scr_num)); XSetLineAttributes(display, gc_DASHED, 0, LineOnOffDash, CapRound, JoinRound); XSetDashes(display, gc_DASHED, dash_offset, dash_list, list_len); /* numbers */ gc_numb = XCreateGC(display, win, valuemask, &values); XSetFont(display, gc_numb, numb_font->fid); XSetForeground(display, gc_numb, BlackPixel(display, scr_num)); /* Invisible lines */ gc_XOR = XCreateGC(display, win, 0, NULL); XSetFunction(display, gc_XOR, GXxor); XSetForeground(display, gc_XOR, WhitePixel(display, scr_num)); } /*========================================================================*/ load_fonts() { if( (text_font = XLoadQueryFont(display, "-*-helvetica-bold-r-normal-*-12-*")) == NULL ) { (void) fprintf(stderr, "%s: Cannot open font\n", prog_name); exit(-1); } if( (numb_font = XLoadQueryFont(display, "-*-helvetica-bold-r-normal-*-10-*")) == NULL ) { (void) fprintf(stderr, "%s: Cannot open font\n", prog_name); exit(-1); } } /*========================================================================*/ draw(Window win, GC gc, int win_x_dim, int win_y_dim) { int x_0, y_0, x_dim, y_dim; x_0 = win_x_dim/5; y_0 = win_y_dim/5; x_dim = 3*win_x_dim/5; y_dim = 3*win_y_dim/5; XDrawRectangle(display, win, gc, x_0, y_0, x_dim, y_dim); } /*========================================================================*/ place_text(Window win, GC gc, XFontStruct *text_font, int win_x_dim, int win_y_dim, char *string) { int width, height; /* string height and width */ width = XTextWidth(text_font, string, strlen(string)); height = text_font->ascent + text_font->descent; XDrawString(display, win, gc, (win_x_dim-width)/2, (win_y_dim+height)/2, string, strlen(string)); } /*========================================================================*/ create_buttons(Window parent) { int b; unsigned long valuemask = CWWinGravity; unsigned long border, background; XSetWindowAttributes attr; attr.win_gravity = NorthEastGravity; for(b=0; bascent + text_font->descent; width = XTextWidth(text_font, butt_data[b].caption, strlen(butt_data[b].caption)); if(butt_data[b].pressed==ON) {attr.background_pixel = BlackPixel(display, scr_num); attr.border_pixel = WhitePixel(display, scr_num);} if(butt_data[b].pressed==OFF) {attr.background_pixel = WhitePixel(display, scr_num); attr.border_pixel = BlackPixel(display, scr_num);} XChangeWindowAttributes(display, button[b], valuemask, &attr); XClearWindow(display, button[b]); /* XFlush(display); */ if(butt_data[b].pressed==ON) gc=gc_WoB; if(butt_data[b].pressed==OFF) gc=gc_BoW; XDrawString(display, button[b], gc, (butt_data[b].wdth-width)/2, (butt_data[b].hght+height)/2, butt_data[b].caption, strlen(butt_data[b].caption)); } /*=========================================================================*/ draw_mesh(Window win) { int e, n, s, ei, ej, ek, ea, eb; double x, y, xc, yc, xd, yd, x1, y1, x2, y2; char numb[80]; int f_hght, f_wdth; f_hght = 9; /*numb_font->ascent + numb_font->descent;*/ /*********************** * Draw Delaunay Mesh * ***********************/ if(butt_data[DELAUNAY].pressed==ON) for(s=0; s0) /* It means, side is on the boundary */ { xc=node[side[s].c].x; yc=node[side[s].c].y; xd=node[side[s].d].x; yd=node[side[s].d].y; XDrawLine(display, win, gc_THICK, (int)(xc*scl + X0), (int)(-yc*scl + Y0), (int)(xd*scl + X0), (int)(-yd*scl + Y0)); } if(butt_data[MATERIALS].pressed==ON || butt_data[ELEMENTS].pressed==ON) for(e=0; e0) /* It means, side is on the boundary */ { x = 0.5*(node[side[s].c].x + node[side[s].d].x); y = 0.5*(node[side[s].c].y + node[side[s].d].y); sprintf(numb, "%d", side[s].mark); f_wdth = XTextWidth(numb_font, numb, strlen(numb)); XClearArea(display, win, (int)(x*scl+X0-f_wdth/2-1), (int)(-y*scl+Y0-1-f_hght/2), f_wdth+2, f_hght+1, False); XDrawString(display, win, gc_numb, (int)(x*scl+X0-f_wdth/2), (int)(-y*scl+Y0+f_hght/2), numb, strlen(numb)); } for(n=0; n0) { x=node[n].x; y=node[n].y; sprintf(numb, "%d", node[n].mark); f_wdth = XTextWidth(numb_font, numb, strlen(numb)); XClearArea(display, win, (int)(x*scl+X0-f_wdth/2-1), (int)(-y*scl+Y0-1-f_hght/2), f_wdth+2, f_hght+1, False); XDrawString(display, win, gc_numb, (int)(x*scl+X0-f_wdth/2), (int)(-y*scl+Y0+f_hght/2), numb, strlen(numb)); } } } /*-draw_mesh--------------------------------------------------------------*/ /*========================================================================*/ load_mesh() { int n, s, e, len; int d1, d2, d3, d4, d5, d6; char dummy[80]; FILE *in; strcat(file_name, ".n"); len=strlen(file_name); /*--------+ | Nodes | +--------*/ in=fopen(file_name, "r"); if(in==NULL) {fprintf(stderr, "%s: cannot open file: %s\n\n", prog_name, file_name); fflush(stdout); exit(-1);} fscanf(in, "%d", &Nn); node=(struct nod *) calloc(Nn, sizeof(struct nod)); if(node==NULL) {fprintf(stderr, "%s: cannot allocate enough memory\n\n", prog_name); fflush(stdout); exit(-1);} for(n=0; n"); printf("\n\nShowMesh uses the following three input files:"); printf("\n NAME.n"); printf("\n NAME.e"); printf("\n NAME.s"); printf("\nThese files are created with EasyMesh.\n\n"); exit(-1);} /*-------------------------------+ | Copy the name of the program | +-------------------------------*/ prog_name=argv[0]; file_name=argv[1]; load_mesh(); init(argc, argv); /*============# # MAIN LOOP # #============*/ { Window root, child; /* for XQuerryPointer */ unsigned int mouse_butt; int b, x0=OFF, y0, x_root, y_root, x_new, y_new, x_old, y_old; double x0_fiz, y0_fiz, scl_new; while(1) { XNextEvent(display, &report); switch(report.type) { /****************** * Expose Window * ******************/ case Expose: if(report.xany.window==draw_win) draw_mesh(draw_win); for(b=0; bfid); XFreeGC(display, gc_WoB); XFreeGC(display, gc_BoW); XCloseDisplay(display); exit(1);} for(b=0; b=button[DELAUNAY] && report.xany.window<=button[BOUNDARY]) {XClearWindow(display, draw_win); draw_mesh(draw_win);} if(report.xany.window==draw_win) { if(butt_data[MOVE].pressed==ON) { if(x0==OFF) {x0=report.xmotion.x; y0=report.xmotion.y;} else {butt_data[MOVE].pressed=OFF; write_on_button(MOVE); X0+=(x_new-x0); Y0+=(y_new-y0); x0=OFF; XClearWindow(display, draw_win); draw_mesh(draw_win);} } if(butt_data[ZOOM].pressed==ON) { if(x0==OFF) {x0=report.xmotion.x; y0=report.xmotion.y;} else {butt_data[ZOOM].pressed=OFF; write_on_button(ZOOM); x0_fiz = (min(x0, x_new)-X0)/scl; y0_fiz = (min(y0, y_new)-Y0)/scl; if(x0!=x_new && y0!=y_new) scl_new=( min( (double)draw_wdth/abs(x0-x_new), (double)draw_hght/abs(y0-y_new) ) )*scl; if( max(scl_new*xmax, scl_new*ymax) < 32768 ) {scl=scl_new; X0=-x0_fiz*scl; Y0=-y0_fiz*scl;} x0=OFF; XClearWindow(display, draw_win); draw_mesh(draw_win);} } } break; /***************** * Mouse Motion * *****************/ case MotionNotify: if(report.xany.window==draw_win) { if(butt_data[MOVE].pressed==ON) {x_old=x_new; y_old=y_new; XQueryPointer(display, report.xmotion.window, &root, &child, &x_root, &y_root, &x_new, &y_new, &mouse_butt); if(x0!=OFF) {XDrawLine(display, draw_win, gc_XOR, x0, y0, x_old, y_old); XDrawLine(display, draw_win, gc_XOR, x0, y0, x_new, y_new);}} if(butt_data[ZOOM].pressed==ON) {x_old=x_new; y_old=y_new; XQueryPointer(display, report.xmotion.window, &root, &child, &x_root, &y_root, &x_new, &y_new, &mouse_butt); if(x0!=OFF) {XDrawRectangle(display, draw_win, gc_XOR, min(x0, x_old), min(y0, y_old), abs(x_old-x0), abs(y_old-y0)); XDrawRectangle(display, draw_win, gc_XOR, min(x0, x_new), min(y0, y_new), abs(x_new-x0), abs(y_new-y0));}} } break; } /* end switch */ } /* end while */ } /* end of block */ }