|
#include <stdio.h> - j8 G+ y, H0 T
#include <uf.h>$ x, g# b: K. {" W" ?/ n
#include <uf_defs.h>; o" W; y% L+ C; }
#include <uf_exit.h>) T# j2 e; W! a& x7 y7 e! T
#include <uf_ui.h>: U- C; j4 A! t4 c9 u
#include <uf_styler.h>4 q* d- u2 @: l5 G' k* L6 v) ~
#include <uf_mb.h>
( r8 [5 m4 i6 E$ T#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>
0 b& l$ m( ?% b) o1 a$ n+ i
# G" ?. H1 i) r: y& b+ |4 Z1 P#include <stdlib.h>//后加; ]$ w" l: c! {% f! L
#include <uf_part.h>7 Q0 ~0 r- ^, k
#include <uf_defs.h>
9 f; A: q2 R6 W; K" k0 X#include <uf_modl.h>5 e4 h5 b/ a% C- h- ]2 M" F
1 Z( A( [8 }* w; `#define UF_CALL$ y: s, ~8 p3 {/ M
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
( j Y' ?0 \& a6 Z1 W/ n: Mstatic UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] = + a* n! \" Y$ U( B/ } Z
{
' u5 {) l( c1 }& K/ I/ k: I7 V {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},
# V% s9 z. p7 I {UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},* D1 @9 j2 P! ~2 j: [+ l. T7 j$ A+ q8 `
{UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},8 k" p, X7 |$ \ z7 I' `
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},
; Z# ]9 |$ M7 y) q {UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }
- ?* ~) Y7 D( p2 p* S; P};
# |. C$ V# _0 i3 T$ C
0 z( Z* j* R) ?! B$ O5 [; }static UF_MB_styler_actions_t actions[] = {( B/ b7 ?! t7 G- N# Q
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },# u3 \% `6 @( L1 J
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
+ w3 k: j6 \; p$ R};
; v) L b/ Y* N' C
2 a! _: Z$ I( `9 c1 nstatic void do_ugopen_api(void)
9 r% F' {- f1 |1 M{
4 V: B7 u- u( K' B/ r; X8 M! n/ N2 \! k3 O* L8 b
char *prtnam = "create_bsurf";
' F2 I2 P7 E- g" R3 w
K0 t% F" c$ l0 d0 v( M /* Points for B-surface */
7 z9 z. L J0 x8 ~ F double points[16][3] = { X1, Y1, Z1,
! i9 S- N, y# [% i: ^+ I X2, Y2, Z2,
9 x8 }5 \4 s+ |" D2 |' ?( w X3, Y3, Z3,' L$ [* Q; s d' b% H2 F& l
X4, Y4, Z4,, p$ c, }9 w8 h* ^
X5, Y5, Z5,
4 E' p3 h9 P/ S. @4 U6 M7 V0 s- l X6, Y6, Z6,
# v1 z/ }& }/ r X7, Y7, Z7,$ B; }+ Y X9 H& ?' D' P
X8, Y8, Z8,
7 J+ `! O1 u9 F L4 w- [1 {" j X9, Y9, Z9,
8 v p$ @$ e% c: J5 r X10, Y10, Z10,3 p1 { k" _; M9 t$ |
X11, Y11, Z11,9 j: c! d' C) Y! @
X12, Y12, Z12,1 _6 {+ t4 L; v# H6 ?2 j+ m
X13, Y13, Z13,
3 n k7 R9 {) u0 c3 m& T1 |/ A+ { X14, Y14, Z14,
& l/ @4 g" }- g% i0 { X15, Y15, Z15,
O2 d$ [8 |5 S1 _, m+ {8 O X16, Y16, Z16 }; # J" e* u. }# o
4 B) j3 j8 E( B9 e O5 N# l
int create_mode = 1;9 A2 x. D, s/ G4 ^
int u_closed_status = 0;
1 X+ A& j* x" _ int v_closed_status = 0;
* V0 f* ^; ]' V) X7 L: O int u_degree = 3;
8 a2 ] c/ C; I int v_degree = 3;% H$ _, W+ O( f
int num_rows = 4;1 Z6 X2 [2 C3 S# e8 y! Z* x, U- o; q
int pts_per_row[4] = {4, 4, 4, 4};
* m- ?) L* L/ W6 w2 ~ 0 n- w3 Y) j& Q/ G3 @2 i
int ii, jj, kk, indx;0 i6 Z- H! S- ^ Q+ g2 R# j
/ q2 [5 U5 b' ? tag_t part_tag;
' ], o$ O0 ^ _+ q tag_t bsurf_obj_id = NULL_TAG; j3 H: M0 G) z2 U1 A ]
! A# \# v; c6 h! ^2 f9 j: G UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
5 f: d% {/ d1 X UF_MODL_bsurface_t bsurf;
5 o2 P# L: H) b5 k3 O3 x) j$ K0 [
$ n2 T1 a' @( t* u o1 Z; ^' @9 [6 w9 A3 q" ^
/* Open a new part */& L7 h8 { M2 N# n' k
UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );. ]4 ?/ `$ \, S6 r& t
5 N9 N# e% `' ?- V5 v { V pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
4 z. r3 i t# ?7 n: m sizeof(UF_MODL_bsurf_row_info_t) );! g3 l) ` N$ Z. k6 n( O$ v6 @
5 h5 A- C+ w1 ~0 I3 j, P9 H /* allocate and load point and other information for each row of points */9 j) o( e( y' z% R/ r3 D
indx = 0;6 h, V4 W6 p4 a
for (ii=0; ii<num_rows; ii++)/ J$ \' P( @" l' W% ]
{
; W% E+ r! Q. K2 S4 N4 [5 H7 S pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
! I! \ j6 ~5 v" x pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *3 {4 m% a( ?5 n5 ~) O
sizeof(double) );) G, ?' I' O5 ~
1 X5 x: F: v3 ~% l) y% V- b6 ^
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] * 1 |$ J, d3 U# f2 l; H; b+ G8 b
sizeof(double) );- p6 r0 [: |& c
' ?; R$ ]0 f8 \. ^* A/ E" [
/* load up point and weight info */
6 R5 K7 v, r* L/ k+ v' D for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++) u5 `, y; ?* F% n
{! r. N6 h- z7 m# P& K4 _, T/ [
pts_info_per_row[ii].points[jj] = points[indx][0];3 o' ~) g9 a: L. Q9 G! F
pts_info_per_row[ii].points[jj+1] = points[indx][1];
; b/ K* E: q5 r0 k" y2 J8 [ pts_info_per_row[ii].points[jj+2] = points[indx][2];
8 x9 P" F& B9 Q9 R pts_info_per_row[ii].weight[kk] = 1.0;4 P5 v; c1 d- l9 H
+ k) H) h4 d& s) R8 D: z
}! x3 Y7 @& R' h J; ^% D
}+ Z" E. I* i4 J
% h/ N. {- c9 t* ]: C
/* create B-surface */6 |2 p/ v0 J# X! v1 L
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, / C# `" \6 C3 f; |" X; [
v_closed_status, u_degree, + R4 l5 o+ N$ [
v_degree, num_rows, pts_info_per_row,; p% k" F+ a# ^0 B
&bsurf_obj_id));
7 I. }6 ^) K6 X7 C9 B0 x
+ {+ F' I2 u+ |6 E7 d2 l if ( bsurf_obj_id == NULL_TAG )
4 k% F! _+ m# M7 N- K7 F3 u5 x printf("*** ERROR CREATING B-SURFACE ***\n");3 T, e8 |4 s, \) y1 e+ P+ s
' m' @ M X3 E& s" e: S# f /* free allocated memory */# u. S2 ]# e- p3 B$ u9 z5 T
for (ii=0; ii<num_rows; ii++)) p5 d* i1 T4 N& i8 V, Y
{
8 O, R* c! i8 E. @; N% y8 k: d free(pts_info_per_row[ii].points);2 y1 l& Y4 y" F" a
free(pts_info_per_row[ii].weight);
$ i' q" l* B0 Y* C& d8 _ }
" f1 c* C7 I, P u6 ^) I! n " i4 C* ?( B |) l" x
free(pts_info_per_row);7 \# h D# k- v5 {0 I
$ g) b) u" d6 U- W9 C# U
0 {7 P' \8 ]* _) N4 e /* ask the B-surface information */
" [) A- C0 N# N% |. v UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));% b4 r6 p& j. b H
* }, L+ _2 ~2 C" d /* validate the surface */4 F' R& ?; n. L1 |, ~ I; T
if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )
+ P. `: O/ I$ t printf("*** ERROR ASKING B-SURFACE ***\n");2 L9 k8 D, K( \* I3 @
+ A6 H, r# v9 `
UF_CALL(UF_MODL_free_bsurf_data(&bsurf));5 {$ ] `) X5 G P, R) S+ m
) S8 ^ v# r* g9 [" a5 \1 Y
" H+ |1 u; Y* Y} # V$ @' l. h- g ~, g
extern DllExport void ufsta (char *param, int *retcode, int rlen)
7 l! K6 v3 j) H I1 T. c4 q{2 k# [' |3 Z8 f8 u
int error_code;- y; D7 U: r& I. w, Q3 p' v6 Y
/ a2 \" R9 f! R2 C1 j; Q4 Z2 } if ( (UF_initialize()) != 0)
2 G2 r! d" S: ]! V# f" e1 e0 q do_UGopen_api(); 3 O. c7 X ?0 h+ B- K. X
return;. F1 Z0 q# S) k) f
- W, F* V) T/ z7 m- S9 Q
if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )6 Y5 v1 m- n6 R1 [) D
{! p7 V# X6 o# d" C. b
char fail_message[133];
- u( {' d! l+ [/ Y ! Q* I; M! {5 N) f5 Q" g# Y
UF_get_fail_message(error_code, fail_message);# D+ f/ M* e' H1 Y
printf ( "%s\n", fail_message ); 0 X, T5 `6 {, ^1 B0 J9 M* y
}
. |% u. j( N. P/ ]0 h) ] ) [2 |$ l' D$ O0 u3 r0 L
UF_terminate();
# w- S5 i' ^$ f4 F; J @ return;7 l6 u) U! `7 ]6 i# [- ?& x
}: {' s3 E+ ^' l; W
extern int LaunchBsurfaceDialog ( int *response )0 q# E, x* a! ^6 w3 q1 m' S8 _! ~
{
; G6 V! ~3 T8 @# j* ~5 ^ Q int error_code = 0;
: e& y, E( R3 f8 H
7 n; a2 e S7 @* A+ d! s% k% } if ( ( error_code = UF_initialize() ) != 0 )
) Y3 D9 F- }( U' z% Y5 Y9 s8 ?3 z return (0) ;/ L4 ]2 W. Q5 D0 w2 W
& `) G' `. p2 | ~
if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",/ O; ]0 l( E9 D& z
BSURFACE_cbs, /* Callbacks from dialog */* T3 R5 C: w) {: O- {! b( K
BSURFACE_CB_COUNT, /* number of callbacks*/
8 C8 Y) C7 L' X# W% | NULL, /* This is your client data */( X6 S$ j) S* W5 {5 e
response ) ) != 0 )) X0 D8 c; O8 t& u
{
9 \. W9 t4 Y* a0 B char fail_message[133];' t: O$ w# o6 u+ l
& b; O; Z. B! F4 F
/* Get the user function fail message based on the fail code.*/' B, B* Z( ?0 l# F( ?: B1 I" s$ x
UF_get_fail_message(error_code, fail_message);
|0 r7 U, T G: B( |$ T0 x UF_UI_set_status (fail_message);. A) o M; T4 ~- T$ T
printf ( "%s\n", fail_message ); ' I+ p$ [ a" a2 T' B; F( I# _
}
3 i3 y D( X* B' C0 s* n8 X
5 z: P* r- ]2 ]9 I; i+ d( k: D( `% O* u9 x
UF_terminate(); " c5 d9 ~: I s/ E! K/ H1 b+ p
return (error_code);
; w; v1 a& c3 R7 A2 s2 @2 g/ V}
9 ]; s" e( M! f* S% K8 [- I5 [' }" Z8 l! A% p( B
extern int ufusr_ask_unload (void)
/ E5 W5 K' d4 j1 n7 R{4 ?- ~7 B/ Q+ w1 T, N. W
/* unload immediately after application exits*/" P; o) ^) x3 T$ r
return ( UF_UNLOAD_IMMEDIATELY );2 y' B% c, V7 m2 ~# |
}
: v1 r& r9 P6 ]* Zextern void ufusr_cleanup (void)1 ]3 m* k' L& B
{
* O+ D$ W$ f- p- e. t return;
) n" {9 r1 q4 j' R+ _ H}! p" [$ T) | p9 a- X6 L
#endif |
|