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;
72 QgsMeshVectorValueInterpolator &operator=(
const QgsMeshVectorValueInterpolator &other );
75 void updateCacheFaceIndex(
const QgsPointXY &point )
const;
81 mutable int mCacheFaceIndex = -1;
82 bool mUseScalarActiveFaceFlagValues =
false;
83 bool isVectorValid(
const QgsVector &v )
const;
87 void activeFaceFilter(
QgsVector &vector,
int faceIndex )
const;
89 virtual QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const = 0;
100 class QgsMeshVectorValueInterpolatorFromVertex:
public QgsMeshVectorValueInterpolator
104 QgsMeshVectorValueInterpolatorFromVertex(
const QgsTriangularMesh &triangularMesh,
108 QgsMeshVectorValueInterpolatorFromVertex(
const QgsTriangularMesh &triangularMesh,
113 QgsMeshVectorValueInterpolatorFromVertex(
const QgsMeshVectorValueInterpolatorFromVertex &other );
116 virtual QgsMeshVectorValueInterpolatorFromVertex *clone()
override;
119 QgsMeshVectorValueInterpolatorFromVertex &operator=(
const QgsMeshVectorValueInterpolatorFromVertex &other );
122 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
133 class QgsMeshVectorValueInterpolatorFromFace:
public QgsMeshVectorValueInterpolator
146 QgsMeshVectorValueInterpolatorFromFace(
const QgsMeshVectorValueInterpolatorFromFace &other );
149 virtual QgsMeshVectorValueInterpolatorFromFace *clone()
override;
152 QgsMeshVectorValueInterpolatorFromFace &operator=(
const QgsMeshVectorValueInterpolatorFromFace &other );
155 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
166 class QgsMeshStreamField
182 double magnitudeMaximum,
183 bool dataIsOnVertices,
186 int resolution = 1 );
189 QgsMeshStreamField(
const QgsMeshStreamField &other );
192 virtual ~QgsMeshStreamField();
209 bool isValid()
const;
215 QPoint topLeft()
const;
218 void addTrace( QPoint startPixel );
224 void addRandomTraces();
227 void addRandomTrace();
230 void addGriddedTraces(
int dx,
int dy );
236 void setResolution(
int width );
239 int resolution()
const;
242 QSize imageSize()
const;
245 virtual QImage image();
248 void setPixelFillingDensity(
double maxFilling );
251 void setColor( QColor color );
254 void setLineWidth(
double width );
257 void setFilter(
double min,
double max );
260 void setMinimizeFieldSize(
bool minimizeFieldSize );
263 QgsMeshStreamField &operator=(
const QgsMeshStreamField &other );
267 QPointF fieldToDevice(
const QPoint &pixel )
const;
268 bool filterMag(
double value )
const;
271 QgsPointXY positionToMapCoordinates(
const QPoint &pixelPosition,
const QgsPointXY &positionInPixel );
272 bool addPixelToChunkTrace( QPoint &pixel,
273 QgsMeshStreamField::FieldData &data,
274 std::list<QPair<QPoint, QgsMeshStreamField::FieldData> > &chunkTrace );
275 void setChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
276 virtual void drawChunkTrace(
const std::list<QPair<QPoint, FieldData>> &chunkTrace ) = 0;
277 void clearChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
278 virtual void storeInField(
const QPair<QPoint, FieldData> pixelData ) = 0;
279 virtual void initField() = 0;
280 void simplifyChunkTrace( std::list<QPair<QPoint, FieldData>> &shunkTrace );
282 virtual bool isTraceExists(
const QPoint &pixel )
const = 0;
283 bool isTraceOutside(
const QPoint &pixel )
const;
288 std::unique_ptr<QPainter> mPainter = std::unique_ptr<QPainter>(
nullptr );
289 int mFieldResolution = 1;
297 int mPixelFillingCount = 0;
298 int mMaxPixelFillingCount = 0;
299 std::unique_ptr<QgsMeshVectorValueInterpolator> mVectorValueInterpolator;
302 QPoint mFieldTopLeftInDeviceCoordinates;
304 double mMaximumMagnitude = 0;
305 double mPixelFillingDensity = 0;
306 double mMinMagFilter = -1;
307 double mMaxMagFilter = -1;
309 bool mMinimizeFieldSize =
true;
320 class QgsMeshStreamlinesField:
public QgsMeshStreamField
329 bool dataIsOnVertices,
334 QgsMeshStreamlinesField(
const QgsMeshStreamlinesField &other );
337 QgsMeshStreamlinesField &operator=(
const QgsMeshStreamlinesField &other );
340 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
341 void initField()
override;
342 bool isTraceExists(
const QPoint &pixel )
const override;
343 void drawChunkTrace(
const std::list<QPair<QPoint, FieldData> > &chunkTrace )
override;
345 QVector<bool> mField;
349 class QgsMeshParticleTracesField;
359 struct QgsMeshTraceParticle
363 std::list<QPoint> tail;
364 double remainingTime = 0;
375 class QgsMeshParticleTracesField:
public QgsMeshStreamField
384 bool dataIsOnVertices,
389 QgsMeshParticleTracesField(
const QgsMeshParticleTracesField &other );
392 void addParticle(
const QPoint &startPoint,
double lifeTime );
395 void addParticleXY(
const QgsPointXY &startPoint,
double lifeTime );
398 void addRandomParticles();
401 void moveParticles();
404 QImage imageRendered()
const;
407 void setParticlesCount(
int particlesCount );
410 void setParticlesLifeTime(
double particlesLifeTime );
420 void setStumpFactor(
int sf );
423 void setTimeStep(
double timeStep );
426 void setParticleSize(
double particleSize );
429 void setTailFactor(
double tailFactor );
432 void setMinTailLength(
int minTailLength );
435 QgsMeshParticleTracesField &operator=(
const QgsMeshParticleTracesField &other );
438 void setStumpParticleWithLifeTime(
bool stumpParticleWithLifeTime );
441 void setParticlesColor(
const QColor &
c );
443 QPoint direction( QPoint position )
const;
445 float time( QPoint position )
const;
446 float magnitude( QPoint position )
const;
448 void drawParticleTrace(
const QgsMeshTraceParticle &particle );
450 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
451 void initField()
override;
452 bool isTraceExists(
const QPoint &pixel )
const override;
453 void drawChunkTrace(
const std::list<QPair<QPoint, FieldData>> &chunkTrace )
override {Q_UNUSED( chunkTrace )}
462 QVector<float> mTimeField;
463 QVector<float> mMagnitudeField;
478 QVector<char> mDirectionField;
479 QList<QgsMeshTraceParticle> mParticles;
482 double mTimeStep = 200;
483 double mParticlesLifeTime = 5000;
484 int mParticlesCount = 1000;
485 double mTailFactor = 5;
486 int mMinTailLength = 3;
487 QColor mParticleColor = Qt::white;
488 double mParticleSize = 2.5;
489 int mStumpFactor = 50;
490 bool mStumpParticleWithLifeTime =
true;
503 class QgsMeshVectorStreamlineRenderer:
public QgsMeshVectorRenderer
510 bool dataIsOnVertices,
516 void draw()
override;
519 std::unique_ptr<QgsMeshStreamField> mStreamlineField;
534 class QgsMeshVectorTraceRenderer:
public QgsMeshVectorRenderer
541 bool dataIsOnVertices,
547 void draw()
override;
550 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
573 bool dataIsOnVertices,
589 void seedRandomParticles(
int count );
592 QImage imageRendered();
595 void setFPS(
int FPS );
598 void setMaxSpeedPixel(
int max );
601 void setParticlesLifeTime(
double particleLifeTime );
604 void setParticlesColor(
const QColor &
c );
607 void setParticlesSize(
double width );
610 void setTailFactor(
double fct );
613 void setMinimumTailLength(
int l );
616 void setTailPersitence(
double p );
621 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
625 double mParticleLifeTime = 5;
627 void updateFieldParameter();
630 #endif // QGSMESHTRACERENDERER_H