Commit bdac6be1 authored by Thilo Rörig's avatar Thilo Rörig

fixed VectorFieldVisualizer

parent 27dbfc74
...@@ -64,8 +64,6 @@ public abstract class AbstractSceneGraphComponentVisualization extends AbstractD ...@@ -64,8 +64,6 @@ public abstract class AbstractSceneGraphComponentVisualization extends AbstractD
public abstract void updateSceneGraphComponent(); public abstract void updateSceneGraphComponent();
void clearSceneGraphComponent() { void clearSceneGraphComponent() {
sceneGraphComponent.setGeometry(null); sceneGraphComponent.setGeometry(null);
List<SceneGraphComponent> sgc = sceneGraphComponent.getChildComponents(); List<SceneGraphComponent> sgc = sceneGraphComponent.getChildComponents();
...@@ -75,7 +73,7 @@ public abstract class AbstractSceneGraphComponentVisualization extends AbstractD ...@@ -75,7 +73,7 @@ public abstract class AbstractSceneGraphComponentVisualization extends AbstractD
} }
} }
protected List<? extends Node> getNodes(HalfEdgeDataStructure<?, ?, ?> hds) { List<? extends Node> getNodes(HalfEdgeDataStructure<?, ?, ?> hds) {
List<? extends Node> nodes; List<? extends Node> nodes;
switch (getType()) { switch (getType()) {
......
...@@ -31,8 +31,8 @@ public abstract class AbstractVectorCoordinateAndIndexFactory<COORDTYPE> ...@@ -31,8 +31,8 @@ public abstract class AbstractVectorCoordinateAndIndexFactory<COORDTYPE>
vertexCoordinates.add(Rn.add(null, p, v3D)); vertexCoordinates.add(Rn.add(null, p, v3D));
} else { } else {
Rn.times(v3D, scale / 2., v3D); Rn.times(v3D, scale / 2., v3D);
vertexCoordinates.add(Rn.add(null, p, v3D));
vertexCoordinates.add(p); vertexCoordinates.add(p);
vertexCoordinates.add(Rn.add(null, p, v3D));
} }
} }
......
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.math.Rn;
import de.jreality.scene.IndexedLineSet;
import java.awt.*;
import java.util.List;
class ArrowLineSetCreator implements LineSetCreator {
private double thickness = .1;
private Color color = Color.BLACK;
public ArrowLineSetCreator(double thickness, Color color) {
this.thickness = thickness;
this.color = color;
}
@Override
public IndexedLineSet createLineSet(java.util.List<double[]> vData, List<int[]> iData) {
int numOfVectors = vData.size() / 2;
int numcoords = 6 * numOfVectors;
int numedges = 2 * numOfVectors;
double[][] coords = new double[numcoords][];
int[][] edges = new int[numedges][];
double[] radii = new double[numcoords];
Color[] edgecolors = new Color[numedges];
double[] startcoords, targetcoords, vector;
int[] ids;
int startid, targetid;
for (int i = 0; i < numOfVectors; i++) {
ids = iData.get(i);
if (ids.length != 2)
throw new RuntimeException("Is not a single edge (= vector)!");
startid = ids[0];
targetid = ids[1];
startcoords = vData.get(startid);
targetcoords = vData.get(targetid);
vector = Rn.subtract(null, targetcoords, startcoords);
coords[i + 0 * numOfVectors] = Rn.subtract(null, startcoords,
Rn.setEuclideanNorm(null, 0.001, vector));
coords[i + 1 * numOfVectors] = startcoords.clone();
coords[i + 2 * numOfVectors] = targetcoords.clone();
radii[i + 0 * numOfVectors] = 0.001;
radii[i + 1 * numOfVectors] = thickness;
radii[i + 2 * numOfVectors] = thickness;
edgecolors[i] = color;
edges[i] = new int[]{i + 0 * numOfVectors,
i + 1 * numOfVectors, i + 2 * numOfVectors};
coords[i + 3 * numOfVectors] = Rn.subtract(null,
targetcoords, Rn.times(null, 0.001, vector));
radii[i + 3 * numOfVectors] = 0.001;
coords[i + 4 * numOfVectors] = targetcoords.clone();
radii[i + 4 * numOfVectors] = 1.5 * thickness;
coords[i + 5 * numOfVectors] = Rn.add(null, targetcoords,
Rn.times(null, .2, vector));
radii[i + 5 * numOfVectors] = 0.001;
edges[i + numOfVectors] = new int[]{i + 3 * numOfVectors,
i + 4 * numOfVectors, i + 5 * numOfVectors};
edgecolors[i + numOfVectors] = Color.black;
}
IndexedLineSetFactory ilsf = new IndexedLineSetFactory();
if (numcoords != 0) {
ilsf.setVertexCount(numcoords);
ilsf.setEdgeCount(numedges);
ilsf.setVertexCoordinates(coords);
ilsf.setVertexRelativeRadii(radii);
ilsf.setEdgeIndices(edges);
ilsf.setEdgeColors(edgecolors);
ilsf.update();
}
return ilsf.getIndexedLineSet();
}
}
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.scene.IndexedLineSet;
import java.util.List;
interface LineSetCreator {
IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData);
}
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.scene.IndexedLineSet;
import java.util.List;
class SimpleLineSetCreator implements LineSetCreator {
@Override
public IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData) {
IndexedLineSetFactory ilf = new IndexedLineSetFactory();
if (vData.size() == 0) {
return ilf.getIndexedLineSet();
}
ilf.setVertexCount(vData.size());
ilf.setEdgeCount(vData.size() / 2);
ilf.setVertexCoordinates(vData.toArray(new double[][]{}));
ilf.setEdgeIndices(iData.toArray(new int[][]{}));
ilf.update();
return ilf.getIndexedLineSet();
}
}
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.math.Rn;
import de.jreality.scene.IndexedLineSet;
import java.awt.*;
import java.util.List;
class TubeLineSetCreator implements LineSetCreator {
private double thickness = .1;
private Color color = Color.BLACK;
public TubeLineSetCreator(double thickness, Color color) {
this.thickness = thickness;
this.color = color;
}
@Override
public IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData) {
int numOfVectors = vData.size() / 2;
int numcoords = 4 * numOfVectors;
int numedges = numOfVectors;
double[][] coords = new double[numcoords][];
int[][] edges = new int[numedges][];
double[] radii = new double[numcoords];
Color[] edgecolors = new Color[numedges];
double[] startcoords, targetcoords, vector;
int[] ids;
int startid, targetid;
for (int i = 0; i < numOfVectors; i++) {
ids = iData.get(i);
if (ids.length != 2)
throw new RuntimeException("Is not a single edge (= vector)!");
startid = ids[0];
targetid = ids[1];
startcoords = vData.get(startid);
targetcoords = vData.get(targetid);
vector = Rn.subtract(null, targetcoords, startcoords);
coords[i + 0 * numOfVectors] = Rn.subtract(null, startcoords,
Rn.setEuclideanNorm(null, 0.001, vector));
coords[i + 1 * numOfVectors] = startcoords.clone();
coords[i + 2 * numOfVectors] = targetcoords.clone();
radii[i + 0 * numOfVectors] = 0.001;
radii[i + 1 * numOfVectors] = thickness;
radii[i + 2 * numOfVectors] = thickness;
edgecolors[i] = color;
coords[i + 3 * numOfVectors] = Rn.add(null, targetcoords,
Rn.setEuclideanNorm(null, 0.001, vector));
radii[i + 3 * numOfVectors] = 0.001;
edges[i] = new int[]{i + 0 * numOfVectors,
i + 1 * numOfVectors, i + 2 * numOfVectors,
i + 3 * numOfVectors};
}
IndexedLineSetFactory ilsf = new IndexedLineSetFactory();
if (numcoords != 0) {
ilsf.setVertexCount(numcoords);
ilsf.setEdgeCount(numedges);
ilsf.setVertexCoordinates(coords);
ilsf.setVertexRelativeRadii(radii);
ilsf.setEdgeIndices(edges);
ilsf.setEdgeColors(edgecolors);
ilsf.update();
}
return ilsf.getIndexedLineSet();
}
}
package de.jtem.halfedgetools.plugin.data.visualizer; package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.math.Rn;
import de.jreality.scene.IndexedLineSet; import de.jreality.scene.IndexedLineSet;
import de.jreality.ui.LayoutFactory; import de.jreality.ui.LayoutFactory;
import de.jtem.halfedge.HalfEdgeDataStructure; import de.jtem.halfedge.HalfEdgeDataStructure;
...@@ -180,11 +178,11 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements ...@@ -180,11 +178,11 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
return; return;
actVis.setScale(scaleModel.getNumber().doubleValue()); actVis.setScale(scaleModel.getNumber().doubleValue());
actVis.thickness = thicknessModel.getNumber().doubleValue(); actVis.thickness = thicknessModel.getNumber().doubleValue();
actVis.tubesenabled = tubesChecker.isSelected(); actVis.setDirected(directedChecker.isSelected());
actVis.directed = directedChecker.isSelected();
actVis.setNormalized(normalizedChecker.isSelected()); actVis.setNormalized(normalizedChecker.isSelected());
actVis.setCentered(centeredChecker.isSelected()); actVis.setCentered(centeredChecker.isSelected());
actVis.color = colors[colorChooser.getSelectedIndex()]; actVis.color = colors[colorChooser.getSelectedIndex()];
actVis.enableTubes(tubesChecker.isSelected());
if (selectionChecker.isSelected()) { if (selectionChecker.isSelected()) {
actVis.selection = actVis.getLayer().getSelection(); actVis.selection = actVis.getLayer().getSelection();
} else { } else {
...@@ -203,10 +201,9 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements ...@@ -203,10 +201,9 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
private Color private Color
color = Color.BLACK; color = Color.BLACK;
private AbstractVectorCoordinateAndIndexFactory private AbstractVectorCoordinateAndIndexFactory coordinateAndIndexFactory;
coordinateAndIndexFactory;
private AbstractLineSetCreator lineSetCreator; private LineSetCreator lineSetCreator;
public VectorFieldVisualization(HalfedgeLayer layer, Adapter<T> source, public VectorFieldVisualization(HalfedgeLayer layer, Adapter<T> source,
DataVisualizer visualizer, NodeType type) { DataVisualizer visualizer, NodeType type) {
...@@ -266,6 +263,8 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements ...@@ -266,6 +263,8 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
coordinateAndIndexFactory = new MultiVectorCoordinateAndIndexFactory(); coordinateAndIndexFactory = new MultiVectorCoordinateAndIndexFactory();
} }
coordinateAndIndexFactory.setAdapter(getSource()); coordinateAndIndexFactory.setAdapter(getSource());
coordinateAndIndexFactory.centered = centeredChecker.isSelected();
coordinateAndIndexFactory.scale = scaleModel.getNumber().doubleValue();
return coordinateAndIndexFactory; return coordinateAndIndexFactory;
} }
...@@ -288,8 +287,12 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements ...@@ -288,8 +287,12 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
public void enableTubes(boolean enabled) { public void enableTubes(boolean enabled) {
this.tubesenabled = enabled; this.tubesenabled = enabled;
if (tubesenabled) { if(tubesenabled) {
lineSetCreator = new ArrowLineSetCreator(); if(directed) {
lineSetCreator = new ArrowLineSetCreator(thickness, color);
} else {
lineSetCreator = new TubeLineSetCreator(thickness, color);
}
} else { } else {
lineSetCreator = new SimpleLineSetCreator(); lineSetCreator = new SimpleLineSetCreator();
} }
...@@ -312,121 +315,6 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements ...@@ -312,121 +315,6 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
} }
public abstract class AbstractLineSetCreator {
public abstract IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData);
}
class SimpleLineSetCreator extends AbstractLineSetCreator {
@Override
public IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData) {
IndexedLineSetFactory ilf = new IndexedLineSetFactory();
if (vData.size() == 0) {
return ilf.getIndexedLineSet();
}
ilf.setVertexCount(vData.size());
ilf.setEdgeCount(vData.size() / 2);
ilf.setVertexCoordinates(vData.toArray(new double[][]{}));
ilf.setEdgeIndices(iData.toArray(new int[][]{}));
ilf.update();
return ilf.getIndexedLineSet();
}
}
class ArrowLineSetCreator extends AbstractLineSetCreator {
public ArrowLineSetCreator() {
}
@Override
public IndexedLineSet createLineSet(List<double[]> vData, List<int[]> iData) {
int numOfVectors = vData.size() / 2;
int numcoords = directed ? 6 * numOfVectors : 4 * numOfVectors;
int numedges = directed ? 2 * numOfVectors : numOfVectors;
double[][] coords = new double[numcoords][];
int[][] edges = new int[numedges][];
double[] radii = new double[numcoords];
Color[] edgecolors = new Color[numedges];
double[] startcoords, targetcoords, vector;
int[] ids;
int startid, targetid;
for (int i = 0; i < numOfVectors; i++) {
ids = iData.get(i);
if (ids.length != 2)
throw new RuntimeException(
"Is not a single edge (= vector)!");
startid = ids[0];
targetid = ids[1];
startcoords = vData.get(startid);
targetcoords = vData.get(targetid);
vector = Rn.subtract(null, targetcoords, startcoords);
coords[i + 0 * numOfVectors] = Rn.subtract(null, startcoords,
Rn.setEuclideanNorm(null, 0.001, vector));
coords[i + 1 * numOfVectors] = startcoords.clone();
coords[i + 2 * numOfVectors] = targetcoords.clone();
radii[i + 0 * numOfVectors] = 0.001;
radii[i + 1 * numOfVectors] = thickness;
radii[i + 2 * numOfVectors] = thickness;
edgecolors[i] = color;
if (directed) {
edges[i] = new int[]{i + 0 * numOfVectors,
i + 1 * numOfVectors, i + 2 * numOfVectors};
coords[i + 3 * numOfVectors] = Rn.subtract(null,
targetcoords, Rn.times(null, 0.001, vector));
radii[i + 3 * numOfVectors] = 0.001;
coords[i + 4 * numOfVectors] = targetcoords.clone();
radii[i + 4 * numOfVectors] = 1.5 * thickness;
coords[i + 5 * numOfVectors] = Rn.add(null, targetcoords,
Rn.times(null, .2, vector));
radii[i + 5 * numOfVectors] = 0.001;
edges[i + numOfVectors] = new int[]{i + 3 * numOfVectors,
i + 4 * numOfVectors, i + 5 * numOfVectors};
edgecolors[i + numOfVectors] = Color.black;
} else {
coords[i + 3 * numOfVectors] = Rn.add(null, targetcoords,
Rn.setEuclideanNorm(null, 0.001, vector));
radii[i + 3 * numOfVectors] = 0.001;
edges[i] = new int[]{i + 0 * numOfVectors,
i + 1 * numOfVectors, i + 2 * numOfVectors,
i + 3 * numOfVectors};
}
}
IndexedLineSetFactory ilsf = new IndexedLineSetFactory();
if (numcoords != 0) {
ilsf.setVertexCount(numcoords);
ilsf.setEdgeCount(numedges);
ilsf.setVertexCoordinates(coords);
ilsf.setVertexRelativeRadii(radii);
ilsf.setEdgeIndices(edges);
ilsf.setEdgeColors(edgecolors);
ilsf.update();
}
return ilsf.getIndexedLineSet();
}
}
} }
......
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