Commit 8d438188 authored by Stefan Sechelmann's avatar Stefan Sechelmann

add dual graph subdivision

parent 02950fc4
package de.jtem.halfedgetools.algorithm.subdivision;
import java.util.Map;
import java.util.TreeMap;
import de.jtem.halfedge.Edge;
import de.jtem.halfedge.Face;
import de.jtem.halfedge.HalfEdgeDataStructure;
import de.jtem.halfedge.Vertex;
import de.jtem.halfedge.util.HalfEdgeUtils;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.Position;
public class DualGraphSubdivision {
public <
V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>,
HDS extends HalfEdgeDataStructure<V, E, F>
> void subdivide(
HDS graph,
HDS r,
AdapterSet a,
Map<F, V> faceVertexMap,
Map<E, E> edgeEdgeMap,
Map<V, F> vertexFaceMap
) {
if (faceVertexMap == null) {
faceVertexMap = new TreeMap<>();
}
if (edgeEdgeMap == null) {
edgeEdgeMap = new TreeMap<>();
}
if (vertexFaceMap == null) {
vertexFaceMap = new TreeMap<>();
}
for (F f : graph.getFaces()) {
V v = r.addNewVertex();
a.set(Position.class, v, a.getD(Position.class, f));
faceVertexMap.put(f, v);
}
for (E e : graph.getEdges()) {
if (HalfEdgeUtils.isBoundaryEdge(e)) { continue; }
E ee = r.addNewEdge();
edgeEdgeMap.put(e, ee);
}
for (V v : graph.getVertices()) {
if (HalfEdgeUtils.isBoundaryVertex(v)) { continue; }
F f = r.addNewFace();
vertexFaceMap.put(v, f);
}
// linkage
for (E e : graph.getEdges()) {
if (HalfEdgeUtils.isBoundaryEdge(e)) continue;
E ee = edgeEdgeMap.get(e);
E eeOpp = edgeEdgeMap.get(e.getOppositeEdge());
ee.linkOppositeEdge(eeOpp);
ee.setTargetVertex(faceVertexMap.get(e.getLeftFace()));
ee.setLeftFace(vertexFaceMap.get(e.getStartVertex()));
E ePrev = e.getPreviousEdge();
while (HalfEdgeUtils.isBoundaryEdge(ePrev)) {
// find next on boundary
ePrev = ePrev.getPreviousEdge();
}
ee.linkNextEdge(edgeEdgeMap.get(ePrev.getOppositeEdge()));
}
}
}
......@@ -63,6 +63,7 @@ import de.jtem.halfedgetools.plugin.algorithm.simplification.GarlandHeckbertPlug
import de.jtem.halfedgetools.plugin.algorithm.subdivision.CatmullClarkLinearPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.CatmullClarkPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.DooSabinPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.DualGraphSubdivisionPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.LoopLinearPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.LoopPlugin;
import de.jtem.halfedgetools.plugin.algorithm.subdivision.MedialGraphLinearPlugin;
......@@ -161,6 +162,7 @@ public class HalfedgePluginFactory {
s.add(new StellarLinearPlugin());
s.add(new TriangulatePlugin());
s.add(new TriangulateCutCornersPlugin());
s.add(new DualGraphSubdivisionPlugin());
return s;
}
......
/**
This file is part of a jTEM project.
All jTEM projects are licensed under the FreeBSD license
or 2-clause BSD license (see http://www.opensource.org/licenses/bsd-license.php).
Copyright (c) 2002-2010, Technische Universität Berlin, jTEM
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
**/
package de.jtem.halfedgetools.plugin.algorithm.subdivision;
import de.jtem.halfedge.Edge;
import de.jtem.halfedge.Face;
import de.jtem.halfedge.HalfEdgeDataStructure;
import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.TypedAdapterSet;
import de.jtem.halfedgetools.algorithm.subdivision.DualGraphSubdivision;
import de.jtem.halfedgetools.plugin.HalfedgeInterface;
import de.jtem.halfedgetools.plugin.algorithm.AlgorithmCategory;
import de.jtem.halfedgetools.plugin.algorithm.AlgorithmPlugin;
import de.jtem.halfedgetools.plugin.image.ImageHook;
import de.jtem.jrworkspace.plugin.PluginInfo;
public class DualGraphSubdivisionPlugin extends AlgorithmPlugin {
private DualGraphSubdivision
subdivider = new DualGraphSubdivision();
@Override
public <
V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>,
HDS extends HalfEdgeDataStructure<V, E, F>
> void execute(HDS hds, AdapterSet a, HalfedgeInterface hcp) {
HDS hds2 = hcp.createEmpty(hds);
TypedAdapterSet<double[]> da = a.querySet(double[].class);
subdivider.subdivide(hds, hds2, da, null, null, null);
hcp.set(hds2);
}
@Override
public AlgorithmCategory getAlgorithmCategory() {
return AlgorithmCategory.Subdivision;
}
@Override
public String getAlgorithmName() {
return "Dual Graph";
}
@Override
public PluginInfo getPluginInfo() {
PluginInfo info = new PluginInfo("Dual Graph Subdivision", "Stefan Sechelmann");
info.icon = ImageHook.getIcon("stellar.png", 16, 16);
return info;
}
}
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