全是文件操作,没什么困难的,稍微有点坑是obj的face对应的vertex的idx要加1,下面上代码。
思路是找到POINTS把点坐标都读出来,找到CELLS把面片都读出来,然后根据obj的格式写一下数据。
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
using namespace std;
struct TriMesh {
vector<OpenMesh::Vec3d> points;
vector<OpenMesh::Vec3i> faces;
}MyMesh;
void readVtk(std::string input)
{
ifstream input_file(input);
if (!input_file.is_open()) {
std::cout << "Unable to open file";
return;
}
std::string ss[3];
std::string line;
char str[10];
double xt, yt, zt;
int a, b, c, d, tc