|
#include <stdio.h>
3 a" j, t, L/ y/ t% ^; ^/ T#include <uf.h>
' r, y7 l, ? W6 L) \. L8 Q+ ]#include <uf_defs.h>" J+ P4 p. L9 E
#include <uf_exit.h>
$ P5 z6 b+ C# r: J9 h6 ~9 ^#include <uf_ui.h>, n0 {9 f& d- O) t$ S+ J
#include <uf_styler.h>
0 D/ t. |4 N5 _- B' Z4 w) \8 d5 `#include <uf_mb.h> ( x' `1 Y# K" _* o
#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>. h2 F4 c3 W2 R% E3 O' P
8 U$ k" ?/ i% q! q% k4 O: _" S#include <stdlib.h>//后加. O4 b3 p# b7 ?1 N- \8 G# q$ n
#include <uf_part.h>
3 ?! w% S3 t% @- [, K9 Q#include <uf_defs.h>
. W0 S# L1 r. m$ [8 R; R, p#include <uf_modl.h>! V6 {; w% C# g A
$ Z- r" d E+ z3 t$ t
#define UF_CALL% ]* N) j* `- x5 U- v* k' f
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */* W3 ^7 b; B7 N% f7 w
static UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] = 9 B- Q- W" A: T; x' y# ~, @
{
, t4 f; k1 j9 ^7 T K- O {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},
7 U5 ?1 c+ D7 u, _ {UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},+ W! v( W5 ]! i: I
{UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},* b% a/ s& p% B* k5 x$ w8 d
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},
/ T" i5 n# u. t1 o ^6 q {UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }
( ?* d! W' i% Q# g! W};
3 {0 m7 V$ i& h2 I2 u% r4 [( [! F. N8 G
static UF_MB_styler_actions_t actions[] = {/ g+ B# f, e g$ Y8 D% f- I
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },$ B& I' J+ s! l. \+ l
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list *// `1 b# R5 D: o, s% R0 R
};' q- s7 \! E$ k! `- Y/ _# K4 }" \
% `3 T) T0 K2 R9 O9 z! ^0 P% ~static void do_ugopen_api(void)1 d/ m( t+ r( a6 X' t/ {, g3 ^" U1 H
{
( _7 w8 w6 S# V, y' _
7 T6 ^' N) j( ~( b char *prtnam = "create_bsurf";
; U2 l2 o3 k! {$ [% R" V8 J( u) q
% o6 K+ N, X7 |+ _5 } ?7 ? /* Points for B-surface */: |, V/ V( @# q' S- L7 _
double points[16][3] = { X1, Y1, Z1,
& S3 @, m, z" \& P; h X2, Y2, Z2,
: ?$ N* @. o2 ^. N" u X3, Y3, Z3,
8 W' ^5 i1 x: s L i X4, Y4, Z4,
7 r) S3 X) O1 b/ g X5, Y5, Z5,; l8 Q1 e* i% T# s/ F! O
X6, Y6, Z6, 5 {* m. x6 K3 z
X7, Y7, Z7,4 _& h# M; R' J8 k0 Q
X8, Y8, Z8,
5 I& U+ R6 d- Z3 e3 ~7 O X9, Y9, Z9,
% n# |/ z" e. j X10, Y10, Z10,
- Q3 A; u- x2 T$ M X11, Y11, Z11,
1 v( v3 e. o* j- i. o g: X X12, Y12, Z12,+ M. Y0 o4 ]; I
X13, Y13, Z13,; a! c i5 l1 {% E, V+ }7 j- z
X14, Y14, Z14,
2 u' G+ q4 n8 q7 W6 t6 d' r X15, Y15, Z15,
& \' E3 Y% E' S. v: ?: z; { X16, Y16, Z16 };
$ X: N3 U8 b5 ]
H! }# ?3 {+ `4 ] int create_mode = 1;: c( X( n6 t# Y' ^. Y
int u_closed_status = 0;
7 j5 q2 l- t) u+ N/ [% G int v_closed_status = 0;
1 i# Q; \: \4 k. u int u_degree = 3;8 t* J- e0 E q' H
int v_degree = 3;5 j7 Q6 E1 X; j
int num_rows = 4;& l# ?' F. k8 F7 L6 ~
int pts_per_row[4] = {4, 4, 4, 4};
, c- }& P" K" K A* C
. L5 x5 B( ]4 I9 V. A int ii, jj, kk, indx;8 x3 f( W* ~, ^% E
# J8 H+ R, ?( r% `' d% V tag_t part_tag;
" z/ P" R0 [0 O7 i tag_t bsurf_obj_id = NULL_TAG;
3 L, m, Y/ [9 q4 A X- T% ^( }+ N/ C) b' u+ }
UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
2 S! ?; b2 t. Y3 Y UF_MODL_bsurface_t bsurf;
8 ^6 P2 I* t5 [# D( m
1 ] g: @& v! _* x, e7 k
6 b+ Z% ]# y# q& [' N /* Open a new part */
, L! z T; H% Z& g4 Q0 o( b UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );+ U' T2 ?1 d- p) M' O* u
* c F; A( x2 |$ t" S$ o
pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
$ @$ j. @( R, _- z: Q sizeof(UF_MODL_bsurf_row_info_t) ); B$ R& R+ D6 w5 Q
* }9 z' A9 k( w( Y Y, X) q/ B+ {' t /* allocate and load point and other information for each row of points */0 |: `' K* y7 A) S: a1 i
indx = 0;
% O* x7 Q6 Z- U: b! g8 n6 T for (ii=0; ii<num_rows; ii++)& T! n5 C; `, g" v
{
2 _6 D$ u- I# J# w3 f$ d L pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
6 Z0 i) j5 x$ |: i) c# ?+ G pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *8 x9 B9 K9 M( W( e
sizeof(double) );
1 Q8 q$ ?, K/ B) m) Q8 L ) ?' X" p( D6 j. O" h1 U( g5 Y9 p% U
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
' R* R: C: ~0 o5 {$ z sizeof(double) );" ?) w0 t* |5 T8 M, v
5 U# i! t" _) ?# J' `2 s2 R3 L, @& _ /* load up point and weight info */' C5 c2 U( v6 E9 p
for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)
4 @4 P$ Q7 M% b4 b4 { {6 y0 c m0 E j* c; _1 y
pts_info_per_row[ii].points[jj] = points[indx][0];4 E+ p3 L. w1 D& \) r3 h
pts_info_per_row[ii].points[jj+1] = points[indx][1];
8 \3 i0 A: o g pts_info_per_row[ii].points[jj+2] = points[indx][2];7 t0 B4 U- z5 Y' ?
pts_info_per_row[ii].weight[kk] = 1.0;
& E1 p6 x4 E; v% w( j
5 ]. Y" ?) A" H- Q3 I( Q! x }
/ N* O7 m8 c, o! m! {4 Y }% q, G" U( `8 R* B8 ^3 X9 ~
( O& \, p7 \& w% W2 g8 m# c2 p8 q, w* x
/* create B-surface */: `! H" s0 r3 x0 b9 N
UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status,
6 b2 q0 p' \5 n6 B* K7 Q( S v_closed_status, u_degree, / R, ^; D/ N3 n y6 F
v_degree, num_rows, pts_info_per_row,
! q) v F4 f. e0 k' \, _1 P5 {7 I: A &bsurf_obj_id));! J }! D# ^5 _* d. |% ~; e, `' T
* _9 _" _: p4 j+ d if ( bsurf_obj_id == NULL_TAG )
# W! V/ m) @! Q% f L- E printf("*** ERROR CREATING B-SURFACE ***\n");& V1 K* ?3 D: z- B4 A
+ C4 T% ~3 q- \1 M0 I5 q
/* free allocated memory */" z0 U/ N( |% N* {( k4 t; A& B
for (ii=0; ii<num_rows; ii++)
- ?5 b' }( ?. e" ^/ Z. K, R {$ ^) V, E' Y$ F( L3 p( u
free(pts_info_per_row[ii].points);
$ y5 `$ N) z5 d9 I* O free(pts_info_per_row[ii].weight);4 W* l/ f, D/ H
}2 x- E1 D/ D3 d
; v9 J% m& H7 X: b U9 ~ free(pts_info_per_row);/ z a! G9 I! v# Y2 G0 G
- P9 l' a' C, C2 B# C
, a; l& x9 q( Q /* ask the B-surface information */ I; B5 e0 c0 A0 O' \ h: V4 J; A
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));" O$ x' Q( k" o& w/ ^. k) Y) O
5 P9 \2 S( Y. |( D4 W; O; H2 q /* validate the surface */
9 U% ]5 Y" T% g% o; }) V/ f if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )
/ ]1 q2 s- a4 C printf("*** ERROR ASKING B-SURFACE ***\n");+ H2 \+ C$ Q Q2 K
' |; S# I6 M( _3 o UF_CALL(UF_MODL_free_bsurf_data(&bsurf));3 A* J- [% K7 D' ]* c: t8 Y) C6 l
3 S7 W' d& M8 q. A3 `
& P. N! r1 S( ^0 B0 c2 j$ w8 K) g2 A}
) g2 p5 D* L8 G! X0 Dextern DllExport void ufsta (char *param, int *retcode, int rlen)
6 B# \( F8 x9 c( g- d) B9 w# `{
' q$ m4 Q3 Q3 a- ` int error_code; V' Z) a7 a/ {9 R) K5 |6 l$ D
! R* ?! G1 i) Z9 r6 ]8 }' o
if ( (UF_initialize()) != 0)
! o' v* J* f+ r/ K! Y3 M# q6 y do_UGopen_api();
5 w) R& a" M2 f; d8 A return;) m- K/ z9 d2 ? z
% W. ^5 h5 s3 |) @% l6 Q if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )
' c0 X0 q; T O' |7 [ {6 J9 ]5 Q( j( f6 d, Z6 l
char fail_message[133];
( |# I0 s! k6 g* R% w % c$ c! r5 w& Y; P( k3 N$ \! A
UF_get_fail_message(error_code, fail_message); i/ x4 L0 a3 |, C; k3 E
printf ( "%s\n", fail_message ); , T/ s4 |8 C4 C; V+ f9 H
}/ M) O3 E6 ]/ M! N7 ~9 v' n6 V5 q8 J8 f
9 x! Y8 ^& _' k
UF_terminate();
$ p% A* b4 w) e" c- Y return;
6 _; o' `3 O1 x w- j$ C3 D' I}* H/ e) `3 T3 B
extern int LaunchBsurfaceDialog ( int *response ), u* n9 ?" T* M4 a0 B* G% @7 e B, ^
{' }% Y' \1 L4 V# M. P6 y4 D4 T
int error_code = 0;
6 I$ Y" E+ e. |0 W0 ]: m! M& @9 p
2 h$ {' @6 q- V) h, {' U if ( ( error_code = UF_initialize() ) != 0 )
, A9 b, y$ ?& H- x) \ return (0) ;
$ I; t3 I+ W W# q
! ~/ L: m M+ g1 A# Y; k1 p if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",- _) r: B! O/ [. V4 F
BSURFACE_cbs, /* Callbacks from dialog */' r9 A4 s0 R9 y3 Q! T$ m
BSURFACE_CB_COUNT, /* number of callbacks*/% v" `) T d- { p2 L
NULL, /* This is your client data */3 _+ a4 \- i( T
response ) ) != 0 ); |3 [2 r: m- n8 o# Q; D0 ^
{
: l- W* s/ g; F% k" t9 m char fail_message[133];; p, |4 d: u8 E+ `3 L# g* Z
7 e& f! ~3 _3 \( q N* ^ /* Get the user function fail message based on the fail code.*/
+ W' C7 h) j% E, H UF_get_fail_message(error_code, fail_message);- U1 {5 A+ ^5 J6 Y& u/ e* `
UF_UI_set_status (fail_message);6 S5 ]! j7 Y8 \ B4 j0 a. k
printf ( "%s\n", fail_message );
/ q+ B) r' f' ^; e- O }+ h; X. D! x6 O j# ^5 J( J
" s1 e; E3 ^% H Z+ l
0 t: |9 Q: b+ t
UF_terminate(); , y4 E( R; h/ \" u( v8 N
return (error_code);2 `. j& Z1 {8 R. @3 ^: D) {
}9 d9 I: e" ]& M4 j( I
+ m6 h) N3 ?- c# j. B7 N0 }' Q5 \extern int ufusr_ask_unload (void)
. H6 B. ^3 i8 o" {3 B' l{4 X t4 M% a7 M$ h
/* unload immediately after application exits*/, \1 _9 U) [! |7 A R. ^ @( @1 X# R
return ( UF_UNLOAD_IMMEDIATELY ); H/ t0 a/ `/ s; z3 r, A3 p9 u
}
' |" c1 b( M' s' l. lextern void ufusr_cleanup (void)7 D- C+ I( p, B, u1 d
{% S3 G! N) R! |: j/ v1 D: h6 U( t
return;5 d+ D3 a3 C& H% {. D" y
}
$ H8 S7 K( B& F- u+ ~6 }#endif |
|