Commit 89b80b2b authored by Maciej Suminski's avatar Maciej Suminski

Merged rtree.h, to avoid code duplication.

Fixes the case, when waste is never greater then the worst case and seeds assignment does not occur.
parent 17980792
...@@ -153,10 +153,12 @@ struct queryVisitor ...@@ -153,10 +153,12 @@ struct queryVisitor
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
if( aItem->ViewIsVisible() ) if( aItem->ViewIsVisible() )
m_cont.push_back( VIEW::LAYER_ITEM_PAIR( aItem, m_layer ) ); m_cont.push_back( VIEW::LAYER_ITEM_PAIR( aItem, m_layer ) );
return true;
} }
Container& m_cont; Container& m_cont;
...@@ -387,7 +389,7 @@ struct VIEW::updateItemsColor ...@@ -387,7 +389,7 @@ struct VIEW::updateItemsColor
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
// Obtain the color that should be used for coloring the item // Obtain the color that should be used for coloring the item
const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer ); const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer );
...@@ -395,6 +397,8 @@ struct VIEW::updateItemsColor ...@@ -395,6 +397,8 @@ struct VIEW::updateItemsColor
if( group >= 0 ) if( group >= 0 )
gal->ChangeGroupColor( group, color ); gal->ChangeGroupColor( group, color );
return true;
} }
int layer; int layer;
...@@ -447,12 +451,14 @@ struct VIEW::changeItemsDepth ...@@ -447,12 +451,14 @@ struct VIEW::changeItemsDepth
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
int group = aItem->getGroup( layer ); int group = aItem->getGroup( layer );
if( group >= 0 ) if( group >= 0 )
gal->ChangeGroupDepth( group, depth ); gal->ChangeGroupDepth( group, depth );
return true;
} }
int layer, depth; int layer, depth;
...@@ -571,15 +577,17 @@ struct VIEW::drawItem ...@@ -571,15 +577,17 @@ struct VIEW::drawItem
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
// Conditions that have te be fulfilled for an item to be drawn // Conditions that have te be fulfilled for an item to be drawn
bool drawCondition = aItem->ViewIsVisible() && bool drawCondition = aItem->ViewIsVisible() &&
aItem->ViewGetLOD( currentLayer->id ) < view->m_scale; aItem->ViewGetLOD( currentLayer->id ) < view->m_scale;
if( !drawCondition ) if( !drawCondition )
return; return true;
view->draw( aItem, currentLayer->id ); view->draw( aItem, currentLayer->id );
return true;
} }
const VIEW_LAYER* currentLayer; const VIEW_LAYER* currentLayer;
...@@ -676,9 +684,11 @@ bool VIEW::IsDirty() const ...@@ -676,9 +684,11 @@ bool VIEW::IsDirty() const
struct VIEW::unlinkItem struct VIEW::unlinkItem
{ {
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
aItem->m_view = NULL; aItem->m_view = NULL;
return true;
} }
}; };
...@@ -690,7 +700,7 @@ struct VIEW::recacheItem ...@@ -690,7 +700,7 @@ struct VIEW::recacheItem
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
// Remove previously cached group // Remove previously cached group
int prevGroup = aItem->getGroup( layer ); int prevGroup = aItem->getGroup( layer );
...@@ -712,6 +722,8 @@ struct VIEW::recacheItem ...@@ -712,6 +722,8 @@ struct VIEW::recacheItem
{ {
aItem->setGroup( layer, -1 ); aItem->setGroup( layer, -1 );
} }
return true;
} }
VIEW* view; VIEW* view;
...@@ -792,12 +804,14 @@ struct VIEW::clearLayerCache ...@@ -792,12 +804,14 @@ struct VIEW::clearLayerCache
{ {
} }
void operator()( VIEW_ITEM* aItem ) bool operator()( VIEW_ITEM* aItem )
{ {
if( aItem->storesGroups() ) if( aItem->storesGroups() )
{ {
aItem->deleteGroups(); aItem->deleteGroups();
} }
return true;
} }
VIEW* view; VIEW* view;
......
...@@ -163,7 +163,7 @@ public: ...@@ -163,7 +163,7 @@ public:
/// Calculate Statistics /// Calculate Statistics
Statistics CalcStats( ); Statistics CalcStats();
/// Remove all entries from tree /// Remove all entries from tree
void RemoveAll(); void RemoveAll();
...@@ -396,7 +396,7 @@ protected: ...@@ -396,7 +396,7 @@ protected:
bool IsInternalNode() { return m_level > 0; } // Not a leaf, but a internal node bool IsInternalNode() { return m_level > 0; } // Not a leaf, but a internal node
bool IsLeaf() { return m_level == 0; } // A leaf, contains data bool IsLeaf() { return m_level == 0; } // A leaf, contains data
int m_count; ///< Count int m_count; ///< Count
int m_level; ///< Leaf is zero, others positive int m_level; ///< Leaf is zero, others positive
Branch m_branch[MAXNODES]; ///< Branch Branch m_branch[MAXNODES]; ///< Branch
}; };
...@@ -830,18 +830,18 @@ RTREE_TEMPLATE ...@@ -830,18 +830,18 @@ RTREE_TEMPLATE
bool RTREE_QUAL::Load( RTFileStream& a_stream ) bool RTREE_QUAL::Load( RTFileStream& a_stream )
{ {
// Write some kind of header // Write some kind of header
int _dataFileId = ('R' << 0) | ('T' << 8) | ('R' << 16) | ('E' << 24); int _dataFileId = ('R' << 0) | ('T' << 8) | ('R' << 16) | ('E' << 24);
int _dataSize = sizeof(DATATYPE); int _dataSize = sizeof(DATATYPE);
int _dataNumDims = NUMDIMS; int _dataNumDims = NUMDIMS;
int _dataElemSize = sizeof(ELEMTYPE); int _dataElemSize = sizeof(ELEMTYPE);
int _dataElemRealSize = sizeof(ELEMTYPEREAL); int _dataElemRealSize = sizeof(ELEMTYPEREAL);
int _dataMaxNodes = TMAXNODES; int _dataMaxNodes = TMAXNODES;
int _dataMinNodes = TMINNODES; int _dataMinNodes = TMINNODES;
int dataFileId = 0; int dataFileId = 0;
int dataSize = 0; int dataSize = 0;
int dataNumDims = 0; int dataNumDims = 0;
int dataElemSize = 0; int dataElemSize = 0;
int dataElemRealSize = 0; int dataElemRealSize = 0;
int dataMaxNodes = 0; int dataMaxNodes = 0;
int dataMinNodes = 0; int dataMinNodes = 0;
...@@ -932,10 +932,10 @@ RTREE_TEMPLATE ...@@ -932,10 +932,10 @@ RTREE_TEMPLATE
bool RTREE_QUAL::Save( RTFileStream& a_stream ) bool RTREE_QUAL::Save( RTFileStream& a_stream )
{ {
// Write some kind of header // Write some kind of header
int dataFileId = ('R' << 0) | ('T' << 8) | ('R' << 16) | ('E' << 24); int dataFileId = ('R' << 0) | ('T' << 8) | ('R' << 16) | ('E' << 24);
int dataSize = sizeof(DATATYPE); int dataSize = sizeof(DATATYPE);
int dataNumDims = NUMDIMS; int dataNumDims = NUMDIMS;
int dataElemSize = sizeof(ELEMTYPE); int dataElemSize = sizeof(ELEMTYPE);
int dataElemRealSize = sizeof(ELEMTYPEREAL); int dataElemRealSize = sizeof(ELEMTYPEREAL);
int dataMaxNodes = TMAXNODES; int dataMaxNodes = TMAXNODES;
int dataMinNodes = TMINNODES; int dataMinNodes = TMINNODES;
...@@ -1293,20 +1293,20 @@ int RTREE_QUAL::PickBranch( Rect* a_rect, Node* a_node ) ...@@ -1293,20 +1293,20 @@ int RTREE_QUAL::PickBranch( Rect* a_rect, Node* a_node )
for( int index = 0; index < a_node->m_count; ++index ) for( int index = 0; index < a_node->m_count; ++index )
{ {
Rect* curRect = &a_node->m_branch[index].m_rect; Rect* curRect = &a_node->m_branch[index].m_rect;
area = CalcRectVolume( curRect ); area = CalcRectVolume( curRect );
tempRect = CombineRect( a_rect, curRect ); tempRect = CombineRect( a_rect, curRect );
increase = CalcRectVolume( &tempRect ) - area; increase = CalcRectVolume( &tempRect ) - area;
if( (increase < bestIncr) || firstTime ) if( (increase < bestIncr) || firstTime )
{ {
best = index; best = index;
bestArea = area; bestArea = area;
bestIncr = increase; bestIncr = increase;
firstTime = false; firstTime = false;
} }
else if( (increase == bestIncr) && (area < bestArea) ) else if( (increase == bestIncr) && (area < bestArea) )
{ {
best = index; best = index;
bestArea = area; bestArea = area;
bestIncr = increase; bestIncr = increase;
} }
...@@ -1594,8 +1594,8 @@ void RTREE_QUAL::InitParVars( PartitionVars* a_parVars, int a_maxRects, int a_mi ...@@ -1594,8 +1594,8 @@ void RTREE_QUAL::InitParVars( PartitionVars* a_parVars, int a_maxRects, int a_mi
for( int index = 0; index < a_maxRects; ++index ) for( int index = 0; index < a_maxRects; ++index )
{ {
a_parVars->m_taken[index] = false; a_parVars->m_taken[index] = false;
a_parVars->m_partition[index] = -1; a_parVars->m_partition[index] = -1;
} }
} }
...@@ -1622,7 +1622,7 @@ void RTREE_QUAL::PickSeeds( PartitionVars* a_parVars ) ...@@ -1622,7 +1622,7 @@ void RTREE_QUAL::PickSeeds( PartitionVars* a_parVars )
&a_parVars->m_branchBuf[indexB].m_rect ); &a_parVars->m_branchBuf[indexB].m_rect );
waste = CalcRectVolume( &oneRect ) - area[indexA] - area[indexB]; waste = CalcRectVolume( &oneRect ) - area[indexA] - area[indexB];
if( waste > worst ) if( waste >= worst )
{ {
worst = waste; worst = waste;
seed0 = indexA; seed0 = indexA;
...@@ -1856,8 +1856,6 @@ bool RTREE_QUAL::Search( Node* a_node, Rect* a_rect, int& a_foundCount, bool a_r ...@@ -1856,8 +1856,6 @@ bool RTREE_QUAL::Search( Node* a_node, Rect* a_rect, int& a_foundCount, bool a_r
} }
//calculate the minimum distance between a point and a rectangle as defined by Manolopoulos et al. //calculate the minimum distance between a point and a rectangle as defined by Manolopoulos et al.
//it uses the square distance to avoid the use of ELEMTYPEREAL values, which are slower. //it uses the square distance to avoid the use of ELEMTYPEREAL values, which are slower.
RTREE_TEMPLATE RTREE_TEMPLATE
......
This diff is collapsed.
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <math/box2.h> #include <math/box2.h>
#include <rtree.h> #include <geometry/rtree.h>
namespace KIGFX namespace KIGFX
{ {
...@@ -76,7 +76,6 @@ public: ...@@ -76,7 +76,6 @@ public:
* Executes a function object aVisitor for each item whose bounding box intersects * Executes a function object aVisitor for each item whose bounding box intersects
* with aBounds. * with aBounds.
*/ */
template <class Visitor> template <class Visitor>
void Query( const BOX2I& aBounds, Visitor& aVisitor ) // const void Query( const BOX2I& aBounds, Visitor& aVisitor ) // const
{ {
......
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