BambuStudio/libslic3r/Fill/FillTest.cpp.back

3463 lines
116 KiB
Plaintext
Raw Normal View History

#ifndef AQ_CREAT_CURVES_ALONG_BODY_H_INCLUDED
#define AQ_CREAT_CURVES_ALONG_BODY_H_INCLUDED
#include <uf_defs.h>
#include <uf_ui_types.h>
#include <iostream>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/BlockStyler_UIBlock.hxx>
#include <NXOpen/BlockStyler_BlockDialog.hxx>
#include <NXOpen/BlockStyler_PropertyList.hxx>
#include <NXOpen/BlockStyler_Group.hxx>
#include <NXOpen/BlockStyler_BodyCollector.hxx>
#include <NXOpen/BlockStyler_ExpressionBlock.hxx>
#include<uf.h>
#include<uf_ui.h>
#include<vector>
#include<list>
#include<stack>
#include<map>
#include<math.h>
#include<uf_curve.h>
#include<uf_modl.h>
#include< uf_modl_curves.h >
#include<uf_modl_utilities.h>
#include<uf_modl_form_features.h>
#include<uf_obj.h>
#include< uf_trns.h >
#include<uf_disp.h>
#include <uf_csys.h>
#include <uf_defs.h>
#include <uf_mtx.h>
#define EntityType_AllowBodies (1 << 6);
#define BodyRules_SingleBody (1 << 0);
#define BodyRules_FeatureBodies (1 << 1);
#define BodyRules_BodiesinGroup (1 << 2);
using namespace std;
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
struct infor_inter_curves_s{
list<tag_t> curves;
list< list<tag_t>::iterator > sign_curves;
};
/*定义一个结构体,储存与曲线相关的数据结构
curves存tag_t类型标识符tag_t为唯一标识曲线对象的类型这个列表可能用于表示一组相关的曲线
sign_curves这是一个嵌套的list元素是curves list中元素的迭代器类//型,这个嵌套列表用于标记或记录 curves 列表中某些特定曲线的位置或//状态信息
*/
typedef struct infor_inter_curves_s infor_inter_curves_t;
struct point_two_curve_s{
tag_t point_TAG;
tag_t curve_TAG[2];
};
/*
定义了两个数据结构一个是类型别名infor_inter_curves_t另一个是结构体point_two_curve_s。infor_inter_curves_t 的类型别名,它等价于结构体类型 infor_inter_curves_s
point_TAG这是一个 tag_t 类型的成员变量用于存储一个点的标识符。同样tag_t 通常是在特定编程环境中用于唯一标识点对象的类型
curve_TAG[2]:这是一个包含两个 tag_t 类型元素的数组,用于存储两条曲线的标识符。这个结构体可能用于表示一个点与两条特定曲线之间的关系,例如该点是两条曲线的交点,或者该点在两条曲线的某种特定几何关系中具有重要意义。
*/
typedef struct point_two_curve_s point_two_curve_t;
struct curve_inter_points_s{
tag_t curve_TAG;
list<tag_t> points_TAG;
};
typedef struct curve_inter_points_s curve_inter_points_t;
struct point_four_curve_s{
tag_t point_TAG;
int num_of_curve;
tag_t curve_TAG[4];
};
typedef struct point_four_curve_s point_four_curve_t;
class DllExport AQ_creat_curves_along_body
{
// class members
public:
static Session *theSession;
static UI *theUI;
AQ_creat_curves_along_body();
int Show();
void initialize_cb();
void dialogShown_cb();
int apply_cb();
int ok_cb();
int update_cb(NXOpen::BlockStyler::UIBlock* block);
PropertyList* GetBlockProperties(const char *blockID);
//主函数
int AQ_main();
//切片部分
//创建平面
int creat_Zplanes_along_body ( tag_t body_TAG, double height_layer, vector<tag_t> &planes_TAG );
void creat_plane_along_Zcoor( double Z_coor, tag_t *plane_tag );
//得到交线
int creat_inter_curves
( tag_t body_TAG, vector<tag_t> &planes_TAG, vector< list< list< tag_t > > > & store_inter_curves );
int ask_inter_curves_along_body_plane
( tag_t body_TAG, tag_t plane_TAG, list< tag_t > & curves_TAG );
//切片交线孔位位置拓扑重构
//交线提环
int edit_infor_inter_curves( vector< list< list< tag_t > > > & store_inter_curves );
//生成截面中间过渡曲线
int creat_edge_closing_curves
( vector< list< list< tag_t > > > & store_inter_curves,
vector< list< list< tag_t > * > > & store_inter_curves_pt,
double offset_distance,
int offset_num,
list< list< tag_t > > & Sum_closing_curves_store_list,
vector< multimap< list< tag_t >*, list< tag_t >* > > & Sum_closing_curves_store );
int creat_mid_closing_curves
( list< list< tag_t > * > & layer_closing_curves,
double offset_distance,
list< list< tag_t > > & Sum_closing_curves_store_list,
multimap< list< tag_t >*, list< tag_t >* > & closing_curves_store
);
//异常删除
int delete_all_closing_curves
( list< list< tag_t > > & Sum_closing_curves_store_list );
//小面积方向偏置
int creat_offset_curve_small
( list<tag_t> &input_curves, double distance,
vector< list< list< tag_t > > > &store_inter_curves );
//大面积偏置
int creat_offset_curve_big
( list<tag_t> &input_curves, double offset_distance, list<tag_t> &output_curves );
//处理孔洞它交环
int ask_useful_curves_along_other(
list<tag_t> & closing_curves1, //输入tag
list<tag_t> & closing_curves2,
list< list< tag_t > > &store_inter_curves );
//相交求并环处理
int edit_insert_curves
( list<tag_t> & closing_curves1, list<tag_t> & closing_curves2 , list<tag_t> & output_curves );
//孔位相对位置判断函数
int ask_position_along_two_curves
( list<tag_t> & closing_curves1, list<tag_t> & closing_curves2 );
int ask_right_curves( tag_t curve_TAG, list<tag_t> *output_curves_list );
int is_curve_open( tag_t curve_TAG );
//辅助小函数
//多态求面积函数
double ask_area_along_closing_curves( list<tag_t> &input_curves );
//拐角处理
void edit_curves_inter
( list< list< tag_t > > & Sum_closing_curves_store_list,
double degree, double cute_length );
tag_t edit_curves_inter
( tag_t curve1, tag_t curve2, double degree, double cute_length );
//裁剪连接
//处理层层之间路径
int edit_layer_curves_creat_bridges
( double R, double L, //第一层的起始过度圆环半径,及外连直线
double ref_start_point[3], double ref_end_point[3],
vector< list< tag_t >* > & layer_first_curves_store, double cute_distance );
double is_curves_have_off_part
( tag_t curve1, tag_t curve2, double offset );
int ask_two_ref_points
( double ref_start_point[3], double ref_end_point[3],
list< tag_t > & curves,
tag_t * ref_curveTAG1, tag_t * ref_curveTAG2,
double out_start_point[3], double out_end_point[3] );
//深度优先搜索,进行根部倒置处理层间路径环
int edit_closing_curves_creat_bridges
( multimap< list< tag_t >*, list< tag_t >* >::iterator & father_it,
multimap< list< tag_t >*, list< tag_t >* > & closing_curves_store, double cute_distance );
//编辑连接
int edit_curves_creat_bridge
( list< tag_t > & curves1, list< tag_t > & curves2, double cute_distance );
//点线最短距离
double ask_min_dist_pt_curve
( double point[3], tag_t curve_TAG, double min_dist_point[3] );
//桥接相切曲线
int create_bridge_curve_along_two_curves_points
( int bridge_method, tag_t curve_ids [2] ,double parms [ 2 ] , tag_t * bridge_id );
int creat_tangent_line_along_curve
(double startpoint[3], tag_t curve_TAG, double length, tag_t *line_TAG);
//剪切曲线
int edit_cute_curve_along_point_length
( tag_t curve_TAG, double point[3], double length, tag_t *another_curve_TAG );
//复制对象
int copy_obj(tag_t obj, tag_t *copyed_obj);
//线上点和参数相互转换
int ask_curve_point_along_parm( tag_t curve_id, double parm, double outputpoint [3] );
int ask_curve_parm_along_point( tag_t curve_id, double point [ 3 ] , double * parm);
//曲线相交
int intersect_curve_along_curve
(tag_t curve1_TAG, tag_t curve2_TAG, vector<tag_t > *points_TAG );
//起点判断
int is_start_point_along_curve
( double*start_point, tag_t curve, double modeling_tolerance, double parameter_tolerance );
//两点距离
double point_distance( double *p1,double *p2 );
//求线终点
void ask_endpoint_along_curve
( double* Start_point, tag_t curve, double * output_endpoint );
//参考缩放操作
void scale_opition( tag_t solid, double* refpoint, double *param );
//路径显示
void path_display
(vecter<tag_t> curves, int colour, int type_curve, int wide_curve);
private:
const char* theDlxFileName;
NXOpen::BlockStyler::BlockDialog* theDialog;
NXOpen::BlockStyler::Group* group0;// Block type: Group
NXOpen::BlockStyler::BodyCollector* bodySelect0;// Block type: Body Collector
NXOpen::BlockStyler::Group* group;// Block type: Group
NXOpen::BlockStyler::ExpressionBlock* expression0;// Block type: Expression
NXOpen::BlockStyler::ExpressionBlock* expression1;// Block type: Expression
};
#endif //AQ_CREAT_CURVES_ALONG_BODY_H_INCLUDED
//预处理文件,#ifndef与#endif中为一次编译代码其他.cpp避免二次编译
#include "AQ_creat_curves_along_body.hpp"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
Session *(AQ_creat_curves_along_body::theSession) = NULL;
UI *(AQ_creat_curves_along_body::theUI) = NULL;
AQ_creat_curves_along_body::AQ_creat_curves_along_body()
{
try
{
// Initialize the NX Open C++ API environment
AQ_creat_curves_along_body::theSession = NXOpen::Session::GetSession();
AQ_creat_curves_along_body::theUI = UI::GetUI();
theDlxFileName = "AQ_creat_curves_along_body.dlx";
theDialog = AQ_creat_curves_along_body::theUI->CreateDialog(theDlxFileName);
// Registration of callback functions
theDialog->AddApplyHandler(make_callback(this, &AQ_creat_curves_along_body::apply_cb));
theDialog->AddOkHandler(make_callback(this, &AQ_creat_curves_along_body::ok_cb));
theDialog->AddUpdateHandler(make_callback(this, &AQ_creat_curves_along_body::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &AQ_creat_curves_along_body::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &AQ_creat_curves_along_body::dialogShown_cb));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
throw;
}
}
//初始化AQ_creat_curves_along_body类的实例获取会话session和ui对象。
AQ_creat_curves_along_body::~AQ_creat_curves_along_body()
{
if (theDialog != NULL)
{
delete theDialog;
theDialog = NULL;
}
}
//释放生命周期结束后的内存、对话框等资源
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{
AQ_creat_curves_along_body *theAQ_creat_curves_along_body = NULL;
try
{
theAQ_creat_curves_along_body = new AQ_creat_curves_along_body();
// The following method shows the dialog immediately
theAQ_creat_curves_along_body->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
if(theAQ_creat_curves_along_body != NULL)
{
delete theAQ_creat_curves_along_body;
theAQ_creat_curves_along_body = NULL;
}
}
//这个函数的目的是创建一个AQ_creat_curves_along_body类的对象显示相关界面或执行初始化操作如果出现问题则捕获并显示错误信息最后在函数结束时正确清理对象资源。它可能是一个与特定应用程序可能是与 NX 软件相关的二次开发)中创建沿体曲线功能相关的入口点函数,用于与外部环境进行交互并启动相应的操作流程。
extern "C" DllExport int ufusr_ask_unload()
{
//return (int)Session::LibraryUnloadOptionExplicitly;
return (int)Session::LibraryUnloadOptionImmediately;
//return (int)Session::LibraryUnloadOptionAtTermination;
}
extern "C" DllExport void ufusr_cleanup(void)
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
int AQ_creat_curves_along_body::Show()
{
try
{
theDialog->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//显示一个对话框,如果出现问题会出现一个对话框,向用户返回问题
void AQ_creat_curves_along_body::initialize_cb()
{
try
{
group0 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group0"));
bodySelect0 = dynamic_cast<NXOpen::BlockStyler::BodyCollector*>(theDialog->TopBlock()->FindBlock("bodySelect0"));
group = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group"));
expression0 = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("expression0"));
expression1 = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("expression1"));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
void AQ_creat_curves_along_body::dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//是一个对话框显示事件函数
int AQ_creat_curves_along_body::apply_cb()
{
int errorCode = 0;
try
{
AQ_main();//用于执行与创建沿体曲线相关的主要逻辑
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
int AQ_creat_curves_along_body::update_cb(NXOpen::BlockStyler::UIBlock* block)//通过一系列if-else if语句来判断触发更新事件的 UI 元素是哪一个
{
try
{
if(block == bodySelect0)
{
//---------Enter your code here-----------
}
else if(block == expression0)
{
//---------Enter your code here-----------
}
else if(block == expression1)
{
//---------Enter your code here-----------
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
int AQ_creat_curves_along_body::ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();//点击确定按钮执行该函数
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
AQ_creat_curves_along_body::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
PropertyList* AQ_creat_curves_along_body::GetBlockProperties(const char *blockID)
{
return theDialog->GetBlockProperties(blockID);
}
//主函数
int AQ_creat_curves_along_body::AQ_main(){
UF_initialize();
//获取体的tag信息进行必要的错误信息过滤
vector<TaggedObject *>body = bodySelect0->GetSelectedObjects();
if( body.size() > 1 ){//多体,错误过滤
uc1601( "请您选择单个体" , 1);
return 0;
}
//获取参数值
tag_t body_TAG = body[0] -> Tag();
double height_layer = expression0 ->Value();//层高
double offset_distance = expression1 ->Value();//偏移距离
vector<tag_t> planes_TAG;
//创建截平面
int sign_creat_Zplanes = creat_Zplanes_along_body ( body_TAG, height_layer, planes_TAG );
//获取截面曲线信息
vector< list< list< tag_t > > > store_inter_curves;
creat_inter_curves( body_TAG, planes_TAG, store_inter_curves );
//将截面信息进行提环,处理环之间的位置关系
int sign_edit_infor = edit_infor_inter_curves
( store_inter_curves );
//建立多重映射(红黑树实现)+ 链表储存对象
vector< list< list< tag_t > * > > store_inter_curves_pt;
vector< multimap< list< tag_t >*, list< tag_t >* > >
Sum_closing_curves_store;
Sum_closing_curves_store.resize( store_inter_curves.size() );
list< list< tag_t > > Sum_closing_curves_store_list;
list< tag_t > NULL_list;
Sum_closing_curves_store_list.push_back( NULL_list );
//生成边缘层曲线,并给与信息,是否可产生偏置
int offset_num = 3;//控制孔位偏置环数
int sign_creat_edge = creat_edge_closing_curves
( store_inter_curves,
store_inter_curves_pt,
offset_distance,
offset_num,
Sum_closing_curves_store_list,
Sum_closing_curves_store
);
//进行中间层,路径环得生成
for ( int i = 0; i < Sum_closing_curves_store.size() ; i ++ ){
creat_mid_closing_curves
( store_inter_curves_pt[i],
offset_distance,
Sum_closing_curves_store_list,
Sum_closing_curves_store[i] );
}
//拐角处理
edit_curves_inter
( Sum_closing_curves_store_list, 90, offset_distance / 2 );
//处理链表中有无完整环线,如果有进行处理
for( list< list< tag_t > >::iterator
temp_it = Sum_closing_curves_store_list.begin();
temp_it!= Sum_closing_curves_store_list.end(); temp_it ++ ){
if( ( * temp_it ).size() != 1 )
continue;
tag_t another_curve_TAG;
double mid_point[3];
ask_curve_point_along_parm( *( ( * temp_it ).begin() ), 0.5, mid_point );
edit_cute_curve_along_point_length
( *( ( * temp_it ).begin() ), mid_point, 0, &another_curve_TAG );
( * temp_it ).push_back( another_curve_TAG );
}
//return 1;
//层间环间剪切连接
vector< list< tag_t >* > layer_first_curves_store( Sum_closing_curves_store.size() );
for (int i = 0; i < Sum_closing_curves_store.size(); i++){
multimap< list< tag_t >*, list< tag_t >* >::iterator
first_father_it = Sum_closing_curves_store[i].lower_bound
( & ( * ( Sum_closing_curves_store_list.begin() ) ) );
layer_first_curves_store[i] = ( * first_father_it ).second;
}
double ref_start_point [3] = { 0, 0, 0 };
double ref_end_point [3] = { 1, 0, 0 };
edit_layer_curves_creat_bridges
( 5, 5, //第一层的起始过度圆环半径,及外连直线
ref_start_point, ref_end_point,
layer_first_curves_store, height_layer * 2.5 );
//层内环间剪切连接
//深度优先搜索,进行根部倒置处理层间路径环
//UF_UI_open_listing_window();
for ( int i = 0; i < Sum_closing_curves_store.size(); i++ ){
multimap< list< tag_t >*, list< tag_t >* >::iterator
first_father_it = Sum_closing_curves_store[i].lower_bound
( & ( * ( Sum_closing_curves_store_list.begin() ) ) );
//进行编辑
edit_closing_curves_creat_bridges
( first_father_it,
Sum_closing_curves_store[i], offset_distance );
}
uc1601( "1", 1 );
UF_terminate();
return 1;
}
//切片部分
//创建平面
int AQ_creat_curves_along_body::creat_Zplanes_along_body
( tag_t body_TAG, double height_layer, vector<tag_t> &planes_TAG ){
int num;
//获取体的最大最小Z向坐标值
double bounding_box [ 6 ];
UF_MODL_ask_bounding_box( body_TAG, bounding_box);
double Z_min = bounding_box[2];
double Z_max = bounding_box[5];
//创建多个截面,Z坐标
num = ( Z_max - Z_min )/height_layer;
height_layer = ( Z_max - Z_min )/num;
//创建截平面
double origin_point [3] ={0, 0, 0};
double plane_normal [3] ={0, 0, 1};
planes_TAG.resize( num );
for (int i = 0; i < num; i++){
origin_point[2] = ( i * height_layer + Z_min ) + height_layer/2 ;
UF_MODL_create_plane ( origin_point, plane_normal, &( planes_TAG[i] ) );
}
return num;
}
void AQ_creat_curves_along_body::creat_plane_along_Zcoor(double Z_coor, tag_t *plane_tag){
double origin_point [3] ={0, 0, Z_coor};
double plane_normal [3] ={0, 0, 1};
int sign_plane = UF_MODL_create_plane
(origin_point, plane_normal, plane_tag );
}
//得到交线
int AQ_creat_curves_along_body::creat_inter_curves
( tag_t body_TAG, vector<tag_t> &planes_TAG, vector< list< list< tag_t > > > & store_inter_curves ){
//获取公差
double tol = 0.001;
UF_MODL_ask_distance_tolerance(&tol);
int num_inter_curves;
store_inter_curves.resize( planes_TAG.size() );
list< tag_t > temp_curves_store;
//获取截面曲线TAG值信息
for (int i = 0; i < planes_TAG.size(); i++){
//相交
UF_MODL_intersect_info_p_t *intersect_data;
UF_MODL_intersect_objects( body_TAG, planes_TAG[i], tol, &num_inter_curves, &intersect_data );
store_inter_curves[i].push_back( temp_curves_store );
//数据转移
for (int j = 0; j < num_inter_curves; j++){
( *( store_inter_curves[i].begin() ) ).
push_back( intersect_data[j]->intersect.curve.identifier );
UF_free( intersect_data[j] );
}//endfor
//删除截面
UF_OBJ_delete_object( planes_TAG[i] );
//清除内存
if (num_inter_curves != 0){
UF_free( intersect_data );
}
}//end for(int i = 0; i < planes_TAG.size(); i++)
return 1;
}
int AQ_creat_curves_along_body::ask_inter_curves_along_body_plane
(tag_t body_TAG, tag_t plane_TAG, list< tag_t > &curves_TAG ){
double tol = 0.001;
UF_MODL_ask_distance_tolerance( &tol );
int num_inter_curves;
UF_MODL_intersect_info_p_t *intersect_data;
UF_MODL_intersect_objects(body_TAG, plane_TAG, tol, &num_inter_curves, &intersect_data);
curves_TAG.clear();
for (int i = 0; i < num_inter_curves; i++){
curves_TAG.push_back( intersect_data[i]->intersect.curve.identifier );
}//endfor
if (num_inter_curves != 0){
UF_free(intersect_data);
}
return num_inter_curves;
}
//交线提环
int AQ_creat_curves_along_body::edit_infor_inter_curves
( vector< list< list< tag_t > > > & store_inter_curves ){
//store_inter_curves的数量已定
list< tag_t > temp_closing_curves;//储存每一层的线的总线tag
list< list<tag_t> > temp_curves_store;//储存每一层的封闭环的线的TAGs
list< tag_t > temp_curves;//单环线临时储存
for ( int i = 0; i < store_inter_curves.size(); i++ ){//处理动态数组中的每一项(每一层线)
//截取数据
temp_closing_curves.clear();//清理
temp_curves_store.clear();
temp_curves.clear();
temp_closing_curves.insert( temp_closing_curves.end(),//插入数据
( * ( store_inter_curves[i].begin() ) ).begin(),
( * ( store_inter_curves[i].begin() ) ).end() );
//进行环的提取
double temp_start_point[3] = { 0, 0, 0 };
int number = temp_closing_curves.size();
list< tag_t >::iterator temp_it;
int sign_start_point_along_curve = 0;
ask_endpoint_along_curve( temp_start_point, *( temp_closing_curves.begin() ), temp_start_point );
while( !( temp_closing_curves.empty() ) ){//整体每条线段循环
sign_start_point_along_curve = 0;
for ( temp_it = temp_closing_curves.begin();
temp_it != temp_closing_curves.end(); temp_it ++){//起点找线
if( is_start_point_along_curve
( temp_start_point, *temp_it, 0.005, 0.05) == 1 ){//找到线
sign_start_point_along_curve = 1;
break;
}
}
if( sign_start_point_along_curve == 1 ){//找到线
temp_curves.push_back( *temp_it );
//处理起点
ask_endpoint_along_curve( temp_start_point, *temp_it, temp_start_point );
//删除temp_closing_curves列表中的TAG
list< tag_t >::iterator temp_it2 = temp_it;
temp_it2 ++;
temp_closing_curves.erase( temp_it, temp_it2 );
}//end if
else{//没有找到线
//将线置入temp_curves_store总储存中清理
temp_curves_store.push_back( temp_curves );
temp_curves.clear();
//处理起点
ask_endpoint_along_curve( temp_start_point, *( temp_closing_curves.begin() ), temp_start_point );
}//end else
}//end while
temp_curves_store.push_back( temp_curves );
temp_curves.clear();
//进行大环提取,辅助存储
list< list<tag_t> >::iterator real_curves_store_it;
double real_area = 0;
//寻找面积最大环的迭代器
for( list< list<tag_t> >::iterator temp_curves_store_it = temp_curves_store.begin();
temp_curves_store_it != temp_curves_store.end(); temp_curves_store_it ++ ){
//获取当前temp_curves_store_it对应的面积
double temp_area = ask_area_along_closing_curves( *temp_curves_store_it );
if( temp_area > real_area ){
real_area = temp_area;
real_curves_store_it = temp_curves_store_it;
}
}
//将最大面积环提前
temp_curves.clear();
temp_curves.insert( temp_curves.end(),//插入数据
( *real_curves_store_it ).begin(), ( *real_curves_store_it ).end() );
//删除temp_curves_store中对应的最大环
list< list<tag_t> >::iterator real_curves_store_it1 = real_curves_store_it;
real_curves_store_it1 ++;
temp_curves_store.erase( real_curves_store_it, real_curves_store_it1 );
//插入最前端环
temp_curves_store.push_front( temp_curves );
temp_curves.clear();
//将数据储存到store_inter_curves[i]中,list< list<tag_t> > temp_curves_store
store_inter_curves[i].pop_front();
for( list< list<tag_t> >::iterator temp_curves_store_it = temp_curves_store.begin();
temp_curves_store_it != temp_curves_store.end(); temp_curves_store_it ++ ){
store_inter_curves[i].push_back( * temp_curves_store_it );
}
}//end for 层
return 1;
}//end function
int AQ_creat_curves_along_body::creat_edge_closing_curves
( vector< list< list< tag_t > > > & store_inter_curves,
vector< list< list< tag_t > * > > & store_inter_curves_pt,
double offset_distance,
int offset_num,
list< list< tag_t > > & Sum_closing_curves_store_list,
vector< multimap< list< tag_t >*, list< tag_t >* > > &
Sum_closing_curves_store ){
//定义异常检索值
int sign_result = 0;
vector< list< list< tag_t > > > temp_store_inter_curves;
store_inter_curves_pt.resize( store_inter_curves.size() );
for ( int i = 0; i < store_inter_curves.size(); i++ ){
temp_store_inter_curves.clear();
int sign_creat_offset_curve_small = creat_offset_curve_small
( * ( store_inter_curves[i].begin() ), offset_distance / 2, temp_store_inter_curves );
if ( temp_store_inter_curves[0].size() != 1 ){
if( temp_store_inter_curves[0].size() == 0 ){
sign_result = 1;
}
if( temp_store_inter_curves[0].size() > 1 ){
sign_result = 2;
delete_all_closing_curves ( temp_store_inter_curves[0] );
}
break;
}
//储存数据
Sum_closing_curves_store_list.push_back( * ( temp_store_inter_curves[0].begin() ) );
//储存指针对
list< list< tag_t > >::iterator temp_beg =
Sum_closing_curves_store_list.begin();
list< list< tag_t > >::iterator temp_end =
Sum_closing_curves_store_list.end(); temp_end --;
Sum_closing_curves_store[i].insert(
pair< list< tag_t >*, list< tag_t >* >(
& ( * temp_beg ), & ( * temp_end )
)
);
store_inter_curves_pt[i].push_back( & ( * temp_end ) );
}
//排除异常
if( sign_result != 0 ){
delete_all_closing_curves ( Sum_closing_curves_store_list );
return -1;
}
//处理有用层,删除,换线
for ( int i = 0; i < store_inter_curves.size(); i++ ){
for( list< tag_t >::iterator temp_it = ( * ( store_inter_curves[i].begin() ) ).begin();
temp_it != ( * ( store_inter_curves[i].begin() ) ).end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
store_inter_curves[i].pop_front();
multimap< list< tag_t >*, list< tag_t >* >::iterator temp_it_mul;
temp_it_mul =
( Sum_closing_curves_store[i] ).
lower_bound( & ( * ( Sum_closing_curves_store_list.begin() ) ) );
store_inter_curves[i].push_front( *( ( * temp_it_mul ).second ) );
}
//下面进行内环的偏置
//首先将内环想大方向偏置 4.5*offset 距离
list< list< tag_t > > temp_sum_hole_store;
list< list< tag_t > > temp_sum_hole_big_store;
list< tag_t > temp_output_curves;
list< list< tag_t > >::iterator temp_it1;
list< list< tag_t > >::iterator temp_it2;
for ( int i = 0; i < store_inter_curves.size(); i++ ){
//提取当前层的孔位
temp_sum_hole_store.clear();
temp_it1 = store_inter_curves[i].begin();
temp_it1 ++;
temp_it2 = store_inter_curves[i].end();
if( temp_it1 != temp_it2 ){
temp_sum_hole_store.insert( temp_sum_hole_store.end(), temp_it1, temp_it2 );
}
temp_sum_hole_big_store.clear();
//处理临时大孔位
for( temp_it1 = temp_sum_hole_store.begin();
temp_it1 != temp_sum_hole_store.end(); temp_it1 ++ ){
//偏置线
temp_output_curves.clear();
creat_offset_curve_big//12.18
( * temp_it1, offset_distance * ( 0.5 + (double)offset_num ), temp_output_curves );
temp_sum_hole_big_store.push_back( temp_output_curves ) ;
//删除内环
for( list< tag_t >::iterator temp_it = ( * temp_it1 ).begin();
temp_it != ( * temp_it1 ).end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
}
//判断大孔位与最大轮廓的位置关系,进行异常剔除
int sign_pos_relship_holes = 1;
int temp_sign = 0;
temp_it2 = store_inter_curves[i].begin();
for( temp_it1 = temp_sum_hole_big_store.begin();
temp_it1 != temp_sum_hole_big_store.end(); temp_it1 ++ ){
temp_sign = ask_position_along_two_curves ( * temp_it2, * temp_it1 );
if ( temp_sign != 4 ){//环大了
sign_pos_relship_holes = 0;
break;
}
}
//异常剔除
if( sign_pos_relship_holes == 0 ){
delete_all_closing_curves ( Sum_closing_curves_store_list );
delete_all_closing_curves ( temp_sum_hole_big_store );
sign_result = 3;
break;
}
//进行大孔位的位置处理,并进行新的大环位生成
for( temp_it1 = temp_sum_hole_big_store.begin();
temp_it1 != -- ( temp_sum_hole_big_store.end() ); temp_it1 ++ ){
temp_it2 = temp_it1;
temp_it2 ++;
if( ( * temp_it1 ).size() == 0 ){
continue;
}
for( ;temp_it2 != temp_sum_hole_big_store.end(); temp_it2 ++ ){
//空环继续
if( ( * temp_it2 ).size() == 0 ){
continue;
}
//无交环继续
int sign_position = ask_position_along_two_curves ( * temp_it1, * temp_it2 );
if( sign_position != 1 && sign_position != 2 ){//没有相交或者外离
continue;
}
//处理有交环
list< tag_t > temp_output_curves;
edit_insert_curves
( * temp_it1, * temp_it2, temp_output_curves );
temp_sum_hole_big_store.push_back( temp_output_curves );
}
}
//进行大环位的储存+大环位在指针中的储存
//进行输入的处理
temp_it1 = store_inter_curves[i].begin();
temp_it1 ++;
store_inter_curves[i].erase( temp_it1, store_inter_curves[i].end() );
vector< list< list< tag_t > * > > big_hole_ref_store( offset_num + 1 );
for( temp_it1 = temp_sum_hole_big_store.begin();
temp_it1 != temp_sum_hole_big_store.end(); temp_it1 ++ ){
if( ( * temp_it1 ).size() != 0 ){
store_inter_curves[i].push_back( * temp_it1 );
Sum_closing_curves_store_list.push_back( * temp_it1 );
temp_it2 = Sum_closing_curves_store_list.end();
temp_it2 --;
list< tag_t > * temp_list_ref = & ( * temp_it2 );
Sum_closing_curves_store[i].
insert( pair< list< tag_t > *, list< tag_t > * > ( NULL, temp_list_ref ) );
store_inter_curves_pt[i].push_back( temp_list_ref );
big_hole_ref_store[0].push_back( temp_list_ref );
}
else{
temp_it2 = temp_it1;
temp_it2 ++;
temp_sum_hole_big_store.erase( temp_it1, temp_it2 );
}
}
//进行大环位的小方向偏置+储存
//vector< list< list< tag_t > * > > big_hole_ref_store(4);
vector< list< list< tag_t > > > temp_store_inter_curves;
list< list< tag_t > * >::iterator temp_it_1;
list< list< tag_t > * >::iterator temp_it_2;
for( int j = 0; j < offset_num ; j ++ ){
for( temp_it_1 = big_hole_ref_store[j].begin();
temp_it_1 != big_hole_ref_store[j].end() ; temp_it_1 ++ ){
temp_store_inter_curves.clear();
creat_offset_curve_small
( * ( * temp_it_1 ), offset_distance, temp_store_inter_curves );
for( temp_it1 = temp_store_inter_curves[0].begin();
temp_it1 != temp_store_inter_curves[0].end(); temp_it1 ++ ){
Sum_closing_curves_store_list.push_back( * temp_it1 );
temp_it2 = Sum_closing_curves_store_list.end();
temp_it2 --;
list< tag_t > * temp_list_ref = & ( * temp_it2 );
big_hole_ref_store[ j+1 ].push_back( temp_list_ref );
Sum_closing_curves_store[i].
insert(
pair< list< tag_t > *, list< tag_t > * >
( * temp_it_1, temp_list_ref )
);
}//循环偏置得到的小环进行储存处理
}//循环 j 对应的曲线环
}//end j < num_off 循环总小偏层数
}//i 循环每个大层i
return 1;
//return sign_result;
}
//得到中间截面
int AQ_creat_curves_along_body::creat_mid_closing_curves
( list< list< tag_t > * > & layer_closing_curves,
double offset_distance,
list< list< tag_t > > & closing_curves_store_list,
multimap< list< tag_t >*, list< tag_t >* > & closing_curves_store ){
vector< list< list< tag_t > > > temp_store_inter_curves;
//进行偏置
int sign_offset_curves = creat_offset_curve_small
( *( * ( layer_closing_curves.begin() ) ), offset_distance, temp_store_inter_curves );
if( sign_offset_curves == 0 ){//曲线无法偏置
return 0;
}
else{//曲线有可能生成多环
//将曲线进行提环2级主轮廓环数据转移mid_layer_closing_curves中
list< list< tag_t > > mid_layer_closing_curves;
list< list< tag_t > * > island_closing_curves;
list< list< tag_t > * > ::iterator temp_it = layer_closing_curves.begin();
temp_it ++;
for( ; temp_it != layer_closing_curves.end(); temp_it ++ ){
island_closing_curves.push_back( * temp_it ) ;
}
for( list< list< tag_t > > ::iterator temp_it = temp_store_inter_curves[0].begin();
temp_it != temp_store_inter_curves[0].end(); temp_it ++ ){
mid_layer_closing_curves.push_back( * temp_it ) ;
}
//进行它交有效环处理,利用孔位信息处理轮廓信息
//处理它交环
int sign_ask_position = -5;
list< list< tag_t > >::iterator temp_it_1;
list< list< tag_t > * >::iterator temp_it_2;
list< list< tag_t > * > temp_holes_pt;
for(
temp_it_1 = mid_layer_closing_curves.begin();
temp_it_1 != mid_layer_closing_curves.end(); temp_it_1 ++ ){
for(
temp_it_2 = island_closing_curves.begin();
temp_it_2 != island_closing_curves.end(); temp_it_2 ++ ){
//主线环为空
if( ( * temp_it_1 ).size() == 0 ){
break;
}
if( ( * temp_it_2 ) -> size() == 0 ){
continue;
}
sign_ask_position =
ask_position_along_two_curves ( * temp_it_1, * ( * temp_it_2 ) );
//无需操作4 内含、1 外切 0 相离
if( sign_ask_position == 4 || sign_ask_position == 1 || sign_ask_position == 0 ){
continue;
}
//进行它交环处理2 相交 3 内切
if( sign_ask_position == 2 || sign_ask_position == 3 ){
//交环处理
list< list< tag_t > > store_inter_curves_other;
ask_useful_curves_along_other(
* temp_it_1, *( * temp_it_2 ), store_inter_curves_other );
//清除环向
( * temp_it_1 ).clear();
( * temp_it_2 )->clear();
//放置新生成的环
for( list< list< tag_t > >::iterator temp_it = store_inter_curves_other.begin();
temp_it != store_inter_curves_other.end(); temp_it ++ ){
mid_layer_closing_curves.push_back( * temp_it );
}
//将用于生成新环的小环的指针储存下来
//找寻空环的儿子,并储存
multimap< list< tag_t >*, list< tag_t >* >::iterator lower_curves_pt_it;
for( lower_curves_pt_it = closing_curves_store.lower_bound( * temp_it_2 ) ;
lower_curves_pt_it != closing_curves_store.upper_bound( * temp_it_2 ) ;
lower_curves_pt_it ++ ){
temp_holes_pt.push_back( ( * lower_curves_pt_it ).second );
}
continue;
}
//进行环向删除:-4 curve2环面积大内含 、-3 curve2环面积大内切 、 -1 重合
if( sign_ask_position == -4 || sign_ask_position == -3 || sign_ask_position == -1 ){
//删除1环中曲线
list< tag_t >::iterator temp_it;
for( temp_it = ( * temp_it_1 ).begin();
temp_it != ( * temp_it_1 ).end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
//清除一种曲线,由于迭代器不好处理,最好先将环链表清除,以证明没有曲线
( * temp_it_1 ).clear();
//将2环中的曲线与主环的指针连接
closing_curves_store.insert
( pair< list< tag_t > * , list< tag_t > * >
( * ( layer_closing_curves.begin() ), * temp_it_2 ) );
continue;
}
//return -1;//异常抛出
}
}
//清除两链表中空的曲线
list< list< tag_t > >::iterator temp_it_2_;
for(
temp_it_1 = mid_layer_closing_curves.begin();
temp_it_1 != mid_layer_closing_curves.end(); temp_it_1 ++ ){
if( ( * temp_it_1 ).size() == 0 ){
temp_it_2_ = temp_it_1;
temp_it_2_ ++;
mid_layer_closing_curves.erase( temp_it_1, temp_it_2_ );
}
}
list< list< tag_t > * >::iterator temp_it_1_;
for(
temp_it_1_ = island_closing_curves.begin();
temp_it_1_ != island_closing_curves.end(); temp_it_1_ ++ ){
if( ( * temp_it_1_ ) -> size() == 0 ){
temp_it_2 = temp_it_1_;
temp_it_2 ++;
island_closing_curves.erase( temp_it_1_, temp_it_2 );
}
}
//将环向曲线进行分类
vector< list< list< tag_t > * > > temp_mid_layer_closing_curves
( mid_layer_closing_curves.size() );
int i = 0;
for(
temp_it_1 = mid_layer_closing_curves.begin();
temp_it_1 != mid_layer_closing_curves.end(); temp_it_1 ++ ){
//进行主环放置
closing_curves_store_list.push_back( * temp_it_1 );
temp_mid_layer_closing_curves[i].push_back
( &( * ( -- ( closing_curves_store_list.end() ) ) ) );
closing_curves_store.insert(
pair< list< tag_t > *, list< tag_t > * > (
* ( layer_closing_curves.begin() ),
&( * ( -- ( closing_curves_store_list.end() ) ) )
)
);
for(
temp_it_2 = island_closing_curves.begin();
temp_it_2 != island_closing_curves.end(); temp_it_2 ++ ){
if( ( * temp_it_2 )->size() == 0 ){
continue;
}
if( ask_position_along_two_curves ( * temp_it_1, *( * temp_it_2 ) ) != 4 ){
continue;
}
temp_mid_layer_closing_curves[i].push_back( * temp_it_2 );
}
i ++;
}
//将已经被处理过的它交环进行辅助找父环并进行储存指针对操作
//list< list< tag_t > * > temp_holes_pt
//vector< list< list< tag_t > * > > temp_mid_layer_closing_curves
//现在所有被处理过的环的子环储存在list< list< tag_t > * > temp_holes_pt中
//所有大环储存在temp_mid_layer_closing_curves的第一个指针中
//目的为以小孔为纲进行1.1offset_distance距离的大偏置
//找到与其相交的最大面积的环,然后储存指针对
//multimap< list< tag_t >*, list< tag_t >* > & closing_curves_store
for( list< list< tag_t > * >::iterator temp_it = temp_holes_pt.begin();
temp_it != temp_holes_pt.end(); temp_it ++ ){
//定义数据
double temp_max_area = 0;
list< tag_t > * temp_father_curves_pt = NULL;
list< tag_t > temp_big_hole;//1.1偏置
//进行偏置1.1 offset_distance
creat_offset_curve_big
( * ( * temp_it ) , 1.1 * offset_distance, temp_big_hole );
for( int i = 0; i < temp_mid_layer_closing_curves.size(); i ++ ){
int sign_position = ask_position_along_two_curves
( * ( *( temp_mid_layer_closing_curves[i].begin() ) ), temp_big_hole );
if( sign_position == 2 ){
double temp_area = ask_area_along_closing_curves
( * ( *( temp_mid_layer_closing_curves[i].begin() ) ) );
if( temp_max_area < temp_area ){
temp_max_area = temp_area;
temp_father_curves_pt = *( temp_mid_layer_closing_curves[i].begin() );
}
}
}
for( list< tag_t >::iterator temp_it = temp_big_hole.begin();
temp_it != temp_big_hole.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
closing_curves_store.insert
( pair< list< tag_t > *, list< tag_t > * > ( temp_father_curves_pt, * temp_it ) );
//char msg[64];
//UF_UI_open_listing_window();
//sprintf( msg, " < %d , %d > \n", temp_father_curves_pt, * temp_it );
//UF_UI_write_listing_window( msg );
//uc1601( "1", 1 );
}
//分好环的曲线环,进行递归操作
for (int i = 0; i < temp_mid_layer_closing_curves.size(); i++){
//启动循环,进行下一步偏置
creat_mid_closing_curves
( temp_mid_layer_closing_curves[i],
offset_distance,
closing_curves_store_list,
closing_curves_store );
}
}
return 1;
}
int AQ_creat_curves_along_body::delete_all_closing_curves
( list< list< tag_t > > & Sum_closing_curves_store_list ){
for ( list< list< tag_t > >::iterator temp_it1 = Sum_closing_curves_store_list.begin();
temp_it1 != Sum_closing_curves_store_list.end(); temp_it1 ++ ){
for ( list< tag_t >::iterator temp_it2 = ( * temp_it1 ).begin();
temp_it2 != ( * temp_it1 ).end(); temp_it2 ++ ){
if( * temp_it2 != NULL_TAG )
UF_OBJ_delete_object( * temp_it2 );
}
}
return 1;
}
//小面积方向偏置
int AQ_creat_curves_along_body::creat_offset_curve_small
( list<tag_t> &input_curves, double distance,
vector< list< list< tag_t > > > &store_inter_curves ){
//创建拉伸
//创建链表
uf_list_t *objectslsit = NULL;
UF_MODL_create_list ( &objectslsit );
for ( list<tag_t>::iterator temp_it = input_curves.begin();
temp_it != input_curves.end(); temp_it ++){
UF_MODL_put_list_item ( objectslsit, *temp_it );
}
//定义参数
char *taper_angle = "0";
char *limit[2] = {"-0.5","0.5"};
double point[3] = {0.0,0.0,0.0};
double direction[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign = UF_NULLSIGN;
uf_list_t * Features = NULL;
UF_MODL_create_extruded2 ( objectslsit, taper_angle, limit, point, direction, sign, &Features);
//特征找体
tag_t feature_obj_id;
tag_t body_obj_id;
UF_MODL_ask_list_item ( Features, 0, &feature_obj_id );
UF_MODL_ask_feat_body( feature_obj_id, &body_obj_id );
//删除链表
UF_MODL_delete_list ( &objectslsit );
UF_MODL_delete_list ( &Features );
//创建抽壳
//特征找面
uf_list_p_t faceList;
uf_list_p_t faceList_temp;
UF_MODL_create_list( &faceList_temp );
int listcount = 0;
UF_MODL_ask_feat_faces( feature_obj_id, &faceList );
UF_MODL_ask_list_count( faceList, &listcount );
tag_t faceTag = NULL_TAG;
tag_t deleteFaceTag = NULL_TAG;
//设定面的参数
int type;
double point_o [ 3 ];
double dir [ 3 ];
double box [ 6 ];
double radius;
double rad_data;
int norm_dir ;
for (int i = 0; i < listcount; ++i){
//获取TAG
UF_MODL_ask_list_item( faceList, i, &faceTag );
UF_MODL_ask_face_data
( faceTag, &type, point_o, dir, box , & radius, & rad_data, & norm_dir );
if( type == 22
&& fabs( dir[2] ) >= 0.9
&& fabs( dir[1] ) <= 0.1
&& fabs( dir[0] ) <= 0.1 ){
UF_MODL_put_list_item( faceList_temp, faceTag );
}
}
UF_MODL_delete_list( &faceList );
//text_Code
//抽壳
tag_t hollowFeatureTag = NULL_TAG;
char thick[64];
for (int i = 0; i < 2 && hollowFeatureTag == NULL_TAG; i++){
sprintf( thick, "%f", distance + ( i * 0.01 ) );
UF_MODL_create_hollow( thick, faceList_temp, &hollowFeatureTag );
}
if( hollowFeatureTag == NULL_TAG ){
//抽壳失败
UF_OBJ_delete_object( body_obj_id );
UF_DISP_refresh();
return 0;
}
UF_MODL_delete_list( &faceList_temp );
//体交面得线
//获取Z的值
double outputpoint [3];
ask_curve_point_along_parm
( *( input_curves.begin() ), 0, outputpoint );
//创建平面
tag_t plane_tag = NULL_TAG;
creat_plane_along_Zcoor( outputpoint[2], &plane_tag );
//特征找体
tag_t hollow_body_TAG = NULL_TAG;
UF_MODL_ask_feat_body( hollowFeatureTag, &hollow_body_TAG );
//进行交线求解
list< tag_t > curves_TAG;
ask_inter_curves_along_body_plane
( hollow_body_TAG, plane_tag, curves_TAG );
//进行环的提取
store_inter_curves.resize( 1 );
store_inter_curves[0].push_back( curves_TAG );
//首次提环
edit_infor_inter_curves( store_inter_curves );
//删除最大环对应的曲线TAG
for( list< tag_t >::iterator temp_it = ( * ( ( store_inter_curves[0] ).begin() ) ).begin();
temp_it != ( * ( ( store_inter_curves[0] ).begin() ) ).end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
store_inter_curves[0].pop_front();
//删除拉伸、抽壳特征
UF_OBJ_delete_object( plane_tag );
UF_OBJ_delete_object( hollow_body_TAG );
//UF_MODL_delete_feature( Features );
//更新显示
UF_DISP_refresh();
return 1;
}
int AQ_creat_curves_along_body::creat_offset_curve_big
( list<tag_t> &input_curves, double offset_distance, list<tag_t> &output_curves ){
//对于偏置之后产生多环现象,暂时不予处理,就先完成最简单的偏置功能
output_curves.clear();
int number = (int)input_curves.size();
//生成tag集链表
UF_STRING_t string_list1;//定义链表
UF_MODL_init_string_list(&string_list1);//初始化链表
UF_MODL_create_string_list(1, number, &string_list1);//分配链表空间将来释放1
string_list1.num = 1;//截面数量
string_list1.string[0] = number;//曲线的数量建立6边形是不是按照一个曲线算的这个没有验证疑问1
list< tag_t > ::iterator temp_it = input_curves.begin();
for (int i = 0; i < number; i++ ){//获取inputcurves的tag
string_list1.id[i] = * temp_it;
temp_it ++ ;
}
//将来用算法处理
string_list1.dir[0] = UF_MODL_CURVE_START_FROM_BEGIN;//将来变方向UF_MODL_CURVE_START_FROM_END.
UF_CURVE_offset_data_t offset_data_pointer;
offset_data_pointer.input_curves = &string_list1;
offset_data_pointer.approximation_tolerance = 1.0;//控制偏移曲线精度
offset_data_pointer.string_tolerance = 0.05;//距离公差,以确定两条曲线是否足够接近,可以认为是连续的
offset_data_pointer.offset_type = UF_CURVE_OFFSET_DISTANCE_TANGENT;//相切延伸
//距离
char distance_string[64] = {0};
sprintf( distance_string, "%f", offset_distance );
UF_CURVE_offset_distance_tangent_data_t distance_type2;//弄offset_type这个参数设置偏置种类以及距离的
offset_data_pointer.offset_def.distance_type2 = &distance_type2;
distance_type2.distance = distance_string;//偏置距离
tag_t offset_curve_object;
UF_CURVE_create_offset_object(&offset_data_pointer, &offset_curve_object);//创建偏置
//输出tags
//获取tags
int num_curves = 0;
tag_t *offset_curves = NULL;
int sign_ask_offset_curves = UF_CURVE_ask_offset_curves
( offset_curve_object, &num_curves, &offset_curves );
//分配地址并转移
tag_t temp_curve_TAG = NULL_TAG;
for ( int i = 0; i < num_curves; i++ ){
copy_obj( offset_curves[i], &temp_curve_TAG );
output_curves.push_back( temp_curve_TAG );
}
//比较面积是否变大
//获取偏置前曲线面积
double first_area_along_curves = ask_area_along_closing_curves( input_curves );
double second_area_along_curves = ask_area_along_closing_curves( output_curves );
//判定面积是否变小
if( first_area_along_curves < second_area_along_curves ){//面积变大
//释放内存
if( num_curves > 0 )
UF_free(offset_curves);
//删除特征,不知道曲线会不会被删除,不行的话将来就得先复制一份
int sign_delete_obj = UF_OBJ_delete_object( offset_curve_object );
//更新显示
int sign_regenerate_display = UF_DISP_regenerate_display();
}
else{//面积变小,变换方向
//删除之前复制的tag与偏置特征
if( num_curves > 0 )
UF_free(offset_curves);
for ( list< tag_t >::iterator temp_it = output_curves.begin();
temp_it != output_curves.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
UF_OBJ_delete_object(offset_curve_object);
//变换方向,并重新创建
sprintf( distance_string, "%f", (-1) * offset_distance );
distance_type2.distance = distance_string;//偏置距离
UF_CURVE_create_offset_object( &offset_data_pointer, &offset_curve_object );//创建偏置
//输出tags
//获取tags
//int num_curves = 0;
//tag_t *offset_curves = NULL;
sign_ask_offset_curves = UF_CURVE_ask_offset_curves
(offset_curve_object, &num_curves, &offset_curves );
//重新,分配地址并转移
output_curves.clear();
tag_t temp_curve_TAG = NULL_TAG;
for ( int i = 0; i < num_curves; i++ ){
copy_obj( offset_curves[i], &temp_curve_TAG );
output_curves.push_back( temp_curve_TAG );
}
if( num_curves > 0 )
UF_free(offset_curves);
//删除特征,不知道曲线会不会被删除,不行的话将来就得先复制一份
UF_OBJ_delete_object( offset_curve_object );
//更新显示
UF_DISP_regenerate_display();
}
return 1;
}
//它交环处理
int AQ_creat_curves_along_body::ask_useful_curves_along_other(
list<tag_t> & closing_curves1, //输入tag
list<tag_t> & closing_curves2,
list< list< tag_t > > &store_inter_curves ){
//进行环的预处理
double area1 = ask_area_along_closing_curves( closing_curves1 );
double area2 = ask_area_along_closing_curves( closing_curves2 );
list<tag_t> text_temp_curves;
text_temp_curves.insert
( text_temp_curves.end(), closing_curves1.begin(), closing_curves1.end() );
text_temp_curves.insert
( text_temp_curves.end(), closing_curves2.begin(), closing_curves2.end() );
double area3 = ask_area_along_closing_curves( text_temp_curves );
if( area3 > 0 ){//线没有相交
if( area1 > area2 ){//第一个线在外边
return 0;
}
if( area1 < area2 ){//已经偏进去了
return -1;
}
}
//创建拉伸1找到拉伸件1的体的tag_t
//创建链表1
uf_list_t *objectslsit1 = NULL;
UF_MODL_create_list ( &objectslsit1 );
for ( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit1, *temp_it );
}
//定义参数
char *taper_angle1 = "0";
char *limit1[2] = {"-0.5","0.5"};
double point1[3] = {0.0,0.0,0.0};
double direction1[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign1 = UF_NULLSIGN;
uf_list_t * Features1 = NULL;
UF_MODL_create_extruded2 ( objectslsit1, taper_angle1, limit1, point1, direction1, sign1, &Features1 );
//特征找体
tag_t feature_obj_id1;
tag_t body_obj_id1;
UF_MODL_ask_list_item ( Features1, 0, &feature_obj_id1 );
UF_MODL_ask_feat_body( feature_obj_id1, &body_obj_id1 );
//删除链表
UF_MODL_delete_list ( &objectslsit1 );
UF_MODL_delete_list ( &Features1 );
//创建拉伸2找到拉伸件1的体的tag_t
//创建链表2
uf_list_t *objectslsit2 = NULL;
UF_MODL_create_list ( &objectslsit2 );
for ( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit2, *temp_it );
}
//定义参数
char *taper_angle2 = "0";
char *limit2[2] = {"-1.0","1.0"};
double point2[3] = {0.0,0.0,0.0};
double direction2[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign2 = UF_NULLSIGN;
uf_list_t * Features2 = NULL;
UF_MODL_create_extruded2
( objectslsit2, taper_angle2, limit2, point2, direction2, sign2, &Features2 );
//特征找体
tag_t feature_obj_id2;
tag_t body_obj_id2;
UF_MODL_ask_list_item ( Features2, 0, &feature_obj_id2 );
UF_MODL_ask_feat_body( feature_obj_id2, &body_obj_id2 );
//删除链表
UF_MODL_delete_list ( &objectslsit2 );
UF_MODL_delete_list ( &Features2 );
int num_results = 0;
tag_t *resulting_bodies = NULL;
int sign_subtract_bodies = UF_MODL_subtract_bodies
( body_obj_id1, body_obj_id2, &num_results, &resulting_bodies);
if ( num_results > 0 ){//求减成功,进行提线储存
store_inter_curves.resize( num_results );
for (int i = 0; i < num_results; i++){
//体交面得线
//获取Z的值
double outputpoint [3];
ask_curve_point_along_parm
( *( closing_curves1.begin() ), 0, outputpoint );
//创建平面
tag_t plane_tag = NULL_TAG;
creat_plane_along_Zcoor( outputpoint[2], &plane_tag );
//进行交线求解
list< tag_t > curves_TAG;
ask_inter_curves_along_body_plane
( resulting_bodies[i], plane_tag, curves_TAG );
store_inter_curves.push_back( curves_TAG );
//删除体
UF_OBJ_delete_object( resulting_bodies[i] );
UF_OBJ_delete_object( plane_tag );
}
UF_free( resulting_bodies );
//删除原始线
for ( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end();
temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
for ( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end();
temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
}
if( num_results == 0 ){//求交失败,重新偏置,并进行提取有效环
//删除体
UF_OBJ_delete_object( body_obj_id1 );
UF_OBJ_delete_object( body_obj_id2 );
vector < list< list< tag_t > > > temp_store_inter_curves;
creat_offset_curve_small
( closing_curves1, 0.01, temp_store_inter_curves );
for( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end() ; temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
ask_useful_curves_along_other(
* ( temp_store_inter_curves[0].begin() ), //输入tag
closing_curves2,
store_inter_curves );
return 1;
}
}
//相交求并环处理
int AQ_creat_curves_along_body::edit_insert_curves
( list<tag_t> & closing_curves1, list<tag_t> & closing_curves2 , list<tag_t> & output_curves ){
int result = ask_position_along_two_curves( closing_curves1, closing_curves2 );
if( result == 2 ){//曲线相交
//创建拉伸,并进行求并操作
//创建拉伸1找到拉伸件1的体的tag_t
//创建链表1
uf_list_t *objectslsit1 = NULL;
UF_MODL_create_list ( &objectslsit1 );
for ( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit1, *temp_it );
}
//定义参数
char *taper_angle1 = "0";
char *limit1[2] = {"-0.5","0.5"};
double point1[3] = {0.0,0.0,0.0};
double direction1[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign1 = UF_NULLSIGN;
uf_list_t * Features1 = NULL;
UF_MODL_create_extruded2 ( objectslsit1, taper_angle1, limit1, point1, direction1, sign1, &Features1 );
//特征找体
tag_t feature_obj_id1;
tag_t body_obj_id1;
UF_MODL_ask_list_item ( Features1, 0, &feature_obj_id1 );
UF_MODL_ask_feat_body( feature_obj_id1, &body_obj_id1 );
//删除链表
UF_MODL_delete_list ( &objectslsit1 );
UF_MODL_delete_list ( &Features1 );
//创建拉伸2找到拉伸件1的体的tag_t
//创建链表2
uf_list_t *objectslsit2 = NULL;
UF_MODL_create_list ( &objectslsit2 );
for ( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit2, *temp_it );
}
//定义参数
char *taper_angle2 = "0";
char *limit2[2] = {"-0.5","0.5"};
double point2[3] = {0.0,0.0,0.0};
double direction2[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign2 = UF_NULLSIGN;
uf_list_t * Features2 = NULL;
UF_MODL_create_extruded2
( objectslsit2, taper_angle2, limit2, point2, direction2, sign2, &Features2 );
//特征找体
tag_t feature_obj_id2;
tag_t body_obj_id2;
UF_MODL_ask_list_item ( Features2, 0, &feature_obj_id2 );
UF_MODL_ask_feat_body( feature_obj_id2, &body_obj_id2 );
//删除链表
UF_MODL_delete_list ( &objectslsit2 );
UF_MODL_delete_list ( &Features2 );
//进行求并
UF_MODL_unite_bodies
( body_obj_id1, body_obj_id2 );
//获取Z的值
double outputpoint [3];
ask_curve_point_along_parm
( *( closing_curves1.begin() ), 0, outputpoint );
//创建平面
tag_t plane_tag = NULL_TAG;
creat_plane_along_Zcoor( outputpoint[2], &plane_tag );
//进行交线求解
//list< tag_t > curves_TAG;
output_curves.clear();
ask_inter_curves_along_body_plane
( body_obj_id1, plane_tag, output_curves );
UF_OBJ_delete_object( body_obj_id1 );
UF_OBJ_delete_object( body_obj_id2 );
UF_OBJ_delete_object( plane_tag );
for( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
for( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
closing_curves1.clear();
closing_curves2.clear();
return 1;
}
else if( result == 1 ){//外切
//将closing_curves2向外偏置0.01mm
list< tag_t > temp_closing_curves2;
creat_offset_curve_big
( closing_curves2, 0.01, temp_closing_curves2 );
for( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
closing_curves2.clear();
closing_curves2.insert( closing_curves2.end(),
temp_closing_curves2.begin(), temp_closing_curves2.end() );
temp_closing_curves2.clear();
edit_insert_curves
( closing_curves1, closing_curves2 , output_curves );
return 2;
}
else{
return 0;
}
}
/*
-2异常
-1重合
0相离
1外切
2相交
3内切
-3curve2环面积大内切
4内含
-4curve2环面积大内含
*/
int AQ_creat_curves_along_body::ask_position_along_two_curves
( list<tag_t> & closing_curves1, list<tag_t> & closing_curves2 ){
//利用截面环形成面积,判断内含
double area1 = ask_area_along_closing_curves( closing_curves1 );
double area2 = ask_area_along_closing_curves( closing_curves2 );
list<tag_t> text_temp_curves;
text_temp_curves.insert
( text_temp_curves.end(), closing_curves1.begin(), closing_curves1.end() );
text_temp_curves.insert
( text_temp_curves.end(), closing_curves2.begin(), closing_curves2.end() );
double area3 = ask_area_along_closing_curves( text_temp_curves );
if( area3 > 0 ){//线内含
if( area1 > area2 ){//第一个线在外边
return 4;
}
if( area1 < area2 ){//已经偏进去了
return -4;
}
}
//创建拉伸,并进行求交操作
//创建拉伸1找到拉伸件1的体的tag_t
//创建链表1
uf_list_t *objectslsit1 = NULL;
UF_MODL_create_list ( &objectslsit1 );
for ( list< tag_t >::iterator temp_it = closing_curves1.begin();
temp_it != closing_curves1.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit1, *temp_it );
}
//定义参数
char *taper_angle1 = "0";
char *limit1[2] = {"-0.5","0.5"};
double point1[3] = {0.0,0.0,0.0};
double direction1[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign1 = UF_NULLSIGN;
uf_list_t * Features1 = NULL;
UF_MODL_create_extruded2 ( objectslsit1, taper_angle1, limit1, point1, direction1, sign1, &Features1 );
//特征找体
tag_t feature_obj_id1;
tag_t body_obj_id1;
UF_MODL_ask_list_item ( Features1, 0, &feature_obj_id1 );
UF_MODL_ask_feat_body( feature_obj_id1, &body_obj_id1 );
//删除链表
UF_MODL_delete_list ( &objectslsit1 );
UF_MODL_delete_list ( &Features1 );
//创建拉伸2找到拉伸件1的体的tag_t
//创建链表2
uf_list_t *objectslsit2 = NULL;
UF_MODL_create_list ( &objectslsit2 );
for ( list< tag_t >::iterator temp_it = closing_curves2.begin();
temp_it != closing_curves2.end();
temp_it ++ ){
UF_MODL_put_list_item ( objectslsit2, *temp_it );
}
//定义参数
char *taper_angle2 = "0";
char *limit2[2] = {"-0.5","0.5"};
double point2[3] = {0.0,0.0,0.0};
double direction2[3] = {0.0,0.0,1.0};
UF_FEATURE_SIGN sign2 = UF_NULLSIGN;
uf_list_t * Features2 = NULL;
UF_MODL_create_extruded2
( objectslsit2, taper_angle2, limit2, point2, direction2, sign2, &Features2 );
//特征找体
tag_t feature_obj_id2;
tag_t body_obj_id2;
UF_MODL_ask_list_item ( Features2, 0, &feature_obj_id2 );
UF_MODL_ask_feat_body( feature_obj_id2, &body_obj_id2 );
//删除链表
UF_MODL_delete_list ( &objectslsit2 );
UF_MODL_delete_list ( &Features2 );
int num_intersect_results = 0;
tag_t *resulting_intersect_bodies = NULL;
int sign_intersect_bodies = UF_MODL_intersect_bodies
( body_obj_id1, body_obj_id2, &num_intersect_results, &resulting_intersect_bodies);
if( num_intersect_results == 0 ){//没有交集,分离或外切
//并集排除
int sign_unite_bodies = UF_MODL_unite_bodies
( body_obj_id1, body_obj_id2 );
UF_OBJ_delete_object( body_obj_id1 );
UF_OBJ_delete_object( body_obj_id2 );
if( sign_unite_bodies == 0 ){//求并成功,外切中的一种
return 1;
}
//曲线求交排除
int num_intersections = 0;
double* point_date = NULL;
for( list< tag_t >::iterator temp_it1 = closing_curves1.begin();
temp_it1 != closing_curves1.end(); temp_it1 ++ ){
for( list< tag_t >::iterator temp_it2 = closing_curves2.begin();
temp_it2 != closing_curves2.end(); temp_it2 ++ ){
UF_MODL_intersect_curve_to_curve
( *temp_it1, *temp_it2, &num_intersections, &point_date );
if( num_intersections > 0 ){
UF_free( point_date );
return 1;
}
}
}
//剩下即为相离
return 0;
}
//-1重合
//2相交
//3内切
//-3curve2环面积大内切
//求各个相交体的截面积
double sum_area_along_other_body = 0;
list<tag_t > curves_TAG;
tag_t plane_TAG = NULL_TAG;
double point[3];
ask_curve_point_along_parm( *( closing_curves1.begin() ), 0, point );
creat_plane_along_Zcoor( point[2], &plane_TAG );
for (int i = 0; i < num_intersect_results; i ++){
//curves_TAG.clear();
ask_inter_curves_along_body_plane
( resulting_intersect_bodies[i], plane_TAG, curves_TAG );
sum_area_along_other_body += ask_area_along_closing_curves( curves_TAG );
UF_OBJ_delete_object( resulting_intersect_bodies[i] );
for ( list< tag_t >::iterator temp_it = curves_TAG.begin();
temp_it != curves_TAG.end(); temp_it ++ ){
UF_OBJ_delete_object( * temp_it );
}
}
UF_OBJ_delete_object( plane_TAG );
if( area1 > 0.99 * area2 && area1 < 1.01 * area2 ){
if( area1 > 0.98 * sum_area_along_other_body && area1 < 1.02 * sum_area_along_other_body ){
return -1;
}
if( area2 > sum_area_along_other_body ){
return 2;
}
}
if( area1 > area2 ){
if( area2 > sum_area_along_other_body ){
return 2;
}
if( area2 == sum_area_along_other_body ){
return 3;
}
}
if( area2 > area1 ){
if( area1 > sum_area_along_other_body ){
return 2;
}
if( area1 == sum_area_along_other_body ){
return -3;
}
}
//抛出异常
return -2;
}
//把线打断为开环的线
int AQ_creat_curves_along_body::ask_right_curves
( tag_t curve_TAG, list<tag_t> *output_curves_list ){
//排错
if( curve_TAG == NULL_TAG ){
return 0;
}
//开线,入链表
if( is_curve_open( curve_TAG ) ){
output_curves_list -> push_back(curve_TAG);
return 1;
}
else{
tag_t another_curve_TAG;
double mid_point[3];
int sign_ask_point = ask_curve_point_along_parm( curve_TAG, 0.5, mid_point );
int sign_edit_curve = edit_cute_curve_along_point_length
( curve_TAG, mid_point, 0, &another_curve_TAG);
ask_right_curves( curve_TAG, output_curves_list );
ask_right_curves( another_curve_TAG, output_curves_list );
}
}
int AQ_creat_curves_along_body::is_curve_open(tag_t curve_TAG){
//排错,没有线
if(curve_TAG == NULL_TAG){
return -1;
}
//求线两端点
double start_point[3] = { 0 };
double end_point[3] = { 0 } ;
int sign_ask_point = ask_curve_point_along_parm( curve_TAG, 0, start_point );
sign_ask_point = ask_curve_point_along_parm( curve_TAG, 1, end_point );
//闭环线,建模公差内起点重点重合
if( point_distance(start_point, end_point) < 0.01 ){
return 0;
}
//开环线
//获取线的种类
int curve_type ;
int curve_subtype ;
UF_OBJ_ask_type_and_subtype( curve_TAG, &curve_type, &curve_subtype);
if( curve_type != UF_spline_type ){//开线非样条一定没有问题
return 1;
}
//样条线
else{
logical is_self_intersecting ;
int sign_is_close = UF_CURVE_is_spline_self_int( curve_TAG, &is_self_intersecting );
return (-1) * ( is_self_intersecting - 1 );
}
}
//环形面积
double AQ_creat_curves_along_body::ask_area_along_closing_curves( list< tag_t > & input_curves ){
if( input_curves.size() == 0 ){
return 0;
}
//生成tag集链表
int number = (int)input_curves.size();
UF_STRING_t string_list;//定义链表
UF_MODL_init_string_list(&string_list);//初始化链表
UF_MODL_create_string_list(1, number, &string_list);//分配链表空间将来释放1
string_list.num = 1;//截面数量
string_list.string[0] = number;//曲线的数量
list< tag_t >::iterator temp_it = input_curves.begin();
for (int i = 0; i < number; i++){//获取inputcurves的tag
string_list.id[i] = * temp_it;
temp_it ++;
}
string_list.dir[0] = UF_MODL_CURVE_START_FROM_BEGIN;
double tol [ 3 ] = {0.01, 0.01,0} ;
tag_t body_obj_TAG = NULL_TAG;
//生成有界平面
int sign_create_bplane = UF_MODL_create_bplane(&string_list, tol, &body_obj_TAG );
if(body_obj_TAG == NULL_TAG)
return -1;//曲线自交,出现异常
double acc_value [ 11 ] ={1};
double mass_props [ 47 ] ;
double statistics [ 13 ] ;
int ask_area = UF_MODL_ask_mass_props_3d
(&body_obj_TAG, 1, 2, 4, 1, 1, acc_value, mass_props, statistics);
//删除有界平面
int sign_delete_obj = UF_OBJ_delete_object(body_obj_TAG);
//释放链表地址
//UF_MODL_delete_list( &string_list);
//返回面积
return mass_props[0];
}
//多态拐角处理
void AQ_creat_curves_along_body::edit_curves_inter
( list< list< tag_t > > & Sum_closing_curves_store_list,
double degree, double cute_length ){
for ( list< list< tag_t > >::iterator
temp_it_1 = Sum_closing_curves_store_list.begin();
temp_it_1 != Sum_closing_curves_store_list.end();
temp_it_1 ++ ){
if( ( * temp_it_1 ).size() ==0 )
continue;
list< tag_t >::iterator temp_it ;
for ( list< tag_t >::iterator
temp_it_2 = ( * temp_it_1 ).begin() ;
temp_it_2 != ( * temp_it_1 ).end() ; temp_it_2 ++ ){
for ( temp_it = ( * temp_it_1 ).begin();
temp_it != ( * temp_it_1 ).end() ; temp_it ++ ){
edit_curves_inter ( * temp_it_2, * temp_it, degree, cute_length );
}
}
}
}
tag_t AQ_creat_curves_along_body::edit_curves_inter
( tag_t curve1, tag_t curve2, double degree, double cute_length ){
if( curve1 == curve2 ){
return NULL_TAG;
}
//处理两个直线
tag_t curves[2] = { curve1, curve2 };
//得到第一个交点
double startpoint[3];
int num_intersections = 0;
double* data = NULL;
int sign_intersect_curve =
UF_MODL_intersect_curve_to_curve
( curve1, curve2, &num_intersections, &data );
if( num_intersections > 0 ){
for (int i = 0; i < 3; i++){
startpoint[i] = data[i];
}
UF_free(data);
}
else{//没有交点,结束
return NULL_TAG;
}
//处理曲线方向
double output_points[2][3];
double parameter = 0;
double curve_length = 0;
int direction_sign = 1;
for( int i = 0; i < 2 ; i ++ ){
curve_length = 0;
UF_CURVE_ask_arc_length( curves[i], 0, 1, UF_MODL_MMETER , &curve_length );
curve_length /= 2;
if( cute_length > curve_length ){
cute_length = curve_length ;
}
if( curve_length > 0.05 ){//控制精度,用以定位夹角
curve_length = 0.05;
}
direction_sign = 1;
UF_MODL_ask_point_along_curve_2
( startpoint, curves[i], curve_length,
direction_sign, 0.001, output_points[i], &parameter );
if( parameter>1||parameter<0 ){
direction_sign = -1;
}
UF_MODL_ask_point_along_curve_2
( startpoint, curves[i], curve_length,
direction_sign, 0.001, output_points[i], &parameter );
}//end for
//求解角度,用以判断阈值
//处理向量
double temp_degree_cos;
for( int i = 0; i < 2; i ++ ){
for (int j = 0; j < 3; j++){
output_points[i][j] = output_points[i][j] - startpoint[j];
}
}//end for
//单位化处理
for( int i = 0; i < 2; i ++ ){
double temp_length = 0;
for (int j = 0; j < 3; j++){
temp_length += output_points[i][j] * output_points[i][j];
}
temp_length = sqrt( temp_length );
for (int j = 0; j < 3; j++){
output_points[i][j] = output_points[i][j] / temp_length;
}
}//end for
//求解角度的余弦值
temp_degree_cos = 0;
for ( int i = 0; i < 3; i++ ){
temp_degree_cos += output_points[0][i] * output_points[1][i];
}
//return (int) ( temp_degree_cos * 1000 ) ;
if( temp_degree_cos < cos( degree / 180 * 3.1415926 ) ){//余弦值约大,角度越小
return NULL_TAG;//无需操作
}
//打点
double key_cut_points[2][3];
double ref_points[2][3];
for (int i = 0; i < 2; i++){
direction_sign = 1;
UF_MODL_ask_point_along_curve_2
( startpoint, curves[i], cute_length / 10,
direction_sign, 0.001, key_cut_points[i], & parameter );
if( parameter > 1 || parameter < 0 ){
direction_sign = -1;
}
UF_MODL_ask_point_along_curve_2
( startpoint, curves[i], cute_length,
direction_sign, 0.001, key_cut_points[i], & parameter );
UF_MODL_ask_point_along_curve_2
( startpoint, curves[i], cute_length * 0.75,
direction_sign, 0.001, ref_points[i], & parameter );
}
//编辑曲线
for (int i = 0; i < 2; i++){
tag_t temp_point = NULL_TAG;
UF_CURVE_create_point( key_cut_points[i], & temp_point );
UF_CURVE_edit_trim_curve
( curves[i], temp_point, ref_points[i], startpoint, UF_CURVE_NATURAL_SHAPE );
UF_OBJ_delete_object( temp_point );
}
//创建直线
UF_CURVE_line_t line_date;
tag_t temp_line_TAG = NULL_TAG;
for (int i = 0; i < 3; i++){
line_date.start_point[i] = key_cut_points[0][i];
line_date.end_point[i] = key_cut_points[1][i];
}
int sign_creat_line = UF_CURVE_create_line
( &line_date, &temp_line_TAG );
//返回值
return temp_line_TAG;
}
//裁剪连接准备小函数
//编辑连接
//层间连接
int AQ_creat_curves_along_body::edit_layer_curves_creat_bridges
( double R, double L, //第一层的起始过度圆环半径,及外连直线
double ref_start_point[3], double ref_end_point[3],
vector< list< tag_t >* > & layer_first_curves_store, double cute_distance ){
int layer_num = 0;
//首先处理第0层曲线
//得到新的参考点和线段
tag_t temp_start_curveTAG= 0;
tag_t temp_ref_curveTAG1 = 0;
tag_t temp_ref_curveTAG2 = 0;
double temp_out_start_point[3];
double temp_out_end_point[3];
ask_two_ref_points
( ref_start_point, ref_end_point,
* ( layer_first_curves_store[layer_num] ),
& temp_ref_curveTAG1, & temp_ref_curveTAG2,
temp_out_start_point, temp_out_end_point );
temp_start_curveTAG = temp_ref_curveTAG1;
//将新终点创建圆弧及直线
//数据转移
for (int i = 0; i < 3; i++){
ref_start_point[i] = temp_out_start_point[i];
ref_end_point[i] = temp_out_end_point[i];
}
//处理其他层
for( layer_num = 1; layer_num < layer_first_curves_store.size(); layer_num ++ ){
//得到新的参考点和线段
ask_two_ref_points
( ref_start_point, ref_end_point,
* layer_first_curves_store[ layer_num ],
& temp_ref_curveTAG1, & temp_ref_curveTAG2,
temp_out_start_point, temp_out_end_point );
//temp_start_curveTAG 于 temp_ref_curveTAG2 进行曲线桥接
//对应ref_start_point 于 temp_out_end_point 坐标点
tag_t curvesTAG [2] = { temp_start_curveTAG, temp_ref_curveTAG2 };
double parm[2];
tag_t bridge_curve;
ask_curve_parm_along_point
( temp_start_curveTAG, ref_start_point, parm );
ask_curve_parm_along_point
( temp_ref_curveTAG2, temp_out_end_point, parm + 1 );
create_bridge_curve_along_two_curves_points
( UF_CURVE_TANGENT, curvesTAG, parm, & bridge_curve );
//当前层曲线、参考点转移
temp_start_curveTAG = temp_ref_curveTAG1;
for (int i = 0; i < 3; i++){
ref_start_point[i] = temp_out_start_point[i];
ref_end_point[i] = temp_out_end_point[i];
}
}
return 1;
}
int AQ_creat_curves_along_body::ask_two_ref_points
( double ref_start_point[3], double ref_end_point[3],
list< tag_t > & curves,
tag_t * ref_curveTAG1, tag_t * ref_curveTAG2,
double out_start_point[3], double out_end_point[3] ){
//得到线集
//得到最近距离
double min_dist = 10000;
double temp_dist = 10000;
double temp_min_dist_point0[3];
for( list< tag_t >::iterator temp_it = curves.begin();
temp_it != curves.end(); temp_it ++ ){
temp_dist = ask_min_dist_pt_curve
( ref_start_point, * temp_it, temp_min_dist_point0 );
if( min_dist > temp_dist )
min_dist = temp_dist;
}
//处理最短距离
if( 0.1 * min_dist > 1.1 ){
min_dist += 1.1;
}
else{
min_dist *= 1.1;
}
//得到处理后最短距离对应的曲线集
list< tag_t > temp_curves_store;
double temp_min_dist_point[3];
for( list< tag_t >::iterator temp_it = curves.begin();
temp_it != curves.end(); temp_it ++ ){
temp_dist = ask_min_dist_pt_curve
( ref_start_point, * temp_it, temp_min_dist_point );
if( temp_dist < min_dist ){
temp_curves_store.push_back( * temp_it );
}
}
//在线集中找寻最好的一条
//截取2点同时满足在线上 & 向量夹角最小 & 长度足够,的线
tag_t ready_curveTAG = 0;
double v1_v2 = 0;
double vector1[3];
double vector2[3];
//V1
for (int i = 0; i < 3; i++){
vector1[i] = ref_end_point[i] - ref_start_point[i];
v1_v2 -= ( vector1[i] * vector1[i] *100 );
}
//通过最佳的V2找寻最优解
double temp_start_point[3];
double temp_end_point[3];
double temp_parameter;
double temp_v1_v2 = 0;
double temp_curve_length = 0;
int sign_direction = 0;
for( list< tag_t >::iterator temp_it = temp_curves_store.begin();
temp_it != temp_curves_store.end(); temp_it ++ ){
UF_CURVE_ask_arc_length( * temp_it, 0, 1, UF_MODL_MMETER, & temp_curve_length );
for ( int i = -1; i < 2; i += 2 ){
//找最近点
ask_min_dist_pt_curve
( ref_start_point, * temp_it, temp_start_point );
//打点
UF_MODL_ask_point_along_curve_2
( temp_start_point, * temp_it, 0.1, i, 0.001, temp_end_point, & temp_parameter );
//V2
temp_v1_v2 = 0;
for (int j = 0; j < 3; j++){
vector2[j] = temp_end_point[j] - temp_start_point[j];
temp_v1_v2 += ( vector1[j] * vector2[j] );
}
if( 0 <= temp_parameter && temp_parameter <= 1 //在线上
&& temp_v1_v2 > v1_v2 //夹角较小,点乘越大
&& temp_curve_length > 1.1 ){ //长度足够
v1_v2 = temp_v1_v2 ;
sign_direction = i;
ready_curveTAG = * temp_it;
}
}
}
//对于新的线进行新点定位,暂时先不进行往中点偏移
//找最近点
ask_min_dist_pt_curve
( ref_start_point, ready_curveTAG, temp_start_point );
//打点
UF_MODL_ask_point_along_curve_2
( temp_start_point, ready_curveTAG, 0.1, sign_direction, 0.001,
out_start_point, & temp_parameter );
UF_MODL_ask_point_along_curve_2
( temp_start_point, ready_curveTAG, 1.1, sign_direction, 0.001,
out_end_point, & temp_parameter );
//对应裁剪
//复制曲线
( * ref_curveTAG1 ) = ready_curveTAG;
copy_obj( ready_curveTAG, ref_curveTAG2 );
curves.push_back( * ref_curveTAG2 );
//创建参考中间点
double ref_mid_point[3];
UF_MODL_ask_point_along_curve_2
( temp_start_point, ready_curveTAG, 0.6, sign_direction, 0.001,
ref_mid_point, & temp_parameter );
//进行曲线修剪
double real_sta_point[3];
double real_end_point[3];
int parm[2] = { 0,1 };
double parm1, parm2;
ask_curve_parm_along_point( ready_curveTAG, out_start_point, & parm1 );
ask_curve_parm_along_point( ready_curveTAG, out_end_point , & parm2 );
if( parm1 > parm2 ){//反
parm[0] = 1;
parm[1] = 0;
}
//求取起终点
ask_curve_point_along_parm( ready_curveTAG, parm[0], real_sta_point );
ask_curve_point_along_parm( ready_curveTAG, parm[1], real_end_point );
//编辑曲线
tag_t out_start_pointTAG = 0;
tag_t out_end_pointTAG = 0;
UF_CURVE_create_point( out_start_point, & out_start_pointTAG );
UF_CURVE_create_point( out_end_point, & out_end_pointTAG );
UF_CURVE_edit_trim_curve
( ready_curveTAG , out_start_pointTAG, ref_mid_point, out_start_point, UF_CURVE_NATURAL_SHAPE );
UF_CURVE_edit_trim_curve
( * ref_curveTAG2, out_end_pointTAG, ref_mid_point, out_end_point, UF_CURVE_NATURAL_SHAPE );
UF_OBJ_delete_object( out_start_pointTAG );
UF_OBJ_delete_object( out_end_pointTAG );
return 1;
}
//层内连接
int AQ_creat_curves_along_body::edit_closing_curves_creat_bridges
(
multimap< list< tag_t >*, list< tag_t >* >::iterator & father_it,
multimap< list< tag_t >*, list< tag_t >* > & closing_curves_store, double cute_distance ){
//找寻father_pt对应的首位对应的迭代器
for( multimap< list< tag_t >*, list< tag_t >* >::iterator
temp_it = closing_curves_store.lower_bound( ( * father_it ).second );
temp_it!= closing_curves_store.upper_bound( ( * father_it ).second ); temp_it ++ ){
//进行编辑
edit_closing_curves_creat_bridges
( temp_it,
closing_curves_store, cute_distance );
}
edit_curves_creat_bridge
( * ( ( * father_it ).first ), * ( ( * father_it ).second ), cute_distance );
return 1;
}
int AQ_creat_curves_along_body::edit_curves_creat_bridge
( list< tag_t > & curves1, list< tag_t > & curves2, double cute_distance ){
//找寻两条线,距离,小于偏置距离
//double curve_length, tag_t curve_TAG
//首先将曲线的长度进行排序
multimap< double , tag_t > temp_sort_store;
pair< double , tag_t > temp_pair;
for ( list< tag_t >::iterator temp_it = curves2.begin();
temp_it != curves2.end(); temp_it ++ ){
UF_CURVE_ask_arc_length(* temp_it, 0, 1, UF_MODL_MMETER, & ( temp_pair.first ) );
temp_pair.second = * temp_it;
temp_sort_store.insert( temp_pair );
}
//按照顺序进行迭代找线
int sign_find_two_curves = 0;
tag_t two_curves[2] = { 0, 0 };
list< double > temp_parm_curve_list;
double parm_curve[2][2] = { { 0, 0 }, { 0, 0 } };
double temp_point[3];
double temp_parm = 0;
for( multimap< double , tag_t >::iterator temp_it = -- temp_sort_store.end();
temp_it != -- temp_sort_store.begin(); temp_it -- ){
for ( list< tag_t >::iterator temp_it1 = curves1.begin();
temp_it1 != curves1.end(); temp_it1 ++ ){
double sign_is_offset = is_curves_have_off_part
( * temp_it1, ( * temp_it ).second, cute_distance );
if( sign_is_offset > 0 ){
cute_distance = sign_is_offset;
sign_find_two_curves = 1;
two_curves[1] = ( * temp_it ).second;
two_curves[0] = * temp_it1;
}
}
if( sign_find_two_curves == 1 )
break;
}
if( sign_find_two_curves == 0 ){//没有找到线
return 0;
}
//将曲线进行对应位置找寻
//找到两个曲线对应段的参数
for( int i = 0; i < 2; i ++ ){//处理第i条线
temp_parm_curve_list.clear();
for ( double j = 0; j < 2; j ++ ){//另一条线的参数是j
//用2线的起终点来截取1曲线的参数
ask_curve_point_along_parm( two_curves[ 1-i ], j, temp_point );
ask_min_dist_pt_curve( temp_point, two_curves[i], temp_point );
ask_curve_parm_along_point( two_curves[i], temp_point, & temp_parm );
//放置参数
temp_parm_curve_list.push_back( j );
temp_parm_curve_list.push_back( temp_parm );
}
temp_parm_curve_list.sort();
temp_parm_curve_list.pop_back();
temp_parm_curve_list.pop_front();
list< double >::iterator temp_it = temp_parm_curve_list.begin();
for ( int j = 0; j < 2; j ++ ){
parm_curve[i][j] = * temp_it;
temp_it ++;
}
}
//得到裁剪距离
double curve2_length = 0;
UF_CURVE_ask_arc_length( two_curves[1], parm_curve[1][0], parm_curve[1][1],
UF_MODL_MMETER, & curve2_length );
if( ( 0.8 * curve2_length ) < cute_distance ){
cute_distance = 0.8 * curve2_length;
}
//得到裁剪点的参数及tag
//定义存储
double start_point2[3];
double end_point2[3];
double curve2_point1[3];
double curve2_point2[3];
//临时变量
double parameter;
int direction_sign = 1;
//求2线取始末点
ask_curve_point_along_parm( two_curves[1], 0, start_point2 );
ask_curve_point_along_parm( two_curves[1], 1, end_point2 );
//取得两线裁剪中点
double curve1_mid_point[3];
double curve2_mid_point[3];
//得到裁剪中点的距离
double dist1 = 0;
double dist2 = 0;
UF_CURVE_ask_arc_length( two_curves[1], 0, parm_curve[1][0], UF_MODL_MMETER, & dist1 );
UF_CURVE_ask_arc_length( two_curves[1], parm_curve[1][0], parm_curve[1][1], UF_MODL_MMETER, & dist2 );
UF_MODL_ask_point_along_curve_2
( start_point2, two_curves[1], cute_distance / 2, direction_sign, 0.001, curve1_mid_point, & parameter);
if( parameter < 0 || parameter > 1 ){
direction_sign = -1;
}
//得到2线的裁剪中点
UF_MODL_ask_point_along_curve_2
( start_point2, two_curves[1], dist1 + dist2 / 2,
direction_sign, 0.001, curve2_mid_point, & parameter );
//得到1线的裁剪中点
ask_min_dist_pt_curve
( curve2_mid_point, two_curves[0], curve1_mid_point );
//得到2线对应的裁剪点
//求取1线的两个中间点
double start_point1 [3];
double end_point1 [3];
double curve1_point1 [3];
double curve1_point2 [3];
double parameter1, parameter2;
UF_MODL_ask_point_along_curve_2
( curve1_mid_point, two_curves[0], cute_distance / 2,
1, 0.001, curve1_point1, & parameter1 );
UF_MODL_ask_point_along_curve_2
( curve1_mid_point, two_curves[0], cute_distance / 2,
-1, 0.001, curve1_point2, & parameter2 );
double parm[2] = { 0, 1 };
if( parameter1 > parameter2 ){
parm[0] = 1;
parm[1] = 0;
}
//求1线取始末点
ask_curve_point_along_parm( two_curves[0], parm[0], start_point1 );
ask_curve_point_along_parm( two_curves[0], parm[1], end_point1 );
//求取2线的两个中间点
UF_MODL_ask_point_along_curve_2
( curve2_mid_point, two_curves[1], cute_distance / 2,
1, 0.001, curve2_point1, & parameter1 );
UF_MODL_ask_point_along_curve_2
( curve2_mid_point, two_curves[1], cute_distance / 2,
-1, 0.001, curve2_point2, & parameter2 );
if( parameter1 > parameter2 ){
parm[0] = 1;
parm[1] = 0;
}
else{
parm[0] = 0;
parm[1] = 1;
}
//求2线取始末点
ask_curve_point_along_parm( two_curves[1], parm[0], start_point2 );
ask_curve_point_along_parm( two_curves[1], parm[1], end_point2 );
//进行裁剪
//将原曲线在链表中清除
curves1.remove( two_curves[0] );
curves2.remove( two_curves[1] );
//复制曲线
tag_t temp_two_curves[2] = { 0, 0 };
for (int i = 0; i < 2; i++){
copy_obj( two_curves[i], temp_two_curves + i );
UF_OBJ_delete_object( two_curves[i] );
}
for (int i = 0; i < 2; i++){
two_curves[i] = temp_two_curves[i];
}
tag_t curve1_copy = 0;
copy_obj( two_curves[0], & curve1_copy );
curves1.push_back( curve1_copy );
curves1.push_back( two_curves[0] );
tag_t curve2_copy = 0;
copy_obj( two_curves[1], & curve2_copy );
curves2.push_back( curve2_copy );
curves2.push_back( two_curves[1] );
//创建截取点的tag
tag_t curve1_point1_TAG = 0;
tag_t curve1_point2_TAG = 0;
tag_t curve2_point1_TAG = 0;
tag_t curve2_point2_TAG = 0;
UF_CURVE_create_point( curve1_point1, & curve1_point1_TAG );
UF_CURVE_create_point( curve1_point2, & curve1_point2_TAG );
UF_CURVE_create_point( curve2_point1, & curve2_point1_TAG );
UF_CURVE_create_point( curve2_point2, & curve2_point2_TAG );
//进行曲线的截取操作
UF_CURVE_edit_trim_curve
( two_curves[0], curve1_point1_TAG, curve1_mid_point, start_point1, UF_CURVE_NATURAL_SHAPE );
UF_CURVE_edit_trim_curve
( curve1_copy, curve1_point2_TAG, curve1_mid_point, end_point1, UF_CURVE_NATURAL_SHAPE );
UF_CURVE_edit_trim_curve
( two_curves[1], curve2_point1_TAG, curve2_mid_point, start_point2, UF_CURVE_NATURAL_SHAPE );
UF_CURVE_edit_trim_curve
( curve2_copy, curve2_point2_TAG, curve2_mid_point, end_point2, UF_CURVE_NATURAL_SHAPE );
//删除辅助点
UF_OBJ_delete_object( curve1_point1_TAG );
UF_OBJ_delete_object( curve1_point2_TAG );
UF_OBJ_delete_object( curve2_point1_TAG );
UF_OBJ_delete_object( curve2_point2_TAG );
//创建桥接
//数据对接
tag_t four_curves_TAG[4];
double four_parm[4];
if( point_distance( curve1_point1, curve2_point1 )
<= point_distance( curve1_point1, curve2_point2 ) ){//两线参数顺
four_curves_TAG[0] = two_curves[0];//1s
four_curves_TAG[1] = curve2_copy;//2e
four_curves_TAG[2] = two_curves[1];//2s
four_curves_TAG[3] = curve1_copy;//1e
ask_curve_parm_along_point( four_curves_TAG[0], curve1_point1, four_parm + 0 );
ask_curve_parm_along_point( four_curves_TAG[1], curve2_point2, four_parm + 1 );
ask_curve_parm_along_point( four_curves_TAG[2], curve2_point1, four_parm + 2 );
ask_curve_parm_along_point( four_curves_TAG[3], curve1_point2, four_parm + 3 );
}
else{//两线参数反
four_curves_TAG[0] = two_curves[0];//1s
four_curves_TAG[1] = two_curves[1];//2s
four_curves_TAG[2] = curve1_copy;//1e
four_curves_TAG[3] = curve2_copy;//2e
ask_curve_parm_along_point( four_curves_TAG[0], curve1_point1, four_parm + 0 );
ask_curve_parm_along_point( four_curves_TAG[1], curve2_point1, four_parm + 1 );
ask_curve_parm_along_point( four_curves_TAG[2], curve1_point2, four_parm + 2 );
ask_curve_parm_along_point( four_curves_TAG[3], curve2_point2, four_parm + 3 );
}
//创建桥接
tag_t bridge_curves[2];
for( int i = 0; i < 2 ; i ++ ){
create_bridge_curve_along_two_curves_points
( UF_CURVE_TANGENT, four_curves_TAG + ( 2 * i ) ,
four_parm + ( 2 * i ) , bridge_curves + i );
}
return 1;
}
double AQ_creat_curves_along_body::is_curves_have_off_part
( tag_t curve1, tag_t curve2, double offset_dist ){
tag_t T_curves[2] = { curve1, curve2 };
//求解去掉两端的合适距离
double cute_dist[2] = { 0, 0 };
for( int i = 0; i < 2; i ++ ){
UF_CURVE_ask_arc_length( T_curves[i], 0, 1, UF_MODL_MMETER, cute_dist + i );
if( ( 0.5 * cute_dist[i] ) < offset_dist ){
//return 0;
cute_dist[i] = cute_dist[i] / 4;
}
else{
cute_dist[i] = 0.2;
}
}
//复制曲线并截断
//复制曲线
tag_t curve_copy[2] = { 0, 0 };
for( int i = 0; i < 2; i ++ ){
copy_obj( T_curves[i], curve_copy + i );
}
double s_e_point[2][2][3];
for (int i = 0; i < 2; i ++ ){//求起终点
for (int j = 0; j < 2; j ++ ){
ask_curve_point_along_parm
( T_curves[i], j, s_e_point[i][j] );
}
}
tag_t another_curve_TAG;
for ( int i = 0; i < 2; i++ ){//进行截取
for (int j = 0; j < 2; j ++ ){
edit_cute_curve_along_point_length
( curve_copy[i], s_e_point[i][j], cute_dist[i], & another_curve_TAG );
}
}
//求解2线与截后的最短距离是否在公差范围内满足
//设置相关参数
double guess1 [ 3 ] ;
double guess2 [ 3 ] ;
double min_dist;
double pt_on_obj1 [ 3 ];
double pt_on_obj2 [ 3 ];
//求解
UF_MODL_ask_minimum_dist
( curve_copy[0], curve_copy[1],
1, guess1,
1, guess2,
& min_dist, pt_on_obj1, pt_on_obj2 );
for( int i = 0; i < 2; i++ ){
UF_OBJ_delete_object( curve_copy[i] );
}
if( min_dist > 1.01 * offset_dist ){//|| min_dist < 0.999 * offset_dist
return 0;
}
//char msg[64];
//sprintf( msg, "\n %f \n", min_dist );
//UF_UI_write_listing_window( msg );
return min_dist;
}
//点线最短距离
double AQ_creat_curves_along_body::ask_min_dist_pt_curve
( double point[3], tag_t curve_TAG, double min_dist_point[3] ){
//创建点
tag_t point_TAG = NULL_TAG;
UF_CURVE_create_point( point, & point_TAG );
//设置相关参数
double guess1 [ 3 ] ;
double guess2 [ 3 ] ;
double min_dist;
double pt_on_obj1 [ 3 ];
double pt_on_obj2 [ 3 ];
//求解
UF_MODL_ask_minimum_dist
( point_TAG, curve_TAG,
1, guess1,
1, guess2,
& min_dist, pt_on_obj1, pt_on_obj2 );
//返回值
for (int i = 0; i < 3; i++){
min_dist_point[i] = pt_on_obj2[i];
}
//清除辅助点
UF_OBJ_delete_object( point_TAG );
return min_dist;
}
//剪切曲线
int AQ_creat_curves_along_body::edit_cute_curve_along_point_length
( tag_t curve_TAG, double point[3], double length, tag_t *another_curve_TAG ){
*another_curve_TAG = NULL_TAG;
//将点打到曲线上,得到两个边界点的参数
int direction_sign = 1;
double output_point1[3];
double parameter1;
int sign = UF_MODL_ask_point_along_curve_2
(point, curve_TAG, length/2, direction_sign, 0.001, output_point1, &parameter1);//取第一个边界点
direction_sign = -1;
double output_point2[3];
double parameter2;
sign = UF_MODL_ask_point_along_curve_2
(point, curve_TAG, length/2, direction_sign, 0.001, output_point2, &parameter2);//取第一个边界点
//判定截的情况
//参数排序顺序
if(parameter1 > parameter2){
double temp_parameter = parameter1;
parameter1 = parameter2;
parameter2 = temp_parameter;
double temp_point [3];
for (int i = 0; i < 3; i++){
temp_point[i] = output_point1[i];
output_point1[i] = output_point2[i];
output_point2[i] = temp_point[i];
}
}
//裁切边界在曲线外部不必要裁切返回0
if(parameter2 <= 0 || parameter1 >= 1){
*another_curve_TAG = NULL_TAG;
return 0;
}
//裁切包围整条曲线全部裁剪,返回-1
if(parameter1 <= 0 && parameter2 >= 1){
*another_curve_TAG = NULL_TAG;
int sign_delete_curve = UF_OBJ_delete_object(curve_TAG);
return -1;
}
//裁切边界在曲线内部需要复制曲线进行必要裁切返回2
if(parameter2 < 1 && parameter1 > 0){
//复制曲线
int sign_copy_curve = copy_obj(curve_TAG, another_curve_TAG);
//取得参数0-p1、p2-1的曲线
//创建点
tag_t point1_TAG = NULL_TAG;
int sign_creat_point = UF_CURVE_create_point
(output_point1, &point1_TAG);
tag_t point2_TAG = NULL_TAG;
sign_creat_point = UF_CURVE_create_point
(output_point2, &point2_TAG);
//得起点终点坐标
double startpoint[3];
int sign_ask_curve_point = ask_curve_point_along_parm
(curve_TAG, 0, startpoint);
double endpoint[3];
sign_ask_curve_point = ask_curve_point_along_parm
(curve_TAG, 1, endpoint);
//得参考点坐标
double ref_point1[3];
double ref_point2[3];
if(parameter1 < parameter2){
for (int i = 0; i < 3; i++){
ref_point1[i] = point[i];
ref_point2[i] = point[i];
}
}
else{//parameter1 == parameter2
int sign_ask_curve_ref_point1 = ask_curve_point_along_parm
(curve_TAG, parameter1/2, ref_point1);
int sign_ask_curve_ref_point2 = ask_curve_point_along_parm
(curve_TAG, (1+parameter2)/2, ref_point2);
}
//裁剪两条线
int sign_edit_trim1 = UF_CURVE_edit_trim_curve
(curve_TAG, point1_TAG, ref_point1, startpoint, UF_CURVE_NATURAL_SHAPE );
int sign_edit_trim2 = UF_CURVE_edit_trim_curve
(*another_curve_TAG, point2_TAG, ref_point2, endpoint, UF_CURVE_NATURAL_SHAPE );
//删除辅助点
int sign_delete_point1 = UF_OBJ_delete_object( point1_TAG );
int sign_delete_point2 = UF_OBJ_delete_object( point2_TAG );
return 2;
}
//其他情况需要裁切一边返回1
if(parameter1 < 0 && parameter2 <1 && parameter2 > 0){//裁切左边
*another_curve_TAG = NULL_TAG;
//取得参数p2-1的曲线
tag_t point2_TAG = NULL_TAG;
int sign_creat_point = UF_CURVE_create_point
(output_point2, &point2_TAG);
double endpoint[3];
int sign_ask_curve_point = ask_curve_point_along_parm
(curve_TAG, 1, endpoint);
int sign_edit_trim2 = UF_CURVE_edit_trim_curve
(curve_TAG, point2_TAG, point, endpoint, UF_CURVE_NATURAL_SHAPE );
int sign_delete_point = UF_OBJ_delete_object( point2_TAG );//删除辅助点
return 1;
}
if(parameter2 > 1 && parameter1 <1 && parameter1 > 0){//裁切右边
*another_curve_TAG = NULL_TAG;
//取得参数0-p1的曲线
tag_t point1_TAG = NULL_TAG;
int sign_creat_point = UF_CURVE_create_point
(output_point1, &point1_TAG);
double startpoint[3];
int sign_ask_curve_point = ask_curve_point_along_parm
(curve_TAG, 0, startpoint);
int sign_edit_trim1 = UF_CURVE_edit_trim_curve
(curve_TAG, point1_TAG, point, startpoint, UF_CURVE_NATURAL_SHAPE );
int sign_delete_point = UF_OBJ_delete_object( point1_TAG );//删除辅助点
return 1;
}
//异常,其他未被考虑到的情况
return -2;
}
//桥接相切曲线
int AQ_creat_curves_along_body::create_bridge_curve_along_two_curves_points
( int bridge_method, tag_t curve_ids [2] ,double parms [ 2 ] , tag_t * bridge_id ){
//定义辅助数据
double parameter;
double P1[3];
double P2[3];
double P1_curve1[3];
double P2_curve2[3];
double P1_bridge[3];
double P2_bridge[3];
int direction_sign = 1;
tag_t temp_bridge_TAG = NULL_TAG;
int sign = 0;
//参数得点
int sign_1 = ask_curve_point_along_parm(curve_ids[0], parms[0], P1);
sign_1 = ask_curve_point_along_parm(curve_ids[1], parms[1], P2);
//创建线头的相切曲线,用于代替曲线进行桥接
tag_t lines_TAG[2] = {NULL_TAG, NULL_TAG};
int creat_tangent_line = creat_tangent_line_along_curve
(P1, curve_ids[0], 5, lines_TAG);
creat_tangent_line = creat_tangent_line_along_curve
(P2, curve_ids[1], 5, lines_TAG+1);
//得到点在直线上的参数
double point_temp [3] = {0, 0, 0};
int ask_curve_parm = UF_MODL_ask_curve_parm
(lines_TAG[0], P1 , parms, point_temp );
ask_curve_parm = UF_MODL_ask_curve_parm
(lines_TAG[1], P2 , parms+1, point_temp );
//循环创建对象并检验成功返回1曲线tag不成功删除最终不成功返回0
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){
int reverse_tangent [2]={ i, j };//回头方向
int sign_create_bridge = UF_CURVE_create_bridge_curve
(bridge_method, lines_TAG, parms, reverse_tangent, &temp_bridge_TAG);
//打点p1在line1
double dis = 0.1;
double tol = 0.001;
direction_sign = 1;
//获取适宜的dis
double temp_dist = 0;
for (int i = 0; i < 2; i++){
UF_CURVE_ask_arc_length( lines_TAG[i], 0, 1, UF_MODL_MMETER, & temp_dist );
if( dis > ( temp_dist / 2 ) )
dis = temp_dist / 2 ;
}
UF_CURVE_ask_arc_length( temp_bridge_TAG, 0, 1, UF_MODL_MMETER, & temp_dist );
if( dis > ( temp_dist / 2 ) )
dis = temp_dist / 2 ;
//开始打点
UF_MODL_ask_point_along_curve_2
(P1, lines_TAG[0], dis, direction_sign, tol, P1_curve1, &parameter);//取第一个点
if( parameter>1 || parameter<0 ){
direction_sign = -1;
UF_MODL_ask_point_along_curve_2
(P1, lines_TAG[0], dis, direction_sign, tol, P1_curve1, &parameter);
}
//打点p1在bridge曲线
direction_sign = 1;
UF_MODL_ask_point_along_curve_2
(P1, temp_bridge_TAG, dis, direction_sign, tol, P1_bridge, &parameter);//取第一个点
if(parameter>1 || parameter<0){
direction_sign = -1;
UF_MODL_ask_point_along_curve_2
(P1, temp_bridge_TAG, dis, direction_sign, tol, P1_bridge, &parameter);
}
//打点p2在line2
direction_sign = 1;
UF_MODL_ask_point_along_curve_2
(P2, lines_TAG[1], dis, direction_sign, tol, P2_curve2, &parameter);//取第一个点
if(parameter>1 || parameter<0){
direction_sign = -1;
UF_MODL_ask_point_along_curve_2
(P2, lines_TAG[1], dis, direction_sign, tol, P2_curve2, &parameter);
}
//打点p2在bridge曲线
direction_sign = 1;
UF_MODL_ask_point_along_curve_2
(P2, temp_bridge_TAG, dis, direction_sign, tol, P2_bridge, &parameter);//取第一个点
if( parameter > 1 || parameter < 0 ){
direction_sign = -1;
UF_MODL_ask_point_along_curve_2
( P2, temp_bridge_TAG, dis, direction_sign, tol, P2_bridge, &parameter );
}
//下面判断已经创建的bridge曲线的方向是否正确
double sign_strat_dir = (P1_bridge[0] - P1[0])*(P1[0] - P1_curve1[0])
+(P1_bridge[1] - P1[1])*(P1[1] - P1_curve1[1])
+(P1_bridge[2] - P1[2])*(P1[2] - P1_curve1[2]);
double sign_end_dir = (P2_bridge[0] - P2[0])*(P2[0] - P2_curve2[0])
+(P2_bridge[1] - P2[1])*(P2[1] - P2_curve2[1])
+(P2_bridge[2] - P2[2])*(P2[2] - P2_curve2[2]);
if(sign_strat_dir > 0 && sign_end_dir > 0){//创建成功
*bridge_id = temp_bridge_TAG;
//删除辅助直线
UF_OBJ_delete_object( lines_TAG[0] );
UF_OBJ_delete_object( lines_TAG[1] );
return 1;
}
else{
UF_OBJ_delete_object( temp_bridge_TAG );
}
}//endfor_j
}//endfor_i
return 0;
}
int AQ_creat_curves_along_body::creat_tangent_line_along_curve
(double startpoint[3], tag_t curve_TAG, double length, tag_t *line_TAG){
//获取曲线该点得参数
double parm = 0;
int sign_ask_curve_parm = ask_curve_parm_along_point
(curve_TAG, startpoint, &parm);
//获取改参数得切矢量
double point [3];
double tangent [3]; //我只关注这个信息
double p_norm [3];
double b_norm [3];
double torsion;
double rad_of_cur;
int sign_infor = UF_MODL_ask_curve_props
(curve_TAG, parm, point, tangent, p_norm, b_norm, &torsion,& rad_of_cur);
//创建一条直线
UF_CURVE_line_t line_date;
tag_t temp_line_TAG = NULL_TAG;
for (int i = 0; i < 3; i++){
line_date.start_point[i] = startpoint[i];
line_date.end_point[i] =
startpoint[i] + length * ( tangent[i]/sqrt( pow(tangent[0],2)+pow(tangent[1],2)+pow(tangent[2],2) ) );
}
int sign_creat_line = UF_CURVE_create_line
(&line_date, &temp_line_TAG);
//判断终点方向是否正确
//1.线上取点
double dis = 0.01;
double tol = 0.001;
int direction_sign = 1;
double parameter = 0;
double point_along_curve[3]={0,0,0};
int sign_ask_point = UF_MODL_ask_point_along_curve_2
(startpoint, curve_TAG, dis, direction_sign, tol, point_along_curve, &parameter);//取第一个点
if(parameter>1 || parameter<0){
direction_sign = -1;
sign_ask_point = UF_MODL_ask_point_along_curve_2
(startpoint, curve_TAG, dis, direction_sign, tol, point_along_curve, &parameter);
}
//判断曲线的方向是否正确
double sign_point_dir = 0;
for (int i = 0; i < 3; i++){
sign_point_dir += (point_along_curve[i] - startpoint[i])
*(line_date.end_point[i] - startpoint[i]);
}
//处理直线方向
if(sign_point_dir > 0){
*line_TAG = temp_line_TAG;
return 1;
}
else{
int sign_delete_line = UF_OBJ_delete_object( temp_line_TAG );
for (int i = 0; i < 3; i++){
line_date.end_point[i] =
startpoint[i] - length * ( tangent[i]/sqrt( pow(tangent[0],2)+pow(tangent[1],2)+pow(tangent[2],2) ) );
}
sign_creat_line = UF_CURVE_create_line(&line_date, &temp_line_TAG);
*line_TAG = temp_line_TAG;
return 1;
}
return 0;
}
//复制对象
int AQ_creat_curves_along_body::copy_obj(tag_t obj, tag_t *copyed_obj){
//定义移动相关数据
double translation [ 3 ] ={0, 0, 1};//移动向量
double matrix [ 12 ] ;
uf5943(translation, matrix );//通过函数转变为,变换矩阵
//下边参数uf讲的很详细
int n_objects = 1;
int move_or_copy = 2;
int dest_layer = 0;
int trace_curves = 2;//是否要追踪曲线
tag_t input[1];//数量根据对象的多少定吧
input[0] = obj;
tag_t output[1];
tag_t trace_curve_group[2];
int status = 0;
//第一次复制移动001
uf5947
(matrix, input, &n_objects, &move_or_copy, &dest_layer,
&trace_curves, output, trace_curve_group, &status );
//if(status)
// return 0;
//第二次移动数据准备
translation [ 2 ] = -1;//再变换为反方向
uf5943(translation, matrix );
move_or_copy = 1;
uf5947
(matrix, output, &n_objects, &move_or_copy, &dest_layer,
&trace_curves, copyed_obj, trace_curve_group, &status );
if(status)
return 0;
*copyed_obj = output[0];//返回对象的tag
return 1;
}
//线上点和参数相互转换
int AQ_creat_curves_along_body::ask_curve_point_along_parm
(tag_t curve_id, double parm, double outputpoint [3] ){
double tangent [ 3 ] ;
double p_norm [ 3 ] ;
double b_norm [ 3 ] ;
double torsion ;
double rad_of_cur ;
return UF_MODL_ask_curve_props(curve_id, parm, outputpoint , tangent , p_norm , b_norm , & torsion, & rad_of_cur );
}
int AQ_creat_curves_along_body::ask_curve_parm_along_point
(tag_t curve_id, double point [ 3 ] , double * parm){
double point_temp [ 3 ] = {0, 0, 0};
return UF_MODL_ask_curve_parm(curve_id, point , parm, point_temp );
}
//两线相交
int AQ_creat_curves_along_body::intersect_curve_along_curve
(tag_t curve1_TAG, tag_t curve2_TAG, vector<tag_t > *points_TAG ){
int num_intersections = 0;
double* data = NULL;
int sign_intersect_curve =
UF_MODL_intersect_curve_to_curve
(curve1_TAG, curve2_TAG, &num_intersections, &data );
points_TAG->resize(num_intersections+1);
tag_t temp_point_TAG ;
int sign_create_point =0;
for (int i = 0; i < num_intersections; i++){
//创建点
sign_create_point = UF_CURVE_create_point(data+(5*i), &temp_point_TAG );
(*points_TAG)[i] = temp_point_TAG;
}
//释放内存
UF_free(data);
return num_intersections;
}
//起点判断
int AQ_creat_curves_along_body::is_start_point_along_curve
( double*start_point, tag_t curve, double modeling_tolerance, double parameter_tolerance ){
double parameter;
double output_points[3];
int sign = UF_MODL_ask_point_along_curve_2
(start_point, curve, 0, 1, 0.001, output_points, &parameter);
return
(int)(point_distance(start_point, output_points) <= modeling_tolerance //在线上
&&
( fabs(parameter)<parameter_tolerance || fabs(parameter-1)<parameter_tolerance ) //用参数判断靠近端点
);
}
//两点距离
double AQ_creat_curves_along_body::point_distance(double*p1,double*p2){
return
sqrt( (p1[0]-p2[0])*(p1[0]-p2[0]) +
(p1[1]-p2[1])*(p1[1]-p2[1]) +
(p1[2]-p2[2])*(p1[2]-p2[2]) );
}
//求终点
void AQ_creat_curves_along_body::ask_endpoint_along_curve
( double* Start_point, tag_t curve, double * output_endpoint ){
//得到线的两个端点
int temp_sign =0;
double start_point[3];
double end_point[3];
temp_sign = ask_curve_point_along_parm ( curve, 0, start_point );
temp_sign = ask_curve_point_along_parm ( curve, 1, end_point );
//比较距离
double start_distance = point_distance ( Start_point, start_point );
double end_distance = point_distance ( Start_point, end_point );
//进行数据转移
if( start_distance < end_distance ){//输出尾
for (int i = 0; i < 3; i++){
output_endpoint [i] = end_point[i];
}
}
else{//输出头
for (int i = 0; i < 3; i++){
output_endpoint [i] = start_point[i];
}
}
}