|
#include <stdio.h>
( N* x6 r: s' G2 ]3 R/ N3 V. c#include <uf.h>
0 c4 u2 o' s# {+ C* D) r#include <uf_defs.h>+ `, D) s( ?- m5 t/ U& x
#include <uf_exit.h>
& x c3 j9 g3 p2 |3 J+ a#include <uf_ui.h>( e* g* a4 K" e, g8 e) N
#include <uf_styler.h>9 I" \, E* L: y% E1 B
#include <uf_mb.h> : E& i- r2 i/ r' K" i% B* K
#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>
( ?- s* h; G: R; J3 R+ a: } |' F3 V, C7 O& a+ k3 t( H
#include <stdlib.h>//后加& W6 Q9 Z& B. N% m( B+ o
#include <uf_part.h>; \& G" j, f$ `
#include <uf_defs.h>
7 O6 o: u# i+ e, s#include <uf_modl.h>
4 X4 V' d6 ?* p+ E2 o) f7 l" k) c* n/ G6 A' u# j' Q( ]
#define UF_CALL" P4 T! \- ~3 b+ y, @
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
- e+ {$ S' F% t; c( a( @+ Zstatic UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
4 l0 J: c& m# n! B9 s{
/ A8 @" f$ A. ~* @6 R0 E {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},
+ F" E& d5 `6 u6 q {UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},: a# t; `& t- [' b# `6 L6 ^$ i) S! } }
{UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},
/ C# P0 T+ u( ~8 V. V {UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},
; h \ _4 c& O/ a* O0 G. q/ i {UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }
: O8 r+ J) W" X* Q0 @& p9 A};, }/ Y" ?% {- \
% p; k) x+ a( }9 X( i/ }" B% ^
static UF_MB_styler_actions_t actions[] = {4 U+ \% N; I& A% z n Y9 ~
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },! ^; p6 u3 F; n+ `7 |7 y- O2 y
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
7 z1 `" @8 |- v3 @ V; _) c};$ Y6 P3 [6 e7 |0 G& J9 X
. H$ n _* [8 `static void do_ugopen_api(void)8 d. B2 }" N* @- u. V3 V. x
{
$ x' E' N: f5 \- J
! t M0 l7 k" { char *prtnam = "create_bsurf"; * Y/ B- Y( [- j( w- J
( P: u: ]& Z; V. p$ Q+ Q
/* Points for B-surface */
) N2 b3 y- h( c* w7 Y double points[16][3] = { X1, Y1, Z1,
, z4 y0 {* y% x8 H; _- k X2, Y2, Z2,1 f+ \; N0 k4 C/ w! K, `$ k
X3, Y3, Z3,( i8 r0 P0 e# X7 G! R3 H2 Y# L. B
X4, Y4, Z4,
* m3 Y* G; @5 W2 B) K X5, Y5, Z5,
, i! y: [& U( F' I" U X6, Y6, Z6,
) A' E G' P" B- r" O& g7 `; M X7, Y7, Z7,, [: m% J/ u. b( z$ f6 e
X8, Y8, Z8,
/ C5 v0 E$ L {% N X9, Y9, Z9,1 r% \2 A4 Z' n6 _5 {- M
X10, Y10, Z10,
" {, }8 e$ o1 e* a$ y X11, Y11, Z11,3 Z6 h" R5 W- w6 b9 w
X12, Y12, Z12,* ~- ?7 l3 T. U+ f$ m8 Z
X13, Y13, Z13,
7 q. h/ M: {9 O( h ]5 \' S2 G) b3 u X14, Y14, Z14," n7 W! [7 Q8 E" T0 a3 A( f
X15, Y15, Z15,
, n' v, d5 ]4 ]0 x X16, Y16, Z16 };
( ?( q+ T: v. ]7 G; C7 N: B% m* L' K; C; ^- l# |9 o
int create_mode = 1;* v+ U, I# ~9 \# a
int u_closed_status = 0;6 v$ B/ o9 ?% T* w) }
int v_closed_status = 0;& v5 Y" u3 U6 u4 q
int u_degree = 3;
1 }1 ^8 ?. [* g- o1 k. L% X+ M int v_degree = 3;
6 k# Z/ ?: Y( p+ n2 n int num_rows = 4;9 j% D5 ~$ O, t7 u9 R& M
int pts_per_row[4] = {4, 4, 4, 4};
( [0 g7 C. e6 @- p0 j; Q2 J3 [. E ; s* S$ H" C5 W' S( e0 u
int ii, jj, kk, indx;
4 H* m d0 u; H! {# O6 Y! N7 A $ a9 N* q1 O2 w& H4 o
tag_t part_tag;8 c8 c% `- V3 g) Z4 } }5 [
tag_t bsurf_obj_id = NULL_TAG;5 C( X# P$ Z8 E+ }( n1 N
" O" h U: M- C$ r* z/ `
UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */# }5 a6 N, q# Y7 h# U! U- a5 M
UF_MODL_bsurface_t bsurf;% \) g$ Z( a8 ^0 F# f; I5 O
+ G9 H& W( K8 z9 b* |
& d( v! f# X' \2 _ /* Open a new part */
& C9 O8 `' j- Z* o4 T& t6 d UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );0 ^+ m. {. c6 M; C4 L5 T
& O' _: S. y* ?3 B! O
pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
9 J5 u ^8 r0 ~8 l. e2 @ sizeof(UF_MODL_bsurf_row_info_t) );
9 |: T+ J$ [3 H+ @ F5 v
2 p8 U% ^2 M+ y2 {9 Y5 Y8 v7 O% |. e /* allocate and load point and other information for each row of points */
" \' c2 h- `0 q! U8 X% p indx = 0;
6 q. g9 _- X/ C" A for (ii=0; ii<num_rows; ii++)6 B: E% a% J8 p
{, N7 h* S; H# S9 S' x o
pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
* B5 J% M9 h) T* p8 E q. e pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 ** [1 w3 D4 r. O
sizeof(double) );
* e5 N- Q* `2 Z0 h# w! D0 U
% K9 y0 n7 F$ } pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
. r3 ?) W _, T1 ]5 S: e* l8 p sizeof(double) );; Q- {; k/ o5 N$ {8 H% L
5 Y0 |2 j' l: S& F' H
/* load up point and weight info */
4 B% Z% y5 L$ T0 l$ e; N5 n0 F4 Q for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)
0 m' K$ L5 ]% @3 Z0 v) F4 W% E {
7 i$ y6 s j" y1 J pts_info_per_row[ii].points[jj] = points[indx][0];
, O- O- u! m7 ] |0 ]% ?5 I pts_info_per_row[ii].points[jj+1] = points[indx][1];
) _) [- k8 t: G, X pts_info_per_row[ii].points[jj+2] = points[indx][2];
/ h$ n( m4 D a% t pts_info_per_row[ii].weight[kk] = 1.0;
- X: g0 R+ ?0 \* @! V) E9 z- Z( V
2 D% V8 k1 z& r5 o6 t9 d }
( }' b. R8 J* ], f d }" T3 v$ g1 N/ F0 N9 {' L
6 i! D$ W i0 V5 ^, b /* create B-surface */
! m& ^5 r5 ^. G7 M3 k' t UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status,
# _5 g( k7 A8 [ v_closed_status, u_degree, ) M8 d" W- H/ |, q7 E
v_degree, num_rows, pts_info_per_row,
+ ?& O; Y, [, V, ]0 t9 J% `' W &bsurf_obj_id));
4 n: z0 R* n1 ~& q2 s# g" s
8 `/ n: F) K4 C ?. e7 H, |) L( b if ( bsurf_obj_id == NULL_TAG )3 u2 z) e4 H# o) m f
printf("*** ERROR CREATING B-SURFACE ***\n");6 |2 I6 n) g0 y, u' T
$ H! p. L( U" `5 Y( T /* free allocated memory */
, U% Q. _1 w5 @6 O* s j for (ii=0; ii<num_rows; ii++)8 |: _% i5 m0 S4 z' ]% T
{
1 M1 \$ O1 f3 @ free(pts_info_per_row[ii].points);
1 W3 F6 c/ K& {: h free(pts_info_per_row[ii].weight);7 j/ l% u \; b5 Y% H
}
- h$ \/ a0 d% M2 s7 w) ? y& b0 C5 F5 D. D0 R
free(pts_info_per_row);
2 j" Q! S: W- Z5 j/ t4 Z
8 p1 [. v5 W0 [# |4 i( g m% c0 t, d/ Y a
/* ask the B-surface information */' s4 y( O) I5 `1 A
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));
' T. n1 e" c. c6 g3 Y
6 b% Q2 M, O" A0 \8 E /* validate the surface */
, F4 n. F/ Z$ f+ M7 T if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) ), h5 r, {9 J R; v5 [' f
printf("*** ERROR ASKING B-SURFACE ***\n");, M; N! }5 d% t6 d Q
5 B3 Q0 r' k& c; ?+ ?4 b UF_CALL(UF_MODL_free_bsurf_data(&bsurf));/ h1 \5 k4 N3 R4 w. ^( G) e
5 s$ L9 ?, Q I- @) w
5 a! V5 a5 M8 h' f& }}
7 C0 d1 M2 p3 J U- z( Nextern DllExport void ufsta (char *param, int *retcode, int rlen)
9 f$ k' U7 F4 Z; \ a1 k{
& u2 H; H+ F4 `% p) u0 y2 W1 b+ M int error_code;
5 Z' Y# P/ T5 F
. g& H) L8 M, u" S& A+ e if ( (UF_initialize()) != 0)
$ x. Q' P$ G {/ U; G# r do_UGopen_api();
2 C2 Z" d- C7 F return;
% U }# Y) L- B" l/ u* f8 t
+ f u$ m7 i8 U+ z1 b% Q if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )7 F8 n- i" s% _5 h/ f, ~
{
9 R" h8 s' _; S0 D char fail_message[133];
7 K0 L6 k' f/ M & S' B5 [# V& \' @
UF_get_fail_message(error_code, fail_message);5 b4 {) i, q1 R) ^7 |
printf ( "%s\n", fail_message ); 8 C/ q }7 Z4 W) L+ G* ]+ o1 T
}
1 h1 _7 m( N( `, l$ s* R 8 N- _ G9 }/ f! |* ~8 J6 H0 h
UF_terminate(); ; a- d. Q# v2 ~
return;
7 z; T& u1 |- n, X}
, o7 h0 h, M! q7 }! k/ Pextern int LaunchBsurfaceDialog ( int *response )
& Q6 g* P# V2 \, r0 g5 B* v5 Y1 m{6 l5 l( N9 b2 G# Z; L6 b9 C1 e
int error_code = 0;
7 K5 m8 F3 l; X" D# \" Y
+ n4 G* X+ M q if ( ( error_code = UF_initialize() ) != 0 )
' N" O: k2 [, ?; J% [7 l! j return (0) ;& @; [4 E! k! t$ V/ u% \
8 R$ y; J3 M' J3 T+ N' n) J5 o
if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",/ U2 T2 W& E! P8 s$ Q
BSURFACE_cbs, /* Callbacks from dialog */. i& Z! k% k6 J8 T" a: i
BSURFACE_CB_COUNT, /* number of callbacks*/) R- y2 K2 u& q. q: o2 g: `) ?
NULL, /* This is your client data */& c6 m7 a7 T8 g
response ) ) != 0 )6 W1 K0 w9 n# R! M6 ]9 \ r2 p1 S& y
{
" g; f' @% J2 ~ char fail_message[133];8 W4 Q5 A7 P/ k4 W1 D. B
0 u3 E& U* [- ?" q6 |, t /* Get the user function fail message based on the fail code.*/0 f9 ^5 r; o' V& M7 m7 Q
UF_get_fail_message(error_code, fail_message);; D) W) k& Q: V: M) i
UF_UI_set_status (fail_message);
7 f9 k/ D5 a0 t printf ( "%s\n", fail_message );
3 r1 Q3 c7 u0 j; f( E3 Y. W }
! x+ Y9 e1 a6 L+ [
' C3 k) {# n" \1 y, y: O, h: [2 l8 O/ |( M
UF_terminate(); , ]. j2 b2 q2 E" \; n0 q" [3 ~
return (error_code);9 L% `! y1 G/ U ~
}
Y- A- Y. M4 f. K Z, z0 O4 f+ e+ _& F* _; b! ?- ~
extern int ufusr_ask_unload (void)# M* F( C/ R, X3 ~/ ^: j4 b+ A
{ e' e9 _' W) {9 q. h
/* unload immediately after application exits*/
7 V3 A; Y0 }: b- W! q$ \. N return ( UF_UNLOAD_IMMEDIATELY );7 T& S9 W2 s" F
}
: k* Q7 L. W8 s/ k: rextern void ufusr_cleanup (void)
3 j1 Y! U8 M1 Z& b, I) Y{( Y6 O+ ]& v* e2 P8 A
return;
9 ], A2 @! O* T3 F}* K% {6 F: [- R8 j. w% @
#endif |
|