/* Last edited on 2009-11-09 17:12:37 by stolfilocal */ /*************************************************************************** * Copyright (C) 2009 by Douglas Castro * * douglas@ime.unicamp.br * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "imprime.h" void desenha_folhas(PSStream *ps, No *r, int ind, int prof, double xmin, double xmax, double ymin, double ymax) { assert((r->fil[0] == NULL) == (r->fil[1] == NULL)); if(r->fil[0]==NULL) { DrawCells(ps, xmin, xmax, ymin, ymax, TRUE, TRUE, FALSE); return; } if(prof%2==0) { desenha_folhas(ps, r->fil[0], 2*ind + 0, prof + 1, xmin, (xmax+xmin)/2.0, ymin, ymax); desenha_folhas(ps, r->fil[1], 2*ind + 1, prof + 1, (xmax+xmin)/2.0, xmax, ymin, ymax); } else { desenha_folhas(ps, r->fil[0], 2*ind + 0, prof + 1, xmin, xmax, ymin, (ymax+ymin)/2.0); desenha_folhas(ps, r->fil[1], 2*ind + 1, prof + 1, xmin, xmax, (ymin+ymax)/2.0, ymax); } } /** * A chamada dessa funcao retorna a grade formada por todas as celulas folha da arvore */ void DoMesh(char *prefixo, No *u, int tmp) { char str[100]; sprintf(str,"%s%08d", "mesh-", tmp); PSStream *ps = pswr_new_stream(TRUE, prefixo, NULL, NULL, 328.0, 246.0); pswr_new_page(ps, str); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 4.00, 324.00, 3.00, 243.00, 44, 33 ); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 1.000, 1.000); // chamar uma funcao que sai a procura de folhas desenha_folhas(ps, u, 1, 0, 0.0, 1.0, 0.0, 1.0); pswr_close_stream(ps); } void DrawCells(PSStream *ps, double xmin, double xmax, double ymin, double ymax, bool_t fill, bool_t draw, bool_t eo) { /* Usable area [0 _ 12]�[0 _ 15] */ // Aqui e feita uma mudanca de escala para que o retangulo se ajuste ao // dominio onde e feito o desenho [-22,22]X[-16.5,16,5] double xe = 44.0*xmin-22.0; double xd = 44.0*xmax-22.0; double ye = 33.0*ymin-16.5; double yd = 33.0*ymax-16.5; pswr_rectangle(ps, xe, xd, ye, yd, fill, draw); } void MakeTree(char *prefixo, No *u, int niv, int tmp) { char str[100]; sprintf(str,"%s%08d", "tree-", tmp); PSStream *ps = pswr_new_stream(TRUE, prefixo, NULL, NULL, 328.0, 246.0); pswr_new_page(ps, str); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 4.00, 324.00, 3.00, 243.00, 44, 33 ); double x=0.0,y=12.0; int prof = 0; DrawNodes(ps,u,prof,niv,x,y); pswr_close_stream(ps); } void DrawNodes(PSStream *ps, No *u, int prof, int niv, double x, double y) { assert((u->fil[0]==NULL)==(u->fil[1]==NULL)); if(u->fil[0]==NULL){ return;} // if(u->/*fil[0]->*/leaf){ return;} if(prof==0) { // fprintf(stderr,"\natencao para criterio de parada em DrawNodes -imprime.c- \n"); // fprintf(stderr," se eh u.fil == null tem-se arvore com folhas virtuais\n"); // fprintf(stderr," se eh u.fil == leaf tem-se arvore com folhas normais\n"); // fprintf(stderr," em uso u.fil == leaf\n\n"); // fprintf(stderr," em uso u == null\n\n"); } int qual; for(qual = 0;qual<=1;qual++) { double s = qual == 0 ? -1.0 : 1.0; DrawNodes(ps, u->fil[qual], prof+1,niv, x + s*20.0/(pow(2.0,prof+1)), y-1.0); // if(u->fil[qual]->virtual_leaf/* && prof!=niv-2*/) // { // pswr_comment(ps, "Thicker blue segments with arrowheads:"); // pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.20, 0.5, 0.5); // } // else { pswr_comment(ps, "Medium solid black segments:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); } MakeLines(ps, qual, prof, x, y, FALSE); } } void MakeLines(PSStream *ps, int qual, int prof, double xc, double yc, bool_t arrowheads) { auto void do_seg(double xa, double ya, double xb, double yb); void do_seg(double xa, double ya, double xb, double yb) { pswr_segment(ps, xa+xc, ya+yc, xb+xc, yb+yc); pswr_dot(ps, xa+xc, ya+yc, 0.2, FALSE, TRUE); pswr_dot(ps, xb+xc, yb+yc, 0.2, FALSE, TRUE); if (arrowheads) { pswr_arrowhead(ps, xa+xc, ya+yc, xb+xc, yb+yc, 2.0, 3.0, 0.85, TRUE, TRUE); } } if(qual==0) { do_seg(-20.0/(pow(2.0,prof+1)), -1.0, 0.0, 0.0); /*esq*/ } else { do_seg(0.0, 0.0, 20.0/(pow(2.0,prof+1)), -1.0); /*dir*/ } } void escreve_em_arquivo (int d, int prof, FILE *arq, VNo pac[], double xmin[], double xmax[], Preditor pred, int qv, bool_t elz, bool_t op) { int ord = op ? 9 : 5; int ctr = ipow(ord,d)/2; if( pac[ctr].p == NULL ){ return; } auto void escreve_arquivo_nd(int d, FILE *arq, No *u, double xmin[], double xmax[]); void escreve_arquivo_nd(int d, FILE *arq, No *u, double xmin[], double xmax[]) { if(u == NULL){ return; } /* paranoia */ assert( (u->fil[0] == NULL) == (u->fil[1] == NULL) ); //assert(u->fval == u->fv[1]); /* Determina o valor a plotar: */ double val = u->fv[qv]; switch(d){ case 1 : fprintf(arq,"%10.6f %10.6f\n", xmin[0], val); fprintf(arq,"%10.6f %10.6f\n", xmax[0], val); break; case 2 : /* posicao dos vertices 01 --- 11 00 --- 10 */ if (/*(! elz) ||*/ (val)) { fprintf(arq,"%10.6f %10.6f %10.6f\n", xmin[0], xmin[1], val); /* 00 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmax[0], xmin[1], val); /* 10 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmax[0], xmax[1], val); /* 11 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmin[0], xmax[1], val); /* 01 */ } break; case 3 : // imprime o valor de u apenas no vertice inferior da celula. fprintf(arq,"%10.6f %10.6f %10.6f %10.6f\n", xmin[0], xmin[1], xmin[2], val); //return; /* fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); */ break; default : fprintf(stderr,"Nao implementado para dimensao acima de 3 - escreve_arquivo_nd\n"); } return; } int ex = prof % d; int qual; for(qual=0;qual<2;qual++) { int tm = ipow(ord,d); VNo pacf[tm]; double xminf[d], xmaxf[d]; /* Constrói o pacote do filho {qual}: */ divide_pacote_geral(d, pac, ex, pred, qual, pacf, op); limites_celula( d, ex, qual, xmin, xmax, xminf, xmaxf); escreve_em_arquivo( d, prof+1, arq, pacf, xminf, xmaxf, pred, qv, FALSE,op); } /* desenha so as folhas */ assert( (pac[ctr].p->fil[0] == NULL) == (pac[ctr].p->fil[1] == NULL) ); if(pac[ctr].p->fil[0] == NULL) { escreve_arquivo_nd( d, arq, pac[ctr].p, xmin, xmax); } } //---------------------inicio---testes desenhos em 3d---------------- /** * A chamada dessa funcao retorna a grade formada por todas as celulas folha da arvore */ void DoMeshND(int d, char *prefixo, No *u, int tmp, double xmin[], double xmax[], double xminR[],double xmaxR[]) { char str[100]; sprintf(str,"%s%08d", "mesh-", tmp); PSStream *ps = pswr_new_stream(TRUE, prefixo, NULL, NULL, 328.0, 246.0); pswr_new_page(ps, str); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 4.00, 324.00, 3.00, 243.00, 44, 33 ); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 1.000, 1.000); // chamar uma funcao que sai a procura de folhas desenhaFolhasND(d, ps, u, 1, 0, xmin, xmax, xminR, xmaxR); pswr_close_stream(ps); } void desenhaFolhasND(int d, PSStream *ps, No *r, int ind, int prof, double xmin[], double xmax[], double xminR[],double xmaxR[]) { assert((r->fil[0] == NULL) == (r->fil[1] == NULL)); if(r->fil[0]==NULL) { DrawCellsND(d, ps, xmin, xmax, xminR, xmaxR, FALSE /*TRUE*/, TRUE, FALSE); return; } int qual; for(qual=0;qual<2;qual++) { //fprintf(stderr,"%d\n",prof); int ex = prof%d; double xminf[d], xmaxf[d]; limites_celula( d, ex, qual, xmin, xmax, xminf, xmaxf); desenhaFolhasND(d, ps, r->fil[qual], 2*ind + qual, prof + 1, xminf, xmaxf, xminR, xmaxR); } } void DrawCellsND(int d, PSStream *ps, double xmin[], double xmax[], double xminR[], double xmaxR[], bool_t fill, bool_t draw, bool_t eo) { /* Usable area [0 _ 12]�[0 _ 15] */ // Aqui e feita uma mudanca de escala para que o retangulo se ajuste ao // dominio onde e feito o desenho [-22,22]X[-16.5,16.5] if(d==2) { double xm = (xmin[0]-xminR[0])/(xmaxR[0]-xminR[0]); double xM = (xmax[0]-xminR[0])/(xmaxR[0]-xminR[0]); double ym = (xmin[1]-xminR[1])/(xmaxR[1]-xminR[1]); double yM = (xmax[1]-xminR[1])/(xmaxR[1]-xminR[1]); double xe = 44.0*xm-22.0; double xd = 44.0*xM-22.0; double ye = 33.0*ym-16.5; double yd = 33.0*yM-16.5; pswr_rectangle(ps, xe, xd, ye, yd, fill, draw); } else if(d==3) { pswr_comment(ps, "Medium solid black coordinate lines:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); //pswr_coord_line(ps, HOR, 0.0); //pswr_coord_line(ps, VER, 0.0); //pswr_coord_line(ps, HOR, -8.0); //pswr_coord_line(ps, VER, -5.0); double sz0 = (xmaxR[0]-xminR[0]); double sz1 = (xmaxR[1]-xminR[1]); double sz2 = (xmaxR[2]-xminR[2]); //vertices enumerados a partir do vertice inferior no sentido anti-horario. double v0[3] = {(xmin[0]-xminR[0])/sz0, (xmin[1]-xminR[1])/sz1, (xmin[2]-xminR[2])/sz2}; double v1[3] = {(xmax[0]-xminR[0])/sz0, (xmin[1]-xminR[1])/sz1, (xmin[2]-xminR[2])/sz2}; double v2[3] = {(xmax[0]-xminR[0])/sz0, (xmax[1]-xminR[1])/sz1, (xmin[2]-xminR[2])/sz2}; double v3[3] = {(xmin[0]-xminR[0])/sz0, (xmax[1]-xminR[1])/sz1, (xmin[2]-xminR[2])/sz2}; double v4[3] = {(xmin[0]-xminR[0])/sz0, (xmin[1]-xminR[1])/sz1, (xmax[2]-xminR[2])/sz2}; double v5[3] = {(xmax[0]-xminR[0])/sz0, (xmin[1]-xminR[1])/sz1, (xmax[2]-xminR[2])/sz2}; double v6[3] = {(xmax[0]-xminR[0])/sz0, (xmax[1]-xminR[1])/sz1, (xmax[2]-xminR[2])/sz2}; double v7[3] = {(xmin[0]-xminR[0])/sz0, (xmax[1]-xminR[1])/sz1, (xmax[2]-xminR[2])/sz2}; // esquema - posicao dos vertices v0 = (0,0,0), v1 = (1,0,0) // v4-------------v7 v2 = (1,1,0), v3 = (0,1,0) // / | / | v4 = (0,0,1), v5 = (1,0,1) // / | / | v6 = (1,1,1), v7 = (0,1,1) // v5--|---------v6 | // | v0----------|--v3 // | / | / // | / | / // v1------------v2 // // considerando que a nova origem eh o ponto (-8,-5) e que v0 eh // levado nesse ponto, colocamos os outros vertices nos pontos // v0 -> (-8,-5), v1 -> (-15,-12) // v2 -> (10,-12), v3 -> (17,-5) // v4 -> (-8,12), v5 -> (-15,5) // v6 = (10,5), v7 -> (17,12) // posicao de P relativo a R^2 eh auto double xx(int d, double pt[]); double xx(int d, double pt[]) { return -8.0 - 7.0*pt[0] + 25.0*pt[1]; } auto double yy(int d, double pt[]); double yy(int d, double pt[]) { return -5.0 - 7.0*pt[0] + 17.0*pt[2]; } double xe = xx(d, v0); // poderia ser v4 double xd = xx(d, v7); // poderia ser v3 double ye = yy(d, v3); // poderia ser v0 double yd = yy(d, v4); // poderia ser v7 pswr_rectangle(ps, xe, xd, ye, yd, fill, draw); double xl = xx(d, v1); // poderia ser v5 double xr = xx(d, v6); // poderia ser v2 double yl = yy(d, v2); // poderia ser v1 double yr = yy(d, v5); // poderia ser v6 pswr_rectangle(ps, xl, xr, yl, yr, fill, draw); auto void do_seg(double xa, double ya, double xb, double yb); void do_seg(double xa, double ya, double xb, double yb) { double xc = 0.0, yc = 0.0; pswr_segment(ps, xa+xc, ya+yc, xb+xc, yb+yc); //pswr_dot(ps, xa+xc, ya+yc, 1.0, FALSE, TRUE); //pswr_dot(ps, xb+xc, yb+yc, 1.0, FALSE, TRUE); } do_seg(xl, yl, xe, ye); do_seg(xl, yr, xe, yd); do_seg(xr, yl, xd, ye); do_seg(xr, yr, xd, yd); } else { fprintf(stderr,"Nao implementado para dimensao d = %d, - DrawCellsND - imprime.c \n",d); } } //---------------------fim------testes desenhos em 3d---------------- //void escreve_em_arquivo // (int d, int prof, FILE *arq, VNo pac[], double xmin[], double xmax[], Preditor pred, int qv, bool_t elz, bool_t op) //{ // int ord = 5; // int ctr = (int)pow(ord,d)/2; // if( pac[ctr].p == NULL ){ return; } // auto void escreve_arquivo_nd(int d, FILE *arq, No *u, double xmin[], double xmax[]); // void escreve_arquivo_nd(int d, FILE *arq, No *u, double xmin[], double xmax[]) // { // if(u == NULL){ return; } /* paranoia */ // assert( (u->fil[0] == NULL) == (u->fil[1] == NULL) ); // assert(u->fval == u->fv[1]); // /* Determina o valor a plotar: */ // double val = u->fv[qv]; // switch(d){ // case 1 : // fprintf(arq,"%10.6f %10.6f\n", xmin[0], val); // fprintf(arq,"%10.6f %10.6f\n", xmax[0], val); // break; // case 2 : /* posicao dos vertices 01 --- 11 00 --- 10 */ //if (/*(! elz) ||*/ (val)) // { // fprintf(arq,"%10.6f %10.6f %10.6f\n", xmin[0], xmin[1], val); /* 00 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmax[0], xmin[1], val); /* 10 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmax[0], xmax[1], val); /* 11 */ //fprintf(arq,"%10.6f %10.6f %10.6f\n", xmin[0], xmax[1], val); /* 01 */ // } // break; // case 3 : // fprintf(stderr,"Nao implementado para dimensao 3, por enquanto - escreve_arquivo_nd\n"); /* fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*pos[d-1] , val); fprintf(arq,"%10.6f %10.6f\n", xmin[d-1] + Dx[d-1]*(pos[d-1]+1) , val); */ // break; // default : // fprintf(stderr,"Nao implementado para dimensao acima de 3 - escreve_arquivo_nd\n"); // } // return; // } // // int ex = prof % d; // int qual; // for(qual=0;qual<2;qual++) // { // int tm = ipow(ord,d); // VNo pacf[tm]; // double xminf[d], xmaxf[d]; // /* Constrói o pacote do filho {qual}: */ // divide_pacote_geral(d, pac, ex, pred, qual, pacf, op); // limites_celula( d, ex, qual, xmin, xmax, xminf, xmaxf); // escreve_em_arquivo( d, prof+1, arq, pacf, xminf, xmaxf, pred, qv, FALSE,op); // } // /* desenha so as folhas */ // assert( (pac[ctr].p->fil[0] == NULL) == (pac[ctr].p->fil[1] == NULL) ); // if(pac[ctr].p->fil[0] == NULL) // { // escreve_arquivo_nd( d, arq, pac[ctr].p, xmin, xmax); // } //} void cpu_time_seq(FILE *arq, char EP[], char G[], char ER[], char U[], char A[], char CP[]) { fprintf(arq,"%s %s \t%s \t%s \t%s \t%s \t%s\n", "#", EP, G, ER, U, A, CP); /* 00 */ } void cpu_time(FILE *arq, double eps, double ganho, double erro, double unif, double adapt, double comp) { fprintf(arq,"%.10f %.10f %.10f %.10f %.10f %.10f\n", eps, ganho, erro, unif, adapt, comp); } int qtd_cel_eixo(int d, int ex, int prof) { int qtd = 0, q; /* q eh o numero de bits que deve conter a representacao binaria da entrada {ex} do vetor posicao de uma celula de indice {I} */ q = prof/d; if(prof%d > ex){ q += 1; } else { q += 0; } qtd = ipow(2,q); return qtd; } void encontra_posicao(int d, int ind, int delta[]) { int bits[96], d0[32],d1[32], d2[32], i=0,l; // zerando, para nao ter problemas com lixo for(l=0;l<32;l++) { d0[l] = 0; d1[l] = 0; d2[l] = 0; } for(l=0;l<86;l++) bits[l] = 0; //coverte ind para binario while (ind != 0) { bits[i++] = ind % 2; ind = ind /2; if(i>96){fprintf(stderr,"indice muito grande, tem mais que 96 bits em binario...\n"); return;} } // IPORTANTE: no vetor bits, os algoritmos 0 1 provenientes da representacao // binaria estao na ordem inversa. Ou seja, se ind = 11 (base 10) entao sua representacao // binaria deveria e ind_2 = 1011 mas em no vetor bits esta armazenado o numero 1101. int cont0 = 0, cont1 = 0, cont2 = 0; for(l=0;lfil[0]==NULL)==(u->fil[1]==NULL)); if(u->fil[0]==NULL){ return;} int qual; for(qual = 0;qual<=1;qual++) { double s = qual == 0 ? -1.0 : 1.0; DrawRelevantNodes(ps, u->fil[qual], prof+1,niv, x + s*20.0/(pow(2.0,prof+1)), y-1.0); // if(u->fil[qual]->virtual_leaf/* && prof!=niv-2*/) // { // pswr_comment(ps, "Thicker blue segments with arrowheads:"); // pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.20, 0.5, 0.5); // } // else { pswr_comment(ps, "Medium solid black segments:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); } MakeRelevantPoints(ps, qual, prof, x, y, FALSE); } } void MakeRelevantPoints(PSStream *ps, int qual, int prof, double xc, double yc, bool_t arrowheads) { auto void do_seg(double xa, double ya, double xb, double yb); void do_seg(double xa, double ya, double xb, double yb) { //pswr_segment(ps, xa+xc, ya+yc, xb+xc, yb+yc); pswr_dot(ps, xa+xc, ya+yc, 0.2, FALSE, TRUE); pswr_dot(ps, xb+xc, yb+yc, 0.2, FALSE, TRUE); if (arrowheads) { pswr_arrowhead(ps, xa+xc, ya+yc, xb+xc, yb+yc, 2.0, 3.0, 0.85, TRUE, TRUE); } } if(qual==0) { do_seg(-20.0/(pow(2.0,prof+1)), -1.0, 0.0, 0.0); /*esq*/ } else { do_seg(0.0, 0.0, 20.0/(pow(2.0,prof+1)), -1.0); /*dir*/ } /* escreve o numero do nivel a qual a celula pertence*/ pswr_comment(ps, "Text in various positions:"); DrawSomeTexts(ps, -1.0, -(prof), prof); /* para desenhar os eixos */ pswr_comment(ps, "Medium solid black segments:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); DrawAxes(ps, -21.5, 1.5, FALSE); } void DrawSomeTexts(PSStream *ps, double xc, double yc, int prof) { auto void do_lab(char *text, double xd, double yd, double xalign, double yalign); void do_lab(char *text, double xd, double yd, double xalign, double yalign) { pswr_set_fill_color(ps, 0.000, 0.700, 1.000); pswr_label(ps, text, xd+xc, yd+yc, xalign, yalign); } pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.50, 0.0, 0.0); pswr_set_label_font(ps, "Times-Roman", 10.0); char strg[10]; sprintf(strg,"%d",prof); do_lab( strg, -20.00, 11.50, 0.5, 0.0); } void DrawAxes(PSStream *ps, double xc, double yc, bool_t arrowheads) { pswr_segment(ps, 1.0+xc, 12.0+yc, 1.0+xc, 0.0+yc); /* left */ pswr_segment(ps, 43.0+xc, 12.0+yc, 43.0+xc, 0.0+yc); /* right */ pswr_segment(ps, 1.0+xc, 11.0+yc, 43.0+xc, 11.0+yc); /* top */ int i; /* tics nas retas verticais */ for (i = -10; i <= +10; i=i+2/*i++*/) { double align = -0.25;//((i % 2) == 0)*0.5 - ((i % 4) == 0)*0.25; double ticksz = 0.5;//0.5 + ((i % 2) == 0)*0.5 + ((i % 4) == 0)*1.0; pswr_tick(ps, VER, 1.0+xc, 6.5+0.5*i+yc, ticksz, align); /* esquerda */ pswr_tick(ps, VER, 43.0+xc, 6.5+0.5*i+yc, ticksz, 1-align); /* direita */ } /* tics na reta horizontal */ for (i = -41; i <= +42; i=i+2/*i++*/) { double align = -0.25;//((i % 2) == 0)*0.5 - ((i % 4) == 0)*0.25; double ticksz = 0.5; //0.5 + ((i % 2) == 0)*0.5 + ((i % 4) == 0)*1.0; pswr_tick(ps, HOR, 21.0 + 0.5*i+xc, 11.0+yc, ticksz, 1-align); } } void DoEPSTests(char *prefixo) { PSStream *ps = pswr_new_stream(TRUE, prefixo, NULL, NULL, 328.0, 246.0); pswr_new_page(ps, NULL); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 4.00, 324.00, 3.00, 243.00, 44, 33 ); DrawThings(ps); pswr_close_stream(ps); } void DrawThings(PSStream *ps) { pswr_comment(ps, "Thick solid red frame:"); pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.40, 0.0, 0.0); pswr_frame(ps); pswr_comment(ps, "Thin dashed light yellow gridlines:"); pswr_set_pen(ps, 1.000, 1.000, 0.500, 0.10, 2.0, 1.0); pswr_grid_lines(ps); pswr_comment(ps, "Medium solid black coordinate lines:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_coord_line(ps, HOR, 0.17); pswr_coord_line(ps, VER, 3.14); pswr_comment(ps, "Text in various positions:"); DrawTexts(ps, -20.0, -15.5); pswr_comment(ps, "Medium solid black segments:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); DrawLines(ps, -6.0, -15.5, FALSE); pswr_comment(ps, "Thicker blue segments with arrowheads:"); pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.40, 0.0, 0.0); DrawLines(ps, +8.0, -15.5, TRUE); pswr_comment(ps, "Thin solid black figures, yellow filled:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.10, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 1.000, 0.000); pswr_grid_cell(ps, 3, 2, TRUE, TRUE); DrawFigures(ps, -20.0, +0.5, TRUE, TRUE, FALSE); pswr_comment(ps, "Medium solid red figures, unfilled:"); pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_set_fill_color(ps, -1.00, -1.00, -1.00); pswr_grid_cell(ps, 5, 2, TRUE, TRUE); DrawFigures(ps, -6.0, +0.5, TRUE, TRUE, FALSE); pswr_comment(ps, "Unstroked figures, pink e-o-filled:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.50, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 0.800, 0.700); pswr_grid_cell(ps, 7, 2, TRUE, FALSE); DrawFigures(ps, +8.0, +0.5, TRUE, FALSE, TRUE); } void DrawTexts(PSStream *ps, double xc, double yc) { /* Usable area [0 _ 12]�[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); auto void do_lab(char *text, double xd, double yd, double xalign, double yalign); void do_lab(char *text, double xd, double yd, double xalign, double yalign) { pswr_set_fill_color(ps, 0.000, 0.700, 1.000); pswr_dot(ps, xd+xc, yd+yc, 0.3, TRUE, FALSE); pswr_label(ps, text, xd+xc, yd+yc, xalign, yalign); } pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.50, 0.0, 0.0); pswr_set_label_font(ps, "Courier", 10.0); do_lab("red C10", +1.00, +3.00, 0.0, 0.0); pswr_set_label_font(ps, "Times-Roman", 12.0); do_lab("red TR12", +6.00, +6.00, 0.5, 0.0); pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.50, 0.0, 0.0); pswr_set_label_font(ps, "Helvetica", 8.0); do_lab("blu H8", +11.00, +9.00, 1.0, 0.5); pswr_set_label_font(ps, "Courier", 12.0); do_lab("blu C12", +1.00, +12.00, 0.0, 0.5); } void DrawLines(PSStream *ps, double xc, double yc, bool_t arrowheads) { /* Usable area [0 _ 12]�[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); auto void do_seg(double xa, double ya, double b, double yb); void do_seg(double xa, double ya, double xb, double yb) { pswr_segment(ps, xa+xc, ya+yc, xb+xc, yb+yc); pswr_dot(ps, xa+xc, ya+yc, 1.0, FALSE, TRUE); pswr_dot(ps, xb+xc, yb+yc, 1.0, FALSE, TRUE); if (arrowheads) { pswr_arrowhead(ps, xa+xc, ya+yc, xb+xc, yb+yc, 2.0, 3.0, 0.85, TRUE, TRUE); } } do_seg(1.0, 1.0, 11.0, 3.0); do_seg(1.0, 3.0, 11.0, 1.0); pswr_segment(ps, 1.0+xc, 5.0+yc, 1.0+xc, 13.0+yc); pswr_segment(ps, 11.0+xc, 5.0+yc, 11.0+xc, 13.0+yc); pswr_segment(ps, 2.0+xc, 14.0+yc, 10.0+xc, 14.0+yc); int i; for (i = -7; i <= +7; i++) { double align = ((i % 2) == 0)*0.5 - ((i % 4) == 0)*0.25; double ticksz = 0.5 + ((i % 2) == 0)*0.5 + ((i % 4) == 0)*1.0; pswr_tick(ps, VER, 1.0+xc, 9.0+0.5*i+yc, ticksz, align); pswr_tick(ps, VER, 11.0+xc, 9.0+0.5*i+yc, ticksz, 1-align); pswr_tick(ps, HOR, 6.0 + 0.5*i+xc, 14.0+yc, ticksz, 1-align); } pswr_curve(ps, 4.0+xc, 4.0+yc, 11.0+xc, 14.0+yc, 1.0+xc, 14.0+yc, 8.0+xc, 4.0+yc ); pswr_dot(ps, 4.0+xc, 4.0+yc, 1.0, FALSE, TRUE); pswr_dot(ps, 11.0+xc, 14.0+yc, 0.5, FALSE, TRUE); pswr_dot(ps, 1.0+xc, 14.0+yc, 0.5, FALSE, TRUE); pswr_dot(ps, 8.0+xc, 4.0+yc, 1.0, FALSE, TRUE); } void DrawFigures(PSStream *ps, double xc, double yc, bool_t fill, bool_t draw, bool_t eo) { /* Usable area [0 _ 12]�[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); int n = 17; double x[n], y[n]; int i; for (i = 0; i < n; i++) { double t = 2.0*3.1415926*((double)i)/((double)n); double r = (0.75 +0.25*cos(t)); x[i] = xc + 3.0 + 2.0*r*cos(2*t); y[i] = yc + 2.0 + 1.5*r*sin(2*t); } pswr_rectangle(ps, 7.0+xc, 9.0+xc, 1.5+yc, 3.5+yc, fill, draw); pswr_circle(ps, 3.0+xc, 7.0+yc, 2.0, fill, draw); pswr_dot(ps, 3.0+xc, 7.0+yc, 2.0, fill, draw); pswr_lune(ps, 9.0+xc, 7.0+yc, 1.5, 45.0, fill, draw); pswr_slice(ps, 3.0+xc, 12.0+yc, 2.0, 30.0, 135.0, fill, draw); pswr_polygon(ps, x, y, n, fill, draw, eo); pswr_triangle(ps, 7.0+xc, 10.0+yc, 11.0+xc, 12.0+yc, 9.0+xc, 14.0+yc, fill, draw); } void teste(No *r, int prof) { if(prof == 0){fprintf(stderr,"imprime.c - teste -\n");} if(r->fil[0] == NULL) {return;} int qual; for(qual = 0;qual<2;qual++) teste(r->fil[qual],prof+1); if(r->fil[0]==NULL) fprintf(stderr, "%*st\n", 2*prof, "-"); }