[drape] read feature indexes in rect

This commit is contained in:
ExMix 2014-01-15 10:41:23 +03:00 committed by Alex Zolotarev
parent f62a91e8aa
commit 796d3e4632
10 changed files with 171 additions and 29 deletions

View file

@ -117,10 +117,8 @@ void Batcher::InsertTriangles(const GLState & state, strategy s, RefPointer<Attr
ASSERT(availableIndexCount != 0, ("Buffer must be filnalized on previous iteration"));
ASSERT(availableVertexCount != 0, ("Buffer must be filnalized on previous iteration"));
bool needFinalizeBuffer = false;
if (vertexCount > availableVertexCount || indexCount > availableIndexCount)
{
needFinalizeBuffer = true;
if (s.GetIndexCount(availableVertexCount) <= availableIndexCount)
vertexCount = availableVertexCount;
else
@ -146,7 +144,8 @@ void Batcher::InsertTriangles(const GLState & state, strategy s, RefPointer<Attr
}
params->Advance(vertexCount);
if (needFinalizeBuffer)
if (!(buffer->GetAvailableIndexCount() > 3 &&
buffer->GetAvailableVertexCount() > 3))
FinalizeBuffer(state);
}
}

View file

@ -47,12 +47,21 @@ namespace df
, m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
{
///{ Temporary initialization
Platform::FilesList maps;
Platform & pl = GetPlatform();
pl.GetFilesByExt(pl.WritableDir(), DATA_FILE_EXTENSION, maps);
for_each(maps.begin(), maps.end(), bind(&model::FeaturesFetcher::AddMap, &m_model, _1));
///}
m_scaleProcessor.SetParams(visualScale, ScalesProcessor::CalculateTileSize(surfaceWidth, surfaceHeight));
m_currentViewport.SetFromRect(m2::AnyRectD(m_scaleProcessor.GetWorldRect()));
m_commutator->RegisterThread(ThreadsCommutator::ResourceUploadThread, this);
int readerCount = max(1, GetPlatform().CpuCores() - 2);
int readerCount = 1;//max(1, GetPlatform().CpuCores() - 2);
m_threadPool.Reset(new threads::ThreadPool(readerCount, bind(&PostFinishTask, commutator, _1)));
m_batchersPool.Reset(new BatchersPool(readerCount, bind(&BackendRenderer::PostToRenderThreads, this, _1)));
@ -129,7 +138,7 @@ namespace df
void BackendRenderer::CreateTask(TileKey const & info)
{
ReadMWMTask * task = new ReadMWMTask(info, m_index, m_engineContext);
ReadMWMTask * task = new ReadMWMTask(info, m_model, m_index, m_engineContext);
m_taskIndex.insert(task);
m_threadPool->AddTask(task);
}
@ -144,7 +153,6 @@ namespace df
if (removefromIndex)
m_taskIndex.erase(task);
m_index.RemoveFeatures(task->GetTileInfo().m_featureInfo);
if (task->IsFinished())
delete task;
}

View file

@ -12,6 +12,7 @@
#include "../geometry/screenbase.hpp"
#include "../map/scales_processor.hpp"
#include "../map/feature_vec_model.hpp"
#include "../base/thread.hpp"
#include "../base/thread_pool.hpp"
@ -55,7 +56,8 @@ namespace df
/////////////////////////////////////////
/// Calculate rect for read from MWM
ScalesProcessor m_scaleProcessor;
model::FeaturesFetcher m_model;
void GetTileKeys(set<TileKey> & out,
ScreenBase const & screen);
/////////////////////////////////////////

View file

@ -1,17 +1,21 @@
#include "memory_feature_index.hpp"
#include "../base/logging.hpp"
namespace df
{
void MemoryFeatureIndex::ReadFeaturesRequest(const vector<FeatureInfo> & features, vector<size_t> & indexes)
void MemoryFeatureIndex::ReadFeaturesRequest(vector<FeatureInfo> & features, vector<size_t> & indexes)
{
threads::MutexGuard lock(m_mutex);
for (size_t i = 0; i < features.size(); ++i)
{
const FeatureInfo & info = features[i];
ASSERT(!(m_features.find(info.m_id) == m_features.end() && info.m_isOwner == true), ());
FeatureInfo & info = features[i];
if (info.m_isOwner == false && m_features.insert(info.m_id).second == true)
{
info.m_isOwner = true;
indexes.push_back(i);
}
}
}
@ -23,7 +27,8 @@ namespace df
{
const FeatureInfo & info = features[i];
if (info.m_isOwner == true)
VERIFY(m_features.erase(info.m_id) == 1, ());
//VERIFY(m_features.erase(info.m_id) == 1, ("Erase of ", info.m_id.m_mwm, " ", info.m_id.m_offset));
m_features.erase(info.m_id);
}
}
}

View file

@ -14,7 +14,7 @@ namespace df
class MemoryFeatureIndex : private noncopyable
{
public:
void ReadFeaturesRequest(const vector<FeatureInfo> & features, vector<size_t> & indexes);
void ReadFeaturesRequest(vector<FeatureInfo> & features, vector<size_t> & indexes);
void RemoveFeatures(const vector<FeatureInfo> & features);
private:

View file

@ -2,6 +2,8 @@
#include "area_shape.hpp"
#include "../base/logging.hpp"
#include "../std/vector.hpp"
namespace
@ -31,28 +33,63 @@ namespace
m2::PointF(1.5f, 0.5f));
return shape;
}
struct FeatureIndexFetcher
{
public:
FeatureIndexFetcher(df::TileInfo & info)
: m_info(info)
{
}
void Finish()
{
sort(m_info.m_featureInfo.begin(), m_info.m_featureInfo.end());
}
void operator()(FeatureID featureID) const
{
m_info.m_featureInfo.push_back(featureID);
}
private:
df::TileInfo & m_info;
};
}
namespace df
{
ReadMWMTask::ReadMWMTask(TileKey const & tileKey,
model::FeaturesFetcher const & model,
MemoryFeatureIndex & index,
EngineContext &context)
EngineContext & context)
: m_tileInfo(tileKey)
, m_isFinished(false)
, m_model(model)
, m_index(index)
, m_context(context)
, m_isFinished(false)
{
}
ReadMWMTask::~ReadMWMTask()
{
m_index.RemoveFeatures(m_tileInfo.m_featureInfo);
}
void ReadMWMTask::Do()
{
if (m_tileInfo.m_featureInfo.empty())
ReadTileIndex();
if (IsCancelled())
return;
vector<size_t> indexesToRead;
m_index.ReadFeaturesRequest(m_tileInfo.m_featureInfo, indexesToRead);
if (IsCancelled())
return;
if (!indexesToRead.empty())
{
m_context.BeginReadTile(m_tileInfo.m_key);
@ -61,7 +98,9 @@ namespace df
{
FeatureInfo & info = m_tileInfo.m_featureInfo[i];
ReadGeometry(info.m_id);
info.m_isOwner = true;
if (IsCancelled())
break;
}
m_context.EndReadTile(m_tileInfo.m_key);
@ -90,19 +129,18 @@ namespace df
void ReadMWMTask::ReadTileIndex()
{
if (m_tileInfo.m_key == TileKey(-2, -1, 3))
m_tileInfo.m_featureInfo.push_back(FeatureInfo(FeatureID(0, 1)));
else if (m_tileInfo.m_key == TileKey(0, 1, 3))
m_tileInfo.m_featureInfo.push_back(FeatureInfo(FeatureID(0, 2)));
/// TODO read index specified by m_tileInfo(m_x & m_y & m_zoomLevel)
/// TODO insert readed FeatureIDs into m_tileInfo.m_featureInfo;
FeatureIndexFetcher fetcher(m_tileInfo);
m_model.ForEachFeatureID(m_tileInfo.GetGlobalRect(),
fetcher,
m_tileInfo.m_key.m_zoomLevel);
fetcher.Finish();
}
void ReadMWMTask::ReadGeometry(const FeatureID & id)
{
if (id == FeatureID(0, 1))
if (id.m_mwm == 41)
m_context.InsertShape(m_tileInfo.m_key, MovePointer<MapShape>(CreateFakeShape1()));
else if (id == FeatureID(0, 2))
else if (id.m_mwm == 42)
m_context.InsertShape(m_tileInfo.m_key, MovePointer<MapShape>(CreateFakeShape2()));
///TODO read geometry
///TODO proccess geometry by styles

View file

@ -7,6 +7,8 @@
#include "../base/thread.hpp"
#include "../base/object_tracker.hpp"
#include "../map/feature_vec_model.hpp"
namespace df
{
class ReadMWMTask : public threads::IRoutine
@ -21,9 +23,12 @@ namespace df
};
ReadMWMTask(TileKey const & tileKey,
model::FeaturesFetcher const & model,
MemoryFeatureIndex & index,
EngineContext & context);
~ReadMWMTask();
virtual void Do();
df::TileInfo const & GetTileInfo() const;
@ -38,9 +43,10 @@ namespace df
private:
TileInfo m_tileInfo;
bool m_isFinished;
model::FeaturesFetcher const & m_model;
MemoryFeatureIndex & m_index;
EngineContext & m_context;
bool m_isFinished;
#ifdef DEBUG
dbg::ObjectTracker m_objTracker;

View file

@ -1,6 +1,7 @@
#pragma once
#include "../indexer/feature_decl.hpp"
#include "../indexer/mercator.hpp"
#include "../std/vector.hpp"
#include "../std/noncopyable.hpp"
@ -12,6 +13,14 @@ namespace df
FeatureInfo(const FeatureID & id)
: m_id(id), m_isOwner(false) {}
bool operator < (FeatureInfo const & other) const
{
if (!(m_id == other.m_id))
return m_id < other.m_id;
return m_isOwner < other.m_isOwner;
}
FeatureID m_id;
bool m_isOwner;
};
@ -53,12 +62,27 @@ namespace df
TileInfo(int x, int y, int zoomLevel)
: m_key(x, y, zoomLevel) {}
m2::RectD GetGlobalRect() const
{
double const worldSizeDevisor = 1 << m_key.m_zoomLevel;
double const rectSizeX = (MercatorBounds::maxX - MercatorBounds::minX) / worldSizeDevisor;
double const rectSizeY = (MercatorBounds::maxY - MercatorBounds::minY) / worldSizeDevisor;
m2::RectD tileRect(m_key.m_x * rectSizeX,
m_key.m_y * rectSizeY,
(m_key.m_x + 1) * rectSizeX,
(m_key.m_y + 1) * rectSizeY);
return tileRect;
}
bool operator < (const TileInfo & other) const
{
return m_key < other.m_key;
}
TileKey m_key;
vector<FeatureInfo> m_featureInfo;
};
}

View file

@ -1,6 +1,6 @@
# Head project for drape develop and debuging
ROOT_DIR = ..
DEPENDENCIES = drape_frontend map drape indexer platform geometry coding base
DEPENDENCIES = drape_frontend map drape indexer platform geometry coding base protobuf zlib
include($$ROOT_DIR/common.pri)

View file

@ -68,7 +68,7 @@ private:
{
FeaturesVector const & m_V;
F & m_F;
mutable unordered_set<uint32_t> m_offsets;
unordered_set<uint32_t> m_offsets;
MwmId m_mwmID;
public:
@ -77,7 +77,7 @@ private:
{
}
void operator() (uint32_t offset) const
void operator() (uint32_t offset)
{
if (m_offsets.insert(offset).second)
{
@ -133,6 +133,66 @@ private:
F & m_f;
};
template <typename F>
class ReadFeatureIndexFunctor
{
struct ImplFunctor
{
public:
ImplFunctor(F & f, MwmId id)
: m_f(f)
, m_id(id)
{
}
void operator() (uint32_t offset)
{
ASSERT(m_id != -1, ());
if (m_offsets.insert(offset).second)
m_f(FeatureID(m_id, offset));
}
private:
F & m_f;
MwmId m_id;
unordered_set<uint32_t> m_offsets;
};
public:
ReadFeatureIndexFunctor(F & f)
: m_f(f)
{
}
void operator() (MwmLock const & lock, covering::CoveringGetter & cov, uint32_t scale) const
{
MwmValue * pValue = lock.GetValue();
if (pValue)
{
feature::DataHeader const & header = pValue->GetHeader();
// Prepare needed covering.
int const lastScale = header.GetLastScale();
// In case of WorldCoasts we should pass correct scale in ForEachInIntervalAndScale.
if (scale > lastScale) scale = lastScale;
// Use last coding scale for covering (see index_builder.cpp).
covering::IntervalsT const & interval = cov.Get(lastScale);
ScaleIndex<ModelReaderPtr> index(pValue->m_cont.GetReader(INDEX_FILE_TAG),
pValue->m_factory);
// iterate through intervals
ImplFunctor implFunctor(m_f, lock.GetID());
for (size_t i = 0; i < interval.size(); ++i)
index.ForEachInIntervalAndScale(implFunctor, interval[i].first, interval[i].second, scale);
}
}
private:
F & m_f;
};
public:
template <typename F>
@ -152,8 +212,8 @@ public:
template <typename F>
void ForEachFeatureIDInRect(F & f, m2::RectD const & rect, uint32_t scale) const
{
///TODO
//ForEachInIntervals(ReadMWMFunctor(*this, f), rect, scale);
ReadFeatureIndexFunctor<F> implFunctor(f);
ForEachInIntervals(implFunctor, covering::LowLevelsOnly, rect, scale);
}
template <typename F>