001/*
002 * MIT License
003 *
004 * Copyright (c) PhotonVision
005 *
006 * Permission is hereby granted, free of charge, to any person obtaining a copy
007 * of this software and associated documentation files (the "Software"), to deal
008 * in the Software without restriction, including without limitation the rights
009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010 * copies of the Software, and to permit persons to whom the Software is
011 * furnished to do so, subject to the following conditions:
012 *
013 * The above copyright notice and this permission notice shall be included in all
014 * copies or substantial portions of the Software.
015 *
016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
022 * SOFTWARE.
023 */
024
025package org.photonvision.simulation;
026
027import edu.wpi.first.math.geometry.Pose3d;
028import edu.wpi.first.math.geometry.Translation3d;
029import java.util.List;
030import org.photonvision.estimation.TargetModel;
031
032/** Describes a vision target located somewhere on the field that your vision system can detect. */
033public class VisionTargetSim {
034    private Pose3d pose;
035    private TargetModel model;
036
037    public final int fiducialID;
038
039    /**
040     * Describes a vision target located somewhere on the field that your vision system can detect.
041     *
042     * @param pose Pose3d of the tag in field-relative coordinates
043     * @param model TargetModel which describes the geometry of the target
044     */
045    public VisionTargetSim(Pose3d pose, TargetModel model) {
046        this.pose = pose;
047        this.model = model;
048        this.fiducialID = -1;
049    }
050
051    /**
052     * Describes a fiducial tag located somewhere on the field that your vision system can detect.
053     *
054     * @param pose Pose3d of the tag in field-relative coordinates
055     * @param model TargetModel which describes the geometry of the target(tag)
056     * @param id The ID of this fiducial tag
057     */
058    public VisionTargetSim(Pose3d pose, TargetModel model, int id) {
059        this.pose = pose;
060        this.model = model;
061        this.fiducialID = id;
062    }
063
064    /**
065     * Sets the pose of this target on the field.
066     *
067     * @param pose The pose in field-relative coordinates
068     */
069    public void setPose(Pose3d pose) {
070        this.pose = pose;
071    }
072
073    /**
074     * Sets the model describing this target's geometry.
075     *
076     * @param model The model of the target
077     */
078    public void setModel(TargetModel model) {
079        this.model = model;
080    }
081
082    /**
083     * Returns the pose of this target on the field.
084     *
085     * @return The pose in field-relative coordinates
086     */
087    public Pose3d getPose() {
088        return pose;
089    }
090
091    /**
092     * Returns the model describing this target's geometry.
093     *
094     * @return The model of the target
095     */
096    public TargetModel getModel() {
097        return model;
098    }
099
100    /** This target's vertices offset from its field pose. */
101    public List<Translation3d> getFieldVertices() {
102        return model.getFieldVertices(pose);
103    }
104
105    @Override
106    public boolean equals(Object obj) {
107        return this == obj
108                && obj instanceof VisionTargetSim o
109                && pose.equals(o.pose)
110                && model.equals(o.model);
111    }
112}