今天看到胡工对bounding_box的分享,我也来测试一番(原帖地址:https://www.ugapi.com/thread-10287.html)
获取对象的边界盒子的三个函数:
1 UF_MODL_ask_bounding_box //只能得到绝对坐标系下的边界盒子,速度快,结果不精确
2 UF_MODL_ask_bounding_box_aligned //可以得到指定坐标系下的盒子,速度快,结果不精确
3 UF_MODL_ask_bounding_box_exact //可以得到指定坐标系下的盒子,速度慢,结果精确
运行时间测试:
生成上面这个3D产品的边界包容盒100次,测试的结果为:
UF_MODL_ask_bounding_box_exact的速度还是挺慢的
函数例子:
1 //box 2 #include "Text.h" 3 static int init_proc(UF_UI_selection_p_t select, void *user_data) 4 { 5 int errorCode = 0; 6 int num_triples = 1; //选择类型 数量 7 UF_UI_mask_t mask_triples[] = { UF_solid_type,0,0 }; //定义选择类型 8 9 errorCode = UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples); 10 if (errorCode == 0) 11 { 12 return UF_UI_SEL_SUCCESS; 13 } 14 else 15 { 16 return UF_UI_SEL_FAILURE; 17 } 18 } 19 20 extern DllExport void ufusr(char *param, int *returnCode, int rlen) 21 { 22 UF_initialize(); 23 char *message = "提示"; 24 char *title = "标题"; 25 int scope = UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;//选取范围 26 int response; 27 int count = 0; 28 tag_p_t object; 29 UF_UI_select_with_class_dialog(message, title, scope, init_proc, NULL, &response, &count, &object); 30 for (int i = 0; i < count; i++) 31 { 32 tag_t tagObj = object[i]; 33 UF_DISP_set_highlight(tagObj, 0); 34 //---------------------- Enter your callback code here ------------------- 35 double block_corner_pt[3]; 36 char charC[132] = ""; 37 char charK[132] = ""; 38 char charG[132] = ""; 39 char * edge_len[3] = { "","","" }; 40 41 //UF_MODL_ask_bounding_box 42 double bounding_box[6]; 43 UF_MODL_ask_bounding_box(tagObj, bounding_box); 44 //创建方块 45 tag_t tagBox; 46 block_corner_pt[0] = bounding_box[0]; 47 block_corner_pt[1] = bounding_box[1]; 48 block_corner_pt[2] = bounding_box[2]; 49 sprintf(charC, "%f", abs(bounding_box[0]-bounding_box[3])); 50 sprintf(charK, "%f", abs(bounding_box[1]-bounding_box[4])); 51 sprintf(charG, "%f", abs(bounding_box[2]-bounding_box[5])); 52 edge_len[0] = charC; 53 edge_len[1] = charK; 54 edge_len[2] = charG; 55 UF_MODL_create_block1(UF_NULLSIGN, block_corner_pt, edge_len, &tagBox); 56 57 58 //UF_MODL_ask_bounding_box_aligned 59 tag_t tagWcsTemp = NULL_TAG; 60 UF_CSYS_ask_wcs(&tagWcsTemp); 61 double pDblMin_corner[3] = { 0,0,0 }; 62 double pDblminDirections[3][3]; 63 double pDbDistances[3] = { 0,0,0 }; 64 UF_MODL_ask_bounding_box_aligned(tagObj, tagWcsTemp, FALSE, pDblMin_corner, pDblminDirections, pDbDistances); 65 //创建方块 66 block_corner_pt[0] = pDblMin_corner[0]; 67 block_corner_pt[1] = pDblMin_corner[1]; 68 block_corner_pt[2] = pDblMin_corner[2]; 69 sprintf(charC, "%f", pDbDistances[0]); 70 sprintf(charK, "%f", pDbDistances[1]); 71 sprintf(charG, "%f", pDbDistances[2]); 72 edge_len[0] = charC; 73 edge_len[1] = charK; 74 edge_len[2] = charG; 75 UF_MODL_create_block1(UF_NULLSIGN, block_corner_pt, edge_len, &tagBox); 76 77 78 //UF_MODL_ask_bounding_box_exact 79 double pDblBodyBox[3]; 80 double directions[3][3]; 81 double distances[3]; 82 UF_MODL_ask_bounding_box_exact(tagObj, tagWcsTemp, pDblBodyBox, directions, distances); 83 //创建方块 84 block_corner_pt[0] = pDblBodyBox[0]; 85 block_corner_pt[1] = pDblBodyBox[1]; 86 block_corner_pt[2] = pDblBodyBox[2]; 87 sprintf(charC, "%f", distances[0]); 88 sprintf(charK, "%f", distances[1]); 89 sprintf(charG, "%f", distances[2]); 90 edge_len[0] = charC; 91 edge_len[1] = charK; 92 edge_len[2] = charG; 93 UF_MODL_create_block1(UF_NULLSIGN, block_corner_pt, edge_len, &tagBox); 94 95 96 //------------------------------------------------------------------------ 97 } 98 UF_terminate(); 99 } 100 101 extern int ufusr_ask_unload(void) 102 { 103 return (UF_UNLOAD_IMMEDIATELY); 104 }
效果: