static void drawTria (pScene sc, pMesh mesh, int k) { pMaterial pm; pTriangle pt; pPoint p0, p1, p2; double ax, ay, az, bx, by, bz, dd; float shrink, cx, cy, cz, n[3]; /* default */ if (ddebug) printf("draw triangle %d\n", k); if (k < 1 || k > mesh->nt) return; pt = &mesh->tria[k]; if (refpick > 0) pt->ref = refpick; refmat = matRef(sc, pt->ref); p0 = &mesh->point[pt->v[0]]; p1 = &mesh->point[pt->v[1]]; p2 = &mesh->point[pt->v[2]]; pm = &sc->material[refmat]; cx = (p0->c[0] + p1->c[0] + p2->c[0]) / 3.; cy = (p0->c[1] + p1->c[1] + p2->c[1]) / 3.; cz = (p0->c[2] + p1->c[2] + p2->c[2]) / 3.; shrink = 0.95 * sc->shrink; glBegin(GL_TRIANGLES); glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]); /* compute normal */ ax = p1->c[0] - p0->c[0]; ay = p1->c[1] - p0->c[1]; az = p1->c[2] - p0->c[2]; bx = p2->c[0] - p0->c[0]; by = p2->c[1] - p0->c[1]; bz = p2->c[2] - p0->c[2]; n[0] = ay * bz - az * by; n[1] = az * bx - ax * bz; n[2] = ax * by - ay * bx; dd = n[0] * n[0] + n[1] * n[1] + n[2] * n[2]; if (dd > 0.0f) { dd = 1.0f / sqrt(dd); n[0] *= dd; n[1] *= dd; n[2] *= dd; } glNormal3fv(n); glVertex3f(shrink * (p0->c[0] - cx) + cx, shrink * (p0->c[1] - cy) + cy, shrink * (p0->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(shrink * (p1->c[0] - cx) + cx, shrink * (p1->c[1] - cy) + cy, shrink * (p1->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(shrink * (p2->c[0] - cx) + cx, shrink * (p2->c[1] - cy) + cy, shrink * (p2->c[2] - cz) + cz); glEnd(); glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]); output3(p0->c[0], p0->c[1], p0->c[2], "%d", pt->v[0]); output3(p1->c[0], p1->c[1], p1->c[2], "%d", pt->v[1]); output3(p2->c[0], p2->c[1], p2->c[2], "%d", pt->v[2]); }
static void drawHexa (pScene sc, pMesh mesh, int k) { pMaterial pm; pHexa ph; pPoint p0; float n[3]; /*float shrink; */ int l; /* default */ if (ddebug) printf("draw hexa %d\n", k); if (k < 1 || k > mesh->nhex) return; ph = &mesh->hexa[k]; if (refpick > 0) ph->ref = refpick; refmat = matRef(sc, ph->ref); pm = &sc->material[refmat]; /*shrink = 0.95 * sc->shrink;*/ glBegin(GL_QUADS); glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]); for (l = 0; l < 6; l++) { pPoint p1, p2, p3; float ax, ay, az, bx, by, bz, d; float cx, cy, cz; p0 = &mesh->point[ph->v[ch[l][0]]]; p1 = &mesh->point[ph->v[ch[l][1]]]; p2 = &mesh->point[ph->v[ch[l][2]]]; p3 = &mesh->point[ph->v[ch[l][3]]]; cx = (p0->c[0] + p1->c[0] + p2->c[0] + p3->c[0]) / 4.; cy = (p0->c[1] + p1->c[1] + p2->c[1] + p3->c[1]) / 4.; cz = (p0->c[2] + p1->c[2] + p2->c[2] + p3->c[2]) / 4.; /* compute face normal */ ax = p1->c[0] - p0->c[0]; ay = p1->c[1] - p0->c[1]; az = p1->c[2] - p0->c[2]; bx = p2->c[0] - p0->c[0]; by = p2->c[1] - p0->c[1]; bz = p2->c[2] - p0->c[2]; n[0] = ay * bz - az * by; n[1] = az * bx - ax * bz; n[2] = ax * by - ay * bx; d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2]; if (d > 0.0f) { d = 1.0 / sqrt(d); n[0] *= d; n[1] *= d; n[2] *= d; } glNormal3fv(n); glVertex3f(sc->shrink * (p0->c[0] - cx) + cx, sc->shrink * (p0->c[1] - cy) + cy, sc->shrink * (p0->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(sc->shrink * (p1->c[0] - cx) + cx, sc->shrink * (p1->c[1] - cy) + cy, sc->shrink * (p1->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(sc->shrink * (p2->c[0] - cx) + cx, sc->shrink * (p2->c[1] - cy) + cy, sc->shrink * (p2->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(sc->shrink * (p3->c[0] - cx) + cx, sc->shrink * (p3->c[1] - cy) + cy, sc->shrink * (p3->c[2] - cz) + cz); } glEnd(); /* display vertex number */ glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]); for (l = 0; l < 8; l++) { p0 = &mesh->point[ph->v[l]]; output3(p0->c[0], p0->c[1], p0->c[2], "%d", ph->v[l]); } }
int createParticle(pScene sc,pMesh mesh) { pParticle pp; pStream st; pMaterial pm; pTetra pt1; pTriangle pt; pPoint ppt; double v[4],cx,cy,cz; int i,j,k,l,nmat,nbp,base; if ( ddebug ) printf("create particles\n"); if ( egal(sc->iso.val[0],sc->iso.val[MAXISO-1]) ) return(0); if ( sc->stream ) { st = sc->stream; if ( st->listp ) free(st->listp); free(sc->stream); } sc->stream = createStream(sc,mesh); sc->par.cumtim = 0.0; sc->par.advtim = 0; assert(sc->stream); st = sc->stream; fprintf(stdout," Creating particles :"); fflush(stdout); st->nbstl = 0; base = ++mesh->mark; pt = &mesh->tria[refitem]; nmat = matRef(sc,pt->ref); pm = &sc->material[nmat]; k = pm->depmat[LTria]; if ( !k || pm->flag ) return(0); /* point positions */ for (i=1; i<=mesh->np; i++) { ppt = &mesh->point[i]; ppt->mark = base; } if ( sc->par.nbpart >= MAX_PRT ) sc->par.nbpart = MAX_PRT; ++base; l = 1; nbp = 0; while ( k != 0 && st->nbstl < MAX_LST-1 ) { pt = &mesh->tria[k]; if ( pt->v[0] ) { cx = cy = cz = 0.0; for (i=0; i<3; i++) { ppt = &mesh->point[pt->v[i]]; cx += 0.33 * ppt->c[0]; cy += 0.33 * ppt->c[1]; cz += 0.33 * ppt->c[2]; ppt->flag = 1; } st->listp[l++] = cx; st->listp[l++] = cy; st->listp[l++] = cz; ++st->nbstl; if ( st->nbstl > MAX_LST-1 ) break; k = pt->nxt; } } fprintf(stdout,"%d\n",st->nbstl); if ( !st->nbstl ) return(0); /* init positions */ tp = calloc((st->nbstl+1),sizeof(Particle)); assert(tp); for (k=1; k<=st->nbstl; k++) tp[k].nsdep = mesh->ntet / 2; for (k=1; k<=mesh->ntet; k++) mesh->tetra[k].cpt = 0; l = 1; for (k=1; k<=st->nbstl; k++) { pp = &tp[k]; pp->pos[1][0] = st->listp[l++]; pp->pos[1][1] = st->listp[l++]; pp->pos[1][2] = st->listp[l++]; tp[k].nsdep = locateTetra(mesh,pp->nsdep,++mesh->mark,pp->pos[1],pp->cb); if ( !pp->nsdep ) { for (j=1; j<=mesh->ntet; j++) { pt1 = &mesh->tetra[j]; if ( pt1->mark != mesh->mark && inTetra(mesh,j,pp->pos[1],pp->cb) ) break; } if ( j > mesh->ntet ) return(0); else pp->nsdep = j; } pp->norm = field3DInterp(mesh,tp[k].nsdep,tp[k].cb,v); pp->size = sizeTetra(mesh,tp[k].nsdep); if ( pp->size == 0.0 ) pp->step = EPS*sc->dmax; else pp->step = HSIZ * min(pp->size,pp->norm); pp->step = min(0.05*sc->par.dt,pp->step); pp->flag = 1; pp->cur = 1; colorParticle(sc,pp); for (i=2; i<=sc->par.nbpart; i++) { pp->pos[i][0] = pp->pos[1][0]; pp->pos[i][1] = pp->pos[1][1]; pp->pos[i][2] = pp->pos[1][2]; } } return(1); }
static void drawTets (pScene sc, pMesh mesh, int k) { pMaterial pm; pTetra pt; pPoint p0, p1, p2, p3; float n[3]; float shrink; int l; /* default */ if (ddebug) printf("draw tetra %d\n", k); if (k < 1 || k > mesh->ntet) return; pt = &mesh->tetra[k]; if (refpick > 0) pt->ref = refpick; refmat = matRef(sc, pt->ref); pm = &sc->material[refmat]; shrink = 0.95 * sc->shrink; glBegin(GL_TRIANGLES); glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]); for (l = 0; l < 4; l++) { float ax, ay, az, bx, by, bz, d; float cx, cy, cz; p0 = &mesh->point[pt->v[ct[l][0]]]; p1 = &mesh->point[pt->v[ct[l][1]]]; p2 = &mesh->point[pt->v[ct[l][2]]]; cx = (p0->c[0] + p1->c[0] + p2->c[0]) / 3.; cy = (p0->c[1] + p1->c[1] + p2->c[1]) / 3.; cz = (p0->c[2] + p1->c[2] + p2->c[2]) / 3.; /* compute face normal */ ax = p1->c[0] - p0->c[0]; ay = p1->c[1] - p0->c[1]; az = p1->c[2] - p0->c[2]; bx = p2->c[0] - p0->c[0]; by = p2->c[1] - p0->c[1]; bz = p2->c[2] - p0->c[2]; n[0] = ay * bz - az * by; n[1] = az * bx - ax * bz; n[2] = ax * by - ay * bx; d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2]; if (d > 0.0f) { d = 1.0 / sqrt(d); n[0] *= d; n[1] *= d; n[2] *= d; } glNormal3fv(n); glVertex3f(shrink * (p0->c[0] - cx) + cx, shrink * (p0->c[1] - cy) + cy, shrink * (p0->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(shrink * (p1->c[0] - cx) + cx, shrink * (p1->c[1] - cy) + cy, shrink * (p1->c[2] - cz) + cz); glNormal3fv(n); glVertex3f(shrink * (p2->c[0] - cx) + cx, shrink * (p2->c[1] - cy) + cy, shrink * (p2->c[2] - cz) + cz); } glEnd(); /* display vertex number */ p0 = &mesh->point[pt->v[0]]; p1 = &mesh->point[pt->v[1]]; p2 = &mesh->point[pt->v[2]]; p3 = &mesh->point[pt->v[3]]; glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]); output3(p0->c[0], p0->c[1], p0->c[2], "%d", pt->v[0]); output3(p1->c[0], p1->c[1], p1->c[2], "%d", pt->v[1]); output3(p2->c[0], p2->c[1], p2->c[2], "%d", pt->v[2]); output3(p3->c[0], p3->c[1], p3->c[2], "%d", pt->v[3]); /*if ( mesh->nfield == 6 ) drawEllipse(sc,mesh,LTets,k);*/ if (!mesh->nbb) circumSphere(sc, mesh, LTets, k); }
GLuint geomList(pScene sc,pMesh mesh) { GLuint list = 0; pMaterial pm; pEdge pr; pPoint ppt,pp0,pp1; double dd; float n[3]; int k,it = 0,nm; static float green[4] = {0.0, 1.0, 0.0, 1.0}; static float rouge[4] = {1.0, 0.0, 0.0, 1.0}; static float jaune[4] = {1.0, 1.0, 0.0, 1.0}; /* default */ if ( mesh->na+mesh->nc+mesh->np == 0 ) { fprintf(stderr,"ZE MESH IST EMPTY!!!\n"); return(0); } /* create display list */ list = glGenLists(1); if ( !list ) return(0); glNewList(list,GL_COMPILE); /*if ( glGetError() ) return(0);*/ /*fprintf(stdout,"GLERROR: %d\n", glGetError());*/ /* draw corners, ridges and required items */ if ( ddebug ) printf("construct point list\n"); if ( mesh->ne ) { /*--- nouvelle partie -> Laurent glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glEnable(GL_LIGHTING); for (k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; if ( ppt->tag & M_UNUSED && !ppt->ref ) continue; if ( ppt->tag == M_CORNER ) glColor3fv(rouge); else if ( ppt->tag == M_REQUIRED ) glColor3fv(green); else continue; it++; glPushMatrix(); glTranslatef(ppt->c[0],ppt->c[1],ppt->c[2]); glutSolidSphere(0.1*sc->dmax,10,10); glPopMatrix(); } glDisable(GL_LIGHTING); ---*/ /*--- ancienne partie --- */ glPointSize(sc->par.pointsize); glBegin(GL_POINTS); for (k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; if ( ppt->tag & M_UNUSED && !ppt->ref ) continue; if ( ppt->tag == M_CORNER ) glColor3fv(rouge); else if ( ppt->tag == M_REQUIRED ) glColor3fv(green); else continue; it++; if ( sc->par.linc == 1 ) glColor3fv(sc->par.edge); glVertex3f(ppt->c[0],ppt->c[1],ppt->c[2]); } glEnd(); /*-------------------------*/ glPointSize(1); } else { pm = &sc->material[DEFAULT_MAT]; glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,pm->dif); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,pm->amb); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,pm->spe); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,pm->emi); glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,&pm->shininess); /*--- nouvelle partie -> Alexandra glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glEnable(GL_LIGHTING); for (k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; it++; glPushMatrix(); glTranslatef(ppt->c[0],ppt->c[1],ppt->c[2]); glutSolidSphere(0.01*sc->dmax,10,10); glPopMatrix(); } glDisable(GL_LIGHTING); ---*/ glBegin(GL_POINTS); for (k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; n[0] = ppt->c[0] - sc->cx; n[1] = ppt->c[1] - sc->cy; n[2] = ppt->c[2] - sc->cz; dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2]; if ( dd > 0.0 ) { dd = 1.0 / sqrt(dd); n[0] *= dd; n[1] *= dd; n[2] *= dd; } glNormal3fv(n); glVertex3f(ppt->c[0],ppt->c[1],ppt->c[2]); } glEnd(); it = mesh->np; } /* draw edges */ if ( ddebug ) printf("construct edge list\n"); glLineWidth(sc->par.linewidth); glBegin(GL_LINES); for (k=1; k<=mesh->na; k++) { pr = &mesh->edge[k]; if ( pr->v[0] > mesh->np || pr->v[1] > mesh->np ) continue; if ( pr->tag & M_RIDGE ) { if ( pr->tag & M_TAG ) glColor3fv(jaune); /* ridge + ref en jaune */ else glColor3fv(rouge); /* ridges en rouge */ } else if ( !pr->ref ) { glColor3fv(sc->par.edge); } else { nm = matRef(sc,pr->ref); pm = &sc->material[nm]; glColor3fv(pm->dif); } if ( sc->par.linc == 1 ) glColor3fv(sc->par.edge); pp0 = &mesh->point[pr->v[0]]; pp1 = &mesh->point[pr->v[1]]; glVertex3f(pp0->c[0],pp0->c[1],pp0->c[2]); glVertex3f(pp1->c[0],pp1->c[1],pp1->c[2]); it++; } glEnd(); glLineWidth(1.0); glEndList(); if ( it == 0 ) { glDeleteLists(list,1); return(0); } else return(list); }