Skip to content
Permalink
Browse files
Allow GSL-less qgis analysis library
  • Loading branch information
nirvn committed Jun 1, 2021
1 parent 3491f40 commit 0008158ab08eb808dc094d3ac271c611de272568
@@ -705,9 +705,14 @@ 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_GEOREFERENCER TRUE)
set(HAVE_GSL TRUE)
if (WITH_GEOREFERENCER)
set(HAVE_GEOREFERENCER TRUE)
endif()
endif()

if(ENABLE_COVERAGE)
@@ -76,6 +76,8 @@

#cmakedefine HAVE_3D

#cmakedefine HAVE_GSL

#cmakedefine HAVE_GEOREFERENCER

#cmakedefine USE_THREAD_LOCAL
@@ -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))
@@ -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)

@@ -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()
@@ -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,
@@ -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 )
{
@@ -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
@@ -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 )
@@ -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
}
@@ -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,
@@ -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,
@@ -48,7 +48,6 @@ endmacro (ADD_QGIS_TEST)
#############################################################
# Tests:
set(TESTS
testqgsgcptransformer.cpp
testqgsgeometrysnapper.cpp
testqgsinterpolator.cpp
testqgsprocessing.cpp
@@ -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)

0 comments on commit 0008158

Please sign in to comment.