Exemplo n.º 1
0
def _getPropertyPermission(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")

	response = _GET(base_url, method, debug, **args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	acl_lst = []
	acl_dic = {}

	for elem in tree.iter():
		if elem.tag == "acl":
			if acl_dic:
				acl_lst.append( Obj(acl_dic) )
				acl_dic = {}
				
			acl_dic.update(elem.attrib)
		if elem.tag == "group":
			acl_dic[elem.text] = elem.attrib["perm"]
	
	if acl_dic:
		acl_lst.append( Obj(acl_dic) )
	return acl_lst
Exemplo n.º 2
0
def _getHostState(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")
	
	response = _GET(base_url, method, debug, **args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	pkg_list = []
	host_dic = {}
	#pkg_dic = {}
	set_dic = {}

	for elem in tree.iter():
		if elem.tag == "state":
			host_dic.update(elem.attrib)
		if elem.tag == "package":
			set_dic = {}
			pkg_list.append(elem.attrib)
		if elem.tag == "setting":
			set_dic.update({ elem.attrib.values()[0] : elem.text })
			pkg_list[-1]["setting"] = set_dic


	host_dic["packages"] = pkg_list		
	return Obj(host_dic)
Exemplo n.º 3
0
 def draw_tiles(self, bevel, pos, size=32):
     for i in range(0, len(self.grid)):
         for j in range(0, len(self.grid[i])):
             bevel.surf.blit(
                 Tile(self.grid[i][j]).image, (j * size, i * size))
             bevel.surf.blit(
                 Obj(self.obj_grid[i][j].image, (j * size, i * size)))
Exemplo n.º 4
0
def _getRoleInfo(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")

	response = _GET(base_url, method, debug, **args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	role_dic = {}
	members = []
	rules = []

	for elem in tree.iter():
		if elem.tag == "role":
			role_dic.update(elem.attrib)
		if elem.tag == "host":
			members.append( elem.attrib["name"] )
		if elem.tag == "rule":
			rules.append( elem.text )

	role_dic["members"] = members
	role_dic["rules"] = rules
	return Obj(role_dic)
Exemplo n.º 5
0
def prepare(v_boxes_n):
    v_boxes = []
    for b_box in v_boxes_n:
        name = b_box[0]
        XtopLeft, YtopLeft, X_len, Y_len = change_to_width_len_format(b_box)
        obj = Obj(name, [YtopLeft, XtopLeft], [Y_len, X_len])
        v_boxes.append(obj)
    return v_boxes
Exemplo n.º 6
0
    def test_add_bigger_mbr_Obj_expands_root(self):
        r_tree = RTree(4, 2)
        s_Obj = Obj('SMALL_MAN', MBR(Coordinate(52, 43), Coordinate(68, 22)))
        expected_root_mbr = MBR(
            Coordinate(52 - POINT_OFFSET, 43 + POINT_OFFSET),
            Coordinate(68 + POINT_OFFSET, 22 - POINT_OFFSET))
        r_tree.insert(s_Obj)
        self.assertEqual(r_tree.root.mbr, expected_root_mbr)

        # Add a bigger Obj
        expected_root_mbr = MBR(
            Coordinate(20 - POINT_OFFSET, 45 + POINT_OFFSET),
            Coordinate(70 + POINT_OFFSET, 20 - POINT_OFFSET))
        b_Obj = Obj('BIG_MAN', MBR(Coordinate(20, 45), Coordinate(70, 20)))
        r_tree.insert(b_Obj)

        self.assertEqual(r_tree.root.mbr, expected_root_mbr)
        self.assertCountEqual(r_tree.root.members, [b_Obj, s_Obj])
Exemplo n.º 7
0
 def draw_tiles(self, screen, mode):
     for i in range(len(self.button_pos)):
         if (mode):
             screen.blit(
                 Tile(self.selections[i], scaling=self.scaling).image,
                 self.button_pos[i])
         else:
             screen.blit(
                 Obj(self.selections[i], scaling=self.scaling).image,
                 self.button_pos[i])
Exemplo n.º 8
0
    def test_add_without_root_should_add_root(self):
        bounds = MBR(Coordinate(10, 10), Coordinate(20, 0))
        o = Obj('Tank', bounds)
        r_tree = RTree(4, 2)
        r_tree.insert(o)

        self.assertIsNotNone(r_tree.root)
        self.assertIsInstance(r_tree.root, RTree.Node)
        self.assertEqual(r_tree.root.mbr, MBR.generate(bounds))
        self.assertEqual(len(r_tree.root.members), 1)
        self.assertEqual(r_tree.root.members[0], o)
Exemplo n.º 9
0
    def __init__(self, pos, size, tile_id, mode, scaling=2):
        self.hitbox = pg.Rect(pos, (size, size))
        self.pos = pos
        self.tid = tile_id

        if (mode):
            self.img = Tile(tile_id).image
        else:
            self.img = Obj(tile_id).image

        self.size = size
        self.scale(scaling)
Exemplo n.º 10
0
   def __init__( self, *args, **kwargs ):
      Obj.__init__( self, *args, **kwargs )

      # AI event driven actions will be stored here. 
      self.Action = None

      # Event driven orders will be kept here
      self.Orders = None

      # Fleet of ship (if there is one)
      self.Fleet = None

      # Systems cover all basic functions of the ship (Engine, Sensors, Life Support etc etc)
      self.Systems = dict()

      # Weapons cover all offensive damage dealing weapons the ship has on board and equipped. 
      self.Weapons = dict()

      # Shields covers the 4 groups of shields, their status, and their frequencies
      self.Shields = dict()

      # Hull represents the physical state of the ship. Several components will be kept here.
      self.Hull = dict()
Exemplo n.º 11
0
def _get_single(base_url, method, tag, acceptable_params, debug, **args):
	"""Makes the request and parses the response into a single Obj for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")

	response = _GET(base_url,method,debug,**args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	for elem in tree.iter():
		if elem.tag == tag:
			return Obj(elem.attrib)
Exemplo n.º 12
0
def _calculate_pos(ref_points):
    v_boxes = {}
    for index, ref_point in enumerate(ref_points):
        XtopLeft, YtopLeft = ref_point[0][0], ref_point[0][1]
        XbottomRight, YbottomRight = ref_point[1][0], ref_point[1][1]

        X_len = abs(XbottomRight - XtopLeft)
        Y_len = abs(YbottomRight - YtopLeft)
        obj = Obj(str(index), [YtopLeft, XtopLeft], [Y_len, X_len])

        v_boxes[index] = obj
    create_bound_boxes, create_prop, create_rels, create_rules, get_field_size = input_data(
    )
    description = scene_description(v_boxes, create_prop, create_rels,
                                    create_rules, get_field_size)
    print(description)
Exemplo n.º 13
0
    def loadModel(self, filename, translate, scale):
        model = Obj(filename)

        for face in model.faces:

            vertCount = len(face)

            for vert in range(vertCount):

                v0 = model.vertices[face[vert][0] - 1]
                v1 = model.vertices[face[(vert + 1) % vertCount][0] - 1]

                x0 = round(v0[0] * scale[0] + translate[0])
                y0 = round(v0[1] * scale[1] + translate[1])
                x1 = round(v1[0] * scale[0] + translate[0])
                y1 = round(v1[1] * scale[1] + translate[1])

                self.glLine_coord(x0, y0, x1, y1)
Exemplo n.º 14
0
    def load_model(self, filename, scale, translate):
        model = Obj(filename)

        for face in model.faces:
            vcount = len(face)
            for position in range(vcount):
                vi_1 = int(face[position][0]) - 1
                vi_2 = int(face[(position + 1) % vcount][0]) - 1

                v1 = model.vertex[vi_1]
                v2 = model.vertex[vi_2]

                x1 = round(v1[0] * scale[0] + translate[0])
                y1 = round(v1[1] * scale[1] + translate[1])
                x2 = round(v2[0] * scale[0] + translate[0])
                y2 = round(v2[1] * scale[1] + translate[1])

                self.glLine(x1, y1, x2, y2)
Exemplo n.º 15
0
def _getHostInfo(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")
	
	response = _GET(base_url, method, debug, **args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	host_dic = {}

	for elem in tree.iter():
		if elem.tag == "host":
			host_dic.update(elem.attrib)
		if elem.tag == "property":
			if elem.attrib["name"] == "igor_tag":
				host_dic.update( {"igor_tag" : elem.text} )
			
	return Obj(host_dic)
Exemplo n.º 16
0
    def get_obj(self):
        path = "./"
        self.load_dict(path, self.loaded_json)
        sorted_keys = sorted(self.my_types.keys())
        my_parent = {}
        my_obj = {}
        for key in sorted_keys:
            my_parent[key] = 0
            obj = Obj(key)
            obj.type = self.my_types[key]

            if obj.type == "list":
                obj.nb_items = self.my_nb_items[key]
                if key in self.my_nb_items_min:
                    obj.nb_items_min = self.my_nb_items_min[key]

            obj.nb_times_it_exists = self.my_paths[key]

            if key in self.my_values:
                obj.values = self.my_values[key]
            my_obj[key] = obj

        for key in sorted_keys:
            parts = key.split("[x]/")
            parts_len = len(parts)
            if parts_len > 1:
                path = parts[0]
                nb_items = my_obj[path].nb_items
                for i in range(1, parts_len - 1):
                    path += "[x]/%s" % parts[i]
                    nb_items *= my_obj[path].nb_items
                my_obj[key].nb_times_it_is_expected = nb_items

        for i in range(0, len(sorted_keys)):
            needle = sorted_keys[i]
            for key in my_parent:
                if len(key) > len(needle) and key.startswith(needle):
                    my_parent[key] = i
        for i in range(1, len(sorted_keys)):
            child_index = sorted_keys[i]
            child = my_obj[child_index]
            parent_index = sorted_keys[my_parent[child_index]]
            parent = my_obj[parent_index]
            parent.add_child(child)

        return my_obj["./"]
Exemplo n.º 17
0
    def test_find_min_expansion_node(self):
        """
        Given 3 nodes and one Obj, find the node which requires the minimum expansion to accommodate the Obj
        """
        """
        Node C should be chosen
        -----------------------------------------------------------------------------------------------------
        |                                                      |------------------------------------------| |
        |                                                      |                                          | |
        |                                         ______       |                                          | |
        |     ______________                      |     |      |                                          | |
        |    |             |                      |     | ---  |                                          | |
        |    |     A       |                      |     | |  | |                                          | |
        |    |             |                      |     | |E | |                                          | |
        |    |     ________|________              |     | |  | |                                          | |
        |    |     |       |       |              |  C  |  --  |                  D                       | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |B      |              |     |      |                                          | |
        |    --------------        |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          -----------------              |     |      |                                          | |
        |                                         -------      |                                          | |
        |                                                      |                                          | |
        |                                                      |__________________________________________| |
        |                                                                                                   |
        _____________________________________________________________________________________________________
        """
        rtn_a = RTree.Node(MBR(Coordinate(22, 40), Coordinate(30, 30)), 4, 2)
        rtn_b = RTree.Node(MBR(Coordinate(25, 35), Coordinate(40, 25)), 4, 2)
        rtn_c = RTree.Node(MBR(Coordinate(44, 40), Coordinate(47, 25)), 4, 2)
        rtn_d = RTree.Node(MBR(Coordinate(52, 43), Coordinate(68, 22)), 4, 2)
        Obj_e = Obj('E', MBR(Coordinate(47, 35), Coordinate(51, 30)))

        min_expansion_node = RTree.Node.find_min([rtn_a, rtn_b, rtn_c, rtn_d],
                                                 Obj_e)
        self.assertEqual(rtn_c, min_expansion_node)
Exemplo n.º 18
0
def _getRoleRulesLog(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")

	response = _GET(base_url,method,debug,**args)

	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	log_lst = []
	rev_dic = {}

	for elem in tree.iter():
		if elem.tag == "revision":
			rev_dic.update(elem.attrib)
			rev_dic["message"] = elem.text
			log_lst.append( Obj(rev_dic) )
			rev_dic = {}

	return log_lst
Exemplo n.º 19
0
def _getBranchInfo(base_url, method, acceptable_params, debug, **args):
	"""Makes the request and parses the response for its wrapper method"""
	#check if acceptable criteria was entered (prevents some errors)
	if not _correct_params(acceptable_params,**args):
		raise ValueError("At least one parameter with incorrect name given. Check http://devel.yahoo.com/igor/guide/rest_api.html for acceptable parameters")

	response = _GET(base_url, method, debug, **args)
	# parse the XML response
	tree = ElementTree()
	tree.parse(response)

	obj_list = []
	obj_dic = {}

	for elem in tree.iter():
		#print elem.tag, elem.attrib
		if elem.tag == "role":
			obj_dic.update(elem.attrib)
		if elem.tag == "rules":
			obj_dic.update(elem.attrib)
			obj_list.append(Obj(obj_dic))
			obj_dic = {}
			
	return obj_list
Exemplo n.º 20
0
    def test_find_min_expansion_node_chooses_node_that_contains_it_already(
            self):
        """
        Should choose D
        -----------------------------------------------------------------------------------------------------
        |                                                      |------------------------------------------| |
        |                                                      |                                          | |
        |                                         ______       |                                          | |
        |     ______________                      |     |      |              ------                      | |
        |    |             |                      |     |      |             |  E  |                      | |
        |    |     A       |                      |     |      |             ------                       | |
        |    |             |                      |     |      |                                          | |
        |    |     ________|________              |     |      |                                          | |
        |    |     |       |       |              |  C  |      |                  D                       | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |B      |              |     |      |                                          | |
        |    --------------        |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          -----------------              |     |      |                                          | |
        |                                         -------      |                                          | |
        |                                                      |                                          | |
        |                                                      |__________________________________________| |
        |                                                                                                   |
        _____________________________________________________________________________________________________
        """
        rtn_a = RTree.Node(MBR(Coordinate(22, 40), Coordinate(30, 30)), 4, 2)
        rtn_b = RTree.Node(MBR(Coordinate(25, 35), Coordinate(40, 25)), 4, 2)
        rtn_c = RTree.Node(MBR(Coordinate(44, 40), Coordinate(47, 25)), 4, 2)
        rtn_d = RTree.Node(MBR(Coordinate(52, 43), Coordinate(68, 22)), 4, 2)
        Obj_e = Obj('E', MBR(Coordinate(55, 35), Coordinate(60, 30)))

        min_expansion_node = RTree.Node.find_min([rtn_a, rtn_b, rtn_c, rtn_d],
                                                 Obj_e)
        self.assertEqual(min_expansion_node, rtn_d)
Exemplo n.º 21
0
    def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1)):
        model = Obj(filename)

        light = V3(0, 0, 1)

        for face in model.faces:
            vcount = len(face)

            if vcount == 3:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1

                v1 = V3(model.vertices[face1][0], model.vertices[face1][1],
                        model.vertices[face1][2])
                v2 = V3(model.vertices[face2][0], model.vertices[face2][1],
                        model.vertices[face2][2])
                v3 = V3(model.vertices[face3][0], model.vertices[face3][1],
                        model.vertices[face3][2])

                x1 = round((v1.x * scale[0]) + translate[0])
                y1 = round((v1.y * scale[1]) + translate[1])
                z1 = round((v1.z * scale[2]) + translate[2])

                x2 = round((v2.x * scale[0]) + translate[0])
                y2 = round((v2.y * scale[1]) + translate[1])
                z2 = round((v2.z * scale[2]) + translate[2])

                x3 = round((v3.x * scale[0]) + translate[0])
                y3 = round((v3.y * scale[1]) + translate[1])
                z3 = round((v3.z * scale[2]) + translate[2])

                A = V3(x1, y1, z1)
                B = V3(x2, y2, z2)
                C = V3(x3, y3, z3)

                xs = min([x1, x2, x3])
                ys = min([y1, y2, y3])
                colorShader = self.neptuno(xs, ys)

                normal = norm(cross(sub(B, A), sub(C, A)))
                intensity = dot(normal, norm(light))
                colors = []
                for i in colorShader:
                    if i * intensity > 0:
                        colors.append(round(i * intensity))
                    else:
                        colors.append(10)
                colors.reverse()

                self.clear_color = color2(colors[0], colors[1], colors[2])
                self.triangle(A, B, C)

            else:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1
                face4 = face[3][0] - 1

                v1 = V3(model.vertices[face1][0], model.vertices[face1][1],
                        model.vertices[face1][2])
                v2 = V3(model.vertices[face2][0], model.vertices[face2][1],
                        model.vertices[face2][2])
                v3 = V3(model.vertices[face3][0], model.vertices[face3][1],
                        model.vertices[face3][2])
                v4 = V3(model.vertices[face4][0], model.vertices[face4][1],
                        model.vertices[face4][2])

                x1 = round((v1.x * scale[0]) + translate[0])
                y1 = round((v1.y * scale[1]) + translate[1])
                z1 = round((v1.z * scale[2]) + translate[2])

                x2 = round((v2.x * scale[0]) + translate[0])
                y2 = round((v2.y * scale[1]) + translate[1])
                z2 = round((v2.z * scale[2]) + translate[2])

                x3 = round((v3.x * scale[0]) + translate[0])
                y3 = round((v3.y * scale[1]) + translate[1])
                z3 = round((v3.z * scale[2]) + translate[2])

                x4 = round((v4.x * scale[0]) + translate[0])
                y4 = round((v4.y * scale[1]) + translate[1])
                z4 = round((v4.z * scale[2]) + translate[2])

                A = V3(x1, y1, z1)
                B = V3(x2, y2, z2)
                C = V3(x3, y3, z3)
                D = V3(x4, y4, z4)

                normal = norm(cross(sub(B, A), sub(C, A)))
                intensity = dot(normal, norm(light))
                colors = []
                for i in colorShader:
                    if i * intensity > 0:
                        colors.append(round(i * intensity))
                    else:
                        colors.append(10)
                self.clear_color = color(colors[0], colors[1], colors[2])
                colors.reverse()

                self.triangle(A, B, C)
                self.triangle(A, C, D)
Exemplo n.º 22
0
    def loadModel(self,
                  filename="default.obj",
                  translate=[0, 0],
                  scale=[1, 1],
                  shape=None):
        model = Obj(filename)
        self.shape = shape

        for face in model.faces:
            vcount = len(face)

            if vcount == 3:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1

                v1 = model.vertices[face1]
                v2 = model.vertices[face2]
                v3 = model.vertices[face3]

                x1 = round((v1[0] * scale[0]) + translate[0])
                y1 = round((v1[1] * scale[1]) + translate[1])
                z1 = round((v1[2] * scale[2]) + translate[2])

                x2 = round((v2[0] * scale[0]) + translate[0])
                y2 = round((v2[1] * scale[1]) + translate[1])
                z2 = round((v2[2] * scale[2]) + translate[2])

                x3 = round((v3[0] * scale[0]) + translate[0])
                y3 = round((v3[1] * scale[1]) + translate[1])
                z3 = round((v3[2] * scale[2]) + translate[2])

                a = V3(x1, y1, z1)
                b = V3(x2, y2, z2)
                c = V3(x3, y3, z3)

                vn0 = model.normals[face1]
                vn1 = model.normals[face2]
                vn2 = model.normals[face3]

                self.triangle(a, b, c, normals=(vn0, vn1, vn2))

            else:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1
                face4 = face[3][0] - 1

                v1 = model.vertices[face1]
                v2 = model.vertices[face2]
                v3 = model.vertices[face3]
                v4 = model.vertices[face4]

                x1 = round((v1[0] * scale[0]) + translate[0])
                y1 = round((v1[1] * scale[1]) + translate[1])
                z1 = round((v1[2] * scale[2]) + translate[2])

                x2 = round((v2[0] * scale[0]) + translate[0])
                y2 = round((v2[1] * scale[1]) + translate[1])
                z2 = round((v2[2] * scale[2]) + translate[2])

                x3 = round((v3[0] * scale[0]) + translate[0])
                y3 = round((v3[1] * scale[1]) + translate[1])
                z3 = round((v3[2] * scale[2]) + translate[2])

                x4 = round((v4[0] * scale[0]) + translate[0])
                y4 = round((v4[1] * scale[1]) + translate[1])
                z4 = round((v4[2] * scale[2]) + translate[2])

                a = V3(x1, y1, z1)
                b = V3(x2, y2, z2)
                c = V3(x3, y3, z3)
                d = V3(x4, y4, z4)

                vn0 = model.normals[face1]
                vn1 = model.normals[face2]
                vn2 = model.normals[face3]
                vn3 = model.normals[face4]

                self.triangle(a, b, c, normals=(vn0, vn1, vn2))
                self.triangle(a, c, d, normals=(vn0, vn2, vn3))
Exemplo n.º 23
0
    def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1)):
        model = Obj(filename)

        light = V3(0, 0, 1)

        for face in model.faces:
            vcount = len(face)

            if vcount == 3:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1

                v1 = V3(model.vertices[face1][0], model.vertices[face1][1],
                        model.vertices[face1][2])
                v2 = V3(model.vertices[face2][0], model.vertices[face2][1],
                        model.vertices[face2][2])
                v3 = V3(model.vertices[face3][0], model.vertices[face3][1],
                        model.vertices[face3][2])

                x1 = round((v1.x * scale[0]) + translate[0])
                y1 = round((v1.y * scale[1]) + translate[1])
                z1 = round((v1.z * scale[2]) + translate[2])

                x2 = round((v2.x * scale[0]) + translate[0])
                y2 = round((v2.y * scale[1]) + translate[1])
                z2 = round((v2.z * scale[2]) + translate[2])

                x3 = round((v3.x * scale[0]) + translate[0])
                y3 = round((v3.y * scale[1]) + translate[1])
                z3 = round((v3.z * scale[2]) + translate[2])

                A = V3(x1, y1, z1)
                B = V3(x2, y2, z2)
                C = V3(x3, y3, z3)

                normal = norm(cross(sub(B, A), sub(C, A)))
                intensity = dot(normal, light)
                grey = round(255 * intensity)

                if grey < 0:
                    continue

                self.clear_color = color2(grey, grey, grey)

                self.triangle(A, B, C)

            else:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1
                face4 = face[3][0] - 1

                v1 = V3(model.vertices[face1][0], model.vertices[face1][1],
                        model.vertices[face1][2])
                v2 = V3(model.vertices[face2][0], model.vertices[face2][1],
                        model.vertices[face2][2])
                v3 = V3(model.vertices[face3][0], model.vertices[face3][1],
                        model.vertices[face3][2])
                v4 = V3(model.vertices[face4][0], model.vertices[face4][1],
                        model.vertices[face4][2])

                x1 = round((v1.x * scale[0]) + translate[0])
                y1 = round((v1.y * scale[1]) + translate[1])
                z1 = round((v1.z * scale[2]) + translate[2])

                x2 = round((v2.x * scale[0]) + translate[0])
                y2 = round((v2.y * scale[1]) + translate[1])
                z2 = round((v2.z * scale[2]) + translate[2])

                x3 = round((v3.x * scale[0]) + translate[0])
                y3 = round((v3.y * scale[1]) + translate[1])
                z3 = round((v3.z * scale[2]) + translate[2])

                x4 = round((v4.x * scale[0]) + translate[0])
                y4 = round((v4.y * scale[1]) + translate[1])
                z4 = round((v4.z * scale[2]) + translate[2])

                A = V3(x1, y1, z1)
                B = V3(x2, y2, z2)
                C = V3(x3, y3, z3)
                D = V3(x4, y4, z4)

                normal = norm(cross(sub(B, A), sub(C, A)))
                intensity = dot(normal, light)
                grey = round(255 * intensity)
                if grey < 0:
                    continue

                self.clear_color = color2(grey, grey, grey)

                self.triangle(A, B, C)

                self.triangle(A, D, C)
Exemplo n.º 24
0
def create_bound_boxes():
    objects = {}
    objects[0] = Obj('A', [5, 15], [15, 30])
    objects[1] = Obj('B', [45, 150], [25, 90])
    objects[2] = Obj('C', [200, 115], [55, 80])
    return objects
Exemplo n.º 25
0
    def test_split(self):
        """
        -----------------------------------------------------------------------------------------------------
        |                                                      |------------------------------------------| |
        |                                                      |                                          | |
        |                                         ______       |                                          | |
        |     ______________                      |     |      |                                          | |
        |    |             |                      |     |      |                                          | |
        |    |     A       |                      |     |      |                                          | |
        |    |             |                      |     |      |                                          | |
        |    |     ________|________              |     |      |                                          | |
        |    |     |       |       |              |  C  |      |                  D                       | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |       |              |     |      |                                          | |
        |    |     |       |B      |              |     |      |                                          | |
        |    --------------        |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          |               |              |     |      |                                          | |
        |          -----------------              |     |      |                                          | |
        |                                         -------      |                                          | |
        |                                                      |                                          | |
        |                                                      |__________________________________________| |
        |                                                                                                   |
        _____________________________________________________________________________________________________
        Here, A and D should be chosen as the basis for the two new nodes.
            B should go to the A node and C should go to the D node, as that would require the least expansion from both sides
        -----------------------------------------------------------------------------------------------------
        |                                        _____________________________Node B________________________|
        |                                        |             |------------------------------------------|||
        |                                        |             |                                          |||
        |  ______Node A______________            |______       |                                          |||
        |  |  ______________        |            ||     |      |                                          |||
        |  | |             |        |            ||     |      |                                          |||
        |  | |     A       |        |            ||     |      |                                          |||
        |  | |             |        |            ||     |      |                                          |||
        |  | |     ________|________|            ||     |      |                                          |||
        |  | |     |       |       ||            ||  C  |      |                  D                       |||
        |  | |     |       |       ||            ||     |      |                                          |||
        |  | |     |       |       ||            ||     |      |                                          |||
        |  | |     |       |B      ||            ||     |      |                                          |||
        |  | --------------        ||            ||     |      |                                          |||
        |  |       |               ||            ||     |      |                                          |||
        |  |       |               ||            ||     |      |                                          |||
        |  |       -----------------|            ||     |      |                                          |||
        |  |------------------------|            |-------      |                                          |||
        |                                        |             |                                          |||
        |                                        |             |__________________________________________|||
        |                                         --------------------------------------------------------- |
        ____________________________________________________________________________________________________|
       Both nodes should be 1 Coordinate bigger than the nodes
        """
        root = RTree.Node(MBR(Coordinate(20, 45), Coordinate(70, 20)), 4, 2)
        Obj_a = Obj('A', MBR(Coordinate(22, 40), Coordinate(30, 30)))
        Obj_b = Obj('B', MBR(Coordinate(25, 35), Coordinate(40, 25)))
        Obj_c = Obj('C', MBR(Coordinate(44, 40), Coordinate(47, 25)))
        Obj_d = Obj('D', MBR(Coordinate(52, 43), Coordinate(68, 22)))
        root.members = [Obj_a, Obj_b, Obj_c, Obj_d]

        expected_node_a_mbr = MBR(
            Coordinate(22 - POINT_OFFSET, 40 + POINT_OFFSET),
            Coordinate(40 + POINT_OFFSET, 25 - POINT_OFFSET))
        expected_node_b_mbr = MBR(
            Coordinate(44 - POINT_OFFSET, 43 + POINT_OFFSET),
            Coordinate(68 + POINT_OFFSET, 22 - POINT_OFFSET))

        node_a, node_b = root.split()

        self.assertEqual(node_a.mbr, expected_node_a_mbr)
        self.assertEqual(node_b.mbr, expected_node_b_mbr)
        self.assertCountEqual(node_a.members, [Obj_a, Obj_b])
        self.assertCountEqual(node_b.members, [Obj_c, Obj_d])
        self.assertEqual(node_a.children, [])
        self.assertEqual(node_b.children, [])
Exemplo n.º 26
0
	def __init__(self, s1,s2, rect):
		Obj.__init__(self,s1=s1,s2=s2, rect=rect )
		self.shape=0
Exemplo n.º 27
0
 def __init__( self, *args, **kwargs ):
    Obj.__init__( self, *args, **kwargs )
Exemplo n.º 28
0
   def __init__( self, *args, **kwargs ):
      Obj.__init__( self, *args, **kwargs )

      # Eventuall goal here, is to represent the Equipment, hull state, trade goods etc
      #  that a station might offer. 
Exemplo n.º 29
0
    def loadModel(self, filename, translate=[0,0], scale=[1,1]):
        model = Obj(filename)

        light = V3(0, 0, 1)

        for face in model.faces:
            vcount = len(face)

            if vcount == 3:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1

                v1 = model.vertices[face1]
                v2 = model.vertices[face2]
                v3 = model.vertices[face3]

                x1 = round((v1[0] * scale[0]) + translate[0])
                y1 = round((v1[1] * scale[1]) + translate[1])
                z1 = round((v1[2] * scale[2]) + translate[2])

                x2 = round((v2[0] * scale[0]) + translate[0])
                y2 = round((v2[1] * scale[1]) + translate[1])
                z2 = round((v2[2] * scale[2]) + translate[2])

                x3 = round((v3[0] * scale[0]) + translate[0])
                y3 = round((v3[1] * scale[1]) + translate[1])
                z3 = round((v3[2] * scale[2]) + translate[2])

                a = V3(x1, y1, z1)
                b = V3(x2, y2, z2)
                c = V3(x3, y3, z3)

                normal = cross(sub(b, a), sub(c, a))
                intensity = dot(norm(normal), norm(light))
                grey = round(255 * intensity)
                if grey < 0:
                    continue

                intensity_color = color(grey, grey, grey)
                self.triangle(a, b, c, intensity_color)

            else:
                face1 = face[0][0] - 1
                face2 = face[1][0] - 1
                face3 = face[2][0] - 1
                face4 = face[3][0] - 1

                v1 = model.vertices[face1]
                v2 = model.vertices[face2]
                v3 = model.vertices[face3]
                v4 = model.vertices[face4]

                x1 = round((v1[0] * scale[0]) + translate[0])
                y1 = round((v1[1] * scale[1]) + translate[1])
                z1 = round((v1[2] * scale[2]) + translate[2])

                x2 = round((v2[0] * scale[0]) + translate[0])
                y2 = round((v2[1] * scale[1]) + translate[1])
                z2 = round((v2[2] * scale[2]) + translate[2])

                x3 = round((v3[0] * scale[0]) + translate[0])
                y3 = round((v3[1] * scale[1]) + translate[1])
                z3 = round((v3[2] * scale[2]) + translate[2])

                x4 = round((v4[0] * scale[0]) + translate[0])
                y4 = round((v4[1] * scale[1]) + translate[1])
                z4 = round((v4[2] * scale[2]) + translate[2])

                a = V3(x1, y1, z1)
                b = V3(x2, y2, z2)
                c = V3(x3, y3, z3)
                d = V3(x4, y4, z4)

                normal = cross(sub(b, a), sub(c, a))

                intensity = dot(norm(normal), norm(light))
                grey = round(255 * intensity)
                if grey < 0:
                    continue

                intensity_color = color(grey, grey, grey)

                self.triangle(a, b, c, intensity_color)
                self.triangle(a, c, d, intensity_color)