18 #ifndef QGSMESHTRACERENDERER_H
19 #define QGSMESHTRACERENDERER_H
25 #include "qgis_core.h"
44 class QgsMeshVectorValueInterpolator
57 QgsMeshVectorValueInterpolator(
const QgsMeshVectorValueInterpolator &other );
60 virtual QgsMeshVectorValueInterpolator *clone() = 0;
63 virtual ~QgsMeshVectorValueInterpolator() =
default;
69 QgsMeshVectorValueInterpolator &operator=(
const QgsMeshVectorValueInterpolator &other );
72 void updateCacheFaceIndex(
const QgsPointXY &point )
const;
78 mutable int mCacheFaceIndex = -1;
79 bool mUseScalarActiveFaceFlagValues =
false;
80 bool isVectorValid(
const QgsVector &v )
const;
84 void activeFaceFilter(
QgsVector &vector,
int faceIndex )
const;
86 virtual QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const = 0;
97 class QgsMeshVectorValueInterpolatorFromVertex:
public QgsMeshVectorValueInterpolator
101 QgsMeshVectorValueInterpolatorFromVertex(
const QgsTriangularMesh &triangularMesh,
105 QgsMeshVectorValueInterpolatorFromVertex(
const QgsTriangularMesh &triangularMesh,
110 QgsMeshVectorValueInterpolatorFromVertex(
const QgsMeshVectorValueInterpolatorFromVertex &other );
113 virtual QgsMeshVectorValueInterpolatorFromVertex *clone()
override;
116 QgsMeshVectorValueInterpolatorFromVertex &operator=(
const QgsMeshVectorValueInterpolatorFromVertex &other );
119 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
130 class QgsMeshVectorValueInterpolatorFromFace:
public QgsMeshVectorValueInterpolator
143 QgsMeshVectorValueInterpolatorFromFace(
const QgsMeshVectorValueInterpolatorFromFace &other );
146 virtual QgsMeshVectorValueInterpolatorFromFace *clone()
override;
149 QgsMeshVectorValueInterpolatorFromFace &operator=(
const QgsMeshVectorValueInterpolatorFromFace &other );
152 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
163 class QgsMeshStreamField
179 double magnitudeMaximum,
180 bool dataIsOnVertices,
183 int resolution = 1 );
186 QgsMeshStreamField(
const QgsMeshStreamField &other );
189 virtual ~QgsMeshStreamField();
206 bool isValid()
const;
212 QPoint topLeft()
const;
215 void addTrace( QPoint startPixel );
221 void addRandomTraces();
224 void addRandomTrace();
227 void addGriddedTraces(
int dx,
int dy );
233 void setResolution(
int width );
236 int resolution()
const;
239 QSize imageSize()
const;
242 virtual QImage image();
245 void setPixelFillingDensity(
double maxFilling );
248 void setColor( QColor color );
251 void setLineWidth(
double width );
254 void setFilter(
double min,
double max );
257 void setMinimizeFieldSize(
bool minimizeFieldSize );
260 QgsMeshStreamField &operator=(
const QgsMeshStreamField &other );
264 QPointF fieldToDevice(
const QPoint &pixel )
const;
265 bool filterMag(
double value )
const;
268 QgsPointXY positionToMapCoordinates(
const QPoint &pixelPosition,
const QgsPointXY &positionInPixel );
269 bool addPixelToChunkTrace( QPoint &pixel,
270 QgsMeshStreamField::FieldData &data,
271 std::list<QPair<QPoint, QgsMeshStreamField::FieldData> > &chunkTrace );
272 void setChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
273 virtual void drawChunkTrace(
const std::list<QPair<QPoint, FieldData>> &chunkTrace ) = 0;
274 void clearChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
275 virtual void storeInField(
const QPair<QPoint, FieldData> pixelData ) = 0;
276 virtual void initField() = 0;
277 void simplifyChunkTrace( std::list<QPair<QPoint, FieldData>> &shunkTrace );
279 virtual bool isTraceExists(
const QPoint &pixel )
const = 0;
280 bool isTraceOutside(
const QPoint &pixel )
const;
285 std::unique_ptr<QPainter> mPainter = std::unique_ptr<QPainter>(
nullptr );
286 int mFieldResolution = 1;
294 int mPixelFillingCount = 0;
295 int mMaxPixelFillingCount = 0;
296 std::unique_ptr<QgsMeshVectorValueInterpolator> mVectorValueInterpolator;
299 QPoint mFieldTopLeftInDeviceCoordinates;
301 double mMaximumMagnitude = 0;
302 double mPixelFillingDensity = 0;
303 double mMinMagFilter = -1;
304 double mMaxMagFilter = -1;
306 bool mMinimizeFieldSize =
true;
317 class QgsMeshStreamlinesField:
public QgsMeshStreamField
326 bool dataIsOnVertices,
331 QgsMeshStreamlinesField(
const QgsMeshStreamlinesField &other );
334 QgsMeshStreamlinesField &operator=(
const QgsMeshStreamlinesField &other );
337 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
338 void initField()
override;
339 bool isTraceExists(
const QPoint &pixel )
const override;
340 void drawChunkTrace(
const std::list<QPair<QPoint, FieldData> > &chunkTrace )
override;
342 QVector<bool> mField;
346 class QgsMeshParticleTracesField;
356 struct QgsMeshTraceParticle
360 std::list<QPoint> tail;
361 double remainingTime = 0;
372 class QgsMeshParticleTracesField:
public QgsMeshStreamField
381 bool dataIsOnVertices,
386 QgsMeshParticleTracesField(
const QgsMeshParticleTracesField &other );
389 void addParticle(
const QPoint &startPoint,
double lifeTime );
392 void addParticleXY(
const QgsPointXY &startPoint,
double lifeTime );
395 void addRandomParticles();
398 void moveParticles();
401 QImage imageRendered()
const;
404 void setParticlesCount(
int particlesCount );
407 void setParticlesLifeTime(
double particlesLifeTime );
417 void setStumpFactor(
int sf );
420 void setTimeStep(
double timeStep );
423 void setParticleSize(
double particleSize );
426 void setTailFactor(
double tailFactor );
429 void setMinTailLength(
int minTailLength );
432 QgsMeshParticleTracesField &operator=(
const QgsMeshParticleTracesField &other );
435 void setStumpParticleWithLifeTime(
bool stumpParticleWithLifeTime );
438 void setParticlesColor(
const QColor &
c );
440 QPoint direction( QPoint position )
const;
442 float time( QPoint position )
const;
443 float magnitude( QPoint position )
const;
445 void drawParticleTrace(
const QgsMeshTraceParticle &particle );
447 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
448 void initField()
override;
449 bool isTraceExists(
const QPoint &pixel )
const override;
450 void drawChunkTrace(
const std::list<QPair<QPoint, FieldData>> &chunkTrace )
override {Q_UNUSED( chunkTrace )}
459 QVector<float> mTimeField;
460 QVector<float> mMagnitudeField;
475 QVector<char> mDirectionField;
476 QList<QgsMeshTraceParticle> mParticles;
479 double mTimeStep = 200;
480 double mParticlesLifeTime = 5000;
481 int mParticlesCount = 1000;
482 double mTailFactor = 5;
483 int mMinTailLength = 3;
484 QColor mParticleColor = Qt::white;
485 double mParticleSize = 2.5;
486 int mStumpFactor = 50;
487 bool mStumpParticleWithLifeTime =
true;
500 class QgsMeshVectorStreamlineRenderer:
public QgsMeshVectorRenderer
507 bool dataIsOnVertices,
513 void draw()
override;
516 std::unique_ptr<QgsMeshStreamField> mStreamlineField;
531 class QgsMeshVectorTraceRenderer:
public QgsMeshVectorRenderer
538 bool dataIsOnVertices,
544 void draw()
override;
547 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
570 bool dataIsOnVertices,
586 void seedRandomParticles(
int count );
589 QImage imageRendered();
592 void setFPS(
int FPS );
595 void setMaxSpeedPixel(
int max );
598 void setParticlesLifeTime(
double particleLifeTime );
601 void setParticlesColor(
const QColor &
c );
604 void setParticlesSize(
double width );
607 void setTailFactor(
double fct );
610 void setMinimumTailLength(
int l );
613 void setTailPersitence(
double p );
618 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
622 double mParticleLifeTime = 5;
624 void updateFieldParameter();
627 #endif // QGSMESHTRACERENDERER_H