38 const QString &baseName,
39 const QString &providerKey,
45 if ( !meshLayerPath.isEmpty() && !providerKey.isEmpty() )
48 setDataProvider( providerKey, providerOptions );
52 setDefaultRendererSettings();
55 void QgsMeshLayer::setDefaultRendererSettings()
96 return mDataProvider->
extent();
112 return mNativeMesh.get();
117 return mNativeMesh.get();
122 return mTriangularMesh.get();
127 return mTriangularMesh.get();
132 return mRendererCache.get();
137 return mRendererSettings;
142 mRendererSettings = settings;
153 int faceIndex = mTriangularMesh->faceIndexForPoint( point ) ;
154 if ( faceIndex >= 0 )
156 int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
157 if (
dataProvider()->isFaceActive( index, nativeFaceIndex ) )
162 int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
167 const QgsMeshFace &face = mTriangularMesh->triangles()[faceIndex];
168 const int v1 = face[0], v2 = face[1], v3 = face[2];
169 const QgsPoint p1 = mTriangularMesh->vertices()[v1], p2 = mTriangularMesh->vertices()[v2], p3 = mTriangularMesh->vertices()[v3];
173 const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
x(), val2.
x(), val3.
x(), point );
174 double y = std::numeric_limits<double>::quiet_NaN();
177 y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
y(), val2.
y(), val3.
y(), point );
189 void QgsMeshLayer::fillNativeMesh()
191 Q_ASSERT( !mNativeMesh );
193 mNativeMesh.reset(
new QgsMesh() );
201 void QgsMeshLayer::onDatasetGroupsAdded(
int count )
205 for (
int i = newDatasetGroupCount - count; i < newDatasetGroupCount; ++i )
206 assignDefaultStyleToDatasetGroup( i );
217 props[
"color1"] =
"13,8,135,255";
218 props[
"color2"] =
"240,249,33,255";
220 "0.0196078;27,6,141,255:0.0392157;38,5,145,255:0.0588235;47,5,150,255:0.0784314;56,4,154,255:0.0980392;65,4,157,255:" 221 "0.117647;73,3,160,255:0.137255;81,2,163,255:0.156863;89,1,165,255:0.176471;97,0,167,255:0.196078;105,0,168,255:" 222 "0.215686;113,0,168,255:0.235294;120,1,168,255:0.254902;128,4,168,255:0.27451;135,7,166,255:0.294118;142,12,164,255:" 223 "0.313725;149,17,161,255:0.333333;156,23,158,255:0.352941;162,29,154,255:0.372549;168,34,150,255:0.392157;174,40,146,255:" 224 "0.411765;180,46,141,255:0.431373;186,51,136,255:0.45098;191,57,132,255:0.470588;196,62,127,255:0.490196;201,68,122,255:" 225 "0.509804;205,74,118,255:0.529412;210,79,113,255:0.54902;214,85,109,255:0.568627;218,91,105,255:0.588235;222,97,100,255:" 226 "0.607843;226,102,96,255:0.627451;230,108,92,255:0.647059;233,114,87,255:0.666667;237,121,83,255:0.686275;240,127,79,255:" 227 "0.705882;243,133,75,255:0.72549;245,140,70,255:0.745098;247,147,66,255:0.764706;249,154,62,255:0.784314;251,161,57,255:" 228 "0.803922;252,168,53,255:0.823529;253,175,49,255:0.843137;254,183,45,255:0.862745;254,190,42,255:0.882353;253,198,39,255:" 229 "0.901961;252,206,37,255:0.921569;251,215,36,255:0.941176;248,223,37,255:0.960784;246,232,38,255:0.980392;243,240,39,255";
233 void QgsMeshLayer::assignDefaultStyleToDatasetGroup(
int groupIndex )
236 double groupMin = metadata.
minimum();
237 double groupMax = metadata.
maximum();
258 if ( !mTriangularMesh )
261 mTriangularMesh->update( mNativeMesh.get(), &rendererContext );
264 if ( !mRendererCache )
265 mRendererCache.reset(
new QgsMeshLayerRendererCache() );
273 Q_UNUSED( errorMessage );
276 QDomElement elem = node.toElement();
280 QDomElement elemRendererSettings = elem.firstChildElement(
"mesh-renderer-settings" );
281 if ( !elemRendererSettings.isNull() )
282 mRendererSettings.
readXml( elemRendererSettings );
285 QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
286 if ( !blendModeNode.isNull() )
288 QDomElement e = blendModeNode.toElement();
298 Q_UNUSED( errorMessage );
301 QDomElement elem = node.toElement();
305 QDomElement elemRendererSettings = mRendererSettings.
writeXml( doc );
306 elem.appendChild( elemRendererSettings );
309 QDomElement blendModeElement = doc.createElement( QStringLiteral(
"blendMode" ) );
311 blendModeElement.appendChild( blendModeText );
312 node.appendChild( blendModeElement );
319 QString src( source );
320 if ( provider == QLatin1String(
"mdal" ) )
329 QString src( source );
342 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
344 if ( pkeyNode.isNull() )
350 QDomElement pkeyElt = pkeyNode.toElement();
355 if ( !setDataProvider(
mProviderKey, providerOptions ) )
360 QDomElement elemExtraDatasets = layer_node.firstChildElement( QStringLiteral(
"extra-datasets" ) );
361 if ( !elemExtraDatasets.isNull() )
363 QDomElement elemUri = elemExtraDatasets.firstChildElement( QStringLiteral(
"uri" ) );
364 while ( !elemUri.isNull() )
370 QgsDebugMsg( QStringLiteral(
"extra dataset (res %1): %2" ).arg( res ).arg( uri ) );
375 elemUri = elemUri.nextSiblingElement( QStringLiteral(
"uri" ) );
388 QDomElement mapLayerNode = layer_node.toElement();
390 if ( mapLayerNode.isNull() || ( QLatin1String(
"maplayer" ) != mapLayerNode.nodeName() ) )
396 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"mesh" ) );
401 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
402 QDomText providerText = document.createTextNode(
providerType() );
403 provider.appendChild( providerText );
404 layer_node.appendChild( provider );
406 const QStringList extraDatasetUris = mDataProvider->
extraDatasets();
407 QDomElement elemExtraDatasets = document.createElement( QStringLiteral(
"extra-datasets" ) );
408 for (
const QString &uri : extraDatasetUris )
411 QDomElement elemUri = document.createElement( QStringLiteral(
"uri" ) );
412 elemUri.appendChild( document.createTextNode( path ) );
413 elemExtraDatasets.appendChild( elemUri );
415 layer_node.appendChild( elemExtraDatasets );
425 delete mDataProvider;
431 if ( !mDataProvider )
433 QgsDebugMsgLevel( QStringLiteral(
"Unable to get mesh data provider" ), 2 );
437 mDataProvider->setParent(
this );
438 QgsDebugMsgLevel( QStringLiteral(
"Instantiated the mesh data provider plugin" ), 2 );
449 if ( provider == QStringLiteral(
"mesh_memory" ) )
456 assignDefaultStyleToDatasetGroup( i );
void setClassificationMinimumMaximum(double minimum, double maximum)
Sets min/max values used for creation of the color ramp shader.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Base class for all map layer types.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void setRendererSettings(const QgsMeshRendererSettings &settings)
Sets new renderer settings.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QString mProviderKey
Data provider key (name of the data provider)
Represents a mesh renderer settings for mesh object.
A class to represent a 2D point.
Abstract base class for color ramps.
virtual bool addDataset(const QString &uri)=0
Associate dataset with the mesh.
Represents a mesh renderer settings for scalar datasets.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Setting options for loading mesh layers.
bool isValid() const
Returns the status of the layer.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void setScalarSettings(int groupIndex, const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings.
static QgsMapLayerLegend * defaultMeshLegend(QgsMeshLayer *ml)
Create new legend implementation for mesh layer.
QMap< QString, QString > QgsStringMap
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
static QgsStyle * defaultStyle()
Returns default application-wide style.
Implementation of threaded rendering for mesh layers.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
double y() const
Returns y value.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Represents all mesh renderer settings.
QgsRectangle extent() const override
Returns the extent of the layer.
QString providerType() const
Returns the provider type for this layer.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted...
#define QgsDebugMsgLevel(str, level)
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
void setColorRampShader(const QgsColorRampShader &shader)
Sets color ramp shader function.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
void datasetGroupsAdded(int count)
Emitted when some new dataset groups have been added.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be null.
void rendererChanged()
Signal emitted when renderer is changed.
bool mValid
Indicates if the layer is valid and can be drawn.
Point geometry type, with support for z-dimension and m-values.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, const QgsPointXY &point) const
Interpolates the value on the given point from given dataset.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices and faces.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Base class for providing data for QgsMeshLayer.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files...
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
QString name() const
Returns the display name of the layer.
Mesh - vertices and faces.
QString mDataSource
Data source description string, varies by layer type.
QString source() const
Returns the source for the layer.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
void setNativeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new renderer settings, triggers repaint.
QVector< int > QgsMeshFace
List of vertex indexes.
void setActiveScalarDataset(QgsMeshDatasetIndex index=QgsMeshDatasetIndex())
Sets active scalar dataset for rendering.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
virtual QStringList extraDatasets() const =0
Returns list of additional dataset file URIs added using addDataset() calls.
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
void dataChanged()
Data of layer changed.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshDatasetValue represents single dataset value.
virtual QgsMeshDatasetValue datasetValue(QgsMeshDatasetIndex index, int valueIndex) const =0
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files...
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
double x() const
Returns x value.
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="mesh_memory", const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.