Commit 86d571d4 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch '120-set-transparency-of-cutting-planes' into 'master'

Transaprency of cutting planes

See merge request grp-fidentis/analyst2!137
parents b1583cce 0f6a22e6
Loading
Loading
Loading
Loading
+20 −1
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@ package cz.fidentis.analyst.scene;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2;
import java.awt.Color;
import java.awt.Color;
import java.util.Comparator;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3d;


/**
/**
@@ -32,6 +33,24 @@ public abstract class Drawable {
     */
     */
    private int renderMode = GL2.GL_FILL; // GL_FILL, GL_LINE, or GL_POINT
    private int renderMode = GL2.GL_FILL; // GL_FILL, GL_LINE, or GL_POINT


    /**
     * Comparator for Drawable objects based on transparency. Used for rendering.
     *
     * @author Dominik Racek
     */
    public static class TransparencyComparator implements Comparator<Drawable> {
        @Override
        public int compare(Drawable a, Drawable b) {
            if (a.transparency < b.transparency) {
                return 1;
            }
            if (a.transparency > b.transparency) {
                return -1;
            }
            return 0;
        }
    }

    /**
    /**
     * Renders the scene.
     * Renders the scene.
     * @param gl OpenGL context
     * @param gl OpenGL context
+5 −10
Original line number Original line Diff line number Diff line
@@ -117,17 +117,12 @@ public class SceneRenderer {
        gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_DIFFUSE, Color.white.getComponents(null), 0);
        gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_DIFFUSE, Color.white.getComponents(null), 0);
        
        
        setPosition(camera);
        setPosition(camera);
        List<DrawableFace> faces = getOrderedFaces(drawables);


        for (Drawable obj: drawables) {
        List<Drawable> objects = new ArrayList<>(drawables);
            if (!(obj instanceof DrawableFace) && obj.isShown()) {
        objects.sort(new Drawable.TransparencyComparator());
                obj.render(gl);
            }
        }


        for (DrawableFace obj: faces) {
        for (Drawable obj : objects) {
            if (obj.isShown()) {
            if (obj.isShown()) {
                //showBackface(obj);
                obj.render(gl);
                obj.render(gl);
            }
            }
        }
        }
+6 −4
Original line number Original line Diff line number Diff line
@@ -24,7 +24,9 @@ public class PolylinePanel extends JPanel {
    private static final int PREF_H = 500;
    private static final int PREF_H = 500;
    private static final int BORDER_GAP = 15;
    private static final int BORDER_GAP = 15;
    private static final Color PRIMARY_COLOR = Color.green;
    private static final Color PRIMARY_COLOR = Color.green;
    private static final Color SECONDARY_COLOR = Color.blue;
    private static final Color PRIMARY_MIRROR_COLOR = new Color(0, 85, 0);
    private static final Color SECONDARY_COLOR = new Color(0, 155, 200);
    private static final Color SECONDARY_MIRROR_COLOR = Color.blue;
    private static final Stroke GRAPH_STROKE = new BasicStroke(3f);
    private static final Stroke GRAPH_STROKE = new BasicStroke(3f);
    private List<Point3d> primaryPoints;
    private List<Point3d> primaryPoints;
    private List<Point3d> secondaryPoints;
    private List<Point3d> secondaryPoints;
@@ -144,11 +146,11 @@ public class PolylinePanel extends JPanel {


        if (mirrorCuts) {
        if (mirrorCuts) {
            drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
            drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
            drawFace(g2, primaryMirrorPoints, SECONDARY_COLOR, true);
            drawFace(g2, primaryMirrorPoints, PRIMARY_MIRROR_COLOR, true);


            if (secondaryPoints != null) {
            if (secondaryPoints != null) {
                drawFace(g2, secondaryPoints, PRIMARY_COLOR, false);
                drawFace(g2, secondaryPoints, SECONDARY_COLOR, false);
                drawFace(g2, secondaryMirrorPoints, SECONDARY_COLOR, false);
                drawFace(g2, secondaryMirrorPoints, SECONDARY_MIRROR_COLOR, false);
            }
            }
        } else {
        } else {
            drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
            drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
+2 −0
Original line number Original line Diff line number Diff line
@@ -168,8 +168,10 @@ public class ProfilesAction extends ControlPanelAction {
            case ProfilesPanel.ACTION_COMMAND_SHOW_HIDE_PLANE:
            case ProfilesPanel.ACTION_COMMAND_SHOW_HIDE_PLANE:
                if (((JToggleButton) ae.getSource()).isSelected()) {
                if (((JToggleButton) ae.getSource()).isSelected()) {
                    getScene().showCuttingPlanes();
                    getScene().showCuttingPlanes();
                    getScene().showMirrorPlanes();
                } else {
                } else {
                    getScene().hideCuttingPlanes();
                    getScene().hideCuttingPlanes();
                    getScene().hideMirrorPlanes();
                }
                }
                break;
                break;
            case ProfilesPanel.ACTION_COMMAND_EXPORT:
            case ProfilesPanel.ACTION_COMMAND_EXPORT:
+28 −12
Original line number Original line Diff line number Diff line
@@ -75,23 +75,39 @@ public class SymmetryAction extends ControlPanelAction {
        SymmetryEstimator primaryEstimator = new SymmetryEstimator(controlPanel.getSymmetryConfig());
        SymmetryEstimator primaryEstimator = new SymmetryEstimator(controlPanel.getSymmetryConfig());
        getPrimaryDrawableFace().getModel().compute(primaryEstimator);
        getPrimaryDrawableFace().getModel().compute(primaryEstimator);


        getCanvas().getScene().setDrawableSymmetryPlane(0,
        DrawablePlane primarySymmetryPlane = new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(),
                new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
                primaryEstimator.getSymmetryPlane());
        getCanvas().getScene().setDrawableCuttingPlane(0,
        primarySymmetryPlane.setTransparency(0.5f);
                new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
        getScene().setDrawableSymmetryPlane(0, primarySymmetryPlane);
        getCanvas().getScene().setDrawableMirrorPlane(0,

                new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
        DrawablePlane primaryCuttingPlane = new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(),
                primaryEstimator.getSymmetryPlane());
        primaryCuttingPlane.setTransparency(0.5f);
        getScene().setDrawableCuttingPlane(0, primaryCuttingPlane);

        DrawablePlane primaryMirrorPlane = new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(),
                primaryEstimator.getSymmetryPlane());
        primaryMirrorPlane.setTransparency(0.5f);
        getScene().setDrawableMirrorPlane(0, primaryMirrorPlane);


        if (getSecondaryDrawableFace() != null) {
        if (getSecondaryDrawableFace() != null) {
            SymmetryEstimator secondaryEstimator = new SymmetryEstimator(controlPanel.getSymmetryConfig());
            SymmetryEstimator secondaryEstimator = new SymmetryEstimator(controlPanel.getSymmetryConfig());
            getSecondaryDrawableFace().getModel().compute(secondaryEstimator);
            getSecondaryDrawableFace().getModel().compute(secondaryEstimator);


            getCanvas().getScene().setDrawableSymmetryPlane(1,
            DrawablePlane secondarySymmetryPlane = new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(),
                    new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
                    secondaryEstimator.getSymmetryPlane());
            getCanvas().getScene().setDrawableCuttingPlane(1,
            secondarySymmetryPlane.setTransparency(0.5f);
                    new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
            getScene().setDrawableSymmetryPlane(1, secondarySymmetryPlane);
            getCanvas().getScene().setDrawableMirrorPlane(1,

                    new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
            DrawablePlane secondaryCuttingPlane = new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(),
                    secondaryEstimator.getSymmetryPlane());
            secondaryCuttingPlane.setTransparency(0.5f);
            getScene().setDrawableCuttingPlane(1, secondaryCuttingPlane);

            DrawablePlane secondaryMirrorPlane = new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(),
                    secondaryEstimator.getSymmetryPlane());
            secondaryMirrorPlane.setTransparency(0.5f);
            getScene().setDrawableMirrorPlane(1, secondaryMirrorPlane);
        }
        }


        getCanvas().getScene().hideSymmetryPlanes();
        getCanvas().getScene().hideSymmetryPlanes();