mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
55 lines
2.0 KiB
C++
55 lines
2.0 KiB
C++
|
|
/*
|
||
|
|
* Copyright (C) Photon Vision.
|
||
|
|
*
|
||
|
|
* This program is free software: you can redistribute it and/or modify
|
||
|
|
* it under the terms of the GNU General Public License as published by
|
||
|
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
|
* (at your option) any later version.
|
||
|
|
*
|
||
|
|
* This program is distributed in the hope that it will be useful,
|
||
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
* GNU General Public License for more details.
|
||
|
|
*
|
||
|
|
* You should have received a copy of the GNU General Public License
|
||
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "photon/targeting/proto/PNPResultProto.h"
|
||
|
|
|
||
|
|
#include "photon.pb.h"
|
||
|
|
|
||
|
|
google::protobuf::Message* wpi::Protobuf<photon::PNPResult>::New(
|
||
|
|
google::protobuf::Arena* arena) {
|
||
|
|
return google::protobuf::Arena::CreateMessage<
|
||
|
|
photonvision::proto::ProtobufPNPResult>(arena);
|
||
|
|
}
|
||
|
|
|
||
|
|
photon::PNPResult wpi::Protobuf<photon::PNPResult>::Unpack(
|
||
|
|
const google::protobuf::Message& msg) {
|
||
|
|
auto m = static_cast<const photonvision::proto::ProtobufPNPResult*>(&msg);
|
||
|
|
|
||
|
|
if (!m->is_present()) {
|
||
|
|
return photon::PNPResult();
|
||
|
|
}
|
||
|
|
|
||
|
|
return photon::PNPResult{true,
|
||
|
|
wpi::UnpackProtobuf<frc::Transform3d>(m->best()),
|
||
|
|
m->best_reproj_err(),
|
||
|
|
wpi::UnpackProtobuf<frc::Transform3d>(m->alt()),
|
||
|
|
m->alt_reproj_err(),
|
||
|
|
m->ambiguity()};
|
||
|
|
}
|
||
|
|
|
||
|
|
void wpi::Protobuf<photon::PNPResult>::Pack(google::protobuf::Message* msg,
|
||
|
|
const photon::PNPResult& value) {
|
||
|
|
auto m = static_cast<photonvision::proto::ProtobufPNPResult*>(msg);
|
||
|
|
|
||
|
|
m->set_is_present(value.isPresent);
|
||
|
|
wpi::PackProtobuf(m->mutable_best(), value.best);
|
||
|
|
m->set_best_reproj_err(value.bestReprojErr);
|
||
|
|
wpi::PackProtobuf(m->mutable_alt(), value.alt);
|
||
|
|
m->set_alt_reproj_err(value.altReprojErr);
|
||
|
|
m->set_ambiguity(value.ambiguity);
|
||
|
|
}
|