title: Intersection of PointClouds using PCL
body: <p>Let's say I have two different <code>pcl::PointCloud&lt;pcl::PointXYZL&gt;</code> (altough the point type doesn't really matters), <code>c1</code> and <code>c2</code>.</p>
  
  <p><strong>I'd like to find the intersection of these two pointclouds.</strong>
  By intersection I mean the pointcloud <code>inter</code> constructed such that a point <code>pi</code> from <code>c1</code> is inserted in <code>inter</code> if (and only if) a point <code>pj</code> exists in <code>c2</code> and</p>
  
  <pre><code>pi.x == pj.x &amp;&amp; pi.y == pj.y &amp;&amp; pi.z == pj.z
  </code></pre>
  
  <p>At the moment I'm using the following functions to achieve this:</p>
  
  <pre><code>#include &lt;pcl/point_cloud.h&gt;
  #include &lt;pcl/point_types.h&gt;
  
  using namespace pcl;
  
  typedef PointXYZL PointLT;
  typedef PointCloud&lt;PointLT&gt; PointLCloudT;
  
  bool contains(PointLCloudT::Ptr c, PointLT p) {
      PointLCloudT::iterator it = c-&gt;begin();
      for (; it != c-&gt;end(); ++it) {
          if (it-&gt;x == p.x &amp;&amp; it-&gt;y == p.y &amp;&amp; it-&gt;z == p.z)
              return true;
      }
      return false;
  }
  
  PointLCloudT::Ptr intersection(PointLCloudT::Ptr c1,
          PointLCloudT::Ptr c2) {
      PointLCloudT::Ptr inter;
      PointLCloudT::iterator it = c1-&gt;begin();
      for (; it != c1-&gt;end(); ++it) {
          if (contains(c2, *it))
              inter-&gt;push_back(*it);
      }
  
      return inter;
  }
  </code></pre>
  
  <p>I'd like to know if there's a standard (and possibly more efficient) way of doing this?</p>
  
  <p>I haven't found anything about this in the <a href="http://docs.pointclouds.org/1.7.2/" rel="noreferrer">official documentation</a>, but maybe I'm missing something.</p>
  
  <p>Thank you.</p>