VAPOR3 3.9.4
Renderer.h
Go to the documentation of this file.
1
2//************************************************************************
3// *
4// Copyright (C) 2004 *
5// University Corporation for Atmospheric Research *
6// All Rights Reserved *
7// *
8//************************************************************************/
9// File: Renderer.h
10//
11// Author: Alan Norton
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: September 2004
16//
17// Description: Defines the Renderer class.
18// A pure virtual class that is implemented for each renderer.
19// Methods are called by the visualizer class as needed.
20//
21
22#ifndef RENDERER_H
23#define RENDERER_H
24
25#include <vapor/MyBase.h>
26#include <vapor/ParamsMgr.h>
27#include <vapor/RenderParams.h>
28
29namespace VAPoR {
30
31class ShaderProgram;
32struct GLManager;
33
48public:
49 RendererBase(const ParamsMgr *pm, string winName, string dataSetName, string paramsType, string classType, string instName, DataMgr *dataMgr);
50 virtual ~RendererBase();
55 virtual int initializeGL(GLManager *glManager);
56
58 string GetVisualizer() { return _winName; }
59
62 string GetMyName() const { return (_instName); };
63 string GetInstanceName() const { return GetMyName(); }
64
67 string GetMyType() const { return (_classType); };
68
71 string GetMyParamsType() const { return (_paramsType); };
72
75 string GetMyDatasetName() const { return (_dataSetName); };
76
80 bool IsGLInitialized() const { return (_glInitialized); }
81
82protected:
84 string _winName;
87 string _classType;
88 string _instName;
90
92
96 virtual int _initializeGL() = 0;
97
98public:
103
105
106private:
107 bool _glInitialized;
108 bool _flaggedForDeletion;
109};
110
122public:
126 //
127 Renderer(const ParamsMgr *pm, string winName, string dataSetName, string paramsType, string classType, string instName, DataMgr *dataMgr);
128
129 virtual ~Renderer();
130
135 double GetDefaultZ(DataMgr *dataMgr, size_t ts) const;
136
141 virtual int paintGL(bool fast);
142
146 //
147 void ClearCache() { _clearCache(); };
148
149#ifdef VAPOR3_0_0_ALPHA
150#endif
151
152#ifdef VAPOR3_0_0_ALPHA
156 void setBypass(int timestep)
157 {
158 if (_currentRenderParams) _currentRenderParams->setBypass(timestep);
159 }
160
165 void setPartialBypass(int timestep)
166 {
167 if (_currentRenderParams) _currentRenderParams->setPartialBypass(timestep);
168 }
169
174 void setAllBypass(bool val)
175 {
176 if (_currentRenderParams) _currentRenderParams->setAllBypass(val);
177 }
178
182 bool doBypass(int timestep) { return (_currentRenderParams && _currentRenderParams->doBypass(timestep)); }
183
188 bool doAlwaysBypass(int timestep) { return (_currentRenderParams && _currentRenderParams->doAlwaysBypass(timestep)); }
189
194 virtual void setAllDataDirty() { return; }
195#endif
196
197#ifdef VAPOR3_0_0_ALPHA
200 static void SetControlExec(ControlExec *ce) { _controlExec = ce; }
201
206
218 static void UndoRedo(bool isUndo, int instance, Params *beforeP, Params *afterP, Params *auxPrev = 0, Params *auxNext = 0);
219
220#endif
221
222#ifdef VAPOR3_0_0_ALPHA
231 void buildLocal2DTransform(int dataOrientation, float a[2], float b[2], float *constVal, int mappedDims[3]);
232#endif
233
234#ifdef VAPOR3_0_0_ALPHA
235
239 void getLocalContainingRegion(float regMin[3], float regMax[3]);
240#endif
241
244
246
249 RenderParams *GetActiveParams() const { return (_paramsMgr->GetRenderParams(_winName, _dataSetName, _paramsType, _instName)); }
250
251 ViewpointParams *GetViewpointParams() const { return _paramsMgr->GetViewpointParams(_winName); }
252
253 AnnotationParams *GetAnnotationParams() const { return _paramsMgr->GetAnnotationParams(_winName); }
254
255 Transform *GetDatasetTransform() const { return GetViewpointParams()->GetTransform(_dataSetName); }
256
257 static void ApplyTransform(GLManager *gl, const Transform *dataset, const Transform *renderer);
258
259 static void ApplyDatasetTransform(GLManager *gl, const Transform *dataset);
260
261protected:
263
264 virtual std::string _getColorbarVariableName() const;
265
267 virtual int _paintGL(bool fast) = 0;
268
281 void EnableClipToBox(ShaderProgram *shader, float haloFrac = 0.0) const;
282
286 //
288
292 void GetClippingPlanes(float planes[24]) const;
293
297 //
298 virtual bool VariableExists(size_t ts, std::vector<string> &varnames, int level, int lod, bool zeroOK) const;
299
300 virtual void _clearCache() = 0;
301
302 static const int _imgHgt;
303 static const int _imgWid;
304 unsigned char * _colorbarTexture;
305 string _fontName;
306
307private:
308 size_t _timestep;
309
310#ifdef VAPOR3_0_0_ALPHA
311 static ControlExec *_controlExec;
312#endif
313};
314
316//
317// RendererFactory Class
318//
320
322public:
324
325 void RegisterFactoryFunction(string myName, string myParamsName, function<Renderer *(const ParamsMgr *, string, string, string, string, DataMgr *)> classFactoryFunction);
326
327 Renderer *(CreateInstance(const ParamsMgr *pm, string winName, string dataSetName, string classType, string instName, DataMgr *dataMgr));
328
329 string GetRenderClassFromParamsClass(string paramsClass) const;
330 string GetParamsClassFromRenderClass(string renderClass) const;
331 std::vector<string> GetFactoryNames() const;
332
333private:
334 map<string, function<Renderer *(const ParamsMgr *, string, string, string, string, DataMgr *)>> _factoryFunctionRegistry;
335 map<string, string> _factoryMapRegistry;
336
339 RendererFactory &operator=(const RendererFactory &);
340};
341
343//
344// RendererRegistrar Class
345//
346// Register RendererBase derived class with:
347//
348// static RendererRegistrar<RendererClass>
349// registrar("myclassname", "myparamsclassname");
350//
351// where 'RendererClass' is a class derived from 'Renderer', and
352// "myclassname" is the name of the class
353//
355
356template<class T> class RENDER_API RendererRegistrar {
357public:
358 RendererRegistrar(string classType, string paramsClassType)
359 {
360 // register the class factory function
361 //
362 RendererFactory::Instance()->RegisterFactoryFunction(classType, paramsClassType,
363 [](const ParamsMgr *pm, string winName, string dataSetName, string classType, string instName, DataMgr *dataMgr) -> Renderer * {
364 return new T(pm, winName, dataSetName, instName, dataMgr);
365 });
366 }
367};
368
369}; // namespace VAPoR
370
371#endif // RENDERER_H
A class for describing visual features displayed in the visualizer.
Provides API for VAPOR visualizer User Interfaces (UIs)
A cache based data reader.
Definition: DataMgr.h:110
A singleton class for managing Params instances.
Definition: ParamsMgr.h:53
A Params subclass for managing parameters used by Renderers.
Definition: RenderParams.h:43
A base class for Renderer classes.
Definition: Renderer.h:47
GLManager * _glManager
Definition: Renderer.h:91
virtual int _initializeGL()=0
string GetMyName() const
Definition: Renderer.h:62
virtual ~RendererBase()
RendererBase(const ParamsMgr *pm, string winName, string dataSetName, string paramsType, string classType, string instName, DataMgr *dataMgr)
string GetMyDatasetName() const
Definition: Renderer.h:75
string GetMyType() const
Definition: Renderer.h:67
string _paramsType
Definition: Renderer.h:86
string GetInstanceName() const
Definition: Renderer.h:63
DataMgr * _dataMgr
Definition: Renderer.h:89
string GetVisualizer()
Obtain the Visualizer associated with this Renderer.
Definition: Renderer.h:58
bool IsFlaggedForDeletion() const
bool IsGLInitialized() const
Definition: Renderer.h:80
string GetMyParamsType() const
Definition: Renderer.h:71
virtual int initializeGL(GLManager *glManager)
string _dataSetName
Definition: Renderer.h:85
const ParamsMgr * _paramsMgr
Definition: Renderer.h:83
Renderer * CreateInstance(const ParamsMgr *pm, string winName, string dataSetName, string classType, string instName, DataMgr *dataMgr))
string GetParamsClassFromRenderClass(string renderClass) const
std::vector< string > GetFactoryNames() const
static RendererFactory * Instance()
void RegisterFactoryFunction(string myName, string myParamsName, function< Renderer *(const ParamsMgr *, string, string, string, string, DataMgr *)> classFactoryFunction)
string GetRenderClassFromParamsClass(string paramsClass) const
RendererRegistrar(string classType, string paramsClassType)
Definition: Renderer.h:358
A class that performs rendering in a Visualizer.
Definition: Renderer.h:121
virtual int _paintGL(bool fast)=0
All OpenGL rendering is performed in the pure virtual paintGL method.
AnnotationParams * GetAnnotationParams() const
Definition: Renderer.h:253
ViewpointParams * GetViewpointParams() const
Definition: Renderer.h:251
static const int _imgHgt
Definition: Renderer.h:302
virtual void _clearCache()=0
RenderParams * GetActiveParams() const
Definition: Renderer.h:249
virtual bool VariableExists(size_t ts, std::vector< string > &varnames, int level, int lod, bool zeroOK) const
static void ApplyTransform(GLManager *gl, const Transform *dataset, const Transform *renderer)
void renderColorbar()
Render the colorbar for this renderer (if it has one)
void GetClippingPlanes(float planes[24]) const
Renderer(const ParamsMgr *pm, string winName, string dataSetName, string paramsType, string classType, string instName, DataMgr *dataMgr)
string _fontName
Definition: Renderer.h:305
unsigned char * _colorbarTexture
Definition: Renderer.h:304
Transform * GetDatasetTransform() const
Definition: Renderer.h:255
double GetDefaultZ(DataMgr *dataMgr, size_t ts) const
void DisableClippingPlanes()
virtual std::string _getColorbarVariableName() const
virtual int paintGL(bool fast)
static const int _imgWid
Definition: Renderer.h:303
static void ApplyDatasetTransform(GLManager *gl, const Transform *dataset)
void ClearCache()
Definition: Renderer.h:147
virtual ~Renderer()
void EnableClipToBox(ShaderProgram *shader, float haloFrac=0.0) const
Provides a C++ interface to the OpenGL shader program construct.
Definition: ShaderProgram.h:25
class that indicates location and direction of view
Definition: Transform.h:22
A class for describing the viewpoint and lights in a 3D VAPOR scene.
Wasp base class.
Definition: MyBase.h:67
#define RENDER_API
Definition: common.h:78
Contains references to context scope OpenGL data.
Definition: GLManager.h:18