fixed triangulation bug

This commit is contained in:
Mason 2009-08-15 11:39:29 -04:00
parent 00b91269b1
commit cd7d09ee8a
3 changed files with 21 additions and 16 deletions

View File

@ -87,7 +87,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
val i18 = "data/i.18" val i18 = "data/i.18"
val tank = "data/tank.dat" val tank = "data/tank.dat"
var currentModel = strange var currentModel = nazcaMonkey
var doCDT = true var doCDT = true
var mouseButton = 0 var mouseButton = 0

View File

@ -251,20 +251,20 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val point1 = if(ahead) edge.q else edge.p val point1 = if(ahead) edge.q else edge.p
val point2 = if(ahead) edge.p else edge.q val point2 = if(ahead) edge.p else edge.q
var node = aFront.locatePoint(point1) var pNode = aFront.locatePoint(point1)
val first = node val first = pNode
val points = new ArrayBuffer[Point] val points = new ArrayBuffer[Point]
// Neighbor triangles // Neighbor triangles
val nTriangles = new ArrayBuffer[Triangle] val nTriangles = new ArrayBuffer[Triangle]
nTriangles += node.triangle nTriangles += pNode.triangle
node = node.next pNode = pNode.next
while(node.point != point2) { while(pNode.point != point2) {
points += node.point points += pNode.point
nTriangles += node.triangle nTriangles += pNode.triangle
node = node.next pNode = pNode.next
} }
// Triangulate empty areas. // Triangulate empty areas.
@ -283,7 +283,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} }
// Update advancing front // Update advancing front
aFront link (first, node, edgeTri) aFront link (first, pNode, edgeTri)
// Update neighbors // Update neighbors
edgeNeighbors(nTriangles, T) edgeNeighbors(nTriangles, T)
@ -294,6 +294,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} else if(firstTriangle.contains(edge.q, edge.p)) { } else if(firstTriangle.contains(edge.q, edge.p)) {
// Mark constrained edge // Mark constrained edge
firstTriangle markEdge(edge.q, edge.p) firstTriangle markEdge(edge.q, edge.p)
firstTriangle.finalized = true
} else { } else {
throw new Exception("Triangulation error") throw new Exception("Triangulation error")
//null //null
@ -326,7 +327,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
if(P.size > 1) { if(P.size > 1) {
var c = P.first var c = P.first
for(j <- 1 until P.size) { for(j <- 1 until P.size) {
if(illegal(a, P(j), b, c)) { if(illegal(a, c, b, P(j))) {
c = P(j) c = P(j)
i = j i = j
} }
@ -445,6 +446,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} }
t2.markNeighbor(t1) t2.markNeighbor(t1)
// Don't legalize these triangles again
t2.finalized = true
t1.finalized = true
// Update advancing front // Update advancing front
aFront.insertLegalized(t1.points(1), t1, node) aFront.insertLegalized(t1.points(1), t1, node)

View File

@ -126,7 +126,7 @@ class Triangle(val points: Array[Point]) {
// Locate first triangle crossed by constrained edge // Locate first triangle crossed by constrained edge
def locateFirst(edge: Segment): Triangle = { def locateFirst(edge: Segment): Triangle = {
if(contains(edge)) this
if(edge.q == points(0)) if(edge.q == points(0))
search(points(1), points(2), edge, neighbors(2)) search(points(1), points(2), edge, neighbors(2))
else if(edge.q == points(1)) else if(edge.q == points(1))