~yacinechaouche/+junk/BZR

« back to all changes in this revision

Viewing changes to PROG/LETS3D/lets3d/lib/quadtrees.py

  • Committer: yacinechaouche at yahoo
  • Date: 2015-01-14 22:23:03 UTC
  • Revision ID: yacinechaouche@yahoo.com-20150114222303-6gbtqqxii717vyka
Ajout de CODE et PROD. Il faudra ensuite ajouter ce qu'il y avait dan TMP

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## file quadtree.py
 
2
 
 
3
from definitions import *
 
4
from geometry import *
 
5
 
 
6
class QuadTree :
 
7
    def __init__(self,x=0,z=0,size=16,depth= 4,top = None,left= None,right= None,bottom= None):
 
8
        """ depth is the depth of the quadtree """
 
9
        self.depth= depth
 
10
        self.x,self.z,self.size = x,z,size
 
11
        self.sons = []
 
12
        #defining lines
 
13
        if not left :
 
14
            self.leftLine = Line(point = Point(x,0,z),vector = Vector(0,0,1))
 
15
        else :
 
16
            self.leftLine = left
 
17
        if not top :
 
18
            self.topLine = Line(point = Point(x,0,z),vector = Vector(1,0,0))
 
19
        else :
 
20
            self.topLine = top
 
21
        if not right :
 
22
            self.rightLine = Line(point = Point(x+size,0,z+size),vector = Vector(0,0,1))
 
23
        else :
 
24
            self.rightLine = right
 
25
        if not bottom :
 
26
            self.bottomLine = Line(point = Point(x+size,0,z+size),vector = Vector(1,0,0))
 
27
        else :
 
28
            self.bottomLine = bottom
 
29
        
 
30
        self.buildTree()
 
31
 
 
32
    def buildTree(self):
 
33
        x,z,size = self.x,self.z,self.size
 
34
        if self.depth > 0 :
 
35
            # quad number 1 (top left) : top and left lines are the same as for the parent
 
36
            self.sons.append(QuadTree(x=x,z=z,size=size/2.0,depth=self.depth - 1,top=self.topLine,left = self.leftLine))
 
37
            # quad number 2 (top right) : top and right lines are the same as for the parent
 
38
            self.sons.append(QuadTree(x=x+size/2.0,z=z,size=size/2.0,depth=self.depth - 1,top=self.topLine,right=self.rightLine))
 
39
            # quad number 3 (bottom left) : bottom and left lines are the same as for the parent
 
40
            self.sons.append(QuadTree(x=x,z=z+size/2.0,size=size/2.0,depth=self.depth - 1,bottom = self.bottomLine,left = self.leftLine))
 
41
            # quad number 4 (bottom right) : bottom and right lines are the same as for the parent
 
42
            self.sons.append(QuadTree(x=x+size/2.0,z=z+size/2.0,size=size/2.0,depth=self.depth - 1,right = self.rightLine,bottom = self.bottomLine))
 
43
 
 
44
    def printNodesCoordinates(self):
 
45
        for node in self.sons :
 
46
            print node.depth,node.x,node.z
 
47
            node.printNodesCoordinates()
 
48
 
 
49
    def intersect(self,line,depth):
 
50
        pass
 
51
 
 
52
def testQuadTreeLines():
 
53
    c = QuadTree()
 
54
    print c.sons[0].sons[3].sons[2].x , c.sons[0].sons[3].sons[2].z
 
55
    l = Line(A = Point(6,0,4), B = Point(2,0,12))
 
56
    p,t = l.intersect(c.sons[0].sons[3].sons[2].bottomLine)
 
57
    print p.coord,t
 
58
    
 
59
##testQuadTreeLines()