Commit 036ad863 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #259] using stable sort for texture sorting to handle textures with...

[CHANGE #259] using stable sort for texture sorting to handle textures with the same index properly.
parent 04e3f7bf
......@@ -213,6 +213,26 @@ public:
template < typename Comparator >
void sort( typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp );
/**
* Resorts the container using the specified comparator from its begin to its end. Uses stable sort algorithm.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator().
*
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( Comparator comp );
/**
* Resorts the container using the specified comparator between [first,last) in ascending order. Uses stable sort algorithm.
*
* \param first the first element
* \param last the last element
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp );
/**
* Searches the specified value in the range [first,last).
*
......@@ -380,6 +400,23 @@ void WSharedSequenceContainer< S >::sort( typename WSharedSequenceContainer< S >
return std::sort( first, last, comp );
}
template < typename S >
template < typename Comparator >
void WSharedSequenceContainer< S >::stableSort( Comparator comp )
{
typename WSharedObject< S >::WriteTicket a = WSharedObject< S >::getWriteTicket();
return std::stable_sort( a->get().begin(), a->get().end(), comp );
}
template < typename S >
template < typename Comparator >
void WSharedSequenceContainer< S >::stableSort( typename WSharedSequenceContainer< S >::Iterator first,
typename WSharedSequenceContainer< S >::Iterator last,
Comparator comp )
{
return std::stable_sort( first, last, comp );
}
template < typename S >
typename WSharedSequenceContainer< S >::Iterator WSharedSequenceContainer< S >::find(
typename WSharedSequenceContainer< S >::Iterator first,
......
......@@ -270,7 +270,7 @@ bool sortIndexComparator( osg::ref_ptr< WGETexture3D > a, osg::ref_ptr< WGETextu
void WGEColormapping::sortByIndex()
{
// use sort with custom comparator
sort( &sortIndexComparator );
stableSort( &sortIndexComparator );
}
void WGEColormapping::setSortIndices()
......
......@@ -190,6 +190,15 @@ public:
template < typename Comparator >
void sort( Comparator comp );
/**
* Resorts the texture list using the specified comparator using a stable sorting algorithm.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator().
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( Comparator comp );
/**
* Sort the texture list by the indices that have been stored in each texture's sortIndex.
*/
......@@ -446,5 +455,11 @@ void WGEColormapping::sort( Comparator comp )
m_textures.sort< Comparator >( comp );
}
template < typename Comparator >
void WGEColormapping::stableSort( Comparator comp )
{
m_textures.stableSort< Comparator >( comp );
}
#endif // WGECOLORMAPPING_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment