| 241 | //////////////////////////////////////////////////////////////////////////////// |
| 242 | |
| 243 | int |
| 244 | OutofcoreOctreeNodeMetadata::loadMetadataFromDisk () |
| 245 | { |
| 246 | if(directory_ != metadata_filename_.parent_path ()) |
| 247 | { |
| 248 | PCL_ERROR ("directory_ is not set correctly\n"); |
| 249 | } |
| 250 | |
| 251 | //if the file to load doesn't exist, return failure |
| 252 | if (!boost::filesystem::exists (metadata_filename_)) |
| 253 | { |
| 254 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata] Can not find index metadata at %s.\n", metadata_filename_.c_str ()); |
| 255 | return (0); |
| 256 | } |
| 257 | if(boost::filesystem::is_directory (metadata_filename_)) |
| 258 | { |
| 259 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata] Got a directory, but no oct_idx metadata?\n"); |
| 260 | return (0); |
| 261 | } |
| 262 | |
| 263 | //load CJSON |
| 264 | std::vector<char> idx_input; |
| 265 | std::uintmax_t len = boost::filesystem::file_size (metadata_filename_); |
| 266 | idx_input.resize (len + 1); |
| 267 | |
| 268 | std::ifstream f (metadata_filename_.string ().c_str (), std::ios::in); |
| 269 | f.read (&(idx_input.front ()), len); |
| 270 | idx_input.back () = '\0'; |
| 271 | |
| 272 | //Parse |
| 273 | std::shared_ptr<cJSON> idx (cJSON_Parse (&(idx_input.front ())), cJSON_Delete); |
| 274 | |
| 275 | cJSON* cjson_outofcore_version = cJSON_GetObjectItem (idx.get (), "version"); |
| 276 | cJSON* cjson_bb_min = cJSON_GetObjectItem (idx.get (), "bb_min"); |
| 277 | cJSON* cjson_bb_max = cJSON_GetObjectItem (idx.get (), "bb_max"); |
| 278 | cJSON* cjson_bin_point_filename = cJSON_GetObjectItem (idx.get (), "bin"); |
| 279 | |
| 280 | bool parse_failure = false; |
| 281 | |
| 282 | //Sanitize |
| 283 | if (!cjson_outofcore_version) |
| 284 | { |
| 285 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata::%s] Failed to parse \"version\" field of node metadata %s\n", __FUNCTION__, metadata_filename_.c_str ()); |
| 286 | parse_failure = true; |
| 287 | } |
| 288 | if (!cjson_bb_min) |
| 289 | { |
| 290 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata::%s] Failed to parse \"bb_min\" field of node metadata %s\n", __FUNCTION__, metadata_filename_.c_str ()); |
| 291 | parse_failure = true; |
| 292 | } |
| 293 | if (!cjson_bb_max) |
| 294 | { |
| 295 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata::%s] Failed to parse \"bb_max\" field of node metadata %s\n", __FUNCTION__, metadata_filename_.c_str ()); |
| 296 | parse_failure = true; |
| 297 | } |
| 298 | if (!cjson_bin_point_filename) |
| 299 | { |
| 300 | PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeNodeMetadata::%s] Failed to parse \"bin\" field of node metadata %s\n", __FUNCTION__, metadata_filename_.c_str ()); |
no test coverage detected