Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #43478 from nirvn/gsl_split
Allow GSL-less qgis analysis library
  • Loading branch information
m-kuhn committed Jun 1, 2021
2 parents 570846a + bac8385 commit 1975368
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .ci/ogc/build.sh
Expand Up @@ -18,8 +18,8 @@ cmake -GNinja \
-DWITH_QWTPOLAR=OFF \
-DWITH_APIDOC=OFF \
-DWITH_ASTYLE=OFF \
-DWITH_GEOREFERENCER=OFF \
-DWITH_ANALYSIS=ON \
-DWITH_GSL=OFF \
-DWITH_DESKTOP=OFF \
-DWITH_GUI=OFF \
-DWITH_BINDINGS=ON \
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Expand Up @@ -279,8 +279,6 @@ if(WITH_CORE)
endif()
set (WITH_QTMOBILITY ${DEFAULT_WITH_QTMOBILITY} CACHE BOOL "Determines if QtMobility related code should be build (for example internal GPS)")

set (WITH_GEOREFERENCER TRUE CACHE BOOL "Determines whether GeoReferencer plugin should be built")

set (WITH_THREAD_LOCAL TRUE CACHE BOOL "Determines whether std::thread_local should be used")
mark_as_advanced(WITH_THREAD_LOCAL)

Expand Down Expand Up @@ -705,8 +703,11 @@ add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050800)
# For fast string concatenation
add_definitions(-DQT_USE_QSTRINGBUILDER)

if (WITH_GEOREFERENCER OR WITH_ANALYSIS)
set(WITH_GSL TRUE CACHE BOOL "Determines whether GSL library should be used")

if (WITH_ANALYSIS AND WITH_GSL)
find_package(GSL REQUIRED)
set(HAVE_GSL TRUE)
set(HAVE_GEOREFERENCER TRUE)
endif()

Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -76,6 +76,8 @@

#cmakedefine HAVE_3D

#cmakedefine HAVE_GSL

#cmakedefine HAVE_GEOREFERENCER

#cmakedefine USE_THREAD_LOCAL
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Expand Up @@ -258,6 +258,7 @@ if(WITH_ANALYSIS)

# analysis module
file(GLOB_RECURSE sip_files_analysis analysis/*.sip analysis/*.sip.in)

set(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_analysis})
set(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -g -o -a ${CMAKE_BINARY_DIR}/python/qgis.analysis.api)
if((${SIP_VERSION_STR} VERSION_EQUAL 4.19.11) OR (${SIP_VERSION_STR} VERSION_GREATER 4.19.11))
Expand Down
Expand Up @@ -53,7 +53,7 @@ parameters as this one.
Caller takes ownership of the returned object.
%End

virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) = 0;
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) throw( QgsNotSupportedException ) = 0;
%Docstring
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and destination coordinates.

Expand Down Expand Up @@ -94,7 +94,7 @@ Creates a new QgsGcpTransformerInterface subclass representing the specified tra
Caller takes ownership of the returned object.
%End

static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) /Factory/;
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) throw( QgsNotSupportedException ) /Factory/;
%Docstring
Creates a new QgsGcpTransformerInterface subclass representing the specified transform ``method``, initialized
using the given lists of source and destination coordinates.
Expand Down
10 changes: 8 additions & 2 deletions src/analysis/CMakeLists.txt
Expand Up @@ -401,10 +401,13 @@ find_package(EXIV2 REQUIRED)
include_directories(SYSTEM ${SPATIALITE_INCLUDE_DIR})
include_directories(SYSTEM ${SPATIALINDEX_INCLUDE_DIR})
include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR})
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
include_directories(BEFORE raster)
include_directories(BEFORE mesh)

if(HAVE_GSL)
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
endif()

ADD_FLEX_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalclexer.ll)
ADD_BISON_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalcparser.yy)

Expand Down Expand Up @@ -520,9 +523,12 @@ target_link_libraries(
qgis_analysis
qgis_core
${EXIV2_LIBRARY}
${GSL_LIBRARIES}
)

if(HAVE_GSL)
target_link_libraries(qgis_analysis ${GSL_LIBRARIES})
endif()

if(HAVE_OPENCL)
target_link_libraries(qgis_analysis ${OpenCL_LIBRARIES})
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/georeferencing/qgsgcptransformer.h
Expand Up @@ -76,7 +76,7 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
*
* \returns TRUE on success, FALSE on failure
*/
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) = 0;
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;

/**
* Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
Expand Down Expand Up @@ -117,7 +117,7 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
*
* Caller takes ownership of the returned object.
*/
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_FACTORY;
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;

#ifndef SIP_RUN

Expand Down
30 changes: 25 additions & 5 deletions src/analysis/georeferencing/qgsleastsquares.cpp
Expand Up @@ -12,16 +12,20 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <cmath>
#include <stdexcept>

#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>
#include "qgsleastsquares.h"
#include "qgsconfig.h"
#include "qgsexception.h"

#include <QObject>

#include "qgsleastsquares.h"
#include <cmath>
#include <stdexcept>

#ifdef HAVE_GSL
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>
#endif

void QgsLeastSquares::linear( const QVector<QgsPointXY> &sourceCoordinates,
const QVector<QgsPointXY> &destinationCoordinates,
Expand Down Expand Up @@ -67,6 +71,14 @@ void QgsLeastSquares::helmert( const QVector<QgsPointXY> &sourceCoordinates,
QgsPointXY &origin, double &pixelSize,
double &rotation )
{
#ifndef HAVE_GSL
( void )sourceCoordinates;
( void )destinationCoordinates;
( void )origin;
( void )pixelSize;
( void )rotation;
throw QgsNotSupportedException( QStringLiteral( "Calculating a helmert transformation requires a QGIS build based GSL" ) );
#else
int n = destinationCoordinates.size();
if ( n < 2 )
{
Expand Down Expand Up @@ -125,6 +137,7 @@ void QgsLeastSquares::helmert( const QVector<QgsPointXY> &sourceCoordinates,
pixelSize = std::sqrt( std::pow( gsl_vector_get( x, 0 ), 2 ) +
std::pow( gsl_vector_get( x, 1 ), 2 ) );
rotation = std::atan2( gsl_vector_get( x, 1 ), gsl_vector_get( x, 0 ) );
#endif
}

#if 0
Expand Down Expand Up @@ -245,6 +258,12 @@ void QgsLeastSquares::projective( const QVector<QgsPointXY> &sourceCoordinates,
const QVector<QgsPointXY> &destinationCoordinates,
double H[9] )
{
#ifndef HAVE_GSL
( void )sourceCoordinates;
( void )destinationCoordinates;
( void )H;
throw QgsNotSupportedException( QStringLiteral( "Calculating a projective transformation requires a QGIS build based GSL" ) );
#else
Q_ASSERT( sourceCoordinates.size() == destinationCoordinates.size() );

if ( destinationCoordinates.size() < 4 )
Expand Down Expand Up @@ -341,4 +360,5 @@ void QgsLeastSquares::projective( const QVector<QgsPointXY> &sourceCoordinates,
gsl_matrix_free( V );
gsl_vector_free( singular_values );
gsl_vector_free( work );
#endif
}
2 changes: 2 additions & 0 deletions src/analysis/georeferencing/qgsleastsquares.h
Expand Up @@ -42,6 +42,7 @@ class ANALYSIS_EXPORT QgsLeastSquares

/**
* Transforms the point at \a origin in-place, using a helmert transformation calculated from the list of source and destination Ground Control Points (GCPs).
* \throws QgsNotSupportedException on QGIS built without GSL.
*/
static void helmert( const QVector<QgsPointXY> &sourceCoordinates,
const QVector<QgsPointXY> &destinationCoordinates,
Expand All @@ -55,6 +56,7 @@ class ANALYSIS_EXPORT QgsLeastSquares

/**
* Calculates projective parameters from the list of source and destination Ground Control Points (GCPs).
* \throws QgsNotSupportedException on QGIS built without GSL.
*/
static void projective( const QVector<QgsPointXY> &sourceCoordinates,
const QVector<QgsPointXY> &destinationCoordinates,
Expand Down
4 changes: 2 additions & 2 deletions src/app/CMakeLists.txt
Expand Up @@ -252,7 +252,7 @@ if (WITH_SPATIALITE)
)
endif()

if (WITH_GEOREFERENCER)
if (HAVE_GEOREFERENCER)
set(QGIS_APP_SRCS
${QGIS_APP_SRCS}
georeferencer/qgsgcpcanvasitem.cpp
Expand Down Expand Up @@ -547,7 +547,7 @@ if (WITH_3D)
target_link_libraries(qgis_app qgis_3d)
endif()

if (WITH_GEOREFERENCER)
if (HAVE_GEOREFERENCER)
include_directories(SYSTEM
${GSL_INCLUDE_DIR}
)
Expand Down
8 changes: 7 additions & 1 deletion tests/src/analysis/CMakeLists.txt
Expand Up @@ -48,7 +48,6 @@ endmacro (ADD_QGIS_TEST)
#############################################################
# Tests:
set(TESTS
testqgsgcptransformer.cpp
testqgsgeometrysnapper.cpp
testqgsinterpolator.cpp
testqgsprocessing.cpp
Expand All @@ -64,6 +63,13 @@ set(TESTS
testqgstriangulation.cpp
)

if(HAVE_GSL)
set(TESTS
${TESTS}
testqgsgcptransformer.cpp
)
endif()

foreach(TESTSRC ${TESTS})
ADD_QGIS_TEST(${TESTSRC})
endforeach(TESTSRC)
Expand Down

0 comments on commit 1975368

Please sign in to comment.