|
#include <stdio.h>
* X8 Z) W# @: `& y#include <uf.h>
. P8 }2 A# R0 I#include <uf_defs.h>
$ m' l# m6 I- L+ U' d#include <uf_exit.h> e9 x3 }: l9 ?) I Z$ n: y X0 J" }
#include <uf_ui.h>
9 l6 q+ f% c* J4 d+ X#include <uf_styler.h>
0 A: a+ e1 v9 @1 H4 ]#include <uf_mb.h>
+ ]! T1 F. Y: U9 i8 v% x7 l. a& Q1 }#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>1 b9 ~9 p, d A: Z$ l. A
' q% B2 R/ Z5 Q M
#include <stdlib.h>//后加4 e: g! w/ b- s! x. |& i; ^9 L8 A
#include <uf_part.h>
5 Z7 b& b- k' _1 j( _$ W#include <uf_defs.h>, e' \" C4 f1 M# n f
#include <uf_modl.h>
" ^1 }8 Q/ v7 ?2 {' A) J# Y5 T1 W& t" ]3 h
#define UF_CALL* A* m/ ?. ?+ l7 x
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
( x" g+ @* v. X9 l8 r9 A" tstatic UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
4 @/ `1 `0 Q F X9 s' f8 Z1 }$ }' e{
; M" K' X" C) L% l5 @ {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},
) Y k' M' Y {7 b$ o {UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},
4 L2 `3 {' j4 ~, E {UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},5 q+ I, i, u3 Y8 I6 i) `' [
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},1 g0 C, m6 _* P- R, p& O5 }
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }8 V9 M: S/ h7 Y2 G0 k6 A4 m4 _& A
};% o) w+ k% ?: j- N! v
; U! y; S4 K2 ?8 ?! r' A& m: \
static UF_MB_styler_actions_t actions[] = {3 ^, w7 C# P$ v' m% M
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },
% o/ Q" ?3 z% c4 @0 B { NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
/ B6 @4 N" F6 L+ m/ F};
2 c5 ?; U9 s- |* n8 r" w8 k( r& c) h8 U0 _
static void do_ugopen_api(void)3 c, B' j% P+ f
{
L v1 C2 t4 D( }, d3 d7 a0 g5 |" d' A8 L3 s0 r
char *prtnam = "create_bsurf"; 2 o8 C) {+ S2 M$ K3 j& ?/ `$ |
" i% N! n! w1 p" ]: j /* Points for B-surface */" C; ?! |3 {& ^0 N, D
double points[16][3] = { X1, Y1, Z1,
1 G* m `: c5 A4 J; ?+ E X2, Y2, Z2,
( T& _1 F3 S6 ~/ ]& b' Q2 a0 s& J X3, Y3, Z3,
7 F/ V( E+ i% \0 c" [2 u" Y X4, Y4, Z4,+ q; N6 g; a& C0 B2 p- X. Z6 {4 _
X5, Y5, Z5,
6 m- J- A# t5 S, ] w" U" u X6, Y6, Z6,
/ H2 h$ u, g8 n X ?/ t X7, Y7, Z7,
e, l& F; `9 F X8, Y8, Z8,
' l/ l5 p4 ]+ p5 M2 B: i X9, Y9, Z9,
- V/ ^. l6 Y& X( Z X10, Y10, Z10,7 e+ i, o- D9 [% T. M0 V9 x* ]% T
X11, Y11, Z11,
, ~0 Y- p8 \2 X! e) V X12, Y12, Z12,6 b& u8 n% F k: r2 I6 M- A' F
X13, Y13, Z13,$ X: j: s9 Y; }
X14, Y14, Z14,
5 u( F: x o* M) T- I3 U# R6 T X15, Y15, Z15,3 l2 k! q5 _/ X: \
X16, Y16, Z16 };
2 O; t0 M1 u" r4 X# x0 @& I, a) E3 F7 i; @ F0 @
int create_mode = 1;* i$ `4 C% E: b6 |
int u_closed_status = 0;( X c; G- O4 k6 R. E
int v_closed_status = 0;
; }* J; q( ?! { int u_degree = 3;
3 T; a2 L2 w" q int v_degree = 3;
0 x7 M9 B8 b$ Y3 h int num_rows = 4;
) }' i/ D% }' G* s& N6 c0 j Z2 B int pts_per_row[4] = {4, 4, 4, 4};
; G/ A& X' q+ a8 z* @( {
% \( t8 |1 Z! R! M0 A! F int ii, jj, kk, indx;
$ L) s- ~% t9 Z 6 x6 q3 q; p$ o% ?$ F# Y# e
tag_t part_tag;0 j: e" j. ] h
tag_t bsurf_obj_id = NULL_TAG;
+ {( m) H7 X6 w( d8 V/ Y2 u' n+ _7 S4 f D1 A1 G
UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */5 \9 W* j# V5 X
UF_MODL_bsurface_t bsurf;/ N+ ` _% V6 [+ V8 q( g
0 u4 J' Z* [+ v8 \# \
B! b/ P3 J2 O5 ?% d/ } /* Open a new part *// p' W! ?5 g1 M! G
UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
# `) ~: y R5 M3 I+ r$ \: p$ K' I& s
pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
& z4 H- w. P( \0 n$ R/ g5 E0 x0 w. N sizeof(UF_MODL_bsurf_row_info_t) );
4 z' C2 a& A7 U# A0 |2 K - Q) G! S* X: a& l
/* allocate and load point and other information for each row of points */
* r% ~0 C9 ~& Y1 h indx = 0;
) ~* Q; j* \. d for (ii=0; ii<num_rows; ii++)- T* T$ g8 O, [
{
1 E& f) o5 W( \- { pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
' G2 n. n+ K3 _+ m# `9 A pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *( [. r! k; y3 u/ a: f( ]
sizeof(double) );
6 e/ v1 J* ?6 M2 o F
0 O8 z' |, m4 V! C5 k9 x9 Z pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
6 _* k! n+ ^+ ] sizeof(double) );7 w. }6 q- W R l" I8 f; a
6 r6 c, m% n. |) R+ _
/* load up point and weight info */, ~# o9 v5 I% x
for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)! u% A m7 y4 r2 {6 [# U* \& h
{; x7 C _* u+ Z: s5 e( x
pts_info_per_row[ii].points[jj] = points[indx][0];
9 z. K% q i) l& `, l5 N$ d7 [# B pts_info_per_row[ii].points[jj+1] = points[indx][1];
( Z, l, p* w. [4 G, d/ K6 d7 L pts_info_per_row[ii].points[jj+2] = points[indx][2];
4 r9 S$ w, p6 y' T& p+ ^0 R pts_info_per_row[ii].weight[kk] = 1.0;0 [7 p0 ]6 N! V0 |, n7 b! C
8 A3 A# V+ a# V, `/ j' w
}
$ @" ?" S: p2 _, A) R8 H }
9 H( R9 Y) v1 O6 v/ ~ 8 u. S0 I3 E1 p4 D" c- I) H3 G
/* create B-surface */2 x( k9 z* ]1 q. D( h) g, x
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, 4 f' |9 X( @0 X1 |. ~- `
v_closed_status, u_degree, 5 \0 g, ^/ ?: B/ [7 F" J
v_degree, num_rows, pts_info_per_row,
$ T- S) r9 G0 l9 @$ |% F- S6 ^+ _ &bsurf_obj_id));# ^1 H# N; E: Z( v w; u3 F( [
3 W9 d8 e9 J. _0 ~' c; V if ( bsurf_obj_id == NULL_TAG )
. h) K0 {+ r4 P8 Z& R) x: C printf("*** ERROR CREATING B-SURFACE ***\n");
6 j2 b T$ C, i! {9 v* A4 s0 e3 d$ Q3 \9 n0 Z
/* free allocated memory */: }1 b3 s) L( q3 E9 S: s
for (ii=0; ii<num_rows; ii++)$ g# b6 m% N3 r+ ?! b c! [+ M
{
; Y- P$ z3 s) Y3 O- P- p free(pts_info_per_row[ii].points);9 E% c& a( a4 k
free(pts_info_per_row[ii].weight);
! ~! U" q' B$ {: Z0 q }4 E/ Z+ g T3 Q5 W
/ |6 a. }: D- J% ]8 P6 n free(pts_info_per_row);
- r" ?# g* s7 @9 T, B, _
' e7 n b8 r0 x! \( g% t. F( r0 K ! Z$ _" Y, w) v: J+ w& `
/* ask the B-surface information *// E/ e% P; [0 m8 `, ^; K
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));1 w/ c$ u: m! m# ]! |5 M1 J
$ A2 B* `$ I* |# w+ A& ] /* validate the surface */5 U$ m; Q3 U& A& C/ Q5 Q
if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )2 R0 `2 {3 P) A, N
printf("*** ERROR ASKING B-SURFACE ***\n");
( R/ s b2 X5 L* e3 @) D8 b6 A : q" G# o7 ^4 o3 g
UF_CALL(UF_MODL_free_bsurf_data(&bsurf));) e" G8 R$ c6 y# e% n1 v$ e1 W
# U/ g/ d' l- X+ J+ z+ A8 }+ L1 `& z8 B) J6 B- G1 f5 d
} 5 k+ p1 y- y7 [
extern DllExport void ufsta (char *param, int *retcode, int rlen)- z# Y" {0 n3 ~% m- N/ p1 W
{
9 G/ f" }: z; m. u" x0 _ int error_code;
# A+ r% j ~: ]0 h6 @ ) B- l5 Y9 C2 o4 @* I: x( x
if ( (UF_initialize()) != 0) 1 \0 r; a5 ]9 A) D# V" \
do_UGopen_api(); & N2 k5 p& w" w7 F; d! K
return;4 P! g2 Q8 s9 F/ r
$ P8 v) p0 |1 j" G/ O' L if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )
3 o1 C( Q9 W4 D/ u {( V5 [' k" q; U1 b# O
char fail_message[133];
y' N0 b+ X: G/ T# O" w1 x 6 L. R( G' |+ b: y& ~: ?
UF_get_fail_message(error_code, fail_message);0 E. c4 m5 p) q) u" u9 [
printf ( "%s\n", fail_message ); 5 _& M# U& q' u) `$ }* E! q
}
6 q) P, ]9 b$ Z : p7 r: \; b) D! e- o. v( f* J$ F
UF_terminate(); - T/ `3 t+ O& [+ Z1 X$ W
return;9 u6 w0 l: a r/ N8 N% d; q$ D' `
}) Y( I1 h# n9 ]
extern int LaunchBsurfaceDialog ( int *response )
6 K3 g6 I: J* u7 \4 T2 ^9 v: J{2 O: i" y5 e) E' k8 U" E
int error_code = 0;
- F- T! f8 H/ U4 F. a
2 D$ j# k) I" s- Q5 G if ( ( error_code = UF_initialize() ) != 0 ) 1 t& i4 i* E8 o$ \
return (0) ; z1 J/ v1 K: e. Q5 ? G2 X
2 v. E9 {" [0 K, K( m" B if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",( _/ t% M) q7 `! F: R) N- V
BSURFACE_cbs, /* Callbacks from dialog */
+ z2 t5 G) |2 r5 F" Y) I- w/ L" i6 j BSURFACE_CB_COUNT, /* number of callbacks*/
$ a0 Y& w3 E( J u# F NULL, /* This is your client data */: m. @+ S7 O. H- T) ]% t4 h) i
response ) ) != 0 )
+ }% d: f3 w! [6 A2 B {$ f1 t6 p& E! b* ~
char fail_message[133];
2 V# }: w" ^' h, V
( y# r, M% V2 V4 H* d& U+ ` /* Get the user function fail message based on the fail code.*/! a1 l/ D* S! u" m9 a
UF_get_fail_message(error_code, fail_message);9 d+ M2 o. y2 W, p% e6 O
UF_UI_set_status (fail_message);
! s& y6 d. n) Q$ K1 l8 p printf ( "%s\n", fail_message ); . n0 b- {# y1 ?" A/ v3 G* m- f
}- H/ F- S' n/ t! Y- i3 L
$ O! ]' Q6 p0 z: y q5 M5 g7 ]" ^+ k: k0 X& \
UF_terminate();
1 v7 a+ B6 N0 j+ { return (error_code);
. x) X- j9 l/ f* x1 X# S! j( A}
( I1 t: n, H/ F! y5 V
+ J1 |/ b0 W% U! q+ lextern int ufusr_ask_unload (void)$ U% i: H& t. `0 l+ n
{; z, Z) ~8 q3 I. w- K( v( C
/* unload immediately after application exits*/, x; H0 ]: N6 z4 [& c O0 T1 X
return ( UF_UNLOAD_IMMEDIATELY );, J% H/ y! w; s( I( k2 ~+ x
}
& ?* k+ I$ X) \0 s6 ]extern void ufusr_cleanup (void)- S# f8 M/ a) I) a
{( S0 E" Z# v. e" s" `3 a" c" D
return;
3 n1 B, R% I3 v$ w4 R* Q, C}2 F$ O" \( l: X i R) f
#endif |
|