removed update neighbors

This commit is contained in:
zzzzrrr 2009-08-06 12:15:04 -04:00
parent a04b382f7d
commit 97ead85d3b
2 changed files with 30 additions and 62 deletions

View File

@ -76,6 +76,17 @@ class AFront(iTriangle: Triangle) {
node.triangle = triangle node.triangle = triangle
} }
def basin(node: Node) {
if(node.next != tail) {
val p1 = node.point
val p2 = node.next.point
val slope = (p1.y - p2.y) / (p1.x - p2.x)
if(slope < Math.Pi*3/4)
println("basin slope = " + slope)
}
}
} }
// Advancing front node // Advancing front node

View File

@ -116,6 +116,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
private val aFront = new AFront(iTriangle) private val aFront = new AFront(iTriangle)
private val PI_2 = Math.Pi/2 private val PI_2 = Math.Pi/2
private val PI_34 = Math.Pi*3/4
// Sweep points; build mesh // Sweep points; build mesh
sweep sweep
@ -153,35 +154,17 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
mesh.map += lTriangle mesh.map += lTriangle
mesh.map += rTriangle mesh.map += rTriangle
// Legalize new triangles // No need for legalization here
val rLegal = legalization(rTriangle, rTriangle.neighbors(0))
val lLegal = legalization(lTriangle, lTriangle.neighbors(0))
var scanNode: Node = null
// Update advancing front // Update advancing front
if(rLegal) { val newNode = aFront.insert(point, rTriangle, node)
// Update neighbors node.prev.next = newNode
node.triangle.updateNeighbors(rTriangle.points(1), rTriangle.points(2), rTriangle, mesh.debug) newNode.prev = node.prev
scanNode = aFront.insert(point, rTriangle, node) node.prev.triangle = lTriangle
} else {
scanNode = new Node(rTriangle.points(1), rTriangle)
scanNode.next = node.next
node.next = scanNode
scanNode.prev = node
}
// Update neighbor pointers
if(lLegal) {
lTriangle.neighbors(0).updateNeighbors(lTriangle.points(1), lTriangle.points(2), lTriangle, mesh.debug)
node.prev.next = scanNode
scanNode.prev = node.prev
node.prev.triangle = lTriangle
} else {
}
// Fill in adjacent triangles if required // Fill in adjacent triangles if required
scanAFront(scanNode) scanAFront(newNode)
scanNode.triangle newNode.triangle
} else { } else {
@ -197,25 +180,23 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Legalize // Legalize
val legal = legalization(triangle, nTri) val legal = legalization(triangle, nTri)
var scanNode: Node = null var newNode: Node = null
// Update advancing front // Update advancing front
if(legal) { if(legal) {
// Update neighbors newNode = aFront.insert(point, triangle, node)
nTri.updateNeighbors(triangle.points(1), triangle.points(2), triangle, mesh.debug)
scanNode = aFront.insert(point, triangle, node)
} else { } else {
scanNode = new Node(triangle.points(1), triangle) newNode = new Node(triangle.points(1), triangle)
val rNode = node.next val rNode = node.next
rNode.prev = scanNode rNode.prev = newNode
scanNode.next = rNode newNode.next = rNode
node.next = scanNode node.next = newNode
scanNode.prev = node newNode.prev = node
} }
// Fill in adjacent triangles if required // Fill in adjacent triangles if required
scanAFront(scanNode) scanAFront(newNode)
scanNode.triangle newNode.triangle
} }
} }
@ -236,7 +217,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
triangles += triangles.last.findNeighbor(edge.p - edge.q) triangles += triangles.last.findNeighbor(edge.p - edge.q)
// TODO: fix triangles.last == null bug! // TODO: fix triangles.last == null bug!
// This happens in the bird & nazca monkey demo... // Not sure why this happens in bird & nazca monkey demo...
if(triangles.last == null) if(triangles.last == null)
triangles -= triangles.last triangles -= triangles.last
@ -334,8 +315,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
if(!P.isEmpty) { if(!P.isEmpty) {
val points = Array(a, P.first, b) val points = Array(a, P.first, b)
// TODO: Correctly update neighbor pointers?
// Not updating seems to work with simple polygons...
val neighbors = new Array[Triangle](3) val neighbors = new Array[Triangle](3)
T += new Triangle(points, neighbors) T += new Triangle(points, neighbors)
mesh.map += T.last mesh.map += T.last
@ -368,7 +347,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Fill empty space with a triangle // Fill empty space with a triangle
def fill(node: Node): Double = { def fill(node: Node): Double = {
val a = (node.prev.point - node.point) val a = (node.prev.point - node.point)
val b = (node.next.point - node.point) val b = (node.next.point - node.point)
val angle = Math.abs(Math.atan2(a cross b, a dot b)) val angle = Math.abs(Math.atan2(a cross b, a dot b))
@ -376,9 +354,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val points = Array(node.prev.point, node.point, node.next.point) val points = Array(node.prev.point, node.point, node.next.point)
val neighbors = Array(node.triangle, null, node.prev.triangle) val neighbors = Array(node.triangle, null, node.prev.triangle)
val triangle = new Triangle(points, neighbors) val triangle = new Triangle(points, neighbors)
// Update neighbor pointers
node.prev.triangle.updateNeighbors(triangle.points(0), triangle.points(1), triangle, mesh.debug)
node.triangle.updateNeighbors(triangle.points(1), triangle.points(2), triangle, mesh.debug)
mesh.map += triangle mesh.map += triangle
aFront -= (node.prev, node, triangle) aFront -= (node.prev, node, triangle)
} }
@ -406,7 +381,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val sinB = v3 cross v4 val sinB = v3 cross v4
// Some small number // Some small number
if(cosA*sinB + sinA*cosB < -0.01f) if(cosA*sinB + sinA*cosB < -0.0001f)
true true
else else
false false
@ -423,24 +398,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val point = t1.points(0) val point = t1.points(0)
t1.legalize(oPoint) t1.legalize(oPoint)
t2.legalize(oPoint, point) t2.legalize(oPoint, point)
// TODO: Make sure this is correct
val cwNeighbor = t2.neighborCW(oPoint)
val ccwNeighbor = t2.neighborCCW(oPoint)
t1.neighbors(0) = t2
t1.neighbors(1) = cwNeighbor
t1.neighbors(2) = null
if(t2.points(0) == oPoint) {
t2.neighbors(0) = null
t2.neighbors(1) = ccwNeighbor
t2.neighbors(2) = t1
} else {
t2.neighbors(0) = ccwNeighbor
t2.neighbors(1) = t1
t2.neighbors(2) = null
}
false false
} else { } else {
true true