|
leaf
发表于 2014-11-26 07:50:53
tag_t newPartTag = NULL_TAG;
; n5 \* I0 j1 N( j, v: z tag_t cylTag = NULL_TAG;. J5 G3 G3 S3 o. d+ r9 A5 P, M8 [7 w
tag_t bodyTag = NULL_TAG;% e3 j2 x% p R$ p+ Q0 B2 l
double cylOrigin[3] = {20, 30, 40};9 B7 G4 ?7 Q/ } N
char cylDiam[256] = "50";
# K0 @& G2 _- q. j6 I M8 A4 r% [ double cylDirection[3] = {0, 0 ,1};
& F. x! O# x- b, e- o& a( B# Z" J double height = 60;
* P0 w4 O% _2 ^" h$ T
1 l# i: ?8 |9 n& s$ W, I( p$ G* b; I, \* M: _
char cylHeight[256];5 ^$ a9 \& o5 o- l# _- `$ C
sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);
0 a$ {+ {8 Q! H* f* u2 N //创建part
6 D/ _" ~# w% u4 A' Y UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));
( _$ f* F' ~& Q) v6 m* W2 P //创建圆柱
; {' f; h3 r. ^. K! Y UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));
3 n/ g/ g/ ?1 k- \ //获取圆柱特征所在的体
8 X9 J+ v. K: V! m2 ^+ `* T$ K9 t UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));
# [& m ~3 m9 s" S- z& O8 _) ~0 [ //获取体上的边% C0 _( k+ \5 p- e. U% _+ n
uf_list_p_t edge_list ;: p3 Z1 z2 M0 h, _. l0 P; c
UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));+ v' p% j: Z( x
//得到边的数量+ C& u7 I. T) d5 j1 ?/ z
int edgeCount = 0;
, F( I4 v, I& u5 x UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
( |- J( E; W+ L. w* ^* @8 I //打印边的数量# T4 |. X: H, N: T" e2 s
char cCount[256];
, m- O. y" C: p3 {; Y sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d", edgeCount);1 f8 T6 w+ r2 y' [/ ~. B+ `0 h4 y A
uc1601(cCount, 1);) z& W u/ g" ^4 g7 @5 J* t A
1 B; C7 @0 i3 A5 F3 h. {8 G W% K! [
int error;
% q$ A& x3 t6 F- R double (*point_coords)[3];. k& |3 [# Y' e& M3 ?1 f
point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );
/ E& H7 }2 w7 n" M) j; H //获取圆柱的上两条边的圆心1 N% l3 F( h: y# `
int i = 0;
; p' Z. `( ?' ~ tag_t curveOriginTag = NULL_TAG;/ y* \$ l, \# H* r
for (i; i < edgeCount; i++)$ L: U" s, D0 ^5 w5 [3 \) Y
{
# [% j/ c+ y) E UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));
9 U( f$ x' `. G1 R UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));" B! c- g- \' h1 E% K' z
}
P1 p. @0 p5 n //将圆心存放到直线起始点的链表中
: G9 ~# Y) k" h UF_CURVE_line_p_t line_coords;
/ C$ t) P: V% O( g9 q6 N line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );7 m' d0 I% ]" Q. z% e5 A" k4 @
line_coords->start_point[0] = point_coords[0][0];- l- s/ y8 Y& p: z( Y7 m/ z
line_coords->start_point[1] = point_coords[0][1];/ L" Q( H2 i }: R7 E- k# N! c4 c7 W4 p
line_coords->start_point[2] = point_coords[0][2];
7 X8 T9 S9 @# R9 x3 v line_coords->end_point[0] = point_coords[1][0];
?- l& D' V3 r' P' ? line_coords->end_point[1] = point_coords[1][1];0 r( M l9 e. W( ]0 K" k
line_coords->end_point[2] = point_coords[1][2];
8 I8 ]0 K9 L: D2 G' \, Q! G) D, d+ I; i0 k. C+ E5 s
tag_t lineTag = NULL_TAG;
: c6 }. H" B+ Y& ^
9 U" U' `% N7 q! d //创建直线, _4 d( b0 [$ r! p, D
UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));
N* u% v2 ]# o) q- I. G$ z5 b6 L* ~! y* o* L; N
//打印直线的端点
& F6 Q# \* u. v& \" k% s& B" e char msg[256];
# `7 ]6 u6 N: c9 Q% Z+ q sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",
* L' ?5 e9 N8 f& n/ h' x% \/ o line_coords->start_point[0],
4 s( S( g5 N9 ?3 C' J( x- P line_coords->start_point[1],' {* ?7 T/ i8 k& U
line_coords->start_point[2],
# [; @; s. f: D* C5 ^1 i line_coords->end_point[0],* e9 P, i8 z6 r! ^
line_coords->end_point[1],0 k5 F. Z- G' B0 F" q, d' _
line_coords->end_point[2]);
' V6 M$ m- L# P S9 H* S UF_CALL(UF_UI_open_listing_window());
- _2 X% w1 _; i) }) ? UF_CALL(UF_UI_write_listing_window(msg));* U3 q4 L; I, P y9 C: @! i: X& |
//UF_CALL(UF_UI_close_listing_window());
], R& Q* Y# w' `% Q7 I0 U$ d6 z8 Z0 z2 m1 I/ A
//释放动态内存
: d( h. v, v4 U5 H UF_MODL_delete_list(&edge_list);
5 f: D/ @6 M7 ^ I UF_free(point_coords);
3 v, }" h5 O* B7 @. k$ N UF_free(line_coords);- D- J! V( w5 Y
) k0 T# o- _+ |( w
UF_PART_save();" y5 o5 E( |8 i" ^6 M& l
UF_PART_close_all(); |
评分
-
查看全部评分
|