|
|
发表于 2014-11-26 07:50:53
|
显示全部楼层
tag_t newPartTag = NULL_TAG;* |+ p' V5 @ T( i9 `7 w$ t* W
tag_t cylTag = NULL_TAG;
7 P6 k$ f) O3 f! T1 e tag_t bodyTag = NULL_TAG;
' {. C# k% x5 M* N; V double cylOrigin[3] = {20, 30, 40};+ I7 w; X5 O! x
char cylDiam[256] = "50";
a2 K, ]- G1 j; a: @! E double cylDirection[3] = {0, 0 ,1};2 i( }4 Z8 ] _% p s% C+ b: n
double height = 60;
J. B( ]% H% B# I. t; _ 6 i4 h* Z2 D; A+ Y8 o
- q' X$ u: N$ Z6 r( C3 s% I3 J char cylHeight[256];
( m4 k1 d, O% F8 |' O sprintf_s(cylHeight, sizeof(cylHeight), "%f", height); N1 ?& u( Y/ U' a
//创建part
9 q& E7 r* o7 m/ t- ~ UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));
, V7 N& q& }% H //创建圆柱9 R f1 s9 x' G1 k
UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));
& ~) N3 W6 \ ?/ I9 x# R" \& ` //获取圆柱特征所在的体: p" Q; _- s* N3 ~6 E( f
UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));0 s% e. Q3 e2 t4 H* c
//获取体上的边/ q5 p d' f& |$ O% v1 o9 i
uf_list_p_t edge_list ;
0 z3 ~1 [5 F6 E# R9 d# N2 | UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));' z7 S5 N+ N+ r* W& ~: Y3 J7 r
//得到边的数量% y4 D1 i! W; N
int edgeCount = 0;
8 Q) b2 M/ X6 f f UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
I* F3 r$ c0 V //打印边的数量
( d$ x! v) d, S2 ?4 M0 U- H char cCount[256];
- u$ b# _+ I2 h$ u, u) u3 n sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d", edgeCount);
$ a, n/ a: L5 O s* e8 V" u* `, P uc1601(cCount, 1);
7 E$ _3 f* @! E/ T! O5 g, R
. F6 \ d8 Q( D ] int error;" v4 J5 `6 ]. s6 f3 B
double (*point_coords)[3];* p- i# w! Q' [; c! U( A
point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );: ]& i# V/ m J+ N' ^
//获取圆柱的上两条边的圆心
5 a" i9 A4 P# F% p int i = 0;- y$ M" _5 V# P; {; Z
tag_t curveOriginTag = NULL_TAG;
! ?3 s# m8 g K for (i; i < edgeCount; i++)! N( y- j+ Z3 `* Y2 h% O
{
( ~( [4 [8 E& A% v$ w UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));6 z/ N# t1 q/ w" ?
UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));
! E; s8 B& I+ ^2 A) N4 U, g }0 v/ j+ _( Z8 s4 h! f! P7 t% _
//将圆心存放到直线起始点的链表中
8 L( A, g& g( { V( ] UF_CURVE_line_p_t line_coords;3 @) i& @1 H- B s# a5 S3 Y
line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );# [$ q: F# Y) L5 e% W1 g( t# E. x
line_coords->start_point[0] = point_coords[0][0];
3 W& T) E5 c$ ?" K; ^ line_coords->start_point[1] = point_coords[0][1];
) r1 U v7 K/ A line_coords->start_point[2] = point_coords[0][2];* J. M# _ B7 N8 \% H
line_coords->end_point[0] = point_coords[1][0];
! W/ i1 G$ F- D& q3 A4 `) G line_coords->end_point[1] = point_coords[1][1];3 a: A x8 ~5 G* X v
line_coords->end_point[2] = point_coords[1][2];3 Q6 r4 H3 J9 l+ M3 T
2 ~. U5 ` |- N+ g
tag_t lineTag = NULL_TAG;
. V* [! g' N$ [6 ^0 b( [9 U$ k6 ^ % ^; ^) q9 x& @; F" b
//创建直线5 `& H* r. w( |9 W9 c* G
UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));
- @2 n) {+ y2 [8 k! j2 F' p- P( A5 l
//打印直线的端点
, f ~' S2 u. w% ^6 o* \ char msg[256];
. @4 K* r# I# s7 y/ L. @ sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",& Y% |9 a1 n' F" |
line_coords->start_point[0],% L0 j( u. f$ v, F1 `( {
line_coords->start_point[1],
, t( i* y, d) Y% o2 L5 N2 d" F# X line_coords->start_point[2],6 x. q: j6 X5 r4 c) d! \
line_coords->end_point[0],
3 M" U( O' _3 i* l' D6 M line_coords->end_point[1],+ H2 M2 ~" Q o# u: V$ n j/ O
line_coords->end_point[2]);0 A2 B. F v* ?+ e; ^- d: W# G
UF_CALL(UF_UI_open_listing_window());
7 \! _' M2 N# h w UF_CALL(UF_UI_write_listing_window(msg));
' y: o0 y: |8 ^& n //UF_CALL(UF_UI_close_listing_window());
) f, J9 D* ]1 H$ n6 l" D: g ]$ r
- G5 h0 B3 U; ~* E2 v, W% m+ | //释放动态内存
8 n' z! Q* \: ~+ \+ Z UF_MODL_delete_list(&edge_list);
, m4 O0 S% p) S3 C/ k UF_free(point_coords);; S# T! k5 \5 g
UF_free(line_coords);
: y' I! J$ z* H& I$ H
3 S3 U6 k+ l) [ UF_PART_save();
0 g% {) |3 \0 p4 \. W8 I UF_PART_close_all(); |
评分
-
查看全部评分
|