<commit_before>#include <gpg/candidates_generator.h>


CandidatesGenerator::CandidatesGenerator(const Parameters& params,
  const HandSearch::Parameters& hand_search_params) : params_(params)
{
  Eigen::initParallel();

  hand_search_ = new HandSearch(hand_search_params);
}


void CandidatesGenerator::preprocessPointCloud(CloudCamera& cloud_cam)
{
//  const double VOXEL_SIZE = 0.002;
  const double VOXEL_SIZE = 0.003;

  std::cout << "Processing cloud with: " << cloud_cam.getCloudOriginal()->size() << " points.\n";

  // Calculate surface normals using integral images if possible.
  if (cloud_cam.getCloudOriginal()->isOrganized() && cloud_cam.getNormals().cols() == 0)
  {
    cloud_cam.calculateNormals(0);
  }

  // perform statistical outlier removal
  if (params_.remove_statistical_outliers_)
  {
    //    Plot plotter;
    //    plotter.drawCloud(cloud_cam.getCloudProcessed(), "before");

    // Create the filtering object
    pcl::StatisticalOutlierRemoval<pcl::PointXYZRGBA> sor;
    sor.setInputCloud(cloud_cam.getCloudProcessed());
    sor.setMeanK(50);
    sor.setStddevMulThresh(1.0);
    sor.filter(*cloud_cam.getCloudProcessed());
    std::cout << "Cloud after removing statistical outliers: " << cloud_cam.getCloudProcessed()->size() << std::endl;
    //    plotter.drawCloud(cloud_cam.getCloudProcessed(), "after");
  }

  // No indices into point cloud given
  if (cloud_cam.getSampleIndices().size() == 0)
  {
    // 1. Workspace filtering
    cloud_cam.filterWorkspace(params_.workspace_);
    std::cout << "After workspace filtering: " << cloud_cam.getCloudProcessed()->size() << " points left.\n";

    // 2. Voxelization
    if (params_.voxelize_)
    {
      cloud_cam.voxelizeCloud(VOXEL_SIZE);
      std::cout << "After voxelization: " << cloud_cam.getCloudProcessed()->size() << " points left.\n";
    }

    // 3. Subsampling
    if (cloud_cam.getSamples().cols() > 0)
    {
      // 4. Calculate surface normals.
      if (cloud_cam.getNormals().cols() == 0)
      {
        cloud_cam.calculateNormals(params_.num_threads_);
      }

      // 5. Subsample the remaining samples.
      cloud_cam.subsampleSamples(params_.num_samples_);
    }
    else
    {
      if (params_.num_samples_ > cloud_cam.getCloudProcessed()->size())
      {
        std::vector<int> indices_all(cloud_cam.getCloudProcessed()->size());
        for (int i=0; i < cloud_cam.getCloudProcessed()->size(); i++)
          indices_all[i] = i;
        cloud_cam.setSampleIndices(indices_all);
        std::cout << "Cloud is smaller than num_samples. Subsampled all " << cloud_cam.getCloudProcessed()->size()
          << " points.\n";<commit_msg>fix crash when zero points left after workspace filtering<commit_after>#include <gpg/candidates_generator.h>


CandidatesGenerator::CandidatesGenerator(const Parameters& params,
  const HandSearch::Parameters& hand_search_params) : params_(params)
{
  Eigen::initParallel();

  hand_search_ = new HandSearch(hand_search_params);
}


void CandidatesGenerator::preprocessPointCloud(CloudCamera& cloud_cam)
{
//  const double VOXEL_SIZE = 0.002;
  const double VOXEL_SIZE = 0.003;

  std::cout << "Processing cloud with: " << cloud_cam.getCloudOriginal()->size() << " points.\n";

  // Calculate surface normals using integral images if possible.
  if (cloud_cam.getCloudOriginal()->isOrganized() && cloud_cam.getNormals().cols() == 0)
  {
    cloud_cam.calculateNormals(0);
  }

  // perform statistical outlier removal
  if (params_.remove_statistical_outliers_)
  {
    //    Plot plotter;
    //    plotter.drawCloud(cloud_cam.getCloudProcessed(), "before");

    // Create the filtering object
    pcl::StatisticalOutlierRemoval<pcl::PointXYZRGBA> sor;
    sor.setInputCloud(cloud_cam.getCloudProcessed());
    sor.setMeanK(50);
    sor.setStddevMulThresh(1.0);
    sor.filter(*cloud_cam.getCloudProcessed());
    std::cout << "Cloud after removing statistical outliers: " << cloud_cam.getCloudProcessed()->size() << std::endl;
    //    plotter.drawCloud(cloud_cam.getCloudProcessed(), "after");
  }

  // No indices into point cloud given
  if (cloud_cam.getSampleIndices().size() == 0)
  {
    // 1. Workspace filtering
    cloud_cam.filterWorkspace(params_.workspace_);
    std::cout << "After workspace filtering: " << cloud_cam.getCloudProcessed()->size() << " points left.\n";

    if (cloud_cam.getCloudProcessed()->size() == 0)
    {
      return;
    }

    // 2. Voxelization
    if (params_.voxelize_)
    {
      cloud_cam.voxelizeCloud(VOXEL_SIZE);
      std::cout << "After voxelization: " << cloud_cam.getCloudProcessed()->size() << " points left.\n";
    }

    // 3. Subsampling
    if (cloud_cam.getSamples().cols() > 0)
    {
      // 4. Calculate surface normals.
      if (cloud_cam.getNormals().cols() == 0)
      {
        cloud_cam.calculateNormals(params_.num_threads_);
      }

      // 5. Subsample the remaining samples.
      cloud_cam.subsampleSamples(params_.num_samples_);
    }
    else
    {
      if (params_.num_samples_ > cloud_cam.getCloudProcessed()->size())
      {
        std::vector<int> indices_all(cloud_cam.getCloudProcessed()->size());
        for (int i=0; i < cloud_cam.getCloudProcessed()->size(); i++)
          indices_all[i] = i;
        cloud_cam.setSampleIndices(indices_all);
        std::cout << "Cloud is smaller than num_samples. Subsampled all " << cloud_cam.getCloudProcessed()->size()
          << " points.\n";
{'fraction_non_alphanumeric': 0.14251519057263856, 'fraction_numerical': 0.008654023200147302, 'mean_word_length': 3.5456066945606692, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7567395', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1702, 'n_words': 307}