Skip to content

Commit

Permalink
First version of vertex selection for issue #3
Browse files Browse the repository at this point in the history
+ added selection for vertices
    --> you can now click vertices to select/deselect them
	selected vertices will be saved in a list and are printed to the console (for debugging)
	selected vertices will be "highlighted" by changing their color to white
	hold down control while clicking vertices to select multiple vertices
	vertex size was increased for testing purposes
+ fixed a small visual bug while drawing edges
  • Loading branch information
esontak committed Feb 10, 2015
1 parent 4d78217 commit 1248d48
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 13 deletions.
Binary file modified .gradle/2.0/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.0/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/2.0/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/2.0/taskArtifacts/taskArtifacts.bin
Binary file not shown.
34 changes: 31 additions & 3 deletions src/main/java/edu/gcsc/jfx3d/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.thoughtworks.xstream.annotations.XStreamAlias;
import java.util.ArrayList;
import java.util.function.Predicate;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
Expand All @@ -20,6 +21,7 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.PickResult;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
Expand Down Expand Up @@ -69,6 +71,7 @@ public class Main extends Application{

String[] subsetNameArray;
Scene scene;
Group pickedGroup;

private double scenex, sceney = 0;
private double fixedXAngle, fixedYAngle = 0;
Expand All @@ -80,6 +83,7 @@ public class Main extends Application{

Text t;

public static boolean strgPressedDown = false;

Group ugxGeometry;
int ugxSubsetCount;
Expand All @@ -97,7 +101,7 @@ public void start(Stage primaryStage) throws Exception {

// Create camera
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setFarClip(1000);
camera.setFarClip(100000);

// and position it
camera.getTransforms().addAll(
Expand Down Expand Up @@ -266,6 +270,9 @@ private void handleKeyboard(Scene scene,PerspectiveCamera camera){
System.out.println("Currently shown subset: All");
}

if (keycode == KeyCode.CONTROL) {
strgPressedDown = true;
}

if(keycode == KeyCode.T){
camera.setRotationAxis(Rotate.X_AXIS);
Expand All @@ -286,8 +293,18 @@ private void handleKeyboard(Scene scene,PerspectiveCamera camera){

}
});

scene.setOnKeyReleased(releaseEvent -> {

KeyCode keycode = releaseEvent.getCode();

if (keycode == KeyCode.CONTROL) {
strgPressedDown = false;
}

});
}

private void handleMouse(Scene scene,PerspectiveCamera camera){

Rotate xRotate = new Rotate(0, 0, 0, 0, Rotate.X_AXIS);
Expand All @@ -314,11 +331,22 @@ private void handleMouse(Scene scene,PerspectiveCamera camera){
mouseXold = mouseXnew;
mouseYold = mouseYnew;
}
}
}
);

scene.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseClick -> {
//Node pickRes = mouseClick.getPickResult().getIntersectedNode();

//System.out.println("pickRes "+pickRes );



}
);

}


private Group buildPyramid(float height, float hypotenuse, Color color, boolean ambient, boolean fill) {
final TriangleMesh mesh = new TriangleMesh();

Expand Down
88 changes: 78 additions & 10 deletions src/main/java/edu/gcsc/jfx3d/UGXReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.EventType;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
Expand All @@ -38,6 +44,12 @@ public class UGXReader {
private ArrayList<Integer> tetra = new ArrayList<Integer>();
private ArrayList<UGXsubset> subsetList = new ArrayList<UGXsubset>();
private UGXsubsetHandler subsetHandler;
private ArrayList<Node> nodeSelection = new ArrayList<Node>();
private ArrayList<Material> nodeSelectionMaterial = new ArrayList<Material>();
private Node prevPickRes;


boolean strgPressed = false;

public UGXReader(String filePath){

Expand Down Expand Up @@ -351,12 +363,11 @@ public Group xbuildUGX (boolean ambient, boolean fill){
MeshView[] meshViewArray = new MeshView[ssNumber];
Group subsetGroup = new Group();
for (int i = 0; i < ssNumber; i++) {

meshArray[i].getPoints().addAll(vertices);
meshArray[i].getTexCoords().addAll(0,0);
Group vertexGroup = new Group();
Group edgesGroup = new Group();

ssVertices = ugxfile.getSubset_handler().get(0).getSubsets().get(i).getVertexArray();

ssEdges = ugxfile.getSubset_handler().get(0).getSubsets().get(i).getEdgeArray();
Expand All @@ -370,7 +381,7 @@ public Group xbuildUGX (boolean ambient, boolean fill){
Sphere[] sphereArray = new Sphere[ssVertices.length];

for (int j = 0; j < ssVertices.length; j++) {
sphereArray[j] = new Sphere(0.025);
sphereArray[j] = new Sphere(0.075);
sphereArray[j].setTranslateX(vertices[ssVertices[j]*3]);
sphereArray[j].setTranslateY(vertices[ssVertices[j]*3+1]);
sphereArray[j].setTranslateZ(vertices[ssVertices[j]*3+2]);
Expand All @@ -380,7 +391,8 @@ public Group xbuildUGX (boolean ambient, boolean fill){
Math.abs(ugxfile.getSubset_handler().get(0).getSubsets().get(i).getColor()[3])));
sphereArray[j].setMaterial(sphereMat);
vertexGroup.getChildren().add(sphereArray[j]);
}
}
addVertexInteraction(vertexGroup);
}// end of vertex visualisation


Expand All @@ -404,14 +416,14 @@ public Group xbuildUGX (boolean ambient, boolean fill){
//create triangle around the first Node
edgesMesh.getPoints().addAll(bottomXexact - width, bottomYexact - width, bottomZ-width);
edgesMesh.getPoints().addAll(bottomXexact + width, bottomYexact - width, bottomZ);
edgesMesh.getPoints().addAll(bottomXexact, bottomYexact + width, bottomZ);
edgesMesh.getPoints().addAll(bottomXexact, bottomYexact + width, bottomZ+width);
//create triangle around the second Node
edgesMesh.getPoints().addAll(topXexact - width, topYexact - width, topZ-width);
edgesMesh.getPoints().addAll(topXexact + width, topYexact - width, topZ);
edgesMesh.getPoints().addAll(topXexact, topYexact + width, topZ);
edgesMesh.getPoints().addAll(topXexact, topYexact + width, topZ+width);

//creat a prism from the two triagnles and add the faces
edgesPrisms.add(new Prism(j*6, j*6+2, j*6+1, j*6+3, j*6+5, j*6+4, j));
edgesPrisms.add(new Prism(j*6, j*6+1, j*6+2, j*6+3, j*6+4, j*6+5, j));
edgesMesh.getFaces().addAll(edgesPrisms.get(j).getFacesArray());

}
Expand All @@ -422,22 +434,22 @@ public Group xbuildUGX (boolean ambient, boolean fill){
Math.abs(ugxfile.getSubset_handler().get(0).getSubsets().get(i).getColor()[3])));
edgesMeshView.setMaterial(edgeMat);
//edgesMeshView.setDrawMode(DrawMode.FILL);
//edgesMeshView.setCullFace(CullFace.NONE);
edgesMeshView.setCullFace(CullFace.NONE);

edgesGroup.getChildren().addAll(edgesMeshView);

} // end of edge visualisation

// start of face visualisation
if (ugxfile.getSubset_handler().get(0).getSubsets().get(i).isHasFaces()) {
if (ugxfile.getSubset_handler().get(0).getSubsets().get(i).isHasFaces() && fill) {

for (int j = 0; j < ssFaces.length; j++) {
meshArray[i].getFaces().addAll(geometry2DList.get(ssFaces[j]).getFacesArray());
}
} // end of face visualisation

// start of volume visualisation
if (ugxfile.getSubset_handler().get(0).getSubsets().get(i).isHasVolumes()){
if (ugxfile.getSubset_handler().get(0).getSubsets().get(i).isHasVolumes() && fill){

for (int j = 0; j < ssVolumes.length; j++) {
meshArray[i].getFaces().addAll(geometry3DList.get(ssVolumes[j]).getFacesArray());
Expand Down Expand Up @@ -504,6 +516,62 @@ public Group xbuildUGX (boolean ambient, boolean fill){
return subsetGroup;
}

private void addVertexInteraction(Group vGroup) {

vGroup.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseClick -> {
Node pickRes = mouseClick.getPickResult().getIntersectedNode();
Sphere sphr = (Sphere) pickRes;
if (!nodeSelection.contains(pickRes)) {

if (!Main.strgPressedDown) { // strg not pressed
for (int i = 0; i < nodeSelection.size(); i++) {

((Sphere) nodeSelection.get(i)).setMaterial(nodeSelectionMaterial.get(i));
}
nodeSelection.clear();
nodeSelectionMaterial.clear();
}

nodeSelection.add(pickRes);
nodeSelectionMaterial.add(((Sphere) pickRes).getMaterial());
System.out.println("Elements in NodeSelection :");
for (int i = 0; i < nodeSelection.size(); i++) {
System.out.print(nodeSelection.get(i) + " ");
System.out.println(nodeSelection.get(i).getTranslateX() + " "
+ nodeSelection.get(i).getTranslateY() + " "
+ nodeSelection.get(i).getTranslateZ());
}
Color col = new Color(1, 1, 1, 1);
PhongMaterial mat = new PhongMaterial(col);
((Sphere) pickRes).setMaterial(mat);
} else {

int index = nodeSelection.indexOf(pickRes);
((Sphere) nodeSelection.get(index)).setMaterial(nodeSelectionMaterial.get(index));
nodeSelection.remove(index);
nodeSelectionMaterial.remove(index);
if (!Main.strgPressedDown) { // strg not pressed
for (int i = 0; i < nodeSelection.size(); i++) {

((Sphere) nodeSelection.get(i)).setMaterial(nodeSelectionMaterial.get(i));
}
nodeSelection.clear();
nodeSelectionMaterial.clear();
}

System.out.println("Elements in NodeSelection :");
for (int i = 0; i < nodeSelection.size(); i++) {
System.out.print(nodeSelection.get(i) + " ");
System.out.println(nodeSelection.get(i).getTranslateX() + " "
+ nodeSelection.get(i).getTranslateY() + " "
+ nodeSelection.get(i).getTranslateZ());
}

}
}
);
}

public float[] getVerticesFloatArray(){
float[] verticesArray = new float[vertices.size()];
for (int i = 0; i < vertices.size(); i++) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/gcsc/jfx3d/UGXfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public ArrayList<UGXsubsetHandler> getSubset_handler() {


public void convertReaderStringToData(){
this.globalVertices = new ArrayList<Float>();
this.edges = new ArrayList<Edge>();
this.triangles = new ArrayList<Triangle>();
this.quadrilaterals = new ArrayList<Quadrilateral>();
this.tetrahedrons = new ArrayList<Tetrahedron>();
this.hexahedrons = new ArrayList<Hexahedron>();
Expand Down

0 comments on commit 1248d48

Please sign in to comment.