Commit 3fa7cd11 authored by Thilo Rörig's avatar Thilo Rörig

Refactoring VectorFieldVisualizer

Added another level of abstraction to reuse parts of
VectorFieldVisualizer in the PointCloudVisualizer
parent 6b6021af
......@@ -59,6 +59,7 @@ public abstract class AbstractDataVisualization implements DataVisualization, Co
public boolean isActive() {
return active;
}
@Override
public void setActive(boolean active) {
this.active = active;
......
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.scene.Appearance;
import de.jreality.scene.SceneGraphComponent;
import de.jtem.halfedgetools.adapter.Adapter;
import de.jtem.halfedgetools.plugin.HalfedgeLayer;
import de.jtem.halfedgetools.plugin.data.AbstractDataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualizer;
import java.util.List;
import static de.jreality.shader.CommonAttributes.*;
public abstract class AbstractSceneGraphComponentVisualization extends AbstractDataVisualization {
protected SceneGraphComponent sceneGraphComponent = new SceneGraphComponent();
protected Appearance appearance = new Appearance(
"Vector Field Appearance");
public AbstractSceneGraphComponentVisualization(HalfedgeLayer layer, Adapter<?> source, DataVisualizer visualizer, DataVisualizer.NodeType type) {
super(layer, source, visualizer, type);
}
void initAppearance() {
appearance.setAttribute(LINE_SHADER + "." + DEPTH_FUDGE_FACTOR,
0.88888);
appearance.setAttribute(EDGE_DRAW, true);
appearance.setAttribute(VERTEX_DRAW, false);
appearance.setAttribute(LINE_SHADER + "." + TUBES_DRAW, false);
appearance.setAttribute(LINE_SHADER + "." + LINE_WIDTH, 1.0);
appearance.setAttribute(LINE_SHADER + "." + TUBE_RADIUS, 0.1);
appearance.setAttribute(LINE_SHADER + "." + PICKABLE, false);
appearance.setAttribute(DEPTH_FUDGE_FACTOR, 0.9999);
appearance.setAttribute(LINE_SHADER + "." + POLYGON_SHADER
+ "." + SMOOTH_SHADING, true);
appearance.setAttribute(POLYGON_SHADER + "." + SMOOTH_SHADING,
true);
}
@Override
public final void update() {
sceneGraphComponent.setVisible(isActive());
if (!isActive()) {
return;
}
clearSceneGraphComponent();
updateSceneGraphComponent();
updateAppearance();
HalfedgeLayer layer = getLayer();
layer.removeTemporaryGeometry(sceneGraphComponent);
layer.addTemporaryGeometry(sceneGraphComponent);
}
public abstract void updateAppearance();
public abstract void updateSceneGraphComponent();
void clearSceneGraphComponent() {
sceneGraphComponent.setGeometry(null);
List<SceneGraphComponent> sgc = sceneGraphComponent.getChildComponents();
int n = sgc.size();
for (int i = 0; i < n; i++) {
sceneGraphComponent.removeChild(sgc.get(0));
}
}
}
......@@ -14,6 +14,7 @@ import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
......@@ -169,23 +170,23 @@ public class NodeColorVisualizer extends DataVisualizerPlugin implements ActionL
a.addAll(hif.getActiveVolatileAdapters());
switch (getType()) {
case Vertex:
List<? extends Vertex<?,?,?>> vList = getColoredNodes(hds.getVertices(), a, minmax);
List<?> vList = getColoredNodes(hds.getVertices(), a, minmax);
a.add(new ColorAdapter(minmax[0], minmax[1]));
PointSet ps = createVertices(vList, a, true);
PointSet ps = createVertices((List<Vertex<?,?,?>>)vList, a, true);
ps.setName("Vertex Colors Geometry");
geomComponent.setGeometry(ps);
break;
case Edge:
List<? extends Edge<?,?,?>> eList = getColoredNodes(hds.getEdges(), a, minmax);
List<?> eList = getColoredNodes(hds.getEdges(), a, minmax);
a.add(new ColorAdapter(minmax[0], minmax[1]));
IndexedLineSet ils = createEdges(eList, a, true);
IndexedLineSet ils = createEdges((List<Edge<?,?,?>>)eList, a, true);
ils.setName("Edge Colors Geometry");
geomComponent.setGeometry(ils);
break;
case Face:
List<? extends Face<?,?,?>> fList = getColoredNodes(hds.getFaces(), a, minmax);
List<?> fList = getColoredNodes(hds.getFaces(), a, minmax);
a.add(new ColorAdapter(minmax[0], minmax[1]));
IndexedFaceSet ifs = createOffsetFaces(fList, a, offset, true);
IndexedFaceSet ifs = createOffsetFaces((List<? extends Face<?, ?, ?>>)fList, a, offset, true);
ifs.setName("Face Colors Geometry");
geomComponent.setGeometry(ifs);
break;
......
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jtem.halfedgetools.adapter.Adapter;
import de.jtem.halfedgetools.plugin.HalfedgeLayer;
import de.jtem.halfedgetools.plugin.data.DataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualizerPlugin;
public class PointSetVisualizer extends DataVisualizerPlugin {
@Override
public boolean canRead(Adapter<?> a, NodeType type) {
boolean accept = false;
accept |= a.checkType(double[][].class);
accept |= a.checkType(double[].class);
return accept;
}
@Override
public DataVisualization createVisualization(HalfedgeLayer layer, NodeType type, Adapter<?> source) {
PointSetVisualization vis = new PointSetVisualization(layer, source, this, type);
return null;
}
public class PointSetVisualization extends AbstractSceneGraphComponentVisualization {
public PointSetVisualization(HalfedgeLayer layer, Adapter<?> source, PointSetVisualizer pointSetVisualizer, NodeType type) {
super(layer, source, pointSetVisualizer, type);
sceneGraphComponent.setName("Points");
initAppearance();
}
@Override
public void updateAppearance() {
}
@Override
public void updateSceneGraphComponent() {
}
}
}
......@@ -78,7 +78,6 @@ public class LayerComponent extends SceneComponent {
updateSelection();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public synchronized void updateGeometry() {
vertexComponent.getPoints().clear();
vertexComponent.getAnnotations().clear();
......@@ -91,9 +90,9 @@ public class LayerComponent extends SceneComponent {
AdapterSet a = layer.getEffectiveAdapters();
// faces
for (Face f : new LinkedList<Face>(hds.getFaces())) {
for(Face f : new LinkedList<>(hds.getFaces())) {
if (!f.isValid()) continue;
Shape faceShape = getFaceShape(a, f);
Shape faceShape = this.<Vertex, Edge, Face>getFaceShape(a, f);
faces.append(faceShape, false);
double[] p = a.getDefault(TextureBaryCenter2d.class, f, defaultCoord);
Annotation indexAnnotation = new Annotation("" + f.getIndex(), p[0], p[1], Annotation.CENTER);
......@@ -120,7 +119,6 @@ public class LayerComponent extends SceneComponent {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public synchronized void updateSelection() {
if (layer == null) return;
SelectionInterface sif = layer.getHalfedgeInterface().getSelectionInterface();
......@@ -172,7 +170,7 @@ public class LayerComponent extends SceneComponent {
}
for (Face f : s.getFaces()) {
if (!f.isValid()) return;
Shape faceShape = getFaceShape(a, f);
Shape faceShape = this.<Vertex, Edge, Face>getFaceShape(a, f);
Integer channel = s.getChannel(f);
SceneComponent fComp = fMap.get(channel);
if (!fMap.containsKey(channel)) {
......@@ -198,12 +196,13 @@ public class LayerComponent extends SceneComponent {
return new Line2D.Float((float)s[0], (float)s[1], (float)t[0], (float)t[1]);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private Shape getFaceShape(AdapterSet a, Face f) {
private <V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>
> Shape getFaceShape(AdapterSet a, F f) {
Path2D p = new Path2D.Float();
boolean start = true;
for (Object ov : HalfEdgeUtils.boundaryVertices(f)) {
Vertex<?, ?, ?> v = (Vertex<?, ?, ?>)ov;
for (V v : HalfEdgeUtils.boundaryVertices(f)) {
double[] t = a.getDefault(TexturePosition2d.class, v, defaultCoord);
if (start) {
p.moveTo(t[0], t[1]);
......
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