mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-05 13:59:53 +01:00
added refinement algo
This commit is contained in:
parent
8e788b2e15
commit
ed89aea7c0
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user