simulariumio/trajectory_converter.py
def _get_spatial_bundle_data_subpoints(
        agent_data: AgentData,
        type_ids: np.ndarray,
    ) -> List[Dict[str, Any]]:
        """
        Return the spatialData's bundleData for a simulation
        of agents with subpoints, packing buffer with jagged data is slower
        """
        bundle_data = []
        uids = {}
        used_unique_IDs = list(np.unique(agent_data.unique_ids))
        total_steps = (
            agent_data.n_timesteps
            if agent_data.n_timesteps >= 0
            else len(agent_data.times)
        )
        for time_index in range(total_steps):
            # timestep
            frame_data = {}
            frame_data["frameNumber"] = time_index
            frame_data["time"] = float(agent_data.times[time_index])
            n_agents = int(agent_data.n_agents[time_index])
            i = 0
            buffer_size = (V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1) * n_agents
            for agent_index in range(n_agents):
                n_subpoints = int(agent_data.n_subpoints[time_index][agent_index])
                if n_subpoints > 0:
                    buffer_size += 3 * n_subpoints
                    if agent_data.draw_fiber_points:
                        buffer_size += (
                            V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                        ) * max(math.ceil(n_subpoints / 2.0), 1)
            local_buf = np.zeros(buffer_size)
            for agent_index in range(n_agents):
                # add agent
                local_buf[
                    i + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                ] = agent_data.viz_types[time_index, agent_index]
                local_buf[
                    i + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX
                ] = agent_data.unique_ids[time_index, agent_index]
                local_buf[i + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX] = type_ids[
                    time_index, agent_index
                ]
                local_buf[
                    i
                    + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX : i
                    + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX
                    + 3
                ] = agent_data.positions[time_index, agent_index]
                local_buf[
                    i
                    + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX : i
                    + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX
                    + 3
                ] = agent_data.rotations[time_index, agent_index]
                local_buf[i + V1_SPATIAL_BUFFER_STRUCT.R_INDEX] = agent_data.radii[
                    time_index, agent_index
                ]
                n_subpoints = int(agent_data.n_subpoints[time_index][agent_index])
                if n_subpoints > 0:
                    # add subpoints to fiber agent
                    subpoints = [3 * n_subpoints]
                    for p in range(n_subpoints):
                        for d in range(3):
                            subpoints.append(
                                agent_data.subpoints[time_index][agent_index][p][d]
                            )
                    local_buf[
                        i
                        + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX : i
                        + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                        + 1
                        + 3 * n_subpoints
                    ] = subpoints
                    i += (
                        V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                    ) + 3 * n_subpoints
                    # optionally draw spheres at points
                    if agent_data.draw_fiber_points:
                        for p in range(n_subpoints):
                            # every other fiber point
                            if p % 2 != 0:
                                continue
                            # unique instance ID
                            raw_uid = (
                                100
                                * (agent_data.unique_ids[time_index, agent_index] + 1)
                                + p
                            )
                            if raw_uid not in uids:
                                uid = raw_uid
                                while uid in used_unique_IDs:
                                    uid += 100
                                uids[raw_uid] = uid
                                used_unique_IDs.append(uid)
                            # add sphere
                            local_buf[
                                i + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                            ] = VIZ_TYPE.DEFAULT
                            local_buf[i + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX] = uids[
                                raw_uid
                            ]
                            local_buf[
                                i + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX
                            ] = type_ids[time_index, agent_index]
                            local_buf[
                                i
                                + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX : i
                                + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX
                                + 3
                            ] = agent_data.subpoints[time_index][agent_index][p]
                            local_buf[i + V1_SPATIAL_BUFFER_STRUCT.R_INDEX] = 0.5
                            i += V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                else:
                    i += V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
            frame_data["data"] = local_buf.tolist()
            bundle_data.append(frame_data)
        return bundle_data

        Return the spatialData's bundleData for a simulation
        of agents with subpoints, packing buffer with jagged data is slower
        
Return the spatialData's bundleData for a simulation
of agents with subpoints, packing buffer with jagged data is slower
Return the spatialData ' s bundleData for a simulation of agents with subpoints packing buffer with jagged data is slower
def _get_spatial_bundle_data_subpoints(
        agent_data: AgentData,
        type_ids: np.ndarray,
    ) -> List[Dict[str, Any]]:
        bundle_data = []
        uids = {}
        used_unique_IDs = list(np.unique(agent_data.unique_ids))
        total_steps = (
            agent_data.n_timesteps
            if agent_data.n_timesteps >= 0
            else len(agent_data.times)
        )
        for time_index in range(total_steps):
            frame_data = {}
            frame_data["frameNumber"] = time_index
            frame_data["time"] = float(agent_data.times[time_index])
            n_agents = int(agent_data.n_agents[time_index])
            i = 0
            buffer_size = (V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1) * n_agents
            for agent_index in range(n_agents):
                n_subpoints = int(agent_data.n_subpoints[time_index][agent_index])
                if n_subpoints > 0:
                    buffer_size += 3 * n_subpoints
                    if agent_data.draw_fiber_points:
                        buffer_size += (
                            V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                        ) * max(math.ceil(n_subpoints / 2.0), 1)
            local_buf = np.zeros(buffer_size)
            for agent_index in range(n_agents):
                local_buf[
                    i + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                ] = agent_data.viz_types[time_index, agent_index]
                local_buf[
                    i + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX
                ] = agent_data.unique_ids[time_index, agent_index]
                local_buf[i + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX] = type_ids[
                    time_index, agent_index
                ]
                local_buf[
                    i
                    + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX : i
                    + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX
                    + 3
                ] = agent_data.positions[time_index, agent_index]
                local_buf[
                    i
                    + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX : i
                    + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX
                    + 3
                ] = agent_data.rotations[time_index, agent_index]
                local_buf[i + V1_SPATIAL_BUFFER_STRUCT.R_INDEX] = agent_data.radii[
                    time_index, agent_index
                ]
                n_subpoints = int(agent_data.n_subpoints[time_index][agent_index])
                if n_subpoints > 0:
                    subpoints = [3 * n_subpoints]
                    for p in range(n_subpoints):
                        for d in range(3):
                            subpoints.append(
                                agent_data.subpoints[time_index][agent_index][p][d]
                            )
                    local_buf[
                        i
                        + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX : i
                        + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                        + 1
                        + 3 * n_subpoints
                    ] = subpoints
                    i += (
                        V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                    ) + 3 * n_subpoints
                    if agent_data.draw_fiber_points:
                        for p in range(n_subpoints):
                            if p % 2 != 0:
                                continue
                            raw_uid = (
                                100
                                * (agent_data.unique_ids[time_index, agent_index] + 1)
                                + p
                            )
                            if raw_uid not in uids:
                                uid = raw_uid
                                while uid in used_unique_IDs:
                                    uid += 100
                                uids[raw_uid] = uid
                                used_unique_IDs.append(uid)
                            local_buf[
                                i + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                            ] = VIZ_TYPE.DEFAULT
                            local_buf[i + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX] = uids[
                                raw_uid
                            ]
                            local_buf[
                                i + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX
                            ] = type_ids[time_index, agent_index]
                            local_buf[
                                i
                                + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX : i
                                + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX
                                + 3
                            ] = agent_data.subpoints[time_index][agent_index][p]
                            local_buf[i + V1_SPATIAL_BUFFER_STRUCT.R_INDEX] = 0.5
                            i += V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
                else:
                    i += V1_SPATIAL_BUFFER_STRUCT.VALUES_PER_AGENT - 1
            frame_data["data"] = local_buf.tolist()
            bundle_data.append(frame_data)
        return bundle_data
def _get_spatial_bundle_data_subpoints ( agent_data : AgentData , type_ids : np . ndarray , ) -> List [ Dict [ str , Any ] ] : bundle_data = [ ] uids = { } used_unique_IDs = list ( np . unique ( agent_data . unique_ids ) ) total_steps = ( agent_data . n_timesteps if agent_data . n_timesteps >= 0 else len ( agent_data . times ) ) for time_index in range ( total_steps ) : frame_data = { } frame_data [ "frameNumber" ] = time_index frame_data [ "time" ] = float ( agent_data . times [ time_index ] ) n_agents = int ( agent_data . n_agents [ time_index ] ) i = 0 buffer_size = ( V1_SPATIAL_BUFFER_STRUCT . VALUES_PER_AGENT - 1 ) * n_agents for agent_index in range ( n_agents ) : n_subpoints = int ( agent_data . n_subpoints [ time_index ] [ agent_index ] ) if n_subpoints > 0 : buffer_size += 3 * n_subpoints if agent_data . draw_fiber_points : buffer_size += ( V1_SPATIAL_BUFFER_STRUCT . VALUES_PER_AGENT - 1 ) * max ( math . ceil ( n_subpoints / 2.0 ) , 1 ) local_buf = np . zeros ( buffer_size ) for agent_index in range ( n_agents ) : local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . VIZ_TYPE_INDEX ] = agent_data . viz_types [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . UID_INDEX ] = agent_data . unique_ids [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . TID_INDEX ] = type_ids [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . POSX_INDEX : i + V1_SPATIAL_BUFFER_STRUCT . POSX_INDEX + 3 ] = agent_data . positions [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . ROTX_INDEX : i + V1_SPATIAL_BUFFER_STRUCT . ROTX_INDEX + 3 ] = agent_data . rotations [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . R_INDEX ] = agent_data . radii [ time_index , agent_index ] n_subpoints = int ( agent_data . n_subpoints [ time_index ] [ agent_index ] ) if n_subpoints > 0 : subpoints = [ 3 * n_subpoints ] for p in range ( n_subpoints ) : for d in range ( 3 ) : subpoints . append ( agent_data . subpoints [ time_index ] [ agent_index ] [ p ] [ d ] ) local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX : i + V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX + 1 + 3 * n_subpoints ] = subpoints i += ( V1_SPATIAL_BUFFER_STRUCT . VALUES_PER_AGENT - 1 ) + 3 * n_subpoints if agent_data . draw_fiber_points : for p in range ( n_subpoints ) : if p % 2 != 0 : continue raw_uid = ( 100 * ( agent_data . unique_ids [ time_index , agent_index ] + 1 ) + p ) if raw_uid not in uids : uid = raw_uid while uid in used_unique_IDs : uid += 100 uids [ raw_uid ] = uid used_unique_IDs . append ( uid ) local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . VIZ_TYPE_INDEX ] = VIZ_TYPE . DEFAULT local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . UID_INDEX ] = uids [ raw_uid ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . TID_INDEX ] = type_ids [ time_index , agent_index ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . POSX_INDEX : i + V1_SPATIAL_BUFFER_STRUCT . POSX_INDEX + 3 ] = agent_data . subpoints [ time_index ] [ agent_index ] [ p ] local_buf [ i + V1_SPATIAL_BUFFER_STRUCT . R_INDEX ] = 0.5 i += V1_SPATIAL_BUFFER_STRUCT . VALUES_PER_AGENT - 1 else : i += V1_SPATIAL_BUFFER_STRUCT . VALUES_PER_AGENT - 1 frame_data [ "data" ] = local_buf . tolist ( ) bundle_data . append ( frame_data ) return bundle_data
Return the spatialData's bundleData for a simulation
of agents with subpoints, packing buffer with jagged data is slower
Return the spatialData ' s bundleData for a simulation of agents with subpoints packing buffer with jagged data is slower
"""
        Return the spatialData's bundleData for a simulation
        of agents with subpoints, packing buffer with jagged data is slower
        """ # timestep # add agent # add subpoints to fiber agent # optionally draw spheres at points # every other fiber point # unique instance ID # add sphere
agent_data
AgentData
type_ids
np.ndarray