Skip to content

Commit c30202f

Browse files
committed
Feature #8725: Simplification is assigned by flag
The drawing simplification can be configured using flags that indicates what simplification type can be executed (Point, BBOX and AA)
1 parent b2d9ebb commit c30202f

9 files changed

+62
-37
lines changed

src/app/qgsvectorlayerproperties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
393393
cbMaximumScale->setScale( 1.0 / layer->maximumScale() );
394394

395395
// get simplify drawing configuration
396-
mSimplifyDrawingGroupBox->setChecked( layer->simplifyDrawing() );
396+
mSimplifyDrawingGroupBox->setChecked( layer->simplifyDrawingHints() != QgsVectorLayer::NoSimplification );
397397
mSimplifyDrawingSlider->setValue( (int)(5.0f * (layer->simplifyDrawingTol()-1)) );
398398

399399
// load appropriate symbology page (V1 or V2)
@@ -534,7 +534,7 @@ void QgsVectorLayerProperties::apply()
534534
layer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );
535535

536536
//layer simplify drawing configuration
537-
layer->setSimplifyDrawing( mSimplifyDrawingGroupBox->isChecked() );
537+
layer->setSimplifyDrawingHints( mSimplifyDrawingGroupBox->isChecked() ? QgsVectorLayer::FullSimplification : QgsVectorLayer::NoSimplification );
538538
layer->setSimplifyDrawingTol( 1.0f + 0.2f*mSimplifyDrawingSlider->value() );
539539

540540
// update symbology

src/core/qgsfeaturerequest.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,19 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
379379
}
380380

381381
//! Simplify the WKB-geometry using the specified tolerance
382-
inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* sourceWkb, size_t sourceWkbSize, unsigned char* targetWkb, size_t& targetWkbSize, const QgsRectangle& envelope, float map2pixelTol, bool writeHeader = true, bool isaLinearRing = false )
382+
inline static bool simplifyWkbGeometry( const QgsFeatureRequest::Flags& requestFlags, QGis::WkbType wkbType, unsigned char* sourceWkb, size_t sourceWkbSize, unsigned char* targetWkb, size_t& targetWkbSize, const QgsRectangle& envelope, float map2pixelTol, bool writeHeader = true, bool isaLinearRing = false )
383383
{
384384
bool canbeGeneralizable = true;
385385
bool hasZValue = QGis::wkbDimensions(wkbType)==3;
386386
bool result = false;
387387

388388
// Can replace the geometry by its BBOX ?
389-
if ( (envelope.xMaximum()-envelope.xMinimum()) < map2pixelTol && (envelope.yMaximum()-envelope.yMinimum()) < map2pixelTol )
389+
if ( ( requestFlags & QgsFeatureRequest::SimplifyEnvelope ) && (envelope.xMaximum()-envelope.xMinimum()) < map2pixelTol && (envelope.yMaximum()-envelope.yMinimum()) < map2pixelTol )
390390
{
391391
canbeGeneralizable = generalizeGeometry( wkbType, sourceWkb, sourceWkbSize, targetWkb, targetWkbSize, envelope, writeHeader );
392392
if (canbeGeneralizable) return true;
393393
}
394+
if (!( requestFlags & QgsFeatureRequest::SimplifyGeometry ) ) canbeGeneralizable = false;
394395

395396
// Write the main header of the geometry
396397
if ( writeHeader )
@@ -484,7 +485,7 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
484485
size_t sourceWkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2) * sizeof(double);
485486
size_t targetWkbSize_i = 0;
486487

487-
result |= simplifyWkbGeometry( wkbType, sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope_i, map2pixelTol, false, true );
488+
result |= simplifyWkbGeometry( requestFlags, wkbType, sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope_i, map2pixelTol, false, true );
488489
sourceWkb += sourceWkbSize_i;
489490
targetWkb += targetWkbSize_i;
490491

@@ -535,7 +536,7 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
535536
wkb1 += wkbSize_i;
536537
}
537538
}
538-
result |= simplifyWkbGeometry( QGis::singleType(wkbType), sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope, map2pixelTol, true, false );
539+
result |= simplifyWkbGeometry( requestFlags, QGis::singleType(wkbType), sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope, map2pixelTol, true, false );
539540
sourceWkb += sourceWkbSize_i;
540541
targetWkb += targetWkbSize_i;
541542

@@ -573,7 +574,7 @@ bool QgsFeatureRequest::canbeGeneralizedByMapBoundingBox( const QgsRectangle& en
573574
}
574575

575576
//! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
576-
bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
577+
bool QgsFeatureRequest::simplifyGeometry( const QgsFeatureRequest::Flags& requestFlags, QgsGeometry* geometry, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
577578
{
578579
size_t targetWkbSize = 0;
579580

@@ -589,7 +590,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
589590
size_t wkbSize = geometry->wkbSize( );
590591

591592
// Simplify the geometry rewriting temporally its WKB-stream for saving calloc's.
592-
if ( simplifyWkbGeometry( wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, map2pixelTol ) )
593+
if ( simplifyWkbGeometry( requestFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, map2pixelTol ) )
593594
{
594595
unsigned char* targetWkb = (unsigned char*)malloc( targetWkbSize );
595596
memcpy( targetWkb, wkb, targetWkbSize );
@@ -600,8 +601,10 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
600601
}
601602

602603
//! Simplify the specified point stream (Removing duplicated points) when is applied the map2pixel context
603-
bool QgsFeatureRequest::simplifyGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
604+
bool QgsFeatureRequest::simplifyGeometry( const QgsFeatureRequest::Flags& requestFlags, QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
604605
{
606+
bool canbeGeneralizable = ( requestFlags & QgsFeatureRequest::SimplifyGeometry );
607+
605608
pointSimplifiedCount = pointCount;
606609
if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false;
607610
pointSimplifiedCount = 0;
@@ -620,7 +623,7 @@ bool QgsFeatureRequest::simplifyGeometry( QGis::GeometryType geometryType, const
620623
memcpy( &x, xsourcePtr, sizeof( double ) ); xsourcePtr += xStride;
621624
memcpy( &y, ysourcePtr, sizeof( double ) ); ysourcePtr += yStride;
622625

623-
if ( i==0 || calculateLengthSquared2D(x,y,lastX,lastY)>map2pixelTol )
626+
if ( i==0 || !canbeGeneralizable || calculateLengthSquared2D(x,y,lastX,lastY)>map2pixelTol )
624627
{
625628
memcpy( xtargetPtr, &x, sizeof( double ) ); lastX = x; xtargetPtr += xStride;
626629
memcpy( ytargetPtr, &y, sizeof( double ) ); lastY = y; ytargetPtr += yStride;

src/core/qgsfeaturerequest.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class CORE_EXPORT QgsFeatureRequest
6565
NoGeometry = 1, //!< Geometry is not required. It may still be returned if e.g. required for a filter condition.
6666
SubsetOfAttributes = 2, //!< Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
6767
ExactIntersect = 4, //!< Use exact geometry intersection (slower) instead of bounding boxes
68-
SimplifyGeometries = 8 //!< Simplify the geometry using the current map2pixel context (e.g. for fast rendering...)
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...)
6970
};
7071
Q_DECLARE_FLAGS( Flags, Flag )
7172

@@ -182,18 +183,21 @@ class CORE_EXPORT QgsFeatureRequest
182183
inline bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope ) const { return canbeGeneralizedByMapBoundingBox( envelope, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
183184

184185
//! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
185-
static bool simplifyGeometry( QgsGeometry* geometry,
186+
static bool simplifyGeometry( const QgsFeatureRequest::Flags& requestFlags,
187+
QgsGeometry* geometry,
186188
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol = 1.0f );
187189

188190
//! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
189-
inline bool simplifyGeometry( QgsGeometry* geometry ) const { return simplifyGeometry( geometry, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
191+
inline bool simplifyGeometry( QgsGeometry* geometry ) const { return simplifyGeometry( mFlags, geometry, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
190192

191193
//! Simplify the specified point stream (Removing duplicated points) when is applied a map2pixel context
192-
static bool simplifyGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount,
194+
static bool simplifyGeometry( const QgsFeatureRequest::Flags& requestFlags,
195+
QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount,
193196
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol = 1.0f );
194197

195198
//! Simplify the specified point stream (Removing duplicated points) when is applied the map2pixel context
196-
inline bool simplifyGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount ) const { return simplifyGeometry( geometryType, envelope, xptr, xStride, yptr, yStride, pointCount, pointSimplifiedCount, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
199+
inline bool simplifyGeometry( const QgsFeatureRequest::Flags& requestFlags,
200+
QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount ) const { return simplifyGeometry( requestFlags, geometryType, envelope, xptr, xStride, yptr, yStride, pointCount, pointSimplifiedCount, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
197201
};
198202

199203
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )

src/core/qgsvectorlayer.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
136136
, mSymbolFeatureCounted( false )
137137
, mCurrentRendererContext( 0 )
138138
, mSimplifyDrawingTol( QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT )
139-
, mSimplifyDrawing( true )
139+
, mSimplifyDrawingHints( QgsVectorLayer::FullSimplification )
140140

141141
{
142142
mActions = new QgsAttributeAction( this );
@@ -693,13 +693,17 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
693693
.setFilterRect( rendererContext.extent() )
694694
.setSubsetOfAttributes( attributes );
695695

696-
// Enable the simplification of the geometries before fetch the features using the current map2pixel context.
697-
if ( simplifyDrawingCanbeApplied() && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) && !rendererContext.renderingPrintComposition() )
696+
// Enable the simplification of the geometries (Using the current map2pixel context) before fetch the features.
697+
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification | QgsVectorLayer::EnvelopeSimplification ) && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) && !rendererContext.renderingPrintComposition() )
698698
{
699+
QgsFeatureRequest::Flags simplificationHints = QgsFeatureRequest::NoFlags;
700+
if ( mSimplifyDrawingHints & QgsVectorLayer::GeometrySimplification ) simplificationHints |= QgsFeatureRequest::SimplifyGeometry;
701+
if ( mSimplifyDrawingHints & QgsVectorLayer::EnvelopeSimplification ) simplificationHints |= QgsFeatureRequest::SimplifyEnvelope;
702+
699703
QPainter* p = rendererContext.painter();
700704
float dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
701705

702-
featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::SimplifyGeometries );
706+
featureRequest.setFlags( featureRequest.flags() | simplificationHints );
703707
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
704708
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
705709
featureRequest.setMapToPixelTol( mSimplifyDrawingTol * 96.0f/dpi );
@@ -1221,13 +1225,17 @@ bool QgsVectorLayer::setSubsetString( QString subset )
12211225
return res;
12221226
}
12231227

1228+
bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
1229+
{
1230+
return ( mSimplifyDrawingHints & simplifyHint ) && !mEditBuffer && ( !mCurrentRendererContext || !mCurrentRendererContext->renderingPrintComposition() );
1231+
}
12241232

12251233
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
12261234
{
12271235
if ( !mDataProvider )
12281236
return QgsFeatureIterator();
12291237

1230-
if ( mSimplifyDrawing && (request.flags() & QgsFeatureRequest::SimplifyGeometries) && !(request.flags() & QgsFeatureRequest::NoGeometry) )
1238+
if ( request.flags() & ( QgsFeatureRequest::SimplifyGeometry | QgsFeatureRequest::SimplifyEnvelope ) && !( request.flags() & QgsFeatureRequest::NoGeometry ) )
12311239
return QgsFeatureIterator( new QgsSimplifiedVectorLayerFeatureIterator( this, request ) );
12321240

12331241
return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( this, request ) );
@@ -1834,7 +1842,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
18341842
mLabel->setMaxScale( e.attribute( "maxLabelScale", "100000000" ).toFloat() );
18351843

18361844
// get the simplification drawing configuration
1837-
setSimplifyDrawing( e.attribute( "simplifyDrawingFlag", "1" ) == "1" );
1845+
setSimplifyDrawingHints( e.attribute( "simplifyDrawingHints", "7" ).toInt() );
18381846
setSimplifyDrawingTol( e.attribute( "simplifyDrawingTol", "1" ).toFloat() );
18391847

18401848
//also restore custom properties (for labeling-ng)
@@ -2171,7 +2179,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
21712179
mapLayerNode.setAttribute( "maxLabelScale", QString::number( mLabel->maxScale() ) );
21722180

21732181
// save the simplification drawing configuration
2174-
mapLayerNode.setAttribute( "simplifyDrawingFlag", mSimplifyDrawing ? 1 : 0 );
2182+
mapLayerNode.setAttribute( "simplifyDrawingHints", QString::number( mSimplifyDrawingHints ) );
21752183
mapLayerNode.setAttribute( "simplifyDrawingTol", QString::number( mSimplifyDrawingTol ) );
21762184

21772185
//save customproperties (for labeling ng)

src/core/qgsvectorlayer.h

+18-9
Original file line numberDiff line numberDiff line change
@@ -1369,13 +1369,22 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
13691369
/** Returns the Map2pixel simplification threshold for fast rendering of features */
13701370
float simplifyDrawingTol() const { return mSimplifyDrawingTol; }
13711371

1372-
/** Enable the Map2pixel simplification for fast rendering of features */
1373-
void setSimplifyDrawing( bool simplifyDrawing ) { mSimplifyDrawing = simplifyDrawing; }
1374-
/** Returns whether is enabled the map2pixel simplification of geometries for fast rendering of features */
1375-
bool simplifyDrawing() const { return mSimplifyDrawing; }
1372+
/** Simplification flags for fast rendering of features */
1373+
enum SimplifyHint
1374+
{
1375+
NoSimplification = 0, //!< No simplification can be applied
1376+
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
1377+
EnvelopeSimplification = 2, //!< The geometries can be fully simplified by its BoundingBox using the current map2pixel context state
1378+
AntialiasingSimplification = 4, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
1379+
FullSimplification = 7, //!< All simplification hints can be applied
1380+
};
1381+
/** Set the Map2pixel simplification hints for fast rendering of features */
1382+
void setSimplifyDrawingHints( int simplifyDrawingHints ) { mSimplifyDrawingHints = simplifyDrawingHints; }
1383+
/** Returns the Map2pixel simplification hints for fast rendering of features */
1384+
int simplifyDrawingHints() const { return mSimplifyDrawingHints; }
13761385

1377-
/** Returns whether the VectorLayer can apply geometry simplification in FeatureRequests */
1378-
bool simplifyDrawingCanbeApplied() const { return mSimplifyDrawing && !mEditBuffer && ( !mCurrentRendererContext || !mCurrentRendererContext->renderingPrintComposition() ); }
1386+
/** Returns whether the VectorLayer can apply the specified simplification hint */
1387+
bool simplifyDrawingCanbeApplied( int simplifyHint ) const;
13791388

13801389
public slots:
13811390
/**
@@ -1646,10 +1655,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
16461655
/** Renderer object which holds the information about how to display the features */
16471656
QgsFeatureRendererV2 *mRendererV2;
16481657

1649-
/** Map2pixel simplification threshold for fast rendering of features */
1658+
/** Map2pixel geometry simplification threshold for fast rendering of features */
16501659
float mSimplifyDrawingTol;
1651-
/** Enable map2pixel simplification of geometries for fast rendering of features */
1652-
bool mSimplifyDrawing;
1660+
/** Map2pixel geometry simplification hints for fast rendering of features */
1661+
int mSimplifyDrawingHints;
16531662

16541663
/** Label */
16551664
QgsLabel *mLabel;

src/core/symbology-ng/qgslinesymbollayerv2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
181181
p->setPen( context.selected() ? mSelPen : mPen );
182182

183183
// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
184-
if ( points.size()<=2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied() && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
184+
if ( points.size()<=2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
185185
{
186186
p->setRenderHint( QPainter::Antialiasing, false );
187187
p->drawPolyline( points );

src/core/symbology-ng/qgssymbollayerv2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points,
358358
}
359359

360360
// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
361-
if ( points.size()<=5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied() && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
361+
if ( points.size()<=5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
362362
{
363363
p->setRenderHint( QPainter::Antialiasing, false );
364364
p->drawConvexPolygon( points );

0 commit comments

Comments
 (0)