<commit_before>/*
 * Copyright (c) 2012. The Regents of the University of California. All rights reserved.
 * Licensed pursuant to the terms and conditions available for viewing at:
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * File: featurematcher.cpp
 * Author: <NAME>
 * Last Modified: 11.17.2012
 */

#include <FeatureMatcher/featurematcher.h>

#include <vector>
#include <set>

#include <cvd/timer.h>

namespace vrlt {
    
    static void addFeatures( Camera *camera, bool triangulated, std::vector<Feature*> &features )
    {
        ElementList::iterator it;
        for ( it = camera->features.begin(); it != camera->features.end(); it++ )
        {
            Feature *feature = (Feature *)it->second;
            if ( triangulated )
            {
                if ( feature->track == NULL ) continue;
                if ( feature->track->point == NULL ) continue;
            }
            features.push_back( feature );
        }
    }
    
    void addFeatures( Node *node, bool triangulated, std::vector<Feature*> &features )
    {
        if ( node->camera != NULL )
        {
            addFeatures( node->camera, triangulated, features );
        }
        
        ElementList::iterator it;
        for ( it = node->children.begin(); it != node->children.end(); it++ )
        {
            Node *child = (Node *)it->second;
            
            addFeatures( child, triangulated, features );
        }
    }

    FeatureMatcher::FeatureMatcher( NN *nn, bool _deleteNN ) : index( nn ), deleteNN( _deleteNN ), data( NULL ), deleteFeatures( false )
    {
    }

    void FeatureMatcher::init( Node *node, bool triangulated, bool averageDescriptors )
    {
        if ( !features.empty() ) {
            delete [] data;
            data = NULL;
            if ( deleteFeatures ) {
                for ( int i = 0; i < features.size(); i++ ) {
                    delete [] features[i]->descriptor;
                    delete features[i];
                }
            }
            features.clear();
        }
        
        addFeatures( node, triangulated, features );
        if ( features.empty() ) return;
        
        if ( averageDescriptors )
        {
            std::set<Point*> points;
            for ( int i = 0; i < features.size(); i++ ) points.insert( features[i]->track->point );<commit_msg>Converted FeatureMatcher<commit_after>/*
 * Copyright (c) 2012. The Regents of the University of California. All rights reserved.
 * Licensed pursuant to the terms and conditions available for viewing at:
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * File: featurematcher.cpp
 * Author: <NAME>
 * Last Modified: 11.17.2012
 */

#include <FeatureMatcher/featurematcher.h>

#include <vector>
#include <set>

namespace vrlt {
    
    static void addFeatures( Camera *camera, bool triangulated, std::vector<Feature*> &features )
    {
        ElementList::iterator it;
        for ( it = camera->features.begin(); it != camera->features.end(); it++ )
        {
            Feature *feature = (Feature *)it->second;
            if ( triangulated )
            {
                if ( feature->track == NULL ) continue;
                if ( feature->track->point == NULL ) continue;
            }
            features.push_back( feature );
        }
    }
    
    void addFeatures( Node *node, bool triangulated, std::vector<Feature*> &features )
    {
        if ( node->camera != NULL )
        {
            addFeatures( node->camera, triangulated, features );
        }
        
        ElementList::iterator it;
        for ( it = node->children.begin(); it != node->children.end(); it++ )
        {
            Node *child = (Node *)it->second;
            
            addFeatures( child, triangulated, features );
        }
    }

    FeatureMatcher::FeatureMatcher( NN *nn, bool _deleteNN ) : data( NULL ), index( nn ), deleteNN( _deleteNN ), deleteFeatures( false )
    {
    }

    void FeatureMatcher::init( Node *node, bool triangulated, bool averageDescriptors )
    {
        if ( !features.empty() ) {
            delete [] data;
            data = NULL;
            if ( deleteFeatures ) {
                for ( int i = 0; i < features.size(); i++ ) {
                    delete [] features[i]->descriptor;
                    delete features[i];
                }
            }
            features.clear();
        }
        
        addFeatures( node, triangulated, features );
        if ( features.empty() ) return;
        
        if ( averageDescriptors )
        {
            std::set<Point*> points;
            for ( int i = 0; i < features.size(); i++ ) points.insert( features[i]->track->point );
{'fraction_non_alphanumeric': 0.1273817169770927, 'fraction_numerical': 0.006422607578676943, 'mean_word_length': 1.8401215805471125, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 46, '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': '6943612', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1241, 'n_words': 335}