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,
 
  621     std::unique_ptr<QgsMeshParticleTracesField> mParticleField;
 
  625     double mParticleLifeTime = 5;
 
  627     void updateFieldParameter();
 
Class defining color to render mesh datasets.
Perform transforms between map coordinates and device coordinates.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Represents a renderer settings for vector datasets.
A wrapper for QgsMeshParticuleTracesField used to render the particles.
void setParticlesLifeTime(double particleLifeTime)
Sets maximum life time of particles in seconds.
void setMinimumTailLength(int l)
Sets the minimum tail length.
QgsMeshVectorTraceAnimationGenerator(const QgsMeshVectorTraceAnimationGenerator &other)
Copy constructor.
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
Destructor.
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.
QgsMeshVectorTraceAnimationGenerator & operator=(const QgsMeshVectorTraceAnimationGenerator &other)
Assignment operator.
void seedRandomParticles(int count)
seeds particles in the vector fields
A class to represent a 2D point.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
A class to represent a vector.
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.