Point Cloud Library (PCL)  1.10.0
outofcore_base_data.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, 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  * $Id$
37  */
38 
39 #pragma once
40 
41 #include <pcl/pcl_macros.h>
42 #include <pcl/outofcore/boost.h>
43 #include <pcl/outofcore/cJSON.h>
44 
45 #include <pcl/common/eigen.h>
46 
47 #include <pcl/outofcore/metadata.h>
48 
49 //standard library
50 #include <string>
51 
52 namespace pcl
53 {
54  namespace outofcore
55  {
56  /** \class OutofcoreOctreeBaseMetadata
57  *
58  * \brief Encapsulated class to read JSON metadata into memory,
59  * and write the JSON metadata associated with the octree root
60  * node. This is global information that is not the same as the
61  * metadata for the root node. Inherits OutofcoreAbstractMetadata
62  * interface for metadata in \b pcl_outofcore.
63 
64  *
65  * This class encapsulates the outofcore base metadata
66  * serialization/deserialization. At the time it was written,
67  * this depended on cJSON to write JSON objects to disk. This
68  * class can be extended to have arbitrary JSON ascii metadata
69  * fields saved to the metadata object file on disk. The class
70  * has been encapuslated to abstract the detailso of the on-disk
71  * format from the outofcore implementation. For example, the
72  * format could be changed to XML/YAML, or any dynamic format at
73  * some point.
74  *
75  * The JSON file is formatted in the following way:
76  * \verbatim
77  {
78  "name": "nameoftree",
79  "version": 3,
80  "pointtype": "urp", #(needs to be changed*)
81  "lod": 3, #(depth of the tree
82  "numpts": [X0, X1, X2, ..., XD], #total number of points at each LOD
83  "coord_system": "ECEF" #the tree is not affected by this value
84  }
85  \endverbatim
86  *
87  * Any properties not stored in the metadata file are computed
88  * when the file is loaded. By convention, and for historical
89  * reasons from the original Urban Robotics implementation, the
90  * JSON file representing the overall tree is a JSON file named
91  * with the ".octree" extension.
92  *
93  * \ingroup outofcore
94  * \author Stephen Fox (foxstephend@gmail.com)
95  */
97  {
98  public:
101 
102  /** \brief Empty constructor */
104  /** \brief Load metadata from disk
105  *
106  * \param[in] path_arg Location of JSON metadata file to load from disk
107  */
108  OutofcoreOctreeBaseMetadata (const boost::filesystem::path& path_arg);
109  /** \brief Default destructor*/
111 
112  /** \brief Copy constructor */
114 
115  /** \brief et the outofcore version read from the "version" field of the JSON object */
116  int
117  getOutofcoreVersion () const;
118  /** \brief Set the outofcore version stored in the "version" field of the JSON object */
119  void
120  setOutofcoreVersion (const int version);
121 
122  /** \brief Gets the name of the JSON file */
123  boost::filesystem::path
124  getMetadataFilename () const;
125  /** \brief Sets the name of the JSON file */
126  void
127  setMetadataFilename (const boost::filesystem::path& path_to_metadata);
128 
129  /** \brief Writes the data to a JSON file located at \ref metadata_filename_ */
130  void
131  serializeMetadataToDisk () override;
132 
133  /** \brief Loads the data from a JSON file located at \ref metadata_filename_ */
134  virtual int
135  loadMetadataFromDisk ();
136  /** \brief Loads the data from a JSON file located at \ref metadata_filename_ */
137 
138  int
139  loadMetadataFromDisk (const boost::filesystem::path& path_to_metadata) override;
140 
141  /** \brief Returns the name of the tree; this is not the same as the filename */
142  virtual std::string
143  getOctreeName ();
144  /** \brief Sets the name of the tree */
145  virtual void
146  setOctreeName (const std::string& name_arg);
147 
148  virtual std::string
149  getPointType ();
150  /** \brief Sets a single string identifying the point type of this tree */
151  virtual void
152  setPointType (const std::string& point_type_arg);
153 
154  virtual std::vector<std::uint64_t>&
155  getLODPoints ();
156  virtual std::vector<std::uint64_t>
157  getLODPoints () const;
158  /** \brief Get the number of points at the given depth */
159  virtual std::uint64_t
160  getLODPoints (const std::uint64_t& depth_index) const;
161 
162  /** \brief Initialize the LOD vector with points all 0 */
163  virtual void
164  setLODPoints (const std::uint64_t& depth);
165  /** \brief Copy a vector of LOD points into this metadata (dangerous!)*/
166  virtual void
167  setLODPoints (std::vector<std::uint64_t>& lod_points_arg);
168 
169  /** \brief Set the number of points at lod_index_arg manually
170  * \param[in] lod_index_arg the depth at which this increments the number of LOD points
171  * \param[in] num_points_arg The number of points to store at that LOD
172  * \param[in] increment If true, increments the number of points at the LOD rather than overwriting the number of points
173  */
174  virtual void
175  setLODPoints (const std::uint64_t& lod_index_arg, const std::uint64_t& num_points_arg, const bool increment=true);
176 
177  /** \brief Set information about the coordinate system */
178  virtual void
179  setCoordinateSystem (const std::string& coordinate_system);
180  /** \brief Get metadata information about the coordinate system */
181  virtual std::string
182  getCoordinateSystem () const;
183 
184  /** \brief Set the depth of the tree corresponding to JSON "lod:number". This should always be equal to LOD_num_points_.size()-1 */
185  virtual void
186  setDepth (const std::uint64_t& depth_arg);
187  virtual std::uint64_t
188  getDepth () const;
189 
190  /** \brief Provide operator overload to stream ascii file data*/
191  friend std::ostream&
192  operator<<(std::ostream& os, const OutofcoreOctreeBaseMetadata& metadata_arg);
193 
194  protected:
195  /** \brief Metadata (JSON) file pathname (octree extension JSON file) */
196  boost::filesystem::path metadata_filename_;
197 
198  /** \brief Outofcore library version identifier; maps to JSON "version":int */
200 
201  /** \brief Coordinate system; maps to JSON "coord_sys":string */
202  std::string coordinate_system_;
203 
204  /** \brief Name of the tree (which could be used, for example, as the name of a layer); maps to JSON "name":string*/
205  std::string tree_name_;
206 
207  /** \brief Delineates the point types of the field; maps to JSON "pointtype":string:
208  * \note This is inconsistent with "point type" fields used in PCLPointCloud2 and in other places in PCL
209  */
210  std::string point_type_;
211 
212  /** \brief Depth of the tree (which is the number of levels of depth); maps to JSON "lod":int*/
214 
215  /** \brief Vector of number of points at each LOD. For a tree with no LOD, all fields will be zero except for the field indexed by LOD_points_[levels_of_depth]; maps to JSON "numpts":int array*/
216  std::vector<std::uint64_t> LOD_num_points_;
217 
218  /** \brief Writes the JSON metadata to a string */
219  void
220  writeMetadataString (std::vector<char>& buf) override;
221  };
222  }//namespace outofcore
223 }//namespace pcl
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::outofcore::OutofcoreOctreeBaseMetadata::levels_of_depth_
std::uint64_t levels_of_depth_
Depth of the tree (which is the number of levels of depth); maps to JSON "lod":int.
Definition: outofcore_base_data.h:213
pcl::outofcore::OutofcoreAbstractMetadata
Definition: metadata.h:58
pcl::operator<<
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
Definition: bivariate_polynomial.hpp:229
pcl::outofcore::OutofcoreOctreeBaseMetadata::point_type_
std::string point_type_
Delineates the point types of the field; maps to JSON "pointtype":string:
Definition: outofcore_base_data.h:210
pcl::outofcore::OutofcoreOctreeBaseMetadata::outofcore_version_
int outofcore_version_
Outofcore library version identifier; maps to JSON "version":int.
Definition: outofcore_base_data.h:199
pcl::outofcore::OutofcoreOctreeBaseMetadata::Ptr
shared_ptr< OutofcoreOctreeBaseMetadata > Ptr
Definition: outofcore_base_data.h:99
pcl::outofcore::OutofcoreOctreeBaseMetadata::LOD_num_points_
std::vector< std::uint64_t > LOD_num_points_
Vector of number of points at each LOD.
Definition: outofcore_base_data.h:216
pcl::outofcore::OutofcoreOctreeBaseMetadata::coordinate_system_
std::string coordinate_system_
Coordinate system; maps to JSON "coord_sys":string.
Definition: outofcore_base_data.h:202
pcl::outofcore::OutofcoreOctreeBaseMetadata
Encapsulated class to read JSON metadata into memory, and write the JSON metadata associated with the...
Definition: outofcore_base_data.h:96
pcl::outofcore::OutofcoreOctreeBaseMetadata::tree_name_
std::string tree_name_
Name of the tree (which could be used, for example, as the name of a layer); maps to JSON "name":stri...
Definition: outofcore_base_data.h:205
pcl::outofcore::OutofcoreOctreeBaseMetadata::metadata_filename_
boost::filesystem::path metadata_filename_
Metadata (JSON) file pathname (octree extension JSON file)
Definition: outofcore_base_data.h:196
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:253
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:90
pcl::outofcore::OutofcoreOctreeBaseMetadata::ConstPtr
shared_ptr< const OutofcoreOctreeBaseMetadata > ConstPtr
Definition: outofcore_base_data.h:100
pcl::uint64_t
std::uint64_t uint64_t
Definition: pcl_macros.h:98