mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
fixed orientation bug
This commit is contained in:
parent
4fd96b6535
commit
41e40241a1
@ -87,7 +87,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
val i18 = "data/i.18"
|
val i18 = "data/i.18"
|
||||||
val tank = "data/tank.dat"
|
val tank = "data/tank.dat"
|
||||||
|
|
||||||
var currentModel = strange
|
var currentModel = star
|
||||||
var doCDT = true
|
var doCDT = true
|
||||||
|
|
||||||
var mouseButton = 0
|
var mouseButton = 0
|
||||||
|
@ -90,25 +90,39 @@ class AFront(iTriangle: Triangle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update advancing front with constrained edge triangles
|
// Update advancing front with constrained edge triangles
|
||||||
def constrainedEdge(sNode: Node, eNode: Node, T2: ArrayBuffer[Triangle], edge: Segment): Triangle = {
|
def constrainedEdge(sNode: Node, eNode: Node, T1: ArrayBuffer[Triangle],
|
||||||
|
T2: ArrayBuffer[Triangle], edge: Segment) {
|
||||||
|
|
||||||
var node = sNode
|
var node = sNode
|
||||||
|
|
||||||
val point1 = edge.q
|
val point1 = edge.q
|
||||||
val point2 = edge.p
|
val point2 = edge.p
|
||||||
|
|
||||||
var edgeTri: Triangle = null
|
var edgeTri1: Triangle = null
|
||||||
|
var edgeTri2: Triangle = null
|
||||||
var marked = false
|
var marked = false
|
||||||
|
|
||||||
// Scan the advancing front and update Node triangle pointers
|
// Scan the advancing front and update Node triangle pointers
|
||||||
while(node != eNode) {
|
while(node != null && node != eNode.next) {
|
||||||
|
|
||||||
T2.foreach(t => {
|
T2.foreach(t => {
|
||||||
if(t.contains(node.point, node.next.point))
|
if(t.contains(node.point, node.next.point))
|
||||||
node.triangle = t
|
node.triangle = t
|
||||||
if(!marked && t.contains(point1, point2)) {
|
if(!marked && t.contains(point1, point2)) {
|
||||||
edgeTri = t
|
edgeTri2 = t
|
||||||
edgeTri markEdge(point1, point2)
|
edgeTri2 markEdge(point1, point2)
|
||||||
|
marked = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
marked = false
|
||||||
|
|
||||||
|
T1.foreach(t => {
|
||||||
|
if(t.contains(node.point, node.next.point))
|
||||||
|
node.triangle = t
|
||||||
|
if(!marked && t.contains(point1, point2)) {
|
||||||
|
edgeTri1 = t
|
||||||
|
edgeTri1 markEdge(point1, point2)
|
||||||
marked = true
|
marked = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -116,7 +130,8 @@ class AFront(iTriangle: Triangle) {
|
|||||||
node = node.next
|
node = node.next
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeTri
|
edgeTri1.markNeighbor(edgeTri2)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def -=(tuple: Tuple3[Node, Node, Triangle]) {
|
def -=(tuple: Tuple3[Node, Node, Triangle]) {
|
||||||
|
@ -130,10 +130,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
try {
|
try {
|
||||||
val point = points(i)
|
val point = points(i)
|
||||||
// Process Point event
|
// Process Point event
|
||||||
var triangle = pointEvent(point)
|
val node = pointEvent(point)
|
||||||
|
if(i == CDT.clearPoint) {cleanTri = node.triangle; mesh.debug += cleanTri}
|
||||||
// Process edge events
|
// Process edge events
|
||||||
point.edges.foreach(e => triangle = edgeEvent(e, triangle))
|
point.edges.foreach(e => edgeEvent(e, node))
|
||||||
if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri}
|
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception =>
|
case e: Exception =>
|
||||||
@ -153,7 +153,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Point event
|
// Point event
|
||||||
private def pointEvent(point: Point): Triangle = {
|
private def pointEvent(point: Point): Node = {
|
||||||
|
|
||||||
val node = aFront.locate(point)
|
val node = aFront.locate(point)
|
||||||
|
|
||||||
@ -167,15 +167,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val newNode = legalization(triangle, node)
|
val newNode = legalization(triangle, node)
|
||||||
// Fill in adjacent triangles if required
|
// Fill in adjacent triangles if required
|
||||||
scanAFront(newNode)
|
scanAFront(newNode)
|
||||||
newNode.triangle
|
newNode
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EdgeEvent
|
// EdgeEvent
|
||||||
private def edgeEvent(edge: Segment, triangle: Triangle): Triangle = {
|
private def edgeEvent(edge: Segment, node: Node) {
|
||||||
|
|
||||||
// Locate the first intersected triangle
|
// Locate the first intersected triangle
|
||||||
val firstTriangle = triangle.locateFirst(edge)
|
val firstTriangle = node.triangle.locateFirst(edge)
|
||||||
|
|
||||||
// Remove intersected triangles
|
// Remove intersected triangles
|
||||||
if(firstTriangle != null && !firstTriangle.contains(edge)) {
|
if(firstTriangle != null && !firstTriangle.contains(edge)) {
|
||||||
@ -237,13 +237,11 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val sNode = aFront.locate(point1)
|
val sNode = aFront.locate(point1)
|
||||||
val eNode = aFront.locate(point2)
|
val eNode = aFront.locate(point2)
|
||||||
|
|
||||||
val eTri = aFront.constrainedEdge(sNode, eNode, T2, edge)
|
aFront.constrainedEdge(sNode, eNode, T1, T2, edge)
|
||||||
|
|
||||||
// Mark edge triangle neighbors
|
// Mark edge triangle neighbors
|
||||||
//T1.foreach(t => t.markNeighbor(eTri))
|
//T1.foreach(t => t.markNeighbor(eTri))
|
||||||
|
|
||||||
eTri
|
|
||||||
|
|
||||||
} else if(firstTriangle == null) {
|
} else if(firstTriangle == null) {
|
||||||
|
|
||||||
// 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
|
||||||
@ -293,13 +291,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
// Mark constrained edge
|
// Mark constrained edge
|
||||||
edgeTri markEdge(point1, point2)
|
edgeTri markEdge(point1, point2)
|
||||||
|
|
||||||
// Return original triangle
|
|
||||||
triangle
|
|
||||||
|
|
||||||
} else if(firstTriangle.contains(edge.q, edge.p)) {
|
} else if(firstTriangle.contains(edge.q, edge.p)) {
|
||||||
// Mark constrained edge
|
// Mark constrained edge
|
||||||
firstTriangle markEdge(edge.q, edge.p)
|
firstTriangle markEdge(edge.q, edge.p)
|
||||||
triangle
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Triangulation error")
|
throw new Exception("Triangulation error")
|
||||||
//null
|
//null
|
||||||
@ -344,7 +338,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!P.isEmpty) {
|
if(!P.isEmpty) {
|
||||||
val points = Array(a, P(i), b)
|
val ccw = Util.orient2d(a, P(i), b) > 0
|
||||||
|
val points = if(ccw) Array(a, P(i), b) else Array(a, b, P(i))
|
||||||
T += new Triangle(points)
|
T += new Triangle(points)
|
||||||
T.last.finalized = true
|
T.last.finalized = true
|
||||||
mesh.map += T.last
|
mesh.map += T.last
|
||||||
|
Loading…
Reference in New Issue
Block a user