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