def get_unknown_regions(self): """ :return: list of unknown regions :type: [Region] """ cm = ClusterRegions() cm.set_region_type(RegionType.unknown) cm.set_field(self.field) cm.group_regions() self.unknown_regions = cm.get_result_regions() return self.unknown_regions
def test5(self): """ Split the following form into regions: xxxx x x xxxx """ print "test5" test_field3 = self.make_free_map() test_field3[0][5].set_unknown() test_field3[0][6].set_unknown() test_field3[0][7].set_unknown() test_field3[0][8].set_unknown() test_field3[1][5].set_unknown() test_field3[2][5].set_unknown() test_field3[3][5].set_unknown() test_field3[3][6].set_unknown() test_field3[3][7].set_unknown() test_field3[3][8].set_unknown() cm = ClusterRegions(True) cm.set_field(test_field3) cm.print_field() cm.group_regions() # cm.print_segmented_field() c = cm.get_result_map() # regions = cm.get_result_regions() # print "Region count: " + str(len(regions)) # for r in regions: # print r # print "Distance of region to (0,0): " + str(r.euclidean_distance_to_avg(0,0)) # cubified_field = cm.cubify_regions() # cm.print_2d_field(cubified_field) regions_not_sorted = cm.split_and_cubify_regions() # Check the cells of the splitted regions regions = regions_not_sorted self.assertEquals(len(regions), 3) self.assertEquals(regions[0].cell_coords, [[3, 5], [3, 6], [3, 7], [3, 8]]) self.assertEquals(regions[1].cell_coords, [[0, 5], [0, 6], [0, 7], [0, 8]]) self.assertEquals(regions[2].cell_coords, [[1, 5], [2, 5]])
def test5(self): """ Split the following form into regions: xxxx x x xxxx """ print "test5" test_field3 = self.make_free_map() test_field3[0][5].set_unknown() test_field3[0][6].set_unknown() test_field3[0][7].set_unknown() test_field3[0][8].set_unknown() test_field3[1][5].set_unknown() test_field3[2][5].set_unknown() test_field3[3][5].set_unknown() test_field3[3][6].set_unknown() test_field3[3][7].set_unknown() test_field3[3][8].set_unknown() cm = ClusterRegions(True) cm.set_field(test_field3) cm.print_field() cm.group_regions() # cm.print_segmented_field() c = cm.get_result_map() # regions = cm.get_result_regions() # print "Region count: " + str(len(regions)) # for r in regions: # print r # print "Distance of region to (0,0): " + str(r.euclidean_distance_to_avg(0,0)) # cubified_field = cm.cubify_regions() # cm.print_2d_field(cubified_field) regions_not_sorted = cm.split_and_cubify_regions() # Check the cells of the splitted regions regions = regions_not_sorted self.assertEquals(len(regions), 3) self.assertEquals(regions[0].cell_coords, [[3,5],[3,6],[3,7],[3,8]]) self.assertEquals(regions[1].cell_coords, [[0,5],[0,6],[0,7],[0,8]]) self.assertEquals(regions[2].cell_coords, [[1,5],[2,5]])
def get_obstacle_regions(self): """ Searches for a list of obstacle regions with the same color. will only be calculated once. :return: list of obstacle regions with the same color :type: [Region] """ if len(self.obstacle_regions) == 0: cm = ClusterRegions() cm.set_field(self.field) cm.set_region_type(RegionType.blue) cm.group_regions() cm.set_region_type(RegionType.green) cm.group_regions() cm.set_region_type(RegionType.red) cm.group_regions() cm.set_region_type(RegionType.cyan) cm.group_regions() cm.set_region_type(RegionType.yellow) cm.group_regions() cm.set_region_type(RegionType.magenta) cm.group_regions() cm.set_region_type(RegionType.undef) cm.group_regions() rospy.logdebug("Clustering results:") rospy.logdebug(cm.print_segmented_field()) rospy.logdebug(cm.print_field()) self.obstacle_regions = cm.get_result_regions() return self.obstacle_regions
# field[0][7].set_unknown() field[0][8] = Cell() field[0][8].set_unknown() field[1][7] = Cell() field[1][7].set_unknown() field[2][6] = Cell() field[2][6].set_unknown() # field[1][8] = Cell() # field[1][8].set_unknown() # field[2][8] = Cell() # field[2][8].set_unknown() return field cm = ClusterRegions() cm.set_field(test_field4()) cm.print_field() print "Returned regions: " + str(cm.group_regions()) print "Grouping done" cm.print_segmented_field() c = cm.get_result_map() regions = cm.get_result_regions() print "Region count: " + str(len(regions)) for r in regions: print r print "Distance of region to (0,0): " + str(r.euclidean_distance_to_avg(0,0)) cubified_field = cm.cubify_regions() cm.print_2d_field(cubified_field)
field[0][8] = Cell() field[0][8].set_unknown() field[1][7] = Cell() field[1][7].set_unknown() field[2][6] = Cell() field[2][6].set_unknown() # field[1][8] = Cell() # field[1][8].set_unknown() # field[2][8] = Cell() # field[2][8].set_unknown() return field cm = ClusterRegions() cm.set_field(test_field4()) cm.print_field() print "Returned regions: " + str(cm.group_regions()) print "Grouping done" cm.print_segmented_field() c = cm.get_result_map() regions = cm.get_result_regions() print "Region count: " + str(len(regions)) for r in regions: print r print "Distance of region to (0,0): " + str( r.euclidean_distance_to_avg(0, 0)) cubified_field = cm.cubify_regions()
def test6(self): test_field = self.make_free_map() test_field[1][2].set_obstacle() test_field[1][2].set_blue() test_field[1][3].set_obstacle() test_field[1][3].set_blue() test_field[1][4].set_obstacle() test_field[1][4].set_blue() test_field[1][5].set_obstacle() test_field[1][5].set_blue() test_field[1][6].set_obstacle() test_field[1][6].set_green() test_field[2][2].set_obstacle() test_field[2][2].set_blue() test_field[2][3].set_obstacle() test_field[2][3].set_green() test_field[2][4].set_obstacle() test_field[2][4].set_green() test_field[2][5].set_obstacle() test_field[2][5].set_green() test_field[2][6].set_obstacle() test_field[2][6].set_green() cm = ClusterRegions(True) cm.set_field(test_field) cm.print_field() cm.set_region_type(RegionType.blue) cm.group_regions() cm.set_region_type(RegionType.green) cm.group_regions() cm.set_region_type(RegionType.red) cm.group_regions() cm.set_region_type(RegionType.cyan) cm.group_regions() cm.set_region_type(RegionType.yellow) cm.group_regions() cm.set_region_type(RegionType.magenta) cm.group_regions() regions = cm.get_result_regions() for r in regions: print r.get_color_id() muh = [[[1, 2], [2, 2], [1, 3], [1, 4], [1, 5]], [[1, 6], [2, 6], [2, 5], [2, 4], [2, 3]]] self.assertTrue(regions[0].cell_coords in muh) self.assertTrue(regions[1].cell_coords in muh)
def test1(self): """ Split the following form into regions: xxx x x x x """ test_field3 = self.make_free_map() test_field3[0][6].set_unknown() test_field3[0][7].set_unknown() test_field3[0][8].set_unknown() test_field3[1][6].set_unknown() test_field3[2][6].set_unknown() test_field3[1][8].set_unknown() test_field3[2][8].set_unknown() cm = ClusterRegions() cm.set_field(test_field3) cm.print_field() print "Returned regions: " + str(cm.group_regions()) print "Grouping done" cm.print_segmented_field() c = cm.get_result_map() regions = cm.get_result_regions() print "Region count: " + str(len(regions)) for r in regions: print r print "Distance of region to (0,0): " + str( r.euclidean_distance_to_avg(0, 0)) cubified_field = cm.cubify_regions() cm.print_2d_field(cubified_field) regions_not_sorted = cm.split_and_cubify_regions() # Check the cells of the splitted regions regions = sorted(regions_not_sorted) self.assertEquals(len(regions), 3) muh = [[[0, 6], [0, 7], [0, 8]], [[1, 6], [2, 6]], [[1, 8], [2, 8]]] self.assertTrue(regions[0].cell_coords in muh) self.assertTrue(regions[1].cell_coords in muh) self.assertTrue(regions[2].cell_coords in muh)
def test1(self): """ Split the following form into regions: xxx x x x x """ test_field3 = self.make_free_map() test_field3[0][6].set_unknown() test_field3[0][7].set_unknown() test_field3[0][8].set_unknown() test_field3[1][6].set_unknown() test_field3[2][6].set_unknown() test_field3[1][8].set_unknown() test_field3[2][8].set_unknown() cm = ClusterRegions() cm.set_field(test_field3) cm.print_field() print "Returned regions: " + str(cm.group_regions()) print "Grouping done" cm.print_segmented_field() c = cm.get_result_map() regions = cm.get_result_regions() print "Region count: " + str(len(regions)) for r in regions: print r print "Distance of region to (0,0): " + str(r.euclidean_distance_to_avg(0,0)) cubified_field = cm.cubify_regions() cm.print_2d_field(cubified_field) regions_not_sorted = cm.split_and_cubify_regions() # Check the cells of the splitted regions regions = sorted(regions_not_sorted) self.assertEquals(len(regions), 3) muh = [[[0,6],[0,7],[0,8]], [[1,6],[2,6]], [[1,8],[2,8]]] self.assertTrue(regions[0].cell_coords in muh) self.assertTrue(regions[1].cell_coords in muh) self.assertTrue(regions[2].cell_coords in muh)