Point Cloud Library (PCL)  1.12.0-dev
world_model.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
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  * Author: Raphael Favier, Technical University Eindhoven, (r.mysurname <aT> tue.nl)
37  */
38 
39 #pragma once
40 
41 #include <pcl/common/impl/common.hpp>
42 #include <pcl/filters/extract_indices.h>
43 #include <pcl/filters/filter_indices.h>
44 #include <pcl/filters/conditional_removal.h>
45 #include <pcl/point_types.h>
46 #include <pcl/io/pcd_io.h>
47 //#include <pcl/gpu/kinfu_large_scale/tsdf_buffer.h>
48 //#include <boost/graph/buffer_concepts.hpp>
49 
50 
51 namespace pcl
52 {
53  namespace kinfuLS
54  {
55  /** \brief WorldModel maintains a 3D point cloud that can be queried and updated via helper functions.\n
56  * The world is represented as a point cloud.\n
57  * When new points are added to the world, we replace old ones by the newest ones.
58  * This is achieved by setting old points to nan (for speed)
59  * \author Raphael Favier
60  */
61  template <typename PointT>
62  class WorldModel
63  {
64  public:
65 
66  using Ptr = shared_ptr<WorldModel<PointT> >;
67  using ConstPtr = shared_ptr<const WorldModel<PointT> >;
68 
70  using PointCloudPtr = typename PointCloud::Ptr;
72 
76 
77  using FieldList = typename pcl::traits::fieldList<PointT>::type;
78 
79  /** \brief Default constructor for the WorldModel.
80  */
82  world_ (new PointCloud)
83  {
84  world_->is_dense = false;
85  }
86 
87  /** \brief Clear the world.
88  */
89  void reset()
90  {
91  if(!world_->points.empty ())
92  {
93  PCL_WARN("Clearing world model\n");
94  world_->points.clear ();
95  }
96  }
97 
98  /** \brief Append a new point cloud (slice) to the world.
99  * \param[in] new_cloud the point cloud to add to the world
100  */
101  void addSlice (const PointCloudPtr new_cloud);
102 
103 
104  /** \brief Retrieve existing data from the world model, after a shift
105  * \param[in] previous_origin_x global origin of the cube on X axis, before the shift
106  * \param[in] previous_origin_y global origin of the cube on Y axis, before the shift
107  * \param[in] previous_origin_z global origin of the cube on Z axis, before the shift
108  * \param[in] offset_x shift on X, in indices
109  * \param[in] offset_y shift on Y, in indices
110  * \param[in] offset_z shift on Z, in indices
111  * \param[in] volume_x size of the cube, X axis, in indices
112  * \param[in] volume_y size of the cube, Y axis, in indices
113  * \param[in] volume_z size of the cube, Z axis, in indices
114  * \param[out] existing_slice the extracted point cloud representing the slice
115  */
116  void getExistingData(const double previous_origin_x, const double previous_origin_y, const double previous_origin_z,
117  const double offset_x, const double offset_y, const double offset_z,
118  const double volume_x, const double volume_y, const double volume_z, pcl::PointCloud<PointT> &existing_slice);
119 
120  /** \brief Give nan values to the slice of the world
121  * \param[in] origin_x global origin of the cube on X axis, before the shift
122  * \param[in] origin_y global origin of the cube on Y axis, before the shift
123  * \param[in] origin_z global origin of the cube on Z axis, before the shift
124  * \param[in] offset_x shift on X, in indices
125  * \param[in] offset_y shift on Y, in indices
126  * \param[in] offset_z shift on Z, in indices
127  * \param[in] size_x size of the cube, X axis, in indices
128  * \param[in] size_y size of the cube, Y axis, in indices
129  * \param[in] size_z size of the cube, Z axis, in indices
130  */
131  void setSliceAsNans (const double origin_x, const double origin_y, const double origin_z,
132  const double offset_x, const double offset_y, const double offset_z,
133  const int size_x, const int size_y, const int size_z);
134 
135  /** \brief Remove points with nan values from the world.
136  */
138  {
139  world_->is_dense = false;
140  pcl::Indices indices;
141  pcl::removeNaNFromPointCloud (*world_, *world_, indices);
142  }
143 
144  /** \brief Returns the world as a point cloud.
145  */
147  {
148  return (world_);
149  }
150 
151  /** \brief Returns the number of points contained in the world.
152  */
153  std::size_t getWorldSize ()
154  {
155  return (world_->size () );
156  }
157 
158  /** \brief Returns the world as two vectors of cubes of size "size" (pointclouds) and transforms
159  * \param[in] size the size of a 3D cube.
160  * \param[out] cubes a vector of point clouds representing each cube (in their original world coordinates).
161  * \param[out] transforms a vector containing the xyz position of each cube in world coordinates.
162  * \param[in] overlap optional overlap (in percent) between each cube (useful to create overlapped meshes).
163  */
164  void getWorldAsCubes (double size, std::vector<PointCloudPtr> &cubes, std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > &transforms, double overlap = 0.0);
165 
166 
167  private:
168 
169  /** \brief cloud containing our world */
170  PointCloudPtr world_;
171 
172  /** \brief set the points which index is in the indices vector to nan
173  * \param[in] cloud the cloud that contains the point to be set to nan
174  * \param[in] indices the vector of indices to set to nan
175  */
176  inline void setIndicesAsNans (PointCloudPtr cloud, IndicesConstPtr indices);
177 
178  };
179  }
180 }
pcl::ConditionAnd::Ptr
shared_ptr< ConditionAnd< PointT > > Ptr
Definition: conditional_removal.h:509
pcl
Definition: convolution.h:46
point_types.h
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: world_model.h:71
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::ConditionOrPtr
typename pcl::ConditionOr< pcl::PointXYZI >::Ptr ConditionOrPtr
Definition: world_model.h:74
pcl::IndicesConstPtr
shared_ptr< const Indices > IndicesConstPtr
Definition: pcl_base.h:59
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::FieldList
typename pcl::traits::fieldList< pcl::PointXYZI >::type FieldList
Definition: world_model.h:77
pcl::kinfuLS::WorldModel::getWorldSize
std::size_t getWorldSize()
Returns the number of points contained in the world.
Definition: world_model.h:153
pcl::PointCloud< pcl::PointXYZI >
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::FieldComparisonConstPtr
typename pcl::FieldComparison< pcl::PointXYZI >::ConstPtr FieldComparisonConstPtr
Definition: world_model.h:75
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::Ptr
shared_ptr< WorldModel< pcl::PointXYZI > > Ptr
Definition: world_model.h:66
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::ConditionAndPtr
typename pcl::ConditionAnd< pcl::PointXYZI >::Ptr ConditionAndPtr
Definition: world_model.h:73
pcl::ConditionOr::Ptr
shared_ptr< ConditionOr< PointT > > Ptr
Definition: conditional_removal.h:537
pcl::FieldComparison::ConstPtr
shared_ptr< const FieldComparison< PointT > > ConstPtr
Definition: conditional_removal.h:137
pcl::kinfuLS::WorldModel
WorldModel maintains a 3D point cloud that can be queried and updated via helper functions.
Definition: world_model.h:62
pcl::kinfuLS::WorldModel::cleanWorldFromNans
void cleanWorldFromNans()
Remove points with nan values from the world.
Definition: world_model.h:137
pcl::kinfuLS::WorldModel::reset
void reset()
Clear the world.
Definition: world_model.h:89
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::ConstPtr
shared_ptr< const WorldModel< pcl::PointXYZI > > ConstPtr
Definition: world_model.h:67
pcl::kinfuLS::WorldModel::setSliceAsNans
void setSliceAsNans(const double origin_x, const double origin_y, const double origin_z, const double offset_x, const double offset_y, const double offset_z, const int size_x, const int size_y, const int size_z)
Give nan values to the slice of the world.
Definition: world_model.hpp:275
pcl::kinfuLS::WorldModel::getWorldAsCubes
void getWorldAsCubes(double size, std::vector< PointCloudPtr > &cubes, std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &transforms, double overlap=0.0)
Returns the world as two vectors of cubes of size "size" (pointclouds) and transforms.
Definition: world_model.hpp:136
pcl::removeNaNFromPointCloud
void removeNaNFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, Indices &index)
Removes points with x, y, or z equal to NaN.
Definition: filter.hpp:46
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
pcl::kinfuLS::WorldModel::addSlice
void addSlice(const PointCloudPtr new_cloud)
Append a new point cloud (slice) to the world.
Definition: world_model.hpp:47
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
pcl::kinfuLS::WorldModel::getExistingData
void getExistingData(const double previous_origin_x, const double previous_origin_y, const double previous_origin_z, const double offset_x, const double offset_y, const double offset_z, const double volume_x, const double volume_y, const double volume_z, pcl::PointCloud< PointT > &existing_slice)
Retrieve existing data from the world model, after a shift.
Definition: world_model.hpp:63
pcl::kinfuLS::WorldModel::WorldModel
WorldModel()
Default constructor for the WorldModel.
Definition: world_model.h:81
pcl::kinfuLS::WorldModel::getWorld
PointCloudPtr getWorld()
Returns the world as a point cloud.
Definition: world_model.h:146
pcl::kinfuLS::WorldModel< pcl::PointXYZI >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: world_model.h:70