|
#include <stdio.h> & r8 |0 X6 _ } |( E
#include <uf.h>; [1 ^ N( x! `9 x1 M/ |
#include <uf_defs.h>* \$ I8 Y# y5 w! j) X
#include <uf_exit.h>" H8 N7 C3 J8 ]$ l3 B. A- R; @! ^, Y
#include <uf_ui.h>9 L+ f0 W/ S! x) C2 } h# k
#include <uf_styler.h>8 [& C3 A* r3 W) I- T
#include <uf_mb.h>
: S" d# [# Y! ]* A) p9 P2 Y/ i/ V#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>
+ ^ O o3 N! v/ r- n2 {' X" y3 P! n T" a
#include <stdlib.h>//后加5 w4 l8 M1 W7 h" k" n* o; R
#include <uf_part.h>
/ L [6 v7 D- i+ L) T#include <uf_defs.h>- g) u& @9 [+ J8 C+ a2 o( I
#include <uf_modl.h>: R+ a5 c# A% f9 u; z( I
, `, k. X$ O. y9 U5 e2 q! E#define UF_CALL3 Q4 q$ T' m* M+ T5 U$ J+ y
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
: Q; W; T4 j0 ]7 |static UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] = y+ K8 g8 O& n# [0 `; y0 A
{$ v& S, t& }, j" {5 F9 }2 E8 w
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},3 I/ H2 r2 {% C
{UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},
- X. y2 l) B; ^$ n {UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},, {' ]! \ b$ [; ^; L, W8 b" P# c+ f
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},; b$ \" ]- Y9 f* Z: h% r
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }
W2 S1 v- c8 J; e( r/ w};
. C$ c( q7 r3 K; T% e& y: |: B% O: K7 L5 Y8 M6 {' u' J& G
static UF_MB_styler_actions_t actions[] = {+ V, ?$ ?# \1 M# `& G$ s8 Q G( N
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },0 L2 H0 `2 K6 [( v1 u
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
K6 O% e; S; t U};' q% |& S# c' R2 V" `
$ E% R) p/ w& Y% B
static void do_ugopen_api(void); @+ S5 ~( g7 ^6 b( R8 O+ @; d
{
& p8 u% u- |0 S+ T3 P$ D3 c- `9 h( W- X
char *prtnam = "create_bsurf"; 7 D, x, D1 ]* ~. _. \* g7 G
; c( B: j K. T" S. W
/* Points for B-surface */+ P/ L. C1 K+ K1 E/ ~8 N2 L9 W' _9 `
double points[16][3] = { X1, Y1, Z1,+ h" O3 N- G" m% ]2 {
X2, Y2, Z2,+ i' K9 T3 u" U* a8 E
X3, Y3, Z3,
& _( R8 N6 Z9 L/ S' x3 m% X X4, Y4, Z4,
9 M$ n6 F! W7 x- ] X5, Y5, Z5,' A4 Z# A4 _6 {" R
X6, Y6, Z6,
! T( e2 Q( b) K1 ~4 T X7, Y7, Z7,
+ H; n2 H) F& y( n8 m/ O7 J* J X8, Y8, Z8,
0 ?$ D1 |7 F. n# G# e% X X9, Y9, Z9,
1 R& n: a# {4 z) q X10, Y10, Z10,
. |. C0 X9 T/ v$ w: u X11, Y11, Z11,
( e7 P1 O0 V$ ^! X7 a, f2 ` X12, Y12, Z12,$ o: h; ~: F7 q H3 l; A
X13, Y13, Z13,( l1 |' R+ ^) {) k0 Z4 w! A
X14, Y14, Z14,
c5 o2 w! d% V. v, ~1 P1 r X15, Y15, Z15,% S, I. N+ e' |
X16, Y16, Z16 }; ( }# m' w$ V C+ T, n
3 e5 q: g. p6 l% p4 x
int create_mode = 1;, ^. X$ ^, L8 N* F; _4 q1 d1 C
int u_closed_status = 0;2 `; [, _" w0 R& Z& q
int v_closed_status = 0; M& V1 i/ R- b
int u_degree = 3;
. n* s' ]& ?" a" Z- K5 q2 M8 n int v_degree = 3;
8 T4 T2 d- t6 ^# o int num_rows = 4;' Z$ @+ }3 h" u, I# h
int pts_per_row[4] = {4, 4, 4, 4};
- X. A2 D9 ~: B# H" I4 h9 W 7 I# k8 f6 ^! \- C" D9 r5 ?* o
int ii, jj, kk, indx;
$ S' X! }: {9 B4 K, |9 \$ I ) x: S* A2 q. L3 D) U
tag_t part_tag;7 y% ]! F* ~' T2 {4 w$ P; W/ [! }* P8 M- B
tag_t bsurf_obj_id = NULL_TAG;
6 f# R$ S. P4 g6 i0 ^6 {
9 M) Q2 |2 I1 @ UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */! c: ^9 f& A! J2 [9 e
UF_MODL_bsurface_t bsurf;1 ?/ y& v( V" K( Y
5 e) Y: B7 ^3 r; t! T( J4 g7 B, m5 h# [2 d
& Q& |* Y& F' `! _ m/ g7 Q/ w /* Open a new part */% l, N) b1 u) B% g l- _
UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );* X% N& h* ?8 X9 |
$ A: U, ]# ^2 {5 ^6 R8 Z
pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *9 p. O( S; `6 B/ t- Y
sizeof(UF_MODL_bsurf_row_info_t) );
1 t) M* W l4 }: b2 Q9 N& P
: e9 {/ [# I6 @. V& w1 x" B /* allocate and load point and other information for each row of points */# V% f& c/ ]5 A
indx = 0;6 ^! A, @1 x; G. P
for (ii=0; ii<num_rows; ii++)
& ?% G& K v6 H. I {
, d# H: Z9 f' ?* G) N% Z7 |3 } pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */* I' u. q3 {$ T! L& g/ }
pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *5 m* }% U' {- W2 ~
sizeof(double) );
$ T+ T+ s/ B" M- H9 p ' l4 j) w" M: e
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
1 i" d. k1 F; \8 J sizeof(double) );! d- j1 X) M6 f. P! ~ j
" K0 T O) M5 ?* b2 L) L /* load up point and weight info */
: y+ [! r3 z' \( L, J9 u V for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)% `: W% B, t9 k$ F
{: Q, t9 {1 o# L
pts_info_per_row[ii].points[jj] = points[indx][0];
6 Q, t x$ L F7 c. j pts_info_per_row[ii].points[jj+1] = points[indx][1];9 a! M% R& \6 _: _- o( p- c! i( M
pts_info_per_row[ii].points[jj+2] = points[indx][2];
/ ?& E4 \+ q# V6 N pts_info_per_row[ii].weight[kk] = 1.0;4 `* T W7 j7 ?$ C' |1 O# N% `1 p
2 T$ B, v- x- a: S2 v
}
3 B% V9 d# s) v; D }
' U' T; s( I2 r) n
4 D* a& s5 r: p" B0 @6 o0 J+ X /* create B-surface */! q+ j% K/ \% q" t: A
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, & j% D9 R, E* B2 o; H2 F- H
v_closed_status, u_degree, ) l$ R( A: C A, u( N2 P
v_degree, num_rows, pts_info_per_row,4 u* g/ {0 i. ?: }" }, x; O( y
&bsurf_obj_id));
, Y4 l% _8 O3 x; t: I / @4 Q( V' h0 D$ r5 y+ k* w
if ( bsurf_obj_id == NULL_TAG )
+ l8 M6 G. @- ?! Y: } printf("*** ERROR CREATING B-SURFACE ***\n");% [) T" V& {; l& Z% f4 _2 G
9 y! \/ A! c3 |% v+ y( } /* free allocated memory */
+ H1 S) F6 |! z4 u for (ii=0; ii<num_rows; ii++)1 D: T4 T+ y1 c8 |1 B8 Q8 u
{) M1 R* q) g, x' u0 _9 ~9 g
free(pts_info_per_row[ii].points);
: Z, q+ N' Q% f. b' E, S free(pts_info_per_row[ii].weight);( b6 Q1 \- e3 S' X2 ?
}
4 A, c" q7 i, B7 N % O$ l: O$ x4 Z9 ~
free(pts_info_per_row);
) ?4 t5 u3 e/ t9 Z" u1 ^: @. I
" `$ I; K6 @: }6 ^3 X: T( ^9 d 6 n. U1 V6 ^ S8 k1 L H
/* ask the B-surface information */
) A% h! e+ w8 S0 C9 N' }8 {! l* {8 r UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));
6 T% Y7 g$ |* }/ V( y# f( S, _8 {$ |# N
" c4 U Q# I' J) e& H /* validate the surface */
9 S: c$ p- e* P5 [. X* C if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )
3 u; E q4 c4 E. T! b$ J printf("*** ERROR ASKING B-SURFACE ***\n");! p" I6 C& `6 X: o( v: T K; k$ M% k
7 G, H4 W( q3 x2 a: X( h
UF_CALL(UF_MODL_free_bsurf_data(&bsurf));
% W" R" ~) }; V4 r9 T: F, h& R W
/ Q/ |3 }! b3 ?: |0 E3 o; p' z# e8 j4 F9 l2 X! {, j6 B! o. D
} ; m, n8 D8 j3 Z/ F& x! F/ J
extern DllExport void ufsta (char *param, int *retcode, int rlen)
$ a5 M/ i& w" Y% m e{
3 c' R) w9 ~4 t" D/ u int error_code;6 H# ]$ p% L. Y' G/ [. K& A
, ?! `0 y+ o! N if ( (UF_initialize()) != 0) / x. a. P" j1 b( z$ ]6 C' z" S
do_UGopen_api(); ( }. K: i! G" @7 \* C
return;
) ]8 @- X$ f% S8 T$ @9 v" ` ' E C; C4 c" l6 m9 |
if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )
9 m9 v% l" i/ _; [8 A5 p" | {
* ?! z+ d1 n+ m char fail_message[133];
* O c$ Q3 f5 k4 Z ; b: n" |* K0 N! x$ K2 M; N
UF_get_fail_message(error_code, fail_message);
, g/ s: y# i( b ~! R/ `8 A) v printf ( "%s\n", fail_message );
$ [9 J- M7 m6 w$ A, g; w }
& c s% B6 t( a9 \
& t, W' W2 J9 O. u1 C UF_terminate(); + t. G. v- C- A/ S% e8 I$ q; Z
return;) `. L8 ~/ I/ E o8 Q
} n s' z: E0 b$ ?9 z5 ^
extern int LaunchBsurfaceDialog ( int *response )1 _; y* G& y6 Y; R
{
7 D+ C& D) p8 \7 Q int error_code = 0;# L- `! D' T1 L4 r( [& Q1 g) u
/ {7 D) }8 g* b |
if ( ( error_code = UF_initialize() ) != 0 )
- ^- v* A: H( r& r, U7 N return (0) ;
6 K. P( P/ B, x- G5 _2 S: I6 {' [: K* \. Z4 U. J
if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",
' P$ O9 _( g4 Z; {" W- n7 q BSURFACE_cbs, /* Callbacks from dialog */9 T4 s4 k6 \1 K6 U. _! ?
BSURFACE_CB_COUNT, /* number of callbacks*/# b& v' G4 J1 l
NULL, /* This is your client data */0 f# P X+ p, U. R
response ) ) != 0 )
: S, c7 c) B. M O. m; } {4 w) ^, [9 T( S9 ]/ I
char fail_message[133];
# z* T) b# ]$ a% s2 J$ y& S9 U( u' u- ]: M! e+ v! u
/* Get the user function fail message based on the fail code.*/
8 V$ c3 j9 Y- U5 { UF_get_fail_message(error_code, fail_message);0 h1 H7 j; v/ v/ C- {: b _& ]
UF_UI_set_status (fail_message);% n$ u: l( c* N7 e' Y9 r
printf ( "%s\n", fail_message ); 7 u: V1 O7 y6 o' [: @
}9 k/ T% k3 A1 d; a
% T3 Q7 k3 m S }* Z# b. j
3 w) j& p# P5 e UF_terminate();
/ ~# o" w# M" v" P return (error_code);
5 D1 G! u0 q4 k}- r Y+ z: _: t
6 s( ?" N1 U' a! g$ S
extern int ufusr_ask_unload (void)" i5 v. Y$ B8 j
{6 f* s# ?/ H6 N, Q e7 W1 n
/* unload immediately after application exits*/
4 [8 M2 r1 t ^/ d9 ?: } return ( UF_UNLOAD_IMMEDIATELY );$ y5 k4 @# ^' a
}
2 e" m% M: M( y2 G! Oextern void ufusr_cleanup (void)
& w$ A$ o! H+ k& Z+ ]{$ a* h6 N) V: b7 c( R
return;, Q# R Y7 S& O; ~
}8 h* F0 C8 V( ?1 X
#endif |
|