示例#1
0
文件: test_io.py 项目: cmpute/xviz
    def test_glb_metadata_writer(self):
        builder = self._get_metadata_builder()

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        # because json encoding of dict is not necessarily deterministic (different
        # order of iteration of keys), we decode the json and check for dict equality
        expected_prefix = b'glTF\x02\x00\x00\x00\xec\x01\x00\x00\xd0\x01\x00\x00JSON'
        expected_json = {
            "asset": {
                "version": "2",
            },
            "buffers": [{
                "byteLength": 0,
            }],
            "bufferViews": [],
            "accessors": [],
            "images": [],
            "meshes": [],
            "extensions": {
                "AVS_xviz": {
                    "type": "xviz/metadata",
                    "data": {
                        "version": "2.0.0",
                        "streams": {
                            "/vehicle_pose": {
                                "category": "POSE",
                            },
                            "/image/camera": {
                                "category": "PRIMITIVE",
                                "primitive_type": "IMAGE",
                            },
                            "/point/lidar": {
                                "category": "PRIMITIVE",
                                "primitive_type": "POINT",
                                "stream_style": {
                                    "radius_pixels": 1,
                                },
                                "coordinate": "VEHICLE_RELATIVE",
                            },
                        },
                    },
                },
            },
            "extensionsUsed": [
                "AVS_xviz",
            ],
        }
        expected_suffix = b'\x00\x00\x00\x00BIN\x00'

        assert data.startswith(expected_prefix)
        assert data.endswith(expected_suffix)
        data_json = json.loads(
            data[len(expected_prefix):-len(expected_suffix)].decode('ascii'))
        assert data_json == expected_json
示例#2
0
    def test_glb_normal_writer(self):
        builder = self._get_builder(circle=True)

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        expected = b'glTF\x02\x00\x00\x004\x02\x00\x00\x18\x02\x00\x00JSON{"asset":{"version":"2"'\
            b'},"buffers":[{"byteLength":0}],"bufferViews":[],"accessors":[],"images":[],"meshes"'\
            b':[],"extensions":{"AVS_xviz":{"type":"xviz/state_update","data":{"update_type":"INC'\
            b'REMENTAL","updates":[{"timestamp":2.000000000001,"poses":{"/vehicle_pose":{"timesta'\
            b'mp":2.000000000001,"map_origin":{"longitude":4.4,"latitude":5.5,"altitude":6.6},"po'\
            b'sition":[44.0,55.0,66.0],"orientation":[0.44,0.55,0.66]}},"primitives":{"/test_prim'\
            b'itive":{"circles":[{"center":[0.0,0.0,0.0],"radius":2.0}]}}}]}}},"extensionsUsed":['\
            b'"AVS_xviz"]}   \x00\x00\x00\x00BIN\x00'

        assert data == expected
示例#3
0
    def test_glb_polyline_writer(self):
        builder = self._get_builder(polyline=True)

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        expected = b'glTF\x02\x00\x00\x00\xac\x02\x00\x00x\x02\x00\x00JSON{"asset":{"version":"2"'\
            b'},"buffers":[{"byteLength":24}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteLeng'\
            b'th":24}],"accessors":[{"bufferView":0,"type":"VEC3","componentType":5126,"count":2}'\
            b'],"images":[],"meshes":[],"extensions":{"AVS_xviz":{"type":"xviz/state_update","dat'\
            b'a":{"update_type":"INCREMENTAL","updates":[{"timestamp":2.000000000001,"poses":{"/v'\
            b'ehicle_pose":{"timestamp":2.000000000001,"map_origin":{"longitude":4.4,"latitude":5'\
            b'.5,"altitude":6.6},"position":[44.0,55.0,66.0],"orientation":[0.44,0.55,0.66]}},"pr'\
            b'imitives":{"/test_primitive":{"polylines":[{"vertices":"#/accessors/0"}]}}}]}}},"ex'\
            b'tensionsUsed":["AVS_xviz"]} \x18\x00\x00\x00BIN\x00\x00\x00\x80?\x00\x00\x80?\x00'\
            b'\x00\x80?\x00\x00\x00@\x00\x00\x00@\x00\x00\x00@'

        assert data == expected
示例#4
0
    def test_glb_polygon_writer(self):
        builder = self._get_builder(polygon=True)

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        expected = b'glTF\x02\x00\x00\x00\xf0\x02\x00\x00\x98\x02\x00\x00JSON{"asset":{"version":'\
            b'"2"},"buffers":[{"byteLength":60}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteL'\
            b'ength":60}],"accessors":[{"bufferView":0,"type":"VEC3","componentType":5126,"count"'\
            b':5}],"images":[],"meshes":[],"extensions":{"AVS_xviz":{"type":"xviz/state_update","'\
            b'data":{"update_type":"INCREMENTAL","updates":[{"timestamp":2.000000000001,"poses":{'\
            b'"/vehicle_pose":{"timestamp":2.000000000001,"map_origin":{"longitude":4.4,"latitude'\
            b'":5.5,"altitude":6.6},"position":[44.0,55.0,66.0],"orientation":[0.44,0.55,0.66]}},'\
            b'"primitives":{"/test_primitive":{"polygons":[{"base":{"style":{"height":2.0}},"vert'\
            b'ices":"#/accessors/0"}]}}}]}}},"extensionsUsed":["AVS_xviz"]}  <\x00\x00\x00BIN\x00'\
            b'\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x00@\x00\x00\x00@\x00\x00\x00@\x00'\
            b'\x00@@\x00\x00@@\x00\x00@@\x00\x00\x80@\x00\x00\x80@\x00\x00\x80@\x00\x00\x80?\x00'\
            b'\x00\x80?\x00\x00\x80?'

        assert data == expected
示例#5
0
    def test_glb_point_cloud_writer(self):
        builder = self._get_builder(points=True)

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        expected = b'glTF\x02\x00\x00\x00D\x03\x00\x00\xf8\x02\x00\x00JSON{"asset":{"version":"2"'\
            b'},"buffers":[{"byteLength":48}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteLeng'\
            b'th":36},{"buffer":0,"byteOffset":36,"byteLength":12}],"accessors":[{"bufferView":0,'\
            b'"type":"VEC3","componentType":5126,"count":3},{"bufferView":1,"type":"VEC4","compon'\
            b'entType":5121,"count":3}],"images":[],"meshes":[],"extensions":{"AVS_xviz":{"type":'\
            b'"xviz/state_update","data":{"update_type":"INCREMENTAL","updates":[{"timestamp":2.0'\
            b'00000000001,"poses":{"/vehicle_pose":{"timestamp":2.000000000001,"map_origin":{"lon'\
            b'gitude":4.4,"latitude":5.5,"altitude":6.6},"position":[44.0,55.0,66.0],"orientation'\
            b'":[0.44,0.55,0.66]}},"primitives":{"/test_primitive":{"points":[{"points":"#/access'\
            b'ors/0","colors":"#/accessors/1"}]}}}]}}},"extensionsUsed":["AVS_xviz"]}  0\x00\x00'\
            b'\x00BIN\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?\x00\x00'\
            b'\x80?\x00\x00\x80?\x00\x00\x00@\x00\x00\x00@\x00\x00\x00@\xff\x00\x00\x80\x00\xff'\
            b'\x00\x80\x00\x00\xff\x80'

        assert data == expected
示例#6
0
    def test_glb_normal_writer(self):
        builder = xb.XVIZBuilder()
        builder.pose()\
            .timestamp(2.000000000001)\
            .map_origin(4.4, 5.5, 6.6)\
            .position(44., 55., 66.)\
            .orientation(0.44, 0.55, 0.66)
        builder.primitive('/test_primitive').circle([0, 0, 0], 2)

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZGLBWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        expected = b'glTF\x02\x00\x00\x004\x02\x00\x00\x18\x02\x00\x00JSON{"asset":{"version":"2"'\
            b'},"buffers":[{"byteLength":0}],"bufferViews":[],"accessors":[],"image":[],"meshes":'\
            b'[],"extensions":{"AVS_xviz":{"type":"#xviz/state_update","data":{"update_type":"#IN'\
            b'CREMENTAL","updates":[{"timestamp":2.000000000001,"poses":{"/vehicle_pose":{"timest'\
            b'amp":2.000000000001,"map_origin":{"longitude":4.4,"latitude":5.5,"altitude":6.6},"p'\
            b'osition":[44.0,55.0,66.0],"orientation":[0.44,0.55,0.66]}},"primitives":{"/test_pri'\
            b'mitive":{"circles":[{"center":[0.0,0.0,0.0],"radius":2.0}]}}}]}}},"extensionsUsed":'\
            b'["AVS_xviz"]}\x00\x00\x00\x00\x00\x00BIN\x00'

        assert data == expected