Skip to content

Commit 08b5e30

Browse files
ahuarte47m-kuhn
authored andcommitted
#8725-R: simplifier execute in rendering loop
1 parent 319acc2 commit 08b5e30

18 files changed

+47
-545
lines changed

src/core/qgsfeaturerequest.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ QgsFeatureRequest::QgsFeatureRequest()
2323
: mFilter( FilterNone )
2424
, mFilterExpression( 0 )
2525
, mFlags( 0 )
26-
, mMapCoordTransform( NULL )
27-
, mMapToPixel( NULL )
28-
, mMapToPixelTol( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
2926
{
3027
}
3128

@@ -34,9 +31,6 @@ QgsFeatureRequest::QgsFeatureRequest( QgsFeatureId fid )
3431
, mFilterFid( fid )
3532
, mFilterExpression( 0 )
3633
, mFlags( 0 )
37-
, mMapCoordTransform( NULL )
38-
, mMapToPixel( NULL )
39-
, mMapToPixelTol( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
4034
{
4135
}
4236

@@ -45,19 +39,13 @@ QgsFeatureRequest::QgsFeatureRequest( const QgsRectangle& rect )
4539
, mFilterRect( rect )
4640
, mFilterExpression( 0 )
4741
, mFlags( 0 )
48-
, mMapCoordTransform( NULL )
49-
, mMapToPixel( NULL )
50-
, mMapToPixelTol( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
5142
{
5243
}
5344

5445
QgsFeatureRequest::QgsFeatureRequest( const QgsExpression& expr )
5546
: mFilter( FilterExpression )
5647
, mFilterExpression( new QgsExpression( expr.expression() ) )
5748
, mFlags( 0 )
58-
, mMapCoordTransform( NULL )
59-
, mMapToPixel( NULL )
60-
, mMapToPixelTol( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
6149
{
6250
}
6351

@@ -82,9 +70,6 @@ QgsFeatureRequest& QgsFeatureRequest::operator=( const QgsFeatureRequest & rh )
8270
mFilterExpression = 0;
8371
}
8472
mAttrs = rh.mAttrs;
85-
mMapCoordTransform = rh.mMapCoordTransform;
86-
mMapToPixel = rh.mMapToPixel;
87-
mMapToPixelTol = rh.mMapToPixelTol;
8873
return *this;
8974
}
9075

@@ -189,21 +174,3 @@ bool QgsFeatureRequest::acceptFeature( const QgsFeature& feature )
189174

190175
return true;
191176
}
192-
193-
QgsFeatureRequest& QgsFeatureRequest::setCoordinateTransform( const QgsCoordinateTransform* ct )
194-
{
195-
mMapCoordTransform = ct;
196-
return *this;
197-
}
198-
199-
QgsFeatureRequest& QgsFeatureRequest::setMapToPixel( const QgsMapToPixel* mtp )
200-
{
201-
mMapToPixel = mtp;
202-
return *this;
203-
}
204-
205-
QgsFeatureRequest& QgsFeatureRequest::setMapToPixelTol( float map2pixelTol )
206-
{
207-
mMapToPixelTol = map2pixelTol;
208-
return *this;
209-
}

src/core/qgsfeaturerequest.h

+1-22
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
#include "qgsrectangle.h"
2222
#include "qgsexpression.h"
2323

24-
#include "qgscoordinatetransform.h"
25-
#include "qgsmaptopixel.h"
26-
2724
#include <QList>
2825
typedef QList<int> QgsAttributeList;
2926

@@ -64,9 +61,7 @@ class CORE_EXPORT QgsFeatureRequest
6461
NoFlags = 0,
6562
NoGeometry = 1, //!< Geometry is not required. It may still be returned if e.g. required for a filter condition.
6663
SubsetOfAttributes = 2, //!< Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
67-
ExactIntersect = 4, //!< Use exact geometry intersection (slower) instead of bounding boxes
68-
SimplifyGeometry = 8, //!< The geometries can be simplified using the current map2pixel context state (e.g. for fast rendering...)
69-
SimplifyEnvelope = 16 //!< The geometries can be fully simplified by its BoundingBox (e.g. for fast rendering...)
64+
ExactIntersect = 4 //!< Use exact geometry intersection (slower) instead of bounding boxes
7065
};
7166
Q_DECLARE_FLAGS( Flags, Flag )
7267

@@ -140,15 +135,6 @@ class CORE_EXPORT QgsFeatureRequest
140135
// void setFilterNativeExpression(con QString& expr); // using provider's SQL (if supported)
141136
// void setLimit(int limit);
142137

143-
const QgsCoordinateTransform* coordinateTransform() const { return mMapCoordTransform; }
144-
QgsFeatureRequest& setCoordinateTransform( const QgsCoordinateTransform* ct );
145-
146-
const QgsMapToPixel* mapToPixel() const { return mMapToPixel; }
147-
QgsFeatureRequest& setMapToPixel( const QgsMapToPixel* mtp );
148-
149-
float mapToPixelTol() const { return mMapToPixelTol; }
150-
QgsFeatureRequest& setMapToPixelTol( float map2pixelTol );
151-
152138
protected:
153139
FilterType mFilter;
154140
QgsRectangle mFilterRect;
@@ -157,13 +143,6 @@ class CORE_EXPORT QgsFeatureRequest
157143
QgsExpression* mFilterExpression;
158144
Flags mFlags;
159145
QgsAttributeList mAttrs;
160-
161-
//! For transformation between coordinate systems from current layer to map target. Can be 0 if on-the-fly reprojection is not used
162-
const QgsCoordinateTransform* mMapCoordTransform;
163-
//! For transformation between map coordinates and device coordinates
164-
const QgsMapToPixel* mMapToPixel;
165-
//! Factor tolterance to apply in transformation between map coordinates and device coordinates
166-
float mMapToPixelTol;
167146
};
168147

169148
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )

src/core/qgsgeometrysimplifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ QgsTopologyPreservingSimplifier::~QgsTopologyPreservingSimplifier()
6060
}
6161

6262
//! Returns a simplified version the specified geometry
63-
QgsGeometry* QgsTopologyPreservingSimplifier::simplify( QgsGeometry* geometry )
63+
QgsGeometry* QgsTopologyPreservingSimplifier::simplify( QgsGeometry* geometry ) const
6464
{
6565
return geometry->simplify( mTolerance );
6666
}
6767

6868
//! Simplifies the specified geometry
69-
bool QgsTopologyPreservingSimplifier::simplifyGeometry( QgsGeometry* geometry )
69+
bool QgsTopologyPreservingSimplifier::simplifyGeometry( QgsGeometry* geometry ) const
7070
{
7171
QgsGeometry* g = geometry->simplify( mTolerance );
7272

src/core/qgsgeometrysimplifier.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class CORE_EXPORT QgsAbstractGeometrySimplifier
2828
virtual ~QgsAbstractGeometrySimplifier();
2929

3030
//! Returns a simplified version the specified geometry
31-
virtual QgsGeometry* simplify( QgsGeometry* geometry ) = 0;
31+
virtual QgsGeometry* simplify( QgsGeometry* geometry ) const = 0;
3232
//! Simplifies the specified geometry
33-
virtual bool simplifyGeometry( QgsGeometry* geometry ) = 0;
33+
virtual bool simplifyGeometry( QgsGeometry* geometry ) const = 0;
3434

3535
// MapToPixel simplification helper methods
3636
public:
@@ -59,9 +59,9 @@ class CORE_EXPORT QgsTopologyPreservingSimplifier : public QgsAbstractGeometrySi
5959

6060
public:
6161
//! Returns a simplified version the specified geometry
62-
virtual QgsGeometry* simplify( QgsGeometry* geometry );
62+
virtual QgsGeometry* simplify( QgsGeometry* geometry ) const;
6363
//! Simplifies the specified geometry
64-
virtual bool simplifyGeometry( QgsGeometry* geometry );
64+
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;
6565
};
6666

6767
#endif // QGSGEOMETRYSIMPLIFIER_H

src/core/qgsmaptopixelgeometrysimplifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ bool QgsMapToPixelSimplifier::canbeGeneralizedByMapBoundingBox( const QgsRectang
352352
}
353353

354354
//! Returns a simplified version the specified geometry (Removing duplicated points) when is applied the specified map2pixel context
355-
QgsGeometry* QgsMapToPixelSimplifier::simplify( QgsGeometry* geometry )
355+
QgsGeometry* QgsMapToPixelSimplifier::simplify( QgsGeometry* geometry ) const
356356
{
357357
QgsGeometry* g = new QgsGeometry();
358358

@@ -393,7 +393,7 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
393393
}
394394

395395
//! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context
396-
bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry )
396+
bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry ) const
397397
{
398398
return simplifyGeometry( geometry, mSimplifyFlags, mMapCoordTransform, mMapToPixel, mMapToPixelTol );
399399
}

src/core/qgsmaptopixelgeometrysimplifier.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
7777
void setMapToPixelTol( float map2pixelTol ) { mMapToPixelTol = map2pixelTol; }
7878

7979
//! Returns a simplified version the specified geometry
80-
virtual QgsGeometry* simplify( QgsGeometry* geometry );
80+
virtual QgsGeometry* simplify( QgsGeometry* geometry ) const;
8181
//! Simplifies the specified geometry
82-
virtual bool simplifyGeometry( QgsGeometry* geometry );
82+
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;
8383

8484
// MapToPixel simplification helper methods
8585
public:

src/core/qgsvectordataprovider.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ QString QgsVectorDataProvider::capabilitiesString() const
194194
QgsDebugMsg( "Capability: Change Geometries" );
195195
}
196196

197-
if ( abilities & QgsVectorDataProvider::SimplifyGeometries )
198-
{
199-
abilitiesList += tr( "Simplify Geometries" );
200-
QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature" );
201-
}
202-
203197
return abilitiesList.join( ", " );
204198

205199
}

src/core/qgsvectordataprovider.h

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
8686
CreateAttributeIndex = 1 << 12,
8787
/** allows user to select encoding */
8888
SelectEncoding = 1 << 13,
89-
/** supports simplification of geometries before fetch the feature */
90-
SimplifyGeometries = 1 << 14,
9189
};
9290

9391
/** bitmask of all provider's editing capabilities */

src/core/qgsvectorlayer.cpp

+32-26
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
400400

401401

402402

403-
void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling )
403+
void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling, const QgsAbstractGeometrySimplifier* geometrySimplifier )
404404
{
405405
if ( !hasGeometryType() )
406406
return;
@@ -451,6 +451,13 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
451451
bool sel = mSelectedFeatureIds.contains( fet.id() );
452452
bool drawMarker = ( mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
453453

454+
// simplify the geometry using the current map2pixel context
455+
if ( geometrySimplifier )
456+
{
457+
fet = QgsFeature( fet );
458+
geometrySimplifier->simplifyGeometry( fet.geometry() );
459+
}
460+
454461
// render feature
455462
bool rendered = mRendererV2->renderFeature( fet, rendererContext, -1, sel, drawMarker );
456463

@@ -493,7 +500,7 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
493500
#endif
494501
}
495502

496-
void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling )
503+
void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling, const QgsAbstractGeometrySimplifier* geometrySimplifier )
497504
{
498505
if ( !hasGeometryType() )
499506
return;
@@ -539,6 +546,13 @@ void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderCon
539546
continue;
540547
}
541548

549+
// simplify the geometry using the current map2pixel context
550+
if ( geometrySimplifier )
551+
{
552+
fet = QgsFeature( fet );
553+
geometrySimplifier->simplifyGeometry( fet.geometry() );
554+
}
555+
542556
if ( !features.contains( sym ) )
543557
{
544558
features.insert( sym, QList<QgsFeature>() );
@@ -698,14 +712,14 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
698712
//do startRender before getFeatures to give renderers the possibility of querying features in the startRender method
699713
mRendererV2->startRender( rendererContext, this );
700714

701-
QgsFeatureRequest& featureRequest = QgsFeatureRequest()
702-
.setFilterRect( rendererContext.extent() )
703-
.setSubsetOfAttributes( attributes );
715+
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
716+
.setFilterRect( rendererContext.extent() )
717+
.setSubsetOfAttributes( attributes ) );
704718

705-
QgsFeatureIterator fit = QgsFeatureIterator();
719+
QgsAbstractGeometrySimplifier* geometrySimplifier = NULL;
706720

707-
// Enable the simplification of the geometries (Using the current map2pixel context) before fetch the features.
708-
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification | QgsVectorLayer::EnvelopeSimplification ) && !( featureRequest.flags() & QgsFeatureRequest::NoGeometry ) )
721+
// enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
722+
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification | QgsVectorLayer::EnvelopeSimplification ) )
709723
{
710724
QPainter* p = rendererContext.painter();
711725
float dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
@@ -715,29 +729,21 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
715729
if ( mSimplifyDrawingHints & QgsVectorLayer::GeometrySimplification ) simplifyFlags |= QgsMapToPixelSimplifier::SimplifyGeometry;
716730
if ( mSimplifyDrawingHints & QgsVectorLayer::EnvelopeSimplification ) simplifyFlags |= QgsMapToPixelSimplifier::SimplifyEnvelope;
717731

718-
QgsFeatureRequest::Flags requestFlags = QgsFeatureRequest::NoFlags;
719-
if ( mSimplifyDrawingHints & QgsVectorLayer::GeometrySimplification ) requestFlags |= QgsFeatureRequest::SimplifyGeometry;
720-
if ( mSimplifyDrawingHints & QgsVectorLayer::EnvelopeSimplification ) requestFlags |= QgsFeatureRequest::SimplifyEnvelope;
721-
722-
featureRequest.setFlags( featureRequest.flags() | requestFlags );
723-
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
724-
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
725-
featureRequest.setMapToPixelTol( map2pixelTol );
726-
727-
QgsMapToPixelSimplifier* simplifier =
732+
geometrySimplifier =
728733
new QgsMapToPixelSimplifier( simplifyFlags, rendererContext.coordinateTransform(), &rendererContext.mapToPixel(), map2pixelTol );
729-
730-
fit = QgsFeatureIterator( new QgsSimplifiedVectorLayerFeatureIterator( this, featureRequest, simplifier ) );
731-
}
732-
else
733-
{
734-
fit = getFeatures( featureRequest );
735734
}
736735

737736
if (( mRendererV2->capabilities() & QgsFeatureRendererV2::SymbolLevels ) && mRendererV2->usingSymbolLevels() )
738-
drawRendererV2Levels( fit, rendererContext, labeling );
737+
drawRendererV2Levels( fit, rendererContext, labeling, geometrySimplifier );
739738
else
740-
drawRendererV2( fit, rendererContext, labeling );
739+
drawRendererV2( fit, rendererContext, labeling, geometrySimplifier );
740+
741+
// release the optional geometry simplifier
742+
if ( geometrySimplifier )
743+
{
744+
delete geometrySimplifier;
745+
geometrySimplifier = NULL;
746+
}
741747

742748
return true;
743749
}

src/core/qgsvectorlayer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class QgsDiagramLayerSettings;
5757
class QgsGeometryCache;
5858
class QgsVectorLayerEditBuffer;
5959
class QgsSymbolV2;
60+
class QgsAbstractGeometrySimplifier;
6061

6162
typedef QList<int> QgsAttributeList;
6263
typedef QSet<int> QgsAttributeIds;
@@ -729,12 +730,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
729730
/** Draw layer with renderer V2. QgsFeatureRenderer::startRender() needs to be called before using this method
730731
* @note added in 1.4
731732
*/
732-
void drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling );
733+
void drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling, const QgsAbstractGeometrySimplifier* geometrySimplifier = NULL );
733734

734735
/** Draw layer with renderer V2 using symbol levels. QgsFeatureRenderer::startRender() needs to be called before using this method
735736
* @note added in 1.4
736737
*/
737-
void drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling );
738+
void drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling, const QgsAbstractGeometrySimplifier* geometrySimplifier = NULL );
738739

739740
/** Returns point, line or polygon */
740741
QGis::GeometryType geometryType() const;

src/core/qgsvectorlayerfeatureiterator.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -589,47 +589,3 @@ void QgsVectorLayerFeatureIterator::updateFeatureGeometry( QgsFeature &f )
589589
if ( mChangedGeometries.contains( f.id() ) )
590590
f.setGeometry( mChangedGeometries[f.id()] );
591591
}
592-
593-
/***************************************************************************
594-
QgsSimplifiedVectorLayerFeatureIterator class
595-
----------------------
596-
begin : December 2013
597-
copyright : (C) 2013 by Alvaro Huarte
598-
email : http://wiki.osgeo.org/wiki/Alvaro_Huarte
599-
600-
***************************************************************************
601-
* *
602-
* This program is free software; you can redistribute it and/or modify *
603-
* it under the terms of the GNU General Public License as published by *
604-
* the Free Software Foundation; either version 2 of the License, or *
605-
* (at your option) any later version. *
606-
* *
607-
***************************************************************************/
608-
609-
QgsSimplifiedVectorLayerFeatureIterator::QgsSimplifiedVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request, QgsAbstractGeometrySimplifier* simplifier )
610-
: QgsVectorLayerFeatureIterator( layer, request )
611-
, mSimplifier( simplifier )
612-
{
613-
mSupportsPresimplify = layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries;
614-
}
615-
616-
QgsSimplifiedVectorLayerFeatureIterator::~QgsSimplifiedVectorLayerFeatureIterator()
617-
{
618-
if ( mSimplifier )
619-
{
620-
delete mSimplifier;
621-
mSimplifier = NULL;
622-
}
623-
}
624-
625-
//! fetch next feature, return true on success
626-
bool QgsSimplifiedVectorLayerFeatureIterator::fetchFeature( QgsFeature& feature )
627-
{
628-
if ( QgsVectorLayerFeatureIterator::fetchFeature( feature ) )
629-
{
630-
const QgsMapToPixel* mtp = mRequest.mapToPixel();
631-
if ( mtp && !mSupportsPresimplify && mSimplifier ) mSimplifier->simplifyGeometry( feature.geometry() );
632-
return true;
633-
}
634-
return false;
635-
}

0 commit comments

Comments
 (0)