From bd4a1cd601304e5f56b661c4cc0008c174531a99 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 1 Dec 2003 14:31:56 +0000 Subject: [PATCH] From Pavel Moloshton, addition of AlphaFunc support to .ive. --- VisualStudio/osgPlugins/ive/ive.dsp | 8 ++++ examples/osgdem/DataSet.cpp | 46 +------------------ examples/osgdem/DataSet.h | 3 ++ src/osgPlugins/ive/AlphaFunc.cpp | 61 +++++++++++++++++++++++++ src/osgPlugins/ive/AlphaFunc.h | 15 ++++++ src/osgPlugins/ive/DataInputStream.cpp | 7 ++- src/osgPlugins/ive/DataOutputStream.cpp | 6 ++- src/osgPlugins/ive/GNUmakefile | 1 + 8 files changed, 100 insertions(+), 47 deletions(-) create mode 100644 src/osgPlugins/ive/AlphaFunc.cpp create mode 100644 src/osgPlugins/ive/AlphaFunc.h diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index e8ea4ff14..9f1ce4e18 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -94,6 +94,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\AlphaFunc.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\AnimationPath.cpp # End Source File # Begin Source File @@ -330,6 +334,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\VisibilityGroup.cpp # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\AlphaFunc.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\AnimationPath.h # End Source File # Begin Source File diff --git a/examples/osgdem/DataSet.cpp b/examples/osgdem/DataSet.cpp index 4d4fa4b4d..985ea7c22 100644 --- a/examples/osgdem/DataSet.cpp +++ b/examples/osgdem/DataSet.cpp @@ -766,7 +766,7 @@ void DataSet::DestinationTile::computeMaximumSourceResolution(CompositeSource* s SpatialProperties sp = data->computeSpatialProperties(_cs.get()); - if (!sp._extents.intersects(data->getExtents(_cs.get()))) + if (!sp._extents.intersects(_extents)) { std::cout<<"DataSet::DestinationTile::computeMaximumSourceResolution:: source does not overlap ignoring for this tile."<getFileName()<_sourceList.begin(); - itr!=csitr->_sourceList.end(); - ++itr) - { - std::cout<<" Source "<<(*itr)->getFileName()<<" res="<<(*itr)->getSortValue()<setType(LEVEL_OF_DETAIL); - } - std::cout<<"End of Source Iterator itr"<get(); - source->setSortValueFromSourceDataResolution(); - std::cout<<"sort "<getFileName()<<" value "<getSortValue()<sort(); - } - - std::cout<<"Using source_lod_iterator itr"<getFileName()< _model; GDALDataset* _gdalDataSet; + }; diff --git a/src/osgPlugins/ive/AlphaFunc.cpp b/src/osgPlugins/ive/AlphaFunc.cpp new file mode 100644 index 000000000..324d97e5b --- /dev/null +++ b/src/osgPlugins/ive/AlphaFunc.cpp @@ -0,0 +1,61 @@ +/********************************************************************** + * + * FILE: AlphaFunc.cpp + * + * DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk. + * + * CREATED BY: Pavlo Moloshtan + * + * HISTORY: Created 30.11.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "AlphaFunc.h" +#include "Object.h" + +using namespace ive; + +void AlphaFunc::write(DataOutputStream* out){ + + // write AlphaFunc's identification + out->writeInt(IVEALPHAFUNC); + + // if the osg class is inherited by any other class we should also write this to file + osg::Object* obj = dynamic_cast(this); + if(obj) + ((ive::Object*)(obj))->write(out); + else + throw Exception("AlphaFunc::write(): Could not cast this osg::AlphaFunc to an osg::Object."); + + // write AlphaFunc's properties + out->writeInt(getFunction()); + out->writeFloat(getReferenceValue()); +} + +void AlphaFunc::read(DataInputStream* in){ + + // peek on AlphaFunc's identification + int id = in->peekInt(); + if(id == IVEALPHAFUNC) + { + // read AlphaFunc's identification + id = in->readInt(); + + // if the osg class is inherited by any other class we should also read this from file + osg::Object* obj = dynamic_cast(this); + if(obj) + ((ive::Object*)(obj))->read(in); + else + throw Exception("AlphaFunc::read(): Could not cast this osg::AlphaFunc to an osg::Object."); + + // Read AlphaFunc's properties + osg::AlphaFunc::ComparisonFunction comparison_funtion = osg::AlphaFunc::ComparisonFunction(in->readInt()); + float reference_value = in->readFloat(); + setFunction(comparison_funtion, reference_value); + } + else{ + throw Exception("AlphaFunc::read(): Expected AlphaFunc identification."); + } +} diff --git a/src/osgPlugins/ive/AlphaFunc.h b/src/osgPlugins/ive/AlphaFunc.h new file mode 100644 index 000000000..ef3a27bb1 --- /dev/null +++ b/src/osgPlugins/ive/AlphaFunc.h @@ -0,0 +1,15 @@ +#ifndef IVE_ALPHAFUNC +#define IVE_ALPHAFUNC 1 + +#include +#include "ReadWrite.h" + +namespace ive{ + class AlphaFunc : public osg::AlphaFunc, public ReadWrite { + public: + void write(DataOutputStream* out); + void read(DataInputStream* in); + }; +} + +#endif diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index fb19834b9..240234694 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -14,6 +14,7 @@ #include "DataInputStream.h" #include "StateSet.h" +#include "AlphaFunc.h" #include "BlendFunc.h" #include "Material.h" #include "CullFace.h" @@ -530,7 +531,11 @@ osg::StateAttribute* DataInputStream::readStateAttribute() osg::StateAttribute* attribute; int attributeID = peekInt(); - if(attributeID == IVEBLENDFUNC){ + if(attributeID == IVEALPHAFUNC){ + attribute = new osg::AlphaFunc(); + ((ive::AlphaFunc*)(attribute))->read(this); + } + else if(attributeID == IVEBLENDFUNC){ attribute = new osg::BlendFunc(); ((ive::BlendFunc*)(attribute))->read(this); } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index fc70a228a..3db143306 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -16,6 +16,7 @@ #include "Exception.h" #include "StateSet.h" +#include "AlphaFunc.h" #include "BlendFunc.h" #include "Material.h" #include "CullFace.h" @@ -403,7 +404,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) writeInt(id); // write the stateset. - if(dynamic_cast(attribute)){ + if(dynamic_cast(attribute)){ + ((ive::AlphaFunc*)(attribute))->write(this); + } + else if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } // This is a Material diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 6469b6513..c9c5b6c68 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -2,6 +2,7 @@ TOPDIR = ../../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ + AlphaFunc.cpp\ AnimationPath.cpp\ AnimationPathCallback.cpp\ Billboard.cpp\