Tuesday, February 26, 2013

Install PCL and first project in XCode

PCL (Point Cloud Library) is getting more popular these days. It's good for Kinect users and might be also helpful for visualization usages as well.

I used to attempt to install the PCL, couple months ago, however at that time it's not very successful. This time, it works. For my record and for others who may interested, I will list the details below.

1. Following the instruction in: http://pointclouds.org/documentation/tutorials/compiling_pcl_macosx.php#compiling-pcl-macosx
till installing Qhull.
2. Install and download libusb, openNI and sense from the following webpage ( do not install libusb from macports):
http://pointclouds.org/downloads/macosx.html
3. Build PCL as the instruction in Step 1 webpage.

The first project in Xcode:

0.1 Switch Compiler for C/C++/Objective-C from Apple LLVM compiler 4.2 -> LLVM GCC 4.2

1. adding the following entries into "Header Search Paths"
1.1 /usr/local/include/pcl-1.7
1.2 /opt/local/include
1.3 /opt/local/include/eigen3
1.4 /opt/local/include/vtk-5.10



2. Adding "New Group", named: boost, right-click new created "boost" folder, and Add File to project:
locate file: /opt/local/lib/libboost_system-mt.dylib

3. Adding "New Group", named: pcl, right-click new created "pcl" folder, and Add File to project:
locate file: ($whereBuildPCL)/build/lib/libpcl_io.1.7.0.dylib, and ($whereBuildPCL)/build/lib/libpcl_common.1.7.0.dylib

4. input the following script into main.cpp


#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int main(int argc, const char * argv[])
{
    pcl::PointCloud<pcl::PointXYZ> cloud;
    // fill in the cloud data
    cloud.width = 5;
    cloud.height = 1;
    cloud.is_dense = false;
    cloud.points.resize(cloud.width * cloud.height);
    
    for (size_t i = 0; i < cloud.points.size(); ++i){
        cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    }
    
    pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
    std::cerr << "Saved " << cloud.points.size() << " data points to test_pcd.pcd." << std::endl;
    
    for (size_t i = 0; i < cloud.points.size(); ++i)
        std::cerr << "   " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
    
    return 0;
}

5. Find out the output .pcd file 
5.1 Open Organizer: (Window->Organizer)
5.2 find your Projects, right click the right arrow next to your "Derived Data"
5.3 Build/Products/Debug/test_pcd.pcd


5 comments:

  1. Hello,

    I am trying to do the same thing but I get an error. I installed the pre-built binaries and it looks like the version I have is pcl 1.6. The error I get is "ld: library not found for -lpcl_io.1.6.0" , I also get 44 warnings about " warning: invalid access to non-static data member 'pcl::_PointSurfel::::::confidence' of NULL object". Do you have any idea what I am doing wrong?




    ReplyDelete
    Replies
    1. Hi, sorry, I actually haven't used pre-built library before. I am just guessing:

      you may not add the pcl_io.1.6.0.dylib in step 3

      Best,

      Delete
  2. Hello, working hard to get PCL working along your details ( thanks for doing this BTW!)... I am learning the Xcode / coding world and am wondering how to switch compiler from the default Apple LLVM to the LLVM GCC 4.2... your help is greatly appreciated.

    Thank you!

    ReplyDelete
  3. hello,

    i have a problem with the make command within the build of the pcl.

    this is what i get in the terminal:

    /usr/local/include/boost_1_55_0/boost/atomic/detail/gcc-atomic.hpp:961:64: error:
    no matching constructor for initialization of 'storage_type' (aka
    'boost::atomics::detail::storage128_type')
    explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
    ^ ~
    i am new to pcl, what can i do?
    thank you so much.

    -
    matthias

    ReplyDelete
  4. Hi Binlong,

    Thanks for this guide. Unfortunately I am having problem and I could not solve it. As an additional info, I tried to compile it via make, again I got particular error that Xcode gave.

    The errors are:

    /usr/local/include/pcl-1.6/pcl/common/eigen.h:339:28: error: no member named
    'sqrt' in namespace 'Eigen::internal'; did you mean simply 'sqrt'?
    eigenvector = vec1 / Eigen::internal::sqrt (len1);
    ^~~~~~~~~~~~~~~~~
    /usr/local/include/pcl-1.6/pcl/common/eigen.h:96:3: note: 'sqrt' declared here
    sqrt (const Scalar &val)
    ^
    /usr/local/include/pcl-1.6/pcl/common/eigen.h:341:28: error: no member named
    'sqrt' in namespace 'Eigen::internal'; did you mean simply 'sqrt'?
    eigenvector = vec2 / Eigen::internal::sqrt (len2);
    ^~~~~~~~~~~~~~~~~
    /usr/local/include/pcl-1.6/pcl/common/eigen.h:96:3: note: 'sqrt' declared here
    sqrt (const Scalar &val)
    .
    .
    .

    Could you have any suggestions about this issue?

    Thank you in advance.

    Giray

    ReplyDelete

prettify