<commit_before>// __BEGIN_LICENSE__
// Copyright (C) 2006, 2007 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


#include <vw/Stereo/PyramidCorrelator.h>
#include <vw/Stereo/OptimizedCorrelator.h>
#include <vw/Image/ImageViewRef.h>
#include <vw/FileIO/DiskImageResource.h>

using namespace vw;
using namespace stereo;

std::vector<vw::BBox2i>
PyramidCorrelator::subdivide_bboxes(ImageView<PixelMask<Vector2f> > const& disparity_map,
                                    ImageView<uint8> const& dmask,
                                    BBox2i const& box) {
  if (count_valid_pixels(crop(create_mask(dmask), box)) == 0) {
    return std::vector<BBox2i>();
  }

  // No need for try catch on disparity range, because subdivide_bboxes 
  // should only be called for valid subregions
  BBox2 disp_range = get_disparity_range(crop(disparity_map, box));
  bool bad_range = (disp_range.width()+1) * (disp_range.height()+1) > 4;
  
  BBox2i subbox1 = box, subbox2 = box;
  if (box.width() > box.height()) {
    subbox1.max().x() = box.min().x() + box.width()/2;
    subbox2.min().x() = box.min().x() + box.width()/2;
  } else {
    subbox1.max().y() = box.min().y() + box.height()/2;
    subbox2.min().y() = box.min().y() + box.height()/2;
  }

  bool good_size = box.width() > m_min_subregion_dim || box.height() > m_min_subregion_dim;
  bool good_subregion = is_good_subregion(disparity_map, dmask, subbox1) && is_good_subregion(disparity_map, dmask, subbox2);
  bool kill_invalid = count_valid_pixels(crop(create_mask(dmask), subbox1)) == 0 || count_valid_pixels(crop(create_mask(dmask), subbox2)) == 0;
  
  if (kill_invalid || (bad_range && good_size && good_subregion)) {
    std::vector<BBox2i> r = subdivide_bboxes(disparity_map, dmask, subbox1);
    std::vector<BBox2i> l = subdivide_bboxes(disparity_map, dmask, subbox2);
    r.insert(r.end(), l.begin(), l.end());
    return r;
  }
  
  std::vector<vw::BBox2i> result;
  result.push_back(box);
  return result;
}

void draw_bbox(ImageView<PixelRGB<float> > &view, BBox2i const& bbox) {
  int u,v;
  // Top
  v = bbox.min().y();
  for (u = bbox.min().x(); u < bbox.max().x(); ++u)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);

  // Bottom
  v = bbox.max().y()-1;
  for (u = bbox.min().x(); u < bbox.max().x(); ++u)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);

  // Left
  u = bbox.min().x();
  for (v = bbox.min().y(); v < bbox.max().y(); ++v)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);<commit_msg>improved geometry check<commit_after>// __BEGIN_LICENSE__
// Copyright (C) 2006, 2007 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


#include <vw/Stereo/PyramidCorrelator.h>
#include <vw/Stereo/OptimizedCorrelator.h>
#include <vw/Image/ImageViewRef.h>
#include <vw/FileIO/DiskImageResource.h>

using namespace vw;
using namespace stereo;

std::vector<vw::BBox2i>
PyramidCorrelator::subdivide_bboxes(ImageView<PixelMask<Vector2f> > const& disparity_map,
                                    ImageView<uint8> const& dmask,
                                    BBox2i const& box) {
  if (count_valid_pixels(crop(create_mask(dmask), box)) == 0) {
    return std::vector<BBox2i>();
  }

  // No need for try catch on disparity range, because subdivide_bboxes 
  // should only be called for valid subregions
  BBox2 disp_range = get_disparity_range(crop(disparity_map, box));
  bool bad_range = (disp_range.width()+1) * (disp_range.height()+1) > 4;
  
  BBox2i subbox1 = box, subbox2 = box;
  if (box.width() > box.height()) {
    subbox1.max().x() = box.min().x() + box.width()/2;
    subbox2.min().x() = box.min().x() + box.width()/2;
  } else {
    subbox1.max().y() = box.min().y() + box.height()/2;
    subbox2.min().y() = box.min().y() + box.height()/2;
  }

  bool good_size = subbox1.width() > m_min_subregion_dim && subbox1.height() > m_min_subregion_dim;
  bool good_subregion = is_good_subregion(disparity_map, dmask, subbox1) && is_good_subregion(disparity_map, dmask, subbox2);
  bool kill_invalid = count_valid_pixels(crop(create_mask(dmask), subbox1)) == 0 || count_valid_pixels(crop(create_mask(dmask), subbox2)) == 0;
  
  if (kill_invalid || (bad_range && good_size && good_subregion)) {
    std::vector<BBox2i> r = subdivide_bboxes(disparity_map, dmask, subbox1);
    std::vector<BBox2i> l = subdivide_bboxes(disparity_map, dmask, subbox2);
    r.insert(r.end(), l.begin(), l.end());
    return r;
  }
  
  std::vector<vw::BBox2i> result;
  result.push_back(box);
  return result;
}

void draw_bbox(ImageView<PixelRGB<float> > &view, BBox2i const& bbox) {
  int u,v;
  // Top
  v = bbox.min().y();
  for (u = bbox.min().x(); u < bbox.max().x(); ++u)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);

  // Bottom
  v = bbox.max().y()-1;
  for (u = bbox.min().x(); u < bbox.max().x(); ++u)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);

  // Left
  u = bbox.min().x();
  for (v = bbox.min().y(); v < bbox.max().y(); ++v)
    view(u,v) = vw::PixelRGB<float>(1.0,0.0,0.0);
{'fraction_non_alphanumeric': 0.17939814814814814, 'fraction_numerical': 0.02353395061728395, 'mean_word_length': 3.7351598173515983, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4804590', 'n_tokens_mistral': 2119, 'n_tokens_neox': 2037, 'n_words': 381}