📄 ibg2ydl.c
字号:
/* last edit: Ilja Schmelzer -------------- 24-MAR-1995 20:44:26.45 */
/************************************************************************/
/* */
/* <<< I B G >>> - Intersection - Based Grid generation package */
/* */
/* Version 1.1 by Ilja Schmelzer schmelzer@iaas-berlin.d400.de */
/* */
/* to be distributed under IBG license conditions (see "readme.ibg") */
/* */
/************************************************************************/
/* <<< IBG to YDL >>> */
/*
This file contains an file output from the grid of type ibGrid.
The file created by a call of ibgToYDL can be used by the powerflip
program available on Silicon Graphics workstations.
The selection mechanism (ibgOutputType, ibgOSelectedRegion and so on)
is declared in "ibgoutput.h". The related data will be handled in the
following files:
"ibgoutput.c" general default initialization
"ibgexamples.c" application-specific modification
"ibgcontrol.c" pattern for user control of the
selection parameter (trivial).
You can also modify this file changing the printf calls to
create files in your preferred file format.
*/
#include "ibgoutput.h"
#include "ibgapplication.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "ibgg.h"
#include "ibglib.h"
#include "ibgdefault.h"
int ibgToYDL(ibGrid *gg, FILE* out);
/*************************************************************************/
int ibgToYDL(ibGrid *gg, FILE* out)
{int gdim,col,cl,cr,ul,ur,ic,t,u,in,nn,n1,n2,n3,n;
int *cs,*cn,*nnum,*cnum,i,nmax,rc;
double x1,x2,x3,y1,y2,y3,z1,z2,z3;
double detx,dety,detz,norm;
ibgFloat xm,ym,zm,xd,yd,zd;
ibgPoint *point;
rc = ibgSuccess;
gdim = gg->gridDimension;
/* creation of the list of all cells and points which have to be written out: */
cnum = calloc((gg->lastCell+1),sizeof(int)); /* zero initialization */
nnum = calloc((gg->lastPoint+1),sizeof(int));
if(gdim==2){
foribgRegionCells(*gg,ic,t,u){
if(ibgOSelectedRegion(u)){
cnum[ic] = 1; cn = ibgridCPointList(*gg,ic);
for(n=0;n<ibgcPoints(t);n++){
nnum[cn[n]] = 1; /* marking the points */
}
}
}endibgRegionCells(*gg,ic,t,u);
}else if(gdim==3){
foribgFaceCells(*gg,ic,t,u){
cl = ibgridCellLeft( *gg,ic,t);
cr = ibgridCellRight(*gg,ic,t);
if(cl>0) ul = ibgridCellSegment(*gg,cl); else ul = -cl;
if(cr>0) ur = ibgridCellSegment(*gg,cr); else ur = -cr;
if(ibgOSelectedFace(u,ul,ur)){
cnum[ic] = 1; cn = ibgridCPointList(*gg,ic);
for(n=0;n<ibgcPoints(t);n++){
nnum[cn[n]] = 1; /* marking the points */
}
}
}endibgFaceCells(*gg,ic,t,u);
}
nmax = 0;
foribgPoints(*gg,in,t,u,point){
if(nnum[in]) nnum[in] = ++nmax; /* enumeration of the points */
}endibgPoints(*gg,in,t,u,point);
/* writing the point data: */
fprintf(out," v = vertices");
xm = ibgridXMin(*gg,0); xd = ibgridXMax(*gg,0) - xm;
ym = ibgridXMin(*gg,1); yd = ibgridXMax(*gg,1) - ym;
zm = ibgridXMin(*gg,2); zd = ibgridXMax(*gg,2) - zm;
foribgPoints(*gg,in,t,u,point){
if(nnum[in]==0) continue;
fprintf(out,"\n %f %f %f" ,(ibgpX(*point)[0]-xm)/xd
,(ibgpX(*point)[1]-ym)/yd
,(ibgpX(*point)[2]-zm)/zd );
}endibgPoints(*gg,in,t,u,point);
fprintf(out,",\n i = (indices");
if(gdim==2){
foribgRegionCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
ibgassert(ibgcCDIM(t)==2);
fprintf(out,"\n");
/* loop over the points of the cell:*/
cn = ibgridCPointList(*gg,ic);
for(i=0;i<ibgcPoints(t);i++){
nn = cn[i]; /* nn is number in grid */
ibgassert(nn>0);
nn = nnum[nn]; /* nn is now number in file */
ibgassert(nn>0);
fprintf(out," %d",nn-1); /* beg. with zero */
}
fprintf(out,",");
}endibgRegionCells(*gg,ic,t,u);
}else if(gdim==3){
foribgFaceCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
ibgassert(ibgcCDIM(t)==2);
fprintf(out,"\n");
/* loop over the points of the cell: */
cn = ibgridCPointList(*gg,ic);
for(i=0;i<ibgcPoints(t);i++){
nn = cn[i]; /* nn is number in grid */
ibgassert(nn>0);
nn = nnum[nn]; /* nn is now number in file */
ibgassert(nn>0);
fprintf(out," %d",nn-1); /* beg. with zero */
}
fprintf(out,",");
}endibgFaceCells(*gg,ic,t,u);
}
fprintf(out,"\n ), \n\n (indexpolygons v, i :");
fprintf(out,"\n colors");
if(gdim==2){
foribgRegionCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
col = ibgColorRegion(u);
fprintf(out,"\n %lf %lf %lf",
(ibgColorOf[col].r)/((double)ibgColOn),
(ibgColorOf[col].g)/((double)ibgColOn),
(ibgColorOf[col].b)/((double)ibgColOn));
}endibgRegionCells(*gg,ic,t,u);
}else if(gdim==3){
foribgFaceCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
ul = ibgridCellSegment(*gg,cl = ibgridCellLeft( *gg,ic,t));
ur = ibgridCellSegment(*gg,cr = ibgridCellRight(*gg,ic,t));
col = ibgColorFace(u,ul,ur);
fprintf(out,"\n %lf %lf %lf",
(ibgColorOf[col].r)/((double)ibgColOn),
(ibgColorOf[col].g)/((double)ibgColOn),
(ibgColorOf[col].b)/((double)ibgColOn));
}endibgFaceCells(*gg,ic,t,u);
}
fprintf(out,","); fprintf(out,"\n normals");
if(gdim==2){
foribgRegionCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
fprintf(out,"\n %lf %lf %lf",0.0,0.0,1.0);
}endibgRegionCells(*gg,ic,t,u);
}else if(gdim==3){
foribgFaceCells(*gg,ic,t,u){
if(cnum[ic]==0) continue;
ul = ibgridCellSegment(*gg,cl = ibgridCellLeft( *gg,ic,t));
ur = ibgridCellSegment(*gg,cr = ibgridCellRight(*gg,ic,t));
cn = ibgridCPointList(*gg,ic);
n1= *(cn++); n2= *(cn++); n3= *(cn++);
x1=ibgpX(ibgridPoint(*gg,n1))[0];
y1=ibgpX(ibgridPoint(*gg,n1))[1];
z1=ibgpX(ibgridPoint(*gg,n1))[2];
x2=ibgpX(ibgridPoint(*gg,n2))[0]-x1;
y2=ibgpX(ibgridPoint(*gg,n2))[1]-y1;
z2=ibgpX(ibgridPoint(*gg,n2))[2]-z1;
x3=ibgpX(ibgridPoint(*gg,n3))[0]-x1;
y3=ibgpX(ibgridPoint(*gg,n3))[1]-y1;
z3=ibgpX(ibgridPoint(*gg,n3))[2]-z1;
detx=y2*z3-z2*y3; dety=z2*x3-x2*z3; detz=x2*y3-y2*x3;
norm=sqrt(detx*detx + dety*dety + detz*detz);
detx /= norm; dety /= norm; detz /= norm;
if(ul>ur) fprintf(out,"\n %lf %lf %lf", detx, dety, detz);
else fprintf(out,"\n %lf %lf %lf",-detx,-dety,-detz);
}endibgFaceCells(*gg,ic,t,u);
}
fprintf(out,"),\n");
free(nnum); free(cnum);
return rc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -