|
|
发表于 2014-11-26 07:50:53
|
显示全部楼层
tag_t newPartTag = NULL_TAG;6 p* F7 q, w: D) n7 g" c
tag_t cylTag = NULL_TAG;
# U6 T: G" n/ [ b. a5 h0 A tag_t bodyTag = NULL_TAG;* r6 ]( R) b- ^2 G; g' j0 }8 F
double cylOrigin[3] = {20, 30, 40};" ?, Z3 Q$ K5 E3 R, ~ x; e
char cylDiam[256] = "50";* f/ O' p; A* Z5 W8 [
double cylDirection[3] = {0, 0 ,1};
2 `4 Z9 n, R" T: t* f3 H double height = 60;# \/ Y, u( ^, d! _, u8 V0 X
3 H* }* U# |. S4 A6 I9 f! t; r0 `3 w+ A* `5 i$ ] }; q
char cylHeight[256];+ w# M: ^9 q8 ]/ ~/ T/ N6 H
sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);: c! J* f2 Z: `
//创建part/ y9 n+ |2 |( s' V T
UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));& k# ~9 P3 h+ M2 E
//创建圆柱
8 _3 B2 K8 q; G8 @7 D+ o% q' G UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));; V3 o0 @. H, F1 B2 y0 g
//获取圆柱特征所在的体; a/ \# J! u% a2 h( W* y
UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));5 J0 u3 S# I5 Z q7 h0 z4 D
//获取体上的边
2 x/ m! S3 f: m' r uf_list_p_t edge_list ;
) \6 c3 M" O: d G! K9 L4 h- Y UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));
8 s7 f4 i' b) A //得到边的数量' U+ B/ _, n# n. o' F
int edgeCount = 0;
3 m9 ?. G+ r7 r% I' r UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
" z9 t0 b4 B- N0 w6 O //打印边的数量: z* S5 O) C% U3 H) ?1 {* f
char cCount[256];) F' i! X# s& B! b5 U( d. I! m
sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d", edgeCount);1 O4 U7 r7 _5 x4 v. G4 J) b
uc1601(cCount, 1);2 q; j2 y; g5 R8 N
: I1 s5 p: I1 {2 L8 X) I
int error;
6 X7 {+ A5 A1 d double (*point_coords)[3];
0 X0 I8 a! |; P" a/ m- H2 W5 r& T point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );( X# r1 ^5 u- A
//获取圆柱的上两条边的圆心
5 K3 @# w% x* q) J! y int i = 0;
1 R- {! D" V) S! {" P tag_t curveOriginTag = NULL_TAG;2 g" V, s7 i. Q5 Z
for (i; i < edgeCount; i++)5 Z* S6 B& E3 ^8 R
{9 O* a' A" M# g/ `6 }0 D# z0 h
UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));
; e( X# f6 @1 q: \: { UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));
0 }4 z+ ]4 u3 E8 h }
6 E) _( U) d) X, v$ [7 u% U1 | //将圆心存放到直线起始点的链表中
( i: o8 \9 k$ ]8 [( \; `! K UF_CURVE_line_p_t line_coords;- S2 D; @: ]( D2 c5 l* w1 v
line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );& p/ `: a' z( v+ ~+ J& g
line_coords->start_point[0] = point_coords[0][0];- J- t( |2 R; _) ^- U$ c" g( w8 K/ B
line_coords->start_point[1] = point_coords[0][1];5 Y/ x1 I, c' K. l6 A% R
line_coords->start_point[2] = point_coords[0][2];/ r/ g5 e" b+ }
line_coords->end_point[0] = point_coords[1][0];7 j- m* ]# e. f- `% C, f' Z
line_coords->end_point[1] = point_coords[1][1];
- _+ V; _) f9 E6 w line_coords->end_point[2] = point_coords[1][2];
/ \7 J' i3 S: N4 t- X: E5 _" x9 ?
# t. D9 `- Y' J3 R. ]3 ]- {7 Y' N" I tag_t lineTag = NULL_TAG;/ ?. c9 A# A, A. x
7 O; h% T4 f5 P; f0 i3 V7 ` //创建直线
4 F- _5 J l8 \7 z n) Y6 M- m UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));
5 b/ Q. _/ E( z% R
" \2 d- ?! ?2 i$ R //打印直线的端点. x4 Z5 d: H) S
char msg[256];# p; E! t# A( U6 m: v- p0 t
sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",6 R- \1 P5 o2 s; c
line_coords->start_point[0],
6 \# d' t) |* |( j) b line_coords->start_point[1],
* n* m9 K! V9 F- }# V- e line_coords->start_point[2],
1 P: D+ L! l* M* l F line_coords->end_point[0],- ~7 P* x: C# t- n4 P1 l! [8 G
line_coords->end_point[1],
Q3 l% v+ L$ y9 j. \4 V line_coords->end_point[2]);
k* {+ e3 G& V: i& f) i! O UF_CALL(UF_UI_open_listing_window());
& J5 q+ I9 E. c9 p UF_CALL(UF_UI_write_listing_window(msg));9 H6 u2 W0 k; k' v1 ]% @' h
//UF_CALL(UF_UI_close_listing_window());$ X+ _% r, a( p) e# b
- R. W- {1 i' [" z( a( f
//释放动态内存$ H3 U2 J8 V1 s) _
UF_MODL_delete_list(&edge_list);4 Z* N! E! w0 ^
UF_free(point_coords);! _4 ^! n5 I8 X |5 x; Z. |
UF_free(line_coords);
3 ]; M& b) \$ a$ q) }$ E1 i7 K" n j3 A7 p5 N( j2 W% h
UF_PART_save();* Z* m! E( |2 a, e) M
UF_PART_close_all(); |
评分
-
查看全部评分
|