~ubuntu-branches/debian/experimental/openscenegraph/experimental

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgWrappers/serializers/osgSim/ScalarBar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Luaces
  • Date: 2011-01-29 11:36:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110129113629-qisrm2kdqlurc7t3
Tags: 2.9.11-1
* Removed bug-555869-ftbfs_with_binutils_gold.dpatch since upstream has
  already taken care of the issue.
* Removed bug-528229.dpatch since the pkgconfig files are now also split
  in upstream.
* Removed explicit dependency on GLU.
* Upstream no longer includes osgIntrospection (Closes: #592420).
* Disabled zip plugin as its implementation stores an embedded copy of
  zlib.
* Enabled Qt support. Thanks James Goppert.
* Enabled SVG and PDF plugins. Thanks James Goppert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <osgSim/ScalarBar>
 
2
#include <osgDB/ObjectWrapper>
 
3
#include <osgDB/InputStream>
 
4
#include <osgDB/OutputStream>
 
5
 
 
6
// _stc
 
7
static bool checkScalarsToColors( const osgSim::ScalarBar& bar )
 
8
{ return bar.getScalarsToColors()!=NULL; }
 
9
 
 
10
static bool readScalarsToColors( osgDB::InputStream& is, osgSim::ScalarBar& bar )
 
11
{
 
12
    float min, max;
 
13
    is >> osgDB::BEGIN_BRACKET;
 
14
    is >> osgDB::PROPERTY("Range") >> min >> max;
 
15
    
 
16
    bool hasColorRange = false;
 
17
    unsigned int colorSize = 0;
 
18
    is >> osgDB::PROPERTY("Colors") >> hasColorRange >> colorSize;
 
19
    if ( !hasColorRange )
 
20
    {
 
21
        osgSim::ScalarsToColors* stc = new osgSim::ScalarsToColors(min, max);
 
22
        bar.setScalarsToColors( stc );
 
23
    }
 
24
    else
 
25
    {
 
26
        is >> osgDB::BEGIN_BRACKET;
 
27
        std::vector<osg::Vec4> colors;
 
28
        for ( unsigned int i=0; i<colorSize; ++i )
 
29
        {
 
30
            osg::Vec4 color; is >> color;
 
31
            colors.push_back( color );
 
32
        }
 
33
        is >> osgDB::END_BRACKET;
 
34
        
 
35
        osgSim::ColorRange* cr = new osgSim::ColorRange(min, max, colors);
 
36
        bar.setScalarsToColors( cr );
 
37
    }
 
38
    return true;
 
39
}
 
40
 
 
41
static bool writeScalarsToColors( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
 
42
{
 
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");
 
47
    
 
48
    unsigned int colorSize = 0;
 
49
    const osgSim::ColorRange* cr = dynamic_cast<const osgSim::ColorRange*>(stc);
 
50
    if ( cr )
 
51
    {
 
52
        const std::vector<osg::Vec4>& colors = cr->getColors();
 
53
        colorSize = colors.size();
 
54
        
 
55
        os << true << colorSize << osgDB::BEGIN_BRACKET << std::endl;
 
56
        for ( unsigned int i=0; i<colorSize; ++i )
 
57
        {
 
58
            os << colors[i] << std::endl;
 
59
        }
 
60
        os << osgDB::END_BRACKET << std::endl;
 
61
    }
 
62
    else
 
63
        os << false << colorSize << std::endl;
 
64
    os << osgDB::END_BRACKET << std::endl;
 
65
    return true;
 
66
}
 
67
 
 
68
// _sp
 
69
static bool checkScalarPrinter( const osgSim::ScalarBar& bar )
 
70
{
 
71
    return bar.getScalarPrinter()!=NULL &&
 
72
           dynamic_cast<const osg::Object*>(bar.getScalarPrinter());
 
73
}
 
74
 
 
75
static bool readScalarPrinter( osgDB::InputStream& is, osgSim::ScalarBar& bar )
 
76
{
 
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;
 
82
    return true;
 
83
}
 
84
 
 
85
static bool writeScalarPrinter( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
 
86
{
 
87
    os << osgDB::BEGIN_BRACKET << std::endl;
 
88
    os.writeObject( dynamic_cast<const osg::Object*>(bar.getScalarPrinter()) ); 
 
89
    os << osgDB::END_BRACKET << std::endl;
 
90
    return true;
 
91
}
 
92
 
 
93
// _textProperties
 
94
static bool checkTextProperties( const osgSim::ScalarBar& bar )
 
95
{ return true; }
 
96
 
 
97
static bool readTextProperties( osgDB::InputStream& is, osgSim::ScalarBar& bar )
 
98
{
 
99
    osgSim::ScalarBar::TextProperties prop;
 
100
    int resX, resY;
 
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;
 
107
    
 
108
    prop._fontResolution = std::pair<int, int>(resX, resY);
 
109
    bar.setTextProperties( prop );
 
110
    return true;
 
111
}
 
112
 
 
113
static bool writeTextProperties( osgDB::OutputStream& os, const osgSim::ScalarBar& bar )
 
114
{
 
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;
 
123
    return true;
 
124
}
 
125
 
 
126
REGISTER_OBJECT_WRAPPER( osgSim_ScalarBar,
 
127
                         new osgSim::ScalarBar,
 
128
                         osgSim::ScalarBar,
 
129
                         "osg::Object osg::Node osg::Geode osgSim::ScalarBar" )
 
130
{
 
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
 
138
    
 
139
    BEGIN_ENUM_SERIALIZER( Orientation, HORIZONTAL );
 
140
        ADD_ENUM_VALUE( HORIZONTAL );
 
141
        ADD_ENUM_VALUE( VERTICAL );
 
142
    END_ENUM_SERIALIZER();  // _orientation
 
143
    
 
144
    ADD_USER_SERIALIZER( ScalarPrinter );  // _sp
 
145
    ADD_USER_SERIALIZER( TextProperties );  // _textProperties
 
146
}