Updates to osgdem + BoundingBox to support graph iterators
This commit is contained in:
@@ -718,12 +718,21 @@ DataSet::DestinationTile::DestinationTile():
|
||||
|
||||
void DataSet::DestinationTile::computeMaximumSourceResolution(CompositeSource* sourceGraph)
|
||||
{
|
||||
for(CompositeSource::iterator itr(sourceGraph);itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(sourceGraph);itr.valid();++itr)
|
||||
{
|
||||
|
||||
SourceData* data = (*itr)->getSourceData();
|
||||
if (data && (*itr)->getType()!=Source::MODEL)
|
||||
{
|
||||
|
||||
SpatialProperties sp = data->computeSpatialProperties(_cs.get());
|
||||
|
||||
if (!sp._extents.intersects(data->getExtents(_cs.get())))
|
||||
{
|
||||
std::cout<<"DataSet::DestinationTile::computeMaximumSourceResolution:: source does not overlap ignoring for this tile."<<std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (sp._numValuesX!=0 && sp._numValuesY!=0)
|
||||
{
|
||||
@@ -1222,7 +1231,7 @@ osg::Node* DataSet::DestinationTile::createScene()
|
||||
|
||||
void DataSet::DestinationTile::readFrom(CompositeSource* sourceGraph)
|
||||
{
|
||||
for(CompositeSource::iterator itr(sourceGraph);itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(sourceGraph);itr.valid();++itr)
|
||||
{
|
||||
SourceData* data = (*itr)->getSourceData();
|
||||
if (data)
|
||||
@@ -1351,7 +1360,7 @@ void DataSet::addSource(CompositeSource* composite)
|
||||
|
||||
void DataSet::loadSources()
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
(*itr)->loadSourceData();
|
||||
}
|
||||
@@ -1363,7 +1372,7 @@ void DataSet::computeDestinationGraphFromSources()
|
||||
// ensure we have a valid coordinate system
|
||||
if (!_coordinateSystem)
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
SourceData* sd = (*itr)->getSourceData();
|
||||
if (sd)
|
||||
@@ -1382,7 +1391,7 @@ void DataSet::computeDestinationGraphFromSources()
|
||||
osg::BoundingBox extents(_extents);
|
||||
if (!extents.valid())
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
SourceData* sd = (*itr)->getSourceData();
|
||||
if (sd) extents.expandBy(sd->getExtents(_coordinateSystem.get()));
|
||||
@@ -1528,22 +1537,53 @@ void DataSet::CompositeSource::sort()
|
||||
{
|
||||
(*itr)->sort();
|
||||
}
|
||||
|
||||
// source the sources themselves
|
||||
std::sort(_children.begin(),_children.end(),DerefLessFunctor< osg::ref_ptr<CompositeSource> >());
|
||||
|
||||
}
|
||||
|
||||
void DataSet::updateSourcesForDestinationGraphNeeds()
|
||||
{
|
||||
|
||||
std::cout<<"Using Source Iterator itr"<<std::endl;
|
||||
for(CompositeSource::iterator csitr(_sourceGraph.get());csitr.valid();++csitr)
|
||||
std::cout<<"Using source_iterator itr"<<std::endl;
|
||||
for(CompositeSource::source_iterator csitr(_sourceGraph.get());csitr.valid();++csitr)
|
||||
{
|
||||
std::cout<<" Source "<<(*csitr)->getFileName()<<std::endl;
|
||||
}
|
||||
std::cout<<"End of Using Source Iterator itr"<<std::endl;
|
||||
|
||||
std::cout<<"Using Iterator itr"<<std::endl;
|
||||
for(CompositeSource::iterator csitr(_sourceGraph.get());csitr.valid();++csitr)
|
||||
{
|
||||
std::cout<<" Composite Source"<<&(*csitr)<<std::endl;
|
||||
for(CompositeSource::SourceList::iterator itr=csitr->_sourceList.begin();
|
||||
itr!=csitr->_sourceList.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout<<" Source "<<(*itr)->getFileName()<<" res="<<(*itr)->getSortValue()<<std::endl;
|
||||
}
|
||||
csitr->setType(LEVEL_OF_DETAIL);
|
||||
}
|
||||
std::cout<<"End of Source Iterator itr"<<std::endl;
|
||||
|
||||
{
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
Source* source = itr->get();
|
||||
source->setSortValueFromSourceDataResolution();
|
||||
std::cout<<"sort "<<source->getFileName()<<" value "<<source->getSortValue()<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
// sort them so highest sortValue is first.
|
||||
|
||||
_sourceGraph->sort();
|
||||
}
|
||||
|
||||
std::cout<<"Using source_lod_iterator itr"<<std::endl;
|
||||
for(CompositeSource::source_lod_iterator csitr(_sourceGraph.get(),CompositeSource::LODSourceAdvancer(0.0));csitr.valid();++csitr)
|
||||
{
|
||||
std::cout<<" LOD "<<(*csitr)->getFileName()<<std::endl;
|
||||
}
|
||||
std::cout<<"End of Using Source Iterator itr"<<std::endl;
|
||||
|
||||
|
||||
|
||||
std::string temporyFilePrefix("temporaryfile_");
|
||||
@@ -1551,7 +1591,7 @@ void DataSet::updateSourcesForDestinationGraphNeeds()
|
||||
// do standardisation of coordinates systems.
|
||||
// do any reprojection if required.
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
Source* source = itr->get();
|
||||
if (source->needReproject(_coordinateSystem.get()))
|
||||
@@ -1569,7 +1609,7 @@ void DataSet::updateSourcesForDestinationGraphNeeds()
|
||||
|
||||
// do sampling of data to required values.
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
Source* source = itr->get();
|
||||
source->buildOverviews();
|
||||
@@ -1578,7 +1618,7 @@ void DataSet::updateSourcesForDestinationGraphNeeds()
|
||||
|
||||
// sort the sources so that the lowest res tiles are drawn first.
|
||||
{
|
||||
for(CompositeSource::iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr)
|
||||
{
|
||||
Source* source = itr->get();
|
||||
source->setSortValueFromSourceDataResolution();
|
||||
@@ -1591,6 +1631,12 @@ void DataSet::updateSourcesForDestinationGraphNeeds()
|
||||
_sourceGraph->sort();
|
||||
}
|
||||
|
||||
std::cout<<"Using source_lod_iterator itr"<<std::endl;
|
||||
for(CompositeSource::source_lod_iterator csitr(_sourceGraph.get(),CompositeSource::LODSourceAdvancer(0.0));csitr.valid();++csitr)
|
||||
{
|
||||
std::cout<<" LOD "<<(*csitr)->getFileName()<<std::endl;
|
||||
}
|
||||
std::cout<<"End of Using Source Iterator itr"<<std::endl;
|
||||
}
|
||||
|
||||
void DataSet::populateDestinationGraphFromSources()
|
||||
|
||||
@@ -219,29 +219,35 @@ class DataSet : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
CompositeSource() {};
|
||||
CompositeSource(CompositeType type=GROUP):_type(type) {};
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Source> > SourceList;
|
||||
typedef std::vector< osg::ref_ptr< CompositeSource> > ChildList;
|
||||
|
||||
void setSortValue(double s) { _sortValue = s; }
|
||||
double getSortValue() const { return _sortValue; }
|
||||
void setType(CompositeType type) { _type = type; }
|
||||
CompositeType getType() const { return _type; }
|
||||
|
||||
void setSortValueFromSourceDataResolution();
|
||||
|
||||
void sort();
|
||||
void sort();
|
||||
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
|
||||
enum IteratorMode
|
||||
{
|
||||
ACTIVE,
|
||||
ALL
|
||||
};
|
||||
|
||||
|
||||
iterator(CompositeSource* composite)
|
||||
iterator(CompositeSource* composite=0,IteratorMode mode=ALL):
|
||||
_iteratorMode(mode)
|
||||
{
|
||||
if (composite)
|
||||
{
|
||||
_positionStack.push_back(IteratorPosition(composite));
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,21 +260,41 @@ class DataSet : public osg::Referenced
|
||||
_positionStack = rhs._positionStack;
|
||||
}
|
||||
|
||||
bool operator == (const iterator& rhs) const
|
||||
{
|
||||
return _positionStack == rhs._positionStack;
|
||||
}
|
||||
|
||||
bool operator != (const iterator& rhs) const
|
||||
{
|
||||
return _positionStack != rhs._positionStack;
|
||||
}
|
||||
|
||||
bool valid() const
|
||||
{
|
||||
return !_positionStack.empty() && _positionStack.back().valid();
|
||||
}
|
||||
|
||||
osg::ref_ptr<Source>& operator *()
|
||||
CompositeSource& operator *()
|
||||
{
|
||||
return valid()?_positionStack.back().currentSource():_nullSource;
|
||||
return *(valid()?_positionStack.back().current():0);
|
||||
}
|
||||
|
||||
osg::ref_ptr<Source>* operator ->()
|
||||
CompositeSource* operator ->()
|
||||
{
|
||||
return valid()?&(_positionStack.back().currentSource()):&_nullSource;
|
||||
return valid()?_positionStack.back().current():0;
|
||||
}
|
||||
|
||||
const CompositeSource& operator *() const
|
||||
{
|
||||
return *(valid()?_positionStack.back().current():0);
|
||||
}
|
||||
|
||||
const CompositeSource* operator ->() const
|
||||
{
|
||||
return valid()?_positionStack.back().current():0;
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
advance();
|
||||
@@ -289,17 +315,13 @@ class DataSet : public osg::Referenced
|
||||
// simple advance to the next source
|
||||
if (_positionStack.back().advance())
|
||||
{
|
||||
if (_positionStack.back().currentSource().valid()) return true;
|
||||
|
||||
if (_positionStack.back().currentChild())
|
||||
if (_positionStack.back().current())
|
||||
{
|
||||
std::cout<<"Pushing IteratorPosition"<<std::endl;
|
||||
_positionStack.push_back(IteratorPosition(_positionStack.back().currentChild()));
|
||||
_positionStack.push_back(IteratorPosition(_positionStack.back().current()));
|
||||
return advance();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<<"Popping IteratorPosition"<<std::endl;
|
||||
_positionStack.pop_back();
|
||||
return advance();
|
||||
}
|
||||
@@ -325,55 +347,221 @@ class DataSet : public osg::Referenced
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<Source>& currentSource()
|
||||
bool operator == (const IteratorPosition& rhs) const
|
||||
{
|
||||
return (_index>=0 && _index < (int)_composite->_sourceList.size())?_composite->_sourceList[_index]:_nullSource;
|
||||
return _composite == rhs._composite && _index == rhs._index;
|
||||
}
|
||||
|
||||
bool operator != (const IteratorPosition& rhs) const
|
||||
{
|
||||
return _composite != rhs._composite || _index != rhs._index;
|
||||
}
|
||||
|
||||
CompositeSource* currentChild()
|
||||
CompositeSource* current()
|
||||
{
|
||||
return (_index < (int)_composite->_sourceList.size())?0:
|
||||
(_index-_composite->_sourceList.size() < _composite->_children.size())?(_composite->_children[_index-_composite->_sourceList.size()].get()):0;
|
||||
if (_index==-1) return _composite;
|
||||
else return (_index>=0 && _index < (int)_composite->_children.size())?_composite->_children[_index].get():0;
|
||||
}
|
||||
|
||||
const CompositeSource* current() const
|
||||
{
|
||||
if (_index==-1) return _composite;
|
||||
else return (_index>=0 && _index < (int)_composite->_children.size())?_composite->_children[_index].get():0;
|
||||
}
|
||||
|
||||
bool valid() const
|
||||
{
|
||||
return _composite &&
|
||||
_index >= 0 &&
|
||||
_index < (int)(_composite->_sourceList.size()+_composite->_children.size());
|
||||
_index < (int)_composite->_children.size();
|
||||
}
|
||||
|
||||
bool advance()
|
||||
inline bool advance()
|
||||
{
|
||||
if (_index+1 < (int)(_composite->_sourceList.size()+_composite->_children.size()))
|
||||
return advanceToNextChild(*_composite,_index);
|
||||
|
||||
// if (_index+1 < (int)_composite->_children.size())
|
||||
// {
|
||||
// ++_index;
|
||||
// return valid();
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
inline bool isActive(const CompositeSource& composite,int index)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool advanceToNextChild(CompositeSource& composite, int& index)
|
||||
{
|
||||
++index;
|
||||
while (index<(int)composite._children.size())
|
||||
{
|
||||
++_index;
|
||||
return valid();
|
||||
if (isActive(composite,index)) return true;
|
||||
++index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CompositeSource* _composite;
|
||||
int _index;
|
||||
osg::ref_ptr<Source> _nullSource;
|
||||
};
|
||||
|
||||
typedef std::vector<IteratorPosition> PositionStack;
|
||||
PositionStack _positionStack;
|
||||
osg::ref_ptr<Source> _nullSource;
|
||||
IteratorMode _iteratorMode;
|
||||
PositionStack _positionStack;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
class base_source_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
base_source_iterator(CompositeSource* composite=0, T advancer=T()):
|
||||
_advancer(advancer),
|
||||
_compositeIterator(composite),
|
||||
_sourceIndex(-1)
|
||||
{
|
||||
advance();
|
||||
}
|
||||
|
||||
base_source_iterator(const base_source_iterator& rhs):
|
||||
_advancer(rhs._advancer),
|
||||
_compositeIterator(rhs._compositeIterator),
|
||||
_sourceIndex(rhs._sourceIndex) {}
|
||||
|
||||
base_source_iterator& operator = (const base_source_iterator& rhs)
|
||||
{
|
||||
if (&rhs==this) return *this;
|
||||
_advancer = rhs._advancer;
|
||||
_compositeIterator = rhs._compositeIterator;
|
||||
_sourceIndex = rhs._sourceIndex;
|
||||
}
|
||||
|
||||
bool operator == (const base_source_iterator& rhs) const
|
||||
{
|
||||
return _compositeIterator == rhs._compositeIterator &&
|
||||
_sourceIndex == rhs._sourceIndex;
|
||||
}
|
||||
|
||||
bool operator != (const base_source_iterator& rhs) const
|
||||
{
|
||||
return _compositeIterator != rhs._compositeIterator ||
|
||||
_sourceIndex != rhs._sourceIndex;
|
||||
}
|
||||
|
||||
bool valid() const
|
||||
{
|
||||
return _compositeIterator.valid() && _sourceIndex < (int)_compositeIterator->_sourceList.size();
|
||||
}
|
||||
|
||||
osg::ref_ptr<Source>& operator *()
|
||||
{
|
||||
return valid()?_compositeIterator->_sourceList[_sourceIndex]:_nullSource;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Source>* operator ->()
|
||||
{
|
||||
return &(valid()?_compositeIterator->_sourceList[_sourceIndex]:_nullSource);
|
||||
}
|
||||
|
||||
base_source_iterator& operator++()
|
||||
{
|
||||
advance();
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_source_iterator operator++(int)
|
||||
{
|
||||
base_source_iterator tmp=*this;
|
||||
advance();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool advance()
|
||||
{
|
||||
if (!_compositeIterator.valid()) return false;
|
||||
|
||||
if (_advancer.advanceToNextSource(*_compositeIterator,_sourceIndex)) return true;
|
||||
|
||||
// at end of current CompositeSource, so need to advance to new one.
|
||||
_sourceIndex = -1;
|
||||
++_compositeIterator;
|
||||
return advance();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
T _advancer;
|
||||
iterator _compositeIterator;
|
||||
int _sourceIndex;
|
||||
osg::ref_ptr<Source> _nullSource;
|
||||
|
||||
};
|
||||
|
||||
struct DefaultSourceAdvancer
|
||||
{
|
||||
DefaultSourceAdvancer() {}
|
||||
|
||||
bool isActive(const CompositeSource& composite,int index)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool advanceToNextSource(const CompositeSource& composite, int& index)
|
||||
{
|
||||
return ++index<(int)composite._sourceList.size();
|
||||
}
|
||||
};
|
||||
|
||||
struct LODSourceAdvancer
|
||||
{
|
||||
LODSourceAdvancer(float targetResolution=0.0f):
|
||||
_targetResolution(targetResolution) {}
|
||||
|
||||
inline bool advanceToNextSource(const CompositeSource& composite, int& index)
|
||||
{
|
||||
if (composite.getType()==GROUP)
|
||||
{
|
||||
return (++index<(int)composite._sourceList.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (composite._sourceList.empty()) return false;
|
||||
if (index!=-1) return false; // we've already traversed this composite, only ever one valid LOD.
|
||||
|
||||
// find source with resolution closest to target
|
||||
int foundIndex = 0;
|
||||
float closestResolution = fabsf(composite._sourceList[0]->getSortValue()-_targetResolution);
|
||||
for(int i=1;i<(int)composite._sourceList.size();++i)
|
||||
{
|
||||
float delta = fabsf(composite._sourceList[i]->getSortValue()-_targetResolution);
|
||||
if (delta<closestResolution)
|
||||
{
|
||||
foundIndex = i;
|
||||
closestResolution = delta;
|
||||
}
|
||||
}
|
||||
if (foundIndex==index) return false;
|
||||
index = foundIndex;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
float _targetResolution;
|
||||
};
|
||||
|
||||
typedef base_source_iterator<DefaultSourceAdvancer> source_iterator;
|
||||
typedef base_source_iterator<LODSourceAdvancer> source_lod_iterator;
|
||||
|
||||
CompositeType _type;
|
||||
SourceList _sourceList;
|
||||
ChildList _children;
|
||||
float _sortValue;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class DestinationTile : public osg::Referenced, public SpatialProperties
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -170,6 +170,14 @@ class SG_EXPORT BoundingBox
|
||||
|
||||
}
|
||||
|
||||
/** return true if this bounding box with the specified bounding box.*/
|
||||
bool intersects(const BoundingBox& bb) const
|
||||
{ return osg::maximum(xMin(),bb.xMin()) <= osg::minimum(xMax(),bb.xMax()) &&
|
||||
osg::maximum(yMin(),bb.yMin()) <= osg::minimum(yMax(),bb.yMax()) &&
|
||||
osg::maximum(zMin(),bb.zMin()) <= osg::minimum(zMax(),bb.zMax());
|
||||
|
||||
}
|
||||
|
||||
/** return true is vertex v is within the box.*/
|
||||
inline bool contains(const Vec3& v) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user