QGIS API Documentation  3.6.0-Noosa (5873452)
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 "qgsmeshdataprovider.h"
19 #include "qgsrectangle.h"
20 #include "qgis.h"
21 
22 
23 
25  : mGroupIndex( group ), mDatasetIndex( dataset )
26 {}
27 
29 {
30  return mGroupIndex;
31 }
32 
34 {
35  return mDatasetIndex;
36 }
37 
39 {
40  return ( group() > -1 ) && ( dataset() > -1 );
41 }
42 
44 {
45  if ( isValid() && other.isValid() )
46  return other.group() == group() && other.dataset() == dataset();
47  else
48  return isValid() == other.isValid();
49 }
50 
52 {
53  return !( operator==( other ) );
54 }
55 
57  : QgsDataProvider( uri, options )
58 {
59 }
60 
62  : mX( x ), mY( y )
63 {}
64 
66  : mX( scalar )
67 {}
68 
70 {
71  if ( std::isnan( mY ) )
72  {
73  return mX;
74  }
75  else if ( std::isnan( mX ) )
76  {
77  return std::numeric_limits<double>::quiet_NaN();
78  }
79  else
80  {
81  return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
82  }
83 }
84 
86 {
87  setX( scalar );
88 }
89 
91 {
92  mX = x;
93 }
94 
96 {
97  mY = y;
98 }
99 
101 {
102  return mX;
103 }
104 
106 {
107  return mY;
108 }
109 
111 {
112  bool equal = std::isnan( mX ) == std::isnan( other.x() );
113  equal &= std::isnan( mY ) == std::isnan( other.y() );
114 
115  if ( equal )
116  {
117  if ( std::isnan( mY ) )
118  {
119  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
120  }
121  else
122  {
123  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
124  equal &= qgsDoubleNear( other.y(), mY, 1E-8 );
125  }
126  }
127  return equal;
128 }
129 
131  bool isScalar,
132  bool isOnVertices,
133  double minimum,
134  double maximum,
135  const QMap<QString, QString> &extraOptions )
136  : mName( name )
137  , mIsScalar( isScalar )
138  , mIsOnVertices( isOnVertices )
139  , mMinimumValue( minimum )
140  , mMaximumValue( maximum )
141  , mExtraOptions( extraOptions )
142 {
143 }
144 
145 QMap<QString, QString> QgsMeshDatasetGroupMetadata::extraOptions() const
146 {
147  return mExtraOptions;
148 }
149 
151 {
152  return !mIsScalar;
153 }
154 
156 {
157  return mIsScalar;
158 }
159 
161 {
162  return mName;
163 }
164 
166 {
167  return ( mIsOnVertices ) ? DataType::DataOnVertices : DataType::DataOnFaces;
168 }
169 
171 {
172  return mMinimumValue;
173 }
174 
176 {
177  return mMaximumValue;
178 }
179 
181 {
182  return datasetCount( index.group() );
183 }
184 
186 {
187  return datasetGroupMetadata( index.group() );
188 }
189 
191  bool isValid,
192  double minimum,
193  double maximum )
194  : mTime( time )
195  , mIsValid( isValid )
196  , mMinimumValue( minimum )
197  , mMaximumValue( maximum )
198 {
199 }
200 
202 {
203  return mTime;
204 }
205 
207 {
208  return mIsValid;
209 }
210 
212 {
213  return mMinimumValue;
214 }
215 
217 {
218  return mMaximumValue;
219 }
220 
222  : mType( ActiveFlagInteger )
223 {
224 }
225 
227  : mType( type )
228 {
229  switch ( type )
230  {
231  case ActiveFlagInteger:
232  mIntegerBuffer.resize( count );
233  break;
234  case ScalarDouble:
235  mDoubleBuffer.resize( count );
236  break;
237  case Vector2DDouble:
238  mDoubleBuffer.resize( 2 * count );
239  break;
240  }
241 }
242 
244 {
245  return mType;
246 }
247 
249 {
250  switch ( mType )
251  {
252  case ActiveFlagInteger:
253  return mIntegerBuffer.size();
254  case ScalarDouble:
255  return mDoubleBuffer.size();
256  case Vector2DDouble:
257  return static_cast<int>( mDoubleBuffer.size() / 2.0 );
258  }
259  return 0; // no warnings
260 }
261 
263 {
264  return count() > 0;
265 }
266 
268 {
269  switch ( mType )
270  {
271  case ActiveFlagInteger:
272  return QgsMeshDatasetValue();
273  case ScalarDouble:
274  return QgsMeshDatasetValue( mDoubleBuffer[index] );
275  case Vector2DDouble:
276  return QgsMeshDatasetValue(
277  mDoubleBuffer[2 * index],
278  mDoubleBuffer[2 * index + 1]
279  );
280  }
281  return QgsMeshDatasetValue(); // no warnings
282 }
283 
284 bool QgsMeshDataBlock::active( int index ) const
285 {
286  if ( ActiveFlagInteger == mType )
287  return bool( mIntegerBuffer[index] );
288  else
289  return false;
290 }
291 
293 {
294  if ( ActiveFlagInteger == mType )
295  {
296  return mIntegerBuffer.data();
297  }
298  else
299  {
300  return mDoubleBuffer.data();
301  }
302 }
303 
304 const void *QgsMeshDataBlock::constBuffer() const
305 {
306  if ( ActiveFlagInteger == mType )
307  {
308  return mIntegerBuffer.constData();
309  }
310  else
311  {
312  return mDoubleBuffer.constData();
313  }
314 }
315 
316 QgsMeshVertex QgsMesh::vertex( int index ) const
317 {
318  if ( index < vertices.size() && index >= 0 )
319  return vertices[index];
320  return QgsMeshVertex();
321 }
322 
323 QgsMeshFace QgsMesh::face( int index ) const
324 {
325  if ( index < faces.size() && index >= 0 )
326  return faces[index];
327  return QgsMeshFace();
328 }
329 
331 {
332  return vertices.size();
333 }
334 
336 {
337  return faces.size();
338 }
bool operator==(const QgsMeshDatasetValue &other) const
void set(double scalar)
Sets scalar value.
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
QString name() const
Returns name of the dataset group.
int dataset() const
Returns a dataset index within group()
Vector double pairs (x1, y1, x2, y2, ... )
const void * constBuffer() const
Returns internal buffer to the array for fast values reading.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:265
double maximum() const
Returns maximum scalar value/vector magnitude present for the dataset.
int count() const
Number of items stored in the block.
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
QgsMeshDatasetIndex(int group=-1, int dataset=-1)
Creates an index. -1 represents invalid group/dataset.
double maximum() const
Returns maximum scalar value/vector magnitude present for whole dataset group.
void * buffer()
Returns internal buffer to the array.
QgsMeshDatasetGroupMetadata()=default
Constructs an empty metadata object.
Abstract base class for spatial data provider implementations.
void setY(double y)
Sets Y value.
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options)
Ctor.
DataType type() const
Type of data stored in the block.
int group() const
Returns a group index.
bool operator!=(const QgsMeshDatasetIndex &other) const
Inequality operator.
double y() const
Returns y value.
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces.
bool active(int index) const
Returns a value for active flag by the index For scalar and vector 2d the behavior is undefined...
DataType
Location of where data is specified for datasets in the dataset group.
QgsMeshDataBlock()
Constructs an invalid block.
Integer boolean flag whether face is active.
bool operator==(const QgsMeshDatasetIndex &other) const
Equality operator.
double minimum() const
Returns minimum scalar value/vector magnitude present for the dataset.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
DataType
Type of data stored in the block.
bool isValid() const
Returns whether dataset is valid.
bool isScalar() const
Returns whether dataset group has scalar data.
Setting options for creating vector data providers.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QMap< QString, QString > extraOptions() const
Returns extra metadata options, for example description.
bool isVector() const
Returns whether dataset group has vector data.
bool isValid() const
Whether the block is valid.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
QgsMeshFace face(int index) const
Returns a face at the index.
double time() const
Returns the time value for this dataset.
QgsMeshDatasetValue represents single dataset value.
int vertexCount() const
Returns number of vertices.
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
int faceCount() const
Returns number of faces.
void setX(double x)
Sets X value.
double x() const
Returns x value.
QgsPoint QgsMeshVertex
xyz coords of vertex
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.