Skip to content

Commit

Permalink
Merge pull request #10833 from rouault/deferred_warped_vrt_overview
Browse files Browse the repository at this point in the history
Warped VRT: instantiate overview bands in a lazy fashion for faster execution
  • Loading branch information
rouault authored Sep 27, 2024
2 parents caf4b54 + c558e98 commit 725739a
Show file tree
Hide file tree
Showing 3 changed files with 478 additions and 184 deletions.
15 changes: 15 additions & 0 deletions autotest/gdrivers/vrtwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def test_vrtwarp_4():
tmp_ds.BuildOverviews("NONE", overviewlist=[2, 4])
tmp_ds.GetRasterBand(1).GetOverview(0).Fill(127)
cs_ov0 = tmp_ds.GetRasterBand(1).GetOverview(0).Checksum()
data_ov0 = tmp_ds.GetRasterBand(1).GetOverview(0).ReadRaster()
data_ov0_subsampled = (
tmp_ds.GetRasterBand(1)
.GetOverview(0)
.ReadRaster(0, 0, 10, 10, 9, 9, resample_alg=gdal.GRIORA_Bilinear)
)
tmp_ds.GetRasterBand(1).GetOverview(1).Fill(255)
cs_ov1 = tmp_ds.GetRasterBand(1).GetOverview(1).Checksum()

Expand All @@ -109,6 +115,8 @@ def test_vrtwarp_4():
for i in range(3):
assert vrtwarp_ds.GetRasterBand(1).GetOverviewCount() == 2
assert vrtwarp_ds.GetRasterBand(1).Checksum() == cs_main, i
assert vrtwarp_ds.GetRasterBand(1).GetOverview(-1) is None
assert vrtwarp_ds.GetRasterBand(1).GetOverview(2) is None
assert vrtwarp_ds.GetRasterBand(1).GetOverview(0).Checksum() == cs_ov0
assert vrtwarp_ds.GetRasterBand(1).GetOverview(1).Checksum() == cs_ov1
if i == 0:
Expand Down Expand Up @@ -136,6 +144,13 @@ def test_vrtwarp_4():
assert vrtwarp_ds.GetRasterBand(1).GetOverviewCount() == 3
assert vrtwarp_ds.GetRasterBand(1).Checksum() == cs_main
assert vrtwarp_ds.GetRasterBand(1).GetOverview(0).Checksum() == cs_ov0
assert vrtwarp_ds.GetRasterBand(1).ReadRaster(0, 0, 20, 20, 10, 10) == data_ov0
assert (
vrtwarp_ds.GetRasterBand(1).ReadRaster(
0, 0, 20, 20, 9, 9, resample_alg=gdal.GRIORA_Bilinear
)
== data_ov0_subsampled
)
assert vrtwarp_ds.GetRasterBand(1).GetOverview(1).Checksum() == cs_ov1
assert vrtwarp_ds.GetRasterBand(1).GetOverview(2).Checksum() == expected_cs_ov2
vrtwarp_ds = None
Expand Down
14 changes: 12 additions & 2 deletions frmts/vrt/vrtdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,16 @@ class CPL_DLL VRTWarpedDataset final : public VRTDataset
{
GDALWarpOperation *m_poWarper;

int m_nOverviewCount;
VRTWarpedDataset **m_papoOverviews;
bool m_bIsOverview = false;
std::vector<VRTWarpedDataset *> m_apoOverviews{};
int m_nSrcOvrLevel;

bool GetOverviewSize(GDALDataset *poSrcDS, int iOvr, int iSrcOvr,
int &nOvrXSize, int &nOvrYSize, double &dfSrcRatioX,
double &dfSrcRatioY, double &dfTargetRatio) const;
int GetOverviewCount() const;
int GetSrcOverviewLevel(int iOvr, bool &bThisLevelOnlyOut) const;
VRTWarpedDataset *CreateImplicitOverview(int iOvr) const;
void CreateImplicitOverviews();

friend class VRTWarpedRasterBand;
Expand Down Expand Up @@ -1108,6 +1114,10 @@ class CPL_DLL VRTWarpedRasterBand final : public VRTRasterBand
private:
int m_nIRasterIOCounter =
0; //! Protects against infinite recursion inside IRasterIO()

int GetBestOverviewLevel(int &nXOff, int &nYOff, int &nXSize, int &nYSize,
int nBufXSize, int nBufYSize,
GDALRasterIOExtraArg *psExtraArg) const;
};

/************************************************************************/
Expand Down
Loading

0 comments on commit 725739a

Please sign in to comment.