mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Add QGIS 3d provider
Adds a new QGIS processing provider for 3d algorithms, available only when QGIS is built WITH_3D Currently includes only a single algorithm for tesselating geometries, which exposes the functionality of QgsTesselator to processing. Like the native c++ algorithm provider, algorithms in the 3d provider are transparently merged with the other QGIS providers (i.e. they aren't separated into their own group)
This commit is contained in:
parent
8c211f2869
commit
c0e732b799
@ -370,14 +370,14 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
|
||||
# first add qgis/native providers, since they create top level groups
|
||||
for provider in QgsApplication.processingRegistry().providers():
|
||||
if provider.id() in ('qgis', 'native'):
|
||||
if provider.id() in ('qgis', 'native', '3d'):
|
||||
self.addAlgorithmsFromProvider(provider, self.algorithmTree.invisibleRootItem())
|
||||
else:
|
||||
continue
|
||||
self.algorithmTree.sortItems(0, Qt.AscendingOrder)
|
||||
|
||||
for provider in QgsApplication.processingRegistry().providers():
|
||||
if provider.id() in ('qgis', 'native'):
|
||||
if provider.id() in ('qgis', 'native', '3d'):
|
||||
# already added
|
||||
continue
|
||||
else:
|
||||
@ -422,7 +422,7 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
groupItem = TreeGroupItem(alg.group())
|
||||
if not active:
|
||||
groupItem.setInactive()
|
||||
if provider.id() in ('qgis', 'native'):
|
||||
if provider.id() in ('qgis', 'native', '3d'):
|
||||
groupItem.setIcon(0, provider.icon())
|
||||
groups[alg.group()] = groupItem
|
||||
algItem = TreeAlgorithmItem(alg)
|
||||
@ -444,7 +444,7 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
|
||||
text = provider.name()
|
||||
|
||||
if not provider.id() in ('qgis', 'native'):
|
||||
if not provider.id() in ('qgis', 'native', '3d'):
|
||||
if not active:
|
||||
def activateProvider():
|
||||
self.activateProvider(provider.id())
|
||||
@ -459,7 +459,7 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
for group, groupItem in sorted(groups.items(), key=operator.itemgetter(1)):
|
||||
parent.addChild(groupItem)
|
||||
|
||||
if not provider.id() in ('qgis', 'native'):
|
||||
if not provider.id() in ('qgis', 'native', '3d'):
|
||||
parent.setHidden(parent.childCount() == 0)
|
||||
|
||||
|
||||
|
@ -655,7 +655,7 @@ class ModelerDialog(BASE, WIDGET):
|
||||
if show:
|
||||
if alg.group() in groups:
|
||||
groupItem = groups[alg.group()]
|
||||
elif provider.id() in ('qgis', 'native') and alg.group() in qgis_groups:
|
||||
elif provider.id() in ('qgis', 'native', '3d') and alg.group() in qgis_groups:
|
||||
groupItem = qgis_groups[alg.group()]
|
||||
else:
|
||||
groupItem = QTreeWidgetItem()
|
||||
@ -663,7 +663,7 @@ class ModelerDialog(BASE, WIDGET):
|
||||
groupItem.setText(0, name)
|
||||
groupItem.setToolTip(0, name)
|
||||
groupItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
|
||||
if provider.id() in ('qgis', 'native'):
|
||||
if provider.id() in ('qgis', 'native', '3d'):
|
||||
groupItem.setIcon(0, provider.icon())
|
||||
qgis_groups[alg.group()] = groupItem
|
||||
else:
|
||||
|
@ -19,6 +19,9 @@ SET(QGIS_3D_SRCS
|
||||
chunks/qgschunknode_p.cpp
|
||||
chunks/qgschunkqueuejob_p.cpp
|
||||
|
||||
processing/qgs3dalgorithms.cpp
|
||||
processing/qgsalgorithmtesselate.cpp
|
||||
|
||||
symbols/qgsabstract3dsymbol.cpp
|
||||
symbols/qgsline3dsymbol.cpp
|
||||
symbols/qgsline3dsymbol_p.cpp
|
||||
@ -56,6 +59,8 @@ SET(QGIS_3D_MOC_HDRS
|
||||
chunks/qgschunkloader_p.h
|
||||
chunks/qgschunkqueuejob_p.h
|
||||
|
||||
processing/qgs3dalgorithms.h
|
||||
|
||||
terrain/qgsdemterraintileloader_p.h
|
||||
terrain/qgsterrainentity_p.h
|
||||
terrain/qgsterraintexturegenerator_p.h
|
||||
|
62
src/3d/processing/qgs3dalgorithms.cpp
Normal file
62
src/3d/processing/qgs3dalgorithms.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
qgs3dalgorithms.cpp
|
||||
---------------------
|
||||
begin : November 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgs3dalgorithms.h"
|
||||
#include "qgsalgorithmtesselate.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
Qgs3DAlgorithms::Qgs3DAlgorithms( QObject *parent )
|
||||
: QgsProcessingProvider( parent )
|
||||
{}
|
||||
|
||||
QIcon Qgs3DAlgorithms::icon() const
|
||||
{
|
||||
return QgsApplication::getThemeIcon( QStringLiteral( "/providerQgis.svg" ) );
|
||||
}
|
||||
|
||||
QString Qgs3DAlgorithms::svgIconPath() const
|
||||
{
|
||||
return QgsApplication::iconPath( QStringLiteral( "providerQgis.svg" ) );
|
||||
}
|
||||
|
||||
QString Qgs3DAlgorithms::id() const
|
||||
{
|
||||
return QStringLiteral( "3d" );
|
||||
}
|
||||
|
||||
QString Qgs3DAlgorithms::name() const
|
||||
{
|
||||
return tr( "QGIS (3D)" );
|
||||
}
|
||||
|
||||
bool Qgs3DAlgorithms::supportsNonFileBasedOutput() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Qgs3DAlgorithms::loadAlgorithms()
|
||||
{
|
||||
addAlgorithm( new QgsTesselateAlgorithm() );
|
||||
}
|
||||
|
||||
|
||||
///@endcond
|
||||
|
||||
|
||||
|
56
src/3d/processing/qgs3dalgorithms.h
Normal file
56
src/3d/processing/qgs3dalgorithms.h
Normal file
@ -0,0 +1,56 @@
|
||||
/***************************************************************************
|
||||
qgs3dalgorithms.h
|
||||
---------------------
|
||||
begin : November 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGS3DALGORITHMS_H
|
||||
#define QGS3DALGORITHMS_H
|
||||
|
||||
#include "qgis_3d.h"
|
||||
#include "qgis.h"
|
||||
#include "processing/qgsprocessingprovider.h"
|
||||
|
||||
/**
|
||||
* \ingroup analysis
|
||||
* \class Qgs3DAlgorithms
|
||||
* \since QGIS 3.0
|
||||
* \brief QGIS 3D processing algorithm provider.
|
||||
*/
|
||||
class _3D_EXPORT Qgs3DAlgorithms: public QgsProcessingProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for Qgs3DAlgorithms.
|
||||
*/
|
||||
Qgs3DAlgorithms( QObject *parent = nullptr );
|
||||
|
||||
QIcon icon() const override;
|
||||
QString svgIconPath() const override;
|
||||
QString id() const override;
|
||||
QString name() const override;
|
||||
bool supportsNonFileBasedOutput() const override;
|
||||
|
||||
protected:
|
||||
|
||||
void loadAlgorithms() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGS3DALGORITHMS_H
|
||||
|
||||
|
136
src/3d/processing/qgsalgorithmtesselate.cpp
Normal file
136
src/3d/processing/qgsalgorithmtesselate.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmtesselate.cpp
|
||||
---------------------
|
||||
begin : November 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsalgorithmtesselate.h"
|
||||
#include "qgstessellator.h"
|
||||
#include "qgsmultipolygon.h"
|
||||
#include "qgstriangle.h"
|
||||
///@cond PRIVATE
|
||||
|
||||
QString QgsTesselateAlgorithm::name() const
|
||||
{
|
||||
return QStringLiteral( "tesselate" );
|
||||
}
|
||||
|
||||
QString QgsTesselateAlgorithm::displayName() const
|
||||
{
|
||||
return QObject::tr( "Tesselate geometry" );
|
||||
}
|
||||
|
||||
QStringList QgsTesselateAlgorithm::tags() const
|
||||
{
|
||||
return QObject::tr( "3d,triangle" ).split( ',' );
|
||||
}
|
||||
|
||||
QString QgsTesselateAlgorithm::group() const
|
||||
{
|
||||
return QObject::tr( "Vector geometry" );
|
||||
}
|
||||
|
||||
QString QgsTesselateAlgorithm::outputName() const
|
||||
{
|
||||
return QObject::tr( "Tesselated" );
|
||||
}
|
||||
|
||||
QgsProcessing::SourceType QgsTesselateAlgorithm::outputLayerType() const
|
||||
{
|
||||
return QgsProcessing::TypeVectorPolygon;
|
||||
}
|
||||
|
||||
QgsWkbTypes::Type QgsTesselateAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
|
||||
{
|
||||
Q_UNUSED( inputWkbType );
|
||||
return QgsWkbTypes::MultiPolygonZ;
|
||||
}
|
||||
|
||||
QString QgsTesselateAlgorithm::shortHelpString() const
|
||||
{
|
||||
return QObject::tr( "This algorithm tesselates a polygon geometry layer, dividing the geometries into triangular components." )
|
||||
+ QStringLiteral( "\n\n" )
|
||||
+ QObject::tr( "The output layer consists of multipolygon geometries for each input feature, with each multipolygon consisting of multiple triangle component polygons." );
|
||||
}
|
||||
|
||||
QList<int> QgsTesselateAlgorithm::inputLayerTypes() const
|
||||
{
|
||||
return QList<int>() << QgsProcessing::TypeVectorPolygon;
|
||||
}
|
||||
|
||||
QgsTesselateAlgorithm *QgsTesselateAlgorithm::createInstance() const
|
||||
{
|
||||
return new QgsTesselateAlgorithm();
|
||||
}
|
||||
|
||||
QgsPoint getPointFromData( QVector< float >::const_iterator &it )
|
||||
{
|
||||
// tesselator geometry is x, z, -y
|
||||
double x = *it;
|
||||
++it;
|
||||
double z = *it;
|
||||
++it;
|
||||
double y = -( *it );
|
||||
++it;
|
||||
return QgsPoint( x, y, z );
|
||||
}
|
||||
|
||||
void tesselatePolygon( const QgsPolygon *polygon, QgsMultiPolygon *destination )
|
||||
{
|
||||
QgsTessellator t( 0, 0, false );
|
||||
t.addPolygon( *polygon, 0 );
|
||||
|
||||
QVector<float> data = t.data();
|
||||
for ( auto it = data.constBegin(); it != data.constEnd(); )
|
||||
{
|
||||
QgsPoint p1 = getPointFromData( it );
|
||||
QgsPoint p2 = getPointFromData( it );
|
||||
QgsPoint p3 = getPointFromData( it );
|
||||
destination->addGeometry( new QgsTriangle( p1, p2, p3 ) );
|
||||
}
|
||||
}
|
||||
|
||||
QgsFeature QgsTesselateAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingFeedback * )
|
||||
{
|
||||
QgsFeature f = feature;
|
||||
if ( f.hasGeometry() )
|
||||
{
|
||||
if ( QgsWkbTypes::geometryType( f.geometry().wkbType() ) != QgsWkbTypes::PolygonGeometry )
|
||||
f.clearGeometry();
|
||||
else
|
||||
{
|
||||
std::unique_ptr< QgsMultiPolygon > mp = qgis::make_unique< QgsMultiPolygon >();
|
||||
if ( f.geometry().isMultipart() )
|
||||
{
|
||||
const QgsMultiSurface *ms = qgsgeometry_cast< const QgsMultiSurface * >( f.geometry().constGet() );
|
||||
for ( int i = 0; i < ms->numGeometries(); ++i )
|
||||
{
|
||||
std::unique_ptr< QgsPolygon > p( qgsgeometry_cast< QgsPolygon * >( ms->geometryN( i )->segmentize() ) );
|
||||
tesselatePolygon( p.get(), mp.get() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::unique_ptr< QgsPolygon > p( qgsgeometry_cast< QgsPolygon * >( f.geometry().constGet()->segmentize() ) );
|
||||
tesselatePolygon( p.get(), mp.get() );
|
||||
}
|
||||
f.setGeometry( QgsGeometry( std::move( mp ) ) );
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
||||
|
59
src/3d/processing/qgsalgorithmtesselate.h
Normal file
59
src/3d/processing/qgsalgorithmtesselate.h
Normal file
@ -0,0 +1,59 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmtesselate.h
|
||||
---------------------
|
||||
begin : November 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSALGORITHMTESSELATE_H
|
||||
#define QGSALGORITHMTESSELATE_H
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
#include "qgis.h"
|
||||
#include "processing/qgsprocessingalgorithm.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
/**
|
||||
* Native tesselate algorithm.
|
||||
*/
|
||||
class QgsTesselateAlgorithm : public QgsProcessingFeatureBasedAlgorithm
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
QgsTesselateAlgorithm() = default;
|
||||
QString name() const override;
|
||||
QString displayName() const override;
|
||||
virtual QStringList tags() const override;
|
||||
QString group() const override;
|
||||
QString shortHelpString() const override;
|
||||
QList<int> inputLayerTypes() const override;
|
||||
QgsTesselateAlgorithm *createInstance() const override SIP_FACTORY;
|
||||
|
||||
protected:
|
||||
QString outputName() const override;
|
||||
QgsProcessing::SourceType outputLayerType() const override;
|
||||
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
|
||||
|
||||
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
||||
#endif // QGSALGORITHMTESSELATE_H
|
||||
|
||||
|
@ -89,6 +89,7 @@
|
||||
#include "qgs3dmapsettings.h"
|
||||
#include "qgsflatterraingenerator.h"
|
||||
#include "qgsvectorlayer3drenderer.h"
|
||||
#include "processing/qgs3dalgorithms.h"
|
||||
#endif
|
||||
|
||||
#include <QNetworkReply>
|
||||
@ -10190,6 +10191,9 @@ void QgisApp::init3D()
|
||||
void QgisApp::initNativeProcessing()
|
||||
{
|
||||
QgsApplication::processingRegistry()->addProvider( new QgsNativeAlgorithms( QgsApplication::processingRegistry() ) );
|
||||
#ifdef HAVE_3D
|
||||
QgsApplication::processingRegistry()->addProvider( new Qgs3DAlgorithms( QgsApplication::processingRegistry() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
void QgisApp::initLayouts()
|
||||
|
Loading…
x
Reference in New Issue
Block a user