当前位置: 首页>>代码示例>>C++>>正文


C++ QuadTree::mapNodes方法代码示例

本文整理汇总了C++中QuadTree::mapNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree::mapNodes方法的具体用法?C++ QuadTree::mapNodes怎么用?C++ QuadTree::mapNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QuadTree的用法示例。


在下文中一共展示了QuadTree::mapNodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
            switch(i){
                case 2:// INCIDENT_TYPE_DESCRIPTION
                    ;
                    incidentType = string(buff); 
                    iter = incidentTypes.find(incidentType);
                    if(iter == incidentTypes.end()){
                        // Then the incidentType isn't in incidentTypes
                        incidentTypes.emplace(incidentType, incidentCount);
                        c->type = incidentCount;
                        incidentCount++;
                    }else{
                        c->type = iter->second;
                    }
                    break;
                case 6: // FROMDATE
                    c->date.setDate(buff);
                    break;
                case 7: // WEAPONTYPE (either Unarmed, Other, Knife, or Firearm)
                    switch(buff[0]){
                        case 'U': // Unarmed
                            c->weapon = 0;
                            break;
                        case 'O': // Other
                            c->weapon = 1;
                            break;
                        case 'K': // Knife
                            c->weapon = 2;
                            break;
                        case 'F': // Firearm
                            c->weapon = 3;
                            break;
                        default:
                            break;
                    }
                    break;
                case 8: //Shooting (Yes or No)
                    
                    // If there was a shooting, add a shooting flag
                    if(buff[0] == 'Y'){ 
                        c->weapon += 4;
                    }
                    break;
                default:
                    break;
            }
        }   
        crimeFile.getline(buff, 128); //This is the location
        l.setLocation(buff);
        m.setLocation((l.x - MIN_LAT)*LAT_TO_METERS , 
                      (l.y - MIN_LNG)*LNG_TO_METERS);
        // Output the crime CSV
        crimeOut << '"' << l << "\", " << c->date << ", "
                 << int(c->type) << ", " << int(c->weapon) << endl;
        
        // the call to quad.findNodes(m, 100) finds all nodes in the QuadTree within
        // a distance of 100 from the location m, which is the metric coordinates of the crime
        vector<Restauraunt*> v = quad.findNodes(m, 100);
        
        // This bit iterates through and adds the crime to the objects of nearby restauraunts
        if(!v.empty()){
            int initialCost = initialCrimeCost(*c);
            // If the initial cost is 0, no need to add the crime, as that means it was ignorable?
            // Basically I just decided that a MedAssist incident probably shouldn't be counted,
            // although I don't actually kknow what that means, its frequency and name suggests
            // that perhaps the police were merely assisting with something of a medical nature.
            
            if(initialCost > 0){
                for(Restauraunt* r: v){
                    r->addCrime(c, m, initialCost, now);
                }
            }
        }
        // if c->copies = 0, then it wasn't within 100 meters of any restauraunt and should be deleted
        if(c->copies = 0)
            delete c;
        else
            crimes.push_back(c);
        i++;
        if(i%100 == 0)
            cout << i << " crimes processed\n";
    }
    crimeFile.close();
    crimeOut.close();
    cout << "MedAssist: " << (int)incidentTypes["MedAssist"] << endl;
    // This section outputs the food CSV nice and succinctly
    ofstream foodOut (FOOD_OUT);
    foodOut << "Location, Name, Date, Address, Description, CrimeCost, Crimes\n";
    quad.mapNodes(writeRestauraunt, &foodOut);
    
    for(struct Crime* crime : crimes){
        delete crime;
    }
    
    delete addresses;
    
    // I should free all of the restauraunts in the quad, but this doesn't seem
    // to work and I don't really care that much for a one-off script:
    // quad.mapNodes(deleteRestauraunt, NULL);
    
}
开发者ID:digitaltembo,项目名称:Crime-And-Dining,代码行数:101,代码来源:analysis.cpp


注:本文中的QuadTree::mapNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。