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 => {
|
//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)
|
val circ = new Circle(slCDT.cList(i).x, slCDT.cList(i).y, 0.5f)
|
||||||
g.setColor(blue); g.draw(circ); g.fill(circ)
|
g.setColor(blue); g.draw(circ); g.fill(circ)
|
||||||
}
|
}
|
||||||
@ -436,14 +436,10 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
slCDT triangulate
|
slCDT triangulate
|
||||||
val runTime = System.nanoTime - t1
|
val runTime = System.nanoTime - t1
|
||||||
|
|
||||||
if(slCDT.cList.size > 1) {
|
for(j <- 0 until 1) {
|
||||||
//slCDT.addPoint(slCDT.cList(0))
|
slCDT.refine
|
||||||
//slCDT.addPoint(slCDT.cList(1))
|
|
||||||
for(i <- 0 until slCDT.cList.size)
|
|
||||||
slCDT.addPoint(slCDT.cList(i))
|
|
||||||
slCDT.triangulate
|
|
||||||
}
|
}
|
||||||
|
//slCDT.refine
|
||||||
println("CDT average (ms) = " + runTime*1e-6)
|
println("CDT average (ms) = " + runTime*1e-6)
|
||||||
println("Number of triangles = " + slCDT.triangles.size)
|
println("Number of triangles = " + slCDT.triangles.size)
|
||||||
println
|
println
|
||||||
|
@ -54,7 +54,8 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
|
|||||||
def debugTriangles = mesh.debug
|
def debugTriangles = mesh.debug
|
||||||
|
|
||||||
val cList = new ArrayBuffer[Point]
|
val cList = new ArrayBuffer[Point]
|
||||||
var refine = false
|
|
||||||
|
var refined = false
|
||||||
|
|
||||||
// Initialize edges
|
// Initialize edges
|
||||||
initEdges(polyLine)
|
initEdges(polyLine)
|
||||||
@ -152,8 +153,8 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
|
|||||||
|
|
||||||
// Implement sweep-line
|
// Implement sweep-line
|
||||||
private def sweep {
|
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) {
|
for(i <- 1 until points.size) {
|
||||||
|
|
||||||
@ -182,17 +183,22 @@ class CDT(polyLine: Array[Point], clearPoint: Point) {
|
|||||||
})
|
})
|
||||||
// Collect interior triangles constrained by edges
|
// Collect interior triangles constrained by edges
|
||||||
mesh clean cleanTri
|
mesh clean cleanTri
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refine the mesh using Steiner points
|
||||||
|
def refine {
|
||||||
|
cList.clear
|
||||||
mesh.triangles.foreach(t => {
|
mesh.triangles.foreach(t => {
|
||||||
if(t.thin) {
|
if(t.thin) {
|
||||||
val center = Util.circumcenter(t.points(0), t.points(1), t.points(2))
|
val center = Util.circumcenter(t.points(0), t.points(1), t.points(2))
|
||||||
cList += center
|
cList += center
|
||||||
refine = true
|
addPoint(center)
|
||||||
//addPoint(center)
|
|
||||||
//mesh.debug += t
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// Retriangulate
|
||||||
|
if(cList.size > 0)
|
||||||
|
triangulate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Point event
|
// Point event
|
||||||
|
Loading…
Reference in New Issue
Block a user