Commit f79c3e93 authored by Stefan Sechelmann's avatar Stefan Sechelmann

node index optimization using lazy updates

git-svn-id: https://svn.math.tu-berlin.de/svn/jtem@1689 f5b180c5-49ee-4939-b20e-b6ed35f0f7b7
parent 531bdac2
......@@ -47,7 +47,7 @@
</target>
<target name="javadoc" description="generate javadoc in docs/api">
<javadoc destdir="${javadoc_dir}" access="public" author="true" version="true" use="true" useexternalfile="true" windowtitle="halfedge API" source="1.6">
<javadoc destdir="${javadoc_dir}" encoding="UTF-8" access="public" author="true" version="true" use="true" useexternalfile="true" windowtitle="halfedge API" source="1.6">
<fileset dir="${src}" defaultexcludes="yes">
<include name="de/jtem/**/*.java" />
</fileset>
......
......@@ -31,6 +31,7 @@ OF SUCH DAMAGE.
package de.jtem.halfedge;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Test;
......@@ -39,15 +40,16 @@ import de.jtem.halfedge.util.HalfEdgeUtils;
public class TestHalfEdgeDataStructure extends TestCase {
public static class MyHDS extends HalfEdgeDataStructure<MyVertex,MyEdge,MyFace> {
public MyHDS() {
super(MyVertex.class, MyEdge.class, MyFace.class);
}
}
public static class MyVertex extends Vertex<MyVertex,MyEdge,MyFace> {}
public static class MyEdge extends Edge<MyVertex,MyEdge,MyFace> {}
public static class MyFace extends Face<MyVertex,MyEdge,MyFace> {}
// @Test
// public void testHalfEdgeDataStructure() {
// fail("Not yet implemented");
// }
@Test
public void testCreateCombinatoriallyEquivalentCopy() {
HalfEdgeDataStructure<Vertex.Naked, Edge.Naked, Face.Naked>
......@@ -62,129 +64,70 @@ public class TestHalfEdgeDataStructure extends TestCase {
}
}
// @Test
// public void testGetEdgeClass() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetFaceClass() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetVertexClass() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewVertex() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewVertices() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewEdge() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewEdges() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewFace() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testAddNewFaces() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testRemoveFace() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testRemoveEdge() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testRemoveVertex() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetVertex() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetEdge() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetFace() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testNumFaces() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testNumEdges() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testNumVertices() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetFaces() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetVertices() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetEdges() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetPositiveEdges() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testGetNegativeEdges() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testToString() {
// fail("Not yet implemented");
// }
//
// @Test
// public void testIsValidSurface() {
// fail("Not yet implemented");
// }
@Test
public void testReindexingVerticesGetIndex() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewVertices(10);
MyVertex v6 = hds.getVertex(6);
hds.removeVertex(hds.getVertex(5));
Assert.assertEquals(6, v6.index);
Assert.assertEquals(5, v6.getIndex());
}
@Test
public void testReindexingEdgesGetIndex() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewEdges(10);
MyEdge e6 = hds.getEdge(6);
hds.removeEdge(hds.getEdge(5));
Assert.assertEquals(6, e6.index);
Assert.assertEquals(5, e6.getIndex());
}
@Test
public void testReindexingFacesGetIndex() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewFaces(10);
MyFace f6 = hds.getFace(6);
hds.removeFace(hds.getFace(5));
Assert.assertEquals(6, f6.index);
Assert.assertEquals(5, f6.getIndex());
}
@Test
public void testReindexingVerticesGetVertex() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewVertices(10);
MyVertex v6 = hds.getVertex(6);
hds.removeVertex(hds.getVertex(5));
Assert.assertNotSame(hds.vertexList.get(6), v6);
Assert.assertSame(hds.vertexList.get(5), v6);
Assert.assertEquals(6, v6.index);
Assert.assertEquals(5, hds.getVertex(5).index);
}
@Test
public void testReindexingEdgesGetEdge() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewEdges(10);
MyEdge e6 = hds.getEdge(6);
hds.removeEdge(hds.getEdge(5));
Assert.assertNotSame(hds.edgeList.get(6), e6);
Assert.assertSame(hds.edgeList.get(5), e6);
Assert.assertEquals(6, e6.index);
Assert.assertEquals(5, hds.getEdge(5).index);
}
@Test
public void testReindexingFacesGetFace() throws Exception {
MyHDS hds = new MyHDS();
hds.addNewFaces(10);
MyFace f6 = hds.getFace(6);
hds.removeFace(hds.getFace(5));
Assert.assertNotSame(hds.faceList.get(6), f6);
Assert.assertSame(hds.faceList.get(5), f6);
Assert.assertEquals(6, f6.index);
Assert.assertEquals(5, hds.getFace(5).index);
}
}
......@@ -66,13 +66,17 @@ abstract public class Edge <V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>> extends Node<V, E, F> {
private E nextEdge = null;
private E previousEdge = null;
private E oppositeEdge = null;
private V targetVertex = null;
private F leftFace = null;
private boolean isPositive = false;
private E self = null;
E
self = null,
nextEdge = null,
previousEdge = null,
oppositeEdge = null;
V
targetVertex = null;
F
leftFace = null;
boolean
isPositive = false;
public static class Naked extends Edge<Vertex.Naked, Edge.Naked, Face.Naked> {};
......@@ -83,7 +87,6 @@ abstract public class Edge <V extends Vertex<V, E, F>,
this.self = self;
}
/**
* Returns the face on the left of this edge. May return <code>null</code>.
* @return the left Face.
......@@ -299,10 +302,9 @@ abstract public class Edge <V extends Vertex<V, E, F>,
/**
* Copies the data fields of the given edge into this edge
* @param v
* @param e
*/
public void copyData(E e) {
}
}
......@@ -48,17 +48,24 @@ import de.jtem.halfedge.util.HalfEdgeUtils;
* @param <F> the face class of this half-edge data structure
* @param <V> the vertex class of this half-edge data structure
*/
public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F> > {
public class HalfEdgeDataStructure <
V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>
> {
private Class<V> vClass = null;
private Class<E> eClass = null;
private Class<F> fClass = null;
Class<V> vClass = null;
Class<E> eClass = null;
Class<F> fClass = null;
private List<V> vertexList = new ArrayList<V>();
private List<F> faceList = new ArrayList<F>();
private List<E> edgeList = new ArrayList<E>();
List<V> vertexList = new ArrayList<V>();
List<F> faceList = new ArrayList<F>();
List<E> edgeList = new ArrayList<E>();
boolean
vertexIndicesDirty = false,
edgeIndicesDirty = false,
faceIndicesDirty = false;
/**
* Instantiate a new half-edge data structure with given
......@@ -90,8 +97,11 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
* @param fC the face class, used as runtime type token
* @return a combinatorially equivalent copy
*/
public final <VV extends Vertex<VV,EE,FF>, EE extends Edge<VV,EE,FF>, FF extends Face<VV,EE,FF>>
HalfEdgeDataStructure<VV,EE,FF> createCombinatoriallyEquivalentCopy(Class<VV> vC, Class<EE> eC, Class<FF> fC) {
public final <
VV extends Vertex<VV,EE,FF>,
EE extends Edge<VV,EE,FF>,
FF extends Face<VV,EE,FF>
> HalfEdgeDataStructure<VV,EE,FF> createCombinatoriallyEquivalentCopy(Class<VV> vC, Class<EE> eC, Class<FF> fC) {
return createCombinatoriallyEquivalentCopy(new HalfEdgeDataStructure<VV,EE,FF>(vC, eC, fC));
}
......@@ -103,11 +113,12 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
* @param heds The half-edge data structure to fill.
* @return heds
*/
public final <VV extends Vertex<VV,EE,FF>,
EE extends Edge<VV,EE,FF>,
FF extends Face<VV,EE,FF>,
HEDS extends HalfEdgeDataStructure<VV,EE,FF>>
HEDS createCombinatoriallyEquivalentCopy(HEDS heds) {
public final <
VV extends Vertex<VV,EE,FF>,
EE extends Edge<VV,EE,FF>,
FF extends Face<VV,EE,FF>,
HEDS extends HalfEdgeDataStructure<VV,EE,FF>
> HEDS createCombinatoriallyEquivalentCopy(HEDS heds) {
heds.vertexList.clear();
heds.edgeList.clear();
heds.faceList.clear();
......@@ -285,7 +296,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
if (faceList.remove(face)) {
face.setBoundaryEdge(null);
face.setHalfEdgeDataStructure(null);
reindexFaces(face.index);
faceIndicesDirty = true;
return;
}
assert false;
......@@ -319,7 +330,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
edge.linkNextEdge(null);
edge.linkPreviousEdge(null);
edge.setHalfEdgeDataStructure(null);
reindexEdges(edge.index);
edgeIndicesDirty = true;
return;
}
assert false;
......@@ -350,7 +361,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
if (vertexList.remove(vertex)){
vertex.setIncomingEdge(null);
vertex.setHalfEdgeDataStructure(null);
reindexVertices(vertex.index);
vertexIndicesDirty = true;
return;
}
assert false;
......@@ -364,6 +375,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
* @throws IndexOutOfBoundsException if the index is out of range
*/
public final V getVertex(int index) throws IndexOutOfBoundsException {
if (vertexIndicesDirty) reindexVertices(0);
return getNode(vertexList, index);
}
......@@ -373,6 +385,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
* @return the edge
*/
public final E getEdge(int index){
if (edgeIndicesDirty) reindexEdges(0);
return getNode(edgeList, index);
}
......@@ -382,6 +395,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
* @return the face
*/
public final F getFace(int index){
if (faceIndicesDirty) reindexFaces(0);
return getNode(faceList, index);
}
......@@ -397,6 +411,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
while (it.hasNext()) {
it.next().setIndex(start++);
}
vertexIndicesDirty = false;
}
void reindexEdges(int start) {
......@@ -404,6 +419,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
while (it.hasNext()) {
it.next().setIndex(start++);
}
edgeIndicesDirty = false;
}
void reindexFaces(int start) {
......@@ -411,6 +427,7 @@ public class HalfEdgeDataStructure <V extends Vertex<V, E, F>,
while (it.hasNext()) {
it.next().setIndex(start++);
}
faceIndicesDirty = false;
}
......
......@@ -53,6 +53,15 @@ abstract public class Node <
public final int getIndex() {
if (this instanceof Vertex && hds != null && hds.vertexIndicesDirty) {
hds.reindexVertices(0);
} else
if (this instanceof Edge && hds != null && hds.edgeIndicesDirty) {
hds.reindexEdges(0);
} else
if (this instanceof Face && hds != null && hds.faceIndicesDirty) {
hds.reindexFaces(0);
}
return index;
}
......
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