Android Question Import a TIN Model from a LandXML file crashes

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:

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.
 

drgottjr

Expert
Licensed User
Longtime User
this:
B4X:
        If line.Contains("<P")
could get you more than you bargained for.
 
Upvote 0

Terradrones

Active Member
Hi

This is how the format looks in a LandXML file for Points:

<P id="1">2598728.2320 65002.7740 596.4240</P>
<P id="2">2598734.9320 65002.7740 596.0450</P>
<P id="3">2598742.8320 65002.7740 595.6260</P>
<P id="4">2598750.7320 65002.7740 595.2180</P>
<P id="5">2598758.6320 65002.7740 594.7300</P>
<P id="6">2598766.0320 65002.7740 594.2660</P>
<P id="7">2598773.4320 65002.7740 593.7990</P>

And this is how it looks for Faces (Triangles):

<F>1160 1116 1117</F>
<F>1118 1117 1085</F>
<F>1199 1198 1155</F>
<F>1119 1086 1087</F>
<F>1058 1057 1025</F>
<F>1089 1056 1057</F>
<F>1159 1158 1115</F>
<F>1282 1281 1238</F>
<F>1281 1280 1237</F>

That is why I am first looking for "<P" and then for "<F".

It works 100% up to about 800 Points, but with any File more than that the program crashes without any error messages.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the program crashes
if a app crash then the must be something in the log.
There is no crash without error in the log in Android.

Remove the try catch blocks and let the app crash so you should find the probematik code which crashes.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
just fyi, If line.Contains("<P") would also give you:

B4X:
<PntList3D>2846116.335177 375170.253609 -9.563556 2846099.470539 375151.797842 -9.458881 2846082.635587 375133.314560 -9.333968 2846065.780917 375114.849553 -9.222497 2846048.909062 375096.400475 -9.122742 2846032.037207 375077.951397 -9.022987 2846015.123284 375059.541310 -8.951911 2845998.167701 375041.169838 -8.909237 2845981.193541 375022.815583 -8.879228 2845964.173050 375004.504271 -8.880804 2845947.097568 374986.243929 -8.919870 2845930.000316 374968.003765 -8.973778 2845912.904773 374949.762016 -9.026520 2845906.065908 374942.465917 -9.048058 2845895.870911 374931.463097 -9.080222 2845878.893362 374913.111984 -9.124208 2845861.948199 374894.730853 -9.146115 2845845.033340 374876.321633 -9.147361 2845828.103882 374857.925946 -9.158562 2845811.169860 374839.534489 -9.172873 2845794.246869 374821.132807 -9.179664 2845777.344815 374802.711720 -9.172182 2845760.450863 374784.283123 -9.159176 2845743.569858 374765.842526 -9.137343 2845726.671965 374747.417581 -9.127023 2845709.762946 374729.002949 -9.124289 2845692.868986 374710.574360 -9.111289 2845012.965689 374372.571586 -9.208032 2844988.070927 374370.279884 -9.174003 2844984.314450 374369.934079 -9.168868 2844962.602135 374367.699567 -9.138817 2844937.098850 374364.474868 -9.102039 2844911.682290 374360.620584 -9.068825 2844886.367442 374356.140949 -9.040165 2844861.162801 374351.069197 -9.031722 2844836.083559 374345.397999 -9.038460 2844811.155193 374339.085959 -9.037438 2844786.390059 374332.151904 -9.036329 2844761.806551 374324.591227 -9.030495 2844737.421329 374316.407093 -9.019054 2844713.235483 374307.644069 -9.023023 2844689.261904 374298.306958 -9.042537 2844665.515204 374288.396628 -9.075442 2844642.020117 374277.893492 -9.108034 2844618.798194 374266.790493 -9.132791 2844595.878755 374255.069246 -9.135172 2844573.262282 374242.768377 -9.132339 2844550.910637 374229.984419 -9.175905 2844528.863534 374216.671674 -9.236291 2844507.187804 374202.754567 -9.263973 2844485.745014 374188.465725 -9.394436 2844464.658428 374173.640482 -9.525186 2844448.156368 374161.268788 -9.546970 2844444.087250 374158.101538 -9.552314 2844423.993214 374141.948407 -9.570101 2844404.514591 374125.061451 -9.431256 2844385.483282 374107.683766 -9.282669 2844366.638649 374090.112593 -9.321819 2844348.209625 374072.103837 -9.381297 2844330.266765 374053.608849 -9.419068 2844312.819333 374034.645303 -9.437982 2844295.884784 374015.223178 -9.434991 2844279.449490 373995.378477 -9.427045 2844263.526498 373975.122405 -9.412656 2844248.126772 373954.468082 -9.391526 2844233.222186 373933.455834 -9.386945 2844229.322241 373927.770965 -9.386301 2844219.023051 373912.632404 -9.380130 2844204.984872 373891.945759 -9.357016 2844190.929775 373871.270682 -9.344149 2844176.798038 373850.648009 -9.377703 2844162.666703 373830.025061 -9.411014 2844148.641475 373809.329561 -9.380056 2844134.615437 373788.634614 -9.349587 2844120.560001 373767.959769 -9.336926 2844106.465369 373747.311725 -9.348006 2844092.370737 373726.663680 -9.359085 2844078.335921 373705.974736 -9.333934 2844064.296036 373685.289258 -9.311853 2844050.324486 373664.557054 -9.248381 2844036.158498 373643.957801 -9.302682 2844021.928304 373623.402449 -9.395873 2844007.934446 373602.685499 -9.345913 2844000.536831 373591.726961 -9.317567 2844020.872617 373577.822083 3.000000 2844029.127407 373572.177756 3.000000 2844049.071954 373558.540394 -9.080589 2844056.646463 373569.377978 -9.137300 2844070.870374 373589.937626 -9.184915 2844085.209521 373610.418480 -9.302330 2844099.425996 373630.983213 -9.345441 2844113.554278 373651.608248 -9.335133 2844127.863242 373672.109740 -9.434266 2844142.085140 373692.670764 -9.480662 2844156.292878 373713.241471 -9.518481 2844170.472783 373733.831208 -9.539442 2844184.681125 373754.401502 -9.577627 2844198.811507 373775.025101 -9.568591 2844212.934518 373795.653741 -9.555090 2844227.083303 373816.264758 -9.557201 2844241.218561 373836.885023 -9.551119 2845049.157655 374319.369290 -9.238291 2845068.485414 374321.488776 -9.212158 2845093.976056 374324.752315 -9.227015 2845119.384269 374328.597394 -9.269421 2845144.711436 374332.952593 -9.374797 2845169.919929 374337.961305 -9.469320 2845195.010366 374343.545731 -9.591289 2845219.983177 374349.658209 -9.764133 2845244.715375 374356.685646 -9.785292 2845269.268948 374364.309524 -9.816521 2845293.489817 374372.925549 -9.645858 2845317.394105 374382.360316 -9.357696 2845341.156088 374392.096980 -9.224226 2845364.680659 374402.370926 -9.118084 2845388.019986 374413.042238 -9.113622 2845411.155451 374424.146510 -9.190672 2845433.925760 374435.980169 -9.180630 2845447.379607 374443.465548 -9.109612 2845456.307826 374448.524923 -9.043733 2845478.321426 374461.691495 -8.802406 2845500.153370 374475.141725 -8.713328 2845521.709168 374489.029915 -8.685907 2845542.994868 374503.335664 -8.730409 2845563.972703 374518.101228 -8.818903 2845584.554654 374533.424239 -8.886278 2845604.721732 374549.297616 -8.929842 2845624.495952 374565.665880 -8.978337 2845643.844939 374582.541969 -9.016577 2845662.758107 374599.911545 -9.046598 2845681.207631 374617.777975 -9.057843 2845699.170655 374636.136963 -9.043976 2845707.134119 374644.568609 -9.040594 2845716.494499 374654.589479 -9.036647 2845733.572696 374672.847304 -9.038138 2845750.684879 374691.073629 -9.062798 2845767.798766 374709.298375 -9.088620 2845784.895289 374727.539216 -9.102604 2845801.987307 374745.784231 -9.113517 2845819.079326 374764.029246 -9.124430 2845836.155931 374782.288547 -9.124835 2845853.202235 374800.575933 -9.104583 2845870.248540 374818.863319 -9.084331 2845887.282105 374837.162513 -9.055394 2845904.313609 374855.463617 -9.025052 2845921.345254 374873.764591 -8.994805 2845938.377438 374892.065064 -8.964927 2845948.598280 374903.043929 -8.948044 2845955.370264 374910.402018 -8.936890 2845972.293440 374928.803529 -8.904380 2845989.229290 374947.193291 -8.880512 2846006.233208 374965.519964 -8.903048 2846023.268296 374983.817746 -8.946834 2846040.410114 375002.016604 -9.063381 2846057.522017 375020.243189 -9.159535 2846074.640011 375038.464128 -9.259841 2846091.733007 375056.708237 -9.343106 2846108.972617 375074.816453 -9.526323 2846126.105464 375093.023626 -9.636755 2846143.070535 375111.386305 -9.632807 2846160.026964 375129.756994 -9.622968 2846141.804574 375146.646784 2.800000 2846134.470421 375153.444592 2.800000 2846116.335177 375170.253609 -9.563556 </PntList3D>
 
Upvote 0

Terradrones

Active Member
I solved my problem. After every "ProcessPoint" and every "ProcessFace", I put in a "Sleep(20)" and it works. I managed to import a TIN Model in LandXML format with over 20 000 faces.
 
Upvote 0
Top