问题遇到的现象和发生背景
在github上下载了网格简化的算法,用VS2022打开了.sln的文件,直接运行就报错了。知道是没有读取文件。但是怎么读取啊。请求教教我。
问题相关代码,请勿粘贴截图
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <chrono>
#include "Mesh--.h"
int main(int argc, char *argv[])
{
if (argc < 4) {
std::cerr << "Usage: inputMesh outputMesh reduceRatio" << std::endl;
return -1;
}
std::string inputFN(argv[1]);
std::string outputFN(argv[2]);
double ratio = atof(argv[3]);
std::cout << inputFN << std::endl;
std::ifstream in(argv[1]);
if (!in.is_open()) {
std::cerr << "Failed open input mesh file: " << inputFN << std::endl;
return -1;
}
std::cout << "Start parsing mesh..." << std::endl;
mmm::Mesh mesh(in);
in.close();
std::cout << "Finished." << std::endl;
// Simplify the mesh.
std::cout << "Start simplifying mesh..." << std::endl;
size_t origin = mesh.getOldNumFaces();
size_t remain = (size_t)(origin * ratio);
clock_t start = clock();
mesh.simplify(remain, 0.1);
double duration = (clock() - start) / CLOCKS_PER_SEC;
std::cout << "Finished: Simplified / Original = " << std::setw(6) <<
(double)mesh.getNumFaces() / (double)mesh.getOldNumFaces() << std::endl;
std::cout << "Total time: " << std::setw(6) << duration << " sec." << std::endl;
// Dump the output mesh.
std::ofstream out(outputFN);
if (!out.is_open()) {
std::cerr << "Failed opening output file: " << outputFN << std::endl;
return -1;
}
mesh.dumpObj(out);
std::cout << "Saved to > " << outputFN << std::endl;
out.close();
return 0;
}
运行结果及报错内容
直接运行就出现“Usage: inputMesh outputMesh reduceRatio” ,但是如果注释掉if语句,就会报错:0x00007FFF3BD1F551 (ucrtbased.dll)处(位于 Mesh--.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突。
我的解答思路和尝试过的方法
我想要达到的结果
这个代码怎么该才能成功运行。