Point Cloud Library (PCL)  1.15.1
outofcore_node_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: outofcore_node_data.h 6915 2012-08-22 10:54:21Z stfox88 $
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/common/eigen.h>
51 
52 #include <boost/filesystem.hpp>
53 
54 #include <ostream>
55 
56 namespace pcl
57 {
58  namespace outofcore
59  {
60  /** \class OutofcoreOctreeNodeMetadata
61  *
62  * \brief Encapsulated class to read JSON metadata into memory, and write the JSON metadata for each
63  * node.
64  *
65  * This class encapsulates the outofcore node 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 ascii metadata fields
69  * saved to the metadata object file on disk.
70  *
71  * The JSON file is formatted in the following way:
72  * \verbatim
73  {
74  "version": 3,
75  "bb_min": [xxx,yyy,zzz],
76  "bb_max": [xxx,yyy,zzz],
77  "bin": "path_to_data.pcd"
78  }
79  \endverbatim
80  *
81  * Any properties not stored in the metadata file are computed
82  * when the file is loaded (e.g. \ref midpoint_xyz_). By
83  * convention, the JSON files are stored on disk with .oct_idx
84  * extension.
85  *
86  * \ingroup outofcore
87  * \author Stephen Fox (foxstephend@gmail.com)
88  */
89  class PCL_EXPORTS OutofcoreOctreeNodeMetadata
90  {
91 
92  public:
93  //public typedefs
94  using Ptr = shared_ptr<OutofcoreOctreeNodeMetadata>;
95  using ConstPtr = shared_ptr<const OutofcoreOctreeNodeMetadata>;
96 
97  /** \brief Empty constructor */
100 
101  /** \brief Copy constructor */
103 
104  /** \brief Get the lower bounding box corner */
105  const Eigen::Vector3d&
106  getBoundingBoxMin () const;
107  /** \brief Set the lower bounding box corner */
108  void
109  setBoundingBoxMin (const Eigen::Vector3d& min_bb);
110  /** \brief Get the upper bounding box corner */
111  const Eigen::Vector3d&
112  getBoundingBoxMax () const;
113  /** \brief Set the upper bounding box corner */
114  void
115  setBoundingBoxMax (const Eigen::Vector3d& max_bb);
116 
117  /** \brief Get the lower and upper corners of the bounding box enclosing this node */
118  void
119  getBoundingBox (Eigen::Vector3d &min_bb, Eigen::Vector3d &max_bb) const;
120  /** \brief Set the lower and upper corners of the bounding box */
121  void
122  setBoundingBox (const Eigen::Vector3d& min_bb, const Eigen::Vector3d& max_bb);
123 
124  /** \brief Get the directory path name; this is the parent_path of */
125  const boost::filesystem::path&
126  getDirectoryPathname () const;
127  /** \brief Set the directory path name */
128  void
129  setDirectoryPathname (const boost::filesystem::path& directory_pathname);
130 
131  /** \brief Get the path to the PCD file */
132  const boost::filesystem::path&
133  getPCDFilename () const;
134  /** \brief Set the point filename; extension .pcd */
135  void
136  setPCDFilename (const boost::filesystem::path& point_filename);
137 
138  /** \brief et the outofcore version read from the "version" field of the JSON object */
139  int
140  getOutofcoreVersion () const;
141  /** \brief Set the outofcore version stored in the "version" field of the JSON object */
142  void
143  setOutofcoreVersion (const int version);
144 
145  /** \brief Sets the name of the JSON file */
146  const boost::filesystem::path&
147  getMetadataFilename () const;
148  /** \brief Gets the name of the JSON file */
149  void
150  setMetadataFilename (const boost::filesystem::path& path_to_metadata);
151 
152  /** \brief Get the midpoint of this node's bounding box */
153  const Eigen::Vector3d&
154  getVoxelCenter () const;
155 
156  /** \brief Writes the data to a JSON file located at \ref metadata_filename_ */
157  void
158  serializeMetadataToDisk ();
159 
160  /** \brief Loads the data from a JSON file located at \ref metadata_filename_ */
161  int
162  loadMetadataFromDisk ();
163  /** \brief Loads the data from a JSON file located at \ref metadata_filename_ */
164  int
165  loadMetadataFromDisk (const boost::filesystem::path& path_to_metadata);
166 
167  friend
168  std::ostream& operator<<(std::ostream& os, const OutofcoreOctreeNodeMetadata& metadata_arg);
169 
170  protected:
171  /** \brief The X,Y,Z axes-aligned minimum corner for the bounding box */
172  Eigen::Vector3d min_bb_;
173  /** \brief The X,Y,Z axes-aligned maximum corner for the bounding box */
174  Eigen::Vector3d max_bb_;
175  /** \brief Path to PCD file (i.e. "bin"ary point data) */
176  boost::filesystem::path binary_point_filename_;
177  /** \brief Voxel center; not stored on disk */
178  Eigen::Vector3d midpoint_xyz_;
179  /** \brief Directory this metadata belongs in */
180  boost::filesystem::path directory_;
181  /** \brief Metadata (JSON) file pathname (oct_idx extension JSON file) */
182  boost::filesystem::path metadata_filename_;
183  /** \brief Outofcore library version identifier */
184  int outofcore_version_{0};
185 
186  /** \brief Computes the midpoint; used when bounding box is changed */
187  inline void
189  {
190  midpoint_xyz_ = (this->max_bb_ + this->min_bb_)/static_cast<double>(2.0);
191  }
192  };
193  }//namespace outofcore
194 }//namespace pcl
shared_ptr< OutofcoreOctreeNodeMetadata > Ptr
boost::filesystem::path binary_point_filename_
Path to PCD file (i.e.
shared_ptr< const OutofcoreOctreeNodeMetadata > ConstPtr
boost::filesystem::path directory_
Directory this metadata belongs in.
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
Eigen::Vector3d max_bb_
The X,Y,Z axes-aligned maximum corner for the bounding box.
boost::filesystem::path metadata_filename_
Metadata (JSON) file pathname (oct_idx extension JSON file)
Eigen::Vector3d midpoint_xyz_
Voxel center; not stored on disk.
void updateVoxelCenter()
Computes the midpoint; used when bounding box is changed.
Eigen::Vector3d min_bb_
The X,Y,Z axes-aligned minimum corner for the bounding box.
Encapsulated class to read JSON metadata into memory, and write the JSON metadata for each node...