fixed AFront issue

This commit is contained in:
zzzzrrr 2009-08-09 01:53:58 -04:00
parent 6757b713a0
commit 8428c47904
4 changed files with 49 additions and 46 deletions

View File

@ -85,7 +85,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
val strange = "data/strange.dat" val strange = "data/strange.dat"
val i18 = "data/i.18" val i18 = "data/i.18"
var currentModel = i18 var currentModel = strange
var mouseButton = 0 var mouseButton = 0
var mousePressed = false var mousePressed = false

View File

@ -56,6 +56,17 @@ class AFront(iTriangle: Triangle) {
null null
} }
// Locate node containing given point
def locatePoint(point: Point): Node = {
var node = head
while(node != tail) {
if(point == node.point)
return node
node = node.next
}
null
}
def insert(tuple: Tuple3[Point, Triangle, Node]) = { def insert(tuple: Tuple3[Point, Triangle, Node]) = {
val (point, triangle, nNode) = tuple val (point, triangle, nNode) = tuple
val node = new Node(point, triangle) val node = new Node(point, triangle)

View File

@ -132,16 +132,11 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
for(i <- 1 until points.size) { for(i <- 1 until points.size) {
val point = points(i) val point = points(i)
// Process Point event // Process Point event
var triangle: Triangle = null var triangle = pointEvent(point)
try {
triangle = pointEvent(point)
} catch {
case e: Exception =>
println("Offending triangle = " + i)
}
// Process edge events // Process edge events
point.edges.foreach(e => edgeEvent(e, triangle)) point.edges.foreach(e => triangle = edgeEvent(e, triangle))
if(i == 7) {cleanTri = triangle; mesh.debug += cleanTri} if(i == 7) {cleanTri = triangle; mesh.debug += cleanTri}
// strange = 13; star & i18 = 7
} }
} }
@ -226,16 +221,14 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} }
// EdgeEvent // EdgeEvent
private def edgeEvent(edge: Segment, triangle: Triangle) { private def edgeEvent(edge: Segment, triangle: Triangle): Triangle = {
// STEP 1: Locate the first intersected triangle // STEP 1: Locate the first intersected triangle
val firstTriangle = triangle.locateFirst(edge) val firstTriangle = triangle.locateFirst(edge)
val contains = if(firstTriangle != null) firstTriangle.contains(edge) else false
// STEP 2: Remove intersected triangles // STEP 2: Remove intersected triangles
if(firstTriangle != null && !contains) { if(firstTriangle != null && !firstTriangle.contains(edge)) {
// Collect intersected triangles // Collect intersected triangles
val tList = new ArrayBuffer[Triangle] val tList = new ArrayBuffer[Triangle]
tList += firstTriangle tList += firstTriangle
@ -252,9 +245,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Remove old triangles; collect neighbor triangles // Remove old triangles; collect neighbor triangles
tList.foreach(t => { tList.foreach(t => {
t.neighbors.foreach(n => if(n != null) nTriangles += n) t.neighbors.foreach(n => if(n != null && !tList.contains(n)) nTriangles += n)
mesh.map -= t mesh.map -= t
//mesh.debug += t
}) })
val lPoints = new ArrayBuffer[Point] val lPoints = new ArrayBuffer[Point]
@ -268,7 +260,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
tList.foreach(t => { tList.foreach(t => {
t.points.foreach(p => { t.points.foreach(p => {
if(p != edge.q && p != edge.p) { if(p != edge.q && p != edge.p) {
if(t.orient(point1, point2, p) >= 0 ) { if(t.orient(point1, point2, p) > 0 ) {
// Keep duplicate points out // Keep duplicate points out
if(!lPoints.contains(p)) { if(!lPoints.contains(p)) {
lPoints += p lPoints += p
@ -290,56 +282,50 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Update advancing front // Update advancing front
val qNode = aFront.locate(edge.q) val qNode = aFront.locatePoint(edge.q)
val pNode = aFront.locate(edge.p) val pNode = aFront.locatePoint(edge.p)
println(tList.size)
for(t <- tList) { for(t <- tList) {
if(qNode.triangle == t) { if(qNode.triangle == t) {
println("node")
val p1 = qNode.point val p1 = qNode.point
val p2 = qNode.next.point val p2 = qNode.next.point
T1.foreach(tri => if(tri.contains(p1, p2)) qNode.triangle = tri) T1.foreach(tri => if(tri.contains(p1, p2)) qNode.triangle = tri)
T2.foreach(tri => if(tri.contains(p1, p2)) qNode.triangle = tri) T2.foreach(tri => if(tri.contains(p1, p2)) qNode.triangle = tri)
} else if(qNode.prev.triangle == t) { } else if(qNode.prev.triangle == t) {
println("prev node")
val p1 = qNode.prev.point val p1 = qNode.prev.point
val p2 = qNode.point val p2 = qNode.point
T1.foreach(tri => if(tri.contains(p1, p2)) qNode.prev.triangle = tri) T1.foreach(tri => if(tri.contains(p1, p2)) qNode.prev.triangle = tri)
T2.foreach(tri => if(tri.contains(p1, p2)) qNode.prev.triangle = tri) T2.foreach(tri => if(tri.contains(p1, p2)) qNode.prev.triangle = tri)
} else if(qNode.next.triangle == t) { }
println("next node")
} else
if(pNode.triangle == t) { if(pNode != null) {
println("Pnode") if(pNode.triangle == t) {
val p1 = pNode.point val p1 = pNode.point
val p2 = pNode.next.point val p2 = pNode.next.point
T1.foreach(tri => if(tri.contains(p1, p2)) pNode.triangle = tri) T1.foreach(tri => if(tri.contains(p1, p2)) pNode.triangle = tri)
T2.foreach(tri => if(tri.contains(p1, p2)) pNode.triangle = tri) T2.foreach(tri => if(tri.contains(p1, p2)) pNode.triangle = tri)
} else if(pNode.prev.triangle == t) { } else if(pNode.prev.triangle == t) {
println("prev Pnode") val p1 = pNode.point
val p1 = pNode.point val p2 = pNode.prev.point
val p2 = pNode.prev.point T1.foreach(tri => if(tri.contains(p1, p2)) pNode.prev.triangle = tri)
T1.foreach(tri => if(tri.contains(p1, p2)) pNode.prev.triangle = tri) T2.foreach(tri => if(tri.contains(p1, p2)) pNode.prev.triangle = tri)
T2.foreach(tri => if(tri.contains(p1, p2)) pNode.prev.triangle = tri) }
} else if(pNode.next.triangle == t) {
println("next Pnode")
} }
} }
// Update neighbors // Update neighbors
//updateNeighbors(nTriangles, T1) updateNeighbors(nTriangles, T1)
updateNeighbors(nTriangles, T2) updateNeighbors(nTriangles, T2)
//nTriangles.foreach(n => n.printDebug)
// Mark constrained edges // Mark constrained edges
T1.first.mark(point1, point2) T1.first.mark(point1, point2)
T2.first.mark(point1, point2) T2.first.mark(point1, point2)
//TODO update neighbor pointers
// Double check returning T2.first vs T1.first
T2.first
} else if(firstTriangle == null) { } else if(firstTriangle == null) {
// No triangles are intersected by the edge; edge must lie outside the mesh // No triangles are intersected by the edge; edge must lie outside the mesh
@ -354,8 +340,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val nTriangles = new ArrayBuffer[Triangle] val nTriangles = new ArrayBuffer[Triangle]
var node = aFront.locate(point1) var node = aFront.locate(point1)
val first = node val first = node
nTriangles += first.triangle nTriangles += node.triangle
node = node.next node = node.next
@ -372,6 +359,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
triangulate(points.toArray, endPoints, T) triangulate(points.toArray, endPoints, T)
// Update advancing front // Update advancing front
aFront -= (first, node.prev, T.first) aFront -= (first, node.prev, T.first)
// Update neighbors // Update neighbors
@ -379,11 +367,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Mark constrained edge // Mark constrained edge
T.first mark(edge.p, edge.q) T.first mark(edge.p, edge.q)
triangle
} else { } else {
// Mark constrained edge // Mark constrained edge
firstTriangle mark(edge.p, edge.q) firstTriangle mark(edge.p, edge.q)
triangle
} }
} }
// Update neigbor pointers for edge event // Update neigbor pointers for edge event

View File

@ -62,7 +62,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
} }
// Update neighbor pointers // Update neighbor pointers
def markNeighbor(p1: Point, p2: Point, triangle: Triangle) { def markNeighbor(p1: Point, p2: Point, triangle: Triangle) {
if((p1 == points(2) && p2 == points(1)) || (p1 == points(1) && p2 == points(2))) if((p1 == points(2) && p2 == points(1)) || (p1 == points(1) && p2 == points(2)))
neighbors(0) = triangle neighbors(0) = triangle
else if((p1 == points(0) && p2 == points(2)) || (p1 == points(2) && p2 == points(0))) else if((p1 == points(0) && p2 == points(2)) || (p1 == points(2) && p2 == points(0)))