LSBoundingBox

 1# coding: utf-8
 2
 3
 4class LSBoundingBox(object):
 5    def __init__(self):
 6        self.minX = float('Inf')
 7        self.minY = float('Inf')
 8        self.minZ = float('Inf')
 9        self.maxX = float('-Inf')
10        self.maxY = float('-Inf')
11        self.maxZ = float('-Inf')
12
13        self.child_bounding_box = []
14
15    def reset(self):
16        self.minX = float('Inf')
17        self.minY = float('Inf')
18        self.minZ = float('Inf')
19        self.maxX = float('-Inf')
20        self.maxY = float('-Inf')
21        self.maxZ = float('-Inf')
22
23    def set_value(self, arr):
24        self.minX = arr[0]
25        self.minY = arr[1]
26        self.minZ = arr[2]
27        self.maxX = arr[3]
28        self.maxY = arr[4]
29        self.maxZ = arr[5]
30
31    def init_from_bounds(self, bounds):
32        self.minX = bounds[0][0]
33        self.minY = bounds[0][1]
34        self.minZ = bounds[0][2]
35        self.maxX = bounds[1][0]
36        self.maxY = bounds[1][1]
37        self.maxZ = bounds[1][2]
38
39    def add_child(self, bound):
40        self.child_bounding_box.append(bound)
41        self.update_bounding_box()
42
43    def is_in_bounding2d(self, xmin, ymin, xmax, ymax):
44        if self.minX >= xmin and self.maxX <= xmax and self.minY >= ymin and self.maxY <= ymax:
45            return True
46        return False
47
48    def offset_to_new(self, x, y, z):
49        bounding = LSBoundingBox()
50        bounding.minX = self.minX + x
51        bounding.maxX = self.maxX + x
52        bounding.minY = self.minY + y
53        bounding.maxY = self.maxY + y
54        bounding.minZ = self.minZ + z
55        bounding.maxZ = self.maxZ + z
56        return bounding
57
58    def update_bounding_box(self):
59        self.reset()
60        for i in range(len(self.child_bounding_box)):
61            child = self.child_bounding_box[i]
62            self.minX = min(self.minX, child.minX)
63            self.minY = min(self.minY, child.minY)
64            self.minZ = min(self.minZ, child.minZ)
65            self.maxX = max(self.maxX, child.maxX)
66            self.maxY = max(self.maxY, child.maxY)
67            self.maxZ = max(self.maxZ, child.maxZ)
68
69    def get_x_extents(self):
70        return self.maxX - self.minX
71
72    def get_y_extents(self):
73        return self.maxY - self.minY
74
75    def get_z_extents(self):
76        return self.maxZ - self.minZ
77
78    def to_string(self):
79        total_str = ""
80        for i in range(len(self.child_bounding_box)):
81            child_bound_box = self.child_bounding_box[i]
82            total_str += str(child_bound_box.minX) + " "
83            total_str += str(child_bound_box.minY) + " "
84            total_str += str(child_bound_box.minZ) + " "
85            total_str += str(child_bound_box.maxX) + " "
86            total_str += str(child_bound_box.maxY) + " "
87            total_str += str(child_bound_box.maxZ) + " "
88        return total_str.strip()
89
90    @staticmethod
91    def merge(bound1, bound2):
92        new_bound_box = LSBoundingBox()
93        new_bound_box.minX = min(bound1.minX, bound2.minX)
94        new_bound_box.minY = min(bound1.minY, bound2.minY)
95        new_bound_box.minZ = min(bound1.minZ, bound2.minZ)
96        new_bound_box.maxX = max(bound1.maxX, bound2.maxX)
97        new_bound_box.maxY = max(bound1.maxY, bound2.maxY)
98        new_bound_box.maxZ = max(bound1.maxZ, bound2.maxZ)
99        return new_bound_box
class LSBoundingBox:
  5class LSBoundingBox(object):
  6    def __init__(self):
  7        self.minX = float('Inf')
  8        self.minY = float('Inf')
  9        self.minZ = float('Inf')
 10        self.maxX = float('-Inf')
 11        self.maxY = float('-Inf')
 12        self.maxZ = float('-Inf')
 13
 14        self.child_bounding_box = []
 15
 16    def reset(self):
 17        self.minX = float('Inf')
 18        self.minY = float('Inf')
 19        self.minZ = float('Inf')
 20        self.maxX = float('-Inf')
 21        self.maxY = float('-Inf')
 22        self.maxZ = float('-Inf')
 23
 24    def set_value(self, arr):
 25        self.minX = arr[0]
 26        self.minY = arr[1]
 27        self.minZ = arr[2]
 28        self.maxX = arr[3]
 29        self.maxY = arr[4]
 30        self.maxZ = arr[5]
 31
 32    def init_from_bounds(self, bounds):
 33        self.minX = bounds[0][0]
 34        self.minY = bounds[0][1]
 35        self.minZ = bounds[0][2]
 36        self.maxX = bounds[1][0]
 37        self.maxY = bounds[1][1]
 38        self.maxZ = bounds[1][2]
 39
 40    def add_child(self, bound):
 41        self.child_bounding_box.append(bound)
 42        self.update_bounding_box()
 43
 44    def is_in_bounding2d(self, xmin, ymin, xmax, ymax):
 45        if self.minX >= xmin and self.maxX <= xmax and self.minY >= ymin and self.maxY <= ymax:
 46            return True
 47        return False
 48
 49    def offset_to_new(self, x, y, z):
 50        bounding = LSBoundingBox()
 51        bounding.minX = self.minX + x
 52        bounding.maxX = self.maxX + x
 53        bounding.minY = self.minY + y
 54        bounding.maxY = self.maxY + y
 55        bounding.minZ = self.minZ + z
 56        bounding.maxZ = self.maxZ + z
 57        return bounding
 58
 59    def update_bounding_box(self):
 60        self.reset()
 61        for i in range(len(self.child_bounding_box)):
 62            child = self.child_bounding_box[i]
 63            self.minX = min(self.minX, child.minX)
 64            self.minY = min(self.minY, child.minY)
 65            self.minZ = min(self.minZ, child.minZ)
 66            self.maxX = max(self.maxX, child.maxX)
 67            self.maxY = max(self.maxY, child.maxY)
 68            self.maxZ = max(self.maxZ, child.maxZ)
 69
 70    def get_x_extents(self):
 71        return self.maxX - self.minX
 72
 73    def get_y_extents(self):
 74        return self.maxY - self.minY
 75
 76    def get_z_extents(self):
 77        return self.maxZ - self.minZ
 78
 79    def to_string(self):
 80        total_str = ""
 81        for i in range(len(self.child_bounding_box)):
 82            child_bound_box = self.child_bounding_box[i]
 83            total_str += str(child_bound_box.minX) + " "
 84            total_str += str(child_bound_box.minY) + " "
 85            total_str += str(child_bound_box.minZ) + " "
 86            total_str += str(child_bound_box.maxX) + " "
 87            total_str += str(child_bound_box.maxY) + " "
 88            total_str += str(child_bound_box.maxZ) + " "
 89        return total_str.strip()
 90
 91    @staticmethod
 92    def merge(bound1, bound2):
 93        new_bound_box = LSBoundingBox()
 94        new_bound_box.minX = min(bound1.minX, bound2.minX)
 95        new_bound_box.minY = min(bound1.minY, bound2.minY)
 96        new_bound_box.minZ = min(bound1.minZ, bound2.minZ)
 97        new_bound_box.maxX = max(bound1.maxX, bound2.maxX)
 98        new_bound_box.maxY = max(bound1.maxY, bound2.maxY)
 99        new_bound_box.maxZ = max(bound1.maxZ, bound2.maxZ)
100        return new_bound_box
minX
minY
minZ
maxX
maxY
maxZ
child_bounding_box
def reset(self):
16    def reset(self):
17        self.minX = float('Inf')
18        self.minY = float('Inf')
19        self.minZ = float('Inf')
20        self.maxX = float('-Inf')
21        self.maxY = float('-Inf')
22        self.maxZ = float('-Inf')
def set_value(self, arr):
24    def set_value(self, arr):
25        self.minX = arr[0]
26        self.minY = arr[1]
27        self.minZ = arr[2]
28        self.maxX = arr[3]
29        self.maxY = arr[4]
30        self.maxZ = arr[5]
def init_from_bounds(self, bounds):
32    def init_from_bounds(self, bounds):
33        self.minX = bounds[0][0]
34        self.minY = bounds[0][1]
35        self.minZ = bounds[0][2]
36        self.maxX = bounds[1][0]
37        self.maxY = bounds[1][1]
38        self.maxZ = bounds[1][2]
def add_child(self, bound):
40    def add_child(self, bound):
41        self.child_bounding_box.append(bound)
42        self.update_bounding_box()
def is_in_bounding2d(self, xmin, ymin, xmax, ymax):
44    def is_in_bounding2d(self, xmin, ymin, xmax, ymax):
45        if self.minX >= xmin and self.maxX <= xmax and self.minY >= ymin and self.maxY <= ymax:
46            return True
47        return False
def offset_to_new(self, x, y, z):
49    def offset_to_new(self, x, y, z):
50        bounding = LSBoundingBox()
51        bounding.minX = self.minX + x
52        bounding.maxX = self.maxX + x
53        bounding.minY = self.minY + y
54        bounding.maxY = self.maxY + y
55        bounding.minZ = self.minZ + z
56        bounding.maxZ = self.maxZ + z
57        return bounding
def update_bounding_box(self):
59    def update_bounding_box(self):
60        self.reset()
61        for i in range(len(self.child_bounding_box)):
62            child = self.child_bounding_box[i]
63            self.minX = min(self.minX, child.minX)
64            self.minY = min(self.minY, child.minY)
65            self.minZ = min(self.minZ, child.minZ)
66            self.maxX = max(self.maxX, child.maxX)
67            self.maxY = max(self.maxY, child.maxY)
68            self.maxZ = max(self.maxZ, child.maxZ)
def get_x_extents(self):
70    def get_x_extents(self):
71        return self.maxX - self.minX
def get_y_extents(self):
73    def get_y_extents(self):
74        return self.maxY - self.minY
def get_z_extents(self):
76    def get_z_extents(self):
77        return self.maxZ - self.minZ
def to_string(self):
79    def to_string(self):
80        total_str = ""
81        for i in range(len(self.child_bounding_box)):
82            child_bound_box = self.child_bounding_box[i]
83            total_str += str(child_bound_box.minX) + " "
84            total_str += str(child_bound_box.minY) + " "
85            total_str += str(child_bound_box.minZ) + " "
86            total_str += str(child_bound_box.maxX) + " "
87            total_str += str(child_bound_box.maxY) + " "
88            total_str += str(child_bound_box.maxZ) + " "
89        return total_str.strip()
@staticmethod
def merge(bound1, bound2):
 91    @staticmethod
 92    def merge(bound1, bound2):
 93        new_bound_box = LSBoundingBox()
 94        new_bound_box.minX = min(bound1.minX, bound2.minX)
 95        new_bound_box.minY = min(bound1.minY, bound2.minY)
 96        new_bound_box.minZ = min(bound1.minZ, bound2.minZ)
 97        new_bound_box.maxX = max(bound1.maxX, bound2.maxX)
 98        new_bound_box.maxY = max(bound1.maxY, bound2.maxY)
 99        new_bound_box.maxZ = max(bound1.maxZ, bound2.maxZ)
100        return new_bound_box