本文整理汇总了C++中Way::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ Way::Read方法的具体用法?C++ Way::Read怎么用?C++ Way::Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Way
的用法示例。
在下文中一共展示了Way::Read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyWays
bool OptimizeAreaWayIdsGenerator::CopyWays(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
NodeUseMap& nodeUseMap)
{
FileScanner scanner;
FileWriter writer;
uint32_t dataCount=0;
progress.SetAction("Copy data from 'wayway.tmp' to 'ways.tmp'");
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"wayway.tmp"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'");
return false;
}
if (!scanner.Read(dataCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"ways.tmp"))) {
progress.Error(std::string("Cannot create '")+writer.GetFilename()+"'");
return false;
}
writer.Write(dataCount);
for (uint32_t current=1; current<=dataCount; current++) {
uint8_t type;
Id id;
Way data;
progress.SetProgress(current,dataCount);
if (!scanner.Read(type) ||
!scanner.Read(id) ||
!data.Read(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(current)+" of "+
NumberToString(dataCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
for (auto& id : data.ids) {
if (!nodeUseMap.IsNodeUsedAtLeastTwice(id)) {
id=0;
}
}
if (!writer.Write(type) ||
!writer.Write(id) ||
!data.Write(typeConfig,
writer)) {
progress.Error(std::string("Error while writing data entry to file '")+
writer.GetFilename()+"'");
return false;
}
}
if (!scanner.Close()) {
progress.Error(std::string("Error while closing file '")+
scanner.GetFilename()+"'");
return false;
}
if (!writer.Close()) {
progress.Error(std::string("Error while closing file '")+
writer.GetFilename()+"'");
return false;
}
return true;
}
示例2: ScanWayIds
bool OptimizeAreaWayIdsGenerator::ScanWayIds(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
NodeUseMap& nodeUseMap)
{
FileScanner scanner;
uint32_t dataCount=0;
progress.SetAction("Scanning ids from 'wayway.tmp'");
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"wayway.tmp"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'");
return false;
}
if (!scanner.Read(dataCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
for (uint32_t current=1; current<=dataCount; current++) {
uint8_t type;
Id id;
Way data;
progress.SetProgress(current,dataCount);
if (!scanner.Read(type) ||
!scanner.Read(id) ||
!data.Read(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(current)+" of "+
NumberToString(dataCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
if (!data.GetType()->CanRoute()) {
continue;
}
std::unordered_set<Id> nodeIds;
for (const auto& id : data.ids) {
if (nodeIds.find(id)==nodeIds.end()) {
nodeUseMap.SetNodeUsed(id);
nodeIds.insert(id);
}
}
// If we have a circular way, we "fake" a double usage,
// to make sure, that the node id of the first node
// is not dropped later on, and we cannot detect
// circular ways anymore
if (data.ids.front()==data.ids.back()) {
nodeUseMap.SetNodeUsed(data.ids.back());
}
}
if (!scanner.Close()) {
progress.Error(std::string("Error while closing file '")+
scanner.GetFilename()+"'");
return false;
}
return true;
}
示例3: Import
//.........这里部分代码省略.........
writer.WriteNumber(wayTypeData[i].cellYStart);
writer.WriteNumber(wayTypeData[i].cellYEnd);
}
}
if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"ways.dat"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error("Cannot open 'ways.dat'");
return false;
}
for (size_t l=parameter.GetAreaWayMinMag(); l<=maxLevel; l++) {
TypeInfoSet indexTypes(*typeConfig);
uint32_t wayCount;
double cellWidth=360.0/pow(2.0,(int)l);
double cellHeight=180.0/pow(2.0,(int)l);
wayScanner.GotoBegin();
for (const auto &type : typeConfig->GetWayTypes()) {
if (wayTypeData[type->GetIndex()].HasEntries() &&
wayTypeData[type->GetIndex()].indexLevel==l) {
indexTypes.Set(type);
}
}
if (indexTypes.Empty()) {
continue;
}
progress.Info("Scanning ways for index level "+NumberToString(l));
std::vector<CoordOffsetsMap> typeCellOffsets(typeConfig->GetTypeCount());
if (!wayScanner.Read(wayCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
Way way;
for (uint32_t w=1; w<=wayCount; w++) {
progress.SetProgress(w,wayCount);
FileOffset offset;
wayScanner.GetPos(offset);
if (!way.Read(*typeConfig,
wayScanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(w)+" of "+
NumberToString(wayCount)+
" in file '"+
wayScanner.GetFilename()+"'");
return false;
}
if (!indexTypes.IsSet(way.GetType())) {
continue;
}
GeoBox boundingBox;
way.GetBoundingBox(boundingBox);
//
// Calculate minimum and maximum tile ids that are covered
// by the way
// Renormalized coordinate space (everything is >=0)
//
uint32_t minxc=(uint32_t)floor((boundingBox.GetMinLon()+180.0)/cellWidth);
uint32_t maxxc=(uint32_t)floor((boundingBox.GetMaxLon()+180.0)/cellWidth);
uint32_t minyc=(uint32_t)floor((boundingBox.GetMinLat()+90.0)/cellHeight);
uint32_t maxyc=(uint32_t)floor((boundingBox.GetMaxLat()+90.0)/cellHeight);
for (uint32_t y=minyc; y<=maxyc; y++) {
for (uint32_t x=minxc; x<=maxxc; x++) {
typeCellOffsets[way.GetType()->GetIndex()][Pixel(x,y)].push_back(offset);
}
}
}
for (const auto &type : indexTypes) {
size_t index=type->GetIndex();
if (!WriteBitmap(progress,
writer,
*typeConfig->GetTypeInfo(index),
wayTypeData[index],
typeCellOffsets[index])) {
return false;
}
}
}
return !writer.HasError() && writer.Close();
}
示例4: Import
bool AreaWayIndexGenerator::Import(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig)
{
FileScanner wayScanner;
FileWriter writer;
std::set<TypeId> remainingWayTypes;
std::vector<TypeData> wayTypeData;
size_t level;
size_t maxLevel=0;
wayTypeData.resize(typeConfig.GetTypes().size());
if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"ways.dat"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error("Cannot open 'ways.dat'");
return false;
}
//
// Scanning distribution
//
progress.SetAction("Scanning level distribution of way types");
for (size_t i=0; i<typeConfig.GetTypes().size(); i++) {
if (typeConfig.GetTypeInfo(i).CanBeWay() &&
!typeConfig.GetTypeInfo(i).GetIgnore()) {
remainingWayTypes.insert(i);
}
}
level=parameter.GetAreaWayMinMag();
while (!remainingWayTypes.empty()) {
uint32_t wayCount=0;
std::set<TypeId> currentWayTypes(remainingWayTypes);
double cellWidth=360.0/pow(2.0,(int)level);
double cellHeight=180.0/pow(2.0,(int)level);
std::vector<CoordCountMap> cellFillCount(typeConfig.GetTypes().size());
progress.Info("Scanning Level "+NumberToString(level)+" ("+NumberToString(remainingWayTypes.size())+" types remaining)");
wayScanner.GotoBegin();
if (!wayScanner.Read(wayCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
Way way;
for (uint32_t w=1; w<=wayCount; w++) {
progress.SetProgress(w,wayCount);
if (!way.Read(wayScanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(w)+" of "+
NumberToString(wayCount)+
" in file '"+
wayScanner.GetFilename()+"'");
return false;
}
// Count number of entries per current type and coordinate
if (currentWayTypes.find(way.GetType())==currentWayTypes.end()) {
continue;
}
double minLon;
double maxLon;
double minLat;
double maxLat;
way.GetBoundingBox(minLon,maxLon,minLat,maxLat);
//
// Calculate minimum and maximum tile ids that are covered
// by the way
// Renormated coordinate space (everything is >=0)
//
uint32_t minxc=(uint32_t)floor((minLon+180.0)/cellWidth);
uint32_t maxxc=(uint32_t)floor((maxLon+180.0)/cellWidth);
uint32_t minyc=(uint32_t)floor((minLat+90.0)/cellHeight);
uint32_t maxyc=(uint32_t)floor((maxLat+90.0)/cellHeight);
for (uint32_t y=minyc; y<=maxyc; y++) {
for (uint32_t x=minxc; x<=maxxc; x++) {
cellFillCount[way.GetType()][Pixel(x,y)]++;
}
}
}
// Check if cell fill for current type is in defined limits
for (size_t i=0; i<typeConfig.GetTypes().size(); i++) {
if (currentWayTypes.find(i)!=currentWayTypes.end()) {
CalculateStatistics(level,wayTypeData[i],cellFillCount[i]);
if (!FitsIndexCriteria(parameter,
//.........这里部分代码省略.........
示例5: CalculateDistribution
bool AreaWayIndexGenerator::CalculateDistribution(const TypeConfigRef& typeConfig,
const ImportParameter& parameter,
Progress& progress,
std::vector<TypeData>& wayTypeData,
size_t& maxLevel) const
{
FileScanner wayScanner;
TypeInfoSet remainingWayTypes;
size_t level;
maxLevel=0;
wayTypeData.resize(typeConfig->GetTypeCount());
if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"ways.dat"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error("Cannot open 'ways.dat'");
return false;
}
remainingWayTypes.Set(typeConfig->GetWayTypes());
level=parameter.GetAreaWayMinMag();
while (!remainingWayTypes.Empty()) {
uint32_t wayCount=0;
TypeInfoSet currentWayTypes(remainingWayTypes);
double cellWidth=360.0/pow(2.0,(int)level);
double cellHeight=180.0/pow(2.0,(int)level);
std::vector<CoordCountMap> cellFillCount(typeConfig->GetTypeCount());
progress.Info("Scanning Level "+NumberToString(level)+" ("+NumberToString(remainingWayTypes.Size())+" types remaining)");
wayScanner.GotoBegin();
if (!wayScanner.Read(wayCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
Way way;
for (uint32_t w=1; w<=wayCount; w++) {
progress.SetProgress(w,wayCount);
if (!way.Read(*typeConfig,
wayScanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(w)+" of "+
NumberToString(wayCount)+
" in file '"+
wayScanner.GetFilename()+"'");
return false;
}
// Count number of entries per current type and coordinate
if (!currentWayTypes.IsSet(way.GetType())) {
continue;
}
GeoBox boundingBox;
way.GetBoundingBox(boundingBox);
//
// Calculate minimum and maximum tile ids that are covered
// by the way
// Renormalized coordinate space (everything is >=0)
//
uint32_t minxc=(uint32_t)floor((boundingBox.GetMinLon()+180.0)/cellWidth);
uint32_t maxxc=(uint32_t)floor((boundingBox.GetMaxLon()+180.0)/cellWidth);
uint32_t minyc=(uint32_t)floor((boundingBox.GetMinLat()+90.0)/cellHeight);
uint32_t maxyc=(uint32_t)floor((boundingBox.GetMaxLat()+90.0)/cellHeight);
for (uint32_t y=minyc; y<=maxyc; y++) {
for (uint32_t x=minxc; x<=maxxc; x++) {
cellFillCount[way.GetType()->GetIndex()][Pixel(x,y)]++;
}
}
}
// Check if cell fill for current type is in defined limits
for (auto &type : currentWayTypes) {
size_t i=type->GetIndex();
CalculateStatistics(level,
wayTypeData[i],
cellFillCount[i]);
if (!FitsIndexCriteria(parameter,
progress,
*typeConfig->GetTypeInfo(i),
wayTypeData[i],
cellFillCount[i])) {
currentWayTypes.Remove(type);
}
}
for (const auto &type : currentWayTypes) {
maxLevel=std::max(maxLevel,level);
//.........这里部分代码省略.........