Skip to content
Snippets Groups Projects
Commit 5a82334a authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Feature points

parent 7e384425
No related branches found
No related tags found
No related merge requests found
Showing
with 479 additions and 316 deletions
...@@ -2,6 +2,7 @@ package cz.fidentis.analyst.core; ...@@ -2,6 +2,7 @@ package cz.fidentis.analyst.core;
import cz.fidentis.analyst.canvas.Canvas; import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.scene.DrawableFace; import cz.fidentis.analyst.scene.DrawableFace;
import cz.fidentis.analyst.scene.DrawableFeaturePoints;
import cz.fidentis.analyst.scene.Scene; import cz.fidentis.analyst.scene.Scene;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
...@@ -82,6 +83,14 @@ public abstract class ControlPanelAction extends AbstractAction { ...@@ -82,6 +83,14 @@ public abstract class ControlPanelAction extends AbstractAction {
return (canvas.getScene() != null) ? canvas.getScene().getDrawableFace(1) : null; return (canvas.getScene() != null) ? canvas.getScene().getDrawableFace(1) : null;
} }
protected DrawableFeaturePoints getPrimaryFeaturePoints() {
return (canvas.getScene() != null) ? canvas.getScene().getDrawableFeaturePoints(0) : null;
}
protected DrawableFeaturePoints getSecondaryFeaturePoints() {
return (canvas.getScene() != null) ? canvas.getScene().getDrawableFeaturePoints(1) : null;
}
protected void renderScene() { protected void renderScene() {
canvas.renderScene(); canvas.renderScene();
} }
......
...@@ -13,7 +13,12 @@ import org.openide.util.NbBundle.Messages; ...@@ -13,7 +13,12 @@ import org.openide.util.NbBundle.Messages;
import cz.fidentis.analyst.Project; import cz.fidentis.analyst.Project;
import cz.fidentis.analyst.face.HumanFace; import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.face.HumanFaceFactory; import cz.fidentis.analyst.face.HumanFaceFactory;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.services.FeaturePointImportExportService;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -306,6 +311,20 @@ public final class ProjectTopComp extends TopComponent { ...@@ -306,6 +311,20 @@ public final class ProjectTopComp extends TopComponent {
} else { } else {
String faceId = HumanFaceFactory.instance().loadFace(file); String faceId = HumanFaceFactory.instance().loadFace(file);
HumanFace face = HumanFaceFactory.instance().getFace(faceId); HumanFace face = HumanFaceFactory.instance().getFace(faceId);
try {
// simple hack:
Path path = Paths.get(file.getAbsolutePath());
Path folder = path.getParent();
Path filename = path.getFileName();
String filestr = filename.toString();
filestr = filestr.split("_ECA.obj")[0];
filestr = filestr + "_landmarks.csv";
face.loadFeaturePoints(folder.toString(), filestr);
} catch(IOException ex) {
ex.printStackTrace();
}
this.project.setPrimaryFace(face); this.project.setPrimaryFace(face);
jLabel1.setText(face.getName()); jLabel1.setText(face.getName());
createSingleFaceTab(face, face.getName()); createSingleFaceTab(face, face.getName());
...@@ -339,6 +358,33 @@ public final class ProjectTopComp extends TopComponent { ...@@ -339,6 +358,33 @@ public final class ProjectTopComp extends TopComponent {
String faceId2 = HumanFaceFactory.instance().loadFace(file2); String faceId2 = HumanFaceFactory.instance().loadFace(file2);
HumanFace face1 = HumanFaceFactory.instance().getFace(faceId1); HumanFace face1 = HumanFaceFactory.instance().getFace(faceId1);
HumanFace face2 = HumanFaceFactory.instance().getFace(faceId2); HumanFace face2 = HumanFaceFactory.instance().getFace(faceId2);
try {
// simple hack:
Path path = Paths.get(file1.getAbsolutePath());
Path folder = path.getParent();
Path filename = path.getFileName();
String filestr = filename.toString();
filestr = filestr.split("_ECA.obj")[0];
filestr = filestr + "_landmarks.csv";
face1.loadFeaturePoints(folder.toString(), filestr);
} catch(IOException ex) {
ex.printStackTrace();
}
try {
// simple hack:
Path path = Paths.get(file2.getAbsolutePath());
Path folder = path.getParent();
Path filename = path.getFileName();
String filestr = filename.toString();
filestr = filestr.split("_ECA.obj")[0];
filestr = filestr + "_landmarks.csv";
face2.loadFeaturePoints(folder.toString(), filestr);
} catch(IOException ex) {
ex.printStackTrace();
}
this.project.setPrimaryFace(face1); this.project.setPrimaryFace(face1);
this.project.setSecondaryFaces(List.of(face2)); this.project.setSecondaryFaces(List.of(face2));
jLabel1.setText(face1.getName()); jLabel1.setText(face1.getName());
......
package cz.fidentis.analyst.registration; package cz.fidentis.analyst.registration;
import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.canvas.Canvas; import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.core.ControlPanelAction; import cz.fidentis.analyst.core.ControlPanelAction;
import cz.fidentis.analyst.feature.FeaturePoint; import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.icp.IcpTransformer; import cz.fidentis.analyst.icp.IcpTransformer;
import cz.fidentis.analyst.icp.NoUndersampling;
import cz.fidentis.analyst.icp.RandomStrategy; import cz.fidentis.analyst.icp.RandomStrategy;
import cz.fidentis.analyst.icp.UndersamplingStrategy; import cz.fidentis.analyst.icp.UndersamplingStrategy;
import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshPoint; import cz.fidentis.analyst.mesh.core.MeshPoint;
import cz.fidentis.analyst.scene.DrawableFace; import cz.fidentis.analyst.scene.DrawableFace;
import cz.fidentis.analyst.scene.DrawableFeaturePoints;
import java.awt.Color; import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField; import javax.swing.JFormattedTextField;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;
import javax.vecmath.Point3d; import javax.vecmath.Point3d;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
...@@ -46,12 +51,16 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -46,12 +51,16 @@ public class RegistrationAction extends ControlPanelAction {
public static final String ACTION_COMMAND_RESET_SCALE = "reset scale"; public static final String ACTION_COMMAND_RESET_SCALE = "reset scale";
public static final String ACTION_COMMAND_APPLY_TRANSFORMATIONS = "apply transformations"; public static final String ACTION_COMMAND_APPLY_TRANSFORMATIONS = "apply transformations";
public static final String ACTION_COMMAND_TRANSPARENCY = "transparency"; public static final String ACTION_COMMAND_TRANSPARENCY = "transparency";
public static final String ACTION_COMMAND_FP_CLOSENESS_THRESHOLD = "fp closeness treshold";
public static final String ACTION_COMMAND_ICP_SCALE = "ICP scale";
public static final String ACTION_COMMAND_ICP_MAX_ITERATIONS = "ICP iterations";
public static final String ACTION_COMMAND_ICP_ERROR = "ICP error";
public static final String ACTION_COMMAND_ICP_UNDERSAMPLING = "ICP undersampling";
/* /*
* Attributes handling the state * Attributes handling the state
*/ */
private IcpTransformer visitor = null;
private boolean scale = true; private boolean scale = true;
private int maxIterations = 10; private int maxIterations = 10;
private double error = 0.3; private double error = 0.3;
...@@ -66,7 +75,7 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -66,7 +75,7 @@ public class RegistrationAction extends ControlPanelAction {
/** /**
* Threshold of feature points showing too far away * Threshold of feature points showing too far away
*/ */
private double featurePointsThreshold = 0.1; private double featurePointsThreshold = 5.0;
private final RegistrationPanel controlPanel; private final RegistrationPanel controlPanel;
...@@ -86,13 +95,17 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -86,13 +95,17 @@ public class RegistrationAction extends ControlPanelAction {
double value; double value;
String action = ae.getActionCommand(); String action = ae.getActionCommand();
/*
* OTHER ACTIONS ARE INVOKED BY DIRECT CALL (to be refactored)
*/
switch (action) { switch (action) {
case ACTION_COMMAND_SHOW_HIDE_PANEL: case ACTION_COMMAND_SHOW_HIDE_PANEL:
hideShowPanelActionPerformed(ae, this.controlPanel); hideShowPanelActionPerformed(ae, this.controlPanel);
if (((JToggleButton) ae.getSource()).isSelected()) {
calculateFeaturePoints(); // color points
} else {
for (int i = 0; i < getPrimaryFeaturePoints().getFeaturePoints().size(); i++) {
getPrimaryFeaturePoints().setColor(i, DrawableFeaturePoints.DEFAULT_COLOR);
getSecondaryFeaturePoints().setColor(i, DrawableFeaturePoints.DEFAULT_COLOR);
}
}
break; break;
case ACTION_COMMAND_APPLY_ICP: case ACTION_COMMAND_APPLY_ICP:
applyICP(); applyICP();
...@@ -101,31 +114,49 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -101,31 +114,49 @@ public class RegistrationAction extends ControlPanelAction {
case ACTION_COMMAND_SHIFT_X: case ACTION_COMMAND_SHIFT_X:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getTranslation().x = value; getSecondaryDrawableFace().getTranslation().x = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getTranslation().x = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_SHIFT_Y: case ACTION_COMMAND_SHIFT_Y:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getTranslation().y = value; getSecondaryDrawableFace().getTranslation().y = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getTranslation().y = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_SHIFT_Z: case ACTION_COMMAND_SHIFT_Z:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getTranslation().z = value; getSecondaryDrawableFace().getTranslation().z = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getTranslation().z = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_ROTATE_X: case ACTION_COMMAND_ROTATE_X:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getRotation().x = value; getSecondaryDrawableFace().getRotation().x = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getRotation().x = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_ROTATE_Y: case ACTION_COMMAND_ROTATE_Y:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getRotation().y = value; getSecondaryDrawableFace().getRotation().y = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getRotation().y = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_ROTATE_Z: case ACTION_COMMAND_ROTATE_Z:
value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue(); value = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
getSecondaryDrawableFace().getRotation().z = value; getSecondaryDrawableFace().getRotation().z = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getRotation().z = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_SCALE: case ACTION_COMMAND_SCALE:
...@@ -133,6 +164,11 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -133,6 +164,11 @@ public class RegistrationAction extends ControlPanelAction {
getSecondaryDrawableFace().getScale().x = value; getSecondaryDrawableFace().getScale().x = value;
getSecondaryDrawableFace().getScale().y = value; getSecondaryDrawableFace().getScale().y = value;
getSecondaryDrawableFace().getScale().z = value; getSecondaryDrawableFace().getScale().z = value;
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().getScale().x = value;
getSecondaryFeaturePoints().getScale().y = value;
getSecondaryFeaturePoints().getScale().z = value;
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_FRONT_VIEW: case ACTION_COMMAND_FRONT_VIEW:
...@@ -144,14 +180,23 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -144,14 +180,23 @@ public class RegistrationAction extends ControlPanelAction {
break; break;
case ACTION_COMMAND_RESET_TRANSLATION: case ACTION_COMMAND_RESET_TRANSLATION:
getSecondaryDrawableFace().setTranslation(new Vector3d(0, 0, 0)); getSecondaryDrawableFace().setTranslation(new Vector3d(0, 0, 0));
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().setTranslation(new Vector3d(0, 0, 0));
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_RESET_ROTATION: case ACTION_COMMAND_RESET_ROTATION:
getSecondaryDrawableFace().setRotation(new Vector3d(0, 0, 0)); getSecondaryDrawableFace().setRotation(new Vector3d(0, 0, 0));
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().setRotation(new Vector3d(0, 0, 0));
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_RESET_SCALE: case ACTION_COMMAND_RESET_SCALE:
getSecondaryDrawableFace().setScale(new Vector3d(0, 0, 0)); getSecondaryDrawableFace().setScale(new Vector3d(0, 0, 0));
if (getSecondaryFeaturePoints() != null) {
getSecondaryFeaturePoints().setScale(new Vector3d(0, 0, 0));
}
calculateFeaturePoints(); calculateFeaturePoints();
break; break;
case ACTION_COMMAND_RESET_ALL: case ACTION_COMMAND_RESET_ALL:
...@@ -170,6 +215,32 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -170,6 +215,32 @@ public class RegistrationAction extends ControlPanelAction {
int transparency = ((JSlider) ae.getSource()).getValue(); int transparency = ((JSlider) ae.getSource()).getValue();
setTransparency(transparency); setTransparency(transparency);
break; break;
case ACTION_COMMAND_FP_CLOSENESS_THRESHOLD:
featurePointsThreshold = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
calculateFeaturePoints();
break;
case ACTION_COMMAND_ICP_SCALE:
this.scale = ((JCheckBox) ae.getSource()).isSelected();
break;
case ACTION_COMMAND_ICP_MAX_ITERATIONS:
maxIterations = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).intValue();
break;
case ACTION_COMMAND_ICP_ERROR:
error = ((Number)(((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
break;
case ACTION_COMMAND_ICP_UNDERSAMPLING:
String item = (String)((JComboBox) ae.getSource()).getSelectedItem();
switch (item) {
case "None":
this.undersampling = new NoUndersampling();
break;
case "Random 200":
this.undersampling = new RandomStrategy(200);
break;
default:
throw new UnsupportedOperationException(item);
}
break;
default: default:
throw new UnsupportedOperationException(action); throw new UnsupportedOperationException(action);
} }
...@@ -178,10 +249,8 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -178,10 +249,8 @@ public class RegistrationAction extends ControlPanelAction {
} }
protected void applyICP() { protected void applyICP() {
if (visitor == null) { IcpTransformer visitor = new IcpTransformer(getPrimaryDrawableFace().getModel(), maxIterations, scale, error, undersampling);
this.visitor = new IcpTransformer(getPrimaryDrawableFace().getModel(), maxIterations, scale, error, undersampling); getSecondaryDrawableFace().getModel().compute(visitor); // NOTE: the secondary face is physically transformed
getSecondaryDrawableFace().getModel().compute(visitor); // NOTE: the secondary face is physically transformed
}
} }
/** /**
...@@ -210,14 +279,19 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -210,14 +279,19 @@ public class RegistrationAction extends ControlPanelAction {
* otherwise set color to default * otherwise set color to default
*/ */
private void calculateFeaturePoints() { private void calculateFeaturePoints() {
if (getPrimaryDrawableFace() == null || !getPrimaryDrawableFace().isRenderFeaturePoints()) { if (getPrimaryDrawableFace() == null) { // scene not yet initiated
return; return;
} }
List<Color> color = getSecondaryDrawableFace().getFeaturePointsColor(); if (getPrimaryFeaturePoints() == null ||
for (int i = 0; i < getPrimaryDrawableFace().getFeaturePoints().size(); i++) { getSecondaryFeaturePoints() == null ||
FeaturePoint primary = getPrimaryDrawableFace().getFeaturePoints().get(i); getPrimaryFeaturePoints().getFeaturePoints().size() != getSecondaryFeaturePoints().getFeaturePoints().size()) {
FeaturePoint secondary = getSecondaryDrawableFace().getFeaturePoints().get(i); return;
}
for (int i = 0; i < getPrimaryFeaturePoints().getFeaturePoints().size(); i++) {
FeaturePoint primary = getPrimaryFeaturePoints().getFeaturePoints().get(i);
FeaturePoint secondary = getSecondaryFeaturePoints().getFeaturePoints().get(i);
Point3d transformed = new Point3d(secondary.getX(), secondary.getY(), secondary.getZ()); Point3d transformed = new Point3d(secondary.getX(), secondary.getY(), secondary.getZ());
transformPoint(transformed); transformPoint(transformed);
double distance = Math.sqrt( double distance = Math.sqrt(
...@@ -225,9 +299,11 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -225,9 +299,11 @@ public class RegistrationAction extends ControlPanelAction {
Math.pow(transformed.y - primary.getY(), 2) + Math.pow(transformed.y - primary.getY(), 2) +
Math.pow(transformed.z - primary.getZ(), 2)); Math.pow(transformed.z - primary.getZ(), 2));
if (distance > featurePointsThreshold) { if (distance > featurePointsThreshold) {
color.set(i, Color.RED); getPrimaryFeaturePoints().setColor(i, Color.RED);
getSecondaryFeaturePoints().setColor(i, Color.RED);
} else { } else {
color.set(i, DrawableFace.SKIN_COLOR_SECONDARY); getPrimaryFeaturePoints().setColor(i, DrawableFeaturePoints.DEFAULT_COLOR);
getSecondaryFeaturePoints().setColor(i, DrawableFeaturePoints.DEFAULT_COLOR);
} }
} }
} }
...@@ -243,13 +319,12 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -243,13 +319,12 @@ public class RegistrationAction extends ControlPanelAction {
transformPoint(comparedPoint.getPosition()); transformPoint(comparedPoint.getPosition());
} }
} }
for (int i = 0; i < getSecondaryDrawableFace().getFeaturePoints().size(); i++) { for (int i = 0; i < getSecondaryFeaturePoints().getFeaturePoints().size(); i++) {
FeaturePoint point = getSecondaryDrawableFace().getFeaturePoints().get(i); FeaturePoint point = getSecondaryFeaturePoints().getFeaturePoints().get(i);
Point3d transformed = new Point3d(point.getX(), point.getY(), point.getZ()); Point3d transformed = new Point3d(point.getX(), point.getY(), point.getZ());
transformPoint(transformed); transformPoint(transformed);
point = new FeaturePoint(transformed.x, transformed.y, point = new FeaturePoint(transformed.x, transformed.y, transformed.z, point.getFeaturePointType());
transformed.z, point.getFeaturePointType()); getSecondaryFeaturePoints().getFeaturePoints().set(i, point);
getSecondaryDrawableFace().getFeaturePoints().set(i, point);
} }
} }
...@@ -310,38 +385,4 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -310,38 +385,4 @@ public class RegistrationAction extends ControlPanelAction {
point.z *= 1 + getSecondaryDrawableFace().getScale().z; point.z *= 1 + getSecondaryDrawableFace().getScale().z;
} }
public double getFeaturePointsThreshold() {
return featurePointsThreshold;
}
public void setFeaturePointsThreshold(double featurePointsThreshold) {
this.featurePointsThreshold = featurePointsThreshold;
calculateFeaturePoints();
renderScene();
}
/////////////////////////////
protected boolean areFeaturePointsActive() {
return getPrimaryDrawableFace().isRenderFeaturePoints();
}
protected void setFeaturePointsActive(boolean state) {
getPrimaryDrawableFace().setRenderFeaturePoints(state);
getSecondaryDrawableFace().setRenderFeaturePoints(state);
calculateFeaturePoints();
renderScene();
}
protected boolean isShowBackfaceActive() {
return getPrimaryDrawableFace().isShowBackface();
}
protected void setShowBackfaceActive(boolean state) {
getPrimaryDrawableFace().setShowBackface(state);
getSecondaryDrawableFace().setShowBackface(state);
renderScene();
}
} }
...@@ -22,9 +22,9 @@ public class DrawableFace extends DrawableMesh { ...@@ -22,9 +22,9 @@ public class DrawableFace extends DrawableMesh {
public static final Color SKIN_COLOR_SECONDARY = new Color(236, 188, 180); public static final Color SKIN_COLOR_SECONDARY = new Color(236, 188, 180);
/* feature points */ /* feature points */
private List<FeaturePoint> featurePoints = new ArrayList<>(); //private List<FeaturePoint> featurePoints = new ArrayList<>();
private List<Color> featurePointsColor = new ArrayList<>(); //private List<Color> featurePointsColor = new ArrayList<>();
private boolean renderFeaturePoints = false; //private boolean renderFeaturePoints = false;
private boolean renderHeatMap = false; private boolean renderHeatMap = false;
/** /**
...@@ -46,14 +46,15 @@ public class DrawableFace extends DrawableMesh { ...@@ -46,14 +46,15 @@ public class DrawableFace extends DrawableMesh {
/** /**
* @return {@link List} of {@link FeaturePoint} * @return {@link List} of {@link FeaturePoint}
*/ */
public List<FeaturePoint> getFeaturePoints() { //public List<FeaturePoint> getFeaturePoints() {
return featurePoints; // return featurePoints;
} //}
/** /**
* Sets feature points * Sets feature points
* @param featurePoints Feature points * @param featurePoints Feature points
*/ */
/*
public void setFeaturePoints(List<FeaturePoint> featurePoints) { public void setFeaturePoints(List<FeaturePoint> featurePoints) {
this.featurePoints = featurePoints; this.featurePoints = featurePoints;
List<Color> colors = new ArrayList<>(); List<Color> colors = new ArrayList<>();
...@@ -61,37 +62,46 @@ public class DrawableFace extends DrawableMesh { ...@@ -61,37 +62,46 @@ public class DrawableFace extends DrawableMesh {
colors.add(getColor()); colors.add(getColor());
}); });
this.setFeaturePointsColor(colors); this.setFeaturePointsColor(colors);
} }
*/
/** /**
* @return {@link List} of feature points {@link Color} * @return {@link List} of feature points {@link Color}
*/ */
/*
public List<Color> getFeaturePointsColor() { public List<Color> getFeaturePointsColor() {
return featurePointsColor; return featurePointsColor;
} }
*/
/** /**
* Sets colors of feature points * Sets colors of feature points
* @param featurePointsColor Colors of feature points * @param featurePointsColor Colors of feature points
*/ */
/*
public void setFeaturePointsColor(List<Color> featurePointsColor) { public void setFeaturePointsColor(List<Color> featurePointsColor) {
this.featurePointsColor = featurePointsColor; this.featurePointsColor = featurePointsColor;
} }
*/
/** /**
* @return {@code true} if feature points should be rendered * @return {@code true} if feature points should be rendered
*/ */
/*
public boolean isRenderFeaturePoints() { public boolean isRenderFeaturePoints() {
return renderFeaturePoints; return renderFeaturePoints;
} }
*/
/** /**
* Sets if feature points should be rendered or not * Sets if feature points should be rendered or not
* @param renderFeaturePoints * @param renderFeaturePoints
*/ */
/*
public void setRenderFeaturePoints(boolean renderFeaturePoints) { public void setRenderFeaturePoints(boolean renderFeaturePoints) {
this.renderFeaturePoints = renderFeaturePoints; this.renderFeaturePoints = renderFeaturePoints;
} }
*/
/** /**
* Sets new heatmap. * Sets new heatmap.
......
...@@ -6,6 +6,7 @@ import com.jogamp.opengl.glu.GLUquadric; ...@@ -6,6 +6,7 @@ import com.jogamp.opengl.glu.GLUquadric;
import cz.fidentis.analyst.feature.FeaturePoint; import cz.fidentis.analyst.feature.FeaturePoint;
import java.awt.Color; import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -37,6 +38,28 @@ public class DrawableFeaturePoints extends Drawable { ...@@ -37,6 +38,28 @@ public class DrawableFeaturePoints extends Drawable {
this.featurePoints = new ArrayList<>(featurePoints); this.featurePoints = new ArrayList<>(featurePoints);
setColor(DEFAULT_COLOR); setColor(DEFAULT_COLOR);
} }
public Color getColor(int index) {
if (index < 0 || index >= featurePoints.size()) {
return null;
}
if (specialColors.containsKey(index)) {
return specialColors.get(index);
} else {
return DEFAULT_COLOR;
}
}
public void setColor(int index, Color color) {
if (index < 0 || index >= featurePoints.size() || color == null) {
return;
}
if (color.equals(DEFAULT_COLOR)) {
specialColors.remove(index);
} else {
specialColors.put(index, color);
}
}
@Override @Override
protected void renderObject(GL2 gl) { protected void renderObject(GL2 gl) {
...@@ -56,28 +79,30 @@ public class DrawableFeaturePoints extends Drawable { ...@@ -56,28 +79,30 @@ public class DrawableFeaturePoints extends Drawable {
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, tmpRGB, 0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, tmpRGB, 0);
} }
//gl.glPushMatrix(); gl.glPushMatrix();
//gl.glTranslated(fp.getX(), fp.getY(), fp.getZ()); gl.glTranslated(fp.getX(), fp.getY(), fp.getZ());
GLUquadric center = GLU_CONTEXT.gluNewQuadric(); GLUquadric center = GLU_CONTEXT.gluNewQuadric();
GLU_CONTEXT.gluQuadricDrawStyle(center, GLU.GLU_FILL); GLU_CONTEXT.gluQuadricDrawStyle(center, GLU.GLU_FILL);
GLU_CONTEXT.gluQuadricNormals(center, GLU.GLU_FLAT); GLU_CONTEXT.gluQuadricNormals(center, GLU.GLU_FLAT);
GLU_CONTEXT.gluQuadricOrientation(center, GLU.GLU_OUTSIDE); GLU_CONTEXT.gluQuadricOrientation(center, GLU.GLU_OUTSIDE);
GLU_CONTEXT.gluSphere(center, 3f, 16, 16); GLU_CONTEXT.gluSphere(center, 3f, 16, 16);
GLU_CONTEXT.gluDeleteQuadric(center); GLU_CONTEXT.gluDeleteQuadric(center);
//gl.glPopMatrix(); gl.glPopMatrix();
if (specialColor != null) { if (specialColor != null) {
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, rgba, 0); // set default color gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, rgba, 0); // set default color
} }
} }
} }
/** /**
* @return {@link List} of {@link FeaturePoint} * @return {@link List} of {@link FeaturePoint}
*/ */
//public List<FeaturePoint> getFeaturePoints() { public List<FeaturePoint> getFeaturePoints() {
// return Collections.unmodifiableList(featurePoints); return Collections.unmodifiableList(featurePoints);
//} }
/** /**
* Sets feature points * Sets feature points
......
...@@ -20,11 +20,6 @@ public class DrawableMesh extends Drawable { ...@@ -20,11 +20,6 @@ public class DrawableMesh extends Drawable {
private final MeshModel model; private final MeshModel model;
/**
* Flag if back should be rendered
*/
private boolean showBackface = true;
/** /**
* Constructor. * Constructor.
* *
...@@ -109,19 +104,4 @@ public class DrawableMesh extends Drawable { ...@@ -109,19 +104,4 @@ public class DrawableMesh extends Drawable {
return this.model; return this.model;
} }
/**
* @return {@code true} if back face shoud be shown
*/
public boolean isShowBackface() {
return showBackface;
}
/**
* Sets if back face should be shown or not
* @param showBackface
*/
public void setShowBackface(boolean showBackface) {
this.showBackface = showBackface;
}
} }
...@@ -29,7 +29,12 @@ public class Scene { ...@@ -29,7 +29,12 @@ public class Scene {
faces.add(face); faces.add(face);
drawableFaces.add(new DrawableFace(face.getMeshModel())); drawableFaces.add(new DrawableFace(face.getMeshModel()));
drawableFeaturePoints.add(null); if (face.getFeaturePoints() != null) {
System.out.println("AAA"+face.getFeaturePoints());
drawableFeaturePoints.add(new DrawableFeaturePoints(face.getFeaturePoints()));
} else {
drawableFeaturePoints.add(null);
}
drawableSymmetryPlanes.add(null); drawableSymmetryPlanes.add(null);
} }
...@@ -47,14 +52,27 @@ public class Scene { ...@@ -47,14 +52,27 @@ public class Scene {
if (secondary == null) { if (secondary == null) {
throw new IllegalArgumentException("secondary"); throw new IllegalArgumentException("secondary");
} }
faces.add(primary); faces.add(primary);
faces.add(secondary); faces.add(secondary);
drawableFaces.add(new DrawableFace(primary.getMeshModel())); drawableFaces.add(new DrawableFace(primary.getMeshModel()));
drawableFaces.add(new DrawableFace(secondary.getMeshModel())); drawableFaces.add(new DrawableFace(secondary.getMeshModel()));
drawableFeaturePoints.add(null);
drawableFeaturePoints.add(null); if (primary.getFeaturePoints() != null) {
drawableFeaturePoints.add(new DrawableFeaturePoints(primary.getFeaturePoints()));
} else {
drawableFeaturePoints.add(null);
}
if (secondary.getFeaturePoints() != null) {
drawableFeaturePoints.add(new DrawableFeaturePoints(secondary.getFeaturePoints()));
} else {
drawableFeaturePoints.add(null);
}
drawableSymmetryPlanes.add(null); drawableSymmetryPlanes.add(null);
drawableSymmetryPlanes.add(null); drawableSymmetryPlanes.add(null);
drawableFaces.get(1).setColor(DrawableFace.SKIN_COLOR_SECONDARY); drawableFaces.get(1).setColor(DrawableFace.SKIN_COLOR_SECONDARY);
} }
......
...@@ -4,6 +4,7 @@ import com.jogamp.opengl.GL; ...@@ -4,6 +4,7 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2; import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU; import com.jogamp.opengl.glu.GLU;
import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshFacet;
import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -109,6 +110,11 @@ public class SceneRenderer { ...@@ -109,6 +110,11 @@ public class SceneRenderer {
*/ */
public void renderScene(Camera camera, Collection<Drawable> drawables) { public void renderScene(Camera camera, Collection<Drawable> drawables) {
clearScene(); clearScene();
// light backface
gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_POSITION, new float[] {0f, 0f, -1f, 0f}, 0);
gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_DIFFUSE, Color.white.getComponents(null), 0);
setPosition(camera); setPosition(camera);
List<DrawableFace> faces = getOrderedFaces(drawables); List<DrawableFace> faces = getOrderedFaces(drawables);
...@@ -118,8 +124,9 @@ public class SceneRenderer { ...@@ -118,8 +124,9 @@ public class SceneRenderer {
} }
} }
for (Drawable obj: faces) { for (DrawableFace obj: faces) {
if (obj.isShown()) { if (obj.isShown()) {
//showBackface(obj);
obj.render(gl); obj.render(gl);
} }
} }
......
...@@ -4,6 +4,7 @@ import com.jogamp.opengl.GL2; ...@@ -4,6 +4,7 @@ import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.canvas.Canvas; import cz.fidentis.analyst.canvas.Canvas;
import static cz.fidentis.analyst.toolbar.RenderingToolBar.REFLECTIONS_COLOR; import static cz.fidentis.analyst.toolbar.RenderingToolBar.REFLECTIONS_COLOR;
import cz.fidentis.analyst.scene.Drawable; import cz.fidentis.analyst.scene.Drawable;
import cz.fidentis.analyst.scene.DrawableFeaturePoints;
import java.awt.Color; import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
...@@ -23,9 +24,11 @@ public class RenderingModeAction extends AbstractAction { ...@@ -23,9 +24,11 @@ public class RenderingModeAction extends AbstractAction {
public static final String ACTION_COMMAND_REFLECTIONS_ON_OFF = "reflections"; public static final String ACTION_COMMAND_REFLECTIONS_ON_OFF = "reflections";
public static final String ACTION_COMMAND_SHOW_HIDE_PRIMARY_FACE = "primary face"; public static final String ACTION_COMMAND_SHOW_HIDE_PRIMARY_FACE = "primary face";
public static final String ACTION_COMMAND_SHOW_HIDE_SECONDARY_FACES = "secondary faces"; public static final String ACTION_COMMAND_SHOW_HIDE_SECONDARY_FACES = "secondary faces";
public static final String ACTION_COMMAND_SHOW_HIDE_FEATURE_POINTS = "feature points";
private final Canvas canvas; private final Canvas canvas;
private boolean showFPs = true;
/** /**
* Constructor. * Constructor.
...@@ -71,18 +74,22 @@ public class RenderingModeAction extends AbstractAction { ...@@ -71,18 +74,22 @@ public class RenderingModeAction extends AbstractAction {
} }
break; break;
case ACTION_COMMAND_SHOW_HIDE_PRIMARY_FACE: case ACTION_COMMAND_SHOW_HIDE_PRIMARY_FACE:
if (((JToggleButton) ae.getSource()).isSelected()) { showHideFace(0, ((JToggleButton) ae.getSource()).isSelected());
canvas.getScene().getDrawableFace(0).show();
} else {
canvas.getScene().getDrawableFace(0).hide();
}
break; break;
case ACTION_COMMAND_SHOW_HIDE_SECONDARY_FACES: case ACTION_COMMAND_SHOW_HIDE_SECONDARY_FACES:
for (int i = 1; i < canvas.getScene().getNumFaces(); i++) { for (int i = 1; i < canvas.getScene().getNumFaces(); i++) {
if (((JToggleButton) ae.getSource()).isSelected()) { showHideFace(i, ((JToggleButton) ae.getSource()).isSelected());
canvas.getScene().getDrawableFace(i).show(); }
} else { break;
canvas.getScene().getDrawableFace(i).hide(); case ACTION_COMMAND_SHOW_HIDE_FEATURE_POINTS:
for (int i = 0; i < canvas.getScene().getNumFaces(); i++) {
DrawableFeaturePoints fp = canvas.getScene().getDrawableFeaturePoints(i);
if (((JToggleButton) ae.getSource()).isSelected()) { // show
if (canvas.getScene().getDrawableFace(i).isShown() && fp != null) {
fp.show();
}
} else if (fp != null) { // hide
fp.hide();
} }
} }
break; break;
...@@ -92,4 +99,18 @@ public class RenderingModeAction extends AbstractAction { ...@@ -92,4 +99,18 @@ public class RenderingModeAction extends AbstractAction {
canvas.renderScene(); canvas.renderScene();
} }
private void showHideFace(int i, boolean show) {
DrawableFeaturePoints fp = canvas.getScene().getDrawableFeaturePoints(i);
if (show) {
canvas.getScene().getDrawableFace(i).show();
if (showFPs) {
fp.show();
}
} else { //hide
canvas.getScene().getDrawableFace(i).hide();
if (fp != null) {
fp.hide();
}
}
}
} }
...@@ -31,7 +31,8 @@ public class RenderingToolBar extends JToolBar { ...@@ -31,7 +31,8 @@ public class RenderingToolBar extends JToolBar {
public static final String POINTS_BUTTON_ICON = "points-tri28x28.png"; public static final String POINTS_BUTTON_ICON = "points-tri28x28.png";
public static final String PRIMARY_FACE_BUTTON_ICON = "primaryFace28x28.png"; public static final String PRIMARY_FACE_BUTTON_ICON = "primaryFace28x28.png";
public static final String SECONDARY_FACE_BUTTON_ICON = "secondaryFace28x28.png"; public static final String SECONDARY_FACE_BUTTON_ICON = "secondaryFace28x28.png";
//public static final String FEATURE_POINTS_BUTTON_ICON = "wireframe-tri28x28.png";
private final Canvas canvas; private final Canvas canvas;
/** /**
...@@ -44,6 +45,7 @@ public class RenderingToolBar extends JToolBar { ...@@ -44,6 +45,7 @@ public class RenderingToolBar extends JToolBar {
addRenderingModeButton(); addRenderingModeButton();
addBackgroundButton(); addBackgroundButton();
addReflectionsButton(); addReflectionsButton();
addFeaturePointsButton();
} }
protected Canvas getCanvas() { protected Canvas getCanvas() {
...@@ -142,4 +144,16 @@ public class RenderingToolBar extends JToolBar { ...@@ -142,4 +144,16 @@ public class RenderingToolBar extends JToolBar {
button.setFocusable(false); button.setFocusable(false);
add(button); add(button);
} }
protected void addFeaturePointsButton() {
JToggleButton button = new JToggleButton();
button.addActionListener(new RenderingModeAction(canvas));
button.setActionCommand(RenderingModeAction.ACTION_COMMAND_SHOW_HIDE_FEATURE_POINTS);
//button.setIcon(new ImageIcon(getClass().getResource("/" + RenderingToolBar.FEATURE_POINTS_BUTTON_ICON)));
button.setToolTipText(NbBundle.getMessage(RenderingToolBar.class, "RenderingToolBar.secondaryfaces.text"));
button.setText("FPs");
button.setSelected(true);
button.setFocusable(false);
add(button);
}
} }
...@@ -32,20 +32,17 @@ RegistrationPanel.lowShiftRB.toolTipText=set low shifting amount ...@@ -32,20 +32,17 @@ RegistrationPanel.lowShiftRB.toolTipText=set low shifting amount
RegistrationPanel.lowShiftRB.text=low RegistrationPanel.lowShiftRB.text=low
RegistrationPanel.shiftLabel.toolTipText=transformation amount RegistrationPanel.shiftLabel.toolTipText=transformation amount
RegistrationPanel.shiftLabel.text=shift RegistrationPanel.shiftLabel.text=shift
RegistrationPanel.featurePointsLabel.text=Feature points: RegistrationPanel.featurePointsLabel.text=FP closeness treshold:
RegistrationPanel.resetAllButton.toolTipText=reset all transformations RegistrationPanel.resetAllButton.toolTipText=reset all transformations
RegistrationPanel.resetAllButton.text=reset all RegistrationPanel.resetAllButton.text=reset all
RegistrationPanel.scaleButton.toolTipText=reset scale RegistrationPanel.scaleButton.toolTipText=reset scale
RegistrationPanel.scaleButton.text= RegistrationPanel.scaleButton.text=
RegistrationPanel.scaleFTF.toolTipText= RegistrationPanel.scaleFTF.toolTipText=
RegistrationPanel.thersholdButton.text=thershold
RegistrationPanel.thersholdUpButton.text= RegistrationPanel.thersholdUpButton.text=
RegistrationPanel.thresholdDownButton.text= RegistrationPanel.thresholdDownButton.text=
RegistrationPanel.scaleMinusButton.text= RegistrationPanel.scaleMinusButton.text=
RegistrationPanel.featurePointsButton.text=show
RegistrationPanel.scalePlusButton.text= RegistrationPanel.scalePlusButton.text=
RegistrationPanel.jLabel4.text=Scale: RegistrationPanel.jLabel4.text=Scale:
RegistrationPanel.backfaceButton.text=hide backface
RegistrationPanel.viewLabel.text=View: RegistrationPanel.viewLabel.text=View:
RegistrationPanel.jLabel3.text=Rotation: RegistrationPanel.jLabel3.text=Rotation:
RegistrationPanel.frontButton.toolTipText=model front view RegistrationPanel.frontButton.toolTipText=model front view
...@@ -59,5 +56,10 @@ RegistrationPanel.profileButton.text=side ...@@ -59,5 +56,10 @@ RegistrationPanel.profileButton.text=side
RegistrationPanel.rightRotationXButton.text= RegistrationPanel.rightRotationXButton.text=
RegistrationPanel.leftRotationZButton.text= RegistrationPanel.leftRotationZButton.text=
RegistrationPanel.rightRotationYButton.text= RegistrationPanel.rightRotationYButton.text=
RegistrationPanel.jButton1.text=ICP RegistrationPanel.jButton1.text=(Re)compute
RegistrationPanel.jLabel1.text=Registration: RegistrationPanel.jLabel1.text=ICP:
RegistrationPanel.jCheckBox1.text=scale
RegistrationPanel.jFormattedTextField1.text=0,3
RegistrationPanel.jLabel5.text=error
RegistrationPanel.jFormattedTextField2.text=10
RegistrationPanel.jLabel6.text=max iters
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment