Slow creating 3DFaces

Discussion in 'AutoCAD' started by Yves, Dec 8, 2004.

  1. Yves

    Yves Guest

    Hi, I have a very simple code that reads an ASCII file to extract Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.

    For i = 1 To CntTri - 1
    FacePt1(0) = VtxX.Item(Tri1.Item(i))
    FacePt1(1) = VtxY.Item(Tri1.Item(i))
    FacePt1(2) = VtxZ.Item(Tri1.Item(i))
    FacePt2(0) = VtxX.Item(tri2.Item(i))
    FacePt2(1) = VtxY.Item(tri2.Item(i))
    FacePt2(2) = VtxZ.Item(tri2.Item(i))
    FacePt3(0) = VtxX.Item(Tri3.Item(i))
    FacePt3(1) = VtxY.Item(Tri3.Item(i))
    FacePt3(2) = VtxZ.Item(Tri3.Item(i))
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
     
    Yves, Dec 8, 2004
    #1
  2. The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
    For i = 1 To CntTri - 1
    t1 = Tri1.Item(i)
    t2 = Tri2.Item(i)
    t3 = Tri3.Item(i)
    FacePt1(0) = VtxX.Item(t1)
    FacePt1(1) = VtxY.Item(t1)
    FacePt1(2) = VtxZ.Item(t1)
    FacePt2(0) = VtxX.Item(t2)
    FacePt2(1) = VtxY.Item(t2)
    FacePt2(2) = VtxZ.Item(t2)
    FacePt3(0) = VtxX.Item(t3)
    FacePt3(1) = VtxY.Item(t3)
    FacePt3(2) = VtxZ.Item(t3)
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
    
    If you can make collections of user-defined-types (I don't know about this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and Z
    value:

    Code:
    Type Point3Data
    x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
    Pt2 = Vtx.Item(t2)
    FacePt2(0) = Pt2.x
    FacePt2(1) = Pt2.y
    FacePt2(2) = Pt2.z
    Pt3 = Vtx.Item(t3)
    FacePt3(0) = Pt3.x
    FacePt3(1) = Pt3.y
    FacePt3(2) = Pt3.z
    
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can disprove
    this point....

    James
     
    James Belshan, Dec 8, 2004
    #2
  3. Yves

    Yves Guest

    Thanks James,

    I used the collection because it's the only way I could find to store data,
    and not having to know in advance it's size.

    Putting it all in an array would mean, I need to got through the collections
    anyways.




     
    Yves, Dec 8, 2004
    #3
  4. Yves

    Yves Guest

    Hi James,

    After knowing that the collections might be part of my problem, I created
    array way bigger than needed, and the 5min file now opens in less than 20
    sec.


    Thanks.



     
    Yves, Dec 8, 2004
    #4
  5. Hi,

    If the file lines are of constant length, you can compute the number of
    lines from the file size and dimension your array accordingly.

    Alternatively, you may be able to open the file read it to count the number
    of lines, close the file, dimension the array and then reopen the file for
    reading.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

     
    Laurie Comerford, Dec 8, 2004
    #5
  6. Yes, but you'd be going through them only one time apiece, before you start
    looping, to copy them into an array. This would go quickly, especially with
    a For...Each loop. I think it's repeated diving into them for a specific
    item that gets so slow.

    I see from your other post that you found a quick solution... that's good.

    If you still wanted to use collections to input from the files, you could
    use a dynamic array and then re-size it using the collections .Count
    property before copying from the collection.

    James
     
    James Belshan, Dec 8, 2004
    #6
  7. Yves

    Tony Burba Guest

    You can refine this a bit by tracking the highest item in the array as it
    fills, then redimensioning it to that number after you've filled the array
    as far as it will go.


     
    Tony Burba, Dec 10, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.