# automatically generated by the FlatBuffers compiler, do not modify

# namespace: foxglove

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

# Camera calibration parameters
class CameraCalibration(object):
    __slots__ = ['_tab']

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

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

    # Timestamp of calibration data
    # CameraCalibration
    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 for the camera. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image.
    # CameraCalibration
    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

    # Image width
    # CameraCalibration
    def Width(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0

    # Image height
    # CameraCalibration
    def Height(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

    # Name of distortion model
    # 
    # Supported parameters: `plumb_bob` (k1, k2, p1, p2, k3) and `rational_polynomial` (k1, k2, p1, p2, k3, k4, k5, k6). Distortion models are based on [OpenCV's](https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html) [pinhole camera model](https://en.wikipedia.org/wiki/Distortion_%28optics%29#Software_correction). This is the same [implementation used by ROS](http://docs.ros.org/en/diamondback/api/image_geometry/html/c++/pinhole__camera__model_8cpp_source.html)
    # CameraCalibration
    def DistortionModel(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Distortion parameters
    # CameraCalibration
    def D(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Float64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # CameraCalibration
    def DAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
        return 0

    # CameraCalibration
    def DLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # CameraCalibration
    def DIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        return o == 0

    # Intrinsic camera matrix (3x3 row-major matrix)
    # 
    # A 3x3 row-major matrix for the raw (distorted) image.
    # 
    # Projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx, fy) and principal point (cx, cy).
    # 
    # ```
    #     [fx  0 cx]
    # K = [ 0 fy cy]
    #     [ 0  0  1]
    # ```
    # length 9
    # CameraCalibration
    def K(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Float64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # CameraCalibration
    def KAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
        return 0

    # CameraCalibration
    def KLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # CameraCalibration
    def KIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        return o == 0

    # Rectification matrix (stereo cameras only, 3x3 row-major matrix)
    # 
    # A rotation matrix aligning the camera coordinate system to the ideal stereo image plane so that epipolar lines in both stereo images are parallel.
    # length 9
    # CameraCalibration
    def R(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Float64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # CameraCalibration
    def RAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
        return 0

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

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

    # Projection/camera matrix (3x4 row-major matrix)
    # 
    # ```
    #     [fx'  0  cx' Tx]
    # P = [ 0  fy' cy' Ty]
    #     [ 0   0   1   0]
    # ```
    # 
    # By convention, this matrix specifies the intrinsic (camera) matrix of the processed (rectified) image. That is, the left 3x3 portion is the normal camera intrinsic matrix for the rectified image.
    # 
    # It projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx', fy') and principal point (cx', cy') - these may differ from the values in K.
    # 
    # For monocular cameras, Tx = Ty = 0. Normally, monocular cameras will also have R = the identity and P[1:3,1:3] = K.
    # 
    # For a stereo pair, the fourth column [Tx Ty 0]' is related to the position of the optical center of the second camera in the first camera's frame. We assume Tz = 0 so both cameras are in the same stereo image plane. The first camera always has Tx = Ty = 0. For the right (second) camera of a horizontal stereo pair, Ty = 0 and Tx = -fx' * B, where B is the baseline between the cameras.
    # 
    # Given a 3D point [X Y Z]', the projection (x, y) of the point onto the rectified image is given by:
    # 
    # ```
    # [u v w]' = P * [X Y Z 1]'
    #        x = u / w
    #        y = v / w
    # ```
    # 
    # This holds for both images of a stereo pair.
    # length 12
    # CameraCalibration
    def P(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.Float64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # CameraCalibration
    def PAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
        return 0

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

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

def CameraCalibrationStart(builder): builder.StartObject(9)
def Start(builder):
    return CameraCalibrationStart(builder)
def CameraCalibrationAddTimestamp(builder, timestamp): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(timestamp), 0)
def AddTimestamp(builder, timestamp):
    return CameraCalibrationAddTimestamp(builder, timestamp)
def CameraCalibrationAddFrameId(builder, frameId): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(frameId), 0)
def AddFrameId(builder, frameId):
    return CameraCalibrationAddFrameId(builder, frameId)
def CameraCalibrationAddWidth(builder, width): builder.PrependUint32Slot(2, width, 0)
def AddWidth(builder, width):
    return CameraCalibrationAddWidth(builder, width)
def CameraCalibrationAddHeight(builder, height): builder.PrependUint32Slot(3, height, 0)
def AddHeight(builder, height):
    return CameraCalibrationAddHeight(builder, height)
def CameraCalibrationAddDistortionModel(builder, distortionModel): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(distortionModel), 0)
def AddDistortionModel(builder, distortionModel):
    return CameraCalibrationAddDistortionModel(builder, distortionModel)
def CameraCalibrationAddD(builder, d): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(d), 0)
def AddD(builder, d):
    return CameraCalibrationAddD(builder, d)
def CameraCalibrationStartDVector(builder, numElems): return builder.StartVector(8, numElems, 8)
def StartDVector(builder, numElems):
    return CameraCalibrationStartDVector(builder, numElems)
def CameraCalibrationAddK(builder, k): builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(k), 0)
def AddK(builder, k):
    return CameraCalibrationAddK(builder, k)
def CameraCalibrationStartKVector(builder, numElems): return builder.StartVector(8, numElems, 8)
def StartKVector(builder, numElems):
    return CameraCalibrationStartKVector(builder, numElems)
def CameraCalibrationAddR(builder, r): builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(r), 0)
def AddR(builder, r):
    return CameraCalibrationAddR(builder, r)
def CameraCalibrationStartRVector(builder, numElems): return builder.StartVector(8, numElems, 8)
def StartRVector(builder, numElems):
    return CameraCalibrationStartRVector(builder, numElems)
def CameraCalibrationAddP(builder, p): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(p), 0)
def AddP(builder, p):
    return CameraCalibrationAddP(builder, p)
def CameraCalibrationStartPVector(builder, numElems): return builder.StartVector(8, numElems, 8)
def StartPVector(builder, numElems):
    return CameraCalibrationStartPVector(builder, numElems)
def CameraCalibrationEnd(builder): return builder.EndObject()
def End(builder):
    return CameraCalibrationEnd(builder)