Files
Work/bsptree/RGBTREE.HPP
2024-08-07 09:12:07 -04:00

99 lines
2.4 KiB
C++

#ifndef _BSPTREE_RGBTREE_HPP_
#define _BSPTREE_RGBTREE_HPP_
#ifndef _COMMON_PALETTEENTRY_HPP_
#include <common/palentry.hpp>
#endif
#ifndef _COMMON_ARRAY_HPP_
#include <common/array.hpp>
#endif
#ifndef _COMMON_SMARTPOINTER_HPP_
#include <common/pointer.hpp>
#endif
#ifndef _BSPTREE_BTREE_HPP_
#include <bsptree/btree.hpp>
#endif
#ifndef _BSPTREE_RGBNDX_HPP_
#include <bsptree/rgbndx.hpp>
#endif
#ifndef _BSPTREE_COLORKEY_HPP_
#include <bsptree/colorkey.hpp>
#endif
#ifndef _BSPTREE_RGBSTACK_HPP_
#include <bsptree/rgbstack.hpp>
#endif
//#ifndef _COMMON_PVECTOR_TPP_
//#include <common/pvector.tpp>
//#endif
#ifndef _BSPTREE_BTREE_TPP_
#include <bsptree/btree.tpp>
#endif
class RGBTree : public BTree<RGBIndex>, private RGBStack
{
public:
enum SearchType{SearchExact,SearchNearest};
RGBTree(void);
virtual ~RGBTree();
WORD insertItems(Array<RGBIndex> &rgbItems);
WORD insertItem(const RGBIndex &rgbItem);
WORD insertItem(const RGBColor &rgbItem);
WORD insertItem(const PaletteEntry &paletteEntryItem);
BOOL searchItem(RGBIndex &rgbItem,SearchType searchType=SearchExact);
BOOL searchItem(RGBColor &rgbColor,SearchType searchType=SearchExact);
BOOL searchItem(RGBIndex &rgbItem,SmartPointer<RGBIndex> &rgbIndex,SearchType searchType=SearchExact);
void setThreshold(WORD threshold);
void deleteTree(void);
private:
enum {DefaultThreshold=10,MaxThreshold=255,CenterColor=128};
TreeNode<RGBIndex> *insertNode(TreeNode<RGBIndex> *lpRootNode,TreeNode<RGBIndex> *lpCurrentNode,const RGBIndex &rgbItem);
RGBIndex *searchNodeExact(TreeNode<RGBIndex> *lpRootNode,const RGBIndex &rgbItem);
RGBIndex *searchNodeNearest(TreeNode<RGBIndex> *lpRootNode,const RGBIndex &rgbItem);
WORD middleIndex(Array<RGBIndex> &rgbItems)const;
Array<RGBIndex> mVectoredColors;
ColorKey mColorKey;
WORD mThreshold;
};
inline
RGBTree::RGBTree(void)
: mThreshold(DefaultThreshold)
{
}
inline
RGBTree::~RGBTree()
{
}
inline
void RGBTree::setThreshold(WORD threshold)
{
mThreshold=threshold;
}
inline
void RGBTree::deleteTree(void)
{
remove();
}
inline
WORD RGBTree::insertItem(const RGBColor &rgbItem)
{
RGBIndex rgbIndex(rgbItem);
return insertItem(rgbIndex);
}
inline
WORD RGBTree::insertItem(const PaletteEntry &paletteEntryItem)
{
RGBIndex rgbIndex;
rgbIndex.red(paletteEntryItem.red());
rgbIndex.green(paletteEntryItem.green());
rgbIndex.blue(paletteEntryItem.blue());
return insertItem(rgbIndex);
}
#endif