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

Revision 13041, 3.0 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 "VolumeTile.h"
16#include "Group.h"
17#include "VolumeLayer.h"
18
19#include <osgVolume/RayTracedTechnique>
20#include <osgVolume/FixedFunctionTechnique>
21
22using namespace ive;
23
24void VolumeTile::write(DataOutputStream* out)
25{
26    // Write VolumeTile's identification.
27    out->writeInt(IVEVOLUMETILE);
28    // If the osg class is inherited by any other class we should also write this to file.
29    osg::Group*  group = dynamic_cast<osg::Group*>(this);
30    if(group)
31        ((ive::Group*)(group))->write(out);
32    else
33        out_THROW_EXCEPTION("VolumeTile::write(): Could not cast this osgVolume::VolumeTile to an osg::Group.");
34
35
36    out->writeVolumeLocator(getLocator());
37    out->writeVolumeLayer(getLayer());
38
39    writeVolumeTechnique(out, getVolumeTechnique());
40
41}
42
43void VolumeTile::read(DataInputStream* in)
44{
45    // Peek on VolumeTile's identification.
46    int id = in->peekInt();
47    if (id != IVEVOLUMETILE) in_THROW_EXCEPTION("VolumeTile::read(): Expected Volume identification.");
48
49    // Read VolumeTile's identification.
50    id = in->readInt();
51    // If the osg class is inherited by any other class we should also read this from file.
52    osg::Group*  group = dynamic_cast<osg::Group*>(this);
53    if(group)
54        ((ive::Group*)(group))->read(in);
55    else
56        in_THROW_EXCEPTION("VolumeTile::read(): Could not cast this osgVolume::VolumeTile to an osg::Group.");
57
58    setLocator(in->readVolumeLocator());
59    setLayer(in->readVolumeLayer());
60
61    setVolumeTechnique(readVolumeTechnique(in));
62}
63
64void VolumeTile::writeVolumeTechnique(DataOutputStream* out, osgVolume::VolumeTechnique* technique)
65{
66    if (dynamic_cast<osgVolume::RayTracedTechnique*>(technique))
67    {
68        out->writeBool(true);
69        out->writeInt(IVEVOLUMERAYTRACEDTECHNIQUE);
70    }
71    if (dynamic_cast<osgVolume::FixedFunctionTechnique*>(technique))
72    {
73        out->writeBool(true);
74        out->writeInt(IVEVOLUMEFIXEDPIPELINETECHNIQUE);
75    }
76    else
77    {
78        out->writeBool(false);
79    }
80}
81
82osgVolume::VolumeTechnique* VolumeTile::readVolumeTechnique(DataInputStream* in)
83{
84    bool hasTechnique = in->readBool();
85    if (!hasTechnique) return 0;
86
87    int id = in->readInt();
88    if (id==IVEVOLUMERAYTRACEDTECHNIQUE)
89    {
90        return new osgVolume::RayTracedTechnique;
91    }
92    else if (id==IVEVOLUMEFIXEDPIPELINETECHNIQUE)
93    {
94        return new osgVolume::FixedFunctionTechnique;
95    }
96    else
97    {
98        return 0;
99    }
100}
Note: See TracBrowser for help on using the browser.