<commit_before>
#include "slicer.hpp"
#include "options.hpp"

moab::Interface* mbi() {
  static moab::Core instance;
  return &instance;
}

struct program_option_struct opts;

bool point_match(moab::CartVect pnt1, moab::CartVect pnt2, double tolerance) {
  moab::CartVect diff = pnt2-pnt1; 

  return (diff.length() < tolerance);
}

moab::ErrorCode get_sets_by_category(moab::Range &entsets, char* category) {
  
  moab::ErrorCode result = moab::MB_SUCCESS;

  //get the name tag from the moab instance
  moab::Tag category_tag; 
  result = mbi()->tag_get_handle(CATEGORY_TAG_NAME, category_tag); 
  ERR_CHECK(result); 

  //create void pointer for tag data match
  const void *dum = &(category[0]);

  result = mbi()->get_entities_by_type_and_tag(0, moab::MBENTITYSET, &category_tag, &dum, 1, entsets);
  ERR_CHECK(result);
  
  return result;

}

moab::ErrorCode get_surfaces(moab::Range &surfs) {

  moab::ErrorCode result = moab::MB_SUCCESS;

  char category[CATEGORY_TAG_SIZE] = "Surface";
  
  result = get_sets_by_category(surfs, category);

  if (OPT_VERBOSE) std::cout << "There are " << surfs.size() << " surfaces in this model." << std::endl;

  return result;

}

moab::ErrorCode get_all_volumes(moab::Range &vols) {

  moab::ErrorCode result = moab::MB_SUCCESS;

  char category[CATEGORY_TAG_SIZE] = "Volume";
  
  result = get_sets_by_category(vols, category);
  
  if (OPT_VERBOSE) std::cout << "There are " << vols.size() << " volumes in this model." << std::endl;

  return result; 
}

moab::ErrorCode slice_faceted_model_out(std::string filename,
					int axis,
					double coord,
					std::vector< std::vector<double> > &x_pnts,
					std::vector< std::vector<double> > &y_pnts,
					std::vector< std::vector<int> > &codings,
					std::vector<std::string> &group_names,
					bool by_group,
					bool verbose, bool debug) {
  opts.verbose = verbose;
  opts.debug = debug;
  std::vector< std::vector<xypnt> > paths;
  moab::ErrorCode result = slice_faceted_model(filename, axis, coord, paths, codings, group_names, by_group);

  std::vector< std::vector<xypnt> >::iterator path;

  for (path = paths.begin(); path != paths.end(); path++) {
    std::vector<double> path_xs, path_ys;
    for (unsigned int i = 0; i < (*path).size(); i++)	{
      path_xs.push_back((*path)[i].x);
      path_ys.push_back((*path)[i].y);
    }
    x_pnts.push_back(path_xs);
    y_pnts.push_back(path_ys);
  }
  
  return result;
}

moab::ErrorCode slice_faceted_model(std::string filename,
				    int axis,
				    double coord,
				    std::vector< std::vector<xypnt> > &paths,
				    std::vector< std::vector<int> > &codings,
				    std::vector<std::string> &group_names, bool by_group) {
  
  moab::ErrorCode result;
  bool new_file = true;
  std::map<moab::EntityHandle,std::vector<Loop> > intersection_map;

  //get the filename_tag
  moab::Tag filename_tag;
  result = mbi()->tag_get_handle( FILENAME_TAG_NAME, 50, moab::MB_TYPE_OPAQUE, filename_tag, moab::MB_TAG_CREAT|moab::MB_TAG_SPARSE);
  ERR_CHECK(result);


  //check the root_set for this tag
  moab::EntityHandle root_set = mbi()->get_root_set();
  std::vector<moab::Tag> root_set_tags;
  result = mbi()->tag_get_tags_on_entity(root_set, root_set_tags);
  ERR_CHECK(result);


  std::vector<moab::Tag>::iterator val  = std::find(root_set_tags.begin(),root_set_tags.end(),filename_tag);
  if(val != root_set_tags.end()) { 
    //check that filename is the same
    std::string current_filename;
    current_filename.resize(50);
    result = mbi()->tag_get_data(filename_tag, &root_set, 1, (void*)current_filename.c_str());
    ERR_CHECK(result);
    std::cout << "Current filename: " << current_filename << std::endl;
    std::cout << "New Filename: " << filename << std::endl;
    current_filename.resize(filename.size());
    if(current_filename == filename) new_file = false;
  }
  

  if(new_file)
    {
      //remove all old mesh content
      result = mbi()->delete_mesh();
      ERR_CHECK(result);
      //load the new file
      std::cout << "Loading new file..." << std::endl;
      result = mbi()->load_file(filename.c_str());
      ERR_CHECK(result);

      //tag the root set with the filename
      moab::EntityHandle rs = mbi()->get_root_set();
      result = mbi()->tag_set_data(filename_tag,&rs,1,(void*)filename.c_str());
      ERR_CHECK(result);
    }
  
  moab::Range surfaces;
  result = get_surfaces(surfaces);
  ERR_CHECK(result);

  result = create_surface_intersections(surfaces, axis, coord, intersection_map);
  ERR_CHECK(result);<commit_msg>Removed unneeded output in create_slice.<commit_after>
#include "slicer.hpp"
#include "options.hpp"

moab::Interface* mbi() {
  static moab::Core instance;
  return &instance;
}

struct program_option_struct opts;

bool point_match(moab::CartVect pnt1, moab::CartVect pnt2, double tolerance) {
  moab::CartVect diff = pnt2-pnt1; 

  return (diff.length() < tolerance);
}

moab::ErrorCode get_sets_by_category(moab::Range &entsets, char* category) {
  
  moab::ErrorCode result = moab::MB_SUCCESS;

  //get the name tag from the moab instance
  moab::Tag category_tag; 
  result = mbi()->tag_get_handle(CATEGORY_TAG_NAME, category_tag); 
  ERR_CHECK(result); 

  //create void pointer for tag data match
  const void *dum = &(category[0]);

  result = mbi()->get_entities_by_type_and_tag(0, moab::MBENTITYSET, &category_tag, &dum, 1, entsets);
  ERR_CHECK(result);
  
  return result;

}

moab::ErrorCode get_surfaces(moab::Range &surfs) {

  moab::ErrorCode result = moab::MB_SUCCESS;

  char category[CATEGORY_TAG_SIZE] = "Surface";
  
  result = get_sets_by_category(surfs, category);

  if (OPT_VERBOSE) std::cout << "There are " << surfs.size() << " surfaces in this model." << std::endl;

  return result;

}

moab::ErrorCode get_all_volumes(moab::Range &vols) {

  moab::ErrorCode result = moab::MB_SUCCESS;

  char category[CATEGORY_TAG_SIZE] = "Volume";
  
  result = get_sets_by_category(vols, category);
  
  if (OPT_VERBOSE) std::cout << "There are " << vols.size() << " volumes in this model." << std::endl;

  return result; 
}

moab::ErrorCode slice_faceted_model_out(std::string filename,
					int axis,
					double coord,
					std::vector< std::vector<double> > &x_pnts,
					std::vector< std::vector<double> > &y_pnts,
					std::vector< std::vector<int> > &codings,
					std::vector<std::string> &group_names,
					bool by_group,
					bool verbose, bool debug) {
  opts.verbose = verbose;
  opts.debug = debug;
  std::vector< std::vector<xypnt> > paths;
  moab::ErrorCode result = slice_faceted_model(filename, axis, coord, paths, codings, group_names, by_group);

  std::vector< std::vector<xypnt> >::iterator path;

  for (path = paths.begin(); path != paths.end(); path++) {
    std::vector<double> path_xs, path_ys;
    for (unsigned int i = 0; i < (*path).size(); i++)	{
      path_xs.push_back((*path)[i].x);
      path_ys.push_back((*path)[i].y);
    }
    x_pnts.push_back(path_xs);
    y_pnts.push_back(path_ys);
  }
  
  return result;
}

moab::ErrorCode slice_faceted_model(std::string filename,
				    int axis,
				    double coord,
				    std::vector< std::vector<xypnt> > &paths,
				    std::vector< std::vector<int> > &codings,
				    std::vector<std::string> &group_names, bool by_group) {
  
  moab::ErrorCode result;
  bool new_file = true;
  std::map<moab::EntityHandle,std::vector<Loop> > intersection_map;

  //get the filename_tag
  moab::Tag filename_tag;
  result = mbi()->tag_get_handle( FILENAME_TAG_NAME, 50, moab::MB_TYPE_OPAQUE, filename_tag, moab::MB_TAG_CREAT|moab::MB_TAG_SPARSE);
  ERR_CHECK(result);


  //check the root_set for this tag
  moab::EntityHandle root_set = mbi()->get_root_set();
  std::vector<moab::Tag> root_set_tags;
  result = mbi()->tag_get_tags_on_entity(root_set, root_set_tags);
  ERR_CHECK(result);


  std::vector<moab::Tag>::iterator val  = std::find(root_set_tags.begin(),root_set_tags.end(),filename_tag);
  if(val != root_set_tags.end()) { 
    //check that filename is the same
    std::string current_filename;
    current_filename.resize(50);
    result = mbi()->tag_get_data(filename_tag, &root_set, 1, (void*)current_filename.c_str());
    ERR_CHECK(result);
    current_filename.resize(filename.size());
    if(current_filename == filename) new_file = false;
  }
  

  if(new_file)
    {
      //remove all old mesh content
      result = mbi()->delete_mesh();
      ERR_CHECK(result);
      //load the new file
      std::cout << "Loading new file..." << std::endl;
      result = mbi()->load_file(filename.c_str());
      ERR_CHECK(result);

      //tag the root set with the filename
      moab::EntityHandle rs = mbi()->get_root_set();
      result = mbi()->tag_set_data(filename_tag,&rs,1,(void*)filename.c_str());
      ERR_CHECK(result);
    }
  
  moab::Range surfaces;
  result = get_surfaces(surfaces);
  ERR_CHECK(result);

  result = create_surface_intersections(surfaces, axis, coord, intersection_map);
  ERR_CHECK(result);
{'fraction_non_alphanumeric': 0.14949201741654572, 'fraction_numerical': 0.0031260466674109637, 'mean_word_length': 4.313167259786477, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 65, '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': '177295', 'n_tokens_mistral': 3329, 'n_tokens_neox': 3171, 'n_words': 633}