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

Merge branch '93-fix-transparency' into 'master'

Resolve "Fix transparency"

Closes #93

See merge request grp-fidentis/analyst2!96
parents 3f037c17 265034b6
No related branches found
No related tags found
No related merge requests found
......@@ -5,11 +5,16 @@
*/
package cz.fidentis.analyst.gui;
import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.gui.canvas.Canvas;
import cz.fidentis.analyst.gui.scene.DrawableMesh;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshPoint;
import cz.fidentis.analyst.visitors.mesh.BoundingBox;
import java.awt.Color;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
......@@ -20,11 +25,12 @@ import javax.vecmath.Vector3d;
*/
public class RegistrationCPEventListener {
private final Canvas canvas;
private final double featurePointsThreshold = 0.1;
private final Color defaultPrimaryColor = new Color(51, 51, 153);
private final Color defaultSecondaryColor = new Color(255, 239, 0);
private final int transparencyRange = 10;
private final double changeAmount = 500d;
private final Canvas canvas;
private final double moveX;
private final double moveY;
private final double moveZ;
......@@ -52,6 +58,102 @@ public class RegistrationCPEventListener {
scaleXYZ = (visitor.getBoundingBox().getMaxDiag() / (10 * changeAmount));
}
/**
* Calculates feature points which are too far away
*/
private void calculateFeaturePoints() {
if (!primaryFace.isRenderFeaturePoints()) {
return;
}
ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> adjusted = new ArrayList<>();
for (int i = 0; i < primaryFace.getFeaturePoints().size(); i++) {
Point3d primaryPoint = primaryFace.getFeaturePoints().get(i).getKey();
Point3d secondaryPoint = new Point3d(secondaryFace.getFeaturePoints().get(i).getKey());
transformPoint(secondaryPoint);
double distance = Math.sqrt(
Math.pow(secondaryPoint.x - primaryPoint.x, 2) +
Math.pow(secondaryPoint.y - primaryPoint.y, 2) +
Math.pow(secondaryPoint.z - primaryPoint.z, 2));
Point3d point = new Point3d(secondaryFace.getFeaturePoints().get(i).getKey());
if (distance > featurePointsThreshold) {
adjusted.add(new AbstractMap.SimpleEntry<>(
point, Color.RED));
} else {
adjusted.add(new AbstractMap.SimpleEntry<>(
point, Color.YELLOW));
}
secondaryFace.setFeaturePoints(adjusted);
}
}
/**
* Applies carried out transformations
*/
public void transformFace() {
for (MeshFacet transformedFacet : secondaryFace.getFacets()) {
for (MeshPoint comparedPoint : transformedFacet.getVertices()) {
transformPoint(comparedPoint.getPosition());
}
}
for (var point : secondaryFace.getFeaturePoints()) {
transformPoint(point.getKey());
}
canvas.renderScene();
}
/**
* Transforms point based on transformation info from secondary face
*
* @param point Point to transform
*/
public void transformPoint(Point3d point) {
Point3d newPoint = new Point3d(0, 0, 0);
double quotient;
// rotate around X
quotient = Math.toRadians(secondaryFace.getRotation().x);
if (!Double.isNaN(quotient)) {
double cos = Math.cos(quotient);
double sin = Math.sin(quotient);
newPoint.y = point.y * cos - point.z * sin;
newPoint.z = point.z * cos + point.y * sin;
point.y = newPoint.y;
point.z = newPoint.z;
}
// rotate around Y
quotient = Math.toRadians(secondaryFace.getRotation().y);
if (!Double.isNaN(quotient)) {
double cos = Math.cos(quotient);
double sin = Math.sin(quotient);
newPoint.x = point.x * cos + point.z * sin;
newPoint.z = point.z * cos - point.x * sin;
point.x = newPoint.x;
point.z = newPoint.z;
}
// rotate around Z
quotient = Math.toRadians(secondaryFace.getRotation().z);
if (!Double.isNaN(quotient)) {
double cos = Math.cos(quotient);
double sin = Math.sin(quotient);
newPoint.x = point.x * cos - point.y * sin;
newPoint.y = point.y * cos + point.x * sin;
point.x = newPoint.x;
point.y = newPoint.y;
}
// translate
point.x += secondaryFace.getTranslation().x;
point.y += secondaryFace.getTranslation().y;
point.z += secondaryFace.getTranslation().z;
// scale
point.x *= 1 + secondaryFace.getScale().x;
point.y *= 1 + secondaryFace.getScale().y;
point.z *= 1 + secondaryFace.getScale().z;
}
public final void setDeafultColor() {
primaryFace.setColor(defaultPrimaryColor);
secondaryFace.setColor(defaultSecondaryColor);
......@@ -82,25 +184,25 @@ public class RegistrationCPEventListener {
public void setTransparency(int value) {
if (value == transparencyRange) {
setPrimaryTransparency(1d);
setSecondaryTransparency(1d);
setPrimaryTransparency(1);
setSecondaryTransparency(1);
}
if (value < transparencyRange) {
setPrimaryTransparency(value / 10d);
setSecondaryTransparency(1d);
setPrimaryTransparency(value / 10f);
setSecondaryTransparency(1);
}
if (value > transparencyRange) {
setSecondaryTransparency((2 * transparencyRange - value) / 10d);
setPrimaryTransparency(1d);
setSecondaryTransparency((2 * transparencyRange - value) / 10f);
setPrimaryTransparency(1);
}
canvas.renderScene();
}
public void setPrimaryTransparency(double transparency) {
public void setPrimaryTransparency(float transparency) {
primaryFace.setTransparency(transparency);
}
public void setSecondaryTransparency(double transparency) {
public void setSecondaryTransparency(float transparency) {
secondaryFace.setTransparency(transparency);
}
......@@ -133,46 +235,55 @@ public class RegistrationCPEventListener {
public void resetTranslation() {
secondaryFace.setTranslation(new Vector3d(0, 0, 0));
calculateFeaturePoints();
canvas.renderScene();
}
public void resetRotation() {
secondaryFace.setRotation(new Vector3d(0, 0, 0));
calculateFeaturePoints();
canvas.renderScene();
}
public void resetScale() {
secondaryFace.setScale(new Vector3d(0, 0, 0));
calculateFeaturePoints();
canvas.renderScene();
}
public void setXTranslation(double value) {
secondaryFace.getTranslation().x = value * moveX;
calculateFeaturePoints();
canvas.renderScene();
}
public void setYTranslation(double value) {
secondaryFace.getTranslation().y = value * moveY;
calculateFeaturePoints();
canvas.renderScene();
}
public void setZTranslation(double value) {
secondaryFace.getTranslation().z = value * moveZ;
calculateFeaturePoints();
canvas.renderScene();
}
public void setXRotation(double value) {
secondaryFace.getRotation().x = value * moveX;
calculateFeaturePoints();
canvas.renderScene();
}
public void setYRotation(double value) {
secondaryFace.getRotation().y = value * moveY;
calculateFeaturePoints();
canvas.renderScene();
}
public void setZRotation(double value) {
secondaryFace.getRotation().z = value * moveZ;
calculateFeaturePoints();
canvas.renderScene();
}
......@@ -180,6 +291,68 @@ public class RegistrationCPEventListener {
secondaryFace.getScale().x = value * scaleXYZ;
secondaryFace.getScale().y = value * scaleXYZ;
secondaryFace.getScale().z = value * scaleXYZ;
calculateFeaturePoints();
canvas.renderScene();
}
public void setPrimaryHighlights() {
primaryFace.setHighlights(new Color(1, 1, 1));
canvas.renderScene();
}
public void setSecondaryHighlights() {
secondaryFace.setHighlights(new Color(1, 1, 1));
canvas.renderScene();
}
public void removePrimaryHighlights() {
primaryFace.setHighlights(new Color(0, 0, 0));
canvas.renderScene();
}
public void removeSecondaryHighlights() {
secondaryFace.setHighlights(new Color(0, 0, 0));
canvas.renderScene();
}
public void setPrimaryLines() {
primaryFace.setRenderMode(GL2.GL_LINE);
canvas.renderScene();
}
public void setSecondaryLines() {
secondaryFace.setRenderMode(GL2.GL_LINE);
canvas.renderScene();
}
public void setPrimaryPoints() {
primaryFace.setRenderMode(GL2.GL_POINT);
canvas.renderScene();
}
public void setSecondaryPoints() {
secondaryFace.setRenderMode(GL2.GL_POINT);
canvas.renderScene();
}
public void setPrimaryFill() {
primaryFace.setRenderMode(GL2.GL_FILL);
canvas.renderScene();
}
public void setSecondaryFill() {
secondaryFace.setRenderMode(GL2.GL_FILL);
canvas.renderScene();
}
public boolean isFeaturePointsActive() {
return primaryFace.isRenderFeaturePoints();
}
public void setFeaturePointsActive(boolean state) {
primaryFace.setRenderFeaturePoints(state);
secondaryFace.setRenderFeaturePoints(state);
calculateFeaturePoints();
canvas.renderScene();
}
}
......@@ -6,12 +6,17 @@
package cz.fidentis.analyst.gui;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.gui.scene.DrawableMesh;
import cz.fidentis.analyst.gui.tab.PostRegistrationCP;
import cz.fidentis.analyst.mesh.io.ModelFileFilter;
import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.vecmath.Point3d;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
......@@ -72,7 +77,21 @@ public final class RegistrationTestTopComponent extends TopComponent {
} catch (Exception ex) {}
canvas1.initScene(primary, secondary);
// feature points test
ArrayList<DrawableMesh> drawables = new ArrayList<>(canvas1.getScene().getDrawables());
DrawableMesh primaryFace = drawables.get(0);
DrawableMesh secondaryFace = drawables.get(1);
ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> primar = new ArrayList<>();
primar.add(new AbstractMap.SimpleEntry<>(new Point3d(100, 0, 0), Color.BLUE));
primaryFace.setFeaturePoints(primar);
ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> secondar = new ArrayList<>();
secondar.add(new AbstractMap.SimpleEntry<>(new Point3d(101, 0, 0), Color.YELLOW));
secondaryFace.setFeaturePoints(secondar);
postRegistrationCP1.initPostRegistrationCP(new RegistrationCPEventListener(canvas1));
}
/**
......
package cz.fidentis.analyst.gui.scene;
import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshModel;
import java.awt.Color;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
/**
......@@ -19,12 +23,19 @@ public class DrawableMesh {
private boolean display = true;
// TO DO - R. Pajersky: add transformation attributes and methods
// material info
private Color color = new Color(255, 255, 255);
private double transparency = 1f;
private Color highlights = new Color(0, 0, 0, 1);
private float transparency = 1;
// transformation info
private Vector3d translation = new Vector3d(0, 0, 0);
private Vector3d rotation = new Vector3d(0, 0, 0);
private Vector3d scale = new Vector3d(0, 0, 0);
// render mode
private int renderMode = GL2.GL_FILL;
// feature points
private ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> featurePoints = new ArrayList<>();
boolean renderFeaturePoints = false;
/**
* Constructor.
......@@ -78,11 +89,11 @@ public class DrawableMesh {
return color;
}
public double getTransparency() {
public float getTransparency() {
return transparency;
}
public void setTransparency(double transparency) {
public void setTransparency(float transparency) {
this.transparency = transparency;
}
......@@ -113,4 +124,36 @@ public class DrawableMesh {
public MeshModel getModel() {
return this.model;
}
public Color getHighlights() {
return highlights;
}
public void setHighlights(Color highlights) {
this.highlights = highlights;
}
public int getRenderMode() {
return renderMode;
}
public void setRenderMode(int renderMode) {
this.renderMode = renderMode;
}
public ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> getFeaturePoints() {
return featurePoints;
}
public void setFeaturePoints(ArrayList<AbstractMap.SimpleEntry<Point3d, Color>> featurePoints) {
this.featurePoints = featurePoints;
}
public boolean isRenderFeaturePoints() {
return renderFeaturePoints;
}
public void setRenderFeaturePoints(boolean renderFeaturePoints) {
this.renderFeaturePoints = renderFeaturePoints;
}
}
......@@ -4,13 +4,14 @@ import com.jogamp.opengl.GL;
import static com.jogamp.opengl.GL.GL_DEPTH_TEST;
import static com.jogamp.opengl.GL.GL_FRONT_AND_BACK;
import com.jogamp.opengl.GL2;
import static com.jogamp.opengl.GL2GL3.GL_FILL;
import static com.jogamp.opengl.GL2GL3.GL_LINE;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import java.awt.Color;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.vecmath.Point3d;
import javax.vecmath.Point4f;
......@@ -61,9 +62,7 @@ public class SceneRenderer {
gl.glEnable(GL2.GL_NORMALIZE);
gl.glDisable(GL2.GL_CULL_FACE);
//color enabled
gl.glEnable(GL2.GL_COLOR_MATERIAL);
gl.glEnable(GL2.GL_BLEND);
gl.glEnable(GL2.GL_BLEND); // enable transparency
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
}
......@@ -123,38 +122,79 @@ public class SceneRenderer {
upDirection.x, upDirection.y, upDirection.z);
gl.glShadeModel(GL2.GL_SMOOTH);
//gl.glGetIntegerv(GL_VIEWPORT, viewport, 0);
//gl.glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix, 0);
//gl.glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix, 0);
if (this.wireframe) {
gl.glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
} else {
gl.glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
if (((DrawableMesh)drawables.toArray()[0]).getTransparency() != 1) {
Collections.reverse((ArrayList)drawables);
}
for (DrawableMesh obj: drawables) {
// render color
Color color = obj.getColor();
gl.glColor4d(color.getRed() / 255d, color.getGreen() / 255d,
color.getBlue() / 255d , obj.getTransparency());
gl.glPolygonMode( GL_FRONT_AND_BACK, obj.getRenderMode());
setMaterial(obj);
gl.glPushMatrix();
setTransformation(obj);
for (MeshFacet facet: obj.getFacets()) {
// TO DO - R. Pajersky: add transformation (glPushMatrix, glRotate, ...)
// rotate
gl.glPushMatrix();
gl.glRotated(obj.getRotation().x, 1, 0, 0);
gl.glRotated(obj.getRotation().y, 0, 1, 0);
gl.glRotated(obj.getRotation().z, 0, 0, 1);
// move
gl.glTranslated(obj.getTranslation().x, obj.getTranslation().y, obj.getTranslation().z);
// scale
gl.glScaled(1 + obj.getScale().x, 1 + obj.getScale().y, 1 + obj.getScale().z);
renderFacet(facet);
gl.glPopMatrix();
}
if (obj.isRenderFeaturePoints()) {
renderFeaturePoints(obj);
}
gl.glPopMatrix();
}
gl.glFlush();
gl.glFlush();
}
/**
* Sets up material based on info from DrawableMesh
*/
private void setMaterial(DrawableMesh obj) {
// set color
Color color = obj.getColor();
float[] rgba = {color.getRed() / 255f, color.getGreen() / 255f,
color.getBlue() / 255f , obj.getTransparency()};
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, rgba, 0);
// set color of highlights
color = obj.getHighlights();
float[] highlights = {color.getRed(), color.getGreen(), color.getBlue(), 1};
gl.glMaterialf(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 50);
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, highlights, 0);
}
/**
* Sets up object transformation
*/
private void setTransformation(DrawableMesh obj) {
// rotate
gl.glRotated(obj.getRotation().x, 1, 0, 0);
gl.glRotated(obj.getRotation().y, 0, 1, 0);
gl.glRotated(obj.getRotation().z, 0, 0, 1);
// move
gl.glTranslated(obj.getTranslation().x, obj.getTranslation().y, obj.getTranslation().z);
// scale
gl.glScaled(1 + obj.getScale().x, 1 + obj.getScale().y, 1 + obj.getScale().z);
}
/**
* Renders feature points
*/
private void renderFeaturePoints(DrawableMesh obj) {
for (AbstractMap.SimpleEntry<Point3d, Color> featurePoint: obj.getFeaturePoints()) {
Color color = featurePoint.getValue();
Point3d point = featurePoint.getKey();
gl.glPushMatrix();
gl.glTranslated(point.x, point.y, point.z);
float[] rgba = {color.getRed() / 255f, color.getGreen() / 255f,
color.getBlue() / 255f , obj.getTransparency()};
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, rgba, 0);
GLUquadric center = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(center, GLU.GLU_FILL);
glu.gluQuadricNormals(center, GLU.GLU_FLAT);
glu.gluQuadricOrientation(center, GLU.GLU_OUTSIDE);
glu.gluSphere(center, 3f, 16, 16);
glu.gluDeleteQuadric(center);
gl.glPopMatrix();
}
}
/**
......@@ -207,5 +247,4 @@ public class SceneRenderer {
gl.glEnd();
}
}
......@@ -20,20 +20,18 @@ PostRegistrationCP.leftTranslationXButton.text=<<
PostRegistrationCP.translationButton.toolTipText=reset translation
PostRegistrationCP.translationButton.text=reset
PostRegistrationCP.profileButton.toolTipText=model profile view
PostRegistrationCP.profileButton.text=profile
PostRegistrationCP.profileButton.text=side
PostRegistrationCP.frontButton.toolTipText=model front view
PostRegistrationCP.frontButton.text=front
PostRegistrationCP.featurePointsButton.text=Feature points
PostRegistrationCP.featurePointsButton.text=show
PostRegistrationCP.viewLabel.text=View:
PostRegistrationCP.modelLabel.text=Model:
PostRegistrationCP.transparencyButton.toolTipText=reset transparency
PostRegistrationCP.transparencyButton.text=Opacity
PostRegistrationCP.colorButton.toolTipText=reset colors
PostRegistrationCP.colorButton.text=Color
PostRegistrationCP.primaryLabel.text=Primary
PostRegistrationCP.transparencyButton.text=opacity
PostRegistrationCP.primaryLabel.text=primary
PostRegistrationCP.jLabel1.text=Registration adjustment
PostRegistrationCP.secondaryLabel.toolTipText=
PostRegistrationCP.secondaryLabel.text=Secondary
PostRegistrationCP.secondaryLabel.text=secondary
PostRegistrationCP.transparencySlider.toolTipText=sets model transparency
PostRegistrationCP.secondaryColorPanel.toolTipText=sets color of secondary model
PostRegistrationCP.primaryColorPanel.toolTipText=sets color of primary model
......@@ -73,3 +71,20 @@ PostRegistrationCP.rotatZLabel.text=Z
PostRegistrationCP.scaleSmallPlusButton.text=+
PostRegistrationCP.scaleSmallMinusButton.text=-
PostRegistrationCP.rightTranslationXButton.text=>>
PostRegistrationCP.highlightsLabel.text=highlights
PostRegistrationCP.primaryHighlightsCB.text=
PostRegistrationCP.secondaryHighlightsCB.text=
PostRegistrationCP.renderModeLabel.text=render mode
PostRegistrationCP.fillLabel.text=fill
PostRegistrationCP.linesLabel.text=lines
PostRegistrationCP.pointsLabel.text=points
PostRegistrationCP.primaryFillRB.text=
PostRegistrationCP.secondaryFillRB.text=
PostRegistrationCP.primaryLinesRB.text=
PostRegistrationCP.secondaryLinesRB.text=
PostRegistrationCP.secondaryPointsRB.text=
PostRegistrationCP.primaryPointsRB.text=
PostRegistrationCP.colorButton.toolTipText=reset colors
PostRegistrationCP.colorButton.text=color
PostRegistrationCP.transformationLabel.text=Transformation
PostRegistrationCP.featurePointsLabel.text=Feature points:
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