Terradrones
Active Member
Hi All
I have some code that first reads the Points of a TIN Model and thereafter it reads the Faces. If the File is small there is no problem importing it, but if the File is large (say >1000 Points) the program crashes without any warning messages.
Here the code:
A push in the right direction will be appreciated.
I have some code that first reads the Points of a TIN Model and thereafter it reads the Faces. If the File is small there is no problem importing it, but if the File is large (say >1000 Points) the program crashes without any warning messages.
Here the code:
B4X:
Sub ReadFile(Dir As String, FileName As String)
Dim TextReader1 As TextReader
TextReader1.Initialize(File.OpenInput(Dir, FileName))
Dim line As String
line = TextReader1.ReadLine
Do While line <> Null
If line.Contains("<P") Then
ProcessPoint(line)
Else If line.Contains("<F") Then
ProcessFace(line)
End If
line = TextReader1.ReadLine
Loop
TextReader1.Close
End Sub
Sub ProcessPoint(line As String)
Dim inputString As String = line
Dim ID As String
Dim idMatcher As Matcher = Regex.Matcher("\""(\d+)\""", line)
If idMatcher.Find Then
ID = idMatcher.Group(1)
End If
' Extract the numbers
Try
Dim numbersPattern As String = "\d+\.\d+ \d+\.\d+ \d+\.\d+"
Dim numbersMatcher As Matcher = Regex.Matcher(numbersPattern, inputString)
If numbersMatcher.Find Then
Dim numbers As String = numbersMatcher.Match
Dim parts() As String = Regex.Split(" ", numbers)
End If
Catch
Log(LastException)
End Try
Try
If IsNumber(ID)=True Then
Dim point As Map
point.Initialize
point.Put("X", parts(0))
point.Put("Y", parts(1))
point.Put("Z", parts(2))
Pnts.Put(ID, point)
End If
Catch
Log(LastException)
End Try
End Sub
Sub ProcessFace(line As String)
' Extract the numbers
Try
Dim numbersPattern As String = "\d+ \d+ \d+"
Dim numbersMatcher As Matcher = Regex.Matcher(numbersPattern, line)
If numbersMatcher.Find Then
Dim numbers As String = numbersMatcher.Match
Dim parts() As String = Regex.Split(" ", numbers)
End If
Catch
Log(LastException)
End Try
Try
Dim face As Map
face.Initialize
face.Put("P1", parts(0))
face.Put("P2", parts(1))
face.Put("P3", parts(2))
Faces.Add(face)
Catch
Log(LastException)
End Try
End Sub
Sub CreateTINModel
Rec=0
For Each face As Map In Faces
Try
Dim p1 As Map = Pnts.Get(face.Get("P1"))
Dim p2 As Map = Pnts.Get(face.Get("P2"))
Dim p3 As Map = Pnts.Get(face.Get("P3"))
If p1.IsInitialized And p2.IsInitialized And p3.IsInitialized Then
' Create a triangle with points p1, p2, p3
Y1=p1.Get("Y")
X1=p1.Get("X")
Z1=p1.Get("Z")
Y2=p2.Get("Y")
X2=p2.Get("X")
Z2=p2.Get("Z")
Y3=p3.Get("Y")
X3=p3.Get("X")
Z3=p3.Get("Z")
Rec=Rec+1
Engine.CalcTinArea(Y1, X1, Y2, X2, Y3, X3)
Query = "INSERT INTO Tin VALUES (?,?,?,?,?,?,?,?,?,?,?)"
CGlobals.SQL1.ExecNonQuery2(Query, Array As String(Rec, Y1, X1, Z1,Y2,X2,Z2,Y3, X3, Z3, Engine.Area))
Else
Log("One or more points not found for face: " & face)
End If
Catch
Log(LastException)
End Try
Next
ProgressDialogHide
ToastMessageShow("TIN Model Imported", False)
ShowTable
End Sub
A push in the right direction will be appreciated.