报错:vtkSTLReader (0000027753736D90): A FileName must be specified.;vtkCompositeDataPipeline (00000277

完整报错

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<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
vtkSmartPointer<vtkPolyData> inputPolyData = reader->GetOutput();

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<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;
    }
}

解决bug有感

vtk大多数报错都是vtkSmartPoint智能指针的作用域问题!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

踏过山河,踏过海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值