forked from organicmaps/organicmaps-tmp
Rearrange strip's points for better serialization size.
This commit is contained in:
parent
d6d8d502a0
commit
9d5595ca7e
4 changed files with 73 additions and 18 deletions
|
@ -364,6 +364,37 @@ namespace
|
|||
m_pos += count;
|
||||
}
|
||||
};
|
||||
|
||||
/// @name Rearrange strips for optimal save size.
|
||||
/// Save in this order: 0, 2, 4, ..., 15, 13, ..., 1
|
||||
//@{
|
||||
void RearrangeStripsSave(vector<m2::PointD> const & src, vector<m2::PointD> & dest)
|
||||
{
|
||||
size_t const count = src.size();
|
||||
dest.resize(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
if (i & 1)
|
||||
dest[count-1 - (i/2)] = src[i];
|
||||
else
|
||||
dest[i/2] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
void RearrangeStripsLoad( buffer_vector<m2::PointD, 32> const & src,
|
||||
buffer_vector<m2::PointD, 32> & dest)
|
||||
{
|
||||
size_t const count = src.size();
|
||||
dest.resize(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
if (i & 1)
|
||||
dest[i] = src[count-1 - (i/2)];
|
||||
else
|
||||
dest[i] = src[i/2];
|
||||
}
|
||||
}
|
||||
//@}
|
||||
}
|
||||
|
||||
void FeatureBuilder2::Serialize(buffers_holder_t & data, int64_t base)
|
||||
|
@ -429,7 +460,11 @@ void FeatureBuilder2::Serialize(buffers_holder_t & data, int64_t base)
|
|||
if (m_bArea)
|
||||
{
|
||||
if (trgCount > 0)
|
||||
feature::SavePointsSimple(data.m_innerTrg, base, sink);
|
||||
{
|
||||
vector<m2::PointD> toSave;
|
||||
RearrangeStripsSave(data.m_innerTrg, toSave);
|
||||
feature::SavePointsSimple(toSave, base, sink);
|
||||
}
|
||||
else
|
||||
{
|
||||
// offsets was pushed from high scale index to low
|
||||
|
@ -578,7 +613,7 @@ void FeatureType::Deserialize(read_source_t & src)
|
|||
m_bHeader2Parsed = m_bPointsParsed = m_bTrianglesParsed = false;
|
||||
m_ptsSimpMask = 0;
|
||||
|
||||
m_Size = 0;
|
||||
m_InnerStats.MakeZero();
|
||||
|
||||
base_type::Deserialize(src.m_data, src.m_offset, src.m_base);
|
||||
}
|
||||
|
@ -770,9 +805,13 @@ void FeatureType::ParseHeader2() const
|
|||
m_ptsSimpMask += (mask << (i << 3));
|
||||
}
|
||||
|
||||
char const * start = static_cast<char const *>(src.Ptr());
|
||||
|
||||
m_InnerPoints.reserve(ptsCount);
|
||||
src = ArrayByteSource(ReadVarInt64Array(
|
||||
src.Ptr(), ptsCount, MakeBackInsertFunctor(m_InnerPoints)));
|
||||
|
||||
m_InnerStats.m_Points = static_cast<char const *>(src.Ptr()) - start;
|
||||
}
|
||||
else
|
||||
ReadOffsets(src, ptsMask, m_ptsOffsets);
|
||||
|
@ -784,8 +823,13 @@ void FeatureType::ParseHeader2() const
|
|||
{
|
||||
trgCount += 2;
|
||||
|
||||
points_t points;
|
||||
ReadInnerPoints(src, points, trgCount);
|
||||
char const * start = static_cast<char const *>(src.Ptr());
|
||||
|
||||
points_t toLoad, points;
|
||||
ReadInnerPoints(src, toLoad, trgCount);
|
||||
RearrangeStripsLoad(toLoad, points);
|
||||
|
||||
m_InnerStats.m_Strips = static_cast<char const *>(src.Ptr()) - start;
|
||||
|
||||
for (uint8_t i = 2; i < trgCount; ++i)
|
||||
{
|
||||
|
@ -799,7 +843,7 @@ void FeatureType::ParseHeader2() const
|
|||
}
|
||||
|
||||
m_bHeader2Parsed = true;
|
||||
m_Size = static_cast<char const *>(src.Ptr()) - DataPtr();
|
||||
m_InnerStats.m_Size = static_cast<char const *>(src.Ptr()) - DataPtr();
|
||||
}
|
||||
|
||||
uint32_t FeatureType::ParseGeometry(int scale) const
|
||||
|
|
|
@ -417,7 +417,17 @@ public:
|
|||
ParseHeader2();
|
||||
}
|
||||
|
||||
uint32_t GetAllSize() const { return m_Size; }
|
||||
struct inner_geom_stat_t
|
||||
{
|
||||
uint32_t m_Points, m_Strips, m_Size;
|
||||
|
||||
void MakeZero()
|
||||
{
|
||||
m_Points = m_Strips = m_Size = 0;
|
||||
}
|
||||
};
|
||||
|
||||
inner_geom_stat_t GetInnerStatistic() const { return m_InnerStats; }
|
||||
|
||||
struct geom_stat_t
|
||||
{
|
||||
|
@ -455,7 +465,7 @@ private:
|
|||
|
||||
mutable bool m_bHeader2Parsed, m_bPointsParsed, m_bTrianglesParsed;
|
||||
|
||||
mutable uint32_t m_Size;
|
||||
mutable inner_geom_stat_t m_InnerStats;
|
||||
|
||||
mutable uint32_t m_ptsSimpMask;
|
||||
|
||||
|
|
|
@ -56,18 +56,19 @@ namespace stats
|
|||
{
|
||||
f.ParseBeforeStatistic();
|
||||
|
||||
uint32_t const datSize = f.GetAllSize();
|
||||
m_info.m_all.Add(datSize);
|
||||
//m_info.m_names.Add(f.GetNameSize());
|
||||
//m_info.m_types.Add(f.GetTypesSize());
|
||||
FeatureType::inner_geom_stat_t const innerStats = f.GetInnerStatistic();
|
||||
|
||||
FeatureType::geom_stat_t geom = f.GetGeometrySize(-1);
|
||||
FeatureType::geom_stat_t trg = f.GetTrianglesSize(-1);
|
||||
m_info.m_inner[0].Add(innerStats.m_Points);
|
||||
m_info.m_inner[1].Add(innerStats.m_Strips);
|
||||
m_info.m_inner[2].Add(innerStats.m_Size);
|
||||
|
||||
FeatureType::geom_stat_t const geom = f.GetGeometrySize(-1);
|
||||
FeatureType::geom_stat_t const trg = f.GetTrianglesSize(-1);
|
||||
|
||||
m_info.AddToSet(geom.m_count, geom.m_size, m_info.m_byPointsCount);
|
||||
m_info.AddToSet(trg.m_count / 3, trg.m_size, m_info.m_byTrgCount);
|
||||
|
||||
uint32_t const allSize = datSize + geom.m_size + trg.m_size;
|
||||
uint32_t const allSize = innerStats.m_Size + geom.m_size + trg.m_size;
|
||||
|
||||
m_info.AddToSet(f.GetFeatureType(), allSize, m_info.m_byGeomType);
|
||||
|
||||
|
@ -144,9 +145,9 @@ namespace stats
|
|||
|
||||
void PrintStatistic(MapInfo & info)
|
||||
{
|
||||
PrintInfo("DAT", info.m_all);
|
||||
//PrintInfo("NAMES", info.m_names);
|
||||
//PrintInfo("TYPES", info.m_types);
|
||||
PrintInfo("DAT header", info.m_inner[2]);
|
||||
PrintInfo("Points header", info.m_inner[0]);
|
||||
PrintInfo("Strips header", info.m_inner[1]);
|
||||
|
||||
PrintTop<greater_size>("Top SIZE by Geometry Type", info.m_byGeomType);
|
||||
PrintTop<greater_size>("Top SIZE by Classificator Type", info.m_byClassifType);
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace stats
|
|||
set<GeneralInfoKey<TypeTag> > m_byClassifType;
|
||||
set<GeneralInfoKey<uint32_t> > m_byPointsCount, m_byTrgCount;
|
||||
|
||||
GeneralInfo m_all; //, m_names, m_types;
|
||||
GeneralInfo m_inner[3];
|
||||
|
||||
template <class TKey, class TSet>
|
||||
void AddToSet(TKey key, uint32_t sz, TSet & theSet)
|
||||
|
|
Loading…
Add table
Reference in a new issue