VAPoR  3.0.0
isolinerenderer.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2014 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: isolinerenderer.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: March 2014
16 //
17 // Description: Definition of the IsolineRenderer class
18 //
19 #ifndef ISOLINERENDERER_H
20 #define ISOLINERENDERER_H
21 
22 #include <GL/glew.h>
23 #ifdef Darwin
24 #include <OpenGL/gl.h>
25 #include <OpenGL/glu.h>
26 #else
27 #include <GL/gl.h>
28 #include <GL/glu.h>
29 #endif
30 
31 #include "assert.h"
32 #include "renderer.h"
33 #include "isolineparams.h"
34 namespace VAPoR {
35 
36 class DataMgr;
43 {
44 
45 public:
46 
48  ~IsolineRenderer();
49 
55  return new IsolineRenderer(v,rp);
56  }
58  virtual int _initializeGL();
61  virtual int _paintGL(DataMgrV3_0* dmgr);
64  virtual void setAllDataDirty() {invalidateCache();}
67  void invalidateLineCache(int timestep);
69  virtual void invalidateCache();
73  bool cacheIsValid(int timestep) {return _cacheValidFlags[timestep];}
74 
77  int buildLineCache(DataMgrV3_0* dmgr);
81  const std::map<pair<int,int>,vector<float*> >& GetLineCache() {return _lineCache;}
82 
83 private:
85  void setupCache();
88  void performRendering(size_t timestep);
99  int edgeCode(int i, int j, float isoval, float* dataVals);
100 
109  int addLineSegment(int timestep, int isoIndex, float x1, float y1, float x2, float y2);
110 
113  int numIsovalsInCache() {return _numIsovalsCached;}
114 
119  void addEdges(int segIndex, pair<int,int> edge1, pair<int,int> edge2);
122  void traverseCurves(int iso);
123 
128  vector<float*>& getLineSegments(int timestep, int isoindex){
129  pair<int,int> indexpair = make_pair(timestep,isoindex);
130  return _lineCache[indexpair];
131  }
132 
139  float interp_j(int i, int j, float isoval, float* dataVals){
140  return ( -1. + 2.*(double)(j)/((double)_gridSize-1.) //y coordinate at (i,j)
141  + 2./(double)(_gridSize -1.) //y grid spacing
142  *(isoval - dataVals[i+_gridSize*j])/(dataVals[i+_gridSize*(j+1)]-dataVals[i+_gridSize*j])); //ratio: 1 is iso at top, 0 if iso at bottom
143  }
150  float interp_i(int i, int j, float isoval, float* dataVals){
151  return (-1. + 2.*(double)(i)/((double)_gridSize-1.) //x coordinate at (i,j)
152  + 2./(double)(_gridSize -1.) //x grid spacing
153  *(isoval - dataVals[i+_gridSize*j])/(dataVals[i+1+_gridSize*(j)]-dataVals[i+_gridSize*j])); //ratio: 1 is iso at right, 0 if iso at left
154  }
159  void buildEdges(int isoval, float* dataVals, float missingVal);
163  void attachAnnotation(int numcomponents, int iso);
164 #ifndef DOXYGEN_SKIP_THIS
165 
166  //for each timestep,there is a pair consisting of the isovalue index and a vector of
167  //4 floats (x1,y1,x2,y2) specifying
168  //the two endpoints of an isoline segment that crosses a cell
169  std::map<pair<int,int>,vector<float*> > _lineCache;
170 
171  // cache valid flags indicate validity of cache at each time step.
172  std::map<int,bool> _cacheValidFlags;
173  //Each edge is represented as a pair (int, int). Horizontal edges have both ints positive; vertical have both negative.
174  //Vertical edges connecting grid vertices (i,j) and (i,j+1) are represented by the pair (-i, -j-1) (-i <=0; -j-1 < 0)
175  //Horizontal edges connecting grid vertices (i,j) and (i+1,j) are represented by the pair (i+1,j) (i+1 > 0, j>=0)
176  //
177 
178  // _lineCache maps pair<int,int>->vector<float[4]> maps a pair (timestep,isovalueIndex) to a vector of segment endpoints, with one segment for each line in the isoline
179  //For each segment in the _lineCache, there are 5 temporary mappings:
180  // prevEdge maps segments to edges. Each segment is identified by (timestep, isoval, segmentIndex), corresponding edge is pair(int,int)
181  // nextEdge is the same; map(int,int,int)->pair(int,int)
182  // plus prevSegment maps prevEdge to segment; i.e. map (timestep, isoval, (int,int))-> segmentIndex
183  // similarly nextSegment maps nextEdge to segment; i.e. map (timestep, isoval, (int,int))-> segmentIndex
184  // plus forwardEdge maps (timestep,isoval,edge)-> edge
185  // and backwardEdge maps (timestep,isoval,edge)-> edge
186 
187  std::map< pair<int,int>, int> _edgeSeg; //map an edge to a segment, to find 3d coords where edge is located
188 
189  std::map<pair<int,int>,pair<int,int> > _edgeEdge1; //map an edge to one adjacent edge;
190  std::map<pair<int,int>,pair<int,int> > _edgeEdge2; //map an edge to other adjacent edge;
191  std::map<pair<int,int>, bool> _markerBit; //indicate whether or not an edge has been visited during current traversal
192  vector<int> _componentLength; //indicates the number of segments in a component.
193  vector<pair<int,int> > _endEdge; //indicates and ending edge for each component
194 
195 
196 
197 
198 
199 
200  int _numIsovalsCached;
201  int _gridSize;
202  std::map<int,int> _objectNums;
203 #endif
204 };
205 };
206 
207 #endif // ISOLINERENDERER_H
A Params subclass for managing parameters used by Renderers.
Definition: renderparams.h:57
static Renderer * CreateInstance(Visualizer *v, RenderParams *rp)
const std::map< pair< int, int >, vector< float * > > & GetLineCache()
A class for performing OpenGL rendering in VAPOR GUI Window.
Definition: visualizer.h:61
#define RENDER_API
Definition: DC.h:10
Class that draws the isolines (contours) as specified by IsolineParams.
A cache based data reader.
Definition: DataMgrV3_0.h:100
bool cacheIsValid(int timestep)
A class that performs rendering in a Visualizer.
Definition: renderer.h:95
virtual void setAllDataDirty()