QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmeshdataprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshdataprovider.cpp
3  -----------------------
4  begin : April 2018
5  copyright : (C) 2018 by Peter Petrik
6  email : zilolv at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgis.h"
19 #include "qgsmeshdataprovider.h"
21 #include "qgsrectangle.h"
22 
24  QgsDataProvider::ReadFlags flags )
25  : QgsDataProvider( uri, options, flags )
26 {
27 }
28 
30 {
31  return mTemporalCapabilities.get();
32 }
33 
35 {
36  return mTemporalCapabilities.get();
37 }
38 
40 {
41  QgsUnitTypes::TemporalUnit oldUnit = mTemporalCapabilities->temporalUnit();
42  mTemporalCapabilities->setTemporalUnit( unit );
43  if ( oldUnit != unit )
44  reloadData();
45 }
46 
48  const QDateTime &referenceTime,
49  int groupIndex, quint64 time,
51 {
52  QDateTime requestDateTime = referenceTime.addMSecs( time );
53  quint64 providerTime;
54  QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
55  if ( mTemporalCapabilities->referenceTime().isValid() )
56  providerTime = referenceTime.msecsTo( requestDateTime );
57  else
58  providerTime = time;
59 
60  switch ( method )
61  {
63  return mTemporalCapabilities->datasetIndexClosestBeforeRelativeTime( groupIndex, providerTime );
64  break;
66  return mTemporalCapabilities->datasetIndexClosestFromRelativeTime( groupIndex, providerTime );
67  break;
68  }
69 
70  return QgsMeshDatasetIndex();
71 }
72 
74  mTemporalCapabilities( qgis::make_unique<QgsMeshDataProviderTemporalCapabilities>() ) {}
75 
77 {
78  return datasetCount( index.group() );
79 }
80 
82 {
83  return datasetGroupMetadata( index.group() );
84 }
85 
87  const QString &path,
88  const QgsMeshDatasetGroupMetadata &meta,
89  const QVector<QgsMeshDataBlock> &datasetValues,
90  const QVector<QgsMeshDataBlock> &datasetActive,
91  const QVector<double> &times )
92 {
93  // Form DRIVER:filename
94  QString filename = path;
95  // ASCII dat supports face, edge and vertex datasets
96  QString driverName = QStringLiteral( "DAT" );
97  QStringList parts = path.split( ':' );
98  if ( parts.size() > 1 )
99  {
100  driverName = parts[0];
101  parts.removeFirst();
102  filename = parts.join( QString() );
103  }
104  return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
105 }
106 
107 QgsMeshVertex QgsMesh::vertex( int index ) const
108 {
109  if ( index < vertices.size() && index >= 0 )
110  return vertices[index];
111  return QgsMeshVertex();
112 }
113 
114 QgsMeshFace QgsMesh::face( int index ) const
115 {
116  if ( index < faces.size() && index >= 0 )
117  return faces[index];
118  return QgsMeshFace();
119 }
120 
121 QgsMeshEdge QgsMesh::edge( int index ) const
122 {
123  if ( index < edges.size() && index >= 0 )
124  return edges[index];
125  return QgsMeshEdge();
126 }
127 
129 {
130  vertices.clear();
131  edges.clear();
132  faces.clear();
133 }
134 
135 bool QgsMesh::compareFaces( const QgsMeshFace &face1, const QgsMeshFace &face2 )
136 {
137  if ( face1.count() != face2.count() )
138  return false;
139 
140  int startFace2 = 0;
141  for ( int i = 0; i < face2.count(); ++i )
142  if ( face2.at( i ) == face1.at( 0 ) )
143  {
144  startFace2 = i;
145  break;
146  }
147 
148  for ( int i = 0; i < face1.count(); ++i )
149  if ( face1.at( i ) != face2.at( ( i + startFace2 ) % ( face2.count() ) ) )
150  return false;
151 
152  return true;
153 }
154 
155 bool QgsMesh::contains( const QgsMesh::ElementType &type ) const
156 {
157  switch ( type )
158  {
159  case ElementType::Vertex:
160  return !vertices.isEmpty();
161  case ElementType::Edge:
162  return !edges.isEmpty();
163  case ElementType::Face:
164  return !faces.isEmpty();
165  }
166  return false;
167 }
168 
170 {
171  return vertices.size();
172 }
173 
175 {
176  return faces.size();
177 }
178 
180 {
181  return edges.size();
182 }
183 
185 {
186  switch ( type )
187  {
188  case QgsMesh::ElementType::Vertex:
189  return vertexCount() != 0;
190  case QgsMesh::ElementType::Edge:
191  return edgeCount() != 0;
193  return faceCount() != 0;
194  }
195  return false;
196 }
QgsMeshDatasetSourceInterface::datasetCount
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
Face
struct Face_t Face
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
qgsrectangle.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsMeshVertex
QgsPoint QgsMeshVertex
xyz coords of vertex
Definition: qgsmeshdataprovider.h:35
QgsMeshDataProviderTemporalCapabilities
Class for handling properties relating to a mesh data provider's temporal capabilities.
Definition: qgsmeshdataprovidertemporalcapabilities.h:35
qgis.h
QgsMeshDataSourceInterface::contains
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgsmeshdataprovider.cpp:184
QgsUnitTypes::TemporalUnit
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
QgsMesh::edges
QVector< QgsMeshEdge > edges
Definition: qgsmeshdataprovider.h:112
QgsMeshDataProviderTemporalCapabilities::FindClosestDatasetFromStartRangeTime
@ FindClosestDatasetFromStartRangeTime
Finds the closest dataset which have its time before the requested start range time.
Definition: qgsmeshdataprovidertemporalcapabilities.h:44
QgsMeshDatasetSourceInterface::datasetValues
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
QgsDataProvider::reloadData
virtual void reloadData()
Reloads the data from the source by calling reloadProviderData() implemented by providers with data c...
Definition: qgsdataprovider.cpp:40
QgsMesh::faceCount
int faceCount() const
Returns number of faces.
Definition: qgsmeshdataprovider.cpp:174
QgsMeshDatasetIndex::group
int group() const
Returns a group index.
Definition: qgsmeshdataset.cpp:26
QgsMesh::vertexCount
int vertexCount() const
Returns number of vertices.
Definition: qgsmeshdataprovider.cpp:169
QgsMesh::ElementType
ElementType
Defines type of mesh elements.
Definition: qgsmeshdataprovider.h:65
QgsMesh::faces
QVector< QgsMeshFace > faces
Definition: qgsmeshdataprovider.h:113
QgsMesh::edgeCount
int edgeCount() const
Returns number of edge.
Definition: qgsmeshdataprovider.cpp:179
QgsMesh::edge
QgsMeshEdge edge(int index) const
Returns an edge at the index.
Definition: qgsmeshdataprovider.cpp:121
QgsMeshDatasetSourceInterface::QgsMeshDatasetSourceInterface
QgsMeshDatasetSourceInterface()
Definition: qgsmeshdataprovider.cpp:73
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsMeshDatasetSourceInterface::persistDatasetGroup
virtual Q_DECL_DEPRECATED bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > &times)
Creates a new dataset group from a data and persists it into a destination path.
Definition: qgsmeshdataprovider.cpp:86
QgsMeshDataProvider::temporalCapabilities
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsmeshdataprovider.cpp:29
QgsMeshDataProvider::setTemporalUnit
void setTemporalUnit(QgsUnitTypes::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
Definition: qgsmeshdataprovider.cpp:39
QgsMesh::face
QgsMeshFace face(int index) const
Returns a face at the index.
Definition: qgsmeshdataprovider.cpp:114
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
Definition: qgsmeshdataprovidertemporalcapabilities.h:42
QgsMeshDataSourceInterface::edgeCount
virtual int edgeCount() const =0
Returns number of edges in the native mesh.
QgsMeshDataSourceInterface::vertexCount
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
QgsMeshFace
QVector< int > QgsMeshFace
List of vertex indexes.
Definition: qgsmeshdataprovider.h:41
QgsMesh::clear
void clear()
Remove all vertices, edges and faces.
Definition: qgsmeshdataprovider.cpp:128
QgsMeshDataProvider::QgsMeshDataProvider
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Ctor.
Definition: qgsmeshdataprovider.cpp:23
QgsMeshDatasetSourceInterface::datasetIndexAtTime
QgsMeshDatasetIndex datasetIndexAtTime(const QDateTime &referenceTime, int groupIndex, quint64 time, QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod method) const
Returns the dataset index of the dataset in a specific dataet group at time from the reference time.
Definition: qgsmeshdataprovider.cpp:47
QgsMeshDataSourceInterface::faceCount
virtual int faceCount() const =0
Returns number of faces in the native mesh.
QgsMesh::contains
bool contains(const ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgsmeshdataprovider.cpp:155
QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Definition: qgsmeshdataset.h:350
QgsMeshDataProviderTemporalCapabilities::FindClosestDatasetBeforeStartRangeTime
@ FindClosestDatasetBeforeStartRangeTime
Definition: qgsmeshdataprovidertemporalcapabilities.h:43
QgsMeshEdge
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
Definition: qgsmeshdataprovider.h:48
QgsMesh::vertices
QVector< QgsMeshVertex > vertices
Definition: qgsmeshdataprovider.h:111
qgsmeshdataprovidertemporalcapabilities.h
QgsMesh::compareFaces
static bool compareFaces(const QgsMeshFace &face1, const QgsMeshFace &face2)
Compare two faces, return true if they are equivalent : same indexes and same clock wise.
Definition: qgsmeshdataprovider.cpp:135
QgsMesh::vertex
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
Definition: qgsmeshdataprovider.cpp:107
qgsmeshdataprovider.h
QgsMeshDatasetSourceInterface::datasetGroupMetadata
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsMeshDatasetSourceInterface::mTemporalCapabilities
std::unique_ptr< QgsMeshDataProviderTemporalCapabilities > mTemporalCapabilities
Definition: qgsmeshdataprovider.h:383