mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
code cleanup
This commit is contained in:
parent
2abca79e6e
commit
18f8f17cc3
@ -86,6 +86,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
val i18 = "data/i.18"
|
val i18 = "data/i.18"
|
||||||
|
|
||||||
var currentModel = strange
|
var currentModel = strange
|
||||||
|
var doCDT = true
|
||||||
|
|
||||||
var mouseButton = 0
|
var mouseButton = 0
|
||||||
var mousePressed = false
|
var mousePressed = false
|
||||||
@ -278,21 +279,27 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
def selectModel(model: String) {
|
def selectModel(model: String) {
|
||||||
model match {
|
model match {
|
||||||
case "data/nazca_monkey.dat" =>
|
case "data/nazca_monkey.dat" =>
|
||||||
CDT.clearPoint = 50
|
//CDT.clearPoint = 50
|
||||||
|
doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||||
loadModel(nazcaMonkey, 4.5f, Point(400, 300), 1500)
|
loadModel(nazcaMonkey, 4.5f, Point(400, 300), 1500)
|
||||||
case "data/bird.dat" =>
|
case "data/bird.dat" =>
|
||||||
CDT.clearPoint = 80
|
doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||||
|
//CDT.clearPoint = 80
|
||||||
loadModel(bird, 25f, Point(400, 300), 350)
|
loadModel(bird, 25f, Point(400, 300), 350)
|
||||||
case "data/i.snake" =>
|
case "data/i.snake" =>
|
||||||
|
doCDT = true; drawCDT = true
|
||||||
CDT.clearPoint = 6
|
CDT.clearPoint = 6
|
||||||
loadModel(snake, 10f, Point(600, 300), 10)
|
loadModel(snake, 10f, Point(600, 300), 10)
|
||||||
case "data/star.dat" =>
|
case "data/star.dat" =>
|
||||||
|
doCDT = true; drawCDT = true
|
||||||
CDT.clearPoint = 6
|
CDT.clearPoint = 6
|
||||||
loadModel(star, -1f, Point(0f, 0f), 10)
|
loadModel(star, -1f, Point(0f, 0f), 10)
|
||||||
case "data/strange.dat" =>
|
case "data/strange.dat" =>
|
||||||
|
doCDT = true; drawCDT = true
|
||||||
CDT.clearPoint = 13
|
CDT.clearPoint = 13
|
||||||
loadModel(strange, -1f, Point(0f, 0f), 15)
|
loadModel(strange, -1f, Point(0f, 0f), 15)
|
||||||
case "data/i.18" =>
|
case "data/i.18" =>
|
||||||
|
doCDT = true; drawCDT = true
|
||||||
CDT.clearPoint = 7
|
CDT.clearPoint = 7
|
||||||
loadModel(i18, 20f, Point(600f, 500f), 20)
|
loadModel(i18, 20f, Point(600f, 500f), 20)
|
||||||
case _ =>
|
case _ =>
|
||||||
@ -334,12 +341,14 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
println("Number of points = " + polyX.size)
|
println("Number of points = " + polyX.size)
|
||||||
println
|
println
|
||||||
|
|
||||||
|
if(doCDT) {
|
||||||
val t1 = System.nanoTime
|
val t1 = System.nanoTime
|
||||||
slCDT = CDT.init(points)
|
slCDT = CDT.init(points)
|
||||||
val runTime = System.nanoTime - t1
|
val runTime = System.nanoTime - t1
|
||||||
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
|
||||||
|
}
|
||||||
|
|
||||||
if(!drawEarClip) {
|
if(!drawEarClip) {
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
|
|
||||||
// Remove intersected triangles
|
// Remove intersected triangles
|
||||||
if(firstTriangle != null && !firstTriangle.contains(edge)) {
|
if(firstTriangle != null && !firstTriangle.contains(edge)) {
|
||||||
println("collect")
|
|
||||||
// Collect intersected triangles
|
// Collect intersected triangles
|
||||||
val tList = new ArrayBuffer[Triangle]
|
val tList = new ArrayBuffer[Triangle]
|
||||||
tList += firstTriangle
|
tList += firstTriangle
|
||||||
@ -257,7 +257,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
first
|
first
|
||||||
|
|
||||||
} else if(firstTriangle == null) {
|
} else if(firstTriangle == null) {
|
||||||
println("intersect")
|
|
||||||
// No triangles are intersected by the edge; edge must lie outside the mesh
|
// No triangles are intersected by the edge; edge must lie outside the mesh
|
||||||
// Apply constraint; traverse the AFront, and build triangles
|
// Apply constraint; traverse the AFront, and build triangles
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
triangle
|
triangle
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
println("contains")
|
|
||||||
// Mark constrained edge
|
// Mark constrained edge
|
||||||
firstTriangle mark(edge.p, edge.q)
|
firstTriangle mark(edge.p, edge.q)
|
||||||
triangle
|
triangle
|
||||||
@ -434,9 +434,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val point = t1.points(0)
|
val point = t1.points(0)
|
||||||
val oPoint = t2 oppositePoint t1
|
val oPoint = t2 oppositePoint t1
|
||||||
|
|
||||||
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0))) {
|
val collinear = t1.collinear(oPoint) || t2.collinear(oPoint, point)
|
||||||
|
|
||||||
|
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) {
|
||||||
|
|
||||||
println("legalize")
|
|
||||||
// Flip edge and rotate everything clockwise
|
// Flip edge and rotate everything clockwise
|
||||||
t1.legalize(oPoint)
|
t1.legalize(oPoint)
|
||||||
t2.legalize(oPoint, point)
|
t2.legalize(oPoint, point)
|
||||||
|
Loading…
Reference in New Issue
Block a user