diff --git a/discretize/_extensions/tree.cpp b/discretize/_extensions/tree.cpp index 8899490d1..955521738 100644 --- a/discretize/_extensions/tree.cpp +++ b/discretize/_extensions/tree.cpp @@ -418,6 +418,44 @@ void Cell::refine_func(node_map_t& nodes, function test_func, double *xs, double } } +void Cell::refine_image(node_map_t& nodes, double* image, int_t *shape_cells, double *xs, double*ys, double *zs, bool diag_balance){ + // early exit if my level is higher than or equal to target + if (level == max_level){ + return; + } + int_t start_ix = points[0]->location_ind[0]/2; + int_t start_iy = points[0]->location_ind[1]/2; + int_t start_iz = n_dim == 2 ? 0 : points[0]->location_ind[2]/2; + int_t end_ix = points[3]->location_ind[0]/2; + int_t end_iy = points[3]->location_ind[1]/2; + int_t end_iz = n_dim == 2? 1 : points[7]->location_ind[2]/2; + int_t nx = shape_cells[0]; + int_t ny = shape_cells[1]; + int_t nz = shape_cells[2]; + + int_t i_image = (nx * ny) * start_iz + nx * start_iy + start_ix; + double val_start = image[i_image]; + bool all_unique = true; + + // if any of the image data contained in the cell are different, subdivide myself + for(int_t iz=start_iz; izrefine_image(nodes, image, shape_cells, xs, ys, zs, diag_balance); + } + } +} + void Cell::divide(node_map_t& nodes, double* xs, double* ys, double* zs, bool balance, bool diag_balance){ // Gaurd against dividing a cell that is already at the max level if (level == max_level){ @@ -896,6 +934,18 @@ void Tree::refine_function(function test_func, bool diagonal_balance){ roots[iz][iy][ix]->refine_func(nodes, test_func, xs, ys, zs, diagonal_balance); }; +void Tree::refine_image(double *image, bool diagonal_balance){ + int_t shape_cells[3]; + shape_cells[0] = nx/2; + shape_cells[1] = ny/2; + shape_cells[2] = nz/2; + for(int_t iz=0; izrefine_image(nodes, image, shape_cells, xs, ys, zs, diagonal_balance); +} + + void Tree::finalize_lists(){ for(int_t iz=0; iz void refine_geom(const T& geom, int_t p_level, bool diagonal_balance=false){ for(int_t iz=0; iz