@@ -84,7 +84,10 @@ namespace
8484 index[axis0] += increments[axis0];
8585 painted_cells.push_back ( index );
8686 }
87- painted_cells.push_back ( end );
87+ if ( painted_cells.back () != end )
88+ {
89+ painted_cells.push_back ( end );
90+ }
8891 return painted_cells;
8992 }
9093
@@ -98,12 +101,17 @@ namespace
98101 std::array< int , dimension > increments;
99102 for ( const auto i : geode::LRange{ dimension } )
100103 {
104+ if ( end[i] == start[i] )
105+ {
106+ deltas[i] = 0 ;
107+ increments[i] = 0 ;
108+ }
101109 if ( end[i] > start[i] )
102110 {
103111 deltas[i] = end[i] - start[i];
104112 increments[i] = 1 ;
105113 }
106- else
114+ else if ( end[i] < start[i] )
107115 {
108116 deltas[i] = start[i] - end[i];
109117 increments[i] = -1 ;
@@ -176,9 +184,9 @@ namespace
176184 std::array< int , dimension > increments;
177185 std::tie ( deltas, increments ) =
178186 compute_deltas< dimension >( start, end );
179- const auto i = get_major_axis< dimension >( deltas );
187+ const auto major_axis = get_major_axis< dimension >( deltas );
180188 return paint_segment_axis< dimension >(
181- i , deltas, increments, start, end );
189+ major_axis , deltas, increments, start, end );
182190 }
183191
184192 std::vector< CellIndices< 2 > > conservative_voxelization_triangle (
@@ -446,39 +454,56 @@ namespace
446454 return cells;
447455 }
448456
449- absl::InlinedVector< CellIndices< 3 >, 6 > neighbors (
450- const geode::Grid3D& grid, const CellIndices< 3 >& cell )
457+ void add_neighbors_to_queue ( const geode::Grid3D& grid,
458+ const CellIndices< 3 >& cell,
459+ std::queue< CellIndices< 3 > >& cells_queue,
460+ const CellIndices< 3 >& min,
461+ const CellIndices< 3 >& max )
451462 {
452- absl::InlinedVector< CellIndices< 3 >, 6 > neighbors;
453- for ( const auto d : geode::LRange{ 3 } )
463+ for ( const auto axis : geode::LRange{ 3 } )
454464 {
455- if ( const auto prev = grid.previous_cell ( cell, d ) )
465+ if ( const auto prev = grid.previous_cell ( cell, axis ) )
456466 {
457- neighbors.push_back ( prev.value () );
467+ if ( prev.value ()[axis] >= min[axis] )
468+ {
469+ cells_queue.emplace ( prev.value () );
470+ }
458471 }
459- if ( const auto next = grid.next_cell ( cell, d ) )
472+ if ( const auto next = grid.next_cell ( cell, axis ) )
460473 {
461- neighbors.push_back ( next.value () );
474+ if ( next.value ()[axis] <= max[axis] )
475+ {
476+ cells_queue.emplace ( next.value () );
477+ }
462478 }
463479 }
464- return neighbors;
465480 }
466481
467482 std::vector< CellIndices< 3 > > conservative_voxelization_segment (
468483 const geode::Grid3D& grid,
469484 const geode::Segment3D& segment,
470- const std::array< geode::Grid3D::CellsAroundVertex, 2 > /* unused */ )
485+ const std::array< geode::Grid3D::CellsAroundVertex, 2 > vertex_cells )
471486 {
472487 auto cells = geode::rasterize_segment ( grid, segment );
473488 std::vector< bool > tested_cells ( grid.nb_cells (), false );
489+ auto min = grid.cell_indices ( grid.nb_cells () - 1 );
490+ auto max = grid.cell_indices ( 0 );
491+ for ( const auto vertex_id : geode::LRange{ 2 } )
492+ {
493+ for ( const auto & cell_indices : vertex_cells[vertex_id] )
494+ {
495+ for ( const auto axis : geode::LRange{ 3 } )
496+ {
497+ max[axis] = std::max ( max[axis], cell_indices[axis] );
498+ min[axis] = std::min ( min[axis], cell_indices[axis] );
499+ }
500+ }
501+ }
474502 std::queue< CellIndices< 3 > > to_test;
475503 for ( const auto & cell : cells )
476504 {
477505 tested_cells[grid.cell_index ( cell )] = true ;
478- for ( auto && neighbor : neighbors ( grid, cell ) )
479- {
480- to_test.emplace ( std::move ( neighbor ) );
481- }
506+ add_neighbors_to_queue ( grid, cell, to_test, min, max );
482507 }
483508 const auto half_cell_size =
484509 std::sqrt ( grid.cell_length_in_direction ( 0 )
@@ -502,10 +527,7 @@ namespace
502527 if ( geode::point_segment_distance ( center, segment )
503528 <= half_cell_size )
504529 {
505- for ( auto && neighbor : neighbors ( grid, cell ) )
506- {
507- to_test.emplace ( std::move ( neighbor ) );
508- }
530+ add_neighbors_to_queue ( grid, cell, to_test, min, max );
509531 cells.emplace_back ( std::move ( cell ) );
510532 }
511533 }
0 commit comments