PointCloudLibrary / pcl

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

[compile error] "严重性 代码 说明 项目 文件 行 禁止显示状态 错误 LNK2001 无法解析的外部符号 "public: class ON_3dVector __cdecl ON_Curve::CurvatureAt(double)const " (?CurvatureAt@ON_Curve@@QEBA?AVON_3dVector@@N@Z) Project1 D:\pcltest\Project1\Project1\GFmain.obj 1 " #5240

Closed CaiHuFan closed 2 years ago

CaiHuFan commented 2 years ago

include <pcl/surface/on_nurbs/fitting_curve_2d.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_pdm.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_tdm.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_sdm.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_apdm.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_asdm.h>

include <pcl/surface/on_nurbs/fitting_curve_2d_atdm.h>

include <pcl/surface/on_nurbs/triangulation.h>

include <pcl/surface/3rdparty/opennurbs/opennurbs_nurbscurve.h>

include <pcl/surface/3rdparty/opennurbs/opennurbs_curve.h>

include <pcl/io/ply_io.h>

include <pcl/visualization/pcl_visualizer.h>

pcl::visualization::PCLVisualizer viewer("Curve Fitting 2D");

void PointCloud2Vector2d(pcl::PointCloud::Ptr cloud, pcl::on_nurbs::vector_vec2d &data) { for (const auto &p : *cloud) { if (!std::isnan(p.x) && !std::isnan(p.y)) data.emplace_back(p.x, p.y); } }

void VisualizeCurve(ON_NurbsCurve &curve, double r, double g, double b, bool show_cps) { ON_Curve* curve_1; pcl::PointCloud::Ptr cloud1(new pcl::PointCloud); pcl::PointCloud::Ptr cloud3(new pcl::PointCloud); pcl::PointCloud::Ptr cloud4(new pcl::PointCloud); curve_1=curve.DuplicateCurve();

pcl::on_nurbs::Triangulation::convertCurve2PointCloud(curve, cloud1, 8);

//cout<<curve.;
cout << (cloud1->points.size()) / 2;
double distance[50000];
double a[50000];
int k = 0;
int n = 0;
pcl::PointXYZRGB point;
ON_3dVector p;
ON_3dPoint q;
double t = 0.0;
for (int i = 0; i < ((cloud1->points.size()) / 2)-1; i++)
{

    curve_1->CurvatureAt(t);
    point.x = cloud1->points[i].x;
    point.y = cloud1->points[i].y;
    point.z = cloud1->points[i].z;
    point.r = cloud1->points[i].r;
    point.g = cloud1->points[i].g;
    point.b = cloud1->points[i].b;
    //cout<< cloud1->points[i].y<<endl;
    cloud3->push_back(point);
    /*pcl::PointXYZRGB &p1 = cloud->at(i);
    pcl::PointXYZRGB &p2 = cloud->at(i + 1);*/
    /*pcl::PointXYZRGB &p2 = cloud->at(i + 2);
    pcl::PointXYZRGB &p2 = cloud->at(i + 3);*/
    if ((cloud1->points[i].y) - (cloud1->points[i + 1].y) > 0)
    {
        distance[n++] = -1;
    }
    else if ((cloud1->points[i].y) - (cloud1->points[i + 1].y) < 0)
    {
        distance[n++] = 1;
    }
    else if ((cloud1->points[i].y) - (cloud1->points[i + 1].y) == 0)
    {
        distance[n++] = 0;
    }
    cout << distance[i]<<endl;
}

for (int j = 1; j < n; j++)
{
    //cout << distance[j] << endl;
    if (distance[j] != 0 && distance[j+1] != 0&& distance[j] != distance[j + 1])
    {
        cout << (point.x = double((cloud1->points[j].x + cloud1->points[j + 2].x) / 2)) << " "
            << (point.y = double((cloud1->points[j].y + cloud1->points[j + 2].y) / 2)) << endl;
        point.z = 0;
        k++;
        cloud4->push_back(point);
    }
}
cout << k << endl;
viewer.addPointCloud(cloud3, "cloud3");

viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "cloud3");
//viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 0, 0, "cloud3");
viewer.addPointCloud(cloud4, "cloud4");

viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "cloud4");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 0, 0, "cloud3");
if (show_cps)
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cps(new pcl::PointCloud<pcl::PointXYZ>);
    for (int i = 0; i < curve.CVCount(); i++)
    {
        ON_3dPoint cp;
        curve.GetCV(i, cp);

        pcl::PointXYZ p;
        p.x = float(cp.x);
        p.y = float(cp.y);
        p.z = float(cp.z);
        cps->push_back(p);
    }
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler(cps, 255 * r, 255 * g, 255 * b);
    viewer.addPointCloud<pcl::PointXYZ>(cps, handler, "cloud_cps");
}

}

int main(int argc, char *argv[]) { std::string pcd_file;

if (argc > 1)
{
    pcd_file = argv[1];
}
else
{
    printf("\nUsage: pcl_example_nurbs_fitting_curve pcd-file \n\n");
    printf("  pcd-file    point-cloud file\n");
    exit(0);
}

// #################### LOAD FILE #########################
printf("  loading %s\n", pcd_file.c_str());
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud2;

if (pcl::io::loadPLYFile(pcd_file, cloud2) == -1)
    throw std::runtime_error("  PCD file not found.");

fromPCLPointCloud2(cloud2, *cloud);
pcl::PointCloud<pcl::PointXYZ>::iterator it_1;
//for (it_1 = cloud->begin(); it_1 != cloud->end();)
//{
//  float x = 0;
//  float y = it_1->y;
//  float z = it_1->z;

//  it_1->x = z;
//  it_1->y = y;
//  it_1->z = x;

//  ++it_1;
//}
// convert to NURBS data structure
pcl::on_nurbs::NurbsDataCurve2d data;
PointCloud2Vector2d(cloud, data.interior);

// #################### CURVE PARAMETERS #########################
unsigned order(3);
unsigned n_control_points(22);

pcl::on_nurbs::FittingCurve2d::Parameter curve_params;
curve_params.smoothness = 0.000001;
curve_params.rScale = 1.0;

// #################### CURVE FITTING #########################
ON_NurbsCurve curve = pcl::on_nurbs::FittingCurve2d::initNurbsPCA(order, &data, n_control_points);

pcl::on_nurbs::FittingCurve2d fit(&data, curve);
fit.assemble(curve_params);

/*Eigen::Vector2d fix1(0.1, 0.1);
Eigen::Vector2d fix2(1.0, 0.0);
  fit.addControlPointConstraint (0, fix1, 100.0);
  fit.addControlPointConstraint (curve.CVCount () - 1, fix2, 100.0);*/

fit.solve();
double t = 0.0;

VisualizeCurve(fit.m_nurbs, 1.0, 0.0, 0.0, true);

viewer.addCoordinateSystem(0.1);
viewer.setSize(800, 600);
viewer.setBackgroundColor(255, 255, 255);
viewer.addPointCloud<pcl::PointXYZ>(cloud, "cloud");

viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "cloud");
while (!viewer.wasStopped())
{
    viewer.spinOnce(100);
    boost::this_thread::sleep(boost::posix_time::microseconds(10000));
}
return 0;

}

mvieth commented 2 years ago

Which operating system do you use? Which PCL version? And how did you install it? How do you compile your own program? If you use CMake, please post the CMakeLists.txt here.

CaiHuFan commented 2 years ago

windows+pcl1.9.1+vs2017 Release x64

CaiHuFan commented 2 years ago

Which operating system do you use? Which PCL version? And how did you install it? How do you compile your own program? If you use CMake, please post the CMakeLists.txt here. I don't know why this function doesn't work. Is there a problem with the input parameters or something

include <pcl/surface/3rdparty/opennurbs/opennurbs_curve.h>

ON_3dVector CurvatureAt( double t ) const;

mvieth commented 2 years ago

How did you install PCL? Do you use CMake? If yes, please post the CMakeLists.txt. There is probably something wrong with how you link to the PCL libraries

CaiHuFan commented 2 years ago

How did you install PCL? Do you use CMake? If yes, please post the CMakeLists.txt. There is probably something wrong with how you link to the PCL libraries

I just used PCL-1.9.1-AllInOne-msvc2017-win64.exe and don't used CMake

mvieth commented 2 years ago

@CaiHuFan If you don't use CMake, how do you build your own project/your own code? With Visual Studio (Code)? Then please show screenshots of your project configuration.

mvieth commented 2 years ago

My best guess is that the on-nurbs stuff is not included in the all-in-one installer: https://pcl.readthedocs.io/projects/tutorials/en/master/bspline_fitting.html#pcl-installation-settings