当前位置:   article > 正文

VTK读取接口_c++ vtk 接口

c++ vtk 接口

#include
#include
#include
#include
#include
using namespace std;

template
vector<vector> DataOut(ifstream& fin, int n, int size)
{
string line;
stringstream lineStream;
vector<vector> Data;
vector vecTmp;
vecTmp.resize(size);
for (int i = 0; i < n; i++)
{
getline(fin, line);
lineStream << line;
for (int j = 0; j < size; j++)
lineStream >> vecTmp[j];
Data.push_back(vecTmp);
lineStream.clear();
}
return Data;
}

vector<vector> Read_Vtk
(
int frame,
string partName,
string inVariableName,
int setType,//0表示set为节点,1表示单元集合
int partId//看输入是否有,不是一定有
)
{
/*
//输入
int frame = 1;
string partName = “KEY_R_05MM”;
string inVariableName = “U”;
int setType = 1;//0表示set为节点,1表示单元集合
int partId = 1; //看输入是否有,不是一定有
*/

for (int i = 0; i < inVariableName.size(); i++)
{
	inVariableName[i]=tolower(inVariableName[i]);
}
if (inVariableName.size() > 0)
	inVariableName[0]=toupper(inVariableName[0]);

//判断寻找变量在VTK中的名字
string judgeInVariableName;
if (inVariableName == "U")
	judgeInVariableName = "Displacement";
else if (inVariableName == "Coord")
	judgeInVariableName = "Coord";
else if (inVariableName == "Density")
	judgeInVariableName = "density";
else if (inVariableName == "Resistivity")
	judgeInVariableName = "resistivity";
else if (inVariableName == "Temperature")
	judgeInVariableName = "temperature";
else if (inVariableName == "Permittivity")
	judgeInVariableName = "permittivity";




//result.2_1_RIGID
//result.1_KEY_R_05MM.vtk   
string inFile = "result.";
inFile = inFile + to_string(frame) + "_" + partName + ".vtk";   //切忌一定要把 后缀vtk带上,不然就是错误

ifstream fin;
fin.open(inFile.c_str(), ios::in);


//	POINTS	8	double
int n_points;     //节点总数
string pointsDatetype;//节点数据类型
vector<vector<int>> pointDataInt;//读入数据
vector<vector<float>> pointDataFloat;//读入数据
vector<vector<double>> pointDataDouble;//读入数据

									   //CELLS 1 9
int n_cells;   //单元总数
int elementsDateblockNum;  //这一块包含的数据总数
vector<vector<int>> elementNodeIdArray;

//	CELL_TYPES 1
//单元类型
vector<int> elementType;

//	POINT_DATA 3782
//	CELL_DATA 1
int dateTypeFlag = -1;//0:point数据  1:cell数据
int dataSize;

//SCALARS density double 1
//LOOKUP_TABLE table1
string physicalType;// //SCALAR,VECTOR或TENSOR,不同类型的数据需要不同的格式
string varieableName;//变量名
string dataType;//数据块数据类型
int numComp;   //分量个数
vector<vector<int>> phyDataInt;//读入数据
vector<vector<float>> phyDataFloat;//读入数据
vector<vector<double>> phyDataDouble;//读入数据

stringstream lineStream;

string line;
//line = "	POINTS	8	double";
string temp;
string temp1;


if (!fin.is_open())
{
	cout << "File open fail" << endl;
	return pointDataDouble;
}



if (fin)
{
	while (getline(fin, line))
	{

		//清除每行段前空格
		while (line[0] == '\t')
			line.erase(0, 1);

		//读取节点数
		if ((line[0] >= 'a' & line[0] <= 'z') || (line[0] >= 'A' && line[0] <= 'Z'))
		{
			//	POINTS	8	double
			if (line.substr(0, 6) == "POINTS")
			{

				lineStream << line;
				lineStream >> temp;
				lineStream >> n_points;
				lineStream >> pointsDatetype;
				lineStream.clear();

				if (pointsDatetype == "int")
				{
					pointDataInt = DataOut<int>(fin, n_points, 3);
				}
				else if (pointsDatetype == "double" || pointsDatetype == "float")
				{
					if ((judgeInVariableName == "Coord") && (setType == 0))
					{
						pointDataDouble = DataOut<double>(fin, n_points, 3);
						return pointDataDouble;
					}
					else
					{
						for (int i = 0; i < n_points; i++)
						{
							getline(fin, line);//跳过这些行
						}
					}
				}
				else if (pointsDatetype == "double")
				{
					pointDataDouble = DataOut<double>(fin, n_points, 3);
				}
				else if (pointsDatetype == "float")
				{
					pointDataFloat = DataOut<float>(fin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/996127
推荐阅读
相关标签
  

闽ICP备14008679号