0

I am resampling the point cloud with laslib library on VS2017.The following error occurred after running in the Debug environment.I have tried to adjust the runtime in the property sheet to "multi-threaded debugging DLL(/MDd)", but this error still exists. Here is my code, please help me to see where the problem is

enter image description here

#include <fstream>
#include <liblas/liblas.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/keypoints/uniform_sampling.h>
#include <pcl/filters/voxel_grid.h>

int main()
{
    //open las file
    std::ifstream ifs("E:/temp/in/Tile_1321222320002302112.las", std::ios::in | std::ios::binary);
    liblas::ReaderFactory f;
    liblas::Reader reader = f.CreateWithStream(ifs);

    //read las head
    liblas::Header const& header = reader.GetHeader();
    int nbPoints = header.GetPointRecordsCount();

    //转换为pcl格式
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    while (reader.ReadNextPoint())
    {

        //坐标信息
        double x = reader.GetPoint().GetX();
        double y = reader.GetPoint().GetY();
        double z = reader.GetPoint().GetZ();

        //颜色信息
        uint16_t r1 = reader.GetPoint().GetColor().GetRed();
        uint16_t g1 = reader.GetPoint().GetColor().GetGreen();
        uint16_t b1 = reader.GetPoint().GetColor().GetBlue();
        uint32_t r2 = ceil(((float)r1 / 65536)*(float)256);
        uint32_t g2 = ceil(((float)g1 / 65536)*(float)256);
        uint32_t b2 = ceil(((float)b1 / 65536)*(float)256);
        uint32_t rgb = ((int)r2 << 16 | (int)g2 << 8 | (int)b2);
        pcl::PointXYZRGB thept;
        thept.x = x;
        thept.y = y;
        thept.z = z;
        thept.rgb = rgb;
        in_cloud->push_back(thept);

    }

    //采样
    //pcl::UniformSampling<pcl::PointXYZRGB> filter;
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    
    //均匀
    //filter.setInputCloud(in_cloud);
    //filter.setRadiusSearch(0.1f);
    //filter.filter(*filteredCloud);

    pcl::VoxelGrid<pcl::PointXYZRGB> filter;
    filter.setInputCloud(in_cloud);
    filter.setLeafSize(0.1f,0.1f,0.1f);
    filter.filter(*filteredCloud);
    int out_p_n = filteredCloud->size();

    //写入las文件
    std::string save_path = "E:/temp/out/";
    std::string name = "Tile_1321222320002302112.las";

    double minPt[3] = { 9999999, 9999999, 9999999 };
    double maxPt[3] = { 0, 0, 0 };

    std::ofstream ofs = std::ofstream(save_path + name, std::ios::out | std::ios::binary);
    //设置文件头、点数、格式、缩放因子、偏移量
    liblas::Header f_header;
    f_header.SetVersionMajor(1);
    f_header.SetVersionMinor(2);
    f_header.SetMin(minPt[0], minPt[1], minPt[2]);
    f_header.SetMax(maxPt[0], maxPt[1], maxPt[2]);
    f_header.SetDataFormatId(liblas::PointFormatName::ePointFormat3);
    f_header.SetOffset(0, 0, 0);
    f_header.SetScale(0.001, 0.001, 0.001);
    f_header.SetPointRecordsCount(out_p_n);
    liblas::Writer writer(ofs,f_header);
    liblas::Point point(&f_header);

    for (size_t i = 0; i < filteredCloud->size(); ++i)
    {
        double x = filteredCloud->points[i].x;
        double y = filteredCloud->points[i].y;
        double z = filteredCloud->points[i].z;
        point.SetX(x);
        point.SetY(y);
        point.SetZ(z);
        uint32_t r = (uint32_t)filteredCloud->points[i].r;
        uint32_t g = (uint32_t)filteredCloud->points[i].g;
        uint32_t b = (uint32_t)filteredCloud->points[i].b;
        liblas::Color pointColor(r, g, b);
        point.SetColor(pointColor);
        writer.WritePoint(point);
    }

    writer.SetHeader(f_header);
    ofs.flush();
    ofs.close();

    return EXIT_SUCCESS;

}
  • You want to Abort, and then go back in the call stack to point which part of your code triggered the assertion failure. You'll also see the values of the variables in the current scope. – Soleil Dec 28 '20 at 13:47
  • I found that "liblas::Header f_header; " once i add this one,the error will rise.but i don't know why and this is an important line in my code. – paobukuaideluozi Dec 28 '20 at 14:04
  • Go back again in the call stack several times until you reach your code. – Soleil Dec 28 '20 at 14:06
  • i'm sorry ,i am a new guy for c++.can u tell me exactly what should i do to solve this problem?should i chang my code? – paobukuaideluozi Dec 28 '20 at 14:12
  • You need to reach first the part of your code that is at the origin of the problem; here the problem manifests after calling library functions, which are probably fine, so you go back in the call stack to reach your code and its context, then you can examine what you're doing wrong. Once you know, you can modify your code (or you data, but you should check if you data is acceptable first in the code) consequently. – Soleil Dec 28 '20 at 14:19
  • Are you saying That I should break the point, then run the program, and see the health of each line of code in the call stack window? – paobukuaideluozi Dec 28 '20 at 14:34
  • Yes, but not each, only the first time (as debugger, or the last time in runtime) you reach your code; you should have everything you need to understand what is wrong there. – Soleil Dec 28 '20 at 14:37
  • I run the code in turn as described above.No exceptions were found in the call stack window. When the program finishes running the last line of code, the error in the picture pops up – paobukuaideluozi Dec 28 '20 at 14:37
  • My bad, you want you use "retry", not "abort", then you'll enter the callstack. – Soleil Dec 28 '20 at 14:41
  • Do you mean I don't need a break point, just click "retry" when the error is prompted and look for the error in the call stack window? – paobukuaideluozi Dec 28 '20 at 14:46
  • Exactly, absolutely, and ignore anything that is not your code. Then you'll be able to hover the different variables of your code (or inspect that in the current scope https://learn.microsoft.com/en-us/visualstudio/debugger/autos-and-locals-windows?view=vs-2019). (Supposing you're using Visual studio). – Soleil Dec 28 '20 at 14:51
  • After popping up an error, I click "retry".The program shows that it is running, but the call stack window shows nothing。yes,i'm using Visual studio2017 – paobukuaideluozi Dec 28 '20 at 14:53
  • Are you in debug mode ? – Soleil Dec 28 '20 at 14:54
  • yes,it is.debug mode ,x64. it just stop there – paobukuaideluozi Dec 28 '20 at 14:56

0 Answers0