【UG\NX二次开发】UF 修剪曲线(UF_CURVE_create_trim)

//用边界线修剪曲线(裁剪或延伸)
tag_t curve_trim_line(tag_t original_line, tag_t bound_line, bool start_pt)
{
	int  trim_string[1], trim_dir[1], bound_string[1], bound_dir[1];
	tag_t  trim_curve_feat=NULL_TAG;
	UF_CURVE_trim_mult_t out_trim_info;
	UF_CURVE_trim_t trim_object;

	trim_string[0] = 1; trim_dir[0] = 1;
	trim_object.string_to_trim.num = 1;
	trim_object.string_to_trim.string = trim_string;
	trim_object.string_to_trim.dir = trim_dir;
	trim_object.string_to_trim.id = &original_line;

	trim_object.spline_extend_opt = UF_CURVE_EXTEND_NATURAL;
	trim_object.trim_type = UF_CURVE_TRIM_TO_ONE_BOUND;
	trim_object.tolerances[0] = 0.02;
	trim_object.tolerances[1] = 0.02;

	bound_string[0] = 1; bound_dir[0] = 1;
	if (start_pt) trim_object.trim_to.one_bound.string_trim_extend_end = UF_CURVE_TRIM_EXTEND_START;
	else  trim_object.trim_to.one_bound.string_trim_extend_end = UF_CURVE_TRIM_EXTEND_END;

	trim_object.trim_to.one_bound.bound.string.num = 1;
	trim_object.trim_to.one_bound.bound.string.string = bound_string;
	trim_object.trim_to.one_bound.bound.string.dir = bound_dir;
	trim_object.trim_to.one_bound.bound.string.id = &bound_line;
	trim_object.trim_to.one_bound.bound.use_suggested = FALSE;
	trim_object.trim_to.one_bound.view = NULL_TAG;
	trim_object.trim_to.one_bound.bound.object = NULL_TAG;
	trim_object.trim_to.one_bound.trim_bound = FALSE;

	if (UF_CURVE_create_trim(&trim_object, &out_trim_info, &trim_curve_feat) == UF_CURVE_TRIM_MULT_PTS)
	{
		trim_object.trim_to.one_bound.bound.use_suggested = TRUE;
		trim_object.trim_to.one_bound.bound.suggested_point[0] = out_trim_info.bound1_pts[0];
		trim_object.trim_to.one_bound.bound.suggested_point[1] = out_trim_info.bound1_pts[1];
		trim_object.trim_to.one_bound.bound.suggested_point[2] = out_trim_info.bound1_pts[2];
		if (out_trim_info.bound1_pts) UF_free(out_trim_info.bound1_pts);
		if (out_trim_info.bound2_pts) UF_free(out_trim_info.bound2_pts);
		if (UF_CALL(UF_CURVE_create_trim(&trim_object, &out_trim_info, &trim_curve_feat)))
		{
			trim_curve_feat = NULL_TAG;
		}
	}

	if (trim_curve_feat != NULL_TAG)
	{
		int n_eids=0; tag_t* eids;

		UF_MODL_ask_feat_object(trim_curve_feat, &n_eids, &eids); 
		if (n_eids>0)
		{
			for (int i = 0; i < n_eids; i++)
			{
				if (eids[i] != NULL_TAG)
				{
					uf_list_p_t body_list;
					UF_MODL_create_list(&body_list);
					UF_MODL_put_list_item(body_list, eids[i]);
					UF_MODL_delete_object_parms(body_list);
					UF_MODL_delete_list(&body_list);
				}
			}
			tag_t newcurve=eids[0];
			UF_free(eids);
			UF_OBJ_delete_object(original_line);
			return newcurve;
		}
	}
	return NULL_TAG;
}
//自动判断裁剪头还是尾,第一个参数必须是被裁剪的  
tag_t trim_curves_new(tag_t original_line,tag_t bound_line)
{
	double point[3]={0,0,0};
	double center_point[3]={0,0,0};
	UF_CURVE_trim_t trim_info; 
	UF_CURVE_trim_mult_t out_info;
	tag_t trim_feature=NULL_TAG; 
	UF_STRING_t  string_list1,string_list2;
	UF_MODL_init_string_list(&string_list1);
	UF_MODL_init_string_list(&string_list2);
	UF_MODL_create_string_list(1,1,&string_list1);
	UF_MODL_create_string_list(1,1,&string_list2);
	int resp=get_intersect_point_new(original_line,bound_line);
	string_list1.dir[0]=UF_MODL_CURVE_START_FROM_BEGIN ;
	string_list1.id[0]=original_line;
	string_list1.num=1;
	string_list1.string[0]=1;
	string_list2.dir[0]=UF_MODL_CURVE_START_FROM_BEGIN ;
	string_list2.id[0]=bound_line;
	string_list2.num=1;
	string_list2.string[0]=1;
	double start_pt1[3],start_pt2[3],end_pt1[3],end_pt2[3] ; 
	double tangent [ 3 ] ; 
	double p_norm [ 3 ] ;
	double b_norm [ 3 ] ; 
	double  torsion; 
	double rad_of_cur; 
	double distance11=0,distance12=0,distance21=0,distance22=0;
	UF_MODL_ask_curve_props(original_line, 0, start_pt1  ,  tangent  , p_norm  ,  b_norm  ,  &torsion,  &rad_of_cur );
	UF_MODL_ask_curve_props(original_line, 1, end_pt1  ,  tangent  , p_norm  ,  b_norm  ,  &torsion,  &rad_of_cur );
	UF_MODL_ask_curve_props(bound_line, 0, start_pt2  ,  tangent  , p_norm  ,  b_norm  ,  &torsion,  &rad_of_cur );
	UF_MODL_ask_curve_props(bound_line, 1, end_pt2  ,  tangent  , p_norm  ,  b_norm  ,  &torsion,  &rad_of_cur );
	UF_VEC3_distance(start_pt1,intersect_point,&distance11);
	UF_VEC3_distance(end_pt1,intersect_point,&distance12);
	UF_VEC3_distance(start_pt2,intersect_point,&distance21);
	UF_VEC3_distance(end_pt2,intersect_point,&distance22);
	if (distance11 < distance12)
	{
		string_list1.dir[0] = UF_MODL_CURVE_START_FROM_BEGIN;
		trim_info.trim_to.one_bound.string_trim_extend_end = UF_CURVE_TRIM_EXTEND_START;
	}
	else
	{
		string_list1.dir[0] = UF_MODL_CURVE_START_FROM_END;
		trim_info.trim_to.one_bound.string_trim_extend_end = UF_CURVE_TRIM_EXTEND_END;
	}
	if(distance21<distance22)
		string_list2.dir[0]=UF_MODL_CURVE_START_FROM_BEGIN ;
	else 
		string_list2.dir[0]=UF_MODL_CURVE_START_FROM_END ;
	//修剪注意:短的为第一条线,即为欲延伸的线,长的为第二条
	if(resp>0)
		trim_info.spline_extend_opt=UF_CURVE_EXTEND_NONE;//此选项可以自动延伸 spline误导人以为只能是SPLINE类型
	//有交点的可以设置为NONE,否则为NATURAL
	else 
		trim_info.spline_extend_opt= UF_CURVE_EXTEND_NATURAL;//UF_CURVE_EXTEND_NATURAL;
	trim_info.string_to_trim=string_list1;
	trim_info.tolerances[0]=0.2;//3
	trim_info.tolerances[1]=0.2;
	trim_info.trim_to.one_bound.bound.object=bound_line;
	trim_info.trim_to.one_bound.bound.string=string_list2;
	UF_VEC3_copy(intersect_point,trim_info.trim_to.one_bound.bound.suggested_point);
	trim_info.trim_to.one_bound.bound.use_suggested=true;
	//trim_info.trim_to.one_bound.string_trim_extend_end=UF_CURVE_TRIM_EXTEND_START;
	trim_info.trim_to.one_bound.trim_bound=true;

	UF_MODL_vector_t  vector_option;

	vector_option.vector_type=UF_MODL_VECTOR_DIRECTION;  //可以成功修剪
	vector_option.reverse_vector=0;
	vector_option.defined_by.direction.xyz[0]=0;
	vector_option.defined_by.direction.xyz[1]=0;
	vector_option.defined_by.direction.xyz[2]=1;
	trim_info.trim_to.one_bound.view=&vector_option;
	trim_info.trim_to.one_bound.trim_bound=true;
	trim_info.trim_type=UF_CURVE_TRIM_TO_ONE_BOUND;//5
	UF_CALL(UF_CURVE_create_trim(&trim_info, &out_info, &trim_feature ));
	if(trim_feature!=NULL_TAG){
		int num=0;
		tag_p_t list;
		UF_CURVE_ask_feature_curves(trim_feature,&num,&list);
		for(int i=0;i<num;i++){
			UF_OBJ_set_color(list[i],186);
			remove_parameters_for_one(list[i]);
		}
		UF_OBJ_delete_object(original_line);
		UF_OBJ_delete_object(bound_line);
	}
	UF_MODL_free_string_list(&string_list1);
	UF_MODL_free_string_list(&string_list2);
	return trim_feature;
}

  • 11
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

社恐猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值