Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_TREENODEIMAGE_H__
00009 #define __SP_TREENODEIMAGE_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014
00015 namespace sp
00016 {
00017 namespace scene
00018 {
00019
00020
00032 template <class T> class ImageTreeNode
00033 {
00034
00035 public:
00036
00037 ImageTreeNode() :
00038 ChildA_ (0),
00039 ChildB_ (0),
00040 Image_ (0)
00041 {
00042 }
00043 ImageTreeNode(const dim::size2di &Size) :
00044 Rect_ (0, 0, Size.Width, Size.Height ),
00045 ChildA_ (0 ),
00046 ChildB_ (0 ),
00047 Image_ (0 )
00048 {
00049 }
00050 ImageTreeNode(const dim::rect2di &Rect) :
00051 Rect_ (Rect ),
00052 ChildA_ (0 ),
00053 ChildB_ (0 ),
00054 Image_ (0 )
00055 {
00056 }
00057 ~ImageTreeNode()
00058 {
00059 delete ChildA_;
00060 delete ChildB_;
00061 }
00062
00063
00064
00072 ImageTreeNode<T>* insert(T* Image)
00073 {
00074 if (!Image)
00075 return 0;
00076
00077 if (ChildA_)
00078 {
00079
00080 ImageTreeNode<T>* NewNode = ChildA_->insert(Image);
00081
00082 if (NewNode)
00083 return NewNode;
00084
00085 return ChildB_->insert(Image);
00086 }
00087
00088
00089 const dim::size2di ImageSize(Image->getSize());
00090
00091 if (Image_ || ImageSize.Width > Rect_.getWidth() || ImageSize.Height > Rect_.getHeight())
00092 return 0;
00093
00094
00095 if (ImageSize == Rect_.getSize())
00096 {
00097 Image_ = Image;
00098 Image_->setupTreeNode(this);
00099 return this;
00100 }
00101
00102
00103 ChildA_ = new ImageTreeNode<T>();
00104 ChildB_ = new ImageTreeNode<T>();
00105
00106 if (Rect_.getWidth() - ImageSize.Width > Rect_.getHeight() - ImageSize.Height)
00107 {
00108 ChildA_->Rect_ = dim::rect2di(Rect_.Left, Rect_.Top, Rect_.Left + ImageSize.Width, Rect_.Bottom);
00109 ChildB_->Rect_ = dim::rect2di(Rect_.Left + ImageSize.Width, Rect_.Top, Rect_.Right, Rect_.Bottom);
00110 }
00111 else
00112 {
00113 ChildA_->Rect_ = dim::rect2di(Rect_.Left, Rect_.Top, Rect_.Right, Rect_.Top + ImageSize.Height);
00114 ChildB_->Rect_ = dim::rect2di(Rect_.Left, Rect_.Top + ImageSize.Height, Rect_.Right, Rect_.Bottom);
00115 }
00116
00117
00118 return ChildA_->insert(Image);
00119 }
00120
00122 void deleteChildren()
00123 {
00124 delete ChildA_;
00125 delete ChildB_;
00126
00127 ChildA_ = 0;
00128 ChildB_ = 0;
00129 }
00130
00131
00132
00133 inline void setRect(const dim::rect2di &Rect)
00134 {
00135 Rect_ = Rect;
00136 }
00137 inline dim::rect2di getRect() const
00138 {
00139 return Rect_;
00140 }
00141
00142 inline T* getImage() const
00143 {
00144 return Image_;
00145 }
00146
00147 inline ImageTreeNode<T>* getChildA() const
00148 {
00149 return ChildA_;
00150 }
00151 inline ImageTreeNode<T>* getChildB() const
00152 {
00153 return ChildB_;
00154 }
00155
00156 private:
00157
00158
00159
00160 dim::rect2di Rect_;
00161
00162 ImageTreeNode<T>* ChildA_;
00163 ImageTreeNode<T>* ChildB_;
00164
00165 T* Image_;
00166
00167 };
00168
00169
00170 }
00171
00172 }
00173
00174
00175 #endif
00176
00177
00178
00179