<commit_before>#include <objectExtractor.h>
typedef pcl::PointXYZRGB PointT;

ObjectExtractor::ObjectExtractor(bool showViewer){
    cloud.reset(new pcl::PointCloud<PointT>);
    pclViewer.reset(new pcl::visualization::PCLVisualizer ("3DViewer"));
    pclViewer->registerKeyboardCallback(&ObjectExtractor::keyboard_callback,*this, (void*)&pclViewer);
    set_showUI(showViewer);
    l_count = 0;
    index_to_grasp = 0;
    object_to_grasp.reset(new pcl::PointCloud<PointT>);
    initialize_object_to_grasp = true;
    setPCLViewer();
}

void ObjectExtractor::extraction_callback(const pcl::PCLPointCloud2ConstPtr& input){

    pcl::PointCloud<PointT>::Ptr objects(new pcl::PointCloud<PointT>);
    pcl::fromPCLPointCloud2(*input,*objects);
    cloud = objects;

    //Extract objects
    if(!object_vector.empty()){object_vector.clear();}
    object_vector = segment_objects(objects,0.02,200,15000);


    // Initialize object to grasp
    if(initialize_object_to_grasp){
        object_to_grasp = object_vector[index_to_grasp];
        initialize_object_to_grasp = false;
    }

    if(showUI){
        printToPCLViewer();
    }

}


void ObjectExtractor::printToPCLViewer(){
    pclViewer->removeAllPointClouds();

    for(int i=0; i < object_vector.size(); i++){
        pcl::PointCloud<PointT>::Ptr pc = object_vector[i];
        pcl::visualization::PointCloudColorHandlerRandom<PointT> randColor(pc);
        std::stringstream ss;
        ss << i;
        std::string ind = ss.str();
        std::string pc_name = "object_" + ind;
        pclViewer->addPointCloud<PointT>(pc,randColor,pc_name);
        pclViewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, pc_name);
    }

    pcl::visualization::PointCloudColorHandlerRGBField<PointT> rgb(object_to_grasp);
    pclViewer->addPointCloud<PointT>(object_to_grasp,rgb,"source cloud");
    pclViewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "object_to_grasp");
}

void ObjectExtractor::keyboard_callback(const pcl::visualization::KeyboardEvent &event, void* viewer_void){
    l_count = l_count + 1;
    if(l_count < 2){
        boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *> (viewer_void);
        if (event.getKeySym () == "p"){
            if(showUI){
                showUI=false;
            }
            else{
                showUI=true;
            }
        }
        else if(event.getKeySym () == "s"){
            if(index_to_grasp+1 < object_vector.size()){
                index_to_grasp++;
            }
            else{
                index_to_grasp = 0;
            }
            // object_to_track = addNormalsToPointCloud(object_vector[index_to_track]);
            object_to_grasp = object_vector[index_to_grasp];
        }<commit_msg>object to grasp represented in a yellow pointcloud<commit_after>#include <objectExtractor.h>
typedef pcl::PointXYZRGB PointT;

ObjectExtractor::ObjectExtractor(bool showViewer){
    cloud.reset(new pcl::PointCloud<PointT>);
    pclViewer.reset(new pcl::visualization::PCLVisualizer ("3DViewer"));
    pclViewer->registerKeyboardCallback(&ObjectExtractor::keyboard_callback,*this, (void*)&pclViewer);
    set_showUI(showViewer);
    l_count = 0;
    index_to_grasp = 0;
    object_to_grasp.reset(new pcl::PointCloud<PointT>);
    initialize_object_to_grasp = true;
    setPCLViewer();
}

void ObjectExtractor::extraction_callback(const pcl::PCLPointCloud2ConstPtr& input){

    pcl::PointCloud<PointT>::Ptr objects(new pcl::PointCloud<PointT>);
    pcl::fromPCLPointCloud2(*input,*objects);
    cloud = objects;

    //Extract objects
    if(!object_vector.empty()){object_vector.clear();}
    object_vector = segment_objects(objects,0.02,200,15000);


    // Initialize object to grasp
    if((!object_vector.empty()) && initialize_object_to_grasp){
        object_to_grasp = object_vector[index_to_grasp];
        initialize_object_to_grasp = false;
    }

    if(showUI){
        printToPCLViewer();
    }

}


void ObjectExtractor::printToPCLViewer(){
    pclViewer->removeAllPointClouds();

    for(int i=0; i < object_vector.size(); i++){
        pcl::PointCloud<PointT>::Ptr pc = object_vector[i];
        pcl::visualization::PointCloudColorHandlerRandom<PointT> randColor(pc);
        std::stringstream ss;
        ss << i;
        std::string ind = ss.str();
        std::string pc_name = "object_" + ind;
        pclViewer->addPointCloud<PointT>(pc,randColor,pc_name);
        pclViewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, pc_name);
    }

//    pcl::visualization::PointCloudColorHandlerRGBField<PointT> rgb(object_to_grasp);
//    pclViewer->addPointCloud<PointT>(object_to_grasp,rgb,"object_to_grasp");
//    pclViewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "object_to_grasp");

    pcl::visualization::PointCloudColorHandlerCustom<PointT> yellow_color(object_to_grasp, 255, 255, 102);
    pclViewer->addPointCloud<PointT>(object_to_grasp,yellow_color,"object_to_grasp");
    pclViewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "object_to_grasp");
}

void ObjectExtractor::keyboard_callback(const pcl::visualization::KeyboardEvent &event, void* viewer_void){
    l_count = l_count + 1;
    if(l_count < 2){
        boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *> (viewer_void);
        if (event.getKeySym () == "p"){
            if(showUI){
                showUI=false;
            }
            else{
                showUI=true;
            }
        }
        else if(event.getKeySym () == "s"){
            if(index_to_grasp+1 < object_vector.size()){
                index_to_grasp++;
            }
            else{
                index_to_grasp = 0;
            }
            // object_to_track = addNormalsToPointCloud(object_vector[index_to_track]);
            object_to_grasp = object_vector[index_to_grasp];
        }
{'fraction_non_alphanumeric': 0.12632264365944978, 'fraction_numerical': 0.009116067068207716, 'mean_word_length': 3.7813229571984435, 'pattern_counts': {'":': 0, '<': 41, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7451920', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2021, 'n_words': 261}