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

Revision 13041, 2.5 kB (checked in by robert, 3 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 "VolumeCompositeLayer.h"
16#include "VolumeLayer.h"
17#include "Layer.h"
18
19using namespace ive;
20
21void VolumeCompositeLayer::write(DataOutputStream* out)
22{
23    // Write Layer's identification.
24    out->writeInt(IVEVOLUMECOMPOSITELAYER);
25
26    // If the osg class is inherited by any other class we should also write this to file.
27    osgVolume::Layer*  layer = dynamic_cast<osgVolume::Layer*>(this);
28    if  (layer)
29        ((ive::VolumeLayer*)(layer))->write(out);
30    else
31        out_THROW_EXCEPTION("VolumeCompositeLayer::write(): Could not cast this osgVolume::CompositeLayer to an osgVolume::Layer.");
32
33    out->writeUInt(getNumLayers());
34    for(unsigned int i=0; i<getNumLayers(); ++i)
35    {
36        if(getLayer(i))
37        {
38            out->writeBool(true);
39            out->writeVolumeLayer(getLayer(i));
40        }
41        else
42        {
43            out->writeBool(false);
44            out->writeString(getFileName(i));
45        }
46    }
47}
48
49void VolumeCompositeLayer::read(DataInputStream* in)
50{
51    // Peek on Layer's identification.
52    int id = in->peekInt();
53    if (id != IVEVOLUMECOMPOSITELAYER)
54        in_THROW_EXCEPTION("VolumeCompositeLayer::read(): Expected CompositeLayer identification.");
55
56    // Read Layer's identification.
57    id = in->readInt();
58
59    // If the osg class is inherited by any other class we should also read this from file.
60    osgVolume::Layer*  layer = dynamic_cast<osgVolume::Layer*>(this);
61    if (layer)
62        ((ive::VolumeLayer*)(layer))->read(in);
63    else
64        in_THROW_EXCEPTION("VolumeCompositeLayer::read(): Could not cast this osgVolume::Layer to an osg::Group.");
65
66    unsigned int numLayers = in->readUInt();
67    for(unsigned int i=0; i<numLayers; ++i)
68    {
69        bool readInlineLayer = in->readBool();
70        if (readInlineLayer)
71        {
72            addLayer(in->readVolumeLayer());
73        }
74        else
75        {
76            setFileName(i, in->readString());
77        }
78    }
79}
Note: See TracBrowser for help on using the browser.