Midas GTS NX 的三角单元模型转为 3DEC的三棱柱模型 c++源码 (triangles to 3DEC)

三角单元模型导入3DEC成为三棱柱

 

1.使用方法->有问题加群:956765008

(1)数据导出之前:网格->工具->重新编号:单元、节点

 

 

 

(2)数据格式

 

(3)双击打开 Triangles_Prisms_3DEC.exe ,输入节点文件名称:nl,和单元文件名称:el。 

 

(注意:Triangles_Prisms_3DEC.exe 和 节点、单元文件放在同一个文件夹

(4)如果模型Z轴向上,则输入0;Y轴向上,则输入1;

(5)根据Z轴或Y轴的范围,输入三棱柱的底部标高。

 

 

 

 

2.//完整程序:

 

https://pan.baidu.com/s/1a8B_zAGGjI33g2tBCw90Ew

 

3.//可以直接运行的程序:


https://pan.baidu.com/s/1y_8SpPg96kTbx1-uCHpDgg

 

4.//以下是完整代码

 

/************************************************************************/
/* 将Midas GTS NX 的三角单元模型 转为 3DEC的三棱柱模型 2018.4.23 */
/************************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

// 数据结构
typedef struct CVert  // 节点                                            
{                                                                     
	double x, y, z;  
	CVert() {};                                                       
} CVert;

typedef struct CTrgl  // 单元
{
	int pt0, pt1, pt2; 
	int attri;
	CTrgl() {};
} CTrgl;


void printinformation()
{

	cout<<"//************************************************************************//"<<endl;
	cout<<"                将Midas GTS NX 的三角单元模型 转为 3DEC的三棱柱模型          "<<endl;
	cout<<"                                                  "<<endl;
	cout<<" 1、将节点文件,整理成4列,分别为节点ID,X, Y, Z"<<endl;
	cout<<"\t\tnl.txt文件第一行加上节点数量,如下:"<<endl;
	cout<<"\t\t584	"<<endl;
	cout<<"\t\t1	0.000000	-0.000001	500.000000"<<endl;
	cout<<"\t\t2	48.689118	0.581830	500.972253"<<endl;
	cout<<"\t\t3	97.414094	1.165760	502.316390"<<endl;
	cout<<"\t\t................................................"<<endl;
	cout<<" 2、将三角单元文件,整理成5列,分别为"<<endl;
	cout<<"\t\t1)单元ID,材料属性,节点ID1~3; "<<endl;
	cout<<"\t\t2)材料属性统一改成数字,如1,2,3等"<<endl;
	cout<<"\t\t3)el.txt文件第一行加上单元数量,如下:"<<endl;
	cout<<"\t\t1089	"<<endl;					
	cout<<"\t\t1	1	1	2	72"<<endl;
	cout<<"\t\t2	1	2	73	72"<<endl;
	cout<<"\t\t3	1	72	73	74"<<endl;
	cout<<"\t\t................................................"<<endl;	
	cout<<"//************************************************************************//"<<endl;

}



/************************************************************************/
/* 将三角单元转为3dec中的三棱柱模型*/
/************************************************************************/
int main(void)
{
	printinformation();

	string str1, str2;
	double x, y, z;   
	int nVert, nTrgl, id;  
	CVert * verts;                   
	CTrgl * trgls;                       
	double Depth;
	
	// 读入  
	cout << "\n请输入节点文件*.txt:  ";
	cin >> str1; 
	cout << "\n请输入单元文件*.txt:  ";
	cin >> str2;  
	         

	ifstream  fin1(str1 + ".txt");
	if (!fin1)
	{
		cout << "\nCannot Open File ! " << str1 << endl;	
		system("pause"); 
		exit(1);
	}
	fin1 >>nVert;
       
	verts = new CVert[nVert];                                     

	for (int i = 0; i < nVert; i++)
	{
		fin1 >> id >> x >> y >> z;
		verts[i].x = x;
		verts[i].y = y;
		verts[i].z = z;

	}
	fin1.close();
	cout<<"\n\t读入节点数量: "<< nVert <<endl; 



	ifstream  fin2(str2 + ".txt");
	if (!fin2)
	{
		cout << "\nCannot Open File ! " << str2 << endl;
		system("pause"); 
		exit(1);
	}

	vector<int>GroupNum;
	bool gp = false;


	int attri;
	int ID0, ID1, ID2;

	fin2 >>nTrgl;
	trgls = new CTrgl[nTrgl];    

	GroupNum.push_back(0);
	for(int i = 0; i < nTrgl; i++)	
	{
		gp = false;

		fin2 >> id >> attri >> ID0 >> ID1 >> ID2;   

		trgls[i].pt0 = ID0 - 1;                        
		trgls[i].pt1 = ID1 - 1;                          
		trgls[i].pt2 = ID2 - 1;   
		trgls[i].attri = attri;  

		for (int j = 0; j < GroupNum.size(); j++)
		{
			if (attri == GroupNum[j]) 
			{
				gp = true; 
				break; 
			}
		}
		if (!gp) GroupNum.push_back(attri);

	}
    fin2.close();

	cout<<"\t读入单元数量: "<< nTrgl <<endl; 
	cout<<"\t模型区域数量: "<< GroupNum.size() - 1 <<endl; 


	double minZ = z, maxZ = z;
	double minY = y, maxY = y;
	double minX = x, maxX = x;
	for (int i = 0; i < nVert; i++)
	{
		x = verts[i].x;
		y = verts[i].y;
		z = verts[i].z;

		if (minZ > z) minZ = z;
		if (maxZ < z) maxZ = z;
		if (minY > y) minY = y;
		if (maxY < y) maxY = y;
		if (minX > x) minX = x;
		if (maxX < x) maxX = x;

	}


	cout<<"\n模型范围:"<<endl;
	cout<<"\tX:"<<minX<<"__"<<maxX<<endl;
	cout<<"\tY:"<<minY<<"__"<<maxY<<endl;
	cout<<"\tZ:"<<minZ<<"__"<<maxZ<<endl;

	cout<<"\nZ轴向上输入0,Y轴向上输入1:";
	int ZY = 0;
	cin>>ZY;

	cout << "\n请输入三棱柱底部标高:  ";
	cin >> Depth;    

	
	// 输出
	string fname = str1 + "_" + str2 + "_Triangles_Prisms_3DEC.txt";                                          
	ofstream fout(fname);

	/******************************************************************************************************************/
	/* 3DEC PRISM*/
	for (int i = 1; i < GroupNum.size(); i++) 
	{
		for (int j = 0; j < nTrgl; j++) 
		{
			ID0 = trgls[j].pt0;
			ID1 = trgls[j].pt1;
			ID2 = trgls[j].pt2;

			attri = trgls[j].attri;

			if (attri != GroupNum[i])	continue;	

			fout <<"poly prism &\n";
			fout << "a";
			fout <<"\t"<< verts[ID0].x << "," << verts[ID0].y<< "," << verts[ID0].z;
			fout <<"\t"<< verts[ID1].x << "," << verts[ID1].y<< "," << verts[ID1].z;
			fout <<"\t"<< verts[ID2].x << "," << verts[ID2].y<< "," << verts[ID2].z;
			fout <<"\t&"<< endl;
			fout << "b";

			if (ZY == 0)
			{
				fout <<"\t"<< verts[ID0].x << "," << verts[ID0].y<< "," << Depth;
				fout <<"\t"<< verts[ID1].x << "," << verts[ID1].y<< "," << Depth;
				fout <<"\t"<< verts[ID2].x << "," << verts[ID2].y<< "," << Depth;
			}
			if (ZY == 1)
			{
				fout <<"\t"<< verts[ID0].x << "," << Depth<< "," << verts[ID0].z;
				fout <<"\t"<< verts[ID1].x << "," << Depth<< "," << verts[ID0].z;
				fout <<"\t"<< verts[ID2].x << "," << Depth<< "," << verts[ID0].z;
			}

			fout << endl;
		}
		fout<< " mark region "<< GroupNum[i]<<"\n";
		fout<< " hide region "<< GroupNum[i]<<"\n";
	}

	fout<< "seek \n";

	fout.close();
	/*******************************************************************************************************************/

	cout<<"\n转换完成!\n";

	cout<<"\n结果已经保存至: "<< fname << endl;


	delete[] verts;
	delete[] trgls;

	GroupNum.clear();
	GroupNum.shrink_to_fit();

	system("pause");
	return 0;

}

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值