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.vision.pipe.impl;
019
020import java.util.ArrayList;
021import java.util.List;
022import org.opencv.core.Point;
023import org.photonvision.vision.frame.FrameStaticProperties;
024import org.photonvision.vision.opencv.DualOffsetValues;
025import org.photonvision.vision.pipe.CVPipe;
026import org.photonvision.vision.target.*;
027
028/** Represents a pipe that collects available 2d targets. */
029public class Collect2dTargetsPipe
030        extends CVPipe<
031                List<PotentialTarget>, List<TrackedTarget>, Collect2dTargetsPipe.Collect2dTargetsParams> {
032    /**
033     * Processes this pipeline.
034     *
035     * @param in Input for pipe processing.
036     * @return A list of tracked targets.
037     */
038    @Override
039    protected List<TrackedTarget> process(List<PotentialTarget> in) {
040        List<TrackedTarget> targets = new ArrayList<>();
041
042        var calculationParams =
043                new TrackedTarget.TargetCalculationParameters(
044                        params.targetOrientation == TargetOrientation.Landscape,
045                        params.targetOffsetPointEdge,
046                        params.robotOffsetPointMode,
047                        params.robotOffsetSinglePoint,
048                        params.dualOffsetValues,
049                        params.frameStaticProperties);
050
051        for (PotentialTarget target : in) {
052            targets.add(new TrackedTarget(target, calculationParams, target.shape));
053        }
054
055        return targets;
056    }
057
058    public static class Collect2dTargetsParams {
059        private final RobotOffsetPointMode robotOffsetPointMode;
060        private final Point robotOffsetSinglePoint;
061        private final DualOffsetValues dualOffsetValues;
062        private final TargetOffsetPointEdge targetOffsetPointEdge;
063        private final TargetOrientation targetOrientation;
064        private final FrameStaticProperties frameStaticProperties;
065
066        public Collect2dTargetsParams(
067                RobotOffsetPointMode robotOffsetPointMode,
068                Point robotOffsetSinglePoint,
069                DualOffsetValues dualOffsetValues,
070                TargetOffsetPointEdge targetOffsetPointEdge,
071                TargetOrientation orientation,
072                FrameStaticProperties frameStaticProperties) {
073            this.frameStaticProperties = frameStaticProperties;
074            this.robotOffsetPointMode = robotOffsetPointMode;
075            this.robotOffsetSinglePoint = robotOffsetSinglePoint;
076            this.dualOffsetValues = dualOffsetValues;
077            this.targetOffsetPointEdge = targetOffsetPointEdge;
078            targetOrientation = orientation;
079        }
080    }
081}