Skip to content
Snippets Groups Projects
Commit 2d1f6280 authored by Dominik Ráček's avatar Dominik Ráček Committed by Radek Ošlejšek
Browse files

mirror cuts in both single and 1:1 views

parent 512a1dfc
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ public class Scene {
private final List<DrawableFeaturePoints> drawableFeaturePoints = new ArrayList<>();
private final List<DrawablePlane> drawableSymmetryPlanes = new ArrayList<>();
private final List<DrawablePlane> drawableCuttingPlanes = new ArrayList<>();
private final List<DrawablePlane> drawableMirrorPlanes = new ArrayList<>();
private final List<Drawable> otherDrawables = new ArrayList<>();
/**
......@@ -40,6 +41,7 @@ public class Scene {
}
drawableSymmetryPlanes.add(null);
drawableCuttingPlanes.add(null);
drawableMirrorPlanes.add(null);
setDefaultColors();
}
......@@ -78,9 +80,11 @@ public class Scene {
drawableSymmetryPlanes.add(null);
drawableCuttingPlanes.add(null);
drawableMirrorPlanes.add(null);
drawableSymmetryPlanes.add(null);
drawableCuttingPlanes.add(null);
drawableMirrorPlanes.add(null);
setDefaultColors();
}
......@@ -142,7 +146,7 @@ public class Scene {
* Returns drawable symmetry plane.
*
* @param index Index of the face
* @return drawable face or {@code null}
* @return drawable plane or {@code null}
*/
public DrawablePlane getDrawableSymmetryPlane(int index) {
return (index >= 0 && index < getNumFaces()) ? drawableSymmetryPlanes.get(index) : null;
......@@ -195,7 +199,7 @@ public class Scene {
* Returns drawable cutting plane.
*
* @param index Index of the face
* @return drawable face or {@code null}
* @return drawable plane or {@code null}
*/
public DrawablePlane getDrawableCuttingPlane(int index) {
return (index >= 0 && index < getNumFaces()) ? drawableCuttingPlanes.get(index) : null;
......@@ -244,6 +248,59 @@ public class Scene {
hideShowCuttingPlanes(false);
}
/**
* Returns drawable mirror plane.
*
* @param index Index of the face
* @return drawable face or {@code null}
*/
public DrawablePlane getDrawableMirrorPlane(int index) {
return (index >= 0 && index < getNumFaces()) ? drawableMirrorPlanes.get(index) : null;
}
/**
* Sets the drawable mirror plane.
*
* @param index Index of the face
* @param mPlane New mirror plane
*/
public void setDrawableMirrorPlane(int index, DrawablePlane mPlane) {
if (index >= 0 && index < getNumFaces() && mPlane != null) {
this.drawableMirrorPlanes.set(index, mPlane);
}
}
/**
* Helper function for showing or hiding all mirror planes
*
* @param show determines whether to hide or show the planes
*/
private void hideShowMirrorPlanes(boolean show) {
for (int i = 0; i < drawableMirrorPlanes.size(); ++i) {
if (drawableMirrorPlanes.get(i) != null) {
if (show) {
drawableMirrorPlanes.get(i).show();
} else {
drawableMirrorPlanes.get(i).hide();
}
}
}
}
/**
* Show all mirror planes
*/
public void showMirrorPlanes() {
hideShowMirrorPlanes(true);
}
/**
* Hide all mirror planes
*/
public void hideMirrorPlanes() {
hideShowMirrorPlanes(false);
}
/**
* Adds new drawable object to the scene.
*
......@@ -269,6 +326,7 @@ public class Scene {
ret.addAll(this.drawableFeaturePoints);
ret.addAll(this.drawableSymmetryPlanes);
ret.addAll(this.drawableCuttingPlanes);
ret.addAll(this.drawableMirrorPlanes);
ret.addAll(this.otherDrawables);
while (ret.remove(null)) {}
return ret;
......
......@@ -26,10 +26,13 @@ public class PolylinePanel extends JPanel {
private static final Color PRIMARY_COLOR = Color.green;
private static final Color SECONDARY_COLOR = Color.blue;
private static final Stroke GRAPH_STROKE = new BasicStroke(3f);
private List<Point3d> primary;
private List<Point3d> secondary;
private List<Point3d> primaryPoints;
private List<Point3d> secondaryPoints;
private List<Point3d> primaryMirrorPoints;
private List<Point3d> secondaryMirrorPoints;
private boolean alignProfiles = false;
private double primaryOffsetZ = 0;
private boolean mirrorCuts = false;
private double scale = Double.POSITIVE_INFINITY;
......@@ -58,18 +61,18 @@ public class PolylinePanel extends JPanel {
* Constructor for one face
*/
public PolylinePanel(List<Point3d> values) {
this.primary = values;
Collections.sort(this.primary, new CompareY());
this.primaryPoints = values;
Collections.sort(this.primaryPoints, new CompareY());
}
/**
* Constructor for two faces
*/
public PolylinePanel(List<Point3d> primary, List<Point3d> secondary) {
this.primary = primary;
this.secondary = secondary;
Collections.sort(this.primary, new CompareY());
Collections.sort(this.secondary, new CompareY());
public PolylinePanel(List<Point3d> primaryPoints, List<Point3d> secondaryPoints) {
this.primaryPoints = primaryPoints;
this.secondaryPoints = secondaryPoints;
Collections.sort(this.primaryPoints, new CompareY());
Collections.sort(this.secondaryPoints, new CompareY());
}
protected void drawFace(Graphics2D g2, List<Point3d> values, Color faceColor, boolean isPrimary) {
......@@ -77,6 +80,7 @@ public class PolylinePanel extends JPanel {
double maxZ = Double.NEGATIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
double offsetZ = 0;
for (int i = 0; i < values.size(); i++) {
if (values.get(i).z < minZ) {
......@@ -101,12 +105,24 @@ public class PolylinePanel extends JPanel {
scale = ((double) PREF_H - 2 * BORDER_GAP) / (maxY - minY);
}
if (isPrimary) {
this.primaryOffsetZ = (PREF_W * 0.7) - (maxZ * scale);
//Calculate the offsets
if (mirrorCuts) {
if (secondaryPoints == null) {
//Mirror cuts with single face - center the face
this.primaryOffsetZ = (PREF_W * 0.7) - (maxZ * scale);
offsetZ = this.primaryOffsetZ;
} else {
//Mirror cuts with two faces - separate primary and secondary
offsetZ = isPrimary ? (PREF_W * 0.4) - (maxZ * scale) : (PREF_W * 0.9) - (maxZ * scale);
}
} else {
//No mirror cuts - center all faces
if (isPrimary) {
this.primaryOffsetZ = (PREF_W * 0.7) - (maxZ * scale);
}
offsetZ = this.alignProfiles ? (PREF_W * 0.7) - (maxZ * scale) : this.primaryOffsetZ;
}
double offsetZ = this.alignProfiles ? (PREF_W * 0.7) - (maxZ * scale) : this.primaryOffsetZ;
//Draw lines
g2.setColor(faceColor);
g2.setStroke(GRAPH_STROKE);
......@@ -125,12 +141,22 @@ public class PolylinePanel extends JPanel {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawFace(g2, primary, PRIMARY_COLOR, true);
if (secondary != null) {
drawFace(g2, secondary, SECONDARY_COLOR, false);
}
if (mirrorCuts) {
drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
drawFace(g2, primaryMirrorPoints, SECONDARY_COLOR, true);
if (secondaryPoints != null) {
drawFace(g2, secondaryPoints, PRIMARY_COLOR, false);
drawFace(g2, secondaryMirrorPoints, SECONDARY_COLOR, false);
}
} else {
drawFace(g2, primaryPoints, PRIMARY_COLOR, true);
if (secondaryPoints != null) {
drawFace(g2, secondaryPoints, SECONDARY_COLOR, false);
}
}
}
/**
......@@ -139,8 +165,20 @@ public class PolylinePanel extends JPanel {
* @param points primary points
*/
public void setPrimaryPoints(List<Point3d> points) {
this.primary = points;
Collections.sort(this.primary, new CompareY());
this.primaryPoints = points;
Collections.sort(this.primaryPoints, new CompareY());
repaint();
}
/**
* Sets primary mirror points.
* Only draws them if mirrorCuts is checked
*
* @param points primary mirror points
*/
public void setPrimaryMirrorPoints(List<Point3d> points) {
this.primaryMirrorPoints = points;
Collections.sort(this.primaryMirrorPoints, new CompareY());
repaint();
}
......@@ -150,8 +188,20 @@ public class PolylinePanel extends JPanel {
* @param points secondary points
*/
public void setSecondaryPoints(List<Point3d> points) {
this.secondary = points;
Collections.sort(this.secondary, new CompareY());
this.secondaryPoints = points;
Collections.sort(this.secondaryPoints, new CompareY());
repaint();
}
/**
* Sets secondary mirror points.
* Only draws them if mirrorCuts is checked
*
* @param points secondary mirror points
*/
public void setSecondaryMirrorPoints(List<Point3d> points) {
this.secondaryMirrorPoints = points;
Collections.sort(this.secondaryMirrorPoints, new CompareY());
repaint();
}
......@@ -165,6 +215,16 @@ public class PolylinePanel extends JPanel {
repaint();
}
/**
* Displays the mirror cuts
*
* @param mirror
*/
public void setMirrorCuts(boolean mirror) {
this.mirrorCuts = mirror;
repaint();
}
@Override
public Dimension getPreferredSize() {
return new Dimension(PREF_W, PREF_H);
......
......@@ -33,6 +33,8 @@ public class ProfilesAction extends ControlPanelAction {
*/
private List<Point3d> primaryPoints;
private List<Point3d> secondaryPoints;
private List<Point3d> primaryMirrorPoints;
private List<Point3d> secondaryMirrorPoints;
/**
* Constructor.
......@@ -50,9 +52,11 @@ public class ProfilesAction extends ControlPanelAction {
recomputeSecondaryProfile();
controlPanel = new ProfilesPanel(this, this.primaryPoints, this.secondaryPoints);
controlPanel.setSecondaryMirrorPoints(this.secondaryMirrorPoints);
} else {
controlPanel = new ProfilesPanel(this, this.primaryPoints);
}
controlPanel.setPrimaryMirrorPoints(this.primaryMirrorPoints);
// Place control panel to the topControlPanel
this.topControlPanel.addTab(controlPanel.getName(), controlPanel.getIcon(), controlPanel);
......@@ -64,11 +68,17 @@ public class ProfilesAction extends ControlPanelAction {
if (controlPanel.isShowPlaneChecked()) {
getCanvas().getScene().showCuttingPlanes();
}
if (controlPanel.isMirrorCutsChecked()) {
getCanvas().getScene().showMirrorPlanes();
}
} else {
getCanvas().getScene().hideCuttingPlanes();
getCanvas().getScene().hideMirrorPlanes();
}
});
getCanvas().getScene().hideCuttingPlanes();
getCanvas().getScene().hideMirrorPlanes();
}
private void exportProfile(List<Point3d> points, String title) {
......@@ -107,21 +117,46 @@ public class ProfilesAction extends ControlPanelAction {
}
}
void recomputePrimaryProfile() {
CrossSection cs1 = new CrossSection(getScene().getDrawableCuttingPlane(0).getFacets().get(0));
getPrimaryDrawableFace().getModel().compute(cs1);
this.primaryPoints = cs1.getPoints();
private void recomputePrimaryProfile() {
//Main profile
CrossSection cs = new CrossSection(getScene().getDrawableCuttingPlane(0).getFacets().get(0));
getPrimaryDrawableFace().getModel().compute(cs);
this.primaryPoints = cs.getPoints();
//Mirror profile
CrossSection mcs = new CrossSection(getScene().getDrawableMirrorPlane(0).getFacets().get(0));
getPrimaryDrawableFace().getModel().compute(mcs);
this.primaryMirrorPoints = mcs.getPoints();
}
void recomputeSecondaryProfile() {
private void recomputeSecondaryProfile() {
//Main profile
CrossSection cs = new CrossSection(getScene().getDrawableCuttingPlane(1).getFacets().get(0));
getSecondaryDrawableFace().getModel().compute(cs);
this.secondaryPoints = cs.getPoints();
//Mirror profile
CrossSection mcs = new CrossSection(getScene().getDrawableMirrorPlane(1).getFacets().get(0));
getSecondaryDrawableFace().getModel().compute(mcs);
this.secondaryMirrorPoints = mcs.getPoints();
}
void setCuttingPlaneOffset(int index, double value) {
private void recomputeProfiles() {
recomputePrimaryProfile();
controlPanel.setPrimaryPoints(this.primaryPoints);
controlPanel.setPrimaryMirrorPoints(this.primaryMirrorPoints);
if (getSecondaryDrawableFace() != null) {
recomputeSecondaryProfile();
controlPanel.setSecondaryPoints(this.secondaryPoints);
controlPanel.setSecondaryMirrorPoints(this.secondaryMirrorPoints);
}
}
private void setCuttingPlaneOffset(int index, double value) {
for (int i = 0; i < 4; ++i) {
getScene().getDrawableCuttingPlane(index).getFacets().get(0).getVertex(i).getPosition().x = value;
getScene().getDrawableMirrorPlane(index).getFacets().get(0).getVertex(i).getPosition().x = value * -1.0;
}
}
......@@ -144,28 +179,31 @@ public class ProfilesAction extends ControlPanelAction {
}
break;
case ProfilesPanel.ACTION_OFFSET_CUTTING_PLANE:
double value = Double.parseDouble(controlPanel.getOffsetValue());
double value = controlPanel.getOffsetValue();
double multiplier = 150;
setCuttingPlaneOffset(0, multiplier * (value - 0.5));
//TODO translation needs to be done differently, maybe recalculate upon change
if (getSecondaryDrawableFace() != null) {
setCuttingPlaneOffset(1, multiplier * (value - 0.5));
}
recomputeProfiles();
break;
case ProfilesPanel.ACTION_COMMAND_RECOMPUTE:
recomputePrimaryProfile();
controlPanel.setPrimaryPoints(this.primaryPoints);
if (getSecondaryDrawableFace() != null){
recomputeSecondaryProfile();
controlPanel.setSecondaryPoints(this.secondaryPoints);
}
recomputeProfiles();
break;
case ProfilesPanel.ACTION_ALIGN_PROFILES:
controlPanel.setAlignProfiles();
break;
case ProfilesPanel.ACTION_MIRROR_CUTS:
controlPanel.setMirrorCuts();
if (controlPanel.isMirrorCutsChecked()) {
getCanvas().getScene().showMirrorPlanes();
} else {
getCanvas().getScene().hideMirrorPlanes();
}
break;
default:
// do nothing
}
......
......@@ -26,6 +26,7 @@ public class ProfilesPanel extends ControlPanel {
private JCheckBox alignProfiles;
private JCheckBox showCuttingPlane;
private PolylinePanel polylinePanel;
private JCheckBox mirrorCuts;
/*
* Handled actions
......@@ -35,6 +36,7 @@ public class ProfilesPanel extends ControlPanel {
public static final String ACTION_COMMAND_EXPORT = "export";
public static final String ACTION_OFFSET_CUTTING_PLANE = "offset_plane";
public static final String ACTION_ALIGN_PROFILES = "align_profiles";
public static final String ACTION_MIRROR_CUTS = "mirror-cuts";
/*
* Mandatory design elements
......@@ -91,22 +93,27 @@ public class ProfilesPanel extends ControlPanel {
});
builder.addLine();
alignProfiles = builder.addCheckBoxOptionLine(
showCuttingPlane = builder.addCheckBoxOptionLine(
null,
"Align profiles",
false,
createListener(action, ACTION_ALIGN_PROFILES)
"Show cutting plane",
true,
createListener(action, ACTION_COMMAND_SHOW_HIDE_PLANE)
);
builder.addLine();
builder.addCaptionLine("Computation options:");
mirrorCuts = builder.addCheckBoxOptionLine(
null,
"Mirror cuts",
false,
createListener(action, ACTION_MIRROR_CUTS)
);
builder.addLine();
showCuttingPlane = builder.addCheckBoxOptionLine(
alignProfiles = builder.addCheckBoxOptionLine(
null,
"Show cutting plane",
true,
createListener(action, ACTION_COMMAND_SHOW_HIDE_PLANE)
"Align profiles",
false,
createListener(action, ACTION_ALIGN_PROFILES)
);
builder.addLine();
......@@ -159,8 +166,19 @@ public class ProfilesPanel extends ControlPanel {
return showCuttingPlane.isSelected();
}
public String getOffsetValue() {
return cuttingOffset.getText();
public boolean isMirrorCutsChecked() {
return mirrorCuts.isSelected();
}
public double getOffsetValue() {
return ControlPanelBuilder.parseLocaleDouble(cuttingOffset);
}
/**
* Sets the mirrorCuts boolean based on the checkbox
*/
public void setMirrorCuts() {
this.polylinePanel.setMirrorCuts(this.mirrorCuts.isSelected());
}
/**
......@@ -179,6 +197,15 @@ public class ProfilesPanel extends ControlPanel {
this.polylinePanel.setPrimaryPoints(points);
}
/**
* Sets the primary mirror points in the polyline panel
*
* @param points primary mirror points
*/
public void setPrimaryMirrorPoints(List<Point3d> points) {
this.polylinePanel.setPrimaryMirrorPoints(points);
}
/**
* Sets the secondary points in the polyline panel
*
......@@ -188,4 +215,13 @@ public class ProfilesPanel extends ControlPanel {
this.polylinePanel.setSecondaryPoints(points);
}
/**
* Sets the secondary mirror points in the polyline panel
*
* @param points secondary mirror points
*/
public void setSecondaryMirrorPoints(List<Point3d> points) {
this.polylinePanel.setSecondaryMirrorPoints(points);
}
}
......@@ -79,6 +79,8 @@ public class SymmetryAction extends ControlPanelAction {
new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
getCanvas().getScene().setDrawableCuttingPlane(0,
new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
getCanvas().getScene().setDrawableMirrorPlane(0,
new DrawablePlane(primaryEstimator.getSymmetryPlaneMesh(), primaryEstimator.getSymmetryPlane()));
if (getSecondaryDrawableFace() != null) {
SymmetryEstimator secondaryEstimator = new SymmetryEstimator(controlPanel.getSymmetryConfig());
......@@ -88,6 +90,8 @@ public class SymmetryAction extends ControlPanelAction {
new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
getCanvas().getScene().setDrawableCuttingPlane(1,
new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
getCanvas().getScene().setDrawableMirrorPlane(1,
new DrawablePlane(secondaryEstimator.getSymmetryPlaneMesh(), secondaryEstimator.getSymmetryPlane()));
}
getCanvas().getScene().hideSymmetryPlanes();
......
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