added refinement algo

This commit is contained in:
zzzzrrr 2009-08-25 10:58:04 -04:00
parent 8e788b2e15
commit ed89aea7c0
2 changed files with 18 additions and 16 deletions

View File

@ -211,7 +211,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
})
//slCDT.cList.foreach(c => {
for(i <- 0 until 9) {
for(i <- 0 until slCDT.cList.size) {
val circ = new Circle(slCDT.cList(i).x, slCDT.cList(i).y, 0.5f)
g.setColor(blue); g.draw(circ); g.fill(circ)
}
@ -436,14 +436,10 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
slCDT triangulate
val runTime = System.nanoTime - t1
if(slCDT.cList.size > 1) {
//slCDT.addPoint(slCDT.cList(0))
//slCDT.addPoint(slCDT.cList(1))
for(i <- 0 until slCDT.cList.size)
slCDT.addPoint(slCDT.cList(i))
slCDT.triangulate
for(j <- 0 until 1) {
slCDT.refine
}
//slCDT.refine
println("CDT average (ms) = " + runTime*1e-6)
println("Number of triangles = " + slCDT.triangles.size)
println

View File

@ -54,7 +54,8 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
def debugTriangles = mesh.debug
val cList = new ArrayBuffer[Point]
var refine = false
var refined = false
// Initialize edges
initEdges(polyLine)
@ -152,8 +153,8 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
// Implement sweep-line
private def sweep {
// 49 69
val size = if(refine) 50 else points.size
val size = if(refined) 1 else points.size
for(i <- 1 until points.size) {
@ -183,16 +184,21 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
// Collect interior triangles constrained by edges
mesh clean cleanTri
}
// Refine the mesh using Steiner points
def refine {
cList.clear
mesh.triangles.foreach(t => {
if(t.thin) {
val center = Util.circumcenter(t.points(0), t.points(1), t.points(2))
cList += center
refine = true
//addPoint(center)
//mesh.debug += t
addPoint(center)
}
})
// Retriangulate
if(cList.size > 0)
triangulate
}
// Point event