1  /*
2  * Software License Agreement  (BSD License)
3  *
4  *  Point Cloud Library  (PCL) - www.pointclouds.org
5  *  Copyright  (c) 2012, Jeremie Papon.
6  *
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *
13  *   * Redistributions of source code must retain the above copyright
14  *     notice, this list of conditions and the following disclaimer.
15  *   * Redistributions in binary form must reproduce the above
16  *     copyright notice, this list of conditions and the following
17  *     disclaimer in the documentation and/or other materials provided
18  *     with the distribution.
19  *   * Neither the name of Willow Garage, Inc. nor the names of its
20  *     contributors may be used to endorse or promote products derived
21  *     from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  (INCLUDING,
29  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  *  LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  *  POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef IMPL_CLOUD_ITEM_H_
39 #define IMPL_CLOUD_ITEM_H_
40 
41 #include <pcl/apps/cloud_composer/items/cloud_item.h>
42 #include <pcl/memory.h>  // for pcl::make_shared
43 #include <pcl/point_cloud.h>
44 #include <pcl/impl/instantiate.hpp>
45 
46 template <typename PointT> void
printNumPoints() const47 pcl::cloud_composer::CloudItem::printNumPoints () const
48 {
49   QVariant variant = this->data (ItemDataRole::CLOUD_TEMPLATED);
50   typename PointCloud<PointT>::Ptr cloud;
51   if ( variant.canConvert <typename PointCloud<PointT>::Ptr> () )
52   {
53     cloud = variant.value <typename PointCloud<PointT>::Ptr> ();
54   }
55   else
56   {
57     qWarning () << "Attempted to cast to template type which does not exist in this item!";
58     return;
59   }
60 
61   qDebug () << "CLOUD HAS WIDTH = "<< cloud->width;
62 
63 }
64 
65 
66 
67 template <typename PointT> pcl::cloud_composer::CloudItem*
createCloudItemFromTemplate(const QString & name,typename PointCloud<PointT>::Ptr cloud_ptr)68 pcl::cloud_composer::CloudItem::createCloudItemFromTemplate (const QString& name, typename PointCloud<PointT>::Ptr cloud_ptr)
69 {
70   pcl::PCLPointCloud2::Ptr cloud_blob = pcl::make_shared <pcl::PCLPointCloud2> ();
71   toPCLPointCloud2 (*cloud_ptr, *cloud_blob);
72   CloudItem* cloud_item = new CloudItem ( name, cloud_blob,  Eigen::Vector4f (), Eigen::Quaternionf (), false);
73   cloud_item->setData (QVariant::fromValue(cloud_ptr), ItemDataRole::CLOUD_TEMPLATED);
74   cloud_item->setPointType<PointT> ();
75   return cloud_item;
76 }
77 
78 
79 #define PCL_INSTANTIATE_createCloudItemFromTemplate(T) template pcl::cloud_composer::CloudItem* pcl::cloud_composer::CloudItem::createCloudItemFromTemplate<T>(const QString, typename PointCloud<PointT>::Ptr);
80 
81 #define PCL_INSTANTIATE_printNumPoints(T) template void pcl::cloud_composer::CloudItem::getNumPoints<T>();
82 
83 #endif
84