VAPOR3 3.9.4
RenderParams.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2004 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************/
8//
9// File: RenderParams.h
10//
11// Author: Alan Norton
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: July 2014
16//
17// Description: Defines the RendererParams class.
18// This is an abstract class for all the tabbed panel render params classes.
19// Supports functionality common to all the tabbed panel render params.
20
21//
22#ifndef RENDERPARAMS_H
23#define RENDERPARAMS_H
24
25#include <map>
26#include <vapor/common.h>
27#include <vapor/ParamsBase.h>
29#include <vapor/Box.h>
30#include <vapor/ColorbarPbase.h>
31#include <vapor/Transform.h>
32#include <vapor/DataMgr.h>
33
34namespace VAPoR {
35
44public:
47 RenderParams(DataMgr *dataMgr, ParamsBase::StateSave *ssave, const string &classname, int maxdim = 3);
48
49 RenderParams(DataMgr *dataMgr, ParamsBase::StateSave *ssave, XmlNode *node, int maxdim = 3);
50
52
54
55 virtual ~RenderParams();
56
70 //
71 virtual int Initialize();
72
73 int ResetUserExtentsToDataExents(string var="");
74
80 virtual bool IsEnabled() const { return ((bool)GetValueLong(_EnabledTag, (int)false)); }
81
91 virtual void SetEnabled(bool val);
92
97 virtual void SetVariableName(string varName);
98
102 string GetVariableName() const;
103
109 virtual void SetAuxVariableNames(vector<string> varName);
110
116 vector<string> GetAuxVariableNames() const;
117
120 bool UseAuxVariable() const
121 {
122 vector<string> names = GetAuxVariableNames();
123 for (int i = 0; i < names.size(); i++) {
124 if (GetVariableName() == names[i]) return true;
125 }
126 return false;
127 }
128
137 //
138 string GetFirstVariableName() const;
139
145 //
146 virtual void SetFieldVariableNames(vector<string> varNames);
147
150 //
151 void SetXFieldVariableName(std::string varName);
152
155 //
156 void SetYFieldVariableName(std::string varName);
157
160 //
161 void SetZFieldVariableName(std::string varName);
162
166 vector<string> GetFieldVariableNames() const;
167
170 //
171 std::string GetXFieldVariableName() const;
172
175 //
176 std::string GetYFieldVariableName() const;
177
180 //
181 std::string GetZFieldVariableName() const;
182
185 vector<string> GetDistribVariableNames() const { return (GetValueStringVec(_distribVariableNamesTag)); }
186
190 virtual void SetRefinementLevel(int numrefinements);
191
195 virtual int GetRefinementLevel() const;
196
200 virtual int GetCompressionLevel() const;
201
205 virtual void SetCompressionLevel(int val);
206
214 void SetHistoStretch(float factor);
215
221 float GetHistoStretch() const;
222
224 virtual ColorbarPbase *GetColorbarPbase() const { return _Colorbar; }
225
232
237 //
238 virtual MapperFunction *GetMapperFunc(string varname);
239
241 //
242 virtual void RemoveMapperFunc(string varname);
243
248 //
249 virtual void SetMapperFunc(string varname, MapperFunction *tf);
250
256 //
257 virtual Box *GetBox() const { return (_Box); }
258
261 void SetCursorCoords(const float coords[2]);
262
265 void GetCursorCoords(float coords[2]) const;
266
273 virtual void SetHeightVariableName(string varname);
274
277 virtual string GetHeightVariableName() const;
278
281 bool UseSingleColor() const;
282
287 //
288 virtual void SetColorMapVariableName(string varname);
289
293 virtual string GetColorMapVariableName() const;
294
299 virtual string GetActualColorMapVariableName() const = 0;
300
303 void SetUseSingleColor(bool val);
304
314 //
315 void SetConstantColor(const float rgb[3]);
316 void SetConstantColor(vector<float> rgb);
317
323 //
324 void GetConstantColor(float rgb[3]) const;
325
326 vector<float> GetConstantColor() const
327 {
328 float rgb[3];
329 GetConstantColor(rgb);
330 vector<float> v = {rgb[0], rgb[1], rgb[2]};
331 return (v);
332 }
333
339 void SetConstantOpacity(float o);
340
346 //
347 float GetConstantOpacity() const;
348
351 //
352 size_t GetCurrentTimestep() const { return (size_t)GetValueLong(_currentTimestepTag, 0); }
353
356 //
357 void SetCurrentTimestep(size_t ts) { SetValueLong(_currentTimestepTag, "Set timestep", (long)ts); }
358
360 //
361 virtual Transform *GetTransform() const { return _transform; }
362
364
368 virtual void SetDefaultVariables(int dim, bool secondaryColormapVariable);
369
380 virtual size_t GetRenderDim() const = 0;
381
383 virtual bool HasIsoValues() const { return false; }
384 virtual vector<double> GetIsoValues(const string &variable)
385 {
386 VAssert(0);
387 return {};
388 }
389 virtual void SetIsoValues(const string &variable, const vector<double> &values) { VAssert(0); }
390
391 vector<double> GetIsoValues() { return GetIsoValues(GetVariableName()); }
392 void SetIsoValues(const vector<double> &values) { SetIsoValues(GetVariableName(), values); }
393
395 virtual bool GetOrientable() const;
396
400 vector<double> GetSlicePlaneRotation() const;
401
405 vector<double> GetSlicePlaneOrigin() const;
406
410 vector<double> GetSlicePlaneNormal() const;
411
415 double GetXSlicePlaneOrigin() const;
416
420 double GetYSlicePlaneOrigin() const;
421
425 double GetZSlicePlaneOrigin() const;
426
430 void SetXSlicePlaneOrigin(double xOrigin);
431
435 void SetYSlicePlaneOrigin(double yOrigin);
436
440 void SetZSlicePlaneOrigin(double zOrigin);
441
444 void SetSlicePlaneQuad(const std::vector<CoordType> &quad) { _slicePlaneQuad = quad; }
445
448 std::vector<CoordType> GetSlicePlaneQuad() const { return _slicePlaneQuad; }
449
450protected:
453
454 bool InitBoxFromVariable(size_t ts, string varName);
455
456 virtual bool GetUseSingleColorDefault() const { return false; }
457
458private:
459 void _init();
460 void _calculateStride(string varName);
461 int _stride;
462 ParamsContainer * _TFs;
463 Box * _Box;
464 ColorbarPbase * _Colorbar;
465 Transform * _transform;
466 bool _classInitialized; //
467 std::vector<CoordType> _slicePlaneQuad;
468
469 static const string _EnabledTag;
470 static const string _histoScaleTag;
471 static const string _editBoundsTag;
472 static const string _histoBoundsTag;
473 static const string _cursorCoordsTag;
474 static const string _terrainMapTag;
475 static const string _auxVariableNamesTag;
476 static const string _distribVariableNamesTag;
477 static const string _transferFunctionsTag;
478 static const string _stretchFactorsTag;
479 static const string _currentTimestepTag;
480
481 string _findVarStartingWithLetter(std::vector<string> searchVars, char letter);
482 string _findVarEndingWithLetter(std::vector<string> searchVars, char letter);
483
484public:
485 static const string _variableNameTag;
486 static const string _colorMapVariableNameTag;
487 static const string _heightVariableNameTag;
488 static const string _useSingleColorTag;
489 static const string _constantColorTag;
490 static const string _CompressionLevelTag;
491 static const string _RefinementLevelTag;
492 // static const string _fieldVariableNamesTag;
493 static const string _xFieldVariableNameTag;
494 static const string _yFieldVariableNameTag;
495 static const string _zFieldVariableNameTag;
496 static const string _constantOpacityTag;
497 static const string CustomHistogramDataTag;
498 static const string CustomHistogramRangeTag;
499 static const string LightingEnabledTag;
500 static const string UserNameTag;
501
508 static const string XSlicePlaneOriginTag;
509
516 static const string YSlicePlaneOriginTag;
517
524 static const string ZSlicePlaneOriginTag;
525
532 static const string XSlicePlaneRotationTag;
533
540 static const string YSlicePlaneRotationTag;
541
548 static const string ZSlicePlaneRotationTag;
549
556 static const string SampleRateTag;
557
563 static const string SliceOffsetTag;
564
571 static const string SlicePlaneNormalXTag;
572
579 static const string SlicePlaneNormalYTag;
580
587 static const string SlicePlaneNormalZTag;
588
595 static const string SlicePlaneOrientationModeTag;
596
598 Rotation = 0,
599 Normal = 1,
600 };
601};
602
604//
605// RenParamsFactory Class
606//
608
610public:
612 {
613 static RenParamsFactory instance;
614 return &instance;
615 }
616
617 void RegisterFactoryFunction(string name, function<RenderParams *(DataMgr *, ParamsBase::StateSave *, XmlNode *)> classFactoryFunction)
618 {
619 // register the class factory function
620 _factoryFunctionRegistry[name] = classFactoryFunction;
621 }
622
624
625 vector<string> GetFactoryNames() const;
626
627private:
628 map<string, function<RenderParams *(DataMgr *, ParamsBase::StateSave *, XmlNode *)>> _factoryFunctionRegistry;
629
632 RenParamsFactory &operator=(const RenParamsFactory &) { return *this; }
633};
634
636//
637// RenParamsRegistrar Class
638//
639// Register RenParamsBase derived class with:
640//
641// static RenParamsRegistrar<RenParamsClass> registrar("myclassname");
642//
643// where 'RenParamsClass' is a class derived from 'RenderParams', and
644// "myclassname" is the name of the class
645//
647
648template<class T> class RenParamsRegistrar {
649public:
650 RenParamsRegistrar(string classType)
651 {
652 // register the class factory function
653 //
655 if (node)
656 return new T(dataMgr, ssave, node);
657 else
658 return new T(dataMgr, ssave);
659 });
660 }
661};
662
664//
665// RenParamsContainer Class
666//
668
669//
670// The RenParamsContainer class constructs an XML tree as depicted below,
671// where 'Container Name' is the root of XML tree, and is the name
672// passed into the constructor as 'myname'; 'Class Name' is the name of
673// the derived RenParamBase class used to construct new instances of
674// the derived class; and 'ele name x' is the unique name of the element
675// contained in the container.
676//
677/*
678 |----------------|
679 | Container Name |
680 |----------------|
681 |
682 \|/
683 |----------------|
684 | Class Name |
685 |----------------|
686 | \
687 \|/ \
688 |----------------| \ |----------------|
689 | ele name 1 |....| ele name n |
690 |----------------| |----------------|
691*/
693public:
694 RenParamsContainer(DataMgr *dataMgr, ParamsBase::StateSave *ssave, const string &myname);
695
697
700
702
704
705 RenderParams *Insert(const RenderParams *rp, string name);
706
707 RenderParams *Create(string classType, string name);
708
709 void Remove(string name);
710
711 RenderParams *GetParams(string name) const;
712
713 vector<string> GetNames() const;
714
715 size_t Size() const { return (_elements.size()); }
716
717 XmlNode *GetNode() const { return _separator->GetNode(); }
718
719 ParamsSeparator *GetSeparator() const { return _separator; }
720
721 string const GetName() const { return (_separator->GetName()); }
722
723private:
724 DataMgr * _dataMgr;
725 ParamsBase::StateSave * _ssave;
726 ParamsSeparator * _separator;
727 map<string, RenderParams *> _elements;
728};
729
730}; // End namespace VAPoR
731#endif // RENDERPARAMS_H
#define VAssert(expr)
Definition: VAssert.h:9
3D or 2D box with options for orientation angles .
Definition: Box.h:39
Settings for color bar displayed in scene Intended to be used in any Params class.
Definition: ColorbarPbase.h:40
A cache based data reader.
Definition: DataMgr.h:110
Parent class for TransferFunction and IsoControl, supports positioning histogram over color/opacity m...
State capture class.
Definition: ParamsBase.h:62
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:50
RenderParams * Create(string classType, string name)
ParamsSeparator * GetSeparator() const
Definition: RenderParams.h:719
RenderParams * GetParams(string name) const
RenderParams * Insert(const RenderParams *rp, string name)
vector< string > GetNames() const
void Remove(string name)
RenParamsContainer(DataMgr *dataMgr, ParamsBase::StateSave *ssave, const string &myname)
RenParamsContainer(DataMgr *dataMgr, ParamsBase::StateSave *ssave, XmlNode *node)
RenParamsContainer & operator=(const RenParamsContainer &rhs)
RenParamsContainer(const RenParamsContainer &rhs)
Copy constructor.
string const GetName() const
Definition: RenderParams.h:721
XmlNode * GetNode() const
Definition: RenderParams.h:717
vector< string > GetFactoryNames() const
static RenParamsFactory * Instance()
Definition: RenderParams.h:611
RenderParams * CreateInstance(string classType, DataMgr *, ParamsBase::StateSave *, XmlNode *))
void RegisterFactoryFunction(string name, function< RenderParams *(DataMgr *, ParamsBase::StateSave *, XmlNode *)> classFactoryFunction)
Definition: RenderParams.h:617
RenParamsRegistrar(string classType)
Definition: RenderParams.h:650
A Params subclass for managing parameters used by Renderers.
Definition: RenderParams.h:43
static const string _useSingleColorTag
Definition: RenderParams.h:488
void SetConstantOpacity(float o)
bool UseAuxVariable() const
Definition: RenderParams.h:120
std::vector< CoordType > GetSlicePlaneQuad() const
Definition: RenderParams.h:448
static const string LightingEnabledTag
Definition: RenderParams.h:499
vector< double > GetSlicePlaneRotation() const
string GetVariableName() const
std::string GetZFieldVariableName() const
static const string _xFieldVariableNameTag
Definition: RenderParams.h:493
std::string GetYFieldVariableName() const
static const string _heightVariableNameTag
Definition: RenderParams.h:487
static const string YSlicePlaneOriginTag
Definition: RenderParams.h:516
void SetIsoValues(const vector< double > &values)
Definition: RenderParams.h:392
RenderParams(DataMgr *dataMgr, ParamsBase::StateSave *ssave, const string &classname, int maxdim=3)
static const string _CompressionLevelTag
Definition: RenderParams.h:490
virtual bool GetUseSingleColorDefault() const
Definition: RenderParams.h:456
vector< float > GetConstantColor() const
Definition: RenderParams.h:326
static const string _constantOpacityTag
Definition: RenderParams.h:496
static const string _RefinementLevelTag
Definition: RenderParams.h:491
void SetZSlicePlaneOrigin(double zOrigin)
bool UseSingleColor() const
string GetFirstVariableName() const
void SetConstantColor(const float rgb[3])
static const string SlicePlaneNormalXTag
Definition: RenderParams.h:571
virtual void SetColorbarPbase(ColorbarPbase *pb)
void SetXFieldVariableName(std::string varName)
virtual void SetColorMapVariableName(string varname)
virtual void SetCompressionLevel(int val)
RenderParams & operator=(const RenderParams &rhs)
RenderParams(DataMgr *dataMgr, ParamsBase::StateSave *ssave, XmlNode *node, int maxdim=3)
virtual void SetVariableName(string varName)
static const string UserNameTag
Definition: RenderParams.h:500
virtual int GetRefinementLevel() const
void initializeBypassFlags()
size_t GetCurrentTimestep() const
Definition: RenderParams.h:352
virtual void SetDefaultVariables(int dim, bool secondaryColormapVariable)
virtual vector< double > GetIsoValues(const string &variable)
Definition: RenderParams.h:384
void SetConstantColor(vector< float > rgb)
virtual MapperFunction * GetMapperFunc(string varname)
virtual bool IsEnabled() const
Definition: RenderParams.h:80
virtual string GetHeightVariableName() const
static const string _colorMapVariableNameTag
Definition: RenderParams.h:486
virtual void SetRefinementLevel(int numrefinements)
virtual bool HasIsoValues() const
This should be overriden by params for renderes that support iso values to return true.
Definition: RenderParams.h:383
double GetYSlicePlaneOrigin() const
static const string YSlicePlaneRotationTag
Definition: RenderParams.h:540
virtual void SetEnabled(bool val)
static const string XSlicePlaneRotationTag
Definition: RenderParams.h:532
vector< double > GetSlicePlaneNormal() const
void SetSlicePlaneQuad(const std::vector< CoordType > &quad)
Definition: RenderParams.h:444
virtual void SetIsoValues(const string &variable, const vector< double > &values)
Definition: RenderParams.h:389
void GetCursorCoords(float coords[2]) const
static const string CustomHistogramDataTag
Definition: RenderParams.h:497
vector< double > GetIsoValues()
Definition: RenderParams.h:391
static const string SlicePlaneOrientationModeTag
Definition: RenderParams.h:595
void SetUseSingleColor(bool val)
virtual Transform * GetTransform() const
Access the transform used by the renderer.
Definition: RenderParams.h:361
void GetConstantColor(float rgb[3]) const
virtual int GetCompressionLevel() const
vector< string > GetAuxVariableNames() const
virtual void SetHeightVariableName(string varname)
static const string _yFieldVariableNameTag
Definition: RenderParams.h:494
virtual void RemoveMapperFunc(string varname)
Remove the mapper function for the named variable.
bool InitBoxFromVariable(size_t ts, string varName)
std::string GetXFieldVariableName() const
static const string _zFieldVariableNameTag
Definition: RenderParams.h:495
virtual void SetMapperFunc(string varname, MapperFunction *tf)
float GetHistoStretch() const
void SetYFieldVariableName(std::string varName)
float GetConstantOpacity() const
static const string SlicePlaneNormalYTag
Definition: RenderParams.h:579
static const string ZSlicePlaneRotationTag
Definition: RenderParams.h:548
virtual int Initialize()
virtual void SetAuxVariableNames(vector< string > varName)
virtual ~RenderParams()
void SetYSlicePlaneOrigin(double yOrigin)
static const string _variableNameTag
Definition: RenderParams.h:485
static const string SampleRateTag
Definition: RenderParams.h:556
int ResetUserExtentsToDataExents(string var="")
static const string SliceOffsetTag
Definition: RenderParams.h:563
vector< string > GetDistribVariableNames() const
Definition: RenderParams.h:185
static const string XSlicePlaneOriginTag
Definition: RenderParams.h:508
void SetXSlicePlaneOrigin(double xOrigin)
void SetHistoStretch(float factor)
virtual Box * GetBox() const
Definition: RenderParams.h:257
void SetZFieldVariableName(std::string varName)
double GetXSlicePlaneOrigin() const
virtual bool GetOrientable() const
Return whether a renderer can be oriented - IE, can this renderer be rotated about an origin point?
static const string SlicePlaneNormalZTag
Definition: RenderParams.h:587
static const string CustomHistogramRangeTag
Definition: RenderParams.h:498
vector< string > GetFieldVariableNames() const
virtual string GetColorMapVariableName() const
static const string ZSlicePlaneOriginTag
Definition: RenderParams.h:524
double GetZSlicePlaneOrigin() const
virtual size_t GetRenderDim() const =0
virtual string GetActualColorMapVariableName() const =0
void SetCursorCoords(const float coords[2])
void SetCurrentTimestep(size_t ts)
Definition: RenderParams.h:357
vector< double > GetSlicePlaneOrigin() const
virtual ColorbarPbase * GetColorbarPbase() const
Obtain ColorbarPBase (used to specify Color Bar properties) from RenderParams.
Definition: RenderParams.h:224
RenderParams(const RenderParams &rhs)
virtual void SetFieldVariableNames(vector< string > varNames)
static const string _constantColorTag
Definition: RenderParams.h:489
class that indicates location and direction of view
Definition: Transform.h:22
An Xml tree.
Definition: XmlNode.h:49
virtual XmlNode * GetNode(std::vector< string > path, bool absolute) const
Wasp base class.
Definition: MyBase.h:67
#define PARAMS_API
Definition: common.h:77