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