|
#include <stdio.h>
4 I) Y4 ]1 P; z( z4 r5 Q6 |& k8 T#include <uf.h>
6 {: @* `- U( `' R3 ^" h#include <uf_defs.h>
7 s. Z& ]! C d' p1 q4 A#include <uf_exit.h>
( ~# _5 F6 g- q! M, h1 n#include <uf_ui.h>
8 U! v$ w8 {' c* ^#include <uf_styler.h>5 k$ Y% b6 j1 m' }8 H' T; j" e: t
#include <uf_mb.h> % ]6 V& r K& D% Q( f/ X
#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>3 g9 e; B4 Q+ T$ m1 B3 x- N
2 Z& w/ F0 H, I" X#include <stdlib.h>//后加
+ m4 M( Q; `0 ], L#include <uf_part.h>3 T1 S5 F* r$ O- A+ ^: i% Q
#include <uf_defs.h>1 e0 L* f9 G; N4 Q3 S
#include <uf_modl.h>
* ?5 e( D( H/ b& v& \( [
2 O/ i. J/ L9 C/ R#define UF_CALL |$ |8 x3 K2 E8 T) ?
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
4 L! p3 C) Q+ M$ u* q: Hstatic UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
; z2 `% ]" K5 X* J; H. H5 r{
* \ L# q( `7 I8 n1 N6 p6 U {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},0 b: j- N: [6 ]" m$ S! S) J
{UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},
6 Y7 z3 l2 s2 n: R" J" K% g {UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},
9 Q$ E6 A" L4 v- x9 C {UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb}," y$ Z+ F8 e* m) `5 Q
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }! c J6 ~4 l" K* w
};1 o2 Q$ Y9 ^. ]; x
3 }" L6 Z: j$ G2 M9 S) tstatic UF_MB_styler_actions_t actions[] = {
8 W# F2 a5 W: f7 I* s { "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP }," }0 R! @; C& Q: |- v
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
: L; `, w5 u+ L8 D1 E};0 T8 V& E' w' O9 J. A5 u
! }8 Q. s- ]& o" Sstatic void do_ugopen_api(void)
; E! b# C7 V9 T+ _{( I H3 `, |7 ?0 D. o* \5 `
9 u' l2 K8 m" R# L' V3 [9 X2 A
char *prtnam = "create_bsurf"; 7 U1 X6 z% P! M/ L# a
- s+ \+ O$ N9 B2 H, ?& q /* Points for B-surface */8 G+ `2 x4 R7 n7 E
double points[16][3] = { X1, Y1, Z1,
0 Y' i# J. b. o) `) _/ _ X2, Y2, Z2,( c& x8 }. a6 v' Y2 b' p
X3, Y3, Z3,0 N% l# C8 v0 i: L, w
X4, Y4, Z4,% L1 E# F6 ~6 r
X5, Y5, Z5,$ o& f0 R; O! G6 `
X6, Y6, Z6, 5 G' J: h2 c9 J3 E1 N
X7, Y7, Z7,
( R+ E8 {1 M8 ]/ U X8, Y8, Z8,+ T9 M3 C* I( @0 X3 m- a
X9, Y9, Z9,
( V& M" ^ |' ?! Z X10, Y10, Z10,2 y% G: l) |+ G' |
X11, Y11, Z11,
% j; v% Y$ s( w0 [, O d X12, Y12, Z12,& u9 E- G/ H7 F6 I7 e$ I
X13, Y13, Z13,) F% h; ~9 E8 w0 ]
X14, Y14, Z14,
/ g+ x: C8 [" r: R& B X15, Y15, Z15,: ?- ^5 [+ M/ c
X16, Y16, Z16 };
) V5 H2 u/ K/ q) E) ^ Y- z8 b5 W' I N) v2 c
int create_mode = 1;; x$ U( E% j$ Z4 f
int u_closed_status = 0;0 y+ q5 F. h! `, V
int v_closed_status = 0;
4 l4 A8 m) P/ c. N int u_degree = 3;
' M. O8 w' D" H6 s/ _3 i int v_degree = 3;
2 @/ h5 n! b3 E, u" z% d int num_rows = 4;8 ?* P; F3 `- {: E' Q$ k9 _' B$ b
int pts_per_row[4] = {4, 4, 4, 4};
" x5 ?5 a' M1 A $ u6 ]! T' |, Z! v, Q
int ii, jj, kk, indx;
9 }0 H* C* r& u! @4 n x: q. F ! S H% f" Z+ i. M% S
tag_t part_tag;: `1 c! ?: D# K2 |9 R8 K
tag_t bsurf_obj_id = NULL_TAG;% l: S" j1 f5 x
4 a" q/ v; s. Q l/ T2 e UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
* W/ B7 a& K1 C5 J UF_MODL_bsurface_t bsurf;4 K, D9 z$ @- Y: K3 m; x8 ~( L
3 q3 m0 J0 P% `: i1 Y v+ D1 }) c" T) |+ V6 @- Y3 z# Y* s% \
/* Open a new part */
1 ]8 \1 N( z" ~9 Z: |% U UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
" `' H% K3 z9 Y* h1 T Y. n
3 m3 v! i& @' w8 ?) p+ I pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
0 j8 o+ f! c4 W5 H3 C sizeof(UF_MODL_bsurf_row_info_t) );; ~0 H* k# [$ }
& Z+ E* m& r' n0 m6 i" {) h /* allocate and load point and other information for each row of points */8 H; j* ^; f; F# t# t d" X
indx = 0;) s. s1 e* [' U$ U+ O! R
for (ii=0; ii<num_rows; ii++)9 a L+ X& d& d% ?
{
+ v5 C5 b1 k4 G! i6 z/ p pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
7 ~- I3 N( t' j pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *
B4 @7 f9 r- T. U# A sizeof(double) );
% \! l9 {; z+ z/ U
6 R$ H" j7 J7 k% n4 f$ e6 y9 U pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
, k9 J. O6 q3 l( y6 t; Y' [ sizeof(double) );# |. J6 N; N. N% J
5 w2 I# i2 S3 h( B& D1 R: h# ^+ y, k
/* load up point and weight info */
/ ]# X3 {6 U$ w" r6 N# C& i3 Z for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)
4 U# N$ }1 |0 ^" B+ ]5 ` {9 p% |$ W# y" L& g" n
pts_info_per_row[ii].points[jj] = points[indx][0];; e+ t6 _5 C* T. C+ z3 h2 b8 {8 P8 U
pts_info_per_row[ii].points[jj+1] = points[indx][1];, w8 E Z" V; S! L# C4 h
pts_info_per_row[ii].points[jj+2] = points[indx][2];; X9 E! l' E( C' S8 I8 |( V
pts_info_per_row[ii].weight[kk] = 1.0;
" a) v/ t: W, b- S: D0 _/ D5 Y/ Y 6 l( x- x! P$ o2 v# I
}4 f2 I# b" U& s# r
}
. o! z2 z( W7 F1 k! a
( C, S5 c! `/ M: \ /* create B-surface */
6 ]1 Z( q7 w8 M; I UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status,
+ p5 W. K% r# t9 b \ v_closed_status, u_degree, 6 r% v" l6 \; F5 z2 W
v_degree, num_rows, pts_info_per_row,
' l4 |7 d6 b2 O& O* c3 T &bsurf_obj_id));
0 ~& }7 G6 P# \/ h; u6 ~ 0 k' ] J) a9 S8 U
if ( bsurf_obj_id == NULL_TAG )
# _8 R5 ?, _8 Q7 O printf("*** ERROR CREATING B-SURFACE ***\n");
% I+ b3 U2 o; ]$ N+ v# a# m% Z X5 H8 y- _ O
/* free allocated memory */+ V% X8 w5 }% E- P& q
for (ii=0; ii<num_rows; ii++)
0 V* t: `' K. y1 ?9 \ {
4 ~( C' B7 r$ i1 s' D free(pts_info_per_row[ii].points);
9 D& D7 }! H2 Q9 ^: J free(pts_info_per_row[ii].weight);' I$ l% S0 [: u9 A$ x1 h/ Y
}
4 V+ e5 j& d& g* o+ q) ?
1 i1 R) c! ^; u9 y" J$ @$ c) R/ R free(pts_info_per_row);
6 ^5 ]1 ]9 n, B1 a9 h1 G8 S f$ v7 ] 5 w* E( A5 I) w6 H% J6 }% t0 U7 p
, ~% S' }: U8 r$ h
/* ask the B-surface information */8 c; J8 q( |7 R4 [
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));# P8 v6 a3 G% G8 a$ j
$ N8 D" u) l; S3 I, _
/* validate the surface */
* i3 @* \2 u3 V1 l# s/ z if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )) r: f, `( A8 I1 n: I
printf("*** ERROR ASKING B-SURFACE ***\n");9 g4 l6 M1 P( [! f4 E3 I
& G) S% T9 X8 j! _, W+ j
UF_CALL(UF_MODL_free_bsurf_data(&bsurf));, k. ^ ^0 A6 {, |, L& I. S# R
7 S6 \8 X+ t; c; q
. }' W b- }+ W0 e} : z& O5 D, Y! E; _% A* {: j- Q
extern DllExport void ufsta (char *param, int *retcode, int rlen)
2 m8 S7 o1 B9 o9 E& V8 d8 r{/ M- |. M G" P
int error_code;
0 s8 L; i+ @3 S1 c
% @6 ^* ^) U2 s' g7 J if ( (UF_initialize()) != 0)
; G5 e8 A* x, j) b) i. } do_UGopen_api();
) d- p9 K9 Y% a3 V2 z return;0 P3 e7 X. D$ S# c R& U0 U
9 D4 k$ Y/ g d1 a* ^ if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )6 _; l8 g/ Z7 }9 W Z% a
{: |7 V4 P P, L5 _& e! b
char fail_message[133];
8 S* [6 ]. M4 D" r: y/ {* N
( T/ X8 G$ P" C6 R3 y7 B1 d UF_get_fail_message(error_code, fail_message);
0 y2 Q Y1 V: @ m5 L- P4 A' c printf ( "%s\n", fail_message );
2 T' a% c; T& F1 y1 F7 f- D }
. _' i* i6 ~+ Z. X4 v
* N- f! m1 q& r6 y3 k, q UF_terminate();
" _: u; I7 ?. m4 T return;* q/ L9 | f0 r9 Q
}
! x% G/ d$ h& H l G- T# L$ jextern int LaunchBsurfaceDialog ( int *response )
' t4 a3 M3 p# O }% Y# W3 N{2 ^& K1 {! s7 U, v) v
int error_code = 0;2 Z8 A3 u1 y5 n4 j
6 B; k* E% P3 K
if ( ( error_code = UF_initialize() ) != 0 )
( Q" B2 A# b* @) o return (0) ;/ U/ }' j4 Y# E9 C5 |3 w0 n( e( Q
8 [9 c5 ?# Y$ G3 K3 g if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",9 ?* f x$ A0 [: q
BSURFACE_cbs, /* Callbacks from dialog */
9 P4 m. |9 E6 H" ^# X3 h BSURFACE_CB_COUNT, /* number of callbacks*/
' T" |9 g: x6 I3 i NULL, /* This is your client data */: l9 p- c4 N6 W) S2 R' f
response ) ) != 0 )4 t4 V0 |0 h8 r" z
{ S+ ^: d6 C2 s: m2 V# D' z6 p: n
char fail_message[133];
! W+ w, [. U. `' o# o4 P8 b* }; e4 g7 O* P7 m& f7 b h1 T: u
/* Get the user function fail message based on the fail code.*/) g' ?1 C: w% C. s
UF_get_fail_message(error_code, fail_message);7 P, [7 K" p3 n& I7 _8 Z
UF_UI_set_status (fail_message);3 N5 i. ?! b) x8 }# I
printf ( "%s\n", fail_message );
1 ^- b9 n$ ]/ I$ P* O& D }8 g8 S" s& V7 Y) S! I0 l
* e4 v% m; w! I, Z9 U: S9 ^: a* x+ {1 V- b
5 T: w/ S/ Q* u" j. J UF_terminate(); ' s9 q. Z+ I) c! ~4 \
return (error_code);, E0 W5 ^# J7 d2 Z. ~5 N2 A
}
5 P) |% G8 X( z/ |
, |' ` j, Z! \5 y" x/ P8 S2 \3 _extern int ufusr_ask_unload (void)
: P0 S' k) R X9 C- e; o( S7 [& ~{/ B& `/ R, z$ q
/* unload immediately after application exits*/7 j3 K1 S3 q# ]) O7 p
return ( UF_UNLOAD_IMMEDIATELY );
6 E" p H, R) I8 S5 [}
) Z/ L" S) I7 jextern void ufusr_cleanup (void) }- Y- `, ^7 Q/ c0 x' g4 X; `
{
* L, a% z6 r7 D) k& i( M, A+ _ return;
2 W4 ~/ |9 |) f) S% S j}
3 [5 z: `) K( z4 u [#endif |
|