Commit 6922bb8c authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch '191-fix-error-in-feature-points-rendering' into 'master'

Resolve "Fix error in feature points rendering"

Closes #191

See merge request grp-fidentis/analyst2!210
parents 1882da95 2883b90b
Loading
Loading
Loading
Loading
+28 −12
Original line number Diff line number Diff line
package cz.fidentis.analyst.featurepoints;

import cz.fidentis.analyst.Logger;
import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.core.ControlPanelAction;
import cz.fidentis.analyst.core.DoubleSpinner;
import cz.fidentis.analyst.core.LoadedActionEvent;
import static cz.fidentis.analyst.drawables.DrawableFeaturePoints.CLOSE_TO_MESH_COLOR;
import static cz.fidentis.analyst.drawables.DrawableFeaturePoints.OFF_THE_MESH_COLOR;
import static cz.fidentis.analyst.drawables.DrawableFeaturePoints.ON_THE_MESH_COLOR;
import cz.fidentis.analyst.events.HumanFaceEvent;
import cz.fidentis.analyst.events.HumanFaceListener;
import cz.fidentis.analyst.feature.FeaturePoint;
@@ -25,7 +29,6 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
    /*
     * GUI elements
     */
    private FeaturePointType hoveredFeaturePoint = null;
    private final FeaturePointsPanel controlPanel;
    private List<FeaturePointType> selectedFeaturePoints = new ArrayList<>();;
    
@@ -48,6 +51,9 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
            // If the FeaturePoints panel is focused...
            if (((JTabbedPane) e.getSource()).getSelectedComponent() instanceof FeaturePointsPanel) {
                getCanvas().getScene().setDefaultColors();
                setColorsOfFeaturePoints();
            } else {
                getPrimaryFeaturePoints().resetAllColorsToDefault();
            }
        });
        
@@ -77,7 +83,7 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
                break;
            case FeaturePointListPanel.ACTION_COMMAND_FEATURE_POINT_SELECT:
                selectFeaturePoint((LoadedActionEvent) ae);
                highlightSelectedFeaturePoints();
                setColorsOfFeaturePoints();
                break;
            case FeaturePointListPanel.ACTION_COMMAND_FEATURE_POINT_HOVER_IN:
                hoverFeaturePoint((LoadedActionEvent) ae, true);
@@ -87,6 +93,7 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
                break;
            case FeaturePointsPanel.ACTION_CHANGE_DISTANCE_THRESHOLD:
                changeDistanceThreshold(ae);
                setColorsOfFeaturePoints();
                break; 
            case FeaturePointsPanel.ACTION_PIN_ALL_FEATURE_POINTS:
                for (FeaturePoint fp : getPrimaryFeaturePoints().getFeaturePoints()) {
@@ -94,10 +101,12 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
                        pinFeaturePointToMesh(fp);
                    }
                }
                setColorsOfFeaturePoints();
                controlPanel.getFeaturePointListPanel().refreshPanel(this, getPrimaryFeaturePoints(), selectedFeaturePoints);
                break;
            case FeaturePointsPanel.ACTION_PIN_SELECTED_FEATURE_POINTS:
                workWithSelectedFp("pin");
                setColorsOfFeaturePoints();
                controlPanel.getFeaturePointListPanel().refreshPanel(this, getPrimaryFeaturePoints(), selectedFeaturePoints);
                break;
            default:
@@ -118,11 +127,9 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
    private void hoverFeaturePoint(LoadedActionEvent actionEvent, boolean entered) {
        final int index = (int) actionEvent.getData();
        
        setColorsOfFeaturePoints();
        if (entered) { // entering a feature point
            getPrimaryFeaturePoints().setColor(index, FEATURE_POINT_HOVER_COLOR);
            hoveredFeaturePoint = getTypeOfFeaturePoint(index);
        } else if (selectedFeaturePoints.contains(hoveredFeaturePoint)) { // leaving highlighted FP
            getPrimaryFeaturePoints().setColor(index, FEATURE_POINT_HIGHLIGHT_COLOR);
        } else { // leaving ordinary FP
            getPrimaryFeaturePoints().resetColorToDefault(index);
        }
@@ -159,19 +166,28 @@ public class FeaturePointsAction extends ControlPanelAction implements HumanFace
        }
    }
    
    private void highlightSelectedFeaturePoints() {
        if (selectedFeaturePoints.isEmpty()) {
            return;
        }

        for (int i = 0; i < getPrimaryFeaturePoints().getFeaturePoints().size(); i++) {
    private void setColorsOfFeaturePoints() {
        List<FeaturePoint> fps = getPrimaryFeaturePoints().getFeaturePoints();
        for (int i = 0; i < fps.size(); i++) {
            if (selectedFeaturePoints.contains(getTypeOfFeaturePoint(i))) {
                getPrimaryFeaturePoints().setColor(i, FEATURE_POINT_HIGHLIGHT_COLOR);
            } else {
                switch (fps.get(i).getRelationToMesh().getPositionType()) {
                    case ON_THE_MESH:
                        getPrimaryFeaturePoints().setColor(i, ON_THE_MESH_COLOR);
                        break;
                    case CLOSE_TO_MESH:
                        getPrimaryFeaturePoints().setColor(i, CLOSE_TO_MESH_COLOR);
                        break;
                    case OFF_THE_MESH:
                        getPrimaryFeaturePoints().setColor(i, OFF_THE_MESH_COLOR);
                        break;
                    default:
                        getPrimaryFeaturePoints().resetColorToDefault(i);
                }
            }
        }
    }
    
    private void workWithSelectedFp(String action) {
        if (selectedFeaturePoints.isEmpty()) {
+3 −1
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@ package cz.fidentis.analyst.featurepoints;

import cz.fidentis.analyst.core.ControlPanel;
import cz.fidentis.analyst.drawables.DrawableFeaturePoints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;

/**
@@ -73,7 +75,7 @@ public class FeaturePointsPanel extends ControlPanel {
     * Resets the slider into initial values
     */
    public void resetSlider() {
        thresholdSpinSlider.initDouble(0.1, 0.0, 0.2, 3);
        thresholdSpinSlider.initDouble(0.01, 0.0, 0.2, 3);
        thresholdSpinSlider.addSpinnerListener(createListener(action, ACTION_CHANGE_DISTANCE_THRESHOLD));
    }

+1 −10
Original line number Diff line number Diff line
@@ -85,16 +85,7 @@ public class DrawableFeaturePoints extends Drawable {
        if (specialColors.containsKey(index)) {
            return specialColors.get(index);
        } else {
            switch (featurePoints.get(index).getRelationToMesh().getPositionType()) {
                case ON_THE_MESH:
                    return ON_THE_MESH_COLOR;
                case CLOSE_TO_MESH:
                    return CLOSE_TO_MESH_COLOR;
                case OFF_THE_MESH:
                    return OFF_THE_MESH_COLOR;
                default:
                    return Color.BLACK;
            }
            return FP_DEFAULT_COLOR;
        }
    }