42 #include <unordered_map> 100 assert(p_index > current_end);
101 U32 diff = p_index - current_end;
103 if (diff > threshold)
132 if (last_cell == 0 || last_index != c_index)
134 last_index = c_index;
135 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->find(c_index);
139 ((
my_cell_hash*)cells)->insert(my_cell_hash::value_type(c_index, last_cell));
143 last_cell = (*hash_element).second;
145 if (last_cell->add(p_index, threshold))
162 return number_intervals;
169 if (num_indices == 1)
171 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->find(indices[0]);
176 ((
my_cell_hash*)cells)->insert(my_cell_hash::value_type(new_index, (*hash_element).second));
181 if (cells_to_merge) ((
my_cell_set*)cells_to_merge)->clear();
182 for (i = 0; i < num_indices; i++)
184 add_cell_to_merge_cell_set(indices[i],
TRUE);
187 ((
my_cell_hash*)cells)->insert(my_cell_hash::value_type(new_index, merged_cells));
202 if (maximum_intervals < get_number_cells())
204 maximum_intervals = 0;
208 maximum_intervals -= get_number_cells();
214 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->begin();
217 cell = (*hash_element).second;
221 map.insert(my_cell_map::value_type(diff, cell));
227 my_cell_map::iterator map_element = map.begin();
228 diff = (*map_element).first;
231 if (map.size() <= maximum_intervals)
233 fprintf(stderr,
"next largest interval gap is %u\n", diff);
237 U32 size = map.size();
238 while (size > maximum_intervals)
240 map_element = map.begin();
241 diff = (*map_element).first;
242 cell = (*map_element).second;
243 map.erase(map_element);
251 delete_cell = cell->
next;
252 cell->
end = delete_cell->
end;
256 map.insert(my_cell_map::value_type(cell->
next->
start - cell->
end - 1, cell));
257 delete_cell->
end = 0;
267 map_element = map.begin();
270 if (map_element == map.end())
break;
271 cell = (*map_element).second;
279 fprintf(stderr,
"largest interval gap increased to %u\n", diff);
287 start_cell = (*hash_element).second;
288 start_cell->
total = 0;
307 my_cell_hash::iterator hash_element;
314 hash_element = ((
my_cell_hash*)cells)->find(last_index);
323 last_index = (*hash_element).first;
324 index = (*hash_element).first;
325 full = (*hash_element).second->full;
326 total = (*hash_element).second->total;
327 current_cell = (*hash_element).second;
333 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->find(c_index);
339 index = (*hash_element).first;
340 full = (*hash_element).second->full;
341 total = (*hash_element).second->total;
342 current_cell = (*hash_element).second;
348 if (current_cell == 0)
352 if (cells_to_merge == 0)
362 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->find(c_index);
367 if (cells_to_merge == 0)
371 ((
my_cell_set*)cells_to_merge)->insert((*hash_element).second);
381 if (merged_cells_temporary)
387 next_next = next->
next;
396 if (cells_to_merge == 0)
return FALSE;
401 merged_cells_temporary =
FALSE;
403 my_cell_set::iterator set_element = ((
my_cell_set*)cells_to_merge)->begin();
404 merged_cells = (*set_element);
408 merged_cells_temporary =
TRUE;
413 my_cell_set::iterator set_element = ((
my_cell_set*)cells_to_merge)->begin();
417 cell = (*set_element);
421 map.insert(my_cell_map::value_type(cell->
start, cell));
427 my_cell_map::iterator map_element = map.begin();
428 cell = (*map_element).second;
429 map.erase(map_element);
431 merged_cells->end = cell->
end;
432 merged_cells->total = cell->
end - cell->
start + 1;
433 if (erase)
delete cell;
439 map_element = map.begin();
440 cell = (*map_element).second;
441 map.erase(map_element);
442 diff = cell->
start - last_cell->
end;
443 if (diff > (
I32)threshold)
446 last_cell = last_cell->
next;
447 merged_cells->total += (cell->
end - cell->
start + 1);
451 diff = cell->
end - last_cell->
end;
454 last_cell->
end = cell->
end;
455 merged_cells->total += diff;
459 if (erase)
delete cell;
462 current_cell = merged_cells;
463 full = merged_cells->full;
464 total = merged_cells->total;
480 full = merged_cells->full;
481 total = merged_cells->total;
482 current_cell = merged_cells;
492 start = current_cell->start;
493 end = current_cell->end;
494 current_cell = current_cell->next;
504 this->threshold = threshold;
505 number_intervals = 0;
510 merged_cells_temporary =
FALSE;
516 if (cells_to_merge)
delete ((
my_cell_set*)cells_to_merge);
522 try { stream->
getBytes((
U8*)signature, 4); }
catch (...)
524 fprintf(stderr,
"ERROR (LASinterval): reading signature\n");
527 if (strncmp(signature,
"LASV", 4) != 0)
529 fprintf(stderr,
"ERROR (LASinterval): wrong signature %4s instead of 'LASV'\n", signature);
535 fprintf(stderr,
"ERROR (LASinterval): reading version\n");
542 fprintf(stderr,
"ERROR (LASinterval): reading number of cells\n");
552 fprintf(stderr,
"ERROR (LASinterval): reading cell index\n");
557 ((
my_cell_hash*)cells)->insert(my_cell_hash::value_type(cell_index, start_cell));
560 U32 number_intervals;
561 try { stream->
get32bitsLE((
U8*)&number_intervals); }
catch (...)
563 fprintf(stderr,
"ERROR (LASinterval): reading number of intervals in cell\n");
568 try { stream->
get32bitsLE((
U8*)&number_points); }
catch (...)
570 fprintf(stderr,
"ERROR (LASinterval): reading number of points in cell\n");
573 start_cell->
full = number_points;
574 start_cell->
total = 0;
575 while (number_intervals)
580 fprintf(stderr,
"ERROR (LASinterval): reading start %d of interval\n", cell->
start);
586 fprintf(stderr,
"ERROR (LASinterval): reading end %d of interval\n", cell->
end);
591 if (number_intervals)
607 fprintf(stderr,
"ERROR (LASinterval): writing signature\n");
613 fprintf(stderr,
"ERROR (LASinterval): writing version\n");
620 fprintf(stderr,
"ERROR (LASinterval): writing number of cells %d\n", number_cells);
624 my_cell_hash::iterator hash_element = ((
my_cell_hash*)cells)->begin();
629 U32 number_intervals = 0;
637 I32 cell_index = (*hash_element).first;
640 fprintf(stderr,
"ERROR (LASinterval): writing cell index %d\n", cell_index);
646 fprintf(stderr,
"ERROR (LASinterval): writing number of intervals %d in cell\n", number_intervals);
652 fprintf(stderr,
"ERROR (LASinterval): writing number of points %d in cell\n", number_points);
656 cell = (*hash_element).second;
662 fprintf(stderr,
"ERROR (LASinterval): writing start %d of interval\n", cell->
start);
668 fprintf(stderr,
"ERROR (LASinterval): writing end %d of interval\n", cell->
end);
virtual BOOL putBytes(const U8 *bytes, U32 num_bytes)=0
BOOL add_cell_to_merge_cell_set(const I32 c_index, const BOOL erase=FALSE)
void merge_intervals(U32 maximum)
U32 get_number_intervals() const
BOOL merge(const BOOL erase=FALSE)
LASinterval(const U32 threshold=1000)
void clear_merge_cell_set()
BOOL add(const U32 p_index, const U32 threshold=1000)
BOOL add(const U32 p_index, const I32 c_index)
OutMapT< typename InMapT::HandleType, std::result_of_t< MapF(typename InMapT::ValueType)> > map(const InMapT &mapIn, MapF func)
Calls func for each value of the given map and save the result in the output map. ...
BOOL get_cell(const I32 c_index)
unordered_map< I32, U32 > my_cell_hash
virtual void getBytes(U8 *bytes, const U32 num_bytes)=0
unordered_map< I32, LASintervalStartCell * > my_cell_hash
BOOL write(ByteStreamOut *stream) const
multimap< U32, LASintervalCell * > my_cell_map
BOOL merge_cells(const U32 num_indices, const I32 *indices, const I32 new_index)
U32 get_number_cells() const
BOOL add_current_cell_to_merge_cell_set()
BOOL read(ByteStreamIn *stream)
virtual BOOL put32bitsLE(const U8 *bytes)=0
set< LASintervalStartCell * > my_cell_set
virtual void get32bitsLE(U8 *bytes)=0