MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / loadMetadataFromDisk

Method loadMetadataFromDisk

outofcore/src/outofcore_base_data.cpp:171–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169 ////////////////////////////////////////////////////////////////////////////////
170
171 int
172 OutofcoreOctreeBaseMetadata::loadMetadataFromDisk ()
173 {
174 // Open JSON
175 std::vector<char> idx_input;
176 std::uintmax_t len = boost::filesystem::file_size (metadata_filename_);
177 idx_input.resize (len + 1);
178
179 std::ifstream f (metadata_filename_.string ().c_str (), std::ios::in);
180 f.read (&(idx_input.front ()), len);
181 idx_input.back () = '\0';
182
183 // Parse JSON
184 std::shared_ptr<cJSON> idx (cJSON_Parse (&(idx_input.front ())), cJSON_Delete);
185 cJSON* name = cJSON_GetObjectItem (idx.get (), "name");
186 cJSON* version = cJSON_GetObjectItem (idx.get (), "version");
187 cJSON* pointtype = cJSON_GetObjectItem (idx.get (), "pointtype");
188 cJSON* lod = cJSON_GetObjectItem (idx.get (), "lod");
189 cJSON* numpts = cJSON_GetObjectItem (idx.get (), "numpts");
190 cJSON* coord = cJSON_GetObjectItem (idx.get (), "coord_system");
191
192 bool parse_failure = false;
193
194 // Validate JSON
195 if (!((name) && (version) && (pointtype) && (lod) && (numpts) && (coord)))
196 {
197 PCL_ERROR ( "[pcl::outofcore::OutofcoreOctreeBaseMetadata::loadMetadataFromDisk] One of expected metadata fields does not exist in %s\n", metadata_filename_.c_str ());
198 parse_failure = true;
199 }
200 if ((name->type != cJSON_String) || (version->type != cJSON_Number) || (pointtype->type != cJSON_String)
201 || (lod->type != cJSON_Number) || (numpts->type != cJSON_Array) || (coord->type != cJSON_String))
202 {
203 PCL_ERROR ( "[pcl::outofcore::OutofcoreOctreeBaseMetadata::loadMetadataFromDisk] One of metadata fields does not contain its expected type in %s\n",metadata_filename_.c_str ());
204 parse_failure = true;
205 }
206 if (version->valuedouble != 2.0 && version->valuedouble != 3.0)//only support version 2.0 and 3.0
207 {
208 PCL_ERROR ( "[pcl::outofcore::OutofcoreOctreeBaseMetadata::loadMetadataFromDisk] Outofcore version field (just read version:number = %.1lf) in %s does not match the current supported versions\n",metadata_filename_.c_str (), version->valuedouble);
209 parse_failure = true;
210 }
211 if ((lod->valueint + 1) != cJSON_GetArraySize (numpts))
212 {
213 PCL_ERROR ( "[pcl::outofcore::OutofcoreOctreeBaseMetadata::loadMetadataFromDisk] lod:num+1=%d+1 (i.e. height of tree) does not match size of LOD array (%d) in %s\n", lod->valueint, cJSON_GetArraySize (numpts), metadata_filename_.c_str ());
214 parse_failure = true;
215 }
216
217 if (parse_failure)
218 {
219 PCL_THROW_EXCEPTION (PCLException, "[pcl::outofcore::OutofcoreOctreeBaseMetadata::loadMetadataFromDisk] Parse Failure\n");
220 }
221
222
223 // Get Data
224 LOD_num_points_.resize (lod->valueint + 1);
225 for (int i = 0; i < (lod->valueint + 1); i++)
226 {
227 //cJSON doesn't have explicit 64bit int, have to use double, get up to 2^52
228 LOD_num_points_[i] = static_cast<std::uint64_t> (cJSON_GetArrayItem (numpts, i)->valuedouble );

Callers

nothing calls this directly

Calls 8

setMetadataFilenameMethod · 0.95
cJSON_ParseFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_GetArraySizeFunction · 0.85
cJSON_GetArrayItemFunction · 0.85
resizeMethod · 0.45
readMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected