Main Page | Class Hierarchy | Class List | File List | Class Members

TQuadTree2D.h

00001 // TQuadTree2D.h: Schnittstelle für die Klasse TQuadTree2D.
00002 //
00004 
00005 #if !defined(AFX_TQUADTREE2D_H__FE2B3BFD_9805_4779_B341_2A52C07CBD52__INCLUDED_)
00006 #define AFX_TQUADTREE2D_H__FE2B3BFD_9805_4779_B341_2A52C07CBD52__INCLUDED_
00007 
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011 
00012 #include "TLinkedList.h"
00013 #include "TKoo3d.h"
00014 #include <qgl.h>
00015 #include "TGeometryData.h"
00016 
00017 class TGeometryData;
00018 
00019 class TQuadTree2DNode
00020 {
00021 private:
00022         bool isLeave;
00023         TGeometryData* posData;
00024         TKoo3d<float> topLeft;
00025         TKoo3d<float> bottomRight;
00026         TKoo3d<int> quadInd[4];
00027         TQuadTree2DNode* childNodes[4];
00028 
00029         bool isWithin(TKoo3d<float>& k)
00030         {
00031                 return (k.v[0]>topLeft.v[0])&&(k.v[1]>topLeft.v[1])&&
00032                         (k.v[0]<bottomRight.v[0])&&(k.v[1]<bottomRight.v[1]);
00033         }
00034 
00035 public:
00036         TQuadTree2DNode(TGeometryData* posA,TQuadTree2DNode** childs=0,TKoo3d<int>* quad=0);
00037         virtual ~TQuadTree2DNode();
00038         TKoo3d<float> getTopLeft()
00039         {
00040                 return topLeft;
00041         }
00042         TKoo3d<float> getBottomRight()
00043         {
00044                 return bottomRight;
00045         }
00046         TLinkedList<TKoo3d<TKoo3d <int> > >* getTrisContaining(TKoo3d<float>& pos,TLinkedList<TKoo3d< TKoo3d<int> > >* aktList);
00047 
00048         void draw(TKoo3d<float>& pos, int layer)
00049         {
00050                 if (layer<20&&isWithin(pos))
00051                 {
00052                         
00053                         glBegin(GL_LINE_LOOP);
00054                         glColor3f(((float)layer)/3.0f,((float)layer)/2.0f,1);
00055                         glVertex3f(topLeft.v[0]*10,topLeft.v[1]*10,0);
00056                         glVertex3f(bottomRight.v[0]*10,topLeft.v[1]*10,0);
00057                         glVertex3f(bottomRight.v[0]*10,bottomRight.v[1]*10,0);
00058                         glVertex3f(topLeft.v[0]*10,bottomRight.v[1]*10,0);
00059                         
00060                         glEnd();
00061                         if (!isLeave)
00062                         
00063                                 for (int i=0;i<4;i++)
00064                                         if (childNodes[i])
00065                                                 childNodes[i]->draw(pos,layer+1);
00066                 }
00067         }
00068 
00069 };
00070 
00071 
00072 class TQuadTree2D  
00073 {
00074 private:
00075 
00076 
00077         
00078 
00079         int xRes;
00080         int yRes;
00081         int translateToIndex(int x, int y)
00082         {
00083                 return x+xRes*y;
00084         }
00085         TQuadTree2DNode** test;
00086         TQuadTree2DNode* root;
00087         TQuadTree2DNode* generateRootNode(int fromX, int toX, int fromY, int toY,TQuadTree2DNode** leaves,TGeometryData* posA);
00088 public:
00089         TKoo3d<float> getBottomRight();
00090         TKoo3d<float> getTopLeft();
00091         TQuadTree2D(TGeometryData* posA, int resX, int resY);
00092         virtual ~TQuadTree2D();
00093         void draw()
00094         {
00095                 glLineWidth(1.0);
00096                 glColor3f(1,1,1);
00097                 root->draw(TKoo3d<float> (6,8,0),0);
00098                 //for (int i=(xRes-1)*100;i<(xRes-1)*200;i++)
00099                 //      test[i]->draw(TKoo3d<float> (1,1,0),0);
00100         }
00101 
00102         TLinkedList<TKoo3d<TKoo3d<int> > >* getTrisContaining(TKoo3d<float>& pos,TLinkedList<TKoo3d<TKoo3d<int> > >* aktList); 
00103 
00104 };
00105 
00106 #endif // !defined(AFX_TQUADTREE2D_H__FE2B3BFD_9805_4779_B341_2A52C07CBD52__INCLUDED_)

Generated on Mon Jan 19 02:06:39 2004 for flowvis by doxygen 1.3.5