1 /**********************************************************************
2 zyGrib: meteorological GRIB file viewer
3 Copyright (C) 2008 - Jacques Zaninetti - http://www.zygrib.org
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 ***********************************************************************/
18 
19 /*************************************
20 Dessin des données GRIB (avec QT)
21 *************************************/
22 
23 #ifndef ISOLINE_H
24 #define ISOLINE_H
25 
26 #include <iostream>
27 #include <cmath>
28 #include <vector>
29 #include <list>
30 #include <set>
31 
32 #include "../../../include/ocpn_plugin.h"
33 
34 #include "GribReader.h"
35 
36 class ViewPort;
37 class wxDC;
38 
39 class Segment;
40 WX_DECLARE_LIST(Segment, MySegList);
41 WX_DECLARE_LIST(MySegList, MySegListList);
42 
43 
44 //-------------------------------------------------------------------------------------------------------
45 //  Cohen & Sutherland Line clipping algorithms
46 //-------------------------------------------------------------------------------------------------------
47 /*
48  *
49  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
50  *
51  * Authors: Percy Zahl <zahl@users.sf.net>
52  * additional features: Andreas Klust <klust@users.sf.net>
53  * WWW Home: http://gxsm.sf.net
54  *
55  */
56 
57 typedef enum { Visible, Invisible } ClipResult;
58 typedef enum {
59       LEFT, RIGHT, BOTTOM, TOP
60 } edge;
61 typedef long outcode;
62 
63 
64 void CompOutCode (double x, double y, outcode *code, struct LOC_cohen_sutherland_line_clip *LINK);
65 #ifdef __cplusplus
66 ClipResult cohen_sutherland_line_clip_d (double *x0, double *y0, double *x1, double *y1,
67                                                      double xmin_, double xmax_, double ymin_, double ymax_);
68 
69 extern "C"  ClipResult cohen_sutherland_line_clip_i (int *x0, int *y0, int *x1, int *y1,
70                                                      int xmin_, int xmax_, int ymin_, int ymax_);
71 
72 #endif
73 
74 
75 // TODO: join segments and draw a spline
76 
77 //===============================================================
78 // Elément d'isobare qui passe dans un carré (ab-cd)de la grille.
79 // a  b
80 // c  d
81 // Rejoint l'arête (i,j)-(k,l) à l'arête (m,n)-(o,p) (indices ds la grille GRIB)
82 
83 class Segment
84 {
85     public:
86         Segment (int I, int w, int J,
87                 char c1, char c2, char c3, char c4,
88                 const GribRecord *rec, double pressure);
89 
90         int   i,j,  k,l;   // arête 1
91         double px1,  py1;   // Coordonées de l'intersection (i,j)-(k,l)
92         int m,n, o,p;      // arête 2
93         double px2,  py2;   // Coordonées de l'intersection (m,n)-(o,p)
94         bool  bUsed;
95 
96     private:
97         void traduitCode(int I, int w, int J, char c1, int &i, int &j);
98 
99         void intersectionAreteGrille(int i,int j, int k,int l,
100                 double *x, double *y,
101                 const GribRecord *rec, double pressure);
102 };
103 
104 class GRIBOverlayFactory;
105 class TexFont;
106 
107 //===============================================================
108 class IsoLine
109 {
110     public:
111          IsoLine(double val, double coeff, double offset, const GribRecord *rec);
112         ~IsoLine();
113 
114 
115         void drawIsoLine(GRIBOverlayFactory *pof, wxDC *dc, PlugIn_ViewPort *vp, bool bHiDef);
116 
117         void drawIsoLineLabels(GRIBOverlayFactory *pof, wxDC *dc,
118                                PlugIn_ViewPort *vp, int density, int first,
119                                wxImage &imageLabel);
120         void drawIsoLineLabelsGL(GRIBOverlayFactory *pof, PlugIn_ViewPort *vp,
121                                  int density, int first,
122                                  wxString label, wxColour &color, TexFont &texfont);
123 
getNbSegments()124         int getNbSegments()     {return trace.size();}
125 
getValue()126         double getValue() {return value;}
127     private:
128         double value;
129         int    W, H;     // taille de la grille
130         const  GribRecord *rec;
131 
132         wxColour  isoLineColor;
133         std::list<Segment *> trace;
134 
135 
136         void intersectionAreteGrille(int i,int j, int k,int l, double *x, double *y,
137                         const GribRecord *rec);
138 
139         //-----------------------------------------------------------------------
140         // Génère la liste des segments.
141         // Les coordonnées sont les indices dans la grille du GribRecord
142         //---------------------------------------------------------
143         void extractIsoLine(const GribRecord *rec);
144         MySegList *BuildContinuousSegment(void);
145 
146         MySegList       m_seglist;
147         MySegListList   m_SegListList;
148 
149         double m_pixelMM;
150 };
151 
152 
153 
154 
155 #endif
156