|
#include <stdio.h>
8 V8 _* c3 w# d6 p# W8 u s( ^#include <uf.h>0 b2 |) N) t4 i: _2 }$ Y, c4 E7 J4 V
#include <uf_defs.h>
! w: C4 G) E% c0 u7 p+ ]% e8 _#include <uf_exit.h>
) m6 Y$ u4 ^' T( ]#include <uf_ui.h>5 @ A4 Z! O; V( u- k9 p8 L
#include <uf_styler.h>/ r/ V0 @; i0 t7 B: ^' k! ? D
#include <uf_mb.h>
, N. J+ Z4 q x& `5 i \#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>
. ^. P; j" I4 f7 P
; Q! h: |! ?$ A' v0 t#include <stdlib.h>//后加
5 ?0 z' b: Z* @$ V% J#include <uf_part.h>
1 e" ^" O- N6 S% D# `1 M#include <uf_defs.h>+ B) Y& [; \2 P2 I! [* J. U: X
#include <uf_modl.h>
' X; M5 b; o) T N0 N
7 G& I# Y ^& ~$ k0 @2 M#define UF_CALL
9 a! _" K3 b/ u2 E8 f7 t#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */" s8 q2 J% ]2 X* Q1 j7 F
static UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
3 [6 ]5 J% A0 T{7 e& }( C9 s( h3 {0 S0 i
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},1 `+ b0 j j% B Y% [* G C, Y+ ^
{UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},
2 c B5 M' L4 R3 m/ Q/ w9 s {UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},
( ]3 W1 P6 i" j$ p5 l: w {UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},
( I9 C8 A3 A+ v @9 g9 y1 k {UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }' F( a2 h4 m# d: ^
};
- S+ L/ [& q0 n& `, t; m3 u" r; d! g# [% t
static UF_MB_styler_actions_t actions[] = {
9 r2 }* u. K, ?) |) [! P$ y, |& ^% }' \ { "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },
4 K$ Q& q( S/ b% ~ { NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
& B- H- R" q; c5 R8 X1 |5 g};
# O5 L8 p. z U$ Q
! T4 ^. Y1 `0 e2 r$ {! Rstatic void do_ugopen_api(void)
$ T& G2 {, j5 l' I{
9 {* j- U: R1 ?" Y1 O& w) e$ _
6 [7 ]# ?7 M% v- l4 i char *prtnam = "create_bsurf"; * a% [. E9 v, @- F# G( Y1 `
: j$ E `% h% t8 V" B" A /* Points for B-surface */
e+ E5 q7 C( q' W+ t! L9 ] double points[16][3] = { X1, Y1, Z1,9 r W: f- R+ S
X2, Y2, Z2,
. {+ L+ O, h/ H; n/ x# m- e X3, Y3, Z3,
8 v% {$ Z( @7 E& ^6 ], V X4, Y4, Z4,
* d& [5 Q8 N7 ^- M0 h# F D X5, Y5, Z5,5 M4 b' C9 f: }9 g
X6, Y6, Z6, 2 q; r1 y' M! f) j( j0 L+ Z
X7, Y7, Z7,
$ C s/ @1 f+ j; s5 Z. z X8, Y8, Z8,% }9 A" z/ J9 b
X9, Y9, Z9,' z& F4 M# } b7 T3 v7 n7 r
X10, Y10, Z10,
/ d* F' ?% Y' |- n4 B X11, Y11, Z11,
6 w, A( y4 X% Q2 v7 l* x D' `0 j X12, Y12, Z12,# q/ b1 n' e- h3 a
X13, Y13, Z13,0 h8 R2 G5 F- `% y. ?
X14, Y14, Z14,
1 u- k$ e& O! ~: i6 P X15, Y15, Z15,( J0 n/ c5 |5 d( `
X16, Y16, Z16 };
; l5 i9 X" |0 R. g# L6 m* b/ s1 Q2 X% S% x, g1 Q' z
int create_mode = 1;
2 p3 t- q; @/ w+ A0 v int u_closed_status = 0;- R4 Z8 e' f( ?# ^2 c9 ?! T% c! g
int v_closed_status = 0;
& ~! b7 s% j4 W, x% N int u_degree = 3;
( t" |5 F% \: ~1 @3 w. Q# D int v_degree = 3;0 k& y' ~( `8 r; f
int num_rows = 4;
& p: \* i- \& S5 E' B# p3 ~% P int pts_per_row[4] = {4, 4, 4, 4};
+ O$ C2 l) t" D6 l( V/ P: }3 }; ] 1 x0 p5 e8 V; @- P4 [" A& S1 _
int ii, jj, kk, indx;
& m) F/ j( N+ \ # Z" w$ z% ~* t7 R$ y& j
tag_t part_tag;- m B8 q5 Q8 o+ P$ i4 i6 s
tag_t bsurf_obj_id = NULL_TAG;
0 f2 U# ]) X( Y, x3 I" [! F3 b5 t8 D+ ^: c4 g6 A$ F
UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
0 P9 i5 `6 w& v7 Y4 P" ?5 M( Z9 H UF_MODL_bsurface_t bsurf;1 d1 O, ? x3 n- ^5 d& k( ?
, b) B0 t/ c9 b% Q, W
! c7 N2 H2 L/ p /* Open a new part */
: b; c! [8 C2 x$ H UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
. o" P8 D0 k7 H" a$ h Z( @! }# f4 U: \* O
pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
/ Q( H* H- Q' Z6 q6 t sizeof(UF_MODL_bsurf_row_info_t) );
" \# O( P6 E7 Z 0 @0 A+ ^$ o* K* Q
/* allocate and load point and other information for each row of points */
: I& F) N+ @- g! }9 a) ]( F indx = 0;' `1 v! w3 w- [( {1 a
for (ii=0; ii<num_rows; ii++)
4 ?) u# r. a) M7 y P( C! l3 P! ^ {
' g- s+ j# z6 R% P0 v& J pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
5 m9 X0 j: Q7 N8 c6 ?' H- a8 x3 j pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *" p5 C" N+ V; r% Q
sizeof(double) );, S3 |( ]7 n: Z3 B- j1 {
$ b" m" H) S. N' M7 R) v+ S
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
; F% t+ }; U. P& Z sizeof(double) );+ s. E) ]% }, ~# ^& D r& H# d
2 `& P+ S5 p0 u; X, M$ ~( |% J
/* load up point and weight info */
: m+ f4 q' h9 I7 l( p6 n for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)2 s! P! `# o* o2 |
{, C7 L) U: G4 ^
pts_info_per_row[ii].points[jj] = points[indx][0];
0 \/ @" h( [& N& ^) _ pts_info_per_row[ii].points[jj+1] = points[indx][1];
- q8 U4 o* d% L* u$ n pts_info_per_row[ii].points[jj+2] = points[indx][2];+ a1 k7 M6 G* f1 z
pts_info_per_row[ii].weight[kk] = 1.0;
% O( c2 }9 u- n3 l" O " f; q+ @+ c$ f, W
}9 \; w& j! i; a! P+ ^: Y
}$ ~% Z* ?( I$ ~
0 p5 S7 C3 p- J9 r
/* create B-surface */) i( X. @1 b! T* k# m( I7 Q- w
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, 9 j% G( G0 S' G5 X3 c0 `( {- C
v_closed_status, u_degree, 1 c# m+ I8 z7 ^* L
v_degree, num_rows, pts_info_per_row,
2 j, l" X: B( Z- b' p' n9 T &bsurf_obj_id));
* r- ] T$ @& `0 F" x# y8 W) z ' U0 s5 p6 f0 y, C* Y( V4 u
if ( bsurf_obj_id == NULL_TAG )
0 y/ V7 n# f& K# @9 {* O printf("*** ERROR CREATING B-SURFACE ***\n");
" `& t% I' P z) m" r/ [" H# p* C3 F0 o: Y5 e Q8 R
/* free allocated memory */0 Y8 _2 {+ a; V/ r' K- ~
for (ii=0; ii<num_rows; ii++)5 c# U C) O: y& O
{
& D# w0 J; U- U- u& d free(pts_info_per_row[ii].points);7 c' ^- k6 Y" K: _. E
free(pts_info_per_row[ii].weight);
: K* N9 S( J/ v- Y# Q }: f/ g3 _: B4 r' T5 p& X2 B
+ B' \& E: w" A. j+ H free(pts_info_per_row);
2 Y, [9 l" _- o( y, z
[: a6 D+ K4 m" u% F( T
- G# x0 D9 X. G. s6 R0 Q9 t /* ask the B-surface information */7 } e' y* G' W" p! u( H
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));
1 Q/ ]4 T7 C( b. W/ U5 i
1 R& w; O4 X) G, h& |1 I2 q; ~ /* validate the surface */* d" |' O, U0 B
if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )$ u+ X+ D i3 x. o0 V
printf("*** ERROR ASKING B-SURFACE ***\n");4 P2 J* s/ W) v! Y) n
+ ~- M ]: S8 k- t+ \ UF_CALL(UF_MODL_free_bsurf_data(&bsurf));
4 t- q9 i* I: [& C+ c
+ _: r( b( g z4 D' e+ [- r4 e
/ W4 |5 `: t0 O4 J. L}
% t' l$ j' N6 L+ z5 [+ pextern DllExport void ufsta (char *param, int *retcode, int rlen)
$ o, F+ _& G# O/ q{
+ @8 q8 }" j$ n& a6 u int error_code;1 F5 Y" ?3 u p3 R
9 O7 b5 f! w8 E, I( h% N2 [5 @4 e if ( (UF_initialize()) != 0)
. O* l) k2 H, G+ Z/ Y* c+ E% U% L do_UGopen_api();
. s% R! t% H, d8 a0 A0 Z! k% m return;. H5 @5 m. N" r
8 R) _2 R8 l! `8 {: J( g) ]# D if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )1 `1 i! C$ q/ I
{5 v5 l( Z0 Q- }0 j. Y7 \" G/ E
char fail_message[133];
; z3 A, u7 n, {0 v5 x7 e! h- `! X
2 v- h/ q2 F6 N8 U, f0 x1 r' V b0 G UF_get_fail_message(error_code, fail_message);5 P) ]9 ~" D( i0 V$ J
printf ( "%s\n", fail_message ); 7 n- L4 p g( A7 O" H& m8 m' v
}& h/ z9 R( B( y Y+ P
/ a! ^1 _) Y3 N& x* Y6 Z
UF_terminate(); & }4 g* {# ~. e' ]3 m/ y- m# @
return;7 @* P O/ i/ b D! I
}
8 Q- n, i, X; `# Y0 ^* V# uextern int LaunchBsurfaceDialog ( int *response )
- I$ r# p( D9 L# x% a! K{
* Q! c% t/ A. F0 r. c1 q int error_code = 0;' b1 m! Z7 J2 V2 T; v, j# L1 r% L
0 T- M6 c8 _; B& J if ( ( error_code = UF_initialize() ) != 0 ) ' m( y" F, @& L2 L( {
return (0) ;
% Q" t, m+ o9 R6 ?" S8 A. I% R: E& z) d- Q! G( a" a" P
if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",4 B* Y1 a& v# O
BSURFACE_cbs, /* Callbacks from dialog */
4 n! @, E# ?( K! y. e! B Q+ G BSURFACE_CB_COUNT, /* number of callbacks*/, H8 j R4 m: m4 h+ ~
NULL, /* This is your client data */
1 R* j7 a- C. h. X# Z4 S6 Y response ) ) != 0 )4 x% `" y( z6 j6 g, C) Y' H* u
{: g' p5 e4 | o" X5 c
char fail_message[133];
& y/ r7 w& ^$ D6 X9 s9 z" x; S4 H" g0 c1 f& r
/* Get the user function fail message based on the fail code.*/% ~/ a' \* q& f, J) W; o( G
UF_get_fail_message(error_code, fail_message);
/ k2 c8 _4 n! i0 V, @+ j UF_UI_set_status (fail_message); G" T4 `! u: @
printf ( "%s\n", fail_message );
& |- k" P. ^5 v1 ]" B4 S# W }5 g' j! ^5 n! o- m5 s) F
- V9 C N. u8 h: k
8 i5 S. S. s. g1 t6 [ UF_terminate(); * z5 d9 t/ W; y2 q! ?' \& F( Y
return (error_code);0 [- [5 _- p' p
}
( B* @$ d ]! U& D! |$ D" @
% c, N4 Y/ _# kextern int ufusr_ask_unload (void)9 P' u3 P6 B5 x/ j: i- v
{+ r% `( G. I# i. D2 O% Y8 M* R
/* unload immediately after application exits*/
2 y# K7 f) s+ L; S% S" c. a$ @6 Y% B9 t2 Q return ( UF_UNLOAD_IMMEDIATELY );" [7 |' Z# @* D. i
}
4 J& t$ t" W6 i7 D/ A( L |. }extern void ufusr_cleanup (void)0 i# Q+ c1 S4 a3 I# z7 E, J: S5 X( Z: g8 K
{
; G7 n- H! c @" D3 e+ p return;
; Z; \; F3 W7 p! S}* k) N$ F% o/ h5 X
#endif |
|