From 457d3fd7e486124a618f0e4e0bd34094e91eac80 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 9 Dec 2007 16:23:19 +0000 Subject: [PATCH] Removed redundent OpenFlightOptimizer --- include/osgSim/OpenFlightOptimizer | 114 --------- src/osgSim/CMakeLists.txt | 2 - src/osgSim/OpenFlightOptimizer.cpp | 240 ------------------ .../osgSim/OpenFlightOptimizer.cpp | 107 -------- 4 files changed, 463 deletions(-) delete mode 100644 include/osgSim/OpenFlightOptimizer delete mode 100644 src/osgSim/OpenFlightOptimizer.cpp delete mode 100644 src/osgWrappers/osgSim/OpenFlightOptimizer.cpp diff --git a/include/osgSim/OpenFlightOptimizer b/include/osgSim/OpenFlightOptimizer deleted file mode 100644 index 890789ef3..000000000 --- a/include/osgSim/OpenFlightOptimizer +++ /dev/null @@ -1,114 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ -// -// OpenFlightŪ loader for OpenSceneGraph -// -// Copyright (C) 2005-2006 Brede Johansen -// - -#ifndef OSGSIM_OPENFLIGHTOPTIMIZER -#define OSGSIM_OPENFLIGHTOPTIMIZER - -#include -#include -#include - -#include - -namespace osgSim { - -/** Flight optimizer - */ -class OSGSIM_EXPORT Optimizer -{ - public: - - Optimizer() {} - virtual ~Optimizer() {} - - enum OptimizationOptions - { - TESSELLATE_POLYGON = 0x001, - MERGE_GEODES = 0x002, - MAKE_LIT = 0x004, - DEFAULT_OPTIMIZATIONS = TESSELLATE_POLYGON | MERGE_GEODES, - ALL_OPTIMIZATIONS = TESSELLATE_POLYGON | MERGE_GEODES - }; - - - /** Traverse the node and its subgraph with a series of optimization - * visitors, specified by the OptimizationOptions.*/ - void optimize(osg::Node* node); - - /** Traverse the node and its subgraph with a series of optimization - * visitors, specified by the OptimizationOptions.*/ - virtual void optimize(osg::Node* node, unsigned int options); - - protected: - - - public: - - class OSGSIM_EXPORT TessellateVisitor : public osg::NodeVisitor - { - public: - - /// default to traversing all children. - TessellateVisitor() : - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - virtual void apply(osg::Geode& geode); - - protected: - - bool hasPolygons(osg::Geometry& geometry); - - }; - - class OSGSIM_EXPORT MakeLitVisitor : public osg::NodeVisitor - { - public: - - /// default to traversing all children. - MakeLitVisitor() : - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - virtual void apply(osg::Geode& geode); - }; - - - /** Combine geodes - */ - class OSGSIM_EXPORT MergeGeodesVisitor : public osg::NodeVisitor - { - public: - - /// default to traversing all children. - MergeGeodesVisitor() : - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - virtual void apply(osg::Group& group); - - void mergeGeodes(osg::Group& group); - - protected: - - bool mergeGeode(osg::Geode& lhs, osg::Geode& rhs); - - }; - -}; - -} // end namespace - -#endif diff --git a/src/osgSim/CMakeLists.txt b/src/osgSim/CMakeLists.txt index c361dedf1..2aad845c5 100644 --- a/src/osgSim/CMakeLists.txt +++ b/src/osgSim/CMakeLists.txt @@ -23,7 +23,6 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/LightPointSystem ${HEADER_PATH}/LineOfSight ${HEADER_PATH}/MultiSwitch - ${HEADER_PATH}/OpenFlightOptimizer ${HEADER_PATH}/OverlayNode ${HEADER_PATH}/ScalarBar ${HEADER_PATH}/ScalarsToColors @@ -54,7 +53,6 @@ ADD_LIBRARY(${LIB_NAME} LightPointSpriteDrawable.h LineOfSight.cpp MultiSwitch.cpp - OpenFlightOptimizer.cpp OverlayNode.cpp ScalarBar.cpp ScalarsToColors.cpp diff --git a/src/osgSim/OpenFlightOptimizer.cpp b/src/osgSim/OpenFlightOptimizer.cpp deleted file mode 100644 index c0267bdce..000000000 --- a/src/osgSim/OpenFlightOptimizer.cpp +++ /dev/null @@ -1,240 +0,0 @@ -// -// OpenFlightŪ loader for OpenSceneGraph -// -// Copyright (C) 2005-2006 Brede Johansen -// - -#include - -#include - -#include -#include - -#include -#include - -#include -#include - -using namespace osgSim; - -void Optimizer::optimize(osg::Node* node) -{ - unsigned int options = 0; - - const char* env = getenv("OSG_FLIGHTUTIL_OPTIMIZER"); - if (env) - { - std::string str(env); - - if(str.find("OFF")!=std::string::npos) options = 0; - - if(str.find("~DEFAULT")!=std::string::npos) options ^= DEFAULT_OPTIMIZATIONS; - else if(str.find("DEFAULT")!=std::string::npos) options |= DEFAULT_OPTIMIZATIONS; - - if(str.find("~TESSELLATE_POLYGON")!=std::string::npos) options ^= TESSELLATE_POLYGON; - else if(str.find("TESSELLATE_POLYGON")!=std::string::npos) options |= TESSELLATE_POLYGON; - - if(str.find("~MAKE_LIT")!=std::string::npos) options ^= MAKE_LIT; - else if(str.find("MAKE_LIT")!=std::string::npos) options |= MAKE_LIT; - - if(str.find("~MERGE_GEODES")!=std::string::npos) options ^= MERGE_GEODES; - else if(str.find("MERGE_GEODES")!=std::string::npos) options |= MERGE_GEODES; - } - else - { - options = DEFAULT_OPTIMIZATIONS; - } - - optimize(node,options); -} - -void Optimizer::optimize(osg::Node* node, unsigned int options) -{ - if (options & TESSELLATE_POLYGON) - { - osg::notify(osg::INFO)<<"osgFlightUtil::Optimizer::optimize() doing TESSELLATE_POLYGON"<accept(visitor); - } - - if (options & MAKE_LIT) - { - osg::notify(osg::INFO)<<"osgFlightUtil::Optimizer::optimize() doing MAKE_LIT"<accept(visitor); - } - - if (options & MERGE_GEODES) - { - osg::notify(osg::INFO)<<"osgFlightUtil::Optimizer::optimize() doing MERGE_GEODES"<accept(visitor); - } -} - - -void Optimizer::TessellateVisitor::apply(osg::Geode& geode) -{ - for (unsigned int i=0; i(geode.getDrawable(i)); - if (geometry) - { - if (hasPolygons(*geometry)) - { - // Tessellate - osgUtil::Tessellator Tessellator; - Tessellator.retessellatePolygons(*geometry); - } - } - } -} - -bool Optimizer::TessellateVisitor::hasPolygons(osg::Geometry& geometry) -{ - for (unsigned int i=0; igetMode() == osg::PrimitiveSet::POLYGON) - return true; - } - - return false; -} - - -void Optimizer::MakeLitVisitor::apply(osg::Geode& /*geode*/) -{ -#if 0 // TODO - osg::StateSet* stateset = geode.getStateSet(); - if (stateset) - { - // Not lit? - if (!(stateset->getMode(GL_LIGHTING)&osg::StateAttribute::ON)) - { - stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); - for (unsigned int i=0; i(geode.getDrawable(i)); - if (geometry) - { - if () TODO Compare vertex array length and normal array length + normal binding. - { - // generate normals - osgUtil::SmoothingVisitor smoother; - smoother.smooth(*geometry); - } - } - } - } - } -#endif -} - -/** Need to share stateset before merging geodes. - */ -class GeodeStateOptimizer : public osgUtil::Optimizer::StateVisitor -{ - public: - - GeodeStateOptimizer(): - osgUtil::Optimizer::StateVisitor() {} - - void optimize(osg::Group& group) - { - for (unsigned int i=0; igetStateSet(),geode); - } - } - - osgUtil::Optimizer::StateVisitor::optimize(); - } - - -}; - - -void Optimizer::MergeGeodesVisitor::apply(osg::Group& group) -{ - mergeGeodes(group); - traverse(group); -} - - -// Requires shared stateset to work. Run GeodeStateOptimizer before MergeGeodesVisitor. -struct LessGeode -{ - bool operator() (const osg::Geode* lhs,const osg::Geode* rhs) const - { - if (lhs->getStateSet()getStateSet()) return true; -// if (rhs->getStateSet()getStateSet()) return false; - return false; - } -}; - -void Optimizer::MergeGeodesVisitor::mergeGeodes(osg::Group& group) -{ - { - GeodeStateOptimizer gsopt; - gsopt.optimize(group); - } - - typedef std::vector DuplicateList; - typedef std::map GeodeDuplicateMap; - - GeodeDuplicateMap geodeDuplicateMap; - - for (unsigned int i=0; isecond.size()>1) - { - osg::Geode* lhs = itr->second[0]; - for(DuplicateList::iterator dupItr=itr->second.begin()+1; - dupItr!=itr->second.end(); - ++dupItr) - { - osg::Geode* rhs = *dupItr; - - if (mergeGeode(*lhs,*rhs)) - { - group.removeChild(rhs); - - static int co = 0; - osg::notify(osg::INFO)<<"merged and removed Geode "<<++co< -#include -#include -#include - -#include -#include -#include -#include - -// Must undefine IN and OUT macros defined in Windows headers -#ifdef IN -#undef IN -#endif -#ifdef OUT -#undef OUT -#endif - -BEGIN_ENUM_REFLECTOR(osgSim::Optimizer::OptimizationOptions) - I_DeclaringFile("osgSim/OpenFlightOptimizer"); - I_EnumLabel(osgSim::Optimizer::TESSELLATE_POLYGON); - I_EnumLabel(osgSim::Optimizer::MERGE_GEODES); - I_EnumLabel(osgSim::Optimizer::MAKE_LIT); - I_EnumLabel(osgSim::Optimizer::DEFAULT_OPTIMIZATIONS); - I_EnumLabel(osgSim::Optimizer::ALL_OPTIMIZATIONS); -END_REFLECTOR - -BEGIN_VALUE_REFLECTOR(osgSim::Optimizer) - I_DeclaringFile("osgSim/OpenFlightOptimizer"); - I_Constructor0(____Optimizer, - "", - ""); - I_Method1(void, optimize, IN, osg::Node *, node, - Properties::NON_VIRTUAL, - __void__optimize__osg_Node_P1, - "Traverse the node and its subgraph with a series of optimization visitors, specified by the OptimizationOptions. ", - ""); - I_Method2(void, optimize, IN, osg::Node *, node, IN, unsigned int, options, - Properties::VIRTUAL, - __void__optimize__osg_Node_P1__unsigned_int, - "Traverse the node and its subgraph with a series of optimization visitors, specified by the OptimizationOptions. ", - ""); -END_REFLECTOR - -BEGIN_OBJECT_REFLECTOR(osgSim::Optimizer::MakeLitVisitor) - I_DeclaringFile("osgSim/OpenFlightOptimizer"); - I_BaseType(osg::NodeVisitor); - I_Constructor0(____MakeLitVisitor, - "default to traversing all children. ", - ""); - I_Method1(void, apply, IN, osg::Geode &, geode, - Properties::VIRTUAL, - __void__apply__osg_Geode_R1, - "", - ""); -END_REFLECTOR - -BEGIN_OBJECT_REFLECTOR(osgSim::Optimizer::MergeGeodesVisitor) - I_DeclaringFile("osgSim/OpenFlightOptimizer"); - I_BaseType(osg::NodeVisitor); - I_Constructor0(____MergeGeodesVisitor, - "default to traversing all children. ", - ""); - I_Method1(void, apply, IN, osg::Group &, group, - Properties::VIRTUAL, - __void__apply__osg_Group_R1, - "", - ""); - I_Method1(void, mergeGeodes, IN, osg::Group &, group, - Properties::NON_VIRTUAL, - __void__mergeGeodes__osg_Group_R1, - "", - ""); - I_ProtectedMethod2(bool, mergeGeode, IN, osg::Geode &, lhs, IN, osg::Geode &, rhs, - Properties::NON_VIRTUAL, - Properties::NON_CONST, - __bool__mergeGeode__osg_Geode_R1__osg_Geode_R1, - "", - ""); -END_REFLECTOR - -BEGIN_OBJECT_REFLECTOR(osgSim::Optimizer::TessellateVisitor) - I_DeclaringFile("osgSim/OpenFlightOptimizer"); - I_BaseType(osg::NodeVisitor); - I_Constructor0(____TessellateVisitor, - "default to traversing all children. ", - ""); - I_Method1(void, apply, IN, osg::Geode &, geode, - Properties::VIRTUAL, - __void__apply__osg_Geode_R1, - "", - ""); - I_ProtectedMethod1(bool, hasPolygons, IN, osg::Geometry &, geometry, - Properties::NON_VIRTUAL, - Properties::NON_CONST, - __bool__hasPolygons__osg_Geometry_R1, - "", - ""); -END_REFLECTOR -