/*
* C code from the article
* "An Implicit Surface Polygonizer"
* by Jules Bloomenthal, jbloom@beauty.gmu.edu
* in "Graphics Gems IV", Academic Press, 1994
*/
/* implicit.c
* an implicit surface polygonizer, translated from Mesa
* applications should call polygonize()
*
* to compile a test program for ASCII output:
* cc implicit.c -o implicit -lm
*
* to compile a test program for display on an SGI workstation:
* cc -DSGIGFX implicit.c -o implicit -lgl_s -lm
*
* Authored by Jules Bloomenthal, Xerox PARC.
* Copyright (c) Xerox Corporation, 1991. All rights reserved.
* Permission is granted to reproduce, use and distribute this code for
* any and all purposes, provided that this notice appears in all copies. */
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "polyparam.h"
#define TET 0 /* use tetrahedral decomposition */
#define NOTET 1 /* no tetrahedral decomposition */
#define RES 10 /* # converge iterations */
#define L 0 /* left direction: -x, -i */
#define R 1 /* right direction: +x, +i */
#define B 2 /* bottom direction: -y, -j */
#define T 3 /* top direction: +y, +j */
#define N 4 /* near direction: -z, -k */
#define F 5 /* far direction: +z, +k */
#define LBN 0 /* left bottom near corner */
#define LBF 1 /* left bottom far corner */
#define LTN 2 /* left top near corner */
#define LTF 3 /* left top far corner */
#define RBN 4 /* right bottom near corner */
#define RBF 5 /* right bottom far corner */
#define RTN 6 /* right top near corner */
#define RTF 7 /* right top far corner */
/* the LBN corner of cube (i, j, k), corresponds with location
* (start.x+(i-.5)*size, start.y+(j-.5)*size, start.z+(k-.5)*size) */
#define RAND() ((rand()&32767)/32767.) /* random number between 0 and 1 */
#define HASHBIT (5)
#define HASHSIZE (size_t)(1<<(3*HASHBIT)) /* hash table size (32768) */
#define MASK ((1<<HASHBIT)-1)
#define HASH(i,j,k) ((((((i)&MASK)<<HASHBIT)|((j)&MASK))<<HASHBIT)|((k)&MASK))
#define BIT(i, bit) (((i)>>(bit))&1)
#define FLIP(i,bit) ((i)^1<<(bit)) /* flip the given bit of i */
typedef struct point { /* a three-dimensional point */
double x, y, z; /* its coordinates */
} POINT;
typedef struct test { /* test the function for a signed value */
POINT p; /* location of test */
double value; /* function value at p */
int ok; /* if value is of correct sign */
} TEST;
typedef struct vertex { /* surface vertex */
POINT position, normal; /* position and surface normal */
} VERTEX;
typedef struct vertices { /* list of vertices in polygonization */
int count, max; /* # vertices, max # allowed */
VERTEX *ptr; /* dynamically allocated */
} VERTICES;
typedef struct corner { /* corner of a cube */
int i, j, k; /* (i, j, k) is index within lattice */
double x, y, z, value; /* location and function value */
} CORNER;
typedef struct cube { /* partitioning cell (cube) */
int i, j, k; /* lattice location of cube */
CORNER *corners[8]; /* eight corners */
} CUBE;
typedef struct cubes { /* linked list of cubes acting as stack */
CUBE cube; /* a single cube */
struct cubes *next; /* remaining elements */
} CUBES;
typedef struct centerlist { /* list of cube locations */
int i, j, k; /* cube location */
struct centerlist *next; /* remaining elements */
} CENTERLIST;
typedef struct cornerlist { /* list of corners */
int i, j, k; /* corner id */
double value; /* corner value */
struct cornerlist *next; /* remaining elements */
} CORNERLIST;
typedef struct edgelist { /* list of edges */
int i1, j1, k1, i2, j2, k2; /* edge corner ids */
int vid; /* vertex id */
struct edgelist *next; /* remaining elements */
} EDGELIST;
typedef struct intlist { /* list of integers */
int i; /* an integer */
struct intlist *next; /* remaining elements */
} INTLIST;
typedef struct intlists { /* list of list of integers */
INTLIST *list; /* a list of integers */
struct intlists *next; /* remaining elements */
} INTLISTS;
typedef struct process { /* parameters, function, storage */
double (*function)(); /* implicit surface function */
int (*triproc)(); /* triangle output function */
double size, delta; /* cube size, normal delta */
int bounds; /* cube range within lattice */
POINT start; /* start point on surface */
CUBES *cubes; /* active cubes */
VERTICES vertices; /* surface vertices */
CENTERLIST **centers; /* cube center hash table */
CORNERLIST **corners; /* corner value hash table */
EDGELIST **edges; /* edge and vertex id hash table */
} PROCESS;
char *mycalloc(int, int);
FILE *fp, *ft;
/**** A Test Program ****/
double myfunc(double x, double y, double z);
int gntris; /* global needed by application */
VERTICES gvertices; /* global needed by application */
/* triangle: called by polygonize() for each triangle; write to stdout */
triangle (i1, i2, i3, vertices)
int i1, i2, i3;
VERTICES vertices;
{
gvertices = vertices;
gntris++;
#if 0
fprintf(stdout, "%d %d %d\n", i1, i2, i3);
#endif
#if 1
fwrite( &i1, sizeof(int), 1, ft);
fwrite( &i2, sizeof(int), 1, ft);
fwrite( &i3, sizeof(int), 1, ft);
#endif
return 1;
}
/* main: call polygonize() with torus function
* write points-polygon formatted data to stdout */
int main ()
{
int i; double tt[6];
char *err, *polygonize();
VERTEX v;
gntris = 0;
fp = fopen("luiz.dat", "w+b");
ft = fopen("tran.dat", "w+b");
if ((err = polygonize(myfunc, myCubeSize, myBound, 0.,0.,0., triangle, TET)) != NULL) {
fprintf(stdout, "%s\n", err);
exit(1);
}
/* fprintf(stdout, "\n%d triangles, %d vertices\n", gntris, gvertices.count); */
/* fprintf(stdout, "\nvertices\n\n"); */
for (i = 0; i < gvertices.count; i++) {
v = gvertices.ptr[i];
#if 0
fprintf(stdout, "%f %f %f\t%f %f %f\n",
v.position.x, v.position.y, v.position.z,
v.normal.x, v.normal.y, v.normal.z);
#endif
tt[0] = v.position.x;
tt[1] = v.position.y;
tt[2] = v.position.z;
tt[3] = v.normal.x;
tt[4] = v.normal.y;
tt[5] = v.normal.z;
if ( fwrite( tt, sizeof(double), 6, fp) != 6 )
{ printf("write error\n");
}
#if 0
fprintf(stdout, "%f, %f, %f, %f, %f, %f\n",
tt[0], tt[1], tt[2], tt[3], tt[4], tt[5]);
#endif
}
fprintf(stderr, "%d triangles, %d vertices\n", gntris, gvertices.count);
fclose(fp);
fclose(ft);
return 0;
}
/**** An Implicit Surface Polygonizer ****/
/* polygonize: polygonize the implicit surface function
* arguments are:
* double function (x, y, z)
* double x, y, z (an arbitrary 3D point)
* the implicit surface function
* return negative for inside, positive for outside
* double size
* width of the partitioning cube
* int bounds
* max. range of cubes (+/- on the three axes) from first cube
* double x, y, z
* coordinates of a starting point on or near the surface
* may be defaulted to 0., 0., 0.
* int triproc (i1, i2, i3, vertices)
* int i1, i2, i3 (indices into the vertex array)
* VERTICES vertices (the vertex array, indexed from 0)
* called for each triangle
* the triangle coordinates are (for i = i1, i2, i3):
* vertices.ptr[i].position.x, .y, and .z
* vertices are ccw when viewed from the out (positive) side
* in a left-handed coordinate system
* vertex normals point outwards
* return 1 to continue, 0 to abort
* int mode
*
没有合适的资源?快使用搜索试试~ 我知道了~
NURBS 曲面曲线例子
共31个文件
dat:14个
mydll:4个
readme:3个
5星 · 超过95%的资源 需积分: 15 108 下载量 161 浏览量
2009-05-25
17:57:17
上传
评论 1
收藏 675KB ZIP 举报
温馨提示
基于NURBS 的曲面曲线。BSPLINE 曲面曲线。 KNOT 插入算法。曲面细分算法。曲线基函数调整。
资源推荐
资源详情
资源评论
收起资源包目录
DMWin.zip (31个子文件)
DesignMentor
Gdi32.mydll 162KB
StartImplicit.bat 38B
implsurf
MAKEFILE.WIN 280B
ImplScript.bat 366B
polyparam.h 549B
implicit.c 23KB
README 397B
myfunc.c 2KB
Glut32.mydll 151KB
surface.exe 236KB
Opengl32.mydll 683KB
LICENSE 2KB
curve.rc 1KB
Glu32.mydll 127KB
README 2KB
curve.exe 132KB
res
rule2.dat 897B
subdiv2.dat 3KB
rule1.dat 500B
revol1.dat 2KB
swept2.dat 2KB
subdiv1.dat 4KB
revol2.dat 4KB
swung1.dat 1KB
sphere.dat 2KB
cyclide.dat 1KB
torus.dat 2KB
3surf.dat 2KB
README 2KB
swept1.dat 2KB
swung2.dat 2KB
共 31 条
- 1
weiskic
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页