Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3434 from pvalsecc/lessWKB
Avoid back and forth with WKB in rendering
  • Loading branch information
nyalldawson committed Aug 29, 2016
2 parents 235204f + db91330 commit 9253228
Show file tree
Hide file tree
Showing 39 changed files with 452 additions and 892 deletions.
20 changes: 20 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions python/core/geometry/qgscircularstring.sip
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions python/core/geometry/qgscompoundcurve.sip
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions python/core/geometry/qgscurve.sip
Expand Up @@ -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;
Expand Down
21 changes: 3 additions & 18 deletions python/core/geometry/qgslinestring.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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/;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions python/core/qgsclipper.sip
Expand Up @@ -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 );

};
4 changes: 0 additions & 4 deletions python/core/qgsgeometrysimplifier.sip
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
};
19 changes: 2 additions & 17 deletions python/core/qgsmaptopixelgeometrysimplifier.sip
Expand Up @@ -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 );

};
14 changes: 1 addition & 13 deletions python/core/symbology-ng/qgsrenderer.sip
Expand Up @@ -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 );

Expand Down
14 changes: 7 additions & 7 deletions python/core/symbology-ng/qgssymbol.sip
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -848,7 +847,6 @@ SET(QGIS_CORE_HDRS
geometry/qgspolygon.h
geometry/qgssurface.h
geometry/qgswkbptr.h
geometry/qgswkbsimplifierptr.h
geometry/qgswkbtypes.h
)

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -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 )
Expand Down
16 changes: 16 additions & 0 deletions src/core/geometry/qgscircularstring.cpp
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgscircularstring.h
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/core/geometry/qgscompoundcurve.cpp
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgscompoundcurve.h
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/core/geometry/qgscurve.cpp
Expand Up @@ -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;
}

19 changes: 19 additions & 0 deletions src/core/geometry/qgscurve.h
Expand Up @@ -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(); }
Expand Down

0 comments on commit 9253228

Please sign in to comment.