ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (0000027753736D90): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C7349E0): Algorithm vtkSTLReader(0000027753736D90) returned failure for request: vtkInformation (000002775C3081B0)
Debug: Off
Modified Time: 52611
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (0000027753736B20): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C733FE0): Algorithm vtkSTLReader(0000027753736B20) returned failure for request: vtkInformation (000002775C308CA0)
Debug: Off
Modified Time: 125835
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (00000277537371A0): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C733CE0): Algorithm vtkSTLReader(00000277537371A0) returned failure for request: vtkInformation (000002775C3081B0)
Debug: Off
Modified Time: 125980
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (00000277537379C0): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C7324E0): Algorithm vtkSTLReader(00000277537379C0) returned failure for request: vtkInformation (000002775C307C60)
Debug: Off
Modified Time: 244547
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (0000027753736B20): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C732EE0): Algorithm vtkSTLReader(0000027753736B20) returned failure for request: vtkInformation (000002775C3081B0)
Debug: Off
Modified Time: 349445
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (0000027753736B20): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C733CE0): Algorithm vtkSTLReader(0000027753736B20) returned failure for request: vtkInformation (000002775C3087A0)
Debug: Off
Modified Time: 398181
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\IO\Geometry\vtkSTLReader.cxx, line 97
vtkSTLReader (0000027753736B20): A FileName must be specified.
ERROR: In D:\vs2022\Qt_VTK\vtk-v9.1.0\vtk-v9.1.0\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000002775C733CE0): Algorithm vtkSTLReader(0000027753736B20) returned failure for request: vtkInformation (000002775C308ED0)
Debug: Off
Modified Time: 457347
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
报错是随机的,每次运行读取失败的stl文件也不同
现在我要遍历几千个stl文件,对于其中一个stl文件,我要读取他们的一些数据属性,然后进行判断
流程图:
相关demo:
QObject::connect(ui->pushButton, &QPushButton::clicked,
this, &MainWindow::onDetermine);
void MainWindow::onDetermine()
{
//E:/111111111111111111111111111111111tmp/facc2/
QString destPath = "E:/111111111111111111111111111111111tmp/facc2/";
QDir srcDir(destPath);
// 遍历源路径下的文件夹
QFileInfoList folderList = srcDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo folderInfo, folderList)
{
QString tmp = folderInfo.fileName();
QString tmpPath = destPath + tmp + "/upper.stl";
qDebug() << tmpPath;
MainWindow::Determine_if_the_stl_file_coordinates_are_correct(tmpPath);
}
}
问题就出现在下面的两个智能指针中:
vtkSmartPointer
vtkSmartPointer
void MainWindow::Determine_if_the_stl_file_coordinates_are_correct(QString path)
{
const char* stlFilePath = path.toUtf8().constData();
// 创建STL文件读取器
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(stlFilePath);
reader->Update();
// 获取STL数据
vtkSmartPointer<vtkPolyData> inputPolyData = reader->GetOutput();
inputPolyData = reader->GetOutput();
// Compute the bounding box
double bounds[6];
inputPolyData->GetBounds(bounds);
// Bounds are in the form [xmin, xmax, ymin, ymax, zmin, zmax]
double xmin = bounds[0];
double xmax = bounds[1];
double ymin = bounds[2];
double ymax = bounds[3];
double zmin = bounds[4];
double zmax = bounds[5];
// Calculate the corner points
double corners[8][3] = {
{xmin, ymin, zmin},
{xmax, ymin, zmin},
{xmin, ymax, zmin},
{xmax, ymax, zmin},
{xmin, ymin, zmax},
{xmax, ymin, zmax},
{xmin, ymax, zmax},
{xmax, ymax, zmax}
};
//cout << path.toUtf8().constData() << endl;
cout << "xmin:" << xmin << ",max:" << xmax <<
",ymin:" << ymin << ",ymax:" << ymax <<
",zmin:" << zmin << ",zmax:" << zmax << endl;
//y轴长度
double Ylen = ymax - ymin;
//z轴长度
double Zlen = zmax - zmin;
if (Ylen > Zlen) {
//异常;
cout << path.toUtf8().constData()<<"此病例坐标轴异常" << endl;
}
}
//将这两个指针搞成全局变量,不然系统可能反应不过来,
//这种情况出现的原因是:上次的reader还没完成自动析构,这次的reader就来申请了,就会读取失败,
//方法:直接全局变量,程序结束前不再析构,让程序会那么手忙脚乱!
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
vtkSmartPointer<vtkPolyData> inputPolyData;
void MainWindow::Determine_if_the_stl_file_coordinates_are_correct(QString path)
{
const char* stlFilePath = path.toUtf8().constData();
// 创建STL文件读取器
//vtkSmartPointer reader = vtkSmartPointer::New();
reader->SetFileName(stlFilePath);
reader->Update();
// 获取STL数据
//vtkSmartPointer inputPolyData = reader->GetOutput();
inputPolyData = reader->GetOutput();
// Compute the bounding box
double bounds[6];
inputPolyData->GetBounds(bounds);
// Bounds are in the form [xmin, xmax, ymin, ymax, zmin, zmax]
double xmin = bounds[0];
double xmax = bounds[1];
double ymin = bounds[2];
double ymax = bounds[3];
double zmin = bounds[4];
double zmax = bounds[5];
// Calculate the corner points
double corners[8][3] = {
{xmin, ymin, zmin},
{xmax, ymin, zmin},
{xmin, ymax, zmin},
{xmax, ymax, zmin},
{xmin, ymin, zmax},
{xmax, ymin, zmax},
{xmin, ymax, zmax},
{xmax, ymax, zmax}
};
//cout << path.toUtf8().constData() << endl;
cout << "xmin:" << xmin << ",max:" << xmax <<
",ymin:" << ymin << ",ymax:" << ymax <<
",zmin:" << zmin << ",zmax:" << zmax << endl;
//y轴长度
double Ylen = ymax - ymin;
//z轴长度
double Zlen = zmax - zmin;
if (Ylen > Zlen) {
//异常;
cout << path.toUtf8().constData()<<"此病例坐标轴异常" << endl;
}
}
vtk大多数报错都是vtkSmartPoint智能指针的作用域问题!!!