fixed orientation bug

This commit is contained in:
zzzzrrr 2009-08-14 16:16:54 -04:00
parent 4fd96b6535
commit 41e40241a1
3 changed files with 33 additions and 23 deletions

View File

@ -87,7 +87,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
val i18 = "data/i.18"
val tank = "data/tank.dat"
var currentModel = strange
var currentModel = star
var doCDT = true
var mouseButton = 0

View File

@ -90,25 +90,39 @@ class AFront(iTriangle: Triangle) {
}
// 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
val point1 = edge.q
val point2 = edge.p
var edgeTri: Triangle = null
var edgeTri1: Triangle = null
var edgeTri2: Triangle = null
var marked = false
// Scan the advancing front and update Node triangle pointers
while(node != eNode) {
while(node != null && node != eNode.next) {
T2.foreach(t => {
if(t.contains(node.point, node.next.point))
node.triangle = t
if(!marked && t.contains(point1, point2)) {
edgeTri = t
edgeTri markEdge(point1, point2)
edgeTri2 = t
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
}
})
@ -116,7 +130,8 @@ class AFront(iTriangle: Triangle) {
node = node.next
}
edgeTri
edgeTri1.markNeighbor(edgeTri2)
}
def -=(tuple: Tuple3[Node, Node, Triangle]) {

View File

@ -130,10 +130,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
try {
val point = points(i)
// Process Point event
var triangle = pointEvent(point)
val node = pointEvent(point)
if(i == CDT.clearPoint) {cleanTri = node.triangle; mesh.debug += cleanTri}
// Process edge events
point.edges.foreach(e => triangle = edgeEvent(e, triangle))
if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri}
point.edges.foreach(e => edgeEvent(e, node))
} catch {
case e: Exception =>
@ -153,7 +153,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
}
// Point event
private def pointEvent(point: Point): Triangle = {
private def pointEvent(point: Point): Node = {
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)
// Fill in adjacent triangles if required
scanAFront(newNode)
newNode.triangle
newNode
}
// EdgeEvent
private def edgeEvent(edge: Segment, triangle: Triangle): Triangle = {
private def edgeEvent(edge: Segment, node: Node) {
// Locate the first intersected triangle
val firstTriangle = triangle.locateFirst(edge)
val firstTriangle = node.triangle.locateFirst(edge)
// Remove intersected triangles
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 eNode = aFront.locate(point2)
val eTri = aFront.constrainedEdge(sNode, eNode, T2, edge)
aFront.constrainedEdge(sNode, eNode, T1, T2, edge)
// Mark edge triangle neighbors
//T1.foreach(t => t.markNeighbor(eTri))
eTri
} else if(firstTriangle == null) {
// 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
edgeTri markEdge(point1, point2)
// Return original triangle
triangle
} else if(firstTriangle.contains(edge.q, edge.p)) {
// Mark constrained edge
firstTriangle markEdge(edge.q, edge.p)
triangle
} else {
throw new Exception("Triangulation error")
//null
@ -344,7 +338,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
}
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.last.finalized = true
mesh.map += T.last