From 9454eb53ba225a1212fa5da3947bacbbae0ac097 Mon Sep 17 00:00:00 2001 From: David Stephan Date: Fri, 27 Jul 2018 14:48:10 -0700 Subject: [PATCH 1/4] added switch names to osgSim::MultiSwitch serializer --- examples/CMakeLists.txt | 1 + examples/osgmultiswitchtest/CMakeLists.txt | 5 ++ .../osgmultiswitchtest/osgmultiswitchtest.cpp | 86 +++++++++++++++++++ .../serializers/osgSim/MultiSwitch.cpp | 35 ++++++++ 4 files changed, 127 insertions(+) create mode 100644 examples/osgmultiswitchtest/CMakeLists.txt create mode 100644 examples/osgmultiswitchtest/osgmultiswitchtest.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4edb8dc39..70d98af13 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -73,6 +73,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgmovie) ADD_SUBDIRECTORY(osgmultiplemovies) ADD_SUBDIRECTORY(osgmultiplerendertargets) + ADD_SUBDIRECTORY(osgmultiswitchtest) ADD_SUBDIRECTORY(osgmultitexture) ADD_SUBDIRECTORY(osgmultitexturecontrol) ADD_SUBDIRECTORY(osgmultitouch) diff --git a/examples/osgmultiswitchtest/CMakeLists.txt b/examples/osgmultiswitchtest/CMakeLists.txt new file mode 100644 index 000000000..504c037cb --- /dev/null +++ b/examples/osgmultiswitchtest/CMakeLists.txt @@ -0,0 +1,5 @@ + +SET(TARGET_SRC osgmultiswitchtest.cpp) +SET(TARGET_ADDED_LIBRARIES osgSim) +# also depends on osgsim plugin, osg plugins +SETUP_COMMANDLINE_EXAMPLE(osgmultiswitchtest) diff --git a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp new file mode 100644 index 000000000..7c757a899 --- /dev/null +++ b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp @@ -0,0 +1,86 @@ +/* OpenSceneGraph example, osgmultiswitchtest. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include +#include +#include + +#include + +void assert2(bool success) { + if (!success) throw std::runtime_error(""); +} + +void testSerializer(const osgSim::MultiSwitch::SwitchSetList &values, + const osgSim::MultiSwitch::SwitchSetNameList &names) { + + osg::ref_ptr ms(new osgSim::MultiSwitch); + if (values.size() > 0) { + int nchildren = values[0].size(); + for (int i = 0; i < nchildren; i++) { + ms->addChild(new osg::Node); + } + } + + ms->setSwitchSetList(values); + for (int i = 0; i < names.size(); i++) { + ms->setValueName(i, names[i]); + } + + osgDB::ReaderWriter *rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); + osg::ref_ptr options = new osgDB::Options; + std::stringstream ss; + + // write + auto wresult = rw->writeNode(*ms, ss, options); + + // read + auto rresult = rw->readNode(ss, options); + osg::ref_ptr node = rresult.takeNode(); + + osg::ref_ptr ms2(dynamic_cast(node.get())); + assert2(ms2 != nullptr); + + assert2(ms2->getSwitchSetList() == values); + for (int i = 0; i < values.size(); i++) { + assert2(ms2->getValueName(i) == names[i]); + } + assert2(ms->getNumChildren() == ms2->getNumChildren()); +} + +int main( int argc, char **argv ) +{ + testSerializer( + { + {false, false}, + {true, true} + }, + { "offs", "ons" } + ); + + testSerializer({}, {}); + + testSerializer( + { + { true, true, false, true, false, true } + }, + {"stuff"} + ); + + return 0; +} diff --git a/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp b/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp index 14d3c64a8..b08e4951b 100644 --- a/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp +++ b/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp @@ -49,6 +49,36 @@ static bool writeValues( osgDB::OutputStream& os, const osgSim::MultiSwitch& nod return true; } +static bool checkValueNames(const osgSim::MultiSwitch& node) +{ + return node.getSwitchSetList().size()>0; +} + +static bool readValueNames(osgDB::InputStream& is, osgSim::MultiSwitch& node) +{ + unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; + for (unsigned int i = 0; i> name; + node.setValueName(i, name); + } + is >> is.END_BRACKET; + return true; +} + +static bool writeValueNames(osgDB::OutputStream& os, const osgSim::MultiSwitch& node) +{ + const osgSim::MultiSwitch::SwitchSetList& switches = node.getSwitchSetList(); + os.writeSize(switches.size()); os << os.BEGIN_BRACKET << std::endl; + for (unsigned int i = 0; i Date: Fri, 27 Jul 2018 14:55:02 -0700 Subject: [PATCH 2/4] tabs to spaces --- .../osgmultiswitchtest/osgmultiswitchtest.cpp | 86 +++++++++---------- .../serializers/osgSim/MultiSwitch.cpp | 44 +++++----- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp index 7c757a899..ef4b4fb3a 100644 --- a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp +++ b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp @@ -23,64 +23,64 @@ #include void assert2(bool success) { - if (!success) throw std::runtime_error(""); + if (!success) throw std::runtime_error(""); } void testSerializer(const osgSim::MultiSwitch::SwitchSetList &values, - const osgSim::MultiSwitch::SwitchSetNameList &names) { + const osgSim::MultiSwitch::SwitchSetNameList &names) { - osg::ref_ptr ms(new osgSim::MultiSwitch); - if (values.size() > 0) { - int nchildren = values[0].size(); - for (int i = 0; i < nchildren; i++) { - ms->addChild(new osg::Node); - } - } + osg::ref_ptr ms(new osgSim::MultiSwitch); + if (values.size() > 0) { + int nchildren = values[0].size(); + for (int i = 0; i < nchildren; i++) { + ms->addChild(new osg::Node); + } + } - ms->setSwitchSetList(values); - for (int i = 0; i < names.size(); i++) { - ms->setValueName(i, names[i]); - } + ms->setSwitchSetList(values); + for (int i = 0; i < names.size(); i++) { + ms->setValueName(i, names[i]); + } - osgDB::ReaderWriter *rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); - osg::ref_ptr options = new osgDB::Options; - std::stringstream ss; + osgDB::ReaderWriter *rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); + osg::ref_ptr options = new osgDB::Options; + std::stringstream ss; - // write - auto wresult = rw->writeNode(*ms, ss, options); + // write + auto wresult = rw->writeNode(*ms, ss, options); - // read - auto rresult = rw->readNode(ss, options); - osg::ref_ptr node = rresult.takeNode(); + // read + auto rresult = rw->readNode(ss, options); + osg::ref_ptr node = rresult.takeNode(); - osg::ref_ptr ms2(dynamic_cast(node.get())); - assert2(ms2 != nullptr); + osg::ref_ptr ms2(dynamic_cast(node.get())); + assert2(ms2 != nullptr); - assert2(ms2->getSwitchSetList() == values); - for (int i = 0; i < values.size(); i++) { - assert2(ms2->getValueName(i) == names[i]); - } - assert2(ms->getNumChildren() == ms2->getNumChildren()); + assert2(ms2->getSwitchSetList() == values); + for (int i = 0; i < values.size(); i++) { + assert2(ms2->getValueName(i) == names[i]); + } + assert2(ms->getNumChildren() == ms2->getNumChildren()); } int main( int argc, char **argv ) { - testSerializer( - { - {false, false}, - {true, true} - }, - { "offs", "ons" } - ); + testSerializer( + { + {false, false}, + {true, true} + }, + { "offs", "ons" } + ); - testSerializer({}, {}); + testSerializer({}, {}); - testSerializer( - { - { true, true, false, true, false, true } - }, - {"stuff"} - ); + testSerializer( + { + { true, true, false, true, false, true } + }, + {"stuff"} + ); - return 0; + return 0; } diff --git a/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp b/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp index b08e4951b..592aea7ab 100644 --- a/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp +++ b/src/osgWrappers/serializers/osgSim/MultiSwitch.cpp @@ -51,32 +51,32 @@ static bool writeValues( osgDB::OutputStream& os, const osgSim::MultiSwitch& nod static bool checkValueNames(const osgSim::MultiSwitch& node) { - return node.getSwitchSetList().size()>0; + return node.getSwitchSetList().size()>0; } static bool readValueNames(osgDB::InputStream& is, osgSim::MultiSwitch& node) { - unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; - for (unsigned int i = 0; i> name; - node.setValueName(i, name); - } - is >> is.END_BRACKET; - return true; + unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; + for (unsigned int i = 0; i> name; + node.setValueName(i, name); + } + is >> is.END_BRACKET; + return true; } static bool writeValueNames(osgDB::OutputStream& os, const osgSim::MultiSwitch& node) { - const osgSim::MultiSwitch::SwitchSetList& switches = node.getSwitchSetList(); - os.writeSize(switches.size()); os << os.BEGIN_BRACKET << std::endl; - for (unsigned int i = 0; i Date: Fri, 27 Jul 2018 18:39:36 -0700 Subject: [PATCH 3/4] changes for angry travis --- .../osgmultiswitchtest/osgmultiswitchtest.cpp | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp index ef4b4fb3a..a978b3c23 100644 --- a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp +++ b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -31,14 +32,14 @@ void testSerializer(const osgSim::MultiSwitch::SwitchSetList &values, osg::ref_ptr ms(new osgSim::MultiSwitch); if (values.size() > 0) { - int nchildren = values[0].size(); - for (int i = 0; i < nchildren; i++) { + size_t nchildren = values[0].size(); + for (size_t i = 0; i < nchildren; i++) { ms->addChild(new osg::Node); } } ms->setSwitchSetList(values); - for (int i = 0; i < names.size(); i++) { + for (size_t i = 0; i < names.size(); i++) { ms->setValueName(i, names[i]); } @@ -47,40 +48,65 @@ void testSerializer(const osgSim::MultiSwitch::SwitchSetList &values, std::stringstream ss; // write - auto wresult = rw->writeNode(*ms, ss, options); + osgDB::ReaderWriter::WriteResult wresult = rw->writeNode(*ms, ss, options); // read - auto rresult = rw->readNode(ss, options); + osgDB::ReaderWriter::ReadResult rresult = rw->readNode(ss, options); osg::ref_ptr node = rresult.takeNode(); osg::ref_ptr ms2(dynamic_cast(node.get())); - assert2(ms2 != nullptr); + assert2(ms2 != NULL); assert2(ms2->getSwitchSetList() == values); - for (int i = 0; i < values.size(); i++) { + for (size_t i = 0; i < values.size(); i++) { assert2(ms2->getValueName(i) == names[i]); } assert2(ms->getNumChildren() == ms2->getNumChildren()); } -int main( int argc, char **argv ) +int main() { - testSerializer( - { - {false, false}, - {true, true} - }, - { "offs", "ons" } - ); + osgSim::MultiSwitch::SwitchSetList values; + osgSim::MultiSwitch::SwitchSetNameList names; + //testSerializer( + // { + // {false, false}, + // {true, true} + // }, + // { "offs", "ons" } + //); + std::vector offs(false, 2); + std::vector ons(true, 2); + values.push_back(offs); + values.push_back(ons); + names.push_back("offs"); + names.push_back("ons"); + testSerializer(values, names); - testSerializer({}, {}); + //testSerializer({}, {}); + values.clear(); + names.clear(); + testSerializer(values, names); - testSerializer( - { - { true, true, false, true, false, true } - }, - {"stuff"} - ); + //testSerializer( + // { + // { true, true, false, true, false, true } + // }, + // {"stuff"} + //); + values.clear(); + std::vector stuff; + stuff.push_back(true); + stuff.push_back(true); + stuff.push_back(false); + stuff.push_back(true); + stuff.push_back(false); + stuff.push_back(true); + values.push_back(stuff); + + names.clear(); + names.push_back("stuff"); + testSerializer(values, names); return 0; } From c1d3767ca5911b37b8211ddf6d4ec426f59692a7 Mon Sep 17 00:00:00 2001 From: David Stephan Date: Sun, 29 Jul 2018 14:13:17 -0700 Subject: [PATCH 4/4] removed tests --- examples/CMakeLists.txt | 1 - examples/osgmultiswitchtest/CMakeLists.txt | 5 - .../osgmultiswitchtest/osgmultiswitchtest.cpp | 112 ------------------ 3 files changed, 118 deletions(-) delete mode 100644 examples/osgmultiswitchtest/CMakeLists.txt delete mode 100644 examples/osgmultiswitchtest/osgmultiswitchtest.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 70d98af13..4edb8dc39 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -73,7 +73,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgmovie) ADD_SUBDIRECTORY(osgmultiplemovies) ADD_SUBDIRECTORY(osgmultiplerendertargets) - ADD_SUBDIRECTORY(osgmultiswitchtest) ADD_SUBDIRECTORY(osgmultitexture) ADD_SUBDIRECTORY(osgmultitexturecontrol) ADD_SUBDIRECTORY(osgmultitouch) diff --git a/examples/osgmultiswitchtest/CMakeLists.txt b/examples/osgmultiswitchtest/CMakeLists.txt deleted file mode 100644 index 504c037cb..000000000 --- a/examples/osgmultiswitchtest/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -SET(TARGET_SRC osgmultiswitchtest.cpp) -SET(TARGET_ADDED_LIBRARIES osgSim) -# also depends on osgsim plugin, osg plugins -SETUP_COMMANDLINE_EXAMPLE(osgmultiswitchtest) diff --git a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp b/examples/osgmultiswitchtest/osgmultiswitchtest.cpp deleted file mode 100644 index a978b3c23..000000000 --- a/examples/osgmultiswitchtest/osgmultiswitchtest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* OpenSceneGraph example, osgmultiswitchtest. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include -#include -#include -#include - -#include - -void assert2(bool success) { - if (!success) throw std::runtime_error(""); -} - -void testSerializer(const osgSim::MultiSwitch::SwitchSetList &values, - const osgSim::MultiSwitch::SwitchSetNameList &names) { - - osg::ref_ptr ms(new osgSim::MultiSwitch); - if (values.size() > 0) { - size_t nchildren = values[0].size(); - for (size_t i = 0; i < nchildren; i++) { - ms->addChild(new osg::Node); - } - } - - ms->setSwitchSetList(values); - for (size_t i = 0; i < names.size(); i++) { - ms->setValueName(i, names[i]); - } - - osgDB::ReaderWriter *rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); - osg::ref_ptr options = new osgDB::Options; - std::stringstream ss; - - // write - osgDB::ReaderWriter::WriteResult wresult = rw->writeNode(*ms, ss, options); - - // read - osgDB::ReaderWriter::ReadResult rresult = rw->readNode(ss, options); - osg::ref_ptr node = rresult.takeNode(); - - osg::ref_ptr ms2(dynamic_cast(node.get())); - assert2(ms2 != NULL); - - assert2(ms2->getSwitchSetList() == values); - for (size_t i = 0; i < values.size(); i++) { - assert2(ms2->getValueName(i) == names[i]); - } - assert2(ms->getNumChildren() == ms2->getNumChildren()); -} - -int main() -{ - osgSim::MultiSwitch::SwitchSetList values; - osgSim::MultiSwitch::SwitchSetNameList names; - //testSerializer( - // { - // {false, false}, - // {true, true} - // }, - // { "offs", "ons" } - //); - std::vector offs(false, 2); - std::vector ons(true, 2); - values.push_back(offs); - values.push_back(ons); - names.push_back("offs"); - names.push_back("ons"); - testSerializer(values, names); - - //testSerializer({}, {}); - values.clear(); - names.clear(); - testSerializer(values, names); - - //testSerializer( - // { - // { true, true, false, true, false, true } - // }, - // {"stuff"} - //); - values.clear(); - std::vector stuff; - stuff.push_back(true); - stuff.push_back(true); - stuff.push_back(false); - stuff.push_back(true); - stuff.push_back(false); - stuff.push_back(true); - values.push_back(stuff); - - names.clear(); - names.push_back("stuff"); - testSerializer(values, names); - - return 0; -}