changed triangle initialization

This commit is contained in:
zzzzrrr 2009-08-10 12:35:03 -04:00
parent 84598700c4
commit a6b338d88d
2 changed files with 13 additions and 24 deletions

View File

@ -72,9 +72,8 @@ object CDT {
val segments = initSegments(points) val segments = initSegments(points)
val sortedPoints = pointSort(points) val sortedPoints = pointSort(points)
val noNeighbors = new Array[Triangle](3)
val tPoints = Array(sortedPoints(0), p1, p2) val tPoints = Array(sortedPoints(0), p1, p2)
val iTriangle = new Triangle(tPoints, noNeighbors) val iTriangle = new Triangle(tPoints)
new CDT(sortedPoints, segments, iTriangle) new CDT(sortedPoints, segments, iTriangle)
} }
@ -158,8 +157,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Projected point hits advancing front; create new triangle // Projected point hits advancing front; create new triangle
val pts = Array(point, node.point, node.next.point) val pts = Array(point, node.point, node.next.point)
val neighbors = Array(node.triangle, null, null) val triangle = new Triangle(pts)
val triangle = new Triangle(pts, neighbors)
mesh.map += triangle mesh.map += triangle
// Legalize // Legalize
@ -367,8 +365,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
if(!P.isEmpty) { if(!P.isEmpty) {
val points = Array(a, P.first, b) val points = Array(a, P.first, b)
val neighbors = new Array[Triangle](3) T += new Triangle(points)
T += new Triangle(points, neighbors)
mesh.map += T.last mesh.map += T.last
} }
} }
@ -404,12 +401,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val angle = Math.abs(Math.atan2(a cross b, a dot b)) val angle = Math.abs(Math.atan2(a cross b, a dot b))
if(angle <= PI_2) { if(angle <= PI_2) {
val points = Array(node.prev.point, node.point, node.next.point) val points = Array(node.prev.point, node.point, node.next.point)
val neighbors = Array(node.triangle, null, node.prev.triangle) val triangle = new Triangle(points)
val triangle = new Triangle(points, neighbors)
// Update neighbor pointers // Update neighbor pointers
//node.prev.triangle.markNeighbor(triangle.points(0), triangle.points(1), triangle)
node.prev.triangle.markNeighbor(triangle) node.prev.triangle.markNeighbor(triangle)
//node.triangle.markNeighbor(triangle.points(1), triangle.points(2), triangle)
node.triangle.markNeighbor(triangle) node.triangle.markNeighbor(triangle)
mesh.map += triangle mesh.map += triangle
aFront -= (node.prev, node, triangle) aFront -= (node.prev, node, triangle)
@ -456,10 +450,12 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// 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)
// Update neighbor pointers // Copy old neighbors
val neighbors = List(t2.neighbors(0), t2.neighbors(1), t2.neighbors(2)) val neighbors = List(t2.neighbors(0), t2.neighbors(1), t2.neighbors(2))
// Clear old neighbors
t2.clearNeighbors t2.clearNeighbors
// Update new neighbors
for(n <- neighbors) { for(n <- neighbors) {
if(n != null) { if(n != null) {
t2.markNeighbor(n) t2.markNeighbor(n)

View File

@ -38,8 +38,10 @@ import utils.Util
// Triangle-based data structures are know to have better performance than quad-edge structures // Triangle-based data structures are know to have better performance than quad-edge structures
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator" // See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
// "Triangulations in CGAL" // "Triangulations in CGAL"
class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) { class Triangle(val points: Array[Point]) {
// Neighbor pointers
var neighbors = new Array[Triangle](3)
// Flags to determine if an edge is the final Delauney edge // Flags to determine if an edge is the final Delauney edge
val edges = Array(false, false, false) val edges = Array(false, false, false)
@ -70,9 +72,6 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
else if((p1 == points(0) && p2 == points(1)) || (p1 == points(1) && p2 == points(0))) else if((p1 == points(0) && p2 == points(1)) || (p1 == points(1) && p2 == points(0)))
neighbors(2) = triangle neighbors(2) = triangle
else { else {
println("**********************")
triangle.printDebug
printDebug
throw new Exception("Neighbor pointer error, please report!") throw new Exception("Neighbor pointer error, please report!")
} }
} }
@ -92,8 +91,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
} }
def clearNeighbors { def clearNeighbors {
for(i <- 0 until 3) neighbors = new Array[Triangle](3)
neighbors(i) = null
} }
def oppositePoint(t: Triangle): Point = { def oppositePoint(t: Triangle): Point = {
@ -104,10 +102,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
else if((points(2) == t.points(1) && points(1) == t.points(2)) || (points(1) == t.points(1) && points(2) == t.points(2))) else if((points(2) == t.points(1) && points(1) == t.points(2)) || (points(1) == t.points(1) && points(2) == t.points(2)))
points(0) points(0)
else { else {
println("**********************") throw new Exception("Point location error, please report")
t.printDebug
printDebug
throw new Exception("point location error")
} }
} }
@ -248,7 +243,6 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
// Legalized triangle by rotating clockwise around point(0) // Legalized triangle by rotating clockwise around point(0)
def legalize(oPoint: Point) { def legalize(oPoint: Point) {
Util.collinear(points(0), points(2), oPoint)
points(1) = points(0) points(1) = points(0)
points(0) = points(2) points(0) = points(2)
points(2) = oPoint points(2) = oPoint
@ -269,7 +263,6 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
points(2) = points(1) points(2) = points(1)
points(1) = nPoint points(1) = nPoint
} }
Util.collinear(points(0), points(2), points(1))
} }
// Make legalized triangle will not be collinear // Make legalized triangle will not be collinear