root/OpenSceneGraph/trunk/src/osgPlugins/ive/ImageLayer.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include "Exception.h"
15#include "ImageLayer.h"
16#include "Layer.h"
17
18#include <osgTerrain/TerrainTile>
19
20#include <osgDB/ReadFile>
21
22using namespace ive;
23
24void ImageLayer::write(DataOutputStream* out)
25{
26    // Write Layer's identification.
27    out->writeInt(IVEIMAGELAYER);
28
29    // If the osg class is inherited by any other class we should also write this to file.
30    osgTerrain::Layer*  layer = dynamic_cast<osgTerrain::Layer*>(this);
31    if  (layer)
32        ((ive::Layer*)(layer))->write(out);
33    else
34        out_THROW_EXCEPTION("ImageLayer::write(): Could not cast this osgLayer::ImageLayer to an osgTerrain::Layer.");
35
36
37    IncludeImageMode imMode = out->getIncludeImageMode(getImage());
38
39    if (getFileName().empty() && imMode==IMAGE_REFERENCE_FILE) imMode = IMAGE_INCLUDE_DATA;
40
41    out->writeChar(imMode);
42    out->writeImage(imMode,getImage());
43
44}
45
46void ImageLayer::read(DataInputStream* in)
47{
48    // Peek on Layer's identification.
49    int id = in->peekInt();
50    if (id != IVEIMAGELAYER)
51        in_THROW_EXCEPTION("ImageLayer::read(): Expected ImageLayer identification.");
52
53    // Read Layer's identification.
54    id = in->readInt();
55
56    // If the osg class is inherited by any other class we should also read this from file.
57    osgTerrain::Layer*  layer = dynamic_cast<osgTerrain::Layer*>(this);
58    if (layer)
59        ((ive::Layer*)(layer))->read(in);
60    else
61        in_THROW_EXCEPTION("ImageLayer::read(): Could not cast this osgLayer::Layer to an osg::Group.");
62
63
64    bool deferExternalLayerLoading = osgTerrain::TerrainTile::getTileLoadedCallback().valid() ?
65        osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() : false;
66
67    // Should we read image data from stream
68    IncludeImageMode includeImg = (IncludeImageMode)in->readChar();
69
70    if (includeImg==IMAGE_REFERENCE_FILE && deferExternalLayerLoading)
71    {
72        setFileName(in->readString());
73    }
74    else
75    {
76        setImage(in->readImage(includeImg));
77    }
78}
Note: See TracBrowser for help on using the browser.