00001
00002 #ifndef STREAMLINERENDERER_H_
00003 #define STREAMLINERENDERER_H_
00004
00005 #include <queue>
00006 #include <QColor>
00007 #include <QBrush>
00008 #include <QPainter>
00009 #include "ARender.h"
00010
00011
00017 class StreamlineRenderer : public ARender {
00018 public:
00022 enum StreamlineMode {
00023 Regular,
00024 Interactive,
00025 EvenlySpaced
00026
00027 };
00031 enum Direction {
00032 Front,
00033 Back,
00034 Both
00035 };
00036
00037 StreamlineRenderer(const Data& aData);
00038
00039 virtual void render(QPixmap* pixmap);
00040
00045 void setStreamlinePen(QPen pen) { mStreamlinePen = pen; }
00046
00050 void setStreamlineMode(StreamlineMode mode) {
00051 if (mode != mMode) {
00052 mMode = mode;
00053 clearStreamlines();
00054 }
00055 }
00056
00060 void clearStreamlines() {
00061 mStreamlinePoints.clear();
00062 }
00063
00067 void addStreamLinePoint(const Vector<>& aPoint, Direction dir) {
00068 mStreamlinePoints.push_back(std::pair<Vector<>, Direction>(aPoint, dir));
00069 }
00073 void addStreamLinePoint(int x, int y, Direction dir) {
00074 QMatrix m;
00075 setupCoordSystem(m);
00076 QPointF transformed(m.inverted().map(QPointF(x, y)));
00077 addStreamLinePoint(Vector<>(transformed.x(), transformed.y()), dir);
00078 }
00079
00083 void setDT(float dt) { mDT = dt; }
00084
00088 void setDSep(float dsep) { mDSep = dsep; }
00089
00094 void setDTest(float dtest) { mDTest = dtest; }
00095
00096 protected:
00097 float mDT;
00098
00099 Vector<> v(const Vector<>& s) const { return mData.getFlow(s.x(),s.y());}
00100
00101 private:
00102 virtual Vector<> newPoint(const Vector<>& oldPoint, Direction dir) const = 0;
00103
00104 void drawStreamline(QPainter& painter, const Vector<>& point, Direction dir);
00105
00112 void streamLinePoints(const Vector<>& point, Direction dir, QVector<QPointF>& pointPairs);
00113
00118 void markSamplePoint(const QPointF& p);
00119
00124 float minDistance(const QPointF& p);
00125
00126 float minDistance(const Vector<>& v) {
00127 return minDistance(QPointF(v.x(), v.y()));
00128 }
00129
00130
00131 std::vector<QPointF> mSamplePoints;
00132
00133 std::queue< Vector<> > mPendingSeedPoints;
00134
00135 QPen mStreamlinePen;
00136 typedef std::vector< std::pair<Vector<>, Direction> > PointList;
00137 PointList mStreamlinePoints;
00138 StreamlineMode mMode;
00139
00140 float mDSep;
00141 float mDTest;
00142 };
00143
00147 class EulerRenderer : public StreamlineRenderer{
00148
00149 public:
00150 EulerRenderer(const Data& aData): StreamlineRenderer(aData){}
00151 EulerRenderer(const StreamlineRenderer& aRenderer): StreamlineRenderer(aRenderer){}
00152
00153 private:
00154 virtual Vector<> newPoint(const Vector<>& s0, Direction dir) const;
00155 };
00156
00160 class Rk2Renderer : public StreamlineRenderer{
00161 public:
00162 Rk2Renderer(const Data& aData): StreamlineRenderer(aData){}
00163 Rk2Renderer(const StreamlineRenderer& aRenderer): StreamlineRenderer(aRenderer){}
00164
00165 private:
00166 virtual Vector<> newPoint(const Vector<>& s0, Direction dir) const;
00167 };
00168
00172 class Rk4Renderer : public StreamlineRenderer{
00173 public:
00174 Rk4Renderer(const Data& aData): StreamlineRenderer(aData){}
00175 Rk4Renderer(const StreamlineRenderer& aRenderer): StreamlineRenderer(aRenderer){}
00176
00177 private:
00178 virtual Vector<> newPoint(const Vector<>& s0, Direction dir) const;
00179 };
00180
00181 #endif