00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QSCONTOUR_H
00020 #define QSCONTOUR_H
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 #include"qsaxes.h"
00026 #include"qsplot.h"
00027 #include<math.h>
00028
00029
00037 class QSContour : public QSPlot2D
00038 {
00039 Q_OBJECT
00040 Q_PROPERTY( bool contourFills READ contourFills WRITE setContourFills )
00041 Q_PROPERTY( bool contourLines READ contourLines WRITE setContourLines )
00042 Q_PROPERTY( bool contourLabels READ contourLabels WRITE setContourLabels )
00043 Q_PROPERTY( double labelSpacing READ labelSpacing WRITE setLabelSpacing )
00044
00045 public:
00049 QSContour(QSAxes* parent, const char * name=0);
00053 virtual ~QSContour();
00054
00055 void setContourFills( bool visible );
00056 void setContourLines( bool visible );
00057 void setContourLabels( bool visible );
00058 void setLabelSpacing( double labelSpacing );
00059
00060 bool contourFills() const { return m_fills; }
00061 bool contourLines() const { return m_lines; }
00062 bool contourLabels() const { return m_labels; }
00063 double labelSpacing() const { return m_label_spacing; }
00064
00065 virtual QString posInfo( QSPt2f& pos );
00066 virtual bool isClicked( const QSPt2f& pos );
00067 virtual QSPt2f legendItemSize( QSDrv *drv );
00068 virtual void drawLegendItem( const QSPt2f& pos, QSDrv *drv );
00069
00070 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00071 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00075 enum PointElement { PointMark = 0 };
00079 enum LineElement { Grid = 0 };
00080
00081 protected:
00082
00086 static const double EPS_VALUE;
00087
00088 virtual void allocRuntimeData();
00089 virtual void freeRuntimeData();
00090 virtual bool start();
00095 virtual bool prepare() { return true; }
00096 virtual bool step();
00097 virtual void end();
00101 virtual int triangles() = 0;
00111 virtual void getTriangle( int number, QSPt3f pts[3], double level = -10.0 ) = 0;
00116 virtual bool getNeighbouringTriangle( int *number, int *edge ) = 0;
00122 virtual int triangleAtPos( const QSPt2f& pos ) = 0;
00127 virtual QString vertexInfo( int t, int v, QSPt2f& pos ) = 0;
00131 virtual void drawGrid() = 0;
00135 virtual void drawPoints() = 0;
00142 virtual bool rectangleGrid() const { return false; }
00150 virtual void getRectangle( int triangleNumber, QSPt3f pts[4] ) {}
00151
00152
00153 private:
00154 bool m_labels;
00155 bool m_fills;
00156 bool m_lines;
00157 double m_label_spacing;
00158 struct contour_runtime_data;
00159 struct contour_levels_data;
00160 struct contour_runtime_data *d;
00161
00162 void init_triangle_buffer();
00163 void call_prepare();
00164 void start_drawing_fills();
00165 void drawing_fills();
00166 void start_drawing_grid();
00167 void drawing_grid();
00168 void start_drawing_lines();
00169 void drawing_lines();
00170 void start_drawing_labels();
00171 void drawing_labels();
00172 void start_drawing_points();
00173 void drawing_points();
00174
00175 void calculate_levels_data( contour_levels_data *data );
00176 void free_levels_data( contour_levels_data *data );
00177 void start_contour( const QSPt3f& p1, const QSPt3f& p2, int level );
00178 void draw_contour( const QSPt3f& p1, const QSPt3f& p2, int level );
00179 void end_contour( int level );
00180 void draw_line_buffer( int level );
00181
00182 void cut_polygon( double level, const QSPt3f *pts, int npts,
00183 QSPt3f *above_pts, int *above_npts,
00184 QSPt3f *under_pts, int *under_npts,
00185 QSPt3f *cross_line = NULL, int *cross_npts = NULL );
00186 inline double distance( const QSPt2f& p1, const QSPt2f& p2 );
00187 inline int find_level_greater_than( double value );
00188 void flush_rectangle_buffer();
00189 bool draw_rectangle( const QSPt3f pts[4] );
00190 };
00191
00192
00193 inline double QSContour::distance( const QSPt2f& p1, const QSPt2f& p2 )
00194 {
00195 return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
00196 }
00197
00198
00199
00200
00207 class QSGriddedContour : public QSContour
00208 {
00209 Q_OBJECT
00210 public:
00217 enum Channels {
00218 XVector = 0,
00219 YVector = 1,
00220 Data = 2
00221 };
00225 QSGriddedContour(QSAxes* parent, const char * name=0);
00229 virtual ~QSGriddedContour();
00230 virtual ColumnType columnType( int channel, int column ) const;
00231 virtual QString channelVariable( int channel ) const;
00232 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00233 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00234
00235 protected:
00236 virtual bool getAxisRange( QSAxis *axis, double& min, double& max );
00237 virtual void dataChanged( int channel = -1 );
00238 virtual void allocRuntimeData();
00239 virtual void freeRuntimeData();
00240 virtual int triangles();
00241 virtual void getTriangle( int number, QSPt3f pts[3], double level = -10.0 );
00242 virtual bool getNeighbouringTriangle( int *number, int *edge );
00243 virtual int triangleAtPos( const QSPt2f& pos );
00244 virtual QString vertexInfo( int t, int v, QSPt2f& pos );
00245 virtual void drawGrid();
00246 virtual void drawPoints();
00247 virtual bool rectangleGrid() const { return true; }
00248 virtual void getRectangle( int triangleNumber, QSPt3f pts[4] );
00249
00250 private:
00251 double m_dmin;
00252 double m_dmax;
00253 bool m_evalid;
00254 void calculate_data_range();
00255 double xvector( int col );
00256 double yvector( int row );
00257 struct gridded_contour_runtime_data;
00258 gridded_contour_runtime_data *d;
00259 void load_mesh_into_buffer( int triangleNumber );
00260 };
00261
00262
00263
00264
00271 class QSNonGriddedContour : public QSContour
00272 {
00273 Q_OBJECT
00274 public:
00285 enum Channels {
00286 VXCoord = 0,
00287 VYCoord = 1,
00288 VZCoord = 2,
00289 Triangles = 3
00290 };
00294 QSNonGriddedContour(QSAxes* parent, const char * name=0);
00298 virtual ~QSNonGriddedContour();
00299 virtual ColumnType columnType( int channel, int column ) const;
00300 virtual QString channelVariable( int channel ) const;
00301 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00302 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00303
00304 protected:
00305 virtual bool getAxisRange( QSAxis *axis, double& min, double& max );
00306 virtual void dataChanged( int channel = -1 );
00307 virtual bool prepare();
00308 virtual void allocRuntimeData();
00309 virtual void freeRuntimeData();
00310 virtual int triangles();
00311 virtual void getTriangle( int number, QSPt3f pts[3], double level = -10.0 );
00312 virtual bool getNeighbouringTriangle( int *number, int *edge );
00313 virtual int triangleAtPos( const QSPt2f& pos );
00314 virtual QString vertexInfo( int t, int v, QSPt2f& pos );
00315 virtual void drawGrid();
00316 virtual void drawPoints();
00317
00318 private:
00319 bool m_evalid;
00320 double m_xmax;
00321 double m_ymax;
00322 double m_zmax;
00323 double m_xmin;
00324 double m_ymin;
00325 double m_zmin;
00326 int *m_neighbours[3];
00327 struct non_gridded_contour_runtime_data;
00328 non_gridded_contour_runtime_data *d;
00329 QSPt3f point( int index );
00330 void search_for_neighbours();
00331 void make_visible_triangles_list();
00332 };
00333
00334
00335
00336 #endif
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379