|
#include <stdio.h>
, Z' z* s; V( a2 b3 H4 D9 r#include <uf.h>1 C9 |/ g3 ^* b$ I! ~
#include <uf_defs.h>4 M2 c" v6 b$ L
#include <uf_exit.h>4 P% V* ~5 _$ A; ?4 u0 n
#include <uf_ui.h>
. k9 ]9 q+ Y/ L: y#include <uf_styler.h>4 g! P" E n6 N7 B- K+ X' w; I, Y- M
#include <uf_mb.h>
( p1 G: s8 @: a4 z7 y#include <C:\Documents and Settings\Administrator\My Documents\bsurface\新建文件夹\bsurface\bsurface.h>$ p8 n2 Q! Z4 d8 m: U
0 v( q" X" o5 R1 |3 [+ U#include <stdlib.h>//后加
+ D. G: Y" K% ~6 ~9 O1 a/ H: h, a#include <uf_part.h>) _7 @% F' l6 m- w& ~: H/ g+ R
#include <uf_defs.h>0 h& z7 m2 I" |1 [1 P# \/ f
#include <uf_modl.h>4 P8 E8 I# P M/ }: l8 u
, S! c6 s6 G- x( O+ L/ l7 n
#define UF_CALL6 A! ^6 Q t/ t# P' d9 \6 @
#define BSURFACE_CB_COUNT ( 4 + 1 ) /* Add 1 for the terminator */
! x3 B) d' W' {static UF_STYLER_callback_info_t BSURFACE_cbs[BSURFACE_CB_COUNT] =
7 T% W3 j% h/ j1 R7 N9 w7 N! a{
, U; Y0 k* I( X- J c2 S+ T8 S& l {UF_STYLER_DIALOG_INDEX, UF_STYLER_CONSTRUCTOR_CB , 0, BSURFACE_constructor_cb},
$ s4 X5 O/ g) @ K3 `/ l2 l {UF_STYLER_DIALOG_INDEX, UF_STYLER_DESTRUCTOR_CB , 0, BSURFACE_destructor_cb},
3 h8 b1 I; A; @ h: B; E5 F {UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BSURFACE_ok_cb},
- z" m( i9 X4 u7 o# n8 d {UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BSURFACE_cancle_cb},( l" a6 ~ e' {& y$ P
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }" f3 ~6 i* i1 I
};
" i3 r0 G" d; J" I. k) k+ N
$ j1 d6 K/ ^5 d, nstatic UF_MB_styler_actions_t actions[] = {/ G% p3 s# b1 y* m) x& A6 x3 z
{ "bsurface.dlg", NULL, BSURFACE_cbs, UF_MB_STYLER_IS_NOT_TOP },
! k& b% R1 i4 S% Z$ Q { NULL, NULL, NULL, 0 } /* This is a NULL terminated list */; c/ ]. m g6 P
};3 J) |, x9 Y" \
! I6 x( p$ p) F+ v' G: G9 b }static void do_ugopen_api(void)$ @5 {5 H `9 K- ~) r0 Z
{
9 ]" }6 S2 b% V6 K& G& E2 L
0 B2 b5 _# T( b6 T% _3 O char *prtnam = "create_bsurf";
9 M8 P7 o0 F' L% K6 U
7 ^# R, s( X8 u+ ^( G7 t /* Points for B-surface */
( j' l8 J2 ~( ~5 M, ]9 x8 d double points[16][3] = { X1, Y1, Z1,
9 m4 N# I2 `* [1 _ X2, Y2, Z2,
( G! I* l5 k8 t+ {1 O. B+ l X3, Y3, Z3,
; a4 q% n- Q# S H$ V X4, Y4, Z4,
+ V5 d7 r4 t4 k3 Q T& s: e X5, Y5, Z5,! y6 M; M& P) b
X6, Y6, Z6,
. z: V9 q, t9 f4 F& H X7, Y7, Z7,
. L6 O" Z2 [# N; L3 [ X8, Y8, Z8,7 F" q" K4 y9 w( ~4 |* q5 k6 _0 p
X9, Y9, Z9,, x0 m& C9 k2 @: W( x. `! P! ]' V
X10, Y10, Z10,5 b0 n* t8 O* C8 e0 Q, S% c
X11, Y11, Z11,
r& W3 x5 @7 [, i6 {( `# v9 x X12, Y12, Z12,+ X# G2 T! \8 w5 Z* J3 h" ]
X13, Y13, Z13,
& i! ]0 v1 e! N X14, Y14, Z14,% S- x& _+ R6 i* W, A$ m; u
X15, Y15, Z15,
a& U! Z9 J9 E, R X16, Y16, Z16 }; : `1 k6 O* M$ k. c) \# p
% I3 g& g' h! d4 E int create_mode = 1;
) g. u4 @1 p% @7 i int u_closed_status = 0;
& R1 M e9 @. L( i1 W9 f5 l int v_closed_status = 0;! y) P2 g0 Z8 p5 I
int u_degree = 3;- S3 n. |. w+ ?! x( M# M* ?
int v_degree = 3;
- [9 r- W3 `' j& p- g int num_rows = 4;
! l* O2 _* @7 c% I8 R1 o3 p0 b int pts_per_row[4] = {4, 4, 4, 4};, d5 i- X+ r8 X. ^( F+ P
2 h7 V/ S9 {, `9 A) E& p int ii, jj, kk, indx;
% z6 g9 |6 t) u. F O ! `- F8 n) K& `5 o) W
tag_t part_tag;1 {' p0 W4 e7 [( m9 u
tag_t bsurf_obj_id = NULL_TAG;7 V, U/ I ]' Q' g% I
( R: c8 @% P1 K, C4 }8 g1 ~ UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */5 ?/ u, u' K/ G1 e+ |
UF_MODL_bsurface_t bsurf;0 c1 q- _! F5 t9 O- V
4 a: G h0 E& E ]2 w5 }6 G5 @! A
0 k! N3 F+ R8 g. V4 s: E+ z+ Y6 J /* Open a new part */7 F. V- k. b6 x4 D6 q5 |
UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
0 H/ R& j$ U3 o+ J2 E: V4 `" c
: j$ l3 W* r4 h; r0 U' \% c8 G6 X pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
* i: X# X& d6 e$ E6 Q8 g. M4 g* M sizeof(UF_MODL_bsurf_row_info_t) );
; w8 y5 b8 @$ A5 Q( k! x) P
6 {8 z( Q% G% h' o. T /* allocate and load point and other information for each row of points */' z5 S! _" C& ? T
indx = 0;9 k. Z! ?) T- |
for (ii=0; ii<num_rows; ii++)
\1 A( X5 g5 T z4 T+ l {! g$ i) ?1 A5 ]1 {' X0 Z
pts_info_per_row[ii].num_points = pts_per_row[ii]; /* can vary */
& }, T) P. T( f U1 r" A& [' F3 ^. O pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *
" I3 Z* V: E8 [ r! y sizeof(double) );
' ?" S5 Q0 ~5 D* f& y9 w ; [# _" H+ T/ i
pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] * 2 p& Z# S. @% n8 Y
sizeof(double) );
' ~6 H* {( C6 a, p/ ]
; x" C% ?5 \; b6 S u /* load up point and weight info */) @! |6 g( g, M4 S' t# n& q
for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)
0 N5 B+ W8 o7 |( }0 N7 o {
3 o, O8 @4 I( r( d; N$ ^ pts_info_per_row[ii].points[jj] = points[indx][0];* Q( w' @! P! u9 K) A0 F
pts_info_per_row[ii].points[jj+1] = points[indx][1];
: ^( |- Q! L& a9 R6 f) l9 I pts_info_per_row[ii].points[jj+2] = points[indx][2];
9 T W7 b! [+ E5 }" q pts_info_per_row[ii].weight[kk] = 1.0;
% H$ ?& a4 X$ K! K' P
- O* ?2 Q: Z) Y; N2 p }
5 N5 {6 a/ w" }2 n$ @+ R6 Y }6 j& k5 r& j. W% |1 G4 \% A$ [
" }% n6 D, e( ?8 A1 Z0 ^! Q4 m0 p5 E) M /* create B-surface */
% r) y" G J% K0 K/ o/ |7 @ UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status, % j' ]' P6 F# j: F
v_closed_status, u_degree, ) B7 E) {0 S& G
v_degree, num_rows, pts_info_per_row,$ R) ?/ H" o a% J
&bsurf_obj_id));
) z9 \! ]5 u9 v# s& s4 y
i7 r# y- s8 e* `1 D/ r q if ( bsurf_obj_id == NULL_TAG )
% `+ J$ Q% b) K. W printf("*** ERROR CREATING B-SURFACE ***\n");! Z5 L0 E3 Y( h
^# |" D0 _% ]$ ^1 i0 R2 K) ?( y /* free allocated memory */9 O! x5 K) o" ^3 i$ l
for (ii=0; ii<num_rows; ii++)
4 R5 K; U4 M- ?! I {
; U! I Z6 s! C/ m; u5 r free(pts_info_per_row[ii].points);1 O( S& X+ I( O: `0 |
free(pts_info_per_row[ii].weight);
4 _9 q7 b5 A* \3 J1 K }8 n; J& K+ E- J0 s' _" p
F2 T v$ O: r+ R% x* K+ X, b free(pts_info_per_row);1 d0 D" m) _7 [
) j, ~. Z; _2 Z% H4 R
, H6 _% h& X4 _9 [2 y$ ] /* ask the B-surface information */! ~4 \: [( a" s
UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));
% u0 K5 g7 K2 v& r* U
6 Z+ ~% q4 {4 @% n4 z /* validate the surface */& M7 Q4 [+ V. R) {: I( H% i
if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )
5 y3 e8 V5 e5 Z5 e/ O printf("*** ERROR ASKING B-SURFACE ***\n");7 K0 z0 e* c, Z. P# ?8 N
J+ ]+ l; O5 U* I' W$ R UF_CALL(UF_MODL_free_bsurf_data(&bsurf));
; N2 y, N5 j9 g: ] u6 L/ [" s* E* y
2 A" q8 \& ?6 |} 1 L+ K# h$ o Y6 g+ w/ I. @
extern DllExport void ufsta (char *param, int *retcode, int rlen)
+ z9 S- e" P [$ X! U+ I" a/ Z# W. A{+ H- b7 e" x- L: ^, X
int error_code;
5 q% Q$ i% d% }" ? ( K, p. D( {5 y5 i0 p
if ( (UF_initialize()) != 0) & G5 D( w& C4 p
do_UGopen_api();
' Y2 y, }9 L4 U0 A/ N. S5 q return;% b9 n S# f) U; T; A
, b- B1 L* w' s" u) T- r. V5 X if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )( D' c& n$ G; }1 W0 S0 r
{
) p- ]+ {5 m# g6 n, x: A char fail_message[133];
6 L. ^0 c' r" O6 l. h; t, t : _! K* k* @, o( u4 ]8 Y3 L) d, N
UF_get_fail_message(error_code, fail_message);4 i3 P8 ^9 w+ L7 ]
printf ( "%s\n", fail_message ); + }3 Y; s3 p& G6 c0 c# Y3 B
}8 b) a9 R3 F0 Z! y6 Z* S
. h% G, X6 O2 d3 o UF_terminate();
( E# o0 [& W% Z- ]# A7 { return;
! e$ t) a8 e8 c}
$ k; Z5 f& ?' ]5 P q/ M% f. Nextern int LaunchBsurfaceDialog ( int *response )
$ J* M8 f: N9 d0 I1 F{" q/ y# ]2 Y% m4 H* l7 ~
int error_code = 0;+ e4 F+ E7 m) s* \0 I' O4 L: z! D
4 T* J! Z1 c. |0 _# ^ if ( ( error_code = UF_initialize() ) != 0 )
, O: V1 V7 o4 u return (0) ;
, @! _% W. @5 _- A5 M/ d# S* U
/ K6 i' o- r) A J3 C! S if ( ( error_code = UF_STYLER_create_dialog ( "bsurface.dlg",/ x; u- ?- a6 @. z B
BSURFACE_cbs, /* Callbacks from dialog */
% u) x# O0 ]: \$ t( ~6 e/ e* o BSURFACE_CB_COUNT, /* number of callbacks*/7 l" w/ d# K: O- v2 V
NULL, /* This is your client data */
7 j' X/ @9 ~4 z1 `+ X. Q2 a; M response ) ) != 0 )
( w% o: B q- a4 p {7 y* e) ^) |4 b( M) ^( L& W
char fail_message[133];
( `4 K" _* L! A' C& D4 u: L
" D( t9 S& f6 L* H" ]" U& v /* Get the user function fail message based on the fail code.*/; _3 q$ s G- \% i
UF_get_fail_message(error_code, fail_message);. L0 `0 Y* U$ y8 V; Q1 d
UF_UI_set_status (fail_message);
1 Z2 u( K& Y6 I: Q* y+ j+ E printf ( "%s\n", fail_message ); . ~. A1 `6 b% `
}
. z I7 ?9 O6 {" @! u' {2 v0 Q/ A7 _! D2 c
; i0 j& k8 X+ r) \, l& d0 Y4 P! Q7 M
UF_terminate();
, R: h6 j' p( |. @7 [" Y6 k2 P return (error_code);
8 F) Q: W- S7 O* X" D8 o}% T8 K6 l2 @! r# @: t1 Y
. o2 N* A a8 u) f" {; [& Xextern int ufusr_ask_unload (void)4 s+ J: d* `! y- n- a y: X/ }
{7 L A4 e5 e5 H- W6 \- A
/* unload immediately after application exits*/
, e7 W2 z$ k- I+ S return ( UF_UNLOAD_IMMEDIATELY );
) d4 `2 C. u8 C7 [}
. u5 D: }4 q* W" W$ B) f7 ?extern void ufusr_cleanup (void)
9 |1 [* _( w) [2 H# Y{& C1 y$ D( n9 S$ S) C/ A
return;& W8 R2 A6 F# ~7 W: o& u* J8 A. t
}
" N4 x" }% `( N! J0 M( x#endif |
|