1
#include <osgSim/ScalarBar>
2
#include <osgDB/ObjectWrapper>
3
#include <osgDB/InputStream>
4
#include <osgDB/OutputStream>
7
static bool checkScalarsToColors( const osgSim::ScalarBar& bar )
8
{ return bar.getScalarsToColors()!=NULL; }
10
static bool readScalarsToColors( osgDB::InputStream& is, osgSim::ScalarBar& bar )
13
is >> osgDB::BEGIN_BRACKET;
14
is >> osgDB::PROPERTY("Range") >> min >> max;
16
bool hasColorRange = false;
17
unsigned int colorSize = 0;
18
is >> osgDB::PROPERTY("Colors") >> hasColorRange >> colorSize;
21
osgSim::ScalarsToColors* stc = new osgSim::ScalarsToColors(min, max);
22
bar.setScalarsToColors( stc );
26
is >> osgDB::BEGIN_BRACKET;
27
std::vector<osg::Vec4> colors;
28
for ( unsigned int i=0; i<colorSize; ++i )
30
osg::Vec4 color; is >> color;
31
colors.push_back( color );
33
is >> osgDB::END_BRACKET;
35
osgSim::ColorRange* cr = new osgSim::ColorRange(min, max, colors);
36
bar.setScalarsToColors( cr );
41
static bool writeScalarsToColors( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
43
const osgSim::ScalarsToColors* stc = bar.getScalarsToColors();
44
os << osgDB::BEGIN_BRACKET << std::endl;
45
os << osgDB::PROPERTY("Range") << stc->getMin() << stc->getMax() << std::endl;
46
os << osgDB::PROPERTY("Colors");
48
unsigned int colorSize = 0;
49
const osgSim::ColorRange* cr = dynamic_cast<const osgSim::ColorRange*>(stc);
52
const std::vector<osg::Vec4>& colors = cr->getColors();
53
colorSize = colors.size();
55
os << true << colorSize << osgDB::BEGIN_BRACKET << std::endl;
56
for ( unsigned int i=0; i<colorSize; ++i )
58
os << colors[i] << std::endl;
60
os << osgDB::END_BRACKET << std::endl;
63
os << false << colorSize << std::endl;
64
os << osgDB::END_BRACKET << std::endl;
69
static bool checkScalarPrinter( const osgSim::ScalarBar& bar )
71
return bar.getScalarPrinter()!=NULL &&
72
dynamic_cast<const osg::Object*>(bar.getScalarPrinter());
75
static bool readScalarPrinter( osgDB::InputStream& is, osgSim::ScalarBar& bar )
77
is >> osgDB::BEGIN_BRACKET;
78
osgSim::ScalarBar::ScalarPrinter* sp =
79
dynamic_cast<osgSim::ScalarBar::ScalarPrinter*>( is.readObject() );
80
if ( sp ) bar.setScalarPrinter( sp );
81
is >> osgDB::END_BRACKET;
85
static bool writeScalarPrinter( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
87
os << osgDB::BEGIN_BRACKET << std::endl;
88
os.writeObject( dynamic_cast<const osg::Object*>(bar.getScalarPrinter()) );
89
os << osgDB::END_BRACKET << std::endl;
94
static bool checkTextProperties( const osgSim::ScalarBar& bar )
97
static bool readTextProperties( osgDB::InputStream& is, osgSim::ScalarBar& bar )
99
osgSim::ScalarBar::TextProperties prop;
101
is >> osgDB::BEGIN_BRACKET;
102
is >> osgDB::PROPERTY("Font") >> prop._fontFile;
103
is >> osgDB::PROPERTY("Resolution") >> resX >> resY;
104
is >> osgDB::PROPERTY("CharacterSize") >> prop._characterSize;
105
is >> osgDB::PROPERTY("Color") >> prop._fontFile;
106
is >> osgDB::END_BRACKET;
108
prop._fontResolution = std::pair<int, int>(resX, resY);
109
bar.setTextProperties( prop );
113
static bool writeTextProperties( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
115
const osgSim::ScalarBar::TextProperties& prop = bar.getTextProperties();
116
os << osgDB::BEGIN_BRACKET << std::endl;
117
os << osgDB::PROPERTY("Font") << prop._fontFile << std::endl;
118
os << osgDB::PROPERTY("Resolution") << prop._fontResolution.first
119
<< prop._fontResolution.second << std::endl;
120
os << osgDB::PROPERTY("CharacterSize") << prop._characterSize << std::endl;
121
os << osgDB::PROPERTY("Color") << prop._color << std::endl;
122
os << osgDB::END_BRACKET << std::endl;
126
REGISTER_OBJECT_WRAPPER( osgSim_ScalarBar,
127
new osgSim::ScalarBar,
129
"osg::Object osg::Node osg::Geode osgSim::ScalarBar" )
131
ADD_INT_SERIALIZER( NumColors, 256 ); // _numColors
132
ADD_INT_SERIALIZER( NumLabels, 0 ); // _numLabels
133
ADD_USER_SERIALIZER( ScalarsToColors ); // _stc
134
ADD_STRING_SERIALIZER( Title, "" ); // _title
135
ADD_VEC3_SERIALIZER( Position, osg::Vec3() ); // _position
136
ADD_FLOAT_SERIALIZER( Width, 0.0f ); // _width
137
ADD_FLOAT_SERIALIZER( AspectRatio, 0.0f ); // _aspectRatio
139
BEGIN_ENUM_SERIALIZER( Orientation, HORIZONTAL );
140
ADD_ENUM_VALUE( HORIZONTAL );
141
ADD_ENUM_VALUE( VERTICAL );
142
END_ENUM_SERIALIZER(); // _orientation
144
ADD_USER_SERIALIZER( ScalarPrinter ); // _sp
145
ADD_USER_SERIALIZER( TextProperties ); // _textProperties