# automatically generated by the FlatBuffers compiler, do not modify

# namespace: foxglove

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

# A 2D grid of data
class Grid(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = Grid()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsGrid(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # Grid
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Timestamp of grid
    # Grid
    def Timestamp(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            x = o + self._tab.Pos
            from .Time import Time
            obj = Time()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Frame of reference
    # Grid
    def FrameId(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Origin of grid's corner relative to frame of reference; grid is positioned in the x-y plane relative to this origin
    # Grid
    def Pose(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            x = self._tab.Indirect(o + self._tab.Pos)
            from .Pose import Pose
            obj = Pose()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Number of grid columns
    # Grid
    def ColumnCount(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0

    # Size of single grid cell along x and y axes, relative to `pose`
    # Grid
    def CellSize(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            x = self._tab.Indirect(o + self._tab.Pos)
            from .Vector2 import Vector2
            obj = Vector2()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Number of bytes between rows in `data`
    # Grid
    def RowStride(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0

    # Number of bytes between cells within a row in `data`
    # Grid
    def CellStride(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0

    # Fields in `data`. `red`, `green`, `blue`, and `alpha` are optional for customizing the grid's color.
    # Grid
    def Fields(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            x = self._tab.Vector(o)
            x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
            x = self._tab.Indirect(x)
            from .PackedElementField import PackedElementField
            obj = PackedElementField()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Grid
    def FieldsLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Grid
    def FieldsIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        return o == 0

    # Grid cell data, interpreted using `fields`, in row-major (y-major) order
    # Grid
    def Data(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1))
        return 0

    # Grid
    def DataAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o)
        return 0

    # Grid
    def DataLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Grid
    def DataIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        return o == 0

def GridStart(builder): builder.StartObject(9)
def Start(builder):
    return GridStart(builder)
def GridAddTimestamp(builder, timestamp): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(timestamp), 0)
def AddTimestamp(builder, timestamp):
    return GridAddTimestamp(builder, timestamp)
def GridAddFrameId(builder, frameId): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(frameId), 0)
def AddFrameId(builder, frameId):
    return GridAddFrameId(builder, frameId)
def GridAddPose(builder, pose): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(pose), 0)
def AddPose(builder, pose):
    return GridAddPose(builder, pose)
def GridAddColumnCount(builder, columnCount): builder.PrependUint32Slot(3, columnCount, 0)
def AddColumnCount(builder, columnCount):
    return GridAddColumnCount(builder, columnCount)
def GridAddCellSize(builder, cellSize): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(cellSize), 0)
def AddCellSize(builder, cellSize):
    return GridAddCellSize(builder, cellSize)
def GridAddRowStride(builder, rowStride): builder.PrependUint32Slot(5, rowStride, 0)
def AddRowStride(builder, rowStride):
    return GridAddRowStride(builder, rowStride)
def GridAddCellStride(builder, cellStride): builder.PrependUint32Slot(6, cellStride, 0)
def AddCellStride(builder, cellStride):
    return GridAddCellStride(builder, cellStride)
def GridAddFields(builder, fields): builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(fields), 0)
def AddFields(builder, fields):
    return GridAddFields(builder, fields)
def GridStartFieldsVector(builder, numElems): return builder.StartVector(4, numElems, 4)
def StartFieldsVector(builder, numElems):
    return GridStartFieldsVector(builder, numElems)
def GridAddData(builder, data): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0)
def AddData(builder, data):
    return GridAddData(builder, data)
def GridStartDataVector(builder, numElems): return builder.StartVector(1, numElems, 1)
def StartDataVector(builder, numElems):
    return GridStartDataVector(builder, numElems)
def GridEnd(builder): return builder.EndObject()
def End(builder):
    return GridEnd(builder)