001/*
002 * Copyright (C) Photon Vision.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package org.photonvision.targeting.proto;
019
020import edu.wpi.first.math.geometry.Transform3d;
021import edu.wpi.first.util.protobuf.Protobuf;
022import org.photonvision.proto.Photon.ProtobufPNPResult;
023import org.photonvision.targeting.PnpResult;
024import us.hebi.quickbuf.Descriptors.Descriptor;
025
026public class PNPResultProto implements Protobuf<PnpResult, ProtobufPNPResult> {
027    @Override
028    public Class<PnpResult> getTypeClass() {
029        return PnpResult.class;
030    }
031
032    @Override
033    public Descriptor getDescriptor() {
034        return ProtobufPNPResult.getDescriptor();
035    }
036
037    @Override
038    public ProtobufPNPResult createMessage() {
039        return ProtobufPNPResult.newInstance();
040    }
041
042    @Override
043    public PnpResult unpack(ProtobufPNPResult msg) {
044        return new PnpResult(
045                Transform3d.proto.unpack(msg.getBest()),
046                Transform3d.proto.unpack(msg.getAlt()),
047                msg.getAmbiguity(),
048                msg.getBestReprojErr(),
049                msg.getAltReprojErr());
050    }
051
052    @Override
053    public void pack(ProtobufPNPResult msg, PnpResult value) {
054        Transform3d.proto.pack(msg.getMutableBest(), value.best);
055        Transform3d.proto.pack(msg.getMutableAlt(), value.alt);
056        msg.setAmbiguity(value.ambiguity)
057                .setBestReprojErr(value.bestReprojErr)
058                .setAltReprojErr(value.altReprojErr);
059    }
060}