41 #include <unordered_map>
62 have_interval =
FALSE;
72 if (spatial)
delete spatial;
73 if (interval)
delete interval;
78 if (this->spatial)
delete this->spatial;
79 this->spatial = spatial;
80 if (this->interval)
delete this->interval;
86 I32 cell = spatial->get_cell_index(point->
get_x(), point->
get_y());
87 return interval->add(p_index, cell);
92 fprintf(stderr,
"before complete %d %d\n", minimum_points, maximum_intervals);
99 interval->get_cells();
100 while (interval->has_cells())
102 cell_hash[hash1][interval->index] = interval->full;
104 while (cell_hash[hash1].size())
106 I32 hash2 = (hash1+1)%2;
107 cell_hash[hash2].clear();
115 my_cell_hash::iterator hash_element_inner;
116 my_cell_hash::iterator hash_element_outer = cell_hash[hash1].begin();
117 while (hash_element_outer != cell_hash[hash1].end())
119 if ((*hash_element_outer).second)
121 if (spatial->coarsen((*hash_element_outer).first, &coarser_index, &num_indices, &indices))
125 for (i = 0; i < num_indices; i++)
127 if ((*hash_element_outer).first == indices[i])
129 hash_element_inner = hash_element_outer;
133 hash_element_inner = cell_hash[hash1].find(indices[i]);
135 if (hash_element_inner != cell_hash[hash1].end())
137 full += (*hash_element_inner).second;
138 (*hash_element_inner).second = 0;
142 if ((full < minimum_points) && (num_filled == num_indices))
144 interval->merge_cells(num_indices, indices, coarser_index);
146 cell_hash[hash2][coarser_index] = full;
150 hash_element_outer++;
152 if (!coarsened)
break;
156 interval->get_cells();
157 while (interval->has_cells())
159 spatial->manage_cell(interval->index);
161 fprintf(stderr,
"after minimum_points %d\n", minimum_points);
164 if (maximum_intervals < 0)
166 maximum_intervals = -maximum_intervals*interval->get_number_cells();
168 if (maximum_intervals)
170 interval->merge_intervals(maximum_intervals);
171 fprintf(stderr,
"after maximum_intervals %d\n", maximum_intervals);
181 U32 total_intervals = 0;
184 interval->get_cells();
185 while (interval->has_cells())
189 while (interval->has_intervals())
191 total_check += interval->end-interval->start+1;
194 if (total_check != interval->total)
196 fprintf(stderr,
"ERROR: total_check %d != interval->total %d\n", total_check, interval->total);
198 if (verbose) fprintf(stderr,
"cell %d intervals %d full %d total %d (%.2f)\n", interval->index, intervals, interval->full, interval->total, 100.0f*interval->full/interval->total);
200 total_full += interval->full;
201 total_total += interval->total;
202 total_intervals += intervals;
204 fprintf(stderr,
"total cells/intervals %d/%d full %d (%.2f)\n", total_cells, total_intervals, total_full, 100.0f*total_full/total_total);
219 have_interval =
FALSE;
220 cells = spatial->intersect_rectangle(r_min_x, r_min_y, r_max_x, r_max_y);
223 return merge_intervals();
229 have_interval =
FALSE;
230 cells = spatial->intersect_tile(ll_x, ll_y, size);
233 return merge_intervals();
239 have_interval =
FALSE;
240 cells = spatial->intersect_circle(center_x, center_y, radius);
243 return merge_intervals();
249 have_interval =
FALSE;
250 return interval->get_merged_cell();
255 if (interval->has_intervals())
257 start = interval->start;
259 full = interval->full;
260 have_interval =
TRUE;
263 have_interval =
FALSE;
269 if (file_name == 0)
return FALSE;
270 char* name = strdup(file_name);
271 if (strstr(file_name,
".las") || strstr(file_name,
".laz"))
273 name[strlen(name)-1] =
'x';
275 else if (strstr(file_name,
".LAS") || strstr(file_name,
".LAZ"))
277 name[strlen(name)-1] =
'X';
281 name[strlen(name)-3] =
'l';
282 name[strlen(name)-2] =
'a';
283 name[strlen(name)-1] =
'x';
285 FILE*
file = fopen(name,
"rb");
299 fprintf(stderr,
"ERROR (LASindex): cannot read '%s'\n", name);
313 if (file_name == 0)
return FALSE;
314 char* name = strdup(file_name);
315 if (strstr(file_name,
".las") || strstr(file_name,
".laz"))
317 name[strlen(name)-1] =
'x';
319 else if (strstr(file_name,
".LAS") || strstr(file_name,
".LAZ"))
321 name[strlen(name)-1] =
'X';
325 name[strlen(name)-3] =
'l';
326 name[strlen(name)-2] =
'a';
327 name[strlen(name)-1] =
'x';
329 FILE*
file = fopen(name,
"wb");
332 fprintf(stderr,
"ERROR (LASindex): cannot open '%s' for write\n", name);
343 fprintf(stderr,
"ERROR (LASindex): cannot write '%s'\n", name);
368 try { stream->
getBytes((
U8*)signature, 4); }
catch (...)
370 fprintf(stderr,
"ERROR (LASindex): reading signature\n");
373 if (strncmp(signature,
"LASX", 4) != 0)
375 fprintf(stderr,
"ERROR (LASindex): wrong signature %4s instead of 'LASX'\n", signature);
381 fprintf(stderr,
"ERROR (LASindex): reading version\n");
386 spatial = spatialRW.
read(stream);
389 fprintf(stderr,
"ERROR (LASindex): cannot read LASspatial\n");
394 if (!interval->read(stream))
396 fprintf(stderr,
"ERROR (LASindex): reading LASinterval\n");
400 interval->get_cells();
401 while (interval->has_cells())
403 spatial->manage_cell(interval->index);
412 fprintf(stderr,
"ERROR (LASindex): writing signature\n");
418 fprintf(stderr,
"ERROR (LASindex): writing version\n");
423 if (!spatialRW.
write(spatial, stream))
425 fprintf(stderr,
"ERROR (LASindex): cannot write LASspatial\n");
429 if (!interval->write(stream))
431 fprintf(stderr,
"ERROR (LASindex): writing LASinterval\n");
442 if (!has_intervals())
return FALSE;
443 lasreader->
seek(start);
447 have_interval =
FALSE;
457 if (!has_intervals())
return FALSE;
458 lasreader->
seek(start);
462 have_interval =
FALSE;
470 if (spatial->get_intersected_cells())
473 while (spatial->has_more_cells())
475 if (interval->get_cell(spatial->current_cell))
477 interval->add_current_cell_to_merge_cell_set();
484 BOOL r = interval->merge();
485 full = interval->full;
486 total = interval->total;
487 interval->clear_merge_cell_set();