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