Commit f890a146 authored by legoc's avatar legoc
Browse files

Added xaml importer (txt files from xaml) to compare with STL

parent 7776982c
package fr.ill.ics.n3d.io;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class XamlImporter {
public ArrayList<Double> matrix = new ArrayList<Double>();
public ArrayList<Float> positions = new ArrayList<Float>();
public ArrayList<Integer> triangleIndices = new ArrayList<Integer>();
private int lastFace = 0;
private int nextFace = 0;
private void loadMatrix(String[] values) {
assert(values.length == 16);
for (int i = 0; i < values.length; ++i) {
matrix.add(Double.valueOf(values[i]));
}
}
private void loadPositions(String[] values) {
assert(values.length % 3 == 0);
for (int i = 0; i < values.length; ++i) {
positions.add(Float.valueOf(values[i]));
}
lastFace = nextFace;
nextFace = positions.size() / 3;
}
private void loadTriangleIndices(String[] values) {
assert(values.length % 3 == 0);
for (int i = 0; i < values.length; ++i) {
triangleIndices.add(lastFace + Integer.valueOf(values[i]));
}
}
public void load(String fileName) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
StringBuilder sb = new StringBuilder();
String line = null;
line = br.readLine();
while (line != null) {
if (line.contains("=")) {
//System.out.println("line = " + line);
int pos = line.indexOf('=');
String key = line.substring(0, pos);
int end = line.lastIndexOf('"');
String value = line.substring(pos + 2, end);
String[] values = value.split("[, ]");
if (key.equals("Matrix")) {
loadMatrix(values);
}
if (key.equals("Positions")) {
loadPositions(values);
}
if (key.equals("TriangleIndices")) {
loadTriangleIndices(values);
}
}
sb.append(line);
sb.append(System.lineSeparator());
try {
line = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
br.close();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
}
// System.out.println("Matrix");
// for (double v : matrix) {
// System.out.println(v);
// }
//
// System.out.println("Positions");
// for (int i = 0; i < positions.size(); i += 3) {
// System.out.println((i / 3) + " = " + positions.get(i) + ", " + positions.get(i + 1) + ", " + positions.get(i + 2));
// }
//
// System.out.println("TriangleIndices");
// for (int i = 0; i < triangleIndices.size(); i += 3) {
// System.out.println((i / 3) + " = " + triangleIndices.get(i) + ", " + triangleIndices.get(i + 1) + ", " + triangleIndices.get(i + 2));
// }
}
public static void main(String[] args) {
XamlImporter importer = new XamlImporter();
importer.load("data/support-1.txt");
}
}
\ No newline at end of file
...@@ -15,6 +15,7 @@ import java.util.logging.Logger; ...@@ -15,6 +15,7 @@ import java.util.logging.Logger;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter; import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import fr.ill.ics.n3d.io.XamlImporter;
import fr.ill.ics.n3d.link.Nomad3DController; import fr.ill.ics.n3d.link.Nomad3DController;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
...@@ -28,6 +29,7 @@ import javafx.scene.input.MouseEvent; ...@@ -28,6 +29,7 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial; import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.CullFace; import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.MeshView; import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh; import javafx.scene.shape.TriangleMesh;
import javafx.scene.shape.VertexFormat; import javafx.scene.shape.VertexFormat;
...@@ -829,6 +831,100 @@ public class Component { ...@@ -829,6 +831,100 @@ public class Component {
configurationsAnalysis(); configurationsAnalysis();
} }
void calculateBB(TriangleMesh mesh) {
System.out.println("Points " + mesh.getPoints().size() + " = " + mesh.getPoints());
float minX = mesh.getPoints().get(0);
float minY = mesh.getPoints().get(1);
float minZ = mesh.getPoints().get(2);
float maxX = mesh.getPoints().get(0);
float maxY = mesh.getPoints().get(1);
float maxZ = mesh.getPoints().get(2);
for (int i = 0; i < mesh.getPoints().size(); i += 3) {
if (mesh.getPoints().get(i) < minX) {
minX = mesh.getPoints().get(i);
}
if (mesh.getPoints().get(i) > maxX) {
maxX = mesh.getPoints().get(i);
}
if (mesh.getPoints().get(i+1) < minY) {
minY = mesh.getPoints().get(i+1);
}
if (mesh.getPoints().get(i+1) > maxY) {
maxY = mesh.getPoints().get(i+1);
}
if (mesh.getPoints().get(i+2) < minZ) {
minZ = mesh.getPoints().get(i+2);
}
if (mesh.getPoints().get(i+2) > maxZ) {
maxZ = mesh.getPoints().get(i+2);
}
}
System.out.println("min = " + minX + ", " + minY + ", " + minZ);
System.out.println("max = " + maxX + ", " + maxY + ", " + maxZ);
System.out.println("center = " + 0.5 * (minX + maxX) + ", " + 0.5 * (minY + maxY) + ", " + 0.5 * (minZ + maxZ));
System.out.println("X = " + (maxX - minX));
System.out.println("Y = " + (maxY - minY));
System.out.println("Z = " + (maxZ - minZ));
}
Transform loadXamlTransform(String componentName) {
XamlImporter importer = new XamlImporter();
importer.load("/users/legoc/nomad3d/SOLIDWORKS_models/Emilio-xaml/Importer/data/" + componentName + ".txt");
Affine transform = new Affine();
transform.setMxx(importer.matrix.get(0));
transform.setMyx(importer.matrix.get(1));
transform.setMzx(importer.matrix.get(2));
transform.setMxy(importer.matrix.get(4));
transform.setMyy(importer.matrix.get(5));
transform.setMzy(importer.matrix.get(6));
transform.setMxz(importer.matrix.get(8));
transform.setMyz(importer.matrix.get(9));
transform.setMzz(importer.matrix.get(10));
// transform.setTx(importer.matrix.get(12));
// transform.setTy(importer.matrix.get(13));
// transform.setTz(importer.matrix.get(14));
transform.setTx(importer.matrix.get(12) * 1000.0);
transform.setTy(importer.matrix.get(13) * 1000.0);
transform.setTz(importer.matrix.get(14) * 1000.0);
return transform;
}
MeshView loadXamlGeometry(String componentName) {
XamlImporter importer = new XamlImporter();
importer.load("/users/legoc/nomad3d/SOLIDWORKS_models/Emilio-xaml/Importer/data/" + componentName + ".txt");
float[] points = new float[importer.positions.size()];
for (int i = 0; i < importer.positions.size(); ++i) {
points[i] = importer.positions.get(i) * 1000.0f;
}
int[] faces = new int[importer.triangleIndices.size() * 2];
for (int i = 0; i < importer.triangleIndices.size(); ++i) {
faces[2 * i] = importer.triangleIndices.get(i);
faces[2 * i + 1] = 0; // texture index
}
TriangleMesh mesh = new TriangleMesh();
mesh.getPoints().addAll(points);
mesh.getTexCoords().addAll(0, 0);
mesh.getFaces().addAll(faces);
MeshView view = new MeshView(mesh);
return view;
}
/** /**
* Compute the scene tree of this component's hierarchy, for the specified configuration. * Compute the scene tree of this component's hierarchy, for the specified configuration.
* @param model Model owning the component * @param model Model owning the component
...@@ -856,11 +952,27 @@ public class Component { ...@@ -856,11 +952,27 @@ public class Component {
invParentTransform = new Affine(); invParentTransform = new Affine();
} }
System.out.println("Component " + getName());
if (this.children.isEmpty()) { if (this.children.isEmpty()) {
String stlPath = this.fileName + ".STL"; String stlPath = this.fileName + ".STL";
File stlFile = new File(model.getDirectoryPath() + File.separator + model.getGeometryDirectory(lod), stlPath); File stlFile = new File(model.getDirectoryPath() + File.separator + model.getGeometryDirectory(lod), stlPath);
MeshView meshView = importMesh(model, stlFile);
MeshView meshView = null;
//if (getName().equals("ringE-1")) {
meshView = importMesh(model, stlFile);
// }
// else {
// meshView = loadXamlGeometry("ringE-1");
// }
this.setSceneNode(meshView); this.setSceneNode(meshView);
System.out.println("");
TriangleMesh mesh = (TriangleMesh)meshView.getMesh();
calculateBB(mesh);
} else { } else {
Group targetGroup = new Group(); Group targetGroup = new Group();
this.setSceneNode(targetGroup); this.setSceneNode(targetGroup);
...@@ -876,7 +988,32 @@ public class Component { ...@@ -876,7 +988,32 @@ public class Component {
} }
this.sceneNode.setVisible(config.isVisible()); this.sceneNode.setVisible(config.isVisible());
this.sceneNode.getTransforms().addAll(invParentTransform, this.axis.getMovementTransform(), config.getTranslation(), config.getRotation(), config.getScale());
this.sceneNode.getTransforms().addAll(
invParentTransform,
this.axis.getMovementTransform(),
config.getTranslation(),
config.getRotation(),
config.getScale());
//
// System.out.println(" inv parent = " + invParentTransform);
// System.out.println(" movement = " + this.axis.getMovementTransform());
// System.out.println(" translation = " + config.getTranslation());
// System.out.println(" rotation = " + config.getRotation());
// System.out.println(" scale = " + config.getScale());
System.out.println(" N3D Transform = " + this.sceneNode.getLocalToSceneTransform());
//Transform xamlTransform = loadXamlTransform(getName());
//System.out.println(" Xaml Transform = " + xamlTransform);
//this.sceneNode.getTransforms().addAll(invParentTransform);
//this.sceneNode.getTransforms().addAll(xamlTransform);
System.out.println("");
} }
for (Component child : this.children) { for (Component child : this.children) {
...@@ -1053,6 +1190,14 @@ public class Component { ...@@ -1053,6 +1190,14 @@ public class Component {
invParentTransform = new Affine(); invParentTransform = new Affine();
} }
System.out.println("Component " + getName());
System.out.println(" inv parent = " + invParentTransform);
System.out.println(" movement = " + this.axis.getMovementTransform());
System.out.println(" translation = " + config.getTranslation());
System.out.println(" rotation = " + config.getRotation());
System.out.println(" scale = " + config.getScale());
System.out.println("");
Node node = this.sceneNode; Node node = this.sceneNode;
node.getTransforms().clear(); node.getTransforms().clear();
node.getTransforms().addAll( node.getTransforms().addAll(
...@@ -1062,6 +1207,7 @@ public class Component { ...@@ -1062,6 +1207,7 @@ public class Component {
config.getRotation(), config.getRotation(),
config.getScale() config.getScale()
); );
node.setVisible(config.isVisible()); node.setVisible(config.isVisible());
for (Component child : this.children) { for (Component child : this.children) {
child.showConfiguration(configName); child.showConfiguration(configName);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment