PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.89k stars 4.61k forks source link

[compile error] "int __cdecl pcl::internal::optimizeModelCoefficientsSphere(class Eigen::Matrix<float,-1,1,0,-1,1> &,class Eigen::Array<float,-1,1,0,-1,1> const" #5984

Closed 181404010226 closed 6 months ago

181404010226 commented 6 months ago

environment: win10 vcpkg visual studio 2022 code:

define _CRT_SECURE_NO_WARNINGS

define PCL_NO_PRECOMPILE

include <pcl/memory.h>

include <pcl/pcl_macros.h>

include <pcl/point_types.h>

include <pcl/point_cloud.h>

include <pcl/io/pcd_io.h>

struct EIGEN_ALIGN16 LabeledPoint { PCL_ADD_POINT4D; // 添加pcl内置的XYZ字段 float label; // 用于标记的额外字段 PCL_MAKE_ALIGNED_OPERATOR_NEW // 确保新类型的内存对齐 }; // 强制SSE对齐

POINT_CLOUD_REGISTER_POINT_STRUCT(LabeledPoint, // 注册新的点类型 (float, x, x) (float, y, y) (float, z, z) (float, label, label) )

include <pcl/segmentation/sac_segmentation.h>

include <pcl/ModelCoefficients.h>

int main() { pcl::PointCloud::Ptr cloud(new pcl::PointCloud);

// Fill in the cloud data
cloud->width = 15;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);

// Generate the data
for (auto& point : *cloud)
{
    point.x = 1024 * rand() / (RAND_MAX + 1.0f);
    point.y = 1024 * rand() / (RAND_MAX + 1.0f);
    point.z = 1.0;
}

// Set a few outliers
(*cloud)[0].z = 2.0;
(*cloud)[3].z = -2.0;
(*cloud)[6].z = 4.0;

std::cerr << "Point cloud data: " << cloud->size() << " points" << std::endl;
for (const auto& point : *cloud)
    std::cerr << "    " << point.x << " "
    << point.y << " "
    << point.z << std::endl;

pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
// Create the segmentation object
pcl::SACSegmentation<LabeledPoint> seg;
// Mandatory
seg.setModelType(pcl::SACMODEL_PLANE);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setDistanceThreshold(0.01);

seg.setInputCloud(cloud);
seg.segment(*inliers, *coefficients);

if (inliers->indices.size() == 0)
{
    PCL_ERROR("Could not estimate a planar model for the given dataset.\n");
    return (-1);
}

std::cerr << "Model coefficients: " << coefficients->values[0] << " "
    << coefficients->values[1] << " "
    << coefficients->values[2] << " "
    << coefficients->values[3] << std::endl;

std::cerr << "Model inliers: " << inliers->indices.size() << std::endl;
for (const auto& idx : inliers->indices)
    std::cerr << idx << "    " << cloud->points[idx].x << " "
    << cloud->points[idx].y << " "
    << cloud->points[idx].z << std::endl;

return (0);

}

181404010226 commented 6 months ago

i happened when i use custom point cloud type and segmentation.

mvieth commented 6 months ago

@181404010226 This is fixed on the PCL master branch ( #5926 ), but not yet on vcpkg. I will create a fix for vcpkg in a few days.

mvieth commented 6 months ago

Fixed in vcpkg by https://github.com/microsoft/vcpkg/commit/fbc542fd5cfc861e0db67c297ad924ecd942a6dc