Removed redundent OpenFlightOptimizer
This commit is contained in:
parent
df2f9f5f7c
commit
457d3fd7e4
@ -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 <osg/NodeVisitor>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geometry>
|
||||
|
||||
#include <osgSim/Export>
|
||||
|
||||
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
|
@ -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
|
||||
|
@ -1,240 +0,0 @@
|
||||
//
|
||||
// OpenFlight® loader for OpenSceneGraph
|
||||
//
|
||||
// Copyright (C) 2005-2006 Brede Johansen
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osgSim/OpenFlightOptimizer>
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/Geode>
|
||||
|
||||
#include <osgUtil/Tessellator>
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
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"<<std::endl;
|
||||
|
||||
TessellateVisitor visitor;
|
||||
node->accept(visitor);
|
||||
}
|
||||
|
||||
if (options & MAKE_LIT)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"osgFlightUtil::Optimizer::optimize() doing MAKE_LIT"<<std::endl;
|
||||
|
||||
MakeLitVisitor visitor;
|
||||
node->accept(visitor);
|
||||
}
|
||||
|
||||
if (options & MERGE_GEODES)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"osgFlightUtil::Optimizer::optimize() doing MERGE_GEODES"<<std::endl;
|
||||
|
||||
MergeGeodesVisitor visitor;
|
||||
node->accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Optimizer::TessellateVisitor::apply(osg::Geode& geode)
|
||||
{
|
||||
for (unsigned int i=0; i<geode.getNumDrawables(); ++i)
|
||||
{
|
||||
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(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; i<geometry.getNumPrimitiveSets(); ++i)
|
||||
{
|
||||
if (geometry.getPrimitiveSet(i)->getMode() == 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.getNumDrawables(); ++i)
|
||||
{
|
||||
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(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; i<group.getNumChildren(); ++i)
|
||||
{
|
||||
osg::Node* child = group.getChild(i);
|
||||
if (typeid(*child)==typeid(osg::Geode))
|
||||
{
|
||||
osg::Geode* geode = (osg::Geode*)child;
|
||||
addStateSet(geode->getStateSet(),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()<rhs->getStateSet()) return true;
|
||||
// if (rhs->getStateSet()<lhs->getStateSet()) return false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void Optimizer::MergeGeodesVisitor::mergeGeodes(osg::Group& group)
|
||||
{
|
||||
{
|
||||
GeodeStateOptimizer gsopt;
|
||||
gsopt.optimize(group);
|
||||
}
|
||||
|
||||
typedef std::vector<osg::Geode*> DuplicateList;
|
||||
typedef std::map<osg::Geode*,DuplicateList,LessGeode> GeodeDuplicateMap;
|
||||
|
||||
GeodeDuplicateMap geodeDuplicateMap;
|
||||
|
||||
for (unsigned int i=0; i<group.getNumChildren(); ++i)
|
||||
{
|
||||
osg::Node* child = group.getChild(i);
|
||||
if (typeid(*child)==typeid(osg::Geode))
|
||||
{
|
||||
osg::Geode* geode = (osg::Geode*)child;
|
||||
geodeDuplicateMap[geode].push_back(geode);
|
||||
}
|
||||
}
|
||||
|
||||
// merge
|
||||
for(GeodeDuplicateMap::iterator itr=geodeDuplicateMap.begin();
|
||||
itr!=geodeDuplicateMap.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.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<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Optimizer::MergeGeodesVisitor::mergeGeode(osg::Geode& lhs, osg::Geode& rhs)
|
||||
{
|
||||
for (unsigned int i=0; i<rhs.getNumDrawables(); ++i)
|
||||
{
|
||||
lhs.addDrawable(rhs.getDrawable(i));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
// ***************************************************************************
|
||||
//
|
||||
// Generated automatically by genwrapper.
|
||||
// Please DO NOT EDIT this file!
|
||||
//
|
||||
// ***************************************************************************
|
||||
|
||||
#include <osgIntrospection/ReflectionMacros>
|
||||
#include <osgIntrospection/TypedMethodInfo>
|
||||
#include <osgIntrospection/StaticMethodInfo>
|
||||
#include <osgIntrospection/Attributes>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
#include <osg/Node>
|
||||
#include <osgSim/OpenFlightOptimizer>
|
||||
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user