Skip to content

C++ SDK Header files including problems in Windows #665

@dwniaoniao

Description

@dwniaoniao

I'm working with a C++ project base on Ouster SDK(0.15.1),
It originally designed for Ubuntu and work normally and now
I'm trying to port it into Windows. Things went well until I
decide to add a new feature into this project, writing and
reading OSF files, built failed in Visual Studio with hundreds
of errors. The same code for this feature built success and work
normally in Ubuntu. Found that these problem may be caused by
incorrect header files including.
Built the example code osf_reader_example.cpp success and work
normally in Windows until I change header file include lines as
bellow:

#include "ouster/osf/reader.h"
#include "ouster/osf/stream_lidar_scan.h"

to:

#include "ouster/sensor_packet_source.h"
#include "ouster/osf/reader.h"
#include "ouster/osf/stream_lidar_scan.h"

The same code build success in ubuntu but fail in Windows.
I also create a simple demo, use the sensor_scan_source API
to get a Lidar scan and the use the Viz API to display the
point cloud and 2d image. This is my code:

#include <iostream>
#include "ouster/point_viz.h"
#include "ouster/sensor_scan_source.h"

int main(int argc, char *argv[])
{
    if (argc < 2) {
        std::cerr << "\n\nUsage: scan_viz <sensor_hostname> "
                  << std::endl;

        return argc == 1 ? EXIT_SUCCESS : EXIT_FAILURE;
    }

    ouster::viz::PointViz viz("scan_viz");
    ouster::viz::add_default_controls(viz);
    ouster::sensor::init_logger("info");

    std::string sensor_hostname = argv[1];
    ouster::sensor::sensor_config config;
    config.udp_dest = "@auto";
    config.lidar_mode = ouster::sensor::MODE_512x20;
    config.operating_mode = ouster::sensor::OPERATING_NORMAL; 
    ouster::sensor::Sensor s(sensor_hostname, config);
    std::vector<ouster::sensor::Sensor> sensors;
    sensors.push_back(s);
    ouster::sensor::SensorScanSource source(sensors);

    const auto &info_v = source.sensor_info();
    auto info = info_v[0];
    std::cerr << "Sensor " << info->sn << " Information:" << std::endl;
    size_t w = info->format.columns_per_frame;
    size_t h = info->format.pixels_per_column;
    ouster::sensor::ColumnWindow column_window = info->format.column_window;
    std::cerr << "  Firmware version:  " << info->image_rev
              << "\n  Serial number:     " << info->sn
              << "\n  Product line:      " << info->prod_line
              << "\n  Scan dimensions:   " << w << " x " << h
              << "\n  Column window:     [" << column_window.first << ", "
              << column_window.second << "]" << std::endl;

    std::pair<int, std::unique_ptr<ouster::LidarScan>> result;
    do{
        result = source.get_scan();
    } while(!(result.second && result.second->complete()));
    auto &scan = *result.second;
    auto xyz_lut = ouster::make_xyz_lut(*info, false);
    auto xyzs = ouster::cartesian(scan, xyz_lut);
    auto n_valid_returns = (scan.field<uint32_t>(ouster::sensor::ChanField::RANGE) != 0).count();

    std::vector<float> points(n_valid_returns * 3);
    size_t j = 0;
    for(size_t i = 0; i < xyzs.rows(); i++){
        auto xyz = xyzs.row(i);
        if(!xyz.isApproxToConstant(0.0)){
            points[j] = static_cast<float>(xyz(0));
            points[j + n_valid_returns] = static_cast<float>(xyz(1));
            points[j + n_valid_returns * 2] = static_cast<float>(xyz(2));
            j++;
        }
    }

    auto cloud = std::make_shared<ouster::viz::Cloud>(n_valid_returns);
    viz.add(cloud);
    cloud->set_xyz(points.data());

    auto img = std::make_shared<ouster::viz::Image>();
    std::vector<float> img_data(info->w() * info->h());
    auto ref = scan.field<uint8_t>(ouster::sensor::ChanField::REFLECTIVITY);
    auto ref_destaggered = ouster::destagger<uint8_t>(ref, info->format.pixel_shift_by_row);
    for(size_t i = 0; i < ref_destaggered.rows(); i++){
        for(size_t j = 0; j < ref_destaggered.cols(); j++){
            img_data[info->w() * i + j] = ref_destaggered(i, j) / 255.0;
        }
    }
    viz.add(img);
    img->set_position(-1, 1, 1 - static_cast<float>(info->h()) / static_cast<float>(info->w()), 1);
    img->set_image(info->w(), info->h(), img_data.data());

    viz.update();
    std::cout << "Running rendering loop: press ESC to exit" << std::endl;
    viz.run();
    std::cout << "Window closed, exiting" << std::endl;

    return EXIT_SUCCESS;
}

The above code built and work well no matter in Ubuntu or Windows.
Now I switch the positions of the header include lines:

#include "ouster/point_viz.h"
#include "ouster/sensor_scan_source.h"

into:

#include "ouster/sensor_scan_source.h"
#include "ouster/point_viz.h"

then it only built and work success in Ubuntu.

Any ideas or advices for such problems in using SDK with Windows?
I'm newbie to C++ programming.

Model: OS1-64-rev06
OS: Windows 11
Tools: Visual Studio 2022
CMake
vcpkg(lastest master commit)
Ouster SDK 0.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions