gpt4 book ai didi

c++ - 如何使用 x y z 坐标创建 3D 图像

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:38 24 4
gpt4 key购买 nike

我得到了使用数据中的 x、y、z 坐标生成 2D 图像的代码,我想修改此代码以创建 3D 图像。 (代码来源:https://physiology.arizona.edu/people/secomb/netflow)

下面的代码创建一个 2D 图像,使用数据中的 x y z 坐标我想修改代码以创建 3D 图像

例如:转这个https://www.researchgate.net/figure/A-2D-meshed-model-of-the-flow-network-in-GAMBIT_fig12_266171604

进入这个https://www.researchgate.net/figure/Single-phase-two-component-flow-in-a-blood-vessel-network-One-dimensional-elements-are_fig4_283761787

这是C++代码,我在visual studio 2019中使用它


/**********************************************************
picturenetwork.cpp - project network on z = 0 plane
Labels nodes with nodvar and segments with segvar (must be float)
Colors segments according to segvar
Generates a postscript file
Version for NetFlowV1, TWS Oct. 2012
***********************************************************/
#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "nrutil.h"

void picturenetwork(float *nodvar, float *segvar, const char fname[])
{
extern int nseg,nnod;
extern int *segtyp,*ista,*iend;
extern float *diam,**cnode;
int k,iseg,inod,ilevel,nlevel = 100;
float xmin,xmax,ymin,ymax,xs,ys,zs,picfac,red,green,blue,xz,xzmin,xzmax, zzmin, zzmax;
float diamfac = 1.,zcoord,zbottom,ztop,zmin,zmax;
FILE *ofp;

//Determine range of x,y,z values
xmin = 1.e6;
xmax = -1.e6;
ymin = 1.e6;
ymax = -1.e6;
zmin = 1.e6;
zmax = -1.e6;
for(inod=1; inod<=nnod; inod++){
xmin = FMIN(xmin,cnode[1][inod]);
xmax = FMAX(xmax,cnode[1][inod]);
ymin = FMIN(ymin,cnode[2][inod]);
ymax = FMAX(ymax,cnode[2][inod]);
zmin = FMIN(zmin,cnode[3][inod]);
zmax = FMAX(zmax,cnode[3][inod]);
}
zmin -= 1.; //make sure everything is included
zmax += 1.;

picfac = FMIN(500./(xmax - xmin),700./(ymax - ymin));
ofp = fopen(fname, "w");

fprintf(ofp, "%%!PS-Adobe-2.0\n");
fprintf(ofp, "%%%%Pages: 1\n");
fprintf(ofp, "%%%%EndComments\n");
fprintf(ofp, "%%%%Page: 1 1\n");
fprintf(ofp, "/mx {%g sub %g mul 50 add} def\n",xmin,picfac);
fprintf(ofp, "/my {%g sub %g mul 50 add} def\n",ymin,picfac);
fprintf(ofp, "/cf {closepath fill} def\n");
fprintf(ofp, "/cs {closepath stroke} def\n");
fprintf(ofp, "/m {moveto} def\n");
fprintf(ofp, "/n {newpath} def\n");
fprintf(ofp, "/l {lineto} def\n");
fprintf(ofp, "/sl {setlinewidth} def\n");
fprintf(ofp, "/sc {setrgbcolor} def\n");
fprintf(ofp, "/s {stroke} def\n");
fprintf(ofp, "/Times-Roman findfont\n");
fprintf(ofp, "8 scalefont\n");
fprintf(ofp, "setfont\n");

fprintf(ofp, "newpath\n");
fprintf(ofp, "%g mx %g my m\n",xmin,ymin);
fprintf(ofp, "%g mx %g my l\n",xmax,ymin);
fprintf(ofp, "%g mx %g my l\n",xmax,ymax);
fprintf(ofp, "%g mx %g my l\n",xmin,ymax);
fprintf(ofp, "closepath\n");
fprintf(ofp, "stroke\n");

fprintf(ofp, "/Times-Roman findfont\n");
fprintf(ofp, "4 scalefont\n");
fprintf(ofp, "setfont\n");

//plot vessels colored according to segvar, in order from bottom to top according to z-coordinate
xzmin = 1.e6;
xzmax = -1.e6;
for(iseg=1; iseg<=nseg; iseg++) if(segtyp[iseg] == 4 || segtyp[iseg] == 5){
xzmin = FMIN(xzmin,segvar[iseg]);
xzmax = FMAX(xzmax,segvar[iseg]);
}
for(ilevel=1; ilevel<=nlevel; ilevel++){
zbottom = zmin + (ilevel-1)*(zmax - zmin)/nlevel;
ztop = zmin + ilevel*(zmax - zmin)/nlevel;
for(iseg=1; iseg<=nseg; iseg++) if(segtyp[iseg] == 4 || segtyp[iseg] == 5){
zcoord = (cnode[3][ista[iseg]] + cnode[3][iend[iseg]])/2.;
if(zcoord >= zbottom && zcoord < ztop){
if(xzmin != xzmax) xz = (segvar[iseg] - xzmin)/(xzmax - xzmin);
else xz = 0.75;
blue = FMIN(FMAX(1.5-4.*fabs(xz-0.25), 0.), 1.);//Set up colors using Matlab 'jet' scheme
green= FMIN(FMAX(1.5-4.*fabs(xz-0.5), 0.), 1.);
red = FMIN(FMAX(1.5-4.*fabs(xz-0.75), 0.), 1.);
fprintf(ofp,"%f %f %f sc\n",red,green,blue);
fprintf(ofp,"%g sl\n",picfac*diam[iseg]*diamfac);//line widths scaled up by diamfac
fprintf(ofp, "%g mx %g my m ", cnode[1][ista[iseg]],cnode[2][ista[iseg]],cnode[3][ista[iseg]]);
fprintf(ofp, "%g mx %g my l s \n", cnode[1][iend[iseg]],cnode[2][iend[iseg]],cnode[3][iend[iseg]]);
}
}
}

创建的图片是.ps文件,目前没有错误。 主要问题是生成的图像是 2D 而不是 3D。该图像是不同颜色的容器。

最佳答案

使用此代码无法创建 3D 模型。此代码正在输出不支持 3D 图形的 .ps 文件。

关于c++ - 如何使用 x y z 坐标创建 3D 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56152442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com