Skip to content
Permalink
Browse files

Avoid back and forth with WKB in rendering

  • Loading branch information
Patrick Valsecchi
Patrick Valsecchi committed Aug 29, 2016
1 parent 235204f commit db91330b663f5c21c21fae9bfd226182324ae71c
Showing with 452 additions and 892 deletions.
  1. +20 −0 doc/api_break.dox
  2. +3 −0 python/core/geometry/qgscircularstring.sip
  3. +3 −0 python/core/geometry/qgscompoundcurve.sip
  4. +18 −0 python/core/geometry/qgscurve.sip
  5. +3 −18 python/core/geometry/qgslinestring.sip
  6. +7 −5 python/core/qgsclipper.sip
  7. +0 −4 python/core/qgsgeometrysimplifier.sip
  8. +2 −17 python/core/qgsmaptopixelgeometrysimplifier.sip
  9. +1 −13 python/core/symbology-ng/qgsrenderer.sip
  10. +7 −7 python/core/symbology-ng/qgssymbol.sip
  11. +0 −2 src/core/CMakeLists.txt
  12. +1 −1 src/core/geometry/qgsabstractgeometry.h
  13. +16 −0 src/core/geometry/qgscircularstring.cpp
  14. +3 −0 src/core/geometry/qgscircularstring.h
  15. +30 −0 src/core/geometry/qgscompoundcurve.cpp
  16. +3 −0 src/core/geometry/qgscompoundcurve.h
  17. +12 −0 src/core/geometry/qgscurve.cpp
  18. +19 −0 src/core/geometry/qgscurve.h
  19. +3 −3 src/core/geometry/qgsgeometry.h
  20. +0 −10 src/core/geometry/qgslinestring.cpp
  21. +2 −17 src/core/geometry/qgslinestring.h
  22. +0 −49 src/core/geometry/qgswkbsimplifierptr.cpp
  23. +0 −62 src/core/geometry/qgswkbsimplifierptr.h
  24. +10 −28 src/core/qgsclipper.cpp
  25. +7 −6 src/core/qgsclipper.h
  26. +0 −12 src/core/qgsgeometrysimplifier.cpp
  27. +0 −4 src/core/qgsgeometrysimplifier.h
  28. +86 −328 src/core/qgsmaptopixelgeometrysimplifier.cpp
  29. +5 −12 src/core/qgsmaptopixelgeometrysimplifier.h
  30. +4 −11 src/core/qgspallabeling.cpp
  31. +32 −34 src/core/simplify/effectivearea.c
  32. +3 −17 src/core/simplify/effectivearea.h
  33. +1 −3 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  34. +2 −14 src/core/symbology-ng/qgsrenderer.cpp
  35. +1 −13 src/core/symbology-ng/qgsrenderer.h
  36. +78 −149 src/core/symbology-ng/qgssymbol.cpp
  37. +14 −13 src/core/symbology-ng/qgssymbol.h
  38. +34 −21 tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp
  39. +22 −19 tests/src/python/test_qgssymbol.py
@@ -295,6 +295,12 @@ variant instead.</li>
<li>GenericDataSourceURI has been renamed to GenericDataSourceUri</li>
</ul>

\subsection qgis_api_break_3_0_QgsClipper QgsClipper

<ul>
<li>clippedLineWKB has been renamed to clippedLine and it's signature has been changed to return a QPolygonF</li>
</ul>

\subsection qgis_api_break_3_0_QgsColorBrewerColorRampDialog QgsColorBrewerColorRampDialog

<ul>
@@ -575,6 +581,12 @@ method to determine if a geometry is valid.</li>
a QgsGeometry value rather than a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGeometrySimplifier QgsGeometrySimplifier

<ul>
<li>simplifyGeometry() has been removed and simplify() must be used instead .</li>
</ul>

\subsection qgis_api_break_3_0_QgsGradientColorRampDialog QgsGradientColorRampDialog

<ul>
@@ -699,6 +711,14 @@ be used instead of a null pointer if no transformation is required.</li>
<li>drawOldLabeling(), drawNewLabeling() were removed. The method drawLabeling() should be used instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsMapToPixelGeometrySimplifier QgsMapToPixelGeometrySimplifier

The whole class has been refactored to stop using WKB and to use QgsAbstractGeometry classes.
<ul>
<li>simplifyGeometry(), simplifyPoints(), isGeneralizableByMapBoundingBox(), _getLineString(), _getPolygon() methods have been removed.</li>
<li>The signature of the static methods _getPoint(), _getLineString() and _getPolygon() have been changed.</li>
</ul>

\subsection qgis_api_break_3_0_QgsMapSettings QgsMapSettings

<ul>
@@ -104,6 +104,9 @@ class QgsCircularString: public QgsCurve
virtual bool dropZValue();
virtual bool dropMValue();

virtual double xAt( int index ) const;
virtual double yAt( int index ) const;

protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -95,6 +95,9 @@ class QgsCompoundCurve: public QgsCurve
virtual bool dropZValue();
virtual bool dropMValue();

virtual double xAt( int index ) const;
virtual double yAt( int index ) const;

protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -103,6 +103,24 @@ class QgsCurve: public QgsAbstractGeometry
*/
virtual bool dropMValue() = 0;

/** Returns the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns x-coordinate of node, or 0.0 if index is out of bounds
* @see setXAt()
*/
virtual double xAt( int index ) const = 0;

/** Returns the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns y-coordinate of node, or 0.0 if index is out of bounds
* @see setYAt()
*/
virtual double yAt( int index ) const = 0;

/** Returns a QPolygonF representing the line string.
*/
QPolygonF asQPolygonF() const;

protected:

virtual void clearCache() const;
@@ -21,20 +21,6 @@ class QgsLineString: public QgsCurve
*/
QgsPointV2 pointN( int i ) const;

/** Returns the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns x-coordinate of node, or 0.0 if index is out of bounds
* @see setXAt()
*/
double xAt( int index ) const;

/** Returns the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns y-coordinate of node, or 0.0 if index is out of bounds
* @see setYAt()
*/
double yAt( int index ) const;

/** Returns the z-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns z-coordinate of node, or 0.0 if index is out of bounds or the line
@@ -102,10 +88,6 @@ class QgsLineString: public QgsCurve
/** Closes the line string by appending the first point to the end of the line, if it is not already closed.*/
void close();

/** Returns a QPolygonF representing the line string.
*/
QPolygonF asQPolygonF() const;

/** Returns the geometry converted to the more generic curve type QgsCompoundCurve
@return the converted geometry. Caller takes ownership*/
QgsAbstractGeometry* toCurveType() const /Factory/;
@@ -170,6 +152,9 @@ class QgsLineString: public QgsCurve

virtual bool convertTo( QgsWkbTypes::Type type );

virtual double xAt( int index ) const;
virtual double yAt( int index ) const;

protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -52,9 +52,11 @@ class QgsClipper

static void trimPolygon( QPolygonF& pts, const QgsRectangle& clipRect );

/** Reads a polyline from WKB and clips it to clipExtent
@param wkb pointer to the start of the line wkb
@param clipExtent clipping bounds
@param line out: clipped line coordinates*/
static QgsConstWkbPtr clippedLineWKB( QgsConstWkbPtr& wkb, const QgsRectangle& clipExtent, QPolygonF& line );
/** Takes a linestring and clips it to clipExtent
* @param curve the linestring
* @param clipExtent clipping bounds
* @return clipped line coordinates
*/
static QPolygonF clippedLine( const QgsCurve& curve, const QgsRectangle& clipExtent );

};
@@ -13,8 +13,6 @@ class QgsAbstractGeometrySimplifier

//! Returns a simplified version the specified geometry
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const = 0;
//! Simplifies the specified geometry
virtual bool simplifyGeometry( QgsGeometry* geometry ) const = 0;

// MapToPixel simplification helper methods
public:
@@ -42,6 +40,4 @@ class QgsTopologyPreservingSimplifier : QgsAbstractGeometrySimplifier

//! Returns a simplified version the specified geometry
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const;
//! Simplifies the specified geometry
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;
};
@@ -43,27 +43,12 @@ class QgsMapToPixelSimplifier : QgsAbstractGeometrySimplifier
//! Sets the local simplification algorithm of the vector layer managed
void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm );

//! Returns a simplified version the specified geometry
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const;
//! Simplifies the specified geometry
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;

//! Simplifies the specified WKB-point array
virtual bool simplifyPoints( QgsWkbTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints ) const;
//! Sets the tolerance of the vector layer managed
void setTolerance( double value );

// MapToPixel simplification helper methods
public:

//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
static bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol );

//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope ) const;

//! Simplifies the geometry when is applied the specified map2pixel context
static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );

//! Simplifies the WKB-point array when is applied the specified map2pixel context
static bool simplifyPoints( QgsWkbTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );

};
@@ -429,19 +429,7 @@ class QgsFeatureRenderer
* Creates a point in screen coordinates from a wkb string in map
* coordinates
*/
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );

/**
* Creates a line string in screen coordinates from a wkb string in map
* coordinates
*/
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );

/**
* Creates a polygon in screen coordinates from a wkb string in map
* coordinates
*/
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
static QPointF _getPoint( QgsRenderContext& context, const QgsPointV2& point );

void setScaleMethodToSymbol( QgsSymbol* symbol, int scaleMethod );

@@ -237,25 +237,25 @@ class QgsSymbol
/**
* Creates a point in screen coordinates from a QgsPointV2 in map coordinates
*/
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPointV2* point );
static QPointF _getPoint( QgsRenderContext& context, const QgsPointV2& point );

/**
* Creates a point in screen coordinates from a wkb string in map
* Creates a line string in screen coordinates from a QgsCurve in map
* coordinates
*/
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
static QPolygonF _getLineString( QgsRenderContext& context, const QgsCurve& curve, bool clipToExtent = true );

/**
* Creates a line string in screen coordinates from a wkb string in map
* Creates a polygon ring in screen coordinates from a QgsCurve in map
* coordinates
*/
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
static QPolygonF _getPolygonRing( QgsRenderContext& context, const QgsCurve& curve, bool clipToExtent );

/**
* Creates a polygon in screen coordinates from a wkb string in map
* Creates a polygon in screen coordinates from a QgsPolygonV2 in map
* coordinates
*/
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
static void _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const QgsPolygonV2& polygon, bool clipToExtent = true );

/**
* Retrieve a cloned list of all layers that make up this symbol.
@@ -350,7 +350,6 @@ SET(QGIS_CORE_SRCS
geometry/qgspolygon.cpp
geometry/qgswkbptr.cpp
geometry/qgswkbtypes.cpp
geometry/qgswkbsimplifierptr.cpp

${CMAKE_CURRENT_BINARY_DIR}/qgscontexthelp_texts.cpp
${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp
@@ -848,7 +847,6 @@ SET(QGIS_CORE_HDRS
geometry/qgspolygon.h
geometry/qgssurface.h
geometry/qgswkbptr.h
geometry/qgswkbsimplifierptr.h
geometry/qgswkbtypes.h
)

@@ -409,7 +409,7 @@ struct CORE_EXPORT QgsVertexId
CurveVertex
};

QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
: part( _part )
, ring( _ring )
, vertex( _vertex )
@@ -408,6 +408,22 @@ QgsPointV2 QgsCircularString::pointN( int i ) const
return QgsPointV2( t, x, y, z, m );
}

double QgsCircularString::xAt( int index ) const
{
if ( index >= 0 && index < mX.size() )
return mX.at( index );
else
return 0.0;
}

double QgsCircularString::yAt( int index ) const
{
if ( index >= 0 && index < mY.size() )
return mY.at( index );
else
return 0.0;
}

void QgsCircularString::points( QgsPointSequence &pts ) const
{
pts.clear();
@@ -129,6 +129,9 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
virtual bool dropZValue() override;
virtual bool dropMValue() override;

double xAt( int index ) const override;
double yAt( int index ) const override;

protected:

virtual QgsRectangle calculateBoundingBox() const override;
@@ -679,6 +679,36 @@ bool QgsCompoundCurve::pointAt( int node, QgsPointV2& point, QgsVertexId::Vertex
return false;
}

double QgsCompoundCurve::xAt( int index ) const
{
int currentVertexId = 0;
for ( int j = 0; j < mCurves.size(); ++j )
{
int nCurvePoints = mCurves.at( j )->numPoints();
if (( index - currentVertexId ) < nCurvePoints )
{
return mCurves.at( j )->xAt( index - currentVertexId );
}
currentVertexId += ( nCurvePoints - 1 );
}
return 0.0;
}

double QgsCompoundCurve::yAt( int index ) const
{
int currentVertexId = 0;
for ( int j = 0; j < mCurves.size(); ++j )
{
int nCurvePoints = mCurves.at( j )->numPoints();
if (( index - currentVertexId ) < nCurvePoints )
{
return mCurves.at( j )->yAt( index - currentVertexId );
}
currentVertexId += ( nCurvePoints - 1 );
}
return 0.0;
}

void QgsCompoundCurve::sumUpArea( double& sum ) const
{
QList< QgsCurve* >::const_iterator curveIt = mCurves.constBegin();
@@ -119,6 +119,9 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
virtual bool dropZValue() override;
virtual bool dropMValue() override;

double xAt( int index ) const override;
double yAt( int index ) const override;

protected:

virtual QgsRectangle calculateBoundingBox() const override;
@@ -117,3 +117,15 @@ QgsRectangle QgsCurve::boundingBox() const
return mBoundingBox;
}

QPolygonF QgsCurve::asQPolygonF() const
{
const int nb = numPoints();
QPolygonF points;
points.reserve( nb );
for ( int i = 0; i < nb; ++i )
{
points << QPointF( xAt( i ), yAt( i ) );
}
return points;
}

@@ -116,6 +116,25 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry

virtual QgsRectangle boundingBox() const override;

/** Returns the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns x-coordinate of node, or 0.0 if index is out of bounds
* @see setXAt()
*/
virtual double xAt( int index ) const = 0;

/** Returns the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns y-coordinate of node, or 0.0 if index is out of bounds
* @see setYAt()
*/
virtual double yAt( int index ) const = 0;

/** Returns a QPolygonF representing the points.
*/
QPolygonF asQPolygonF() const;


protected:

virtual void clearCache() const override { mBoundingBox = QgsRectangle(); mCoordinateSequence.clear(); QgsAbstractGeometry::clearCache(); }

0 comments on commit db91330

Please sign in to comment.
You can’t perform that action at this time.