18#ifndef QGSMESHTRACERENDERER_H
19#define QGSMESHTRACERENDERER_H
33class QgsMeshLayerInterpolator;
34class QgsMeshLayerRendererFeedback;
48class QgsMeshVectorValueInterpolator
52 QgsMeshVectorValueInterpolator(
53 const QgsTriangularMesh &triangularMesh,
54 const QgsMeshDataBlock &datasetVectorValues );
57 QgsMeshVectorValueInterpolator(
58 const QgsTriangularMesh &triangularMesh,
59 const QgsMeshDataBlock &datasetVectorValues,
60 const QgsMeshDataBlock &scalarActiveFaceFlagValues );
62 QgsMeshVectorValueInterpolator(
const QgsMeshVectorValueInterpolator &other );
65 virtual QgsMeshVectorValueInterpolator *clone() = 0;
67 virtual ~QgsMeshVectorValueInterpolator() =
default;
73 virtual QgsVector vectorValue(
const QgsPointXY &point )
const;
76 QgsMeshVectorValueInterpolator &operator=(
const QgsMeshVectorValueInterpolator &other );
79 void updateCacheFaceIndex(
const QgsPointXY &point )
const;
81 QgsTriangularMesh mTriangularMesh;
82 QgsMeshDataBlock mDatasetValues;
83 QgsMeshDataBlock mActiveFaceFlagValues;
85 mutable int mCacheFaceIndex = -1;
86 bool mUseScalarActiveFaceFlagValues =
false;
87 bool isVectorValid(
const QgsVector &v )
const;
91 void activeFaceFilter( QgsVector &vector,
int faceIndex )
const;
93 virtual QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const = 0;
104class QgsMeshVectorValueInterpolatorFromVertex:
public QgsMeshVectorValueInterpolator
108 QgsMeshVectorValueInterpolatorFromVertex(
109 const QgsTriangularMesh &triangularMesh,
110 const QgsMeshDataBlock &datasetVectorValues );
113 QgsMeshVectorValueInterpolatorFromVertex(
114 const QgsTriangularMesh &triangularMesh,
115 const QgsMeshDataBlock &datasetVectorValues,
116 const QgsMeshDataBlock &scalarActiveFaceFlagValues );
118 QgsMeshVectorValueInterpolatorFromVertex(
const QgsMeshVectorValueInterpolatorFromVertex &other );
121 QgsMeshVectorValueInterpolatorFromVertex *clone()
override;
123 QgsMeshVectorValueInterpolatorFromVertex &operator=(
const QgsMeshVectorValueInterpolatorFromVertex &other );
126 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
137class QgsMeshVectorValueInterpolatorFromFace:
public QgsMeshVectorValueInterpolator
141 QgsMeshVectorValueInterpolatorFromFace(
142 const QgsTriangularMesh &triangularMesh,
143 const QgsMeshDataBlock &datasetVectorValues );
146 QgsMeshVectorValueInterpolatorFromFace(
147 const QgsTriangularMesh &triangularMesh,
148 const QgsMeshDataBlock &datasetVectorValues,
149 const QgsMeshDataBlock &scalarActiveFaceFlagValues );
151 QgsMeshVectorValueInterpolatorFromFace(
const QgsMeshVectorValueInterpolatorFromFace &other );
154 QgsMeshVectorValueInterpolatorFromFace *clone()
override;
156 QgsMeshVectorValueInterpolatorFromFace &operator=(
const QgsMeshVectorValueInterpolatorFromFace &other );
159 QgsVector interpolatedValuePrivate(
int faceIndex,
const QgsPointXY point )
const override;
170class QgsMeshStreamField
183 const QgsTriangularMesh &triangularMesh,
184 const QgsMeshDataBlock &dataSetVectorValues,
185 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
186 const QgsRectangle &layerExtent,
187 double magnitudeMaximum,
188 bool dataIsOnVertices,
189 const QgsRenderContext &rendererContext,
190 const QgsInterpolatedLineColor &vectorColoring,
191 int resolution = 1 );
193 QgsMeshStreamField(
const QgsMeshStreamField &other );
194 virtual ~QgsMeshStreamField();
202 void updateSize(
const QgsRenderContext &renderContext );
208 void updateSize(
const QgsRenderContext &renderContext,
int resolution );
211 bool isValid()
const;
217 QPoint topLeft()
const;
220 void addTrace( QPoint startPixel );
223 void addTrace( QgsPointXY startPoint );
226 void addRandomTraces();
229 void addRandomTrace();
232 void addGriddedTraces(
int dx,
int dy );
235 void addTracesOnMesh(
const QgsTriangularMesh &mesh,
const QgsRectangle &extent );
238 void setResolution(
int width );
241 int resolution()
const;
244 QSize imageSize()
const;
247 virtual QImage image()
const;
250 void setPixelFillingDensity(
double maxFilling );
253 void setColor( QColor color );
256 void setLineWidth(
double width );
259 void setFilter(
double min,
double max );
262 void setMinimizeFieldSize(
bool minimizeFieldSize );
265 QgsMeshStreamField &operator=(
const QgsMeshStreamField &other );
268 virtual void initImage();
269 QPointF fieldToDevice(
const QPoint &pixel )
const;
270 bool filterMag(
double value )
const;
271 bool isTraceOutside(
const QPoint &pixel )
const;
274 QgsPointXY positionToMapCoordinates(
const QPoint &pixelPosition,
const QgsPointXY &positionInPixel );
275 bool addPixelToChunkTrace( QPoint &pixel,
276 QgsMeshStreamField::FieldData &data,
277 std::list<QPair<QPoint, QgsMeshStreamField::FieldData> > &chunkTrace );
278 void setChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
279 virtual void drawTrace(
const QPoint & )
const {}
280 void clearChunkTrace( std::list<QPair<QPoint, FieldData>> &chunkTrace );
281 virtual void storeInField(
const QPair<QPoint, FieldData> pixelData ) = 0;
282 virtual void initField() = 0;
283 void simplifyChunkTrace( std::list<QPair<QPoint, FieldData>> &shunkTrace );
285 virtual bool isTraceExists(
const QPoint &pixel )
const = 0;
290 std::unique_ptr<QPainter> mPainter = std::unique_ptr<QPainter>(
nullptr );
291 int mFieldResolution = 1;
295 QgsMapToPixel mMapToFieldPixel;
296 QgsRectangle mOutputExtent = QgsRectangle();
297 QgsInterpolatedLineColor mVectorColoring;
312 QVector<unsigned char> mDirectionField;
313 QgsRenderContext mRenderContext;
316 int mPixelFillingCount = 0;
317 int mMaxPixelFillingCount = 0;
318 std::unique_ptr<QgsMeshVectorValueInterpolator> mVectorValueInterpolator;
319 QgsRectangle mLayerExtent;
320 QgsRectangle mMapExtent;
321 QPoint mFieldTopLeftInDeviceCoordinates;
323 double mMaximumMagnitude = 0;
324 double mPixelFillingDensity = 0;
325 double mMinMagFilter = -1;
326 double mMaxMagFilter = -1;
327 bool mMinimizeFieldSize =
true;
338class QgsMeshStreamlinesField:
public QgsMeshStreamField
342 Q_DECL_DEPRECATED QgsMeshStreamlinesField(
const QgsTriangularMesh &triangularMesh,
343 const QgsMeshDataBlock &datasetVectorValues,
344 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
345 const QgsRectangle &layerExtent,
347 bool dataIsOnVertices,
348 QgsRenderContext &rendererContext,
349 const QgsInterpolatedLineColor &vectorColoring );
351 QgsMeshStreamlinesField(
const QgsTriangularMesh &triangularMesh,
352 const QgsMeshDataBlock &datasetVectorValues,
353 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
354 const QVector<double> &datasetMagValues,
355 const QgsRectangle &layerExtent,
356 QgsMeshLayerRendererFeedback *feedBack,
358 bool dataIsOnVertices,
359 QgsRenderContext &rendererContext,
360 const QgsInterpolatedLineColor &vectorColoring );
365 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
366 void initField()
override;
367 void initImage()
override;
368 bool isTraceExists(
const QPoint &pixel )
const override;
369 void drawTrace(
const QPoint &start )
const override;
371 QVector<bool> mField;
372 QImage mDrawingTraceImage;
373 std::unique_ptr<QPainter> mDrawingTracePainter;
376 QgsTriangularMesh mTriangularMesh;
377 QVector<double> mMagValues;
378 QgsMeshDataBlock mScalarActiveFaceFlagValues;
380 QgsMeshLayerRendererFeedback *mFeedBack =
nullptr;
384class QgsMeshParticleTracesField;
394struct QgsMeshTraceParticle
398 std::list<QPoint> tail;
399 double remainingTime = 0;
410class QgsMeshParticleTracesField:
public QgsMeshStreamField
414 QgsMeshParticleTracesField(
const QgsTriangularMesh &triangularMesh,
415 const QgsMeshDataBlock &datasetVectorValues,
416 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
417 const QgsRectangle &layerExtent,
419 bool dataIsOnVertices,
420 const QgsRenderContext &rendererContext,
421 const QgsInterpolatedLineColor &vectorColoring );
423 QgsMeshParticleTracesField(
const QgsMeshParticleTracesField &other );
426 void addParticle(
const QPoint &startPoint,
double lifeTime );
429 void addParticleXY(
const QgsPointXY &startPoint,
double lifeTime );
432 void addRandomParticles();
435 void moveParticles();
438 QImage imageRendered()
const;
441 void setParticlesCount(
int particlesCount );
444 void setParticlesLifeTime(
double particlesLifeTime );
454 void setStumpFactor(
int sf );
457 void setTimeStep(
double timeStep );
460 void setParticleSize(
double particleSize );
463 void setTailFactor(
double tailFactor );
466 void setMinTailLength(
int minTailLength );
469 void setStumpParticleWithLifeTime(
bool stumpParticleWithLifeTime );
472 void setParticlesColor(
const QColor &
c );
474 QgsMeshParticleTracesField &operator=(
const QgsMeshParticleTracesField &other );
477 QPoint direction( QPoint position )
const;
479 float time( QPoint position )
const;
480 float magnitude( QPoint position )
const;
482 void drawParticleTrace(
const QgsMeshTraceParticle &particle );
484 void storeInField(
const QPair<QPoint, FieldData> pixelData )
override;
485 void initField()
override;
486 bool isTraceExists(
const QPoint &pixel )
const override;
495 QVector<float> mTimeField;
496 QVector<float> mMagnitudeField;
498 QList<QgsMeshTraceParticle> mParticles;
501 double mTimeStep = 200;
502 double mParticlesLifeTime = 5000;
503 int mParticlesCount = 1000;
504 double mTailFactor = 5;
505 int mMinTailLength = 3;
506 QColor mParticleColor = Qt::white;
507 double mParticleSize = 2.5;
508 int mStumpFactor = 50;
509 bool mStumpParticleWithLifeTime =
true;
522class QgsMeshVectorStreamlineRenderer:
public QgsMeshVectorRenderer
526 Q_DECL_DEPRECATED QgsMeshVectorStreamlineRenderer(
527 const QgsTriangularMesh &triangularMesh,
528 const QgsMeshDataBlock &dataSetVectorValues,
529 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
530 bool dataIsOnVertices,
531 const QgsMeshRendererVectorSettings &settings,
532 QgsRenderContext &rendererContext,
533 const QgsRectangle &layerExtent,
536 QgsMeshVectorStreamlineRenderer(
537 const QgsTriangularMesh &triangularMesh,
538 const QgsMeshDataBlock &dataSetVectorValues,
539 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
540 const QVector<double> &datasetMagValues,
541 bool dataIsOnVertices,
542 const QgsMeshRendererVectorSettings &settings,
543 QgsRenderContext &rendererContext,
544 const QgsRectangle &layerExtent,
545 QgsMeshLayerRendererFeedback *feedBack,
548 void draw()
override;
551 std::unique_ptr<QgsMeshStreamlinesField> mStreamlineField;
552 QgsRenderContext &mRendererContext;
566class QgsMeshVectorTraceRenderer:
public QgsMeshVectorRenderer
570 QgsMeshVectorTraceRenderer(
571 const QgsTriangularMesh &triangularMesh,
572 const QgsMeshDataBlock &dataSetVectorValues,
573 const QgsMeshDataBlock &scalarActiveFaceFlagValues,
574 bool dataIsOnVertices,
575 const QgsMeshRendererVectorSettings &settings,
576 QgsRenderContext &rendererContext,
577 const QgsRectangle &layerExtent,
580 void draw()
override;
583 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
584 QgsRenderContext &mRendererContext;
609 bool dataIsOnVertices,
655 std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
659 double mParticleLifeTime = 5;
661 void updateFieldParameter();
A block of integers/doubles from a mesh dataset.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Represents a renderer settings for vector datasets.
void setParticlesLifeTime(double particleLifeTime)
Sets maximum life time of particles in seconds.
QgsMeshVectorTraceAnimationGenerator & operator=(const QgsMeshVectorTraceAnimationGenerator &other)
void setMinimumTailLength(int l)
Sets the minimum tail length.
QgsMeshVectorTraceAnimationGenerator(const QgsMeshVectorTraceAnimationGenerator &other)
void setTailPersitence(double p)
Sets the visual persistence of the tail.
void setParticlesColor(const QColor &c)
Sets colors of particle.
QImage imageRendered()
Moves all the particles using frame per second (fps) to calculate the displacement and return the ren...
QgsMeshVectorTraceAnimationGenerator(QgsMeshLayer *layer, const QgsRenderContext &rendererContext)
Constructor to use with Python binding.
void setTailFactor(double fct)
Sets the tail factor, used to adjust the length of the tail. 0 : minimum length, >1 increase the tail...
~QgsMeshVectorTraceAnimationGenerator()=default
void setFPS(int FPS)
Sets the number of frames per seconds that will be rendered.
QgsMeshVectorTraceAnimationGenerator(const QgsTriangularMesh &triangularMesh, const QgsMeshDataBlock &dataSetVectorValues, const QgsMeshDataBlock &scalarActiveFaceFlagValues, bool dataIsOnVertices, const QgsRenderContext &rendererContext, const QgsRectangle &layerExtent, double magMax, const QgsMeshRendererVectorSettings &vectorSettings)
Constructor to use from QgsMeshVectorRenderer.
void setParticlesSize(double width)
Sets particle size in px.
void setMaxSpeedPixel(int max)
Sets the max number of pixels that can be go through by the particles in 1 second.
void seedRandomParticles(int count)
seeds particles in the vector fields
A rectangle specified with double values.
Contains information about the context of a rendering operation.
A triangular/derived mesh with vertices in map coordinates.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QVector< int > QgsMeshFace
List of vertex indexes.