#include pcl/io/pcd_io.h causes trouble

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

#include pcl/io/pcd_io.h causes trouble

!Genious
Hello, my problem is that I get an AccessViolationException the minute I add pcd_io.h and start using it like, loading a file.... I really need to use it. The thing is this happens in 1 project but not the other.
I know it might be a solid solution to restart this project, but I won't do that.
It has been suggested that it might be the multithreading.
my question:
is this something recognisable and if so, how to fix it?
Reply | Threaded
Open this post in threaded view
|

Re: #include pcl/io/pcd_io.h causes trouble

aichim
Administrator
Hi,

If you do not give us any code, it is impossible to help you.

Cheers,
Alex

On Mar 12, 2013, at 12:35 AM, !Genious <[hidden email]> wrote:

> Hello, my problem is that I get an AccessViolationException the minute I add
> pcd_io.h and start using it like, loading a file.... I really need to use
> it. The thing is this happens in 1 project but not the other.
> I know it might be a solid solution to restart this project, but I won't do
> that.
> It has been suggested that it might be the multithreading.
> my question:
> is this something recognisable and if so, how to fix it?
>
>
>
> --
> View this message in context: http://www.pcl-users.org/include-pcl-io-pcd-io-h-causes-trouble-tp4026686.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: #include pcl/io/pcd_io.h causes trouble

!Genious
This post was updated on .
ok this is the method in which I am positive the AccessViolation takes place in combination with the include:

void MyPclCalc::setCloud(int clr_width, int clr_height, int dpth_width, int dpth_height, int frameId, float clr_focal_x, float clr_focal_y, float dpth_focal_x, float dpth_focal_y, unsigned char *image, unsigned short depth_image[])
{
        static unsigned rgb_array_size = 0;
        static unsigned char* rgb_array(0);
        static unsigned char* rgb_buffer = 0;

        pcl::PointCloud<PointT> tempCloud;

        #undef max
        tempCloud.height = std::max(clr_height, dpth_height);
        tempCloud.width = std::max(clr_width, dpth_width);
        tempCloud.is_dense = false;

        tempCloud.points.resize(tempCloud.height * tempCloud.width);

        register float constant_x = 1.0f / dpth_focal_x;
        register float constant_y = 1.0f / dpth_focal_x;
        register float centerX = float(dpth_width >> 1);
        register float centerY = float(dpth_height >> 1);

        if (pcl_isfinite(clr_focal_x))
                constant_x = 1.0f / static_cast<float>(clr_focal_x);

        if (pcl_isfinite(clr_focal_y))
                constant_y = 1.0f / static_cast<float>(clr_focal_x);

        if (pcl_isfinite(clr_width / 2))
                centerX =  static_cast<float> (clr_width / 2);

        if (pcl_isfinite(clr_height / 2))
                centerY =  static_cast<float>(clr_height / 2);

        if (rgb_array_size < clr_width * clr_height * 4)
        {
                rgb_array_size = clr_width * clr_height * 4;
                rgb_array = new unsigned char[rgb_array_size];
                rgb_buffer = image;
        }

        float bad_point = std::numeric_limits<float>::quiet_NaN();
        unsigned step = tempCloud.width / dpth_width;
        unsigned skip = tempCloud.width * step - tempCloud.width;

        int value_idx = 0;
        int point_idx = 0;
        for (int v = 0; v < dpth_height; ++v, point_idx += skip)
        {
                for (register int u = 0; u < dpth_width; ++u, ++value_idx, point_idx += step)
                {
                        PointT& pt = tempCloud.points[point_idx];
                        if (depth_image[value_idx] != 0)
                        {
                                pt.z = depth_image[value_idx] * 0.001f;
                                pt.x = (static_cast<float>(u) - centerX) * pt.z * constant_x;
                                pt.y = (static_cast<float>(v) - centerY) * pt.z * constant_y;
                        }
                        else
                        {
                                pt.x = pt.y = pt.z = bad_point;
                        }
                }
        }
        step = tempCloud.width / clr_width;
        skip = tempCloud.width * step - tempCloud.width;

        value_idx = 0;
        point_idx = 0;

        for (unsigned yIdx = 0; yIdx < clr_height; ++yIdx, point_idx += skip)
        {
                for (unsigned xIdx = 0; xIdx < clr_width; ++xIdx, point_idx += step, value_idx += 4)
                {
                        PointT& pt = tempCloud.points[point_idx];
                        pt.b = rgb_buffer[value_idx];
                        pt.g = rgb_buffer[value_idx + 1];
                        pt.r = rgb_buffer[value_idx + 2];
                }
        }
        cloud = tempCloud;
        PCDSaver();
        ASCSaver();
}


if you wonder why I am doing this in the first place, I am replacing OpenNi for the kinect SDK and need my own grabber.

the code for actually using pcd_io.h:

void testMesher(pcl::PointCloud<PointT> inputCloud)
{
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
        pcl::io::loadPCDFile<pcl::PointXYZ> ("test_pcd.pcd", *cloud);
        pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
        pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
        pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
        tree->setInputCloud (cloud);
        n.setInputCloud (cloud);
        n.setSearchMethod (tree);
        n.setKSearch (20);
        n.compute (*normals);
        //* normals should not contain the point normals + surface curvatures

        // Concatenate the XYZ and normal fields*
        pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
        pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
        //* cloud_with_normals = cloud + normals

        // Create search tree*
        pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
        tree2->setInputCloud (cloud_with_normals);

        // Initialize objects
        pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
        pcl::PolygonMesh triangles;

        // Set the maximum distance between connected points (maximum edge length)
        gp3.setSearchRadius (0.025);

        // Set typical values for the parameters
        gp3.setMu (2.5);
        gp3.setMaximumNearestNeighbors (100);
        gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
        gp3.setMinimumAngle(M_PI/18); // 10 degrees
        gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
        gp3.setNormalConsistency(false);

        // Get result
        gp3.setInputCloud (cloud_with_normals);
        gp3.setSearchMethod (tree2);
        gp3.reconstruct (triangles);

        // Additional vertex information
        std::vector<int> parts = gp3.getPartIDs();
        std::vector<int> states = gp3.getPointStates();
}