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