From ed89aea7c07eeb48f009683ee0ff28d4aa76efe5 Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Tue, 25 Aug 2009 10:58:04 -0400 Subject: [PATCH] added refinement algo --- src/org/poly2tri/Poly2Tri.scala | 12 ++++-------- src/org/poly2tri/cdt/CDT.scala | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index da559b4..5b55207 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -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 diff --git a/src/org/poly2tri/cdt/CDT.scala b/src/org/poly2tri/cdt/CDT.scala index 6340146..ea90e95 100644 --- a/src/org/poly2tri/cdt/CDT.scala +++ b/src/org/poly2tri/cdt/CDT.scala @@ -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) { @@ -182,17 +183,22 @@ 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