std::vector<std::pair<cord,T> > quadtree<T>::searchRange( node<T> *nd, cord start,cord end ) { std::vector<std::pair<cord, T> > results; std::vector<std::pair<cord, T> > quad; if(nd == nullptr) return results; if(nd->first != nullptr) { cord q1start(nd->first->x.first,nd->first->y.first); cord q1end(nd->first->x.second,nd->first->y.second); cord q2start(nd->second->x.first,nd->second->y.first); cord q2end(nd->second->x.second,nd->second->y.second); cord q3start(nd->third->x.first,nd->third->y.first); cord q3end(nd->third->x.second,nd->third->y.second); cord q4start(nd->fourth->x.first,nd->fourth->y.first); cord q4end(nd->fourth->x.second,nd->fourth->y.second); if(overlapRect(q1start,q1end,start,end)) { quad = searchRange(nd->first,start,end); results.insert(results.end(),quad.begin(),quad.end()); } if(overlapRect(q2start,q2end,start,end)) { quad = searchRange(nd->second,start,end); results.insert(results.end(),quad.begin(),quad.end()); } if(overlapRect(q3start,q3end,start,end)) { quad = searchRange(nd->third,start,end); results.insert(results.end(),quad.begin(),quad.end()); } if(overlapRect(q4start,q4end,start,end)) { quad = searchRange(nd->fourth,start,end); results.insert(results.end(),quad.begin(),quad.end()); } } else { for(auto i:nd->objects) { if(i.first.first < end.first && i.first.first > start.first && i.first.second > end.second && i.first.second < start.second) results.push_back(i); } } return results; }
//! Copies the passed tile in the tile complex. The passed tile \b must //! possess integer geometry (ie tile.m_pos must have integer coordinates), //! otherwise this function is a no-op. bool TCacheResource::upload(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return false; if (m_tileType == NONE) m_tileType = tileType; //For all cells of the lattice which intersect the tile, upload the content in the //complex TRect tileRect(ras->getBounds() + pos); TPoint initialPos(getCellPos(tileRect.getP00())); //DIAGNOSTICS_NUMBEREDSTRSET(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "upload", ::traduce(TRect(pos, ras->getSize()))); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { //Copy tile's content into the cell's raster. TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); PointLess cellIndex(getCellIndex(currPos)); std::pair<TRasterP, CellData *> cellInfos(touch(cellIndex)); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); assert(overlappingCellRas->getBounds() == overlappingTileRas->getBounds()); TRop::copy(overlappingCellRas, overlappingTileRas); cellInfos.second->m_modified = true; } //Update the complex's content region m_region += toQRect(tileRect); return true; }
bool TCacheResource::downloadAll(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return false; //Build the tile's rect TRect tileRect(ras->getBounds() + pos); if (!contains(m_region, tileRect)) return false; //DIAGNOSTICS_NUMBEREDSTRSET(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "downloadAll", ::traduce(TRect(pos, ras->getSize()))); //For all cells intersecting the tile's rect, copy all those intersecting the //complex's content region. TPoint initialPos(getCellPos(tileRect.getP00())); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); QRect overlapQRect(toQRect(overlapRect)); if (m_region.intersects(overlapQRect)) { //Extract the associated rasters and perform the copy to the input tile. std::pair<TRasterP, CellData *> cellInfos(touch(getCellIndex(currPos))); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); TRop::copy(overlappingTileRas, overlappingCellRas); } } return true; }
//! Fills the passed tile with the data contained in the complex, returning //! the copied region. //! The same restriction of the upload() method applies here. QRegion TCacheResource::download(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return QRegion(); //Build the tile's rect TRect tileRect(ras->getBounds() + pos); if (!m_region.intersects(toQRect(tileRect))) return QRegion(); //For all cells intersecting the tile's rect, copy all those intersecting the //complex's content region. TPoint initialPos(getCellPos(tileRect.getP00())); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); QRect overlapQRect(toQRect(overlapRect)); if (m_region.intersects(overlapQRect)) { //Extract the associated rasters and perform the copy to the input tile. std::pair<TRasterP, CellData *> cellInfos(touch(getCellIndex(currPos))); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); TRop::copy(overlappingTileRas, overlappingCellRas); } } return m_region.intersected(QRegion(toQRect(tileRect))); }