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