コード例 #1
0
def test_get_copies_lists():
    list_1 = objects.get(objects.ObjectDefinitionList.ALL)
    list_2 = objects.get(objects.ObjectDefinitionList.ALL)
    assert not (list_1 is list_2)
    assert list_1 == list_2
    for index in range(len(list_1)):
        assert not (list_1[index] is list_2[index])
コード例 #2
0
 def choose_definition(
     self,
     must_be_pickupable: bool = False
 ) -> Dict[str, Any]:
     """Choose and return an object definition."""
     definition_list = random.choice(retrieve_trained_definition_list(
         objects.get(objects.ObjectDefinitionList.PICKUPABLES)
         if must_be_pickupable
         else objects.get(objects.ObjectDefinitionList.ALL)
     ))
     # Same chance to pick each object definition from the list.
     definition = finalize_object_definition(random.choice(definition_list))
     # Finalize the material here in case we need to make a confusor.
     return random.choice(finalize_object_materials_and_colors(definition))
コード例 #3
0
def test_does_have_definitions():
    output_list = objects.get(objects.ObjectDefinitionList.ALL)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0

    output_list = objects.get(objects.ObjectDefinitionList.CONTAINERS)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0

    output_list = objects.get(objects.ObjectDefinitionList.OBSTACLES)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0

    output_list = objects.get(objects.ObjectDefinitionList.OCCLUDERS)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0

    output_list = objects.get(objects.ObjectDefinitionList.PICKUPABLES)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0

    output_list = objects.get(objects.ObjectDefinitionList.NOT_PICKUPABLES)
    assert len(output_list) > 0
    for definition_list in output_list:
        assert len(definition_list) > 0
コード例 #4
0
    def choose_target_definition(self, target_number: int) -> Dict[str, Any]:
        if target_number == 0:
            return self.choose_definition(must_be_pickupable=True)

        if target_number != 1:
            raise exceptions.SceneException(
                f'Expected target with number 0 or 1 but got {target_number}')

        definition_list = random.choice(retrieve_trained_definition_list(
            objects.get(objects.ObjectDefinitionList.STACK_TARGETS)
        ))

        # Same chance to pick each object definition from the list.
        definition = finalize_object_definition(random.choice(definition_list))
        # Finalize the material here in case we need to make a confusor.
        return random.choice(finalize_object_materials_and_colors(definition))
コード例 #5
0
def choose_distractor_definition(
    target_list: List[Dict[str, Any]]
) -> Dict[str, Any]:
    """Choose and return a distractor definition for the given objects."""
    invalid_shape_list = [target['shape'][-1] for target in target_list]
    for _ in range(MAX_TRIES):
        # Distractors should always be both trained and pickupable.
        definition_list = random.choice(retrieve_trained_definition_list(
            objects.get(objects.ObjectDefinitionList.PICKUPABLES)
        ))
        # Finalize the material now.
        definition = random.choice(finalize_object_materials_and_colors(
            finalize_object_definition(random.choice(definition_list))
        ))
        # Distractors cannot have the same shape as an existing object from the
        # given list so we don't unintentionally generate a new confusor.
        if definition['shape'][-1] not in invalid_shape_list:
            break
        definition = None
    return definition
コード例 #6
0
def test_all_objects_have_expected_properties():
    for definition_list in util.retrieve_complete_definition_list(
        objects.get(objects.ObjectDefinitionList.ALL)
    ):
        for object_definition in definition_list:
            print(f'{object_definition["type"]}')
            assert 'type' in object_definition
            assert 'size' in object_definition
            assert 'shape' in object_definition
            assert 'mass' in object_definition
            assert 'attributes' in object_definition
            assert 'dimensions' in object_definition
            assert 'materialCategory' in object_definition
            assert 'salientMaterials' in object_definition
            if len(object_definition['materialCategory']) == 0:
                assert 'color' in object_definition
            assert 'info' not in object_definition
            if 'massMultiplier' in object_definition:
                if object_definition['massMultiplier'] < 1:
                    print('[ERROR] Mass multiplier < 1 will cause '
                          'intermittent errors in other parts of the code')
                    assert False
コード例 #7
0
def test_retrieve_untrained_definition_list_occluder_objects():
    assert len(retrieve_untrained_definition_list(
        objects.get(objects.ObjectDefinitionList.OCCLUDERS),
        'untrainedShape'
    )) > 0
コード例 #8
0
def test_retrieve_untrained_definition_list_obstacle_objects():
    assert len(retrieve_untrained_definition_list(
        objects.get(objects.ObjectDefinitionList.OBSTACLES),
        'untrainedShape'
    )) > 0
コード例 #9
0
def test_retrieve_untrained_definition_list_container_objects():
    assert len(retrieve_untrained_definition_list(
        objects.get(objects.ObjectDefinitionList.CONTAINERS),
        'untrainedShape'
    )) > 0
コード例 #10
0
def test_retrieve_untrained_definition_list_all_objects():
    assert len(retrieve_untrained_definition_list(
        objects.get(objects.ObjectDefinitionList.ALL),
        'untrainedShape'
    )) > 0
コード例 #11
0
import random
import materials
import objects
from util import finalize_object_definition, instantiate_object, \
    random_real, move_to_location, retrieve_complete_definition_list, \
    retrieve_trained_definition_list, retrieve_untrained_definition_list, \
    is_similar_except_in_color, is_similar_except_in_shape, \
    is_similar_except_in_size, choose_distractor_definition


ALL_DEFINITIONS = [
    definition for definition_list in retrieve_complete_definition_list(
        objects.get(objects.ObjectDefinitionList.ALL)
    ) for definition in definition_list
]


PACIFIER = {
    "type": "pacifier",
    "color": "blue",
    "shape": "pacifier",
    "size": "tiny",
    "salientMaterials": ["plastic"],
    "attributes": ["moveable", "pickupable"],
    "dimensions": {
        "x": 0.07,
        "y": 0.04,
        "z": 0.05
    },
    "mass": 0.125,
    "offset": {
コード例 #12
0
        },
        'dimensions': {
            'x': 1,
            'y': 1,
            'z': 1
        }
    }]
}

PICKUPABLE_OBJECTS_WITHOUT_CONTAINMENTS = [
    'duck_on_wheels', 'chair_1', 'chair_2', 'table_1', 'table_3'
]

CONTAINER_DEFINITIONS = [
    definition for definition_list in util.retrieve_complete_definition_list(
        objects.get(objects.ObjectDefinitionList.CONTAINERS))
    for definition in definition_list
]

PICKUPABLE_DEFINITIONS = [
    definition for definition_list in util.retrieve_complete_definition_list(
        objects.get(objects.ObjectDefinitionList.PICKUPABLES))
    for definition in definition_list
]


def get_valid_containments(object_a, object_b=None):
    valid_containments = []
    for definition in CONTAINER_DEFINITIONS:
        if object_b:
            containment = can_contain_both(definition, object_a, object_b)