updated code

This commit is contained in:
Mason 2009-08-09 22:00:32 -04:00
parent 328d8e4962
commit c03ee9e0ff
2 changed files with 39 additions and 35 deletions

View File

@ -76,7 +76,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
var hiLighter = 0
var drawEarClip = false
var drawCDT = true
var drawcdtMesh = true
var drawcdtMesh = false
val nazcaMonkey = "data/nazca_monkey.dat"
val bird = "data/bird.dat"
@ -109,10 +109,12 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
def render(container: GameContainer, g: Graphics) {
g.drawString("'1-6' to cycle models", 10, 540)
g.drawString("'SPACE' to turn on debug info", 10, 552)
g.drawString("'m' to show trapezoidal map (debug mode)", 10, 564)
g.drawString("'e' to switch Seidel / EarClip", 10, 576)
g.drawString("'1-6' to cycle models", 10, 520)
g.drawString("'SPACE' to show Seidel debug info", 10, 532)
g.drawString("'m' to show trapezoidal map (Seidel debug mode)", 10, 544)
g.drawString("'e' to switch Seidel / EarClip", 10, 556)
g.drawString("'d' to switch CDT / Seidel", 10, 568)
g.drawString("'c' to how CDT mesh", 10, 580)
g.scale(scaleFactor, scaleFactor)
g.translate(deltaX, deltaY)
@ -267,7 +269,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
if(c == '6') selectModel(i18)
if(c == 's') drawSegs = !drawSegs
if(c == 'c') drawcdtMesh = !drawcdtMesh
//if(c == 'e') {drawEarClip = !drawEarClip; selectModel(currentModel)}
if(c == 'e') {drawEarClip = !drawEarClip; drawCDT = false; selectModel(currentModel)}
}
def selectModel(model: String) {

View File

@ -131,19 +131,21 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Implement sweep-line
private def sweep {
for(i <- 1 until points.size) {
val point = points(i)
// Process Point event
var triangle = pointEvent(point)
// Process edge events
point.edges.foreach(e => triangle = edgeEvent(e, triangle))
if(i == CDT.clearPoint) {cleanTri = triangle; /*mesh.debug += cleanTri*/}
if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri}
}
}
// Final step in the sweep-line CDT algo
// Clean exterior triangles
private def finalization {
mesh.map.foreach(m => m.markEdges)
mesh clean cleanTri
//mesh.map.foreach(m => m.edges.foreach(e => if(e) mesh.debug += m))
@ -172,10 +174,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// EdgeEvent
private def edgeEvent(edge: Segment, triangle: Triangle): Triangle = {
// STEP 1: Locate the first intersected triangle
// Locate the first intersected triangle
val firstTriangle = triangle.locateFirst(edge)
// STEP 2: Remove intersected triangles
// Remove intersected triangles
if(firstTriangle != null && !firstTriangle.contains(edge)) {
// Collect intersected triangles
@ -223,7 +225,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
})
})
// STEP 3: Triangulate empty areas.
// Triangulate empty areas.
val T1 = new ArrayBuffer[Triangle]
triangulate(lPoints.toArray, List(point1, point2), T1)
val T2 = new ArrayBuffer[Triangle]
@ -234,6 +236,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val qNode = aFront.locatePoint(edge.q)
val pNode = aFront.locatePoint(edge.p)
// TODO: Make this more robust....
for(t <- tList) {
if(qNode.triangle == t) {
@ -265,8 +269,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
}
// Update neighbors
updateNeighbors(nTriangles, T1)
updateNeighbors(nTriangles, T2)
edgeNeighbors(nTriangles, T1)
edgeNeighbors(nTriangles, T2)
// Mark constrained edges
T1.first.mark(point1, point2)
@ -303,16 +307,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val endPoints = if(ahead) List(point2, point1) else List(point1, point2)
// STEP 3: Triangulate empty areas.
// Triangulate empty areas.
val T = new ArrayBuffer[Triangle]
triangulate(points.toArray, endPoints, T)
// Update advancing front
aFront -= (first, node.prev, T.first)
// Update neighbors
updateNeighbors(nTriangles, T)
edgeNeighbors(nTriangles, T)
// Mark constrained edge
T.first mark(edge.p, edge.q)
@ -329,7 +332,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Update neigbor pointers for edge event
// Inneficient, but it works well...
def updateNeighbors(nTriangles: ArrayBuffer[Triangle], T: ArrayBuffer[Triangle]) {
def edgeNeighbors(nTriangles: ArrayBuffer[Triangle], T: ArrayBuffer[Triangle]) {
for(t1 <- nTriangles)
for(t2 <- T)
@ -443,13 +446,12 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
private def legalization(t1: Triangle, node: Node): Node = {
val t2 = node.triangle
val point = t1.points(0)
val oPoint = t2 oppositePoint t1
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0))) {
// Flip edges and rotate everything clockwise
val point = t1.points(0)
t1.legalize(oPoint)
t2.legalize(oPoint, point)
@ -469,9 +471,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} else {
// Update neighbor
node.triangle.markNeighbor(t1)
t2.markNeighbor(t1)
// Update advancing front
aFront.insert(t1.points(0), t1, node)
aFront.insert(point, t1, node)
}