示例#1
0
    bool LoadData(const osmscout::Projection& projection,
                  osmscout::MapData& data)
    {
        osmscout::TypeSet              nodeTypes;
        std::vector<osmscout::TypeSet> wayTypes;
        osmscout::TypeSet              areaTypes;

        styleConfig->GetNodeTypesWithMaxMag(projection.GetMagnification(),
                                            nodeTypes);

        styleConfig->GetWayTypesByPrioWithMaxMag(projection.GetMagnification(),
                wayTypes);

        styleConfig->GetAreaTypesWithMaxMag(projection.GetMagnification(),
                                            areaTypes);

        return database->GetObjects(nodeTypes,
                                    wayTypes,
                                    areaTypes,
                                    projection.GetLonMin(),
                                    projection.GetLatMin(),
                                    projection.GetLonMax(),
                                    projection.GetLatMax(),
                                    projection.GetMagnification(),
                                    searchParameter,
                                    data.nodes,
                                    data.ways,
                                    data.areas);
    }
bool TestAreaIndexAcceess(osmscout::DatabaseRef& database,
                          osmscout::StyleConfig& styleConfig,
                          size_t threadCount,
                          size_t iterationCount)
{
  bool result=true;

  osmscout::TypeConfigRef typeConfig=database->GetTypeConfig();
  osmscout::TypeInfoSet   nodeTypes;
  osmscout::TypeInfoSet   optimizedWayTypes;
  osmscout::TypeInfoSet   wayTypes;
  osmscout::TypeInfoSet   optimizedAreaTypes;
  osmscout::TypeInfoSet   areaTypes;
  osmscout::Magnification magnification;

  magnification.SetLevel(AREAINDEXACCESS_AREA_LEVEL);

  osmscout::AreaNodeIndexRef        areaNodeIndex=database->GetAreaNodeIndex();
  osmscout::AreaWayIndexRef         areaWayIndex=database->GetAreaWayIndex();
  osmscout::OptimizeWaysLowZoomRef  areaOptimizedWayIndex=database->GetOptimizeWaysLowZoom();
  osmscout::AreaAreaIndexRef        areaAreaIndex=database->GetAreaAreaIndex();
  osmscout::OptimizeAreasLowZoomRef areaOptimizedAreaIndex=database->GetOptimizeAreasLowZoom();

  std::cout << "Collection test data..." << std::endl;

  styleConfig.GetNodeTypesWithMaxMag(magnification,
                                     nodeTypes);

  styleConfig.GetWayTypesWithMaxMag(magnification,
                                    wayTypes);

  styleConfig.GetAreaTypesWithMaxMag(magnification,
                                     areaTypes);

  if (areaOptimizedWayIndex->HasOptimizations(magnification.GetMagnification())) {
    areaOptimizedWayIndex->GetTypes(magnification,
                                    wayTypes,
                                    optimizedWayTypes);

    wayTypes.Remove(optimizedWayTypes);
  }

  if (areaOptimizedAreaIndex->HasOptimizations(magnification.GetMagnification())) {
    areaOptimizedAreaIndex->GetTypes(magnification,
                                     areaTypes,
                                     optimizedAreaTypes);

    areaTypes.Remove(optimizedAreaTypes);
  }

  std::cout << " - " << nodeTypes.Size() << " node type(s)" << std::endl;
  std::cout << " - " << optimizedWayTypes.Size() << " optimized way type(s)" << std::endl;
  std::cout << " - " << wayTypes.Size() << " way type(s)" << std::endl;
  std::cout << " - " << optimizedAreaTypes.Size() << " optimized area type(s)" << std::endl;
  std::cout << " - " << areaTypes.Size() << " area type(s)" << std::endl;

  osmscout::GeoBox mapBoundingBox;

  database->GetBoundingBox(mapBoundingBox);

  std::list<AreaIndexTestData> testDataSet;

  AreaIndexTestData testData;

  testData.typeConfig=typeConfig;
  testData.magnification=magnification;
  testData.nodeTypes=nodeTypes;
  testData.optimizedWayTypes=optimizedWayTypes;
  testData.wayTypes=wayTypes;
  testData.optimizedAreaTypes=optimizedAreaTypes;
  testData.areaTypes=areaTypes;
  testData.boundingBox=mapBoundingBox;

  testDataSet.push_back(testData);

  testData.boundingBox=osmscout::GeoBox(osmscout::GeoCoord(mapBoundingBox.GetMinLat()+mapBoundingBox.GetHeight()/3,
                                                           mapBoundingBox.GetMinLon()+mapBoundingBox.GetWidth()/3),
                                        osmscout::GeoCoord(mapBoundingBox.GetMaxLat()-mapBoundingBox.GetHeight()/3,
                                                           mapBoundingBox.GetMaxLon()-mapBoundingBox.GetWidth()/3));

  testDataSet.push_back(testData);

  testData.boundingBox=osmscout::GeoBox(osmscout::GeoCoord(mapBoundingBox.GetMinLat()+4*mapBoundingBox.GetHeight()/10,
                                                           mapBoundingBox.GetMinLon()+4*mapBoundingBox.GetWidth()/10),
                                        osmscout::GeoCoord(mapBoundingBox.GetMaxLat()-4*mapBoundingBox.GetHeight()/10,
                                                           mapBoundingBox.GetMaxLon()-4*mapBoundingBox.GetWidth()/10));

  testDataSet.push_back(testData);

  for (auto& testData : testDataSet) {
    std::cout << " - BoundingBox " << testData.boundingBox.GetDisplayText() << ":" << std::endl;

    if (!areaNodeIndex->GetOffsets(testData.boundingBox,
                                   testData.nodeTypes,
                                   testData.nodeOffsets,
                                   testData.loadedNodeTypes)) {
      return false;
    }

    std::cout << "   * " << testData.nodeOffsets.size() << " node offset(s)" << std::endl;

    if (!areaWayIndex->GetOffsets(testData.boundingBox,
                                  testData.wayTypes,
                                  testData.wayOffsets,
                                  testData.loadedWayTypes)) {
      return false;
    }

    std::cout << "   * " << testData.wayOffsets.size() << " way offset(s)" << std::endl;

    if (!areaAreaIndex->GetAreasInArea(*testData.typeConfig,
                                       testData.boundingBox,
                                       AREAINDEXACCESS_AREA_LEVEL+4,
                                       testData.areaTypes,
                                       testData.areaOffsets,
                                       testData.loadedAreaTypes)) {
      return false;
    }

    std::cout << "   * " << testData.areaOffsets.size() << " area offset(s)" << std::endl;
  }

  std::cout << "Starting retrieval threads..." << std::endl;

  std::vector<std::thread> threads(threadCount);
  bool                     *results;

  results=new bool[threadCount];

  for (size_t i=0; i<threads.size(); i++) {
    threads[i]=std::thread(AccessAreaIndex,
                           std::ref(database),
                           iterationCount,
                           std::ref(testDataSet),
                           std::ref(results[i]));
  }

  for (size_t i=0; i<threads.size(); i++) {
    threads[i].join();

    if (!results[i]) {
      result=false;
    }
  }

  delete [] results;

  std::cout << "Threads finished." << std::endl;

  return result;
}