Skip to content

Commit

Permalink
sort blocks from biggest to smallest (in terms of their segment count…
Browse files Browse the repository at this point in the history
…s) before doing greedy extend)
  • Loading branch information
glennhickey committed Apr 19, 2013
1 parent f820f9b commit f7f0af5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lod/impl/halLodGraph.cpp
Expand Up @@ -254,6 +254,11 @@ void LodGraph::computeAdjacencies()

void LodGraph::optimizeByExtension()
{
// Put bigger blocks first because (we hope) they tend to represent
// more information and we'd rather extend them than, say, a block
// that represents a little insertion.
std::sort(_blocks.begin(), _blocks.end(), LodBlockPBigger());

for (BlockIterator bi = _blocks.begin(); bi != _blocks.end(); ++bi)
{
(*bi)->extend();
Expand Down
12 changes: 12 additions & 0 deletions lod/inc/halLodBlock.h
Expand Up @@ -22,6 +22,11 @@ class LodBlock;

std::ostream& operator<<(std::ostream& os, const LodBlock& block);

struct LodBlockPBigger
{
bool operator()(const LodBlock* b1, const LodBlock* b2) const;
};

/* A block is a list of homolgous segments. All these segments must
* be the same length. The block's destructor will free all segments
* it contains.
Expand Down Expand Up @@ -98,6 +103,13 @@ class LodBlock
const LodBlock& operator=(const LodBlock&) const;
};

inline bool LodBlockPBigger::operator()(const LodBlock* b1,
const LodBlock* b2) const
{
bool bigger = b1->getNumSegments() > b2->getNumSegments();
return bigger;
}

inline hal_size_t LodBlock::getNumSegments() const
{
return _segments.size();
Expand Down

0 comments on commit f7f0af5

Please sign in to comment.