|
#include <stdio.h> : W" X$ R \( W$ h
#include <uf.h>
3 E* m! P. x5 p8 ~+ l0 ^9 B, c#include <uf_defs.h>
4 l# p ]& r! P2 {#include <uf_exit.h>; P' [( B5 J1 l8 n. c* h+ i5 `
#include <uf_ui.h>2 \+ {0 A; \8 [
#include <uf_styler.h>; A$ l! w1 Z# i5 o
#include <uf_mb.h> ! e+ _% B) X9 U
#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>4 ?. r5 }" d* U; F6 v2 y
5 p7 R; @! I n! E
#include <stdlib.h>//后加5 w+ ]: y+ X) A/ C
#include <uf_part.h>
- N0 z) V; i% o% K& }2 G; P* K#include <uf_defs.h>9 w/ K6 F. ?9 j
#include <uf_modl.h>
: g; G9 V8 J" F" g* r% J1 H
2 Y* X6 ^' [( @' ?. a' Q#define UF_CALL6 H3 v W, V' Z" ~/ F
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
7 R, }% m' F" v" j' g, s7 jstatic UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
4 B8 X$ S, _& m% N{& y/ e( }$ I5 V
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},6 V* M* Y( C% T
{UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},: `8 t* `2 L6 T' Z% k- n
{UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},; q5 E( Y* d3 k1 F2 \8 E2 m3 P5 T; F
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},9 m4 [ f1 v3 J1 r4 C5 k3 e7 Y
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }7 o! G. u8 S+ N' `- m9 R6 M
};3 D! v! P( o1 q9 h$ f
" A7 H0 m7 J; q N- V
static UF_MB_styler_actions_t actions[] = {
) ~; S) ?. t6 t( d! Z { "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },
) n# u& I* R9 I { NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
/ s- w6 x) P. S};
; b; v) L% L$ z' C) d. [$ F1 {( N T# t# t. `* y& [% h9 i
static void do_ugopen_api(void)2 Y+ ?7 e: z! U( O: W
{
( \) A" O# f0 U) z- M" r' a! ? s( r' K- X8 P4 q
char *prtnam = "create_bsurf"; , j9 Z' @" X v, B# M
$ y, @+ O8 p4 ~& f- y
/* Points for B-surface */
7 m% ]! a+ q0 ]3 C5 Y: C! Q double points[16][3] = { X1, Y1, Z1,( Q% {# m, D" m( E" o& F
X2, Y2, Z2,
# l' a: g. Y# c6 K) x9 P8 D1 q$ _% m X3, Y3, Z3,
; I9 Y, ]# c% P7 F$ W/ l X4, Y4, Z4,# ~1 m: H+ ^& O- X$ K ~
X5, Y5, Z5,. G; l, M& x! _# \
X6, Y6, Z6, 2 ~' w9 {( }: b
X7, Y7, Z7,0 S( D; D% p. n0 Y
X8, Y8, Z8,
" ~" v8 Z6 B ?+ x& W0 R5 j X9, Y9, Z9,- h8 E* {" o0 E, Q" D y" p) g" w" C
X10, Y10, Z10,
/ I& N7 ]. O- @6 e4 o, `9 S# d" _5 P6 x; X X11, Y11, Z11,
1 F9 S/ ~+ r1 k' w" [8 |2 n/ \- q" g X12, Y12, Z12,& N/ Z6 z% x5 K7 X- M
X13, Y13, Z13,/ G5 ]2 h7 J0 \. S9 d
X14, Y14, Z14,
$ i) G0 o8 ~) B/ n9 A* ~ X15, Y15, Z15,6 [5 ]/ a2 |" b6 s- s% s0 U6 Y3 s: G
X16, Y16, Z16 };
|! G9 i/ M6 ?! i D
- `# f$ [% E- q" @8 j" J2 q0 I0 w int create_mode = 1;# k$ y6 A) P' y7 B V& ? Q# R
int u_closed_status = 0;
2 H3 o, E8 r; u8 M int v_closed_status = 0;8 y" a( S6 e2 n1 V( b3 D& a
int u_degree = 3;
* ]8 J" s4 D* z; T0 | int v_degree = 3; e/ K9 H9 u8 O) p
int num_rows = 4;8 [8 S' c9 }% D! j# E5 E' \
int pts_per_row[4] = {4, 4, 4, 4};
' k. x s5 [. K [3 q: b& \
% t! N4 b/ x" f# L, r) d; U int ii, jj, kk, indx;
4 D$ r# x, ]# c* a, w. r o; a 6 f" x, v2 k/ G! }
tag_t part_tag;1 f$ B% A5 c' ]
tag_t bsurf_obj_id = NULL_TAG;
5 n$ L: T7 A7 `! s1 V
) O2 c2 e+ W6 b! \* f: n# p3 T UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
" T: b M$ V4 `. \ UF_MODL_bsurface_t bsurf;
5 T8 z5 @# v, V: G J7 h9 T( |+ x
0 h& a: V) x9 N4 v8 s0 F1 Y6 F: {* x, k+ C1 f' x! G/ K) X/ D# ]8 K
/* Open a new part */
/ [5 f6 X+ Z/ M% ]* L UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
% l, j8 _+ R1 W& ~! K5 V- g
# A# Z0 [2 K) u pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
. y7 i Z5 s. U' M' x9 `) f0 X sizeof(UF_MODL_bsurf_row_info_t) );
) {$ ^) o- t/ M* ]: b* d5 n
# u7 D7 [4 h5 b* o9 \ /* allocate and load point and other information for each row of points */% v- j* h, T" b, k6 ?+ @: ~& T
indx = 0;
6 M/ I8 y# Q( g( X, b3 o for (ii=0; ii<num_rows; ii++)# {) G6 x( z* }/ L2 B5 u
{
) W1 ^4 F7 ?0 l0 O$ |# H3 u pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */9 p# H) ~! R: Z6 l8 o+ }
pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *
, N5 R! }7 @6 m1 {' Q: E/ Y sizeof(double) );
! v* Q: _, V, P, m4 e F! s # X, d, b) a+ x% p8 C! Z, {
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
2 B/ c( B1 `7 X; P: S! L- g sizeof(double) );, Y" h/ |6 M& M/ Q& U. H' E( ]
3 e2 n- E0 G$ ^# o
/* load up point and weight info */
: r% ^% o0 f9 Q- _9 @4 h3 p/ l for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++), g: L$ A% k) ~6 S$ |6 b
{
; U, ?& ]* X; g* C/ E pts_info_per_row[ii].points[jj] = points[indx][0];7 L1 {1 V" o2 L1 X: Q
pts_info_per_row[ii].points[jj+1] = points[indx][1];
) z; |% z& n1 Z+ i0 ]5 Z pts_info_per_row[ii].points[jj+2] = points[indx][2];
) ]; ~2 s! u' G1 f2 c: E! P+ A pts_info_per_row[ii].weight[kk] = 1.0;8 f% w3 h3 G# b6 I; a4 \/ H
! [9 v/ j% j6 n
}+ R9 `( c5 M8 ]% ?7 s
}
. @/ X& h* X$ V3 _$ \& w! i. c
2 n0 V1 k5 |9 k+ u; U /* create B-surface */; B2 }% d) C) D! T6 N# Z
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, ; A j! e! I |6 p% W0 l: J
v_closed_status, u_degree,
. J% v7 D I( u1 I v_degree, num_rows, pts_info_per_row,/ i' J |% L3 Q* [) M
&bsurf_obj_id));
; _% E U* M3 T1 O: S& E9 U
( G' r' p1 I( _9 n if ( bsurf_obj_id == NULL_TAG )
: O9 a( S2 E" b printf("*** ERROR CREATING B-SURFACE ***\n");, K. n6 H' |+ ^( {9 S3 u; z4 W' m8 \
% D) H' a5 ?3 Z8 E /* free allocated memory */: r- G) U# c) r/ k
for (ii=0; ii<num_rows; ii++)
& B; R7 R* F# F) i {) M1 m- b: c$ `; J' e$ J5 { p
free(pts_info_per_row[ii].points);: X, l6 j! Q# N: b( h
free(pts_info_per_row[ii].weight);$ | _. I; Y; i3 E" E, M# r* ~0 p: t
}* i) h/ j' m# p4 d/ {7 T
; X9 A( }$ O4 w" X" Z free(pts_info_per_row);
! |7 L2 Z/ k) o7 F I7 x1 U6 V
: [/ a! J! O. a- w- C5 {: B 6 T" n. a( c! q
/* ask the B-surface information */
2 |' y* f; n$ k( u UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));* D: e s4 V6 }& C1 B9 a
. O0 J: a: K3 R5 a" l( j
/* validate the surface */
! F9 e3 ^' Z L. e p- t; r# V" u if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )! o1 R( g6 W5 k! K- `; a
printf("*** ERROR ASKING B-SURFACE ***\n");. R/ X# J5 h' A' ^ H% [
" b0 s; T" g2 U: E$ }1 B9 T& l UF_CALL(UF_MODL_free_bsurf_data(&bsurf));
0 {: E, Y6 o: ]' ]4 [& ^4 F0 k$ I; d# q3 x
5 O, `3 ^$ t0 u
}
" Q6 _8 [7 N cextern DllExport void ufsta (char *param, int *retcode, int rlen)
' C( C5 a1 q+ d{
+ {3 ]+ X; {6 i# D: i int error_code;0 K4 a/ k' l- i3 O( U
& n9 W7 k" |3 ?- n: t; M
if ( (UF_initialize()) != 0) 8 h, v+ i2 U& ~) F2 S
do_UGopen_api(); " t- p4 C( b' U
return;( ?& Q9 o' ^" T& ^. }) g7 g3 Q' A
- ]% w- ~. l L/ w h if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )
: k" u# `$ A) W: R" E {1 U% M2 U* d8 \" K6 ~" g4 Q
char fail_message[133];
B/ Y+ l0 p- `7 T6 `) H ; n3 n, W" ]3 E% P: q1 b c- W
UF_get_fail_message(error_code, fail_message);
# k) K7 U0 p2 n- ]! G printf ( "%s\n", fail_message ); / n! R- f! J9 X ^
} I6 i9 m8 x' W/ r6 z8 ~
: K( B7 \% O6 _) v, L UF_terminate();
( L3 ~. U/ M" [! W return;
/ ^5 S/ ? s3 Y" I6 J! k}
" a' C: s/ ^! K( H$ Kextern int LaunchBsurfaceDialog ( int *response )
6 I5 ]9 B" [/ l h7 l{
% F7 H/ q* w, W" p: t$ e8 W& C int error_code = 0;
; ]& k; L( l3 z: H 1 i/ |& l9 A$ y9 O+ ^
if ( ( error_code = UF_initialize() ) != 0 ) ; M- Z+ L6 x. ~* u, t
return (0) ;
" |4 g' H A/ k2 a3 v# \0 p& D3 V7 G; N& ^, @
if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",# o2 p- W5 ^# }
BSURFACE_cbs, /* Callbacks from dialog */# n* j7 b3 L# g0 y X, O9 R
BSURFACE_CB_COUNT, /* number of callbacks*/9 g& y1 c3 }3 w6 l
NULL, /* This is your client data */7 ~2 s* r$ Q0 j+ n) T P9 c! e
response ) ) != 0 )
* F- V- K; N" o5 e* x5 N3 _ {6 c$ L M( f! H# m. J: S0 \3 F
char fail_message[133];7 q& [8 X+ W- \1 h3 C3 n* O* H/ S
1 d& q" \ p- P& }' f1 O/ D# W
/* Get the user function fail message based on the fail code.*/2 c- Q. N" R f6 u
UF_get_fail_message(error_code, fail_message);+ H4 R$ @$ ?5 a( J5 U9 T- e
UF_UI_set_status (fail_message);% }7 w& b. g1 x) q A7 B T
printf ( "%s\n", fail_message );
# y) [% f- ^, M1 J9 H }
$ J( H8 ~% ?1 p) n( k8 ^7 ]) C# q( {
; s0 m5 U% P! d* Z; R& o UF_terminate(); 5 H% e7 i. R4 t/ U: Y; g
return (error_code);
& `! t! B# e5 X" l' B9 t}
5 v( x. f; g# }: E Q
5 t6 s' i' R. S& P7 wextern int ufusr_ask_unload (void)+ H( N X+ P* b4 x8 c
{
8 C. p8 Y' w2 [. \ /* unload immediately after application exits*/
- i, L3 |, I# P% q* z5 C2 y return ( UF_UNLOAD_IMMEDIATELY );
+ t( U7 A$ }8 T3 f1 F6 d Q}9 u$ e! n$ C6 ~( N; X
extern void ufusr_cleanup (void)$ f* C% w' X$ D/ x6 u: p7 E6 |; u
{! N! h/ V5 c' o. d( @* e* `& g
return;
) e) R N( F& T( t. Y}2 X. C% N' r: G; v
#endif |
|