diff --git a/GUI/src/main/java/cz/fidentis/analyst/gui/HistogramComponent.java b/GUI/src/main/java/cz/fidentis/analyst/gui/HistogramComponent.java index 478e65ec5eb3d9b744129f766fe5d656a3e7c864..280fc4ddcc65da58d918564dbc28faf83d0af410 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/gui/HistogramComponent.java +++ b/GUI/src/main/java/cz/fidentis/analyst/gui/HistogramComponent.java @@ -1,8 +1,10 @@ package cz.fidentis.analyst.gui; +import cz.fidentis.analyst.mesh.core.MeshFacet; + +import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; @@ -27,16 +29,20 @@ import java.util.TreeMap; */ public class HistogramComponent extends JPanel { + private final DrawCanvas drawnHistogram = new DrawCanvas(); private final JSpinner minSpinner = new JSpinner(); private final JSpinner maxSpinner = new JSpinner(); - List<Double> values; - int intervalsCount = 20; - Double minValue = 1.0; - Double maxValue = 10.0; - Double oneStep = 1.0; - int maxFrequency = 1; - Map<Double, Integer> frequencies = new TreeMap<>(); - DrawCanvas drawnHistogram = new DrawCanvas(); + + private Map<MeshFacet, List<Double>> values; + private Double minValue = 1.0; + private Double maxValue = 10.0; + private Double oneStep = 1.0; + private final Map<Double, Integer> frequencies = new TreeMap<>(); + + private int maxFrequency = 1; + private int intervalsCount = 20; + + public HistogramComponent() { setupComponents(); @@ -47,31 +53,31 @@ public class HistogramComponent extends JPanel { */ private void setupComponents() { setBackground(new Color(0, 174, 163)); - setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); + add(new JLabel("Number of intervals:")); JSlider intervalSlider = new JSlider(JSlider.HORIZONTAL, 0, 200, intervalsCount); intervalSlider.setMajorTickSpacing(20); intervalSlider.setMinorTickSpacing(5); intervalSlider.setPaintTicks(true); intervalSlider.setPaintLabels(true); intervalSlider.setBackground(new Color(0, 174, 163)); - add(intervalSlider); - drawnHistogram.setMinimumSize(new Dimension(getMinimumSize().width, 270)); - drawnHistogram.setMaximumSize(new Dimension(getMaximumSize().width, 270)); - drawnHistogram.setPreferredSize(new Dimension(getPreferredSize().width, 270)); - + drawnHistogram.setMinimumSize(new Dimension(getMinimumSize().width, 330)); + drawnHistogram.setMaximumSize(new Dimension(getMaximumSize().width, 330)); + drawnHistogram.setPreferredSize(new Dimension(getPreferredSize().width, 330)); add(drawnHistogram); - add(new JLabel("Select minimum value of distances")); - add(minSpinner); - add(new JLabel("Select maximum value of distances")); - add(maxSpinner); + Box tempBox = new Box(BoxLayout.LINE_AXIS); + + tempBox.add(new JLabel("Select minimum value of distances")); + tempBox.add(minSpinner); + tempBox.add(new JLabel("Select maximum value of distances")); + tempBox.add(maxSpinner); JButton newButton = new JButton("Set and Compute"); newButton.addActionListener(e -> { - intervalsCount = intervalSlider.getValue(); minValue = (Double) minSpinner.getValue(); maxValue = (Double) maxSpinner.getValue(); @@ -81,7 +87,8 @@ public class HistogramComponent extends JPanel { drawnHistogram.repaint(); }); - add(newButton); + tempBox.add(newButton); + add(tempBox); } @@ -100,18 +107,18 @@ public class HistogramComponent extends JPanel { } - public List<Double> getValues() { + public Map<MeshFacet, List<Double>> getValues() { return values; } /** * Set new distances and compute their frequencies * - * @param values + * @param values Values */ - public void setValues(List<Double> values) { + public void setValues(Map<MeshFacet, List<Double>> values) { this.values = values; - setMinMax(); + findMinMax(); computeFrequencies(); drawnHistogram.repaint(); setSpinners(); @@ -129,9 +136,11 @@ public class HistogramComponent extends JPanel { for (Double i = minValue; i < maxValue; i += oneStep) { int currFrequency = 0; //Number of values in current interval - for (Double temp : values) { - if (temp >= i && temp < i + oneStep) { - currFrequency++; + for (List<Double> facetValues : values.values() ){ + for (Double temp : facetValues) { + if (temp >= i && temp < i + oneStep) { + currFrequency++; + } } } if (currFrequency > maxFrequency) { @@ -142,15 +151,17 @@ public class HistogramComponent extends JPanel { } } - private void setMinMax() { - minValue = values.get(0); - maxValue = values.get(0); - for (Double temp : values) { - if (temp < minValue) { - minValue = temp; - } - if (temp > maxValue) { - maxValue = temp; + private void findMinMax() { + minValue = Double.MAX_VALUE; + maxValue = Double.MIN_VALUE; + for (List<Double> facetValues : values.values() ){ + for (Double temp : facetValues) { + if (temp < minValue) { + minValue = temp; + } + if (temp > maxValue) { + maxValue = temp; + } } } } @@ -159,13 +170,16 @@ public class HistogramComponent extends JPanel { * Cut of distances that are before minimum or after maximum distance selected by user */ private void cutValues() { - for (int i = 0; i < values.size(); ++i) { - if (values.get(i) < minValue) { - values.set(i, minValue); - } else if (values.get(i) > maxValue) { - values.set(i, maxValue); + for (List<Double> double_values : values.values() ){ + for (int i = 0; i < values.size(); ++i) { + if (double_values.get(i) < minValue) { + double_values.set(i, minValue); + } else if (double_values.get(i) > maxValue) { + double_values.set(i, maxValue); + } } } + } public Double getMinValue() { @@ -206,8 +220,9 @@ public class HistogramComponent extends JPanel { g2.fillRect(place, 300 - height, moveStep - 2, height); g.setColor(Color.BLACK); - String temp = String.format("%.4f", entry.getKey()); - g2.drawString(temp, place, this.getHeight() - 50); + String value = String.format("%.4f", entry.getKey()); + g2.drawString(value, place, this.getHeight() - 50); + g2.drawString(entry.getValue().toString(), place, 50); place += moveStep; } } diff --git a/GUI/src/main/java/cz/fidentis/analyst/tests/HeatMapsTestApp.java b/GUI/src/main/java/cz/fidentis/analyst/tests/HeatMapsTestApp.java index f82a1bbb62efea495ad55858444fb61c49155a04..f185a9102ebaa4c6ed83439f0b6c71b3aa71449b 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/tests/HeatMapsTestApp.java +++ b/GUI/src/main/java/cz/fidentis/analyst/tests/HeatMapsTestApp.java @@ -4,14 +4,30 @@ import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; import cz.fidentis.analyst.face.HumanFace; +import cz.fidentis.analyst.gui.Canvas; +import cz.fidentis.analyst.gui.GeneralGLEventListener; import cz.fidentis.analyst.gui.HistogramComponent; import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshModel; +import cz.fidentis.analyst.mesh.core.MeshPoint; +import cz.fidentis.analyst.visitors.mesh.Curvature; +import cz.fidentis.analyst.visitors.mesh.HausdorffDistance; +import cz.fidentis.analyst.visitors.mesh.HausdorffDistance.Strategy; +import org.openide.util.Exceptions; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.vecmath.Point3d; import javax.vecmath.Vector3d; -import java.awt.*; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.io.File; +import java.io.IOException; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import static com.jogamp.opengl.GL.GL_FRONT_AND_BACK; import static com.jogamp.opengl.GL.GL_VIEWPORT; @@ -19,21 +35,6 @@ import static com.jogamp.opengl.GL2GL3.GL_FILL; import static com.jogamp.opengl.GL2GL3.GL_LINE; import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW_MATRIX; import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION_MATRIX; -import cz.fidentis.analyst.gui.Canvas; -import cz.fidentis.analyst.gui.GeneralGLEventListener; -import cz.fidentis.analyst.mesh.core.MeshPoint; -import cz.fidentis.analyst.visitors.mesh.Curvature; -import cz.fidentis.analyst.visitors.mesh.HausdorffDistance; -import cz.fidentis.analyst.visitors.mesh.HausdorffDistance.Strategy; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.vecmath.Point3d; -import org.openide.util.Exceptions; /** * Testing application displaying different heat maps in 3D. @@ -106,7 +107,6 @@ public class HeatMapsTestApp extends GeneralGLEventListener { c.gridx = 4; c.weightx = 2; c.gridy = 1; - colorListener.histogram.setSize(new Dimension(200,200)); TEST_FRAME.add(colorListener.histogram,c); c.weightx = 1; c.gridwidth = 1; @@ -166,7 +166,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { long duration = System.currentTimeMillis() - startTime; System.err.println(duration + "\tmsec: Gaussian curvature"); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } /** @@ -184,7 +184,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { long duration = System.currentTimeMillis() - startTime; System.err.println(duration + "\tmsec: Mean curvature"); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } /** @@ -202,7 +202,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { long duration = System.currentTimeMillis() - startTime; System.err.println(duration + "\tmsec: Minimum principal curvature"); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } /** @@ -219,7 +219,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { values = vis.getMaxPrincipalCurvatures(); long duration = System.currentTimeMillis() - startTime; System.err.println(duration + "\tmsec: Maximum principal curvature"); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } /** @@ -240,8 +240,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { } catch (IOException ex) { Exceptions.printStackTrace(ex); } - List<Double> distanceList = values.get(getModel().getFacets().get(0)); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } /** @@ -263,7 +262,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { Exceptions.printStackTrace(ex); } List<Double> distanceList = values.get(getModel().getFacets().get(0)); - histogram.setValues(values.get(this.getModel().getFacets().get(0))); + histogram.setValues(values); } @Override @@ -305,7 +304,7 @@ public class HeatMapsTestApp extends GeneralGLEventListener { protected void drawHeatmap(MeshModel model) { for (int i = 0; i < model.getFacets().size(); i++) { - renderFaceWithHeatmap(model.getFacets().get(i), histogram.getValues(), histogram.getMinValue(), histogram.getMaxValue()); + renderFaceWithHeatmap(model.getFacets().get(i), histogram.getValues().get(model.getFacets().get(i)), histogram.getMinValue(), histogram.getMaxValue()); } }