Skip to content

Commit

Permalink
Segmentize curved geometries for rendering, but keep the original geo…
Browse files Browse the repository at this point in the history
…metry in the feature. Use the original geometry for drawing vertex markers
  • Loading branch information
mhugent committed Sep 1, 2015
1 parent d125e3f commit 5b97c03
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions src/core/symbology-ng/qgsrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "qgseffectstack.h"
#include "qgspainteffectregistry.h"
#include "qgswkbptr.h"
#include "qgspointv2.h"

#include <QDomElement>
#include <QDomDocument>
Expand Down Expand Up @@ -278,12 +279,16 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
QgsSymbolV2::SymbolType symbolType = symbol->type();


const QgsGeometry* geom = feature.constGeometry();
if ( !geom || !geom->geometry() )
{
return;
}

const QgsGeometry* segmentizedGeometry = geom;
bool deleteSegmentizedGeometry = false;

//convert curve types to normal point/line/polygon ones
switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
{
Expand All @@ -298,14 +303,14 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
return;
}
feature.setGeometry( new QgsGeometry( g ) );
geom = feature.constGeometry();
segmentizedGeometry = new QgsGeometry( g );
deleteSegmentizedGeometry = true;
}
default:
break;
}

switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
{
case QgsWKBTypes::Point:
{
Expand All @@ -315,11 +320,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}
QPointF pt;
_getPoint( pt, context, geom->asWkb() );
_getPoint( pt, context, segmentizedGeometry->asWkb() );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
break;
case QgsWKBTypes::LineString:
Expand All @@ -330,11 +332,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}
QPolygonF pts;
_getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
_getLineString( pts, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
break;
case QgsWKBTypes::Polygon:
Expand All @@ -346,11 +345,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
}
QPolygonF pts;
QList<QPolygonF> holes;
_getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
break;

Expand All @@ -362,7 +358,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
Expand All @@ -372,9 +368,6 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
}
break;
Expand All @@ -388,7 +381,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
Expand All @@ -398,9 +391,6 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
}
break;
Expand All @@ -414,7 +404,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
Expand All @@ -425,15 +415,39 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
break;
}
default:
QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
}

if ( drawVertexMarker )
{
const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();

QgsPointV2 vertexPoint;
QgsVertexId vertexId;
double z;
QPointF mapPoint;
while ( geom->geometry()->nextVertex( vertexId, vertexPoint ) )
{
//transform
mapPoint.setX( vertexPoint.x() ); mapPoint.setY( vertexPoint.y() ); z = vertexPoint.z();
mtp.transformInPlace( mapPoint.rx(), mapPoint.ry() );
if ( ct )
{
ct->transformInPlace( mapPoint.rx(), mapPoint.ry(), z );
}
renderVertexMarker( mapPoint, context );
}
}

if ( deleteSegmentizedGeometry )
{
delete segmentizedGeometry;
}
}

QString QgsFeatureRendererV2::dump() const
Expand Down

0 comments on commit 5b97c03

Please sign in to comment.